45

Forensic Friday 45: Complete AI Overhaul (We are idiots)

It’s probably not a surprise by now but as the title says, yes - we are idiots. Let us explain…

NPC Behaviour #

Current Implementation #

NPC behaviour in our game has been based on a state machine. An NPC can have a state, whether that is sleeping, eating, or just wandering. When certain conditions are met, the state of an NPC will change, and they’ll start to do some predefined behaviour that we tell them to do. An example would be that when it is past 11pm, and an NPC has a bed, the NPC should pathfind to the bed and sleep.

Example of a state machine

This works completely fine for the most part, until weird scenarios start popping up. For instance (as a pure hypothetical), what happens if there’s an unexpected event such as an emergency at 11pm? In that case, we may have to go through our existing codebase, and make a check for this event, essentially micromanaging what an NPC can do at any one time within different parts of the codebase. Furthermore, NPCs can seem very robotic - in our example you know that at 11pm on the dot they are going to go to sleep no matter what.

Now it’s obvious that this isn’t a great long term plan, but we completely missed better alternative approaches - until right now. Introducing… Utility Systems aka Utility AI.

Utility AI #

Utility AI is a popular way to model behaviour of NPCs, found in games such as The Sims series. The main idea is that every NPC has a set of needs that they would want, which we are calling desires - such as rest, food or comfort. Each of these desires has a score associated with it, that are constantly decreasing at certain fine tuned rates, which increase when an related action is being performed. For example, one of the desires will be bladder, whereby when they go to the toilet, their score will increase. NPCs ideally want each desire to be as high as possible, so to replenish their scores, they can choose to do actions in the world to satisfy all their needs.

To get a list of possible actions, any object in the game can advertise themself as a “fix” for a desire - for example a toilet will advertise itself as “Use me to get +10 Bladder” or “Clean me to get +5 Tidiness”, or NPCs can offer themelves as a way to relieve (Social) desires.

The final step is every NPC looking at all the advertisements in the world, and ranking them from highest score to lowest score, using their own current scores, the distance away from the action, the amount the advertisement will satisfy a desire etc. This final ranking then helps to decide the NPC’s next action, by taking 1 of the top ranking actions - not always the top one, otherwise what’s the point of playing the game when it plays optimally for you? ;)

By giving NPCs different desires, we can simulate NPCs better than before, with unique personalities shining through more, and less predictable behaviour which still makes sense.

Why wasn’t this already a thing? #

See the title :’(

What does this mean for the roadmap? #

The biggest benefit is that this will cut down on future work immensely. New features can be added by just getting an object to advertise a particular desire, and NPCs will interact with them seamlessly - no touching of an ever growing code base needed. Therefore, this has been pushed to the top of our agenda in the coming weeks, with other development branches put on hold temporarily.

While this would push back the roadmap, we fully believe that in the long run, this will speed up development time AND make the NPCs in the game significantly better and life like. Therefore, we will be releasing a new roadmap after this is completed, but fingers crossed everything should be moving forwards - not back.

Other Game Development News #

With the headline out of the way, a smaller bit of news regarding Containment Procedures. Conditional statements have now been added to the GUI (see below).

An example of a containment procedure with 3 conditions

Multiple conditions can be chained together that will then allow you to define containment procedures depending on current conditions within your facility. The next part for Containment Procedures is the actual “action” part, whereby you can direct your NPC’s behaviours but… this may actually use Utility AI desires to implement this functionality rather than the whole kerfuffle of directing NPCs around the site. We hope you can see the immediate impact this new AI overhaul will have!

Case Closed #

As far as meaningful progress, this week has been pretty light. A mixture of personal commitments - including graduation ceremonies and celebrations - have left us a bit short for time, but the main part of this week has been designing the new Utility AI system which will change everything for the better. In the meantime, thank you for reading, and we’ll see you on Monday (hopefully not Tuesday) for the newest anomaly release!!

Case Closed.
The Team
Plasmarc Studios