Plants Update

I wrote this last week put forgot to post it.

Got a large update today. The last week I have been in the zone and have gotten a great deal done. First off, we reworked our website a little. In my last update I said I was working on implementing plants. At that point I was still in the designing phase for them. Since then I have finished implementing them and much more.

For every feature my mantra is easily moddable but lots of control. All of the supported content up to this point has had one form of communication – engine asking for the entities components which are returned in component definition form. I struggled quite a bit while attempting to fit the plants into this format. I finally came to my senses and realized what I had to do.

All of the plant logic resides inside of python. How the plant grows, how it visually looks, how it is harvested, and even how it is planted. With this solution, any modder has unlimited control. As for the “easily” part of my mantra, I am wrapping the core plant concepts up into nice little python classes which are extremely simple to use. I have included the code below for those interested in its awesomeness.

Because of this approach I have had to go through my entire game engine and expose it to python. This is something I have been putting off because I wasn’t sure of the requirements, boost python is a little scary and I knew it was going to be quite an undertaking. With this beast finally slain, creating new content will be much easier and have even more freedom.

Here are some screenshots featuring the plants that can grow overtime and be interacted with. There is also an early version of the grass. Right now the grass just grows on soil and is destroyed when the tile underneath it is removed. Later today I plan to make grass occasionally spread to nearby areas as if seeds were dispersed.

You can harvest the trees too!

This is the Zebra tree script that most people will see and have to worry about. I hope most of this is self explanatory. We are adding the different components to the zebra tree entity and the ZebraTree class is used to override the default properties of the tree (which can be seen below). We can add bases, trunks crowns and saplings images and they will be randomly used in the appropriate places. We can also override many other properties such as the seed it produces how tall it can grow, and how fast it can grow.

name = "Zebra Tree"

add(ModularRender())

interactable = Interactable()
add(interactable)

class ZebraTree(Tree):
trunks = [TreeImage("mods/base/plant/tree/zebra/trunk1.png", 2, 28), 
TreeImage("mods/base/plant/tree/zebra/trunk2.png", 2, 28), 
TreeImage("mods/base/plant/tree/zebra/trunk3.png", 23, 28)]
crowns = [TreeImage("mods/base/plant/tree/zebra/crown1.png", 34, 101), 
TreeImage("mods/base/plant/tree/zebra/crown2.png", 31, 98)]
saplings = [TreeImage("mods/base/plant/tree/zebra/sapling.png", 8, 33)]
seed = "mods/base/plant/tree/zebra/seed.ce"

def __init__(self, entity, organic):
super(ZebraTree, self).__init__(entity, organic)
def createZebraTree(entity, organic):
return ZebraTree(entity, organic)

add(Organic(createZebraTree))

Here is the Zebra seed script which is really simple. As with all content entity scripts we add the needed components, this time a Render, Item and Interactable components. The important part here is that we add an interaction “use” and provide the “useSeed” function which is defined in the tree script just below this one. To make this function reusable the plant the seed creates needs to be bound to the function provided – in this case we provide the path to the zebra tree.

import functools

name = 'Zebra Seed'
render = Render('mods/base/plant/tree/zebra/seed.png')
add(render)
item = Item()
item.stack = 999
item.delay = 200
add(item)

interactable = Interactable()
interactable.add("use", functools.partial(useSeed, "mods/base/plant/tree/zebra/zebra.ce"))
add(interactable)

Now for the meat of the tree logic. Here is the tree script which contains the Tree class and useSeed function that are used in the above scripts. As with everything this is still in the works but is most of the way there. I’m not going to go into detail in this now since there is so much going on but if you understand it then awesome. Once things start becoming finalized we’ll write some official documentation on these sorts of things. I put this in a pastebin because it is somewhat large.

Tree script

Lastly, I wanted to throw in the grass code which I’m happy about because I was able to write it without making any engine code changes. There is still in the works but I have the basics down. I will likely do the same for the grass that I did for the tree and have a base Grass class and allow for inheriting and changing the properties without having to worry about the logic. Pastebin link for the same reason as above.

Grass script

Thanks for reading through all of this! I know it is a lot. I’m interested to hear what you think of this.

One thought on “Plants Update

  1. Zorg

    I think you should have a zebra tree that bears python eggs as fruit. If you eat one, a python pops out of your chest, and stalks the other players.

    Reply

Leave a Reply