# Climate/weather model for turn-based game

I am looking for a model to simulate weather patterns over long time periods on a tilemap.

The basic idea is to have 3 tile types:

• mountains
• land
• water

Over the course of game, the climate of land and mountain tiles should change (desert/grass/snow...) The players should be able to influence climate of tiles by building canals, dams, removing mountains, etc.

For this I need model to calculate weather patterns, especially determine tiles on which it will rain.

The current idea is that rain should depend on height of the tile, proximity of mountains/lakes/rivers/shielding of ocean by mountains...

Also I would like to achieve a behaviour, when rivers can dry up/lower the amount of water they have. For example, if rivers were to originate in mountain tiles with snow, then changing the mountain tile climate would result in drying up of the river.

I understand that it is unfeasible to solve differential equations in a game, therefore I am looking for a simple model that would let me fake realistic climate behaviour.

As you can probably see, I don't have crystal clear concept of what I want to achieve, just the basic outline.

Therefore, I would appreciate any ideas of how to solve similar problems.

• "I understand that it is unfeasible to solve differential equations in a game" -> is it? We do it with game physics systems all the time! We just use numerical integration, which gives us "good enough, fast enough" results when designed and tuned right. Oct 26, 2022 at 22:37
• As currently framed, this question is very broad and vague. A good answer would require doing a great deal of research into climate models and prototyping ways to mimic them in game algorithms - that's a lot of work to ask of a volunteer! A much better way forward is for you to do this research. Look up some world-building articles or videos about how to plan things like currents and precipitation. From that research, determine a set of rules you want to follow in your game. Try implementing those rules, and ask here for help when you hit a snag Oct 26, 2022 at 22:42
• Don't fall into the realism trap! A system that provides a good game experience doesn't necessarily need to be realistic. You might want to try an approach where you first make up your mind about what weather phenomenons your game actually needs to be fun, and then you wonder how you could design a system which causes them to happen. Oct 27, 2022 at 14:30

You could approach this with a cellular automaton.

Each of your tiles would have a series of attributes. For example humidity, wind, height, rainfall… And so on.

Then you are going to make iterations. You would have to tweak how often. It could be one per turn, one each few turns, or even multiple per turn. And each iteration you update those attributes according to rules based on the surrounding tiles. For example, rainfall increases if there are tiles with higher elevation around. You can make the rules as complex as you need. This also depends on how weather should interact with other mechanics of the game, so feel free to deviate from realism.

You would also have to define some minimum and maximum for the attributes, and clamp the values to that.

Similarly, you could define that when an attribute is goes from certain range to another, the tile should change.

You might even make the tiles change probabilistically. For example, if the humidity goes below certain threshold the tile has a 50% chance of drying up that iteration, otherwise you clamp the humidity above the threshold.

Another modification you can do is defining rules based on the distance to a tile of certain type.

And yet another one is that attributes could not be scalars. For example, wind could be a vector, and then you use the dot product to see how much wind a tile gets form an adjacent one. You can do something similar with water flow.

Also, you could change the resolution of your simulation. For example, define blocks of eight by eight tiles, and treat them as a single unit… A chunk. And it is the chunk which has attributes, that update according rules based on surrounding chunks. You might even do a broad simulation with chunks and some attributes and a finer one with tiles and other attributes. And interleave iterations of one and the other.

If you need the chunk attributes for the tile simulation, the simpler solution is to use the value form the chunk the tile belongs to. But if you want it to be smooth, then base it on the a weighted average of the attributes of nearby chunks (including the chunk the tile belongs to) where the weight falls off as the tile is further away from their center… Which also means… chunks don't have to be a regular tiling! You could come up with rules to decide where to place them… But that is probably making it more complicated that it needs to be.

By the way, who says you have to do the iterations for all tiles at once? You can do odd tiles one iteration and even tiles the next, and so on. Which might be useful if iterations are too slow.

• The train tycoon game OpenTTD has a clever way it spreads out these cellular automaton updates in a pseudo-random-looking dither pattern, using a Linear Feedback Shift Register — good explainer video here. This lets it keep the tile update budget per frame quite low, without obvious patterns making the result look too grid-y and regular. Though it is possible the ordering would introduce biases into a more complex sim (like making certain wind patterns stable only in certain cells and unstable elsewhere). Dec 3, 2022 at 9:04