A remake of Caesar III: a mathematical model of the city
I remember playing for the first time in Caesar 3, this is an amazingly smart and balanced game, it creates the feeling that the city lives its own life even after the completion of the mission. You can spend hours watching the city and not interfere in his life: plebeians will run around the city in search of work, and patricians complain about poor living conditions, traders, schoolchildren, boats, priests - this world freezes only in moments of pauses, giving the player the opportunity consider the next step. Investigating the internal algorithms of the game, I do not cease to be surprised with what accuracy the authors put together the pieces of the puzzle, called “balance”. During the time spent on restoring the original game code, there has been accumulated enough material on the game's macromechanics, which I want to share with the media community.
Different trips to the modeling of city bustle
It all starts with the prestige of the land, it is one of the layers of the city, which the game operates on to calculate the parameters of migration and the level of houses. In addition to the base layers, the relationship of which is shown below, each layer can be further divided into parts.
In the city, people live in houses, the number of people and the quality of housing varies with each level, each level has a number of parameters, upon which it passes to the next. As I said, the basic parameter is the prestige of the land, the other basic parameter is food supply: in a small town this may not be noticeable, but in large cities the distance of barns and warehouses greatly affects the location of residential quarters on the map. Given that the market adversely affects the surrounding territory and the priority of traders is shifted towards supplying the population with food, a situation often arises when, due to lack of food, there is a shortage of other goods, especially the most valuable (for the development of houses) - pottery and furniture. Each next level of the house requires more expensive services and resources. We get the classic (human) needs pyramid. ')
At a certain stage of development, houses turn into villas and significantly improve the rating of the city, but it reduces the number of workers in the city: the patricians do not work, which in turn leads to a sharp decrease in the level of production in the city and mass exodus of residents, and if at some point in the game If you skip these “swing populations”, they often lead to losing the mission. You can invite new settlers to the city, but with the advent of huts, already prosperous residents begin to flee from the city and the prosperity rating drops.
The basic layers of the city may contain additional sublayers that are responsible for a specific parameter or service provided. For example, health care can be divided into general (doctors and baths) and specialized, which is required by patricians (clinic), but also replaces general functions: for example, the clinic provides the services of surgeons and doctors, but the cost of maintenance is much higher than that of a doctor's house. It is the same with entertainment, except that entertainment buildings require “students”: actors need actors for the theater, gladiators and lions for the Coliseum. It seems to be a small detail, but such unobtrusive micromanagement greatly influences the layout of the city in conditions of limited coverage of buildings.
Having defined the components of "urban life", you can make a mathematical model of the city. I note that the original game uses a probabilistic-statistical model of the city, which means that at certain points in time (game day, week, month and year) a snapshot of the city parameters is taken and based on this data and taking into account previous states, the probability of an event is calculated. A simplified description of the model is shown below. Red is the negative effect of one object on another, green is positive. The positive aspects of the statistical model are that when calculating the probability of an event not taking into account the parameters of an individual object, we consider the “average temperature in the hospital”, which significantly reduces the workload during the calculations (let me remind you that the game was launched on computers with a RAM size <32Mb). Buildings, although they have their own characteristics, in most cases they are involved in calculating the averaged parameters, and not to calculate the situation for a particular building.
In the remake of the game, from the very beginning a dynamic model of the city was laid, similar can be seen in the game “Tropico”, where each game object has a set of its own characteristics, which it uses to select the object's behavior at a specific point in time. The set of links in this case is more complicated and depends on the specific object, for example, the parameters of the house depend on the number of people living, on the number of working people in this house, the availability of products and goods, and the funds for their purchase on the market. In the picture you can see a simplified model for calculating the parameters of the house.
Since the calculation of the probability of occurrence of an event is transferred from the city level to the object level, additional connections need to be entered for interaction between the objects, in the remake they are performed by “service providers” (porters, bathhouse attendants, market vendors, priest, schoolchildren, etc. .). The model of behavior of objects in the game also changes accordingly, most of the interaction between them occurs through an intermediary.
The use of a dynamic model makes programming the logic of individual objects much more difficult, since it is necessary to take into account the impact and type of source, the positive side of such an organization is the flexibility to customize the behavior of both the event source and its handler. Any dynamic modeling, designed to evaluate non-stationary processes to answer the question: "What if?". And what if: in the city there will be a famine with a large flow of settlers, how will the epidemic, fire or earthquake spread.
Differences from the original game
I have been asked in person many times if I’m doing a Caesar clone and where did the decompiled source go. It was the clone (the code that turned out after the reverse engineering) that I completed 90 percent, the project is going to work and the first mission is going to work. The source code was removed from the github at the request of the copyright holder. This is directly about Caesar's clone, it is located in an even more “gray legal area”. As for the remake, CaesarIA is an independent open source game, an attempt to revive the game with more than 15 years of history from Impressions Games.
No, this is not Caesar, I use the ideas from this game, but all the code is written from scratch: logic, maps, search for the path and other things that you used to see in the old Caesar, they are made with an eye to it, but they are different. Yes, I use ripped resources for test builds, if you are tormented by the question of legality - you are free to choose the mode of working with original archives from an honestly purchased copy.
Having asked the opinions of habrazhiteli, I decided to try to legalize the remake in the way that I thought was available at the moment - to raise funds through crowdfunding, and in Russian “to the world by thread”. The choice fell on the site Indiegogo.com ( and yes, I know that many consider this site garbage for suspicious projects ). After talking with artists on gamedev.ru and their familiar designers, the average price for creating 3D models (and, accordingly, textures) of buildings and people was determined: $ 6k (102 building models + animation) for buildings, $ 4k for people and surroundings. this will avoid the claims of copyright holders and make it possible to distribute the game for both desktop computers and tablets running Android and iOS. At the moment I have done everything I planned with the game world by the fall of this year, but I am just one person and I hope that the help of other people will allow the game to find its own style. Now the project has reached the point where its further development is difficult without new textures, buildings, sounds and other materials.
What problems are solved at the moment
This is the video of the second training mission, then the playing of video clips was not done yet (this is a live gameplay as it is) the video is long, I just played the second mission:
1. City simulation 1.1 fires and building aging 1.2 in the game all the buildings of the original are realized, the functionality of some of them needs to be improved 1.3 all city layers that were used in the original are implemented (training, health, health care, taxes, etc.) 1.4 made tax collection system based on forums 2. Gods and religion, gods can be angry or rejoice 2.1 Calculation of the temples coverage area 3. The calculation of the distribution of water, goods, products and services 4. Made the appearance of disgruntled citizens and rebels 5. Made a simple AI to control the soldiers, their own and enemy 6. Planning and holding festivals 7. Emperor's requests and trade between cities 8. Animals and fishing 9. Birth, aging and death of citizens. Age groups 10. Dynamic update of objects paths, obstacle avoidance 11. Subject missions from the original (until the mission in Tingis) 12. Mining and production chains
Many other little things that had to be solved in the course of creating the game