Decision Making Overview

From Valve Developer Community
Revision as of 22:43, 16 August 2006 by Robin Walker (talk | contribs) (Moved from the old AI Programming page.)
(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 does the following:

  • Perform Sensing
    • The NPC generates a list of entities that it can see, and another list of NPC sounds that it can hear. The NPC ignores entities & sounds that it doesn't care about, and hence doesn't place them into the lists.
  • 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. Examples of conditions are: "I can see an enemy", "I have taken some damage", or "My weapon's clip is empty".
  • Choose an appropriate State
    • The NPC State is the overall assessment of the NPC based upon the list of Conditions. For example: NPCs with a visible enemy will consider themselves in Combat State. NPCs who have no enemies left after killing one will drop back to Alert State. NPCs with a health of 0 would move to Dead State.
  • Select a new Schedule if appropriate
    • The Schedule is the overall action being taken by the NPC, which is then broken down into sub parts for the NPC to actually perform. Schedules are chosen based upon the NPCs current State, and the list of Conditions. Examples of schedules are: "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 the last part of the current schedule.
      • They generate a condition that their current schedule has specified as an Interrupt.
    • If neither of these are true, the NPC will continue running its current schedule.
  • Perform the current Task
    • The Task is the sub part of a Schedule that describes a discrete action within the schedule. The 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", and then "Reload my gun".
    • Many tasks take some time to perform (like the "Run the path" task in the above example), 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.