Building a Farming Game Loop and Troubles with Ground Water

Game #2 (still unnamed) is centered around economics and the environment. So a natural starting point (at least to me) when thinking about a game loop is farming. Yep. Farming. Does the world need another farming game? Hopefully!

A farming loop needs to allow the player to plant, harvest and sell crops. Nice and simple. Right?

Sunflower Farm: Testing visuals for setting up simple farming.

This means that models need to be built, stores need to be coded and basic UI needs to be added. So I setup a quick and dirty (ugly) inventory that allows the collection and basic handling of items. Items are stacked for organization and stacks can be split and recombined. Nothing fancy, just enough to play test. (A good tutorial to get you started.)

An ugly but functional inventory UI

Basic animations allow a player to dig and get some tilled soil in which to plant a crop. Crops can be added, but I didn't grab a image.

 Testing of basic digging mechanics.

Testing of basic digging mechanics.

On top of this crops should respond to the environment. Crops should grow when the conditions are right - it doesn't make much sense for corn to sprout when it's below freezing or there's no moisture in the soil. So this means setting up each plant with ideal conditions and scripting growth. Still not too hard.

 This is apparently what I think a carrot should look like... The jury is still out on this one.

This is apparently what I think a carrot should look like... The jury is still out on this one.

Which brings me to the current struggle...

Getting a working environmental simulation was a matter of a few hours of coding - okay probably double digit hours of coding, but still a very reasonable effort.

So far the wind is working, temperatures are reasonable, seasonal changes are working, it's even multi-threaded (not coroutines!) so there's no real performance hit. All good so far.

And then comes the water cycle. Damn the water cycle!

Ground water and ocean water evaporates into clouds. Clouds move and release water as rain. Sounds easy enough, but we all know what happens when you assume things.

The problem is getting a stable amount of ground water from season to season. How fast does the water evaporate? How fast can the clouds move? How much water can the clouds hold? How fast does a cloud release its water? How quickly does water drain back into the ocean? How many hours can I spent looking at a heat map? 

 Visual Feedback on ground water... 

Visual Feedback on ground water... 

So many variables. Each with the ability to muck up the whole simulation. I could hard code values, but then I'd lose the players ability to screw up the world... And that has to be part of the game. Its part of the real world!

So who's idea was this game anyways? Why couldn't I try to make a 2D platformer like everyone else?

A few changes, including fixing a stupid mistake, are giving me some hope. I have now seemly stabilized the lowest ground water level for a given thermal input/output. This should allow players to mess up the CO2 level and get a higher evaporation rate and thus drier soil... Or allow other season to season changes to impact crop growth. 

One change was to make the ground water flow rate respond to the amount of water in the soil. It is also a function of how many environmental cycles there are per game year. 

GroundWaterEquation.png

This basically slows the rate if the average ground water dips below 0.5 and raise the rate if it climbs above 0.5 (almost all of the environmental setting are floats between 0 and 1). Not a perfect feedback loop, but seems to help contain the crazy swings. This would seemly allow the (minimum) average ground water to be a function of ground water flow rate, evaporation and temperature. 

If I can stabilize a minimum ground water level then I should be quite a bit closer to getting a overall stable and reproducible water cycle.

Fingers crossed.