Decision Making Overview

From Valve Developer Community
Revision as of 16:29, 6 March 2008 by Beeswax (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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:
  1. They finish performing their last schedule
  2. 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:
  1. Find a position to take cover at
  2. Generate a path to that position
  3. Run the path
  4. 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.