creatures caves
welcome, guest 

downloads   gallery   dev   community   creatchi   forum   mycaves
ccsf | links | advice | chat | polls | resources | post
 

  

Updating the Shee Pears   Development   Malkin | 10/10/2013  log in to like post

updated10/14/2013
Looking at the differences between a normal growing foodstuff and a Garden Box-compatible growing foodstuff.

This is looking at the differences between creating a 'growing' foodstuff for a fixed location in C3 or DS and creating a growing foodstuff for use with the Garden Box.

I'm pretending to update Bibble's Shee Pears from growing on the C3 apple tree to being Garden Box compatible.

If you're not familiar with the Shee Pears' behaviour: they grow on the C3 apple tree, they fall off, if left alone they vanish, but if eaten they create a pear core detritus which can itself vanish or be eaten.

Code from the original Shee Pears will be presented first, followed by code from the theoretical Garden Box Shee Pears.

To start with, an inivisible 'monitor' is created in the original Shee Pears, which will periodically count the amount of pears in the world and tell more to grow. In this script, it installs itself and the initial pears.


new: simp 1 1 48500 "blnk" 1 0 0
tick 3600
mvto 2160 100

inst
reps 10
new: simp 2 8 48500 "pear" 15 0 10
attr 64
bhvr 48
elas 30
accg 5
fric 100
tick rand 50 300
mvto rand 2160 2500 rand 100 320

setv ov61 25
repe


Now for the equivalent script in the GB, installing a 'flag agent' which can communicate with the main GB:

*The Flag Agent
new: simp 1 205 1000 "blnk" 0 0 0

*our spawn script will be 1000
setv name "spawn_script" 1000
*fully fruited plant sprite to appear next to the hand when you select the agent.
sets name "sprite_file" "pear"
setv name "sprite_pose" 13
*classifiers
setv name "prod_fmly" 2
setv name "prod_gnus" 8
setv name "prod_spcs" 1000

*now, tell the core that you're here
seta va00 targ
*target the core
enum 1 1 22929
mesg wrt+ targ 1000 va00 0 0
next


Note that the creation of the initial pears is handled by the Spawn Script (script 1000) in the Garden Box version.

Now for the monitor timer, which tells the tree to keep growing new pears.

scrp 1 1 48500 9
inst
setv va00 0
enum 2 8 48500
doif ov00 eq 0
addv va00 1
endi
next
doif va00 lt 5
new: simp 2 8 48500 "pear" 15 0 10
attr 64
bhvr 48
elas 30
accg 5
fric 100
tick rand 50 300
mvto rand 2160 2500 rand 100 320

setv ov61 25
endi
endm


Now for the Garden Box Spawn Script, which creates the initial pears and creates any further pears as well.

**The SPAWN script.
**_p1_ is the x and p2 is the y...
scrp 1 205 1000 1000
*We need to copy over a few vars now
setv va00 name "patch_id"
setv va01 name "tickfrom"
setv va02 name "tickto"
*We are going to classify this as fruit.
*Even the flower blossoms. It's just going to be invisible to creatures until
*it is full grown.
new: simp 2 8 1000 "pear" 15 0 name "patch_plane"
attr 80
*eat and pick up (but it's invisible now so it doesn't matter)
bhvr 48
elas 30
accg 5
fric 100
*these are pretty mandatory:
*carry over the patch id, otherwise it won't be counted and the plants will spawn FOREVER!
setv name "patch_id" va00
*and TICKS as set in the options panel.
tick rand va01 va02
*This is going to be a "default" tick in case people don't change the options.
doif tick eq 0
tick 200
endi
*And finally, mvto
mvto _p1_ _p2_
endm


Now for the pear pickup script, which makes it act more like a fruit.

scrp 2 8 48500 4
lock
doif ov00 eq 0
emit 6 0.5
setv ov00 1
endi
doif attr eq 67
attr 195
endi
perm 60
endm


And the Garden Box equivalent. Aside from comments and the species number, these two scripts are identical.

*This is the fruit pickup script
scrp 2 8 1000 4
lock
*if it hasn't been picked up before, a few things are going to change...
*like it starts actually acting like fruit~
doif ov00 eq 0
emit 6 0.5
setv ov00 1
endi
doif attr eq 67
attr 195
endi
perm 60
endm


Now for the pear pickup script, which ensures that it is always appears in a certain plane.

scrp 2 8 48500 6
doif carr eq null
plne 4000
endi
endm


And again, the Garden Box equivalent, which is again, functionally the same.

*pickup
scrp 2 8 1000 6
doif carr eq null
plne 4000
endi
endm


Now for the pear timer, which causes the flower to bloom, grow, turn into a pear and ripen, automatically create a new pear upon falling off the tree, and eventually rot and vanish.

scrp 2 8 48500 9

doif ov00 eq 0
doif carr eq null
doif pose lt 13
setv va00 pose
addv va00 1
pose va00
else
doif attr eq 64
attr 67
endi
addv ov99 1
endi

doif ov99 ge 20
setv ov99 0
doif attr eq 67
attr 195
endi
setv ov00 1

emit 6 0.01
*make a new pear upon falling off the tree
inst
new: simp 2 8 48500 "pear" 15 0 10

doif rand 1 4 eq 1
perm 60
endi
attr 64
bhvr 48
elas 30
fric 100
accg 5
tick rand 100 300
mvto rand 2160 2500 rand 100 320

setv ov61 25
targ ownr

endi
endi
endi
*if you've fallen off the tree and you're old, rot and die.
doif ov00 eq 1
addv ov99 1
doif ov99 ge 50
doif carr eq null
altr room targ 4 0.01
altr room targ 3 0.01
kill ownr
endi
endi
endi
endm


Now for the GB version. Key differences are that it doesn't automatically respawn a new pear upon falling off the tree (the spawn script handles that), and that it tells the main garden box that it is falling off the tree by using the named patch variable patch_id.

*And the timer:
scrp 2 8 1000 9
doif ov00 eq 0
doif carr eq null
doif pose lt 13
setv va00 pose
addv va00 1
pose va00
else
*changed from 64 to 80
doif attr eq 80
*this is the turning point at which it becomes edible~
attr 67
endi
addv ov99 1
endi

doif ov99 ge 20
setv ov99 0
doif attr eq 67
attr 195
endi
setv ov00 1

emit 6 0.01
endi
endi
endi
*if ov00 is 1, it's been picked or fallen, and thus stops growing and starts rotting.
doif ov00 eq 1
*We're going to set its patch id to 0 now.. this detaches it from the patch itself
*So that it doesn't count toward the number that can grow on the bush
setv name "patch_id" 0

addv ov99 1
doif ov99 ge 50
doif carr eq null and room targ <> -1
altr room targ 4 0.01
altr room targ 3 0.01
kill ownr
endi
endi
endi
endm


Now for the important part - the eat script of the original pears.

scrp 2 8 48500 12

setv va00 posl
setv va01 post

stim writ from 78 1


wait 10
snde "eat1"
inst
new: simp 2 10 48500 "pear" 1 14 20
*if the test move fails for any reason, stop making the detritus
doif tmvt va00 va01 ne 1
kill targ
stop
endi

attr 195
bhvr 48
elas 0
accg 5
fric 100
mvto va00 va01

setv ov61 10
tick 1200
kill ownr
endm


And the Garden Box version - again, functionally the same.

*eat script!
scrp 2 8 1000 12

setv va00 posl
setv va01 post

stim writ from 78 1


wait 10
snde "eat1"
*This creates a pear core.
inst
new: simp 2 10 1000 "pear" 1 14 20

doif tmvt va00 va01 ne 1
kill targ
stop
endi

attr 195
bhvr 48
elas 0
accg 5
fric 100
mvto va00 va01

setv ov61 10
tick 1200
kill ownr
endm



Now the original pear detritus has its own timer script so that it can decay if left in peace.

scrp 2 10 48500 9
doif room targ <> -1 and carr = null
altr room targ 4 0.01
altr room targ 3 0.01
kill targ
elif room targ = -1 and carr = null
kill ownr
endi
endm


And now for the GB version, which is functionally exactly the same:

*core rot script
scrp 2 10 1000 9
doif room targ <> -1 and carr = null
altr room targ 4 0.01
altr room targ 3 0.01
kill targ
elif room targ = -1 and carr = null
kill ownr
endi
endm


The original pears can be eaten and provide the appropriate stimulus, so that ants can survive and toxics can have a treat.

scrp 2 10 48500 12

stim writ from 81 1

wait 1
kill ownr
endm


Now for the GB version, which is the same:

*detritus eat script, just in case.
scrp 2 10 1000 12

stim writ from 81 1

wait 1
kill ownr
endm


Now to remove the original pears:

rscr
enum 2 8 48500
kill targ
next
scrx 2 8 48500 9
scrx 2 8 48500 12



Now to remove the Garden Box equivalent:

rscr
enum 1 205 1000
kill targ
next
enum 2 10 1000
kill targ
next
enum 2 8 1000
kill targ
next


You can see that it is very similar to making a normal growing foodstuff, but that some aspects are handled differently - the individual agent delegates some responsibility (placement, density, when to spawn more etc.) to the main Garden Box.

In return for that reduced responsibility, the agent has to use the named variables, such as patch_id to let the main Garden Box know what it's thinking of doing.

Following on from this, if the agent can be plucked, it's necessary that a Garden Box compatible agent has a 'pickup script' so that the Garden Box can keep tabs on how many items there are in the world.

Once more with feeling, here's the whole code for the theoretical Garden Box version of Bibble's Shee Pears:

*The Flag Agent
new: simp 1 205 1000 "blnk" 0 0 0

*our spawn script will be 1000
setv name "spawn_script" 1000
*fully fruited plant sprite to appear next to the hand when you select the agent.
sets name "sprite_file" "pear"
setv name "sprite_pose" 13
*classifiers
setv name "prod_fmly" 2
setv name "prod_gnus" 8
setv name "prod_spcs" 1000

*now, tell the core that you're here
seta va00 targ
*target the core
enum 1 1 22929
mesg wrt+ targ 1000 va00 0 0
next

**The SPAWN script.
**_p1_ is the x and p2 is the y...
scrp 1 205 1000 1000
*We need to copy over a few vars now
setv va00 name "patch_id"
setv va01 name "tickfrom"
setv va02 name "tickto"
*We are going to classify this as fruit.
*Even the flower blossoms. It's just going to be invisible to creatures until
*it is full grown.
new: simp 2 8 1000 "pear" 15 0 name "patch_plane"
attr 80
*eat and pick up (but it's invisible now so it doesn't matter)
bhvr 48
elas 30
accg 5
fric 100
*these are pretty mandatory:
*carry over the patch id, otherwise it won't be counted and the plants will spawn FOREVER!
setv name "patch_id" va00
*and TICKS as set in the options panel.
tick rand va01 va02
*This is going to be a "default" tick in case people don't change the options.
doif tick eq 0
tick 200
endi
*And finally, mvto
mvto _p1_ _p2_
endm

*This is the fruit pickup script
scrp 2 8 1000 4
lock
*if it hasn't been picked up before, a few things are going to change...
*like it starts actually acting like fruit~
doif ov00 eq 0
emit 6 0.5
setv ov00 1
endi
doif attr eq 67
attr 195
endi
perm 60
endm

*pickup
scrp 2 8 1000 6
doif carr eq null
plne 4000
endi
endm

*And the timer....
scrp 2 8 1000 9
doif ov00 eq 0
doif carr eq null
doif pose lt 13
setv va00 pose
addv va00 1
pose va00
else
*changed from 64 to 80
doif attr eq 80
*this is the turning point at which it becomes edible~
attr 67
endi
addv ov99 1
endi

doif ov99 ge 20
setv ov99 0
doif attr eq 67
attr 195
endi
setv ov00 1

emit 6 0.01
endi
endi
endi
*if ov00 is 1, it's been picked or fallen, and thus stops growing and starts rotting.
doif ov00 eq 1
*We're going to set its patch id to 0 now.. this detaches it from the patch itself
*So that it doesn't count toward the number that can grow on the bush
setv name "patch_id" 0

addv ov99 1
doif ov99 ge 50
doif carr eq null and room targ <> -1
altr room targ 4 0.01
altr room targ 3 0.01
kill ownr
endi
endi
endi
endm

*eat script!
scrp 2 8 1000 12

setv va00 posl
setv va01 post

stim writ from 78 1

wait 10
snde "eat1"
*This creates a pear core.
inst
new: simp 2 10 1000 "pear" 1 14 20

doif tmvt va00 va01 ne 1
kill targ
stop
endi

attr 195
bhvr 48
elas 0
accg 5
fric 100
mvto va00 va01

setv ov61 10
tick 1200
kill ownr
endm

*core rot script
scrp 2 10 1000 9
doif room targ <> -1 and carr = null
altr room targ 4 0.01
altr room targ 3 0.01
kill targ
elif room targ = -1 and carr = null
kill ownr
endi
endm

*detritus eat script, just in case.
scrp 2 10 1000 12

stim writ from 81 1

wait 1
kill ownr
endm

rscr
enum 1 205 1000
kill targ
next
enum 2 10 1000
kill targ
next
enum 2 8 1000
kill targ
next


Happy Garden Boxing!

 


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
3 online
Mioonktoo
Floh
Pilla
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