Evolving Cities and Video

For now, I've finished my work on simulating the economies of planets.   Population and wealth grows and shrinks over time, players have the ability to influence their planets' growth via governmental policies.   Mines consume resources, factories produce goods from raw materials.   The overall desirability of the planet's economic indicators drives natural immigration to the planet or incites the population to vacate.  I can generate the economic indicators of any planet at any time.

This is all fine and good on a spreadsheet or in the game UI


But do people want to play a spreadsheet or a video game? How will these changes manifest themselves on planets in the game, and not just as graphs and metrics in the UI?  Enter the concept of Evolving Cities.

Evolving Cities

The video below shows an evolving city in real-time in the game.  A Headquarters has been placed, it begins with 100 population and 1 million credits and becomes the hub of the planet's capital city.   I've put in a time acceleration hotkey to see the city growth in realtime.



Initially, Pegwars biomes included a few different sized city tiles mixed in with all the natural biomes, all generated and placed during each planets' inception. This was done to make sure the engine could handling rendering large cities at distance, and be integrated into the biome system.

While a semi-random scattering of trees, flowers, bushes, crystals and rocks look fine, having a similar random scattering of residential, light, medium and dense city tiles makes no sense, as the following screenshot portrays.  Random city looks random:


Cities are artificial, they are built for specific reasons and in specific configurations.   Cities in the game should also look like they are built-for-purpose, but not only that, they should reflect the real economic data.   As populations grow, cities on planets should expand.   As populations and wealth wane, installation should be left abandoned, city growth should taper off.   It wouldn't make sense to have a world with a massive population yet only a few buildings and houses.

There is some excellent research into procedural cities:

Of particular use was the survey paper which summarises many existing techniques, and highlights their strengths and weaknesses for particular use-cases.   This provided a great framework for choosing an appropriate strategy for the game.

For Pegwars the agent-based papers made the most sense.  Specific city blocks are chosen and placed based on their ability to satisfy certain desires.   This fits in well with evolving cities over time in the game in response to population growth determined by the economic model.  For example,

  • cities tend to spread in the path-of-least-resistance, i.e on flat areas rather than going up mountains

  • residential tiles on the other hand prefer to grow near water features, on hills, near city centres, near forests, near places of work.
  • high density tiles prefer to grow near city centres.  Cities should have a central CBD containing larger buildings, and semi-organically taper off 
  • the population doesn't like to live too far from the city centre, and so once a certain distance is reached, it becomes more desirable to upgrade a lower-density tile near the city center rather than building new low-density tiles far away.
Evolving Cities uses this kind of rule generator, it listens for planetary evolution events from the economic simulation and manifests and persists the changes in economic indicators on the planet itself.  

Here's a brief overview of the implementation:
  • subscribe to PLANET_EVOLVED events. These come with a payload of all the economic indicators for each new year in the evolution of a planet, e.g. population size, number of mines, factories, airports and spaceports.
  • determine the delta in population, and the delta in installations.   We need to manifest these changes as changes to the planet itself.
  • I want to allow the player to manipulate time, like a fast-foward button.  Sometimes time is advancing rapidly, and each planet terraforming cycle takes some non-negligble time in background jobs to get done.  Especially when the planet heights get changed and the Vertex Buffers need to be re-uploaded to the GPU.   So we don't necessarily evolve a planet year by year, sometimes the delta in population and installations can be much larger as they represent a change over say 50 years.
  • Choose the location for, and build the requisite amount of new installations
  • Choose the location for new residential and city tiles.   The choice depends upon geographical proximity to the city centre, geographical features such as hills and water.
  • Increase the population capacity to accommodate population growth by either building new residential tiles (sprawl), or upgrading exiting tiles from low to medium to high density tiles.

Population Capacity

Planets have a population capacity which is simply a measure of how many residential and city tiles there are, and how much population would feasibly live within these tiles. Right now each planets in Pegwars gets a 512x512 biome cube map.  Each texel in the cube map represents a single biome.  For cities, the current biomes are Thick City, City, and Light City (residential).   So how many tiles of a specific nature are required to house a certain population?   And when the city expands beyond its physically desirable limits, how much extra capacity can be achieved by upgrading tiles from light -> city -> thick?   Can I feasibly house the required population?

Face Width512
Num Tiles1572864
Population5000000000
High DensityRatio0.95
Med DensityRatio0.045
Low DensityRatio0.005
High People per Tile20000
Med People per Tile5000
Low People per Tile500
High Density Tiles237500
High Density Population4750000000
Medium Density Tiles45000
Medium Density Population225000000
Low Density Tiles50000
Low Density Population25000000
Population5000000000
Total Tiles Required332500

In the table above, there are 1,572,864 available tiles per planet, and I want to support planets of around 5 billion population.  The economic simulations are tuned to produce around 5 billion population, which seems like a nice number for now.   For a highly populated city, I would expect 95% of the population will live in high density tiles.  A high density tile can support a population of 20,000.  Medium 5,000 and Residential 500, these are educated guesses based on building sizes within each 250m^2 metre area.

Calculations done, for a high population planet I need 332,500 (237,500 high density, 45,000 medium and 50,000 low density) tiles to support a population of 5 billion.  This leaves over a million tiles untouched, aka plenty of wiggle room.   Perhaps one day we'll get a planet housing a population size of a trillion.

Evolving Installations

I wrote an earlier blog post describing the concept of Installations and Headquarters.  These are major buildings on planets that aren't just scenery, but active entities. I have the planetary economic simulation working, it dictates the population, and it dictates when major installations such as Headquarters, Mines and Factories are built.   With the agent-based city generator I can dynamically create and place installations on the planet when they are required to be built by the governor.

When a player is running a planet, they choose the initial HQ location, and also the location of mines, factories, airports and other installations.   The chosen location of the HQ is important, as cities grow from the HQ and some locations are more desirable (meaning more population growth) than others.   The location of mines are very important due to proximity-to-resources.

Each non-HQ installation also gets included in the evolving city process.  Workers need to work at mines and factories, and they don't want to travel too far.    While the major city centre will build up around the HQ, minor cities will spring up around minor installations as well.  If a mine or factory has been around long enough, and the population needs of the planets are high, you might even find large cities forming around them.

Where to Next?

I'd like to include road systems in the city build since roads are very important features of cities, and even dictate to some degree where city tiles will be built.   Highways between the HQ and installations would be a really nice feature.

Part of the desirability calculation is Eco desirability, I'd like to mix in forests and parks in the city evolution process, much like in real life.

Finally I think I'm getting closer to the core gameplay elements, such as flying your spaceship to other planets and dropping bombs on their cities.    City tiles will be blown up, and this will directly impact the population size, the population capacity, and desirability.

Conversely, it will be important for city governors to build defense installations, like surface-air lasers.  They'll need to build airports and build a defence fighter capacity.    And hopefully, rich planets will be able to build energy-shield domes around important cities and installations.   Maybe even entire-planet shields?

Comments

Popular posts from this blog

2022 Screenshot Update

Screenshot Progress Update!

Rendering Nebulae