DevDiary #2 – July 2018

Hello everybody,

Have you ever wondered why it sometimes takes developers more time to implement a feature or fix a bug than they thought it would? If yes, this dev diary is for you, because this time we want to talk about the hidden pitfalls in game development.

It all started with marital difficulties…
We received reports from players that, if they play over a few decades and want their dynasty’s heir to find a spouse, they couldn’t find any young citizens to actually marry. Also, if they did try to marry someone who was already in their senior years they suddenly gained 15-20 years and then instantly died after getting married.
So far, so good, there seem to have been 2 issues:
a) No young characters are being generated for the city population
b) Characters seem to gain age when they get married
This sounded simple enough. Find out where and why in the code characters get age added on marriage, and find out why there are no new characters being created.

Once you start pulling on a thread…
During the initial investigation, we found the following issues:
a) The part of the code that is responsible for creating new characters had a bug where instead of a new young NPC, it would create characters with an age of +/- 5 years from the average age of the population. So over time, the population became overaged.
b) There was no place in the code where age was added to a character upon marriage, so something else must cause this “death by marriage”
Since there was no immediate cause to see for b) we first started fixing the age of the character creation code. This was simple enough, we already had code that calculated a life span, we only needed to randomize the character’s start age to have a more or less evenly distributed age curve. So we implemented that characters that are created as citizens start with an age between 10 and 50, male and female.

Wait, why doesn’t this work?
While testing the code we realized that after playing for some time there were still mainly senior citizens on the streets of the city. After some head scratching we tried to find out what happens when a citizen dies. It turned out that there was actually a check missing that would let citizen characters die once they reached the end of their life span, this check was only performed for characters that are part of a dynasty family. So basically all citizens and employees were immortal when it came to natural causes of death and therefore, only a few new NPCs were born.

Eternal life? We can’t have that.
The revelation that nobody except dynasty families died of old age brought forth a little “Heureka”-moment. Citizens didn’t age and die after marriage, they had already been dead for 15-20 years when we married them, their age just didn’t get updated further than their date of death. Once they were part of the dynasty family that check was performed, the age was updated and the spouse had a diagnosed time of death: 2 decades ago.
This obviously is not supposed to happen, what good are the joys of life when you know this is going to go on forever?!

How did this happen?
So, we added a check to all characters to let them actually die and also made sure that population growth for citizens is kept track of and that new characters with diverse age distribution are spawned. So when we tested this with one of our save games we were happy to see, that at the start of the game the NPC manager disposed of almost the entire population of the map – because they were already past their natural date of death – and spawned new young citizens. After the initial feeling of accomplishment, we realized that our dynasty was now homeless and did not own a single building anymore, also there were abandoned carts of dead transporters scattered all over the streets.

The death of the working class
Removing the ghost carts from the streets was easy enough, the problem where a dynasty was losing all its property was a little bit tricky. But after some more investigation we found out that when one of your employees died, the game performed the same check as if the employee would be part of your dynasty’s family. The check does the following:
* On death check how many family members there are
* If there is only one member of the core family (so, employees are ignored), that means the dying character is the last family member, so the dynasty died out and all of the dynasty’s property becomes neutral
This basically means, if your dynasty was only your main character (the leader) and employees, but no spouse, sibling, children, or parent the game thought that the employee that died was the last part of the family and made all of the dynasty’s buildings neutral. And with fixing this issue the fix for “everybody is old and my spouse dies instantly on marriage” was ready to be submitted into the code base.

There is a lot more about how characters are created, how their life span is measured, how the death of a character is handled, how the population of a scenario map is “managed” and what influences all of these things. But that would go way beyond the scope of this Dev Diary entry.

We hope that this gives you some kind of insight, why it sometimes takes a while to fix seemingly obvious bugs. While none of those fixes were particularly hard, the domino effect one fix can have on a completely different part of the game caused this bugfix to require several days instead of just a few hours.

Thomas “Tyleet” Fritz
Game Design & Gameplay Programming for The Guild 3
Purple Lamp Studios