Guide to writing Patch Plants

Development guides, discussion, and testing for Garden Box compatible agents.

Guide to writing Patch Plants

Postby Amaikokonut » Wed Aug 01, 2012 9:22 pm

Herein lies the very-detailed annotated cosfile for the chillies patch plant! You should be able to use this as a template for your own patch plants, or just get a general idea of what it entails:

Code: Select all
**How to make a Patch Plant
**Using the Chili Pepper Plant as an example

**The first thing you need to do is make an invisible flag agent
**This agent is classified as 1 205 X, and stores information about your patch plant.
**This means a lot of NAME variables.

new: simp 1 205 22935 "blnk" 0 0 9000

*The first thing you're going to do is define the number of your spawn script
*This is the script that the patch core will trigger when it's time to spawn a fruit/bud/whatever.
*I'm going to use script 1000 for this... we'll get more into it later.

setv name "spawn_script" 1000

*Now you have to define the file name and image number of the sprite that will represent your plant
*when it is fully grown. This will be used both in placing a fruit/bud and serving as the little
*indicator that shows on the hand when you're placing the patch.

sets name "sprite_file" "chilli"
setv name "sprite_pose" 11

*finally, you need to define the classifiers for your produce

setv name "prod_fmly" 2
setv name "prod_gnus" 8
setv name "prod_spcs" 22935

*now personally, I like to define my blossoms as "fruit" all the way through the growing process,
*and just keep them invisible to creatures until they are fully grown. You might chose to do it
*differently and define them as flowers that later are killed and replaced with fruits. However
*you choose to do it is up to you-- but the only agents that are going to be considered part
*of your patch are those with those classifiers as defined above. Thus, once your flower is killed
*and replaced with a fruit, the patch won't recognize it anymore-- so you'll have have to do some
*more creative coding if you want to do it that way.

*Now that you have everything defined, you need to contact the patch core agent (1 1 22929) and let
*it know that you're here-- the patch scripts will take it from there and generate the
*placement windows, let the user choose options, and so on.

seta va00 targ
enum 1 1 22929
   mesg wrt+ targ 1000 va00 0 0
next

**That's it for your install script!

*Now for your spawn script-- this is 1000 as we defined it in the install script.

scrp 1 205 22935 1000
   inst

*If this script is running, it's because the patch core decided it was time for your
*patch to spawn a new bud. It has also sent the coordinates it has decided were proper in
*_p1_ (x) and _p2_ (y). It has also stored the plane set by the patch options in the NAME
*"patch_plane" variable.

*So first, create your little fruit to be:

   new: simp 2 8 22935 "chilli" 14 1 name "patch_plane"

*again, I like to keep my blossoms invisible to creatures so they don't
*try to eat them while they're still flowers. You also obviously don't want them to suffer
*physics just yet.

   attr 80
   bhvr 48
   accg 2
   perm 64
   fric 100
   elas 30
   aero 2

*And move it to the coords sent by the patch agent:

   mvto _p1_ _p2_

*Now, a few new name variables have been defined in your patch flag agent since you last
*left it-- these are settings that have been defined in the options window as well as a
*unique patch ID number that has been generated. You'll need to copy these over to your
*your budding fruit!

*The patch ID is important-- if you don't copy it over, the patch plant won't realize that
*the fruit is there, and it will spawn another one, and continue spawning FOREVER.

   setv name "patch_id" mame "patch_id"

*then there's the ticks as set in the options panel:

   tick rand mame "tickfrom" mame "tickto"

*personally I like to define a default tick too, in case something goes wrong and the tick ends
*up as 0.

   doif tick eq 0
      tick 200
   endi
endm

*And that is just about it.

*From here you pretty much script it like you would any other blossoming plant-- give it a timer
*script to grow, ripen, become visible and so on. Of course, don't forget eat scripts,
*collision scripts, etc.

*Keep in mind: when your plant is picked (or falls off the patch if you decide to code it like that)
*aside from making it suffer physics, you'll also have to decide if you want to clear the
*patch_id variable. If you clear it, it will no longer count toward the total number of
*fruits growing on the patch, and a new one will spawn to take its place. If you don't clear
*it, the script will keep counting it and until that fruit is eaten or otherwise disappears,
*a new fruit won't spawn. If you haven't scripted your fruits to eventually decay, you may
*wish to keep the patch_id variable intact so you don't have a patch that keeps spawning
*endless numbers of fruits that pile up and slow down the game.

*Another thing you might consider doing is setting the tick to something static after the fruit
*falls off the patch, so that the growth rate set by the user does not affect the decay rate of
*the fruit. Personally, I choose not to do this, but it is an option to consider.

*This is my timer script:

scrp 2 8 22935 9

*if it's not fully grown, grow it to the next stage

   doif pose lt 10
      setv va00 pose
      addv va00 1
      pose va00
      stop
   endi

*if it is fully grown, add to its timer (ov00), and make sure creatures can see/grab it.

   doif ov00 lt 10
      addv ov00 1
      doif attr = 80
         attr 67

*also make it start smelling like a fruit

         emit 6 0.01
      endi
      stop
   endi

*if it's fully grown and has been sitting on the plant for 10 turns,
*it should fall off the patch

   doif attr = 67
      attr 195
      pose 11

*I'm going to chose to clear the patch_id variable so a new one can spawn where it fell.

      setv name "patch_id" 0

*and if it's fully grown and already on the ground, it should add to its decay timer (ov01)

   elif attr = 195
      doif ov01 lt 10
         addv ov01 1
      else

*but if its been laying on the floor for 10 turns, go ahead and call it rotten.
*I'm going to be lazy and just kill targ, but if you have proper sprites prepared,
*turning it into detritus can benefit your ecosystem if you've got bugs and critters that eat it.

         kill targ
      endi
   endi
endm

*here's the collision script-- in this case if it's hitting the floor for the first time
*it changes the sprite.

scrp 2 8 22935 6
   lock
   snde "smit"
   doif ov02 = 0
      pose rand 12 13
      setv ov02 1
   endi
endm

*This is the pickup script

scrp 2 8 22935 4
   inst

*if it's attr is still 67, you (or a creature) are picking it directly off the plant
*and need to set it so it doesn't act attached to the patch anymore

   doif attr = 67
      attr 195
      pose 11

*Again, I'm going to chose to clear the patch_id variable so a new one can spawn.

      setv name "patch_id" 0
   endi
endm

*Finally, the eat script. Nom.

scrp 2 8 22935 12
   inst
   snde "leat"
   stim writ from 78 1

*going to add hotness and vitamin C to mimic the hardman chilis.

   doif from ne null
      targ from
      chem 153 .15
      chem 99 .35
   endi

*Again, I'm just killing it here, but no reason you can create a fruit with multiple bites, or
*something that turns into detritus after it's eaten.

   kill ownr
endm

rscr
enum 1 205 22935
   kill targ
next
enum 2 8 22935
   kill targ
next


Feel free to post any questions you have in this thread! I will do my best to keep it updated with clarifications to make the development process as easy as possible.
Amaikokonut
Site Admin
 
Posts: 171
Joined: Wed Feb 08, 2012 3:34 pm

Re: Guide to writing Patch Plants

Postby malkin » Fri Aug 10, 2012 4:13 pm

Is making a 'ground' patch plant (mushrooms, carrots... grass?) significantly different from making a 'wall' patch plant?
malkin
 
Posts: 131
Joined: Sat Feb 11, 2012 3:55 am

Re: Guide to writing Patch Plants

Postby Amaikokonut » Fri Aug 10, 2012 10:13 pm

Not really; I think the only thing to be aware of is that you need to give the plants physics from the start, and you might want to make your first "stage" of growth an invisible or very tiny sprite if you don't want them to be plainly visible since they still spawn in the patch box and then fall to the ground.

Ground patches were one of those things that weren't really intended from the start, but ended up being a nice use for the existing framework anyway!
Amaikokonut
Site Admin
 
Posts: 171
Joined: Wed Feb 08, 2012 3:34 pm

Re: Guide to writing Patch Plants

Postby AquaShee » Sun Aug 12, 2012 6:34 am

A solution for the flower/fruit problem would be keeping the flower hidden behind the fruit until the fruit drops. This way butterflies, hummingbirds and other flower-loving critters get to enjoy the tasty, tasty blossoms properly.
AquaShee
 
Posts: 3
Joined: Sun Aug 12, 2012 6:24 am

Re: Guide to writing Patch Plants

Postby malkin » Mon Jan 21, 2013 1:11 am

Amai, I might need more hand-holding with thinking about ground patch plants' first stage of being. :oops: I've been reading the scripts for the carrot and mushroom, and I'm just having some trouble thinking my way through them.

Carrot:
Code: Select all
new: simp 1 205 22939 "blnk" 0 0 9000
setv name "spawn_script" 1000
sets name "sprite_file" "carr"
setv name "sprite_pose" 1

setv name "prod_fmly" 2
setv name "prod_gnus" 11
setv name "prod_spcs" 22939

seta va00 targ
enum 1 1 22929
   mesg wrt+ targ 1000 va00 0 0
next

scrp 1 205 22939 1000
   inst
*first it's going to be an invisible seed
   new: simp 2 11 22939 "carr" 19 0 201
   pose 18
   attr 208
   bhvr 48
   perm 100
   accg 4
   aero 3
   elas 20
   fric 100
   mvto _p1_ _p2_
   setv name "patch_id" mame "patch_id"
   tick rand mame "tickfrom" mame "tickto"
*facing is determined at birth
   setv va00 rand 0 1
   doif va00 = 0
      sets name "direction" "left"
   elif va00 = 1
      sets name "direction" "right"
   endi
**
   doif tick eq 0
      tick 200
   endi
endm


Mushroom:
Code: Select all
new: simp 1 205 22940 "blnk" 0 0 9000
setv name "spawn_script" 1000
sets name "sprite_file" "fungi"
setv name "sprite_pose" 8

setv name "prod_fmly" 2
setv name "prod_gnus" 8
setv name "prod_spcs" 22940

seta va00 targ
enum 1 1 22929
   mesg wrt+ targ 1000 va00 0 0
next

*spawn
scrp 1 205 22940 1000
   inst
*invisibleish spawnling
   setv va99 rand 0 4
   mulv va99 22
   new: simp 2 8 22940 "fungi" 22 va99 600
   pose 16
   attr 208
   bhvr 48
   elas 0
   fric 100
   perm 100
   accg 2
   mvto _p1_ _p2_
   setv name "patch_id" mame "patch_id"
   tick rand mame "tickfrom" mame "tickto"
   doif tick eq 0
      tick 200
   endi
endm
malkin
 
Posts: 131
Joined: Sat Feb 11, 2012 3:55 am

Re: Guide to writing Patch Plants

Postby Amaikokonut » Mon Jan 21, 2013 12:02 pm

Hmm, what specifically is baffling you? I can try to make that segment a little more clear.

If you compare the chili spawn-code and the carrot-spawn code side-by-side, they're nearly identical with a few differences:
- The carrot seed starts out with attr 208 to allow physics; it falls directly from its spawn-point in the box onto the ground, whereas the chili starts with attr 80 which doesn't allow physics-- obviously it wants to stay in place until it's grown!
- The carrot has some additional code to determine which way it faces when it lies on the ground, but that's just...carrotyness.

Let me know how else I can help!
Amaikokonut
Site Admin
 
Posts: 171
Joined: Wed Feb 08, 2012 3:34 pm


Return to The Greenhouse Laboratory

Who is online

Users browsing this forum: No registered users and 1 guest