When exploring ways to create an adaptive realistic world within both the RTS and simulation genre, procedurally generated environments with realistic economies seemed to arise quite a bit. To briefly explain what type of PCG I will be covering in this post, imagine a game like Majesty, a world where elements such as trees, fish, and animals will be spawned based on an economic variable, one that allows an equal balance throughout the world. Likewise, upon starting the game, these will all be spawned randomly on the map, allowing each playthrough to not only feel distinct but slightly capturing the unpredictable nature of the world's economy.
Before we begin, I simply created a couple of prefabs I'm planning on using to explore these elements. These can be simple 3D models, to more detailed layers and hitboxes, to even going a step further and having values and attributes change on the worlds seasons, whether its day and night, to that areas unique biozone.
To start, we first create a base floor covering the size of the world . To affect pathfinding simply create the grid after calculating the PCG and then add a collider to check whether it collides with another object to then destroy that object or itself depending on importance.
This can then run numerous times with different instances of prefabs to create more detailed elements based on a random number to determine the odds of trees, rocks, and water.
However, the water can turn out to be quite complex due to simulating how puddles or ponds are created. This can be tackled by creating another independent loop inside, drawing around that water prefab, simply expanding around the initial point.
The last process to then fully simulate an economy is to have the passage of time documented in some way, in this instance I had fully functional seasons with a day and night system, assigning random values to trees, rocks, and bushes, and destroying/instantiating them dependant on their unique attributes. This, on paper, is one of the simplest ways to simulate such an economy but allows the methodology to be taken and expanded upon further down the road. Likewise, this process can also cause instances to arise that were quite hard to predict, potentially completely breaking the game, with certain objects overlapping and resources running out, to a tree literally spawning inside a player.
It's important to playtest these mechanics upon creating them, and the true fun is figuring out each problem as you go along.