creatures caves welcome, guest
downloads   gallery   dev   community   creatchi   forum   mycaves
bookmarks | search | post new topic
Development Forum
old
Reduce agent population   
Geek2Nurse

Geek2Nurse
United States  

 visit Geek2Nurse's website: Adventures in Nornia
  4/24/2012

So I've come up with my first actually useful original code snippet. This reduces the population of an agent (eg. dragonflies) by 50%, rather than wiping them out completely when they start to get out of control. I'm really interested in seeing if anyone has suggestions or a slicker way to do it; feedback will help me learn! :)


setv va42 0
enum 2 15 8
doif va42 ne 0
kill targ
setv va42 0
else
setv va42 1
endi
next


(I'm actually using this in the game itself, so it all gets typed on one line, but I broke it up for the sake of legibility here.)

Advice / comments / suggestions? (Also, how do you indent within a code block using the forum commands?)


---
Optimist: the glass is half full.
Pessimist: the glass is half empty.
Engineer: the glass is twice as big as it needs to be.

 
Liam

Liam


 visit Liam's website: Spellhold Studios
  4/24/2012

Possibly something that might be a bit more precise:

setv va00 totl x xx xxxxx
divv va00 2
enum x xx xxxxx
doif va00 gt 0
subv va00 1
kill targ
else
stop
endi
next


- Liam / K'aeloree

Spellhold Studios, a Baldur's Gate II, Neverwinter Nights and Oblivion Modding Community

 
Malkin

Malkin

Manager


 visit Malkin's website: Malkin's page at CWiki
  4/24/2012

The thing with the dragonflies, though, is that they come in two sexes - a problem with the original dragonflies was that the sex balance was severely out of whack in game.

My TCR Norns
 
Geek2Nurse

Geek2Nurse


 visit Geek2Nurse's website: Adventures in Nornia
  4/24/2012

Ooh, thanks, Liam; that's much better.

Malkin, I didn't know about the sexes; guess I can challenge myself by figuring out how to reduce them evenly. Is there an ideal ratio of male to female other than 50:50? (I know nothing about dragonfly mating habits!)

Do other agents (birds, etc.) have sexes? I'm still trying to work out what the relationship is between the birds and their nests. I'm kind of stuck on the nest creation script in hummingbird.cos; it makes 7 nests of varying sizes in the same location with incrementing timer settings (1, 12, 23, etc.) and I haven't figured out yet what's really happening, or whether the nest is necessary to keep a population going.

Any enlightenment would be welcomed!


---
Optimist: the glass is half full.
Pessimist: the glass is half empty.
Engineer: the glass is twice as big as it needs to be.

 
Malkin

Malkin

Manager


 visit Malkin's website: Malkin's page at CWiki
  4/24/2012

50:50 might be good for a start. :) According to the CDN, OV06 might be a good place to start looking.

In Vamp's modified cos, hummingbirds collect grass, which they use to create the nest. Hatchling hummingbirds eat the nest before turning into juvenile hummingbirds, who flutter around, pollinate flowers (in the original, they EAT flowers), and grow up and become adults who build nests, etc. It seems logical to me that they have sexes too, but I can't remember off the top of my head.


My TCR Norns
 
Geek2Nurse

Geek2Nurse


 visit Geek2Nurse's website: Adventures in Nornia
  4/24/2012

See, I've wondered about that sort of stuff too. Like, the trout need dragonfly larvae to live, but I've never actually seen them EAT one. I know that would make the scripts all the more complicated, but not having the interactions be visible makes it hard for a newby to figure out the ecosystem. I suspected the hummingbirds needed flowers somehow, but had no idea which flowers, or how they know what's a flower, and they don't seem to gravitate to any in particular. I've also wondered, if I'm trying to get them started in a metaroom, do I need two, or is one enough, etc.

I wonder if the COB I'm looking at is Vamp's, or the original? I may just have not gotten far enough into it to discover the interactions with the nest, etc.

Yesterday I actually SAW the kingfisher catch a fish and carry it off. I was so excited! The complexity of this thing just keeps amazing me. ;)


---
Optimist: the glass is half full.
Pessimist: the glass is half empty.
Engineer: the glass is twice as big as it needs to be.

 
Liam

Liam


 visit Liam's website: Spellhold Studios
  4/24/2012

I haven't tested this, but if ov06 is the gender variable (you might want to check this), then something like this should work:

enum 2 2 222
doif ov06 eq 1
addv va02 1
endi
next

setv va00 totl 2 2 222
setv va03 va00
subv va03 va02
divv va02 2
divv va03 2

loop
rtar 2 2 222
doif va04 < va02
doif ov06 eq 1 and va04 < va02
addv va04 1
kill targ
endi
elif va05 < va03
doif ov06 eq 0 and va05 < va03
addv va05 1
kill targ
endi
endi
untl va04 ge va01 and va05 ge va01


This will work for any agent with a variable population of male/female objects, as long as you change ov06 to the proper variable.


- Liam / K'aeloree

Spellhold Studios, a Baldur's Gate II, Neverwinter Nights and Oblivion Modding Community

 
Moe

Moe


 visit Moe's website: Creatures 2 to Docking Station
  4/24/2012

This wouldn't work for dragonfly's, because apparently they have issues with their gender ratios, but for any other agent where you're reasonably sure that half are male and half are female at any given time, you could simply add a random, 50/50 variable roll to decide whether or not to kill the enum'd agent.

Enum X X X
setv va99 rand 0 1
doif va99 eq 0
kill targ
endi
next


In theory, the above code should randomly kill half of whatever you look for, male or female. Although it isn't selective, and might kill more or less of a particular gender, it isn't likely to eliminate all of either.

It lacks the elegance of Liam's method, but it is quick and dirty, and should be effective--theoretically, for agents with equal gender ratios.

 
Geek2Nurse

Geek2Nurse


 visit Geek2Nurse's website: Adventures in Nornia
  4/25/2012

You guys are awesome. This is the kind of thing I can really learn from. :)

Liam, is there a reason you used STAR rather than RTAR? I'm still a little shaky on what's owned by what, so I'm not sure. Also, I don't see where va01 is defined, so I'm a little lost, although overall I see what your script is doing -- basically killing half of each gender of the agent being reduced, right?

Moe, that's an interesting approach...maybe not as precise, but definitely less typing, if you're doing it using the in-game CAOS command line. I do aspire to learn to compile stuff and make agents, though!


---
Optimist: the glass is half full.
Pessimist: the glass is half empty.
Engineer: the glass is twice as big as it needs to be.

 
Liam

Liam


 visit Liam's website: Spellhold Studios
  4/25/2012

Whoops, fixed. Should make more sense now.

It should be RTAR rather than STAR, yep -- so used to working on actual objects that it's hard to disengage!

You should definitely download the CAOS tool, however, and use that rather than the command line. It really makes things a lot clearer, and colour codes/indents your code as well. It's awesome.


- Liam / K'aeloree

Spellhold Studios, a Baldur's Gate II, Neverwinter Nights and Oblivion Modding Community

 
Geek2Nurse

Geek2Nurse


 visit Geek2Nurse's website: Adventures in Nornia
  4/25/2012

I'm using the CAOS tool, but having a hard time figuring out how to debug with it. So far I haven't gotten anything to show up in the error/script output windows. :/ Are there instructions for using it anywhere? I was a coder back in the days before all these fancy windowed tools helped you figure out what you were doing wrong, so I'm kind of lost!

I've enlisted the help of my norns with the SEZZ command to see the contents of string variables, but it's not a very useful solution. ;)


---
Optimist: the glass is half full.
Pessimist: the glass is half empty.
Engineer: the glass is twice as big as it needs to be.

 
Ghosthande
Prodigal Sock

Ghosthande


 visit Ghosthande's website: Breeders Beware
  4/25/2012

With the CAOS Tool, you just click the New button and start typing in the window that comes up. The error output window updates itself every time you finish/leave a line, so if there's an error it should print there automatically.

You can also use OUTV and OUTS to figure out what things are, eg. "targ hots outv ov00" for a typical variable or "targ hots outs ov00" if it's a string. It will print the value right in the CAOS command line.



 
Geek2Nurse

Geek2Nurse


 visit Geek2Nurse's website: Adventures in Nornia
  4/25/2012

I'm not sure I'm getting it yet...I've got the part about creating code in the CAOS Tool. And I just realized that if the error window is open while I'm creating the code, I get feedback there (I was only looking at it after I injected...)

But I never get anything in the script output or viewer windows...I have to inject my script into the game to run it, right? There's no CAOS command line for it to print values in because I'm playing with the Magic Words Template* -- if I have a CAOS command line open, I can't type things in speech bubbles.

Am I missing the whole point somehow? ;)

* I thought I'd see if I could type something in a speech bubble like "kill half 2 13 1" and have it execute the "reduce population" script for that family/genus/species. Turns out string manipulation is a bit tedious. ;)


---
Optimist: the glass is half full.
Pessimist: the glass is half empty.
Engineer: the glass is twice as big as it needs to be.

 
Ghosthande
Prodigal Sock

Ghosthande


 visit Ghosthande's website: Breeders Beware
  4/25/2012

Yeah, the error window has to be open or it won't tell you anything. Like I said it updates real-time, although if you've created something with an error before opening that window, you can choose File -> Refresh Syntax and I believe that will make it print whatever it finds.

I've never even used the script output/viewer windows, so I don't know what they are actually supposed to do. Possibly they may make things easier, but I think it's safe to say you can still make do without.



 
Liam

Liam


 visit Liam's website: Spellhold Studios
  4/26/2012

They don't do anything, really.

I'd recommend using the DBG: commands in tandem with the CAOS Debugger which you can download from Gameware.


- Liam / K'aeloree

Spellhold Studios, a Baldur's Gate II, Neverwinter Nights and Oblivion Modding Community

 
Amaikokonut

Amaikokonut


 visit Amaikokonut's website: Naturing :: Nurturing
  4/26/2012

^ This. This so hard.
Once you learn how to use the debugger (and learn how to avoid crashing it) it will seriously be your best friend ever.


[Naturing :: Nurturing]
 
Geek2Nurse

Geek2Nurse


 visit Geek2Nurse's website: Adventures in Nornia
  4/26/2012

Got it. No crashes yet, despite VMWare Fusion and everything. I've got the most bizarre mixture of OSX and Windoze stuff scattered around my screen right now!

So my script is working...as far as it gets. It just kind of stops partway through. I've removed and reinjected it, and even changed the script number to try to start fresh. No matter what, the debug codes show up down to the part marked in the comments, and then nothing else happens. Well, the debugger monitor goes back to spitting out 7-digit numbers I don't know anything about, which feels like nothing, anyway.

Here's the code:

*Code based on Magic words BASIC TEMPLATE

new: simp 1 200 5000 "blank" 0 0 0

*magic_word_count -- the number of words/phrases addressed in this agent
setv name "magic_word_count" 1

*magic word variables will be named "magic_word_#"
sets name "magic_word_1" "_kill half"

*Help string
sets name "magic_word_help_1" "Kill half [F G S] -- Kills half the agents in the world that belong to the category specified by F (family) G (genus) S (species). Note: Only works on critters, bugs, plants, food."

*the core agent will trigger scrp 100# for the corresponding magic word
scrp 1 200 5000 1001
inst

*make sure the first 12 characters in the speech bubble are "kill half 2 "
sets va01 subs _p1_ 1 12
doif va01 ne "kill half 2 "
stop
endi

*find the total length of the input string
setv va02 strl _p1_

*subtract 12 to find the length of the genus-species portion of the classifier
subv va02 12

*set va03 to the classifier substring (gg ssss)
sets va03 subs _p1_ 13 va02

dbg: outs "va03=classifier substring (gg ssss)"
dbg: outs va03

*va20 is the genus identifier, as an integer
setv va20 stoi va03

dbg: outs "va20=genus"
dbg: outv va20

*va04 is the space character
sets va04 " "

*va05 is the location in va03 of the space (gg^ssss)
setv va05 sins va03 1 va04

dbg: outs "va05=location of first space"
dbg: outv va05

*increment va05 by 1, since we want to start with the character following the space
addv va05 1

dbg: outs "increment va05 by 1"
dbg: outv va05
dbg: outs "va02=length of genus-species substring"
dbg: outv va02

*****script is hanging up here. debug output just stops. :(

*now get the substring containing species
sets va06 subs va03 va05 va02

dbg: outs "va06=species substring"
dbg: outs va06

*and the length of the substring
setv va07 strl va06

dbg: outs "va07=length of va06"
dbg: outv va07

*va21 is the species identifier, as an integer
setv va21 stoi va06

dbg: outs "va21=species"
dbg: outv va21

*now we kill half the agents in the specified classification.
*(Will use working code for now, elegant alternatives once this much actually works.)

*va42 is the decision variable: 0=don't kill, 1=kill

* setv va42 0

* enum 2 va21 va22
* doif va42 ne 0
* kill targ
* setv va42 0
* else
* setv va42 1
* endi
* next
endm



*Remove script
rscr
enum 1 200 5000
kill targ
next


---
Optimist: the glass is half full.
Pessimist: the glass is half empty.
Engineer: the glass is twice as big as it needs to be.

 
Amaikokonut

Amaikokonut


 visit Amaikokonut's website: Naturing :: Nurturing
  4/26/2012

Ah, you'll just need to turn autokill off, heh.

When I run this script without autokill, I get a "Slice attempted outside string" error on the line where the script is hanging up (sets va06 subs va03 va05 va02), so that might be where you want to look.

Usually that means your subs count integer (va02 in this case) is larger than the string length (strl va03) minus the start integer (va05)

Maybe you mean to "subv va02 va05"? Adding that line just before "addv va05 1" seems to produce a result closer to what you're looking for. Does that help any?

Strings are a serious pain and I honestly hate working with them, but they have a lot of potential. I admire your ambition to stick with it!


[Naturing :: Nurturing]
 
Geek2Nurse

Geek2Nurse


 visit Geek2Nurse's website: Adventures in Nornia
  4/26/2012

Dangit, it's always so simple. Yup, I was thinking "substring from this position to this position," and it's supposed to be "from this position for this length." Thanks for catching that! And I don't think it ever would have occurred to me to turn off autokill. More thanks!

I think it's more stubbornness than ambition. I hate to let things get the best of me. ;)

Woohoo, it works, it works! #happydance

I am killing half of everything in sight right now. :-D

Next up: proportional population reduction by gender.


---
Optimist: the glass is half full.
Pessimist: the glass is half empty.
Engineer: the glass is twice as big as it needs to be.

 
Malkin

Malkin

Manager


 visit Malkin's website: Malkin's page at CWiki
  4/26/2012

Great work! :D I'm looking forward to seeing this in action! :)

My TCR Norns
 
Geek2Nurse

Geek2Nurse


 visit Geek2Nurse's website: Adventures in Nornia
  4/26/2012

Y'know, I think I've decided against proportional reductions, for now...killing every other one in the ENUM loop has a pretty good chance, statistically, of reducing the population while maintaining whatever the current ratio is, so I think I'm just gonna leave it the way it is, and see how it goes for a while.

Is this potentially useful enough for me to post for other people to use? I'm not even sure how that happens around here...guess I'll go look and see. :)


---
Optimist: the glass is half full.
Pessimist: the glass is half empty.
Engineer: the glass is twice as big as it needs to be.

 


downloads
cobs
adoptions
creaturelink
metarooms
breeds
 
gallery
art
wallpaper
screenshots
graphics
promos
sprites
dev
hack shack
script reservations
dev resources
active projects
dev forum
 
community
links
advice
chat
polls
resources
creatchi
 
forum
bookmarks
general
news
help
development
strangeo
survivor
mycaves
log in
register
lost pw
0 online
creatures caves is your #1 resource for the creatures artificial life game series: creatures, creatures 2, creatures 3, docking station, and the upcoming creatures family.

contact    help    privacy policy    terms & conditions    rules    donate    wiki