Energy Cycle

Okay, to finish off this trifecta of unhealthily co-dependent posts, here we approach one of the most central systems in the entire game: Energy.

“Energy” is everything in Species. Every dynamic in the game uses a type of energy, and every type can be converted into another type. 1 unit of plant-food can become 1 hit point, 1 unit of walking distance (sort of), 1 unit of meat for other creatures to eat, etc. If a creature loses all its energy it will starve. If it loses all its hit points, the energy will be converted to meat. And so on.

There’s nutrient energy in the ground, which is converted into plant energy. Creatures convert that into chemical energy by eating it, which can be used for all sorts of things: it can be used to grow into adulthood, it can be converted to hit points to heal themselves, it can be used to give birth (in which case it is handed directly to the child creature. Childbirth is a somewhat less messy process in Species), or just consumed by their metabolism and exertion (walking about). When they die, spare chemical energy is converted into meat-energy, which can be eaten by other creatures or, to complete the cycle, decay slowly into nutrient energy in the ground.

This system makes the decision of whether to implement a closed or open energy cycle a big deal.

A closed cycle would have the same amount of energy in the global ecosystem at all times according to conservation of energy. Growth, metabolism and exertion convert chemical energy to ‘biomass’, which is returned to the ground as meat when the creatures die. There is no external energy source.

An open cycle doesn’t convert metabolism and exertion energy into biomass: it just vanishes into the ether. In addition, some energy losses are acquired during conversions, such as eating. This requires an external energy source to sustains the losses and allow the cycle to continue.

Given these choices, I decided to build an open system. It’s less controllable, but I don’t want to control the ecosystem in Species: I want it to evolve, to adapt and change, on its own. It’s also more realistic: the earth has an external energy source, a ridiculously massive one that renders anti-evolutionist arguments involving the second law of thermodynamics (yeah, we’ve all heard that one, guys) utterly moot: the sun. It’s only fitting that sunlight in Species should serve the same purpose: feeding the trees that feed everything else.

This doesn’t stop me from closing off the energy cycle, however. It just requires me to add energy gains (the sun) and roughly equivalent energy losses (metabolism, movement) to it.

But it also makes problems harder to debug.

The problems I refer to are “energy leaks.” Under particular atypical confluences of unexpected variables, or more often simply because the programmer can be kindly described as a complete dingbat, energy can be gained without being lost. This particular type of bug absolutely plagued the early iterations of Species. Populations of creatures would often discover these leaks long before I did, and would explode massively as a result. And making it harder for them to survive in an attempt to control the population would simply result in them dying out before they found the exploit.

Some of these were easy to track down: for instance, an observation that the exploding population were all carnivores…

(“I thought you hadn’t yet implemented a carnivorous diet at this stage?” Shuddup. Time can be re-written.)

… led to me rewriting the energy transfer for eating meat. I have to admit, there’s something inherently awesome about the creatures helping me debug their own game without me having to prompt them to do so. ๐Ÿ™‚

Other leaks were more subtle, and an inability to track them down would eventually, after much frustration, lead to some drastic action: I closed off the energy cycle entirely, built an “entire ecosystem” energy counter that added every type of energy in the game up, and watched to see when and why it changed. You can still see the “Entire Ecosystem” counter in both of the Development Video’s.

Only once I’d completely debugged the energy cycle, and ensured that it stayed closed and stable under all conditions, did I slowly reopen it. That was only a few months ago.

(“You’ve completely given up on a sensible chronology, haven’t you?” I am a Time Lord. Chronology has never laid a hand on me. “It hasn’t laid much of a hand on this blog, either.” Damn right it hasn’t!)

Of course, at the time of making this whole system I had no idea what lay ahead: I was just obliviously coding, and seeing populations of creatures change and move about as their constituents lived and died was more than enough for me to be happy I was getting somewhere.

The next step would be implementing variable statistics: tying leg size to speed, size to metabolism, not-yet-implemented head-type to not-yet-implemented diet, and so on. From that combination would emerge one of the most vital points of this entire project: natural selection.

But perhaps, before even doing that, I should implement the still-remaining body parts: head, eyes, hands and feet. Yeah, that’s probably a plan. Assuming I don’t get distracted and go off on some sort of a rant about something shiny.

Huh. That’s pretty much the most planning ahead I’ve ever done in my life. Err… for the blog. Not the game. I planned the game out completely from start to finish, like a professional– oh, who am I kidding? I’m winging every aspect of this thing.

See you next week!

“For the record, I’m… uh… pretty sure he’s not really a Time Lord. Like, 95% sure.”

  1. #1 by Reprieve on November 15, 2011 - 3:40 am

    So can the nutrient value in the ground be highly variable is it pretty uniform for the most part?

  2. #2 by ququasar on November 15, 2011 - 8:32 am

    Err… no idea, actually. The ground is an odd mishmash of systems at the moment. Basically, each node of the terrain grid has a “fertility” and a “spare growth energy” value. Fertility is static and determines the number and type of trees in an area, while spare growth energy changes regularly: decaying corpses and sunlight adds to it, while trees feed from it to regrow (it was originally created as a stop-gap to prevent trees from springing up instantly after being eaten). The energy in each node bounces around like mad, but as a whole I have no idea.

    Eventually I’m planning on combining the two systems, with excess growth energy feeding into fertility and ‘upgrading’ the area with more energetic trees: so it’ll be possible to turn a forest into a desert and vise versa. But that means changing the ground texture in real-time, which means another bloody RenderTarget. I hate those things ever since using them to implement the Tree Of Life graph in Dev Vid 2… ๐Ÿ™‚

  3. #3 by Reprieve on November 17, 2011 - 12:18 am

    From what I gather the factors that give rise to ground fertility irl are very linked. Microbes that “increase fertility” need decay, which needs microbes to grow etc.

    Seems like you’ve got a fairly good approximation of that in there. I look forward to it improving

  1. Speciation « Species Development Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: