City Building Game
(1514 words)A city building game? Why? What? How? When?
That’s five questions, let’s try to answer them one at a time.
Yes, a city building game. By that, I mean a game where you play the designer of a city and place down roads, allow buildings to be built, and raise money from taxes on the people and companies in those buildings. Those taxes can then be used to fund services in the city, such as emergency services, education, healthcare, refuse collection, etc.
Why
Why a city builder? Well, I love playing these sorts of games. Sim City was probably my gateway into the genre. The cities were small and the economic model was very basic, as was the transportation model. There were plenty of others, but the current game is Cities Skylines. It was completely unoptimized, the transportation model is a little better but still mostly broken, and the economic model is an afterthought. For example, why does building an extraction business make a city hugely more profitable than not. Have you noticed that places like Los Angeles and San Francisco don’t have huge forestry or mineral extraction areas?
What
What is a city builder? Time for a little philosophy. A city is just a human creation that benefits those living within and without by virtue that the costs of transportation of goods is lower than in a rural area. Ideas spread quicker, people learn more, and people have more social interactions improving the gene pool and sustainability of the city.
This to me means there are three main elements of a city builder:
- transportation
- land use
- economy
Let’s consider the movement of a good through the system. Somewhere, a tree is chopped down and transported to a lumber yard. The tree is cut into manageable lengths and into planks or posts. These are then transported to a carpentry business who will use some of these pieces of wood and make a table. They will need other materials, such as wood glue and wood polish. The table is then sold to a furniture store. Then a customer enters the furniture store and buys the table. Each step along the way, each business has added value to the product. The lumber yard converted a tree into wood. The carpentry converted wood into a table. The furniture store converted a table into money, that effectively paid the carpentry company, and that money paid for the raw lumber. Each company makes a profit, and therefore the city can tax that profit.
What did we learn from this example? Well, companies can harvest or extract materials. Companies can convert one type of material into other types of material. Companies can buy and sell products. To keep things simple, lets just call all of these goods. The tree was a good. The chopped down tree was a good. The lumber was a good. The table was a good. The family that bought the table owns that good. Goods also move around. The carpenter is not located in the same place as the lumber yard. A lumber yard should ideally be near the trees and not in the center of town. A carpenter should be near the stores. The store is near where people are. This requires transportation, and specialised transportation at that. A lumber truck that moves trees is different from a delivery truck that moves tables around, and that is different from the way that the person who purchased the table moved around.
It matters where people live and work. It matters that people don’t have to live right next to a loud industrial area. It matters that the transportation system is efficient. It matters that companies can make money and invest in their people, equipment and the future.
This shows that transportation, land use, and the economy are all interlinked. Increase taxation, and the companies keep less money to invest in new machinery, that could chop wood quicker, or mill wood quicker, or manufacture tables quicker. This means that these companies will be less competitive with other similar companies producing the same product in a different city. However, you also need taxes to pay for the services that people need or want.
This is what a city builder should be about. Where and what type of transport infrastructure do you need? Where and what types of buildings are allowed in different locations? How much taxes should be and what they should be spent on. Everything else is just lipstick.
How
How is it possible to build such a game? Well, frankly, computers are powerful enough now that we should be able to build such a simulation without much trouble. Obviously, we are not going to be building the eastern seaboard metropolis of the US, from Boston to Washington, DC, but I think we should be able to simulate a million person city without much of a struggle.
Consider a reasonable average machine in say 5 years time. I would expect it has 64 GB of memory, 32 CPU cores, and a reasonably good GPU (although it will be prohibitively expensive, so this is a ‘reasonably good’ and not an ‘high end’ device).
Let’s dedicate half this memory to the simulation of people. That’s 68719476736 bytes of memory. That’s a total of 34000 of memory for each simulated person. To me, that’s way too much memory. Just look at what is required:
- name (8 bytes)
- location (12 bytes)
- birthtime (8 bytes)
- deathtime (8 bytes)
- skills (64 bytes)
- partner (4 bytes)
- children (64 bytes)
- mother (4 bytes)
- father (4 bytes)
- randomness (16 bytes)
- home (4 bytes)
- work (4 bytes)
- school (4 bytes)
That’s just 216 bytes. That’s far short of the 34000 we have budgeted for. Let’s go crazy. Let’s say we have 512 bytes of information per person in the simulation, and 1 million population, that’s still only 0.5 GB of memory.
What’s the rest of this memory being used for? Businesses?
Well, each business has a collection of goods that it owns, and a collection of tools/machines that is owns. It also has a set of processes that it knows about and can use. It has a collection of employees, and a bank account.
The average business has 3 or 4 employees (and we’ll assume adults here), and therefore with a million population, we could have about 250,000 companies. Even if each of these had 4096 bytes of data associated with them, that’s still only 1 GB of memory.
What about the transportation network?
Let’s get absurd. Let’s assume we have 250,000 nodes (locations that define positions of a road), and 250,000 links (the connections between nodes). The nodes will probably be pretty small, so let’s assume they are only 32 bytes each. And the links are not much bigger, so let’s assume 64 bytes each. That’s still only 0.03 GB of memory.
And then we have vehicles. Let’s assume we have 500,000 vehicles, and each has 256 bytes of data each. That’s 128 MB of data.
There is not a memory issue.
What about processing power? Well, that’s just an issue of how stuff is scheduled. Memory bandwidth will probably be the limiting factor.
Modern memory can supply 32 GB/s. Let’s assume that we have access to a quarter of this bandwidth, that gives up 8 GB/s for processing simulation data. If we have just 4 GB of data for the simulation data, that means we can simulate at 2 fps. But we want to simulate some things faster than this. The vehicles for example will need to be simulated at the full frame rate. If we have a 60 Hz refresh rate, then we’d have a demand for 7.5 GB/s of memory bandwidth. This leaves us with 0.5 GB/s of bandwidth for all other simulation tasks.
Essentially, we have 4 GB of data for the simulation and only 0.5 GB/s of bandwidth, this means that the simulation will fully run once every 8 seconds. For such a city builder game, this is perfectly acceptable.
When
The simple answer to this is whenever I get around to it. It’s not going to be a quick task. I have other things that I’m going, like making my house automated, or smarter if you like (I don’t). If nothing happens for another year, then things will go slowly. But if I can get the simulation up and running and a basic UI by the end of the year, then we might have something that is valid. That’s eight months. I don’t know if that’s possible, and software people are typically terrible at coming up with a schedule that is actually realistic, but it is at least a target.
Name
What is this project called? I don’t know. At the moment I’m just going
to call it city. It will have a better name later. And what is the
engine called? I don’t know. I was thinking about calling it stardust,
but that’s already been used. So I’ll call it something else. And, no, I
don’t know what yet. At the moment, I think I’ll just call it engine.