Decision Making Overview
From a high-level perspective, NPCs follow a fairly simple (and real-world logical) process for making decisions. The easiest way to understand it is to examine the basic outline first, and then dig further into the necessary exceptions afterwards.
Each time an NPC thinks, it follows this routine:
- Perform Sensing
- NPC Sensing generates a list of entities that it can see, and another list of NPC sounds that it can hear. The NPC ignores entities and sounds that it doesn't care about.
- Generate a list of Conditions
- Conditions are key pieces of information that the NPC will be using to make a decision. They are extracted from the sensed lists of entities & sounds, and from the state of the world and the NPC. Conditions might include:
- I can see an enemy
- I have taken some damage
- My weapon's clip is empty
- Choose an appropriate State
- The State is the overall assessment of the NPC based upon the list of Conditions. For example:
- NPCs with a visible enemy enter Combat
- NPCs who have no enemies left will drop back to Alert
- NPCs with a health of 0 would move to Dead
- Select a new Schedule if appropriate
- The Schedule is the overall action being taken by the NPC, which is then broken down into Tasks (see below) for the NPC to actually perform. Schedules are chosen based upon the NPC's current State and Conditions. Examples might include:
- I'm taking cover to reload my gun
- I'm chasing after my enemy
- I'm moving to a position where I have line-of-sight to my enemy
- NPCs will choose a new schedule for one of two reasons:
- They finish performing their last schedule
- They generate a condition that their current schedule has specified as an Interrupt
- Perform the current Task
- The Task is a component of a Schedule that describes a discrete action. Tasks must be performed one by one for the schedule to be completed. For example, the "I'm taking cover to reload my gun" schedule would be broken down into the following tasks:
- Find a position to take cover at
- Generate a path to that position
- Run the path
- Reload my gun
- Many tasks, like the one above, take time to perform, so the NPC will keep performing that task each time it thinks until the task is completed. Then, it'll move onto then next task in the current schedule, or pick a new schedule if there are no tasks left. If a task fails, the schedule fails.