Shadows of Doubt DevBlog #8: Simulating a City

Shadows of Doubt DevBlog #8: Simulating a City

Shadows of Doubt is a first person detective game set in a procedurally generated and fully simulated city. As head of the police detective department, it’s your job to organise your sleuths and track down AI serial killers before they strike again! Read previous dev blog entries here.

In this dev blog, I’ll discuss the challenge of creating and simulating the population of the city.

At the core of this project is the simulation of 100s of little citizens, all going about their daily routines. They all have jobs, places to be, things they like doing, and favourite places to eat and drink. Most of them will happily go about their day while you play, unaffected by the grisly murders happening elsewhere in the city. You’ll likely never interact with 90% of them. Yet they’re essential to the game because they are the hay in your needle-in-a-haystack search.

The average citizen currently makes to about 4 – 10 different journeys every day. A typical day might involve getting up and going for a coffee at the cafe down the street from their apartment before going to work. They’ll have lunch at the pizza place in the shopping mall, then back to work. After work they may visit the local sports bar before finally heading back home, picking up some groceries on the way.

Citizens’ needs for caffeine are actually simulated too!

Simulating 100s of the above would be a hugely intensive task for a system to handle in real time. That’s why I’ve chosen not to handle it in real-time. Instead, the game needs a brief period of calculation time before the start of each day (typically no more than 10 -15 seconds depending on the population count). During this time their activities for the day are chosen and mapped out for them. This way I can have the number of citizens I want without it being too demanding on the system. Of course, they can deviate from this if the situation calls for it, and their altered routine can be calculated by the game in real time as there will never be more than a handful of citizens requiring deviations. For example, if they find a dead body in their apartment they may not worry quite so much about getting to work on time!

In addition to having a routine and places to go, they also need to record what/who they’ve seen. This is in case they are relevant to one of your investigations and you decide to question them. Most ‘memories’ the citizens form are sightings- these are triggered by a global check that loops through travelling citizens and checks if they can see one another:

The green lines represent citizens seeing each other, the red ones means they have met/are familiar with each other.

Citizens can also see into windows across the street adjacent to their own if the light is on- this means in certain circumstances you may wish to question the occupants of an apartment in an adjacent building for example. It’s systems like this that can help broaden the logical options available to the player, and hopefully makes the open-ended detective work satisfying!

Citizen memories start off by being pretty much 100% accurate, but over time they become fuzzier. How long memories last depends on a large variety of factors- for example, if and how well they know the other person, their visual distinctiveness, whether they were behaving strangely, how good the citizen’s memory is in general (can be affected by age), and even the alertness level of the witness.

As memories fade, time accuracy is reduced up until the point the memory is lost completely, and therefore won’t surface when you question someone. This creates a natural time pressure within your investigation- you’re going to want to discover and question your witnesses as efficiently as possible so their memories are fresh in their mind and you can get the most accurate picture of what happened.

You may need to be wary. If the citizens know their presence at a certain place looks bad for them (they may have been near the scene of the crime and have no witnesses to back them up) they may actually choose to lie or bend the truth to avoid being treated as suspicious, even if they actually are innocent! Most innocent citizens will be more inclined to tell the truth however. Lying is whole other kettle of fish that I still need to explore in detail to find what works.

You’re not always going to need to go to searching for witnesses either. After a press release and appeal for information, you may get witnesses reaching out to you. Spending more of your resources in getting the word out about your investigation may increase the chance of this. It’s your case and it’s completely down to you how you want to handle it! Freedom in this respect is this game’s killer feature.

Facebook
RSS

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.