C2 Crabs for C3/DS (teardown)
C2 Crabs for C3/DS | ||
---|---|---|
This article is a teardown of an existing CAOS script. | ||
Game Version | Docking Station | |
Filename(s) | C2 Crabs.agents | |
Classifier | 2 23 4071, 2 18 4071, 2 15 4071 | |
Dependencies | ||
Images | ASC2crab.c16 | |
Sounds | ascr.wav, chwp.wav | |
Catalogue Tags | C2crabs.catalogue | |
Agents | C2 Crabs.agents | |
Other | none |
This is a teardown page explaining the details and inner workings of this agent. For general information, see C2 Crabs for C3/DS
C2 Crabs is a simple critter agent made for Docking Station by AquaShee. OV00 is used as an age timer, and OV01 is used to remember 'genetic traits' that can be inherited by crabs. OV02 is a flag used to determine whether the crab is adult or juvenile.
Contents
Scripts[edit]
Launcher Inject[edit]
- A new simple vendor is created
- Tries to install at the DS creator machine or if that doesn't exist, injects to a C3 location.
*create the launcher. easy *Version 0.99 new: simp 2 23 4071 "ASC2crab" 10 34 500 attr 199 bhvr 33 elas 5 fric 100 accg 3 aero 0 setv va00 game "CreatorX" setv va01 game "CreatorY" doif va00 eq 0 and va01 eq 0 setv va00 5687 setv va01 3670 endi mvsf va00 va01
Launcher push[edit]
- Vendor LOCKs to prevent more pushes, and randomly makes between 2 to 5 crab eggs.
- In the crab eggs, OV01 is used with principles of genetic objects to control how many hatchlings emerge from the eggs.
scrp 2 23 4071 1 ** push script. Animate, vend eggs and make noise. lock snde "ascr" setv va00 rand 2 5 reps va00 targ ownr anim [1 2 3 4 5 6 7 8 9] over inst setv va01 posl setv va02 post addv va01 20 subv va02 10 new: simp 2 18 4071 "ASC2crab" 1 45 rand 501 801 attr 195 bhvr 48 accg 1 fric 100 ** age timer setv ov00 0 ** genetics! Defines the number of hatchlings and will be passed on setv ov01 rand 1 3 elas 0 doif tmvt va01 va02 eq 1 mvto va01 va02 velo rand 5 -5 -5 tick rand 300 250 else kill targ endi slow repe targ ownr targ ownr anim [1 2 3 4 5 6 7 8 9] over pose 0 unlk endm
Egg eat script[edit]
scrp 2 18 4071 12 snde "chwp" stim writ from 80 0.2 kill ownr endm
Egg timer script[edit]
- If the eggs are in fresh or salt water, they will try to hatch using the subroutine hatch
scrp 2 18 4071 9 doif rtyp room ownr eq 9 or rtyp room ownr eq 8 gsub hatch elif ov00 gt 3 kill ownr else addv ov00 1 setv vely -1 endi
- In the hatch subroutine:
- According to the genetics factor for the eggs, ov01, the amount of hatchlings are determined.
- Simple critters are in the process of being created.
- MV01 is used to transfer the eggs' OV01 genetics factor for hatchlings to the crabs themselves.
- Then a random mutation factor is added onto that.
- According to the genetics factor for the eggs, ov01, the amount of hatchlings are determined.
subr hatch reps ov01 targ ownr setv va00 posl setv va01 post new: simp 2 15 4071 "ASC2crab" 34 0 rand 600 1000 attr 195 rnge 200 bhvr 48 elas 5 accg 3 fric 80 ** pass the salt...err, genes! setv ov01 mv01 doif rand 1 20 eq 1 doif rand 1 0 eq 1 addv ov01 -1 elif ov01 lt 10 addv ov01 1 endi endi
- Still in the 'hatch' subroutine, OV00, the age timer, is set to 100, then multiplied by OV01, the genetic factor, and 100 is then added on to the age timer. The age timer will count down through the crab's life.
- The PERM is set
- A test move is performed, and
- The TICK is set to 1.
** This is the age timer. It counts down and is based upon the genetics setv ov00 100 mulv ov00 ov01 addv ov00 100 perm 90 doif tmvt va00 va01 eq 1 mvto va00 va01 else kill targ endi tick 1
- The REPS-REPE loop is closed
- The egg item itself is killed.
- The 'hatch' subroutine is ended with RETN
- The egg timer script is ended with ENDM.
repe kill ownr retn endm
Critter eat script[edit]
- If OV02 is less than 1, play a sound, stimulate whatever triggered the eat script with 'I have eaten animal' at a strength of 0.2, and delete the crab.
- If OV02 is not less than 1, stimulate whatever triggered the eat script with 'I have played with a dangerous animal' at a strength of 0.2, and stimulate it with 'reached peak of flower scent' at no given strength.
- Force whatever's holding the crab to drop it.
scrp 2 15 4071 12 doif ov02 lt 1 snde "chwp" stim writ from 80 0.2 kill ownr else stim writ from 88 0.2 mesg writ from 64 targ from drop endi endm
Critter timer script[edit]
scrp 2 15 4071 9 ** Yay! Cute crabby scripty ** first, check our age doif ov00 le 0 and ov02 lt 1 ** let's get adulting! gsub grow elif ov00 le 0 and ov02 ge 1 ** lay eggs and die gsub lay endi ** now, let's grab a bite! gsub eat ** great, good job! Now let's test our location doif rtyp room ownr ne 8 and rtyp room ownr ne 9 ** uh-oh, no water! gsub land else ** Sweet, salt waterness! gsub move endi subv ov00 1
- In the grow subroutine, the ATTR is set to 0, then the BASE is set to 17, effectively skipping the young crab sprites.
- The POSE is set to 0 which recalculates the bounding box and the (larger, adult) crab is moved safely to the top left and the top right of the bounding box. If this step was left out, a bounding box error would occur.
- The ATTR is re-set to 195 (carryable, mouseable, suffer collisions and physics)
- CATO is used to make the adults beasts.
- OV00, the age timer, is randomly set from 300 to 350
- OV02, the juvenile/adult flag, is set to 1.
subr grow attr 0 base 17 pose 0 mvsf posl post attr 195 cato 16 setv ov00 rand 300 350 setv ov02 1 retn
- In the lay subroutine, the adult crabs lay a clump of eggs.
- Firstly, the crab decides where to create the egg clump from. See Making a Vendor for C3 for a fuller discussion of this.
- Two temporary variables are set to the top left and top of the bounding box.
- These two points are added to by 20 pixels (the top left coordinate, drawing the final spot further to the right) and subtracted to by 10 pixels (the topmost coordinate, the subtraction will draw the creation point down from the topmost location).
- A new egg clump is created.
- The genetics factor for the egg clump, ov01, is set, using the adult crab's genetics factor (MV01), determining the amount of hatchlings.
- The egg clump is test-moved to its eventual location, and given velocity and a tick.
- After the egg clump has been laid, the adult crab takes a dead pose and waits between 15 and 30 seconds before the adult crab is removed.
subr lay setv va01 posl setv va02 post addv va01 20 subv va02 10 new: simp 2 18 4071 "ASC2crab" 1 45 rand 501 801 attr 195 bhvr 0 accg 1 fric 100 ** age timer setv ov00 0 ** genetics! Defines the number of hatchlings and will be passed on setv ov01 mv01 elas 0 doif tmvt va01 va02 eq 1 mvto va01 va02 velo rand 2 -2 -5 tick rand 300 250 else kill targ endi targ ownr pose 16 wait rand 300 600 kill ownr retn
- If the crab is on land, they can use two methods with temporary variables to find their way back to water:
- by using GRID to look at the smell properties in the rooms to the left or right of the crab
- or by using HIRP or LORP to smell which rooms have the highest (HIRP) or lowest (LORP) concentration of water smell
- Once the crab has determined which way the water smell is, it sets a third temporary variable to either -5 or 5.
subr land ** Oh no! We are not in water! Crabs can take their time to make it back, but eggs won't hatch. ** The following lines of code get the id's of the neighbouring rooms and the numbers of the rooms ** with the highest and lowest water smell. By comparing these, the critter knows which way the water is, ** even if it can't see one of the rooms. setv va00 grid ownr left setv va01 grid ownr rght setv va02 hirp room ownr 5 0 setv va04 lorp room ownr 5 0 doif va00 eq va02 or va01 eq va04 setv va03 -5 elif va01 eq va02 or va00 eq va04 setv va03 5
- If the crab can't smell any water, it sets the third temporary variable to either 5 or -5.
else doif rand 0 1 eq 1 setv va03 5 else setv va03 -5 endi endi
- Gives velocity in the va03 direction, with a random up value of -3 to -5, letting the crab hop to the left (-5) or right (5).
- If the crab is moving left, use a particular set of animations, or if the crab is moving right, use almost the same animations but in reverse order.
- When the animation is over, loop the animation, and then wait 3 to 5 ticks, until the crab stops falling.
- Return to the main flow of the script, the 'I'm on land!' subroutine is over.
velo va03 rand -3 -5 doif va03 lt 0 anim [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15] else anim [15 14 13 12 11 10 9 8 7 6 5 4 3 2 1] endi over loop wait rand 3 5 untl fall eq 0 retn
subr move doif rand 0 60 eq 3 setv va00 ov02 mulv va00 -5 addv va00 -20 else setv va00 rand -3 -5 endi doif rand 0 5 eq 5 doif rand 1 0 eq 1 setv ov03 5 else setv ov03 -5 endi endi velo ov03 va00 doif ov03 lt 0 anim [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15] else anim [15 14 13 12 11 10 9 8 7 6 5 4 3 2 1] endi over loop wait rand 3 5 untl fall eq 0 retn
subr eat ** eating isn't required, but will maintain the population and clean up rubbish doif ov02 ge 1 setv va00 0 targ ownr esee fmly gnus spcs doif targ ne null and targ ne ownr doif ov02 lt 1 addv va00 1 endi endi next targ ownr doif va00 gt 5 inst seta va05 null etch fmly gnus spcs doif targ ne null and targ ne ownr doif ov02 lt 1 seta va05 targ endi endi next targ ownr doif va05 ne null kill va05 targ ownr snde "chwp" endi endi endi doif rand 0 1 eq 1 inst seta va05 null etch 0 10 0 seta va05 targ next doif va05 ne null kill va05 snde "chwp" endi endi retn endm
Critter exception script[edit]
An exception script can be thought of as an 'emergency stop' script, it specifies the exception handling behaviour when an agent tries to do something to an invalid agent. For example, if you try and access an OWNR, you get a run time error. If the exception script is present, that script is called and you can reset variables as necessary. In the Crabs, the exception script just sets the TICK to 1, effectively rebooting the crabs' timer script to try again.
scrp 2 15 4071 255 tick 1 endm
Removal script[edit]
Counts all vendors and removes them, then counts all eggs and removes them, then counts all crabs and removes them. The scripts are not deleted.
rscr enum 2 23 4071 kill targ next enum 2 18 4071 kill targ next enum 2 15 4071 kill targ next
Notes[edit]
- For greater compatibility with the Creatures Development Standards, the vendor should have a pull and a hit script too, and all three should use the appropriate stimuli.
- For greater compatibility with the Creatures Development Standards, the crab critter should have a push, pull and hit script, and all three should use the appropriate stimuli.
- For greater compatibility with the Creatures Development Standards, the crab critter's TICK should be higher than 1. Typical C3/DS values for critters range from between 8 ticks and 30 ticks or so.
Code[edit]
*create the launcher. easy *Version 0.99 new: simp 2 23 4071 "ASC2crab" 10 34 500 attr 199 bhvr 33 elas 5 fric 100 accg 3 aero 0 setv va00 game "CreatorX" setv va01 game "CreatorY" doif va00 eq 0 and va01 eq 0 setv va00 5687 setv va01 3670 endi mvsf va00 va01 scrp 2 23 4071 1 ** push script. Animate, vend eggs and make noise. lock snde "ascr" setv va00 rand 2 5 reps va00 targ ownr anim [1 2 3 4 5 6 7 8 9] over inst setv va01 posl setv va02 post addv va01 20 subv va02 10 new: simp 2 18 4071 "ASC2crab" 1 45 rand 501 801 attr 195 bhvr 48 accg 1 fric 100 ** age timer setv ov00 0 ** genetics! Defines the number of hatchlings and will be passed on setv ov01 rand 1 3 elas 0 doif tmvt va01 va02 eq 1 mvto va01 va02 velo rand 5 -5 -5 tick rand 300 250 else kill targ endi slow repe targ ownr targ ownr anim [1 2 3 4 5 6 7 8 9] over pose 0 unlk endm scrp 2 18 4071 12 snde "chwp" stim writ from 80 0.2 kill ownr endm scrp 2 18 4071 9 doif rtyp room ownr eq 9 or rtyp room ownr eq 8 gsub hatch elif ov00 gt 3 kill ownr else addv ov00 1 setv vely -1 endi subr hatch reps ov01 targ ownr setv va00 posl setv va01 post new: simp 2 15 4071 "ASC2crab" 34 0 rand 600 1000 attr 195 rnge 200 bhvr 48 elas 5 accg 3 fric 80 ** pass the salt...err, genes! setv ov01 mv01 doif rand 1 20 eq 1 doif rand 1 0 eq 1 addv ov01 -1 elif ov01 lt 10 addv ov01 1 endi endi ** This is the age timer. It counts down and is based upon the genetics setv ov00 100 mulv ov00 ov01 addv ov00 100 perm 90 doif tmvt va00 va01 eq 1 mvto va00 va01 else kill targ endi tick 1 repe kill ownr retn endm scrp 2 15 4071 12 doif ov02 lt 1 snde "chwp" stim writ from 80 0.2 kill ownr else stim writ from 88 0.2 mesg writ from 64 targ from drop endi endm scrp 2 15 4071 9 ** Yay! Cute crabby scripty ** first, check our age doif ov00 le 0 and ov02 lt 1 ** let's get adulting! gsub grow elif ov00 le 0 and ov02 ge 1 ** lay eggs and die gsub lay endi ** now, let's grab a bite! gsub eat ** great, good job! Now let's test our location doif rtyp room ownr ne 8 and rtyp room ownr ne 9 ** uh-oh, no water! gsub land else ** Sweet, salt waterness! gsub move endi subv ov00 1 subr grow attr 0 base 17 pose 0 mvsf posl post attr 195 cato 16 setv ov00 rand 300 350 setv ov02 1 retn subr lay setv va01 posl setv va02 post addv va01 20 subv va02 10 new: simp 2 18 4071 "ASC2crab" 1 45 rand 501 801 attr 195 bhvr 0 accg 1 fric 100 ** age timer setv ov00 0 ** genetics! Defines the number of hatchlings and will be passed on setv ov01 mv01 elas 0 doif tmvt va01 va02 eq 1 mvto va01 va02 velo rand 2 -2 -5 tick rand 300 250 else kill targ endi targ ownr pose 16 wait rand 300 600 kill ownr retn subr land ** Oh no! We are not in water! Crabs can take their time to make it back, but eggs won't hatch. ** The following lines of code get the id's of the neighbouring rooms and the numbers of the rooms ** with the highest and lowest water smell. By comparing these, the critter knows which way the water is, ** even if it can't see one of the rooms. setv va00 grid ownr left setv va01 grid ownr rght setv va02 hirp room ownr 5 0 setv va04 lorp room ownr 5 0 doif va00 eq va02 or va01 eq va04 setv va03 -5 elif va01 eq va02 or va00 eq va04 setv va03 5 else doif rand 0 1 eq 1 setv va03 5 else setv va03 -5 endi endi velo va03 rand -3 -5 doif va03 lt 0 anim [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15] else anim [15 14 13 12 11 10 9 8 7 6 5 4 3 2 1] endi over loop wait rand 3 5 untl fall eq 0 retn subr move doif rand 0 60 eq 3 setv va00 ov02 mulv va00 -5 addv va00 -20 else setv va00 rand -3 -5 endi doif rand 0 5 eq 5 doif rand 1 0 eq 1 setv ov03 5 else setv ov03 -5 endi endi velo ov03 va00 doif ov03 lt 0 anim [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15] else anim [15 14 13 12 11 10 9 8 7 6 5 4 3 2 1] endi over loop wait rand 3 5 untl fall eq 0 retn subr eat ** eating isn't required, but will maintain the population and clean up rubbish doif ov02 ge 1 setv va00 0 targ ownr esee fmly gnus spcs doif targ ne null and targ ne ownr doif ov02 lt 1 addv va00 1 endi endi next targ ownr doif va00 gt 5 inst seta va05 null etch fmly gnus spcs doif targ ne null and targ ne ownr doif ov02 lt 1 seta va05 targ endi endi next targ ownr doif va05 ne null kill va05 targ ownr snde "chwp" endi endi endi doif rand 0 1 eq 1 inst seta va05 null etch 0 10 0 seta va05 targ next doif va05 ne null kill va05 snde "chwp" endi endi retn endm scrp 2 15 4071 255 tick 1 endm rscr enum 2 23 4071 kill targ next enum 2 18 4071 kill targ next enum 2 15 4071 kill targ next