For the humble NPC, decision-making is easy. You have five options; choose one.
But for the programmer, this process is much more difficult. We wanted to find out why.
General Process a step-by-step guide
Sense | Sense the environment and gather data A list of things and sounds the NPC can see and hear is generated, and only the important ones are placed into their respective lists.
Generate | Generate a list of conditions based upon gathered data A list of conditions (key pieces of information that will be used to make a decision) is generated based upon the sensed data, the environment, and the NPC; examples of conditions would be I have taken damage, I have no more arrows, and I have low health.
Choose | An appropriate state is chosen, based upon the conditions The conditions then determine what state the NPC is in; examples include dropping toAlert when the NPC has killed and there are no more enemies, being in Combat mode when there is a visible enemy, and moving to Dead when health is 0.
Follow | The NPC follows a selected schedule, based upon the conditoons and the state The schedule is a goal that the NPC sets out to accomplish by completing a series of tasks, which is determined by the information it has gathered and the state it's currently in. Goals may be attacking an enemy, reloading a gun, or running after an opponent. Schedules will change when a schedule-specific interrupt condition is generated or when the schedule is completed.
Complete | Schedules are accomplished by the completion of smaller tasks The schedule is made up of a series of tasks that are completed one-by-one. If the schedule is taking cover to reload gun, the associated tasks may be: -Find a position to take cover at -Generate a path to reach that position -Run the path -Reload gun
When the tasks are complete, a new schedule will be chosen.
Decisions with Behavior Trees
Behaviour Tree | A hierarchal way of organizing behaviors and sub-behaviours to make decisions
Branches in the tree are composite behaviors, which decide what child behavior to run when, and leaf nodes check conditions. These trees are subdivided into trees modelling sub-behaviours, and they are run through to determine the best action, complete the action via tasks, and determine priority of behaviours. See example at right.
Rather than trying to solve a massive problem all at once, behavior trees enable the computer to deal with several little problems, which lead to other small solutions that are then layered together to solve one complex problem. Not only is this easier for the computer, but this means the programmer doesn't have to code specifically for a landslide of "special cases." This also means that the AI is incredibly more flexible when dealing with several different possible scenarios.