From Valve Developer Community
Revision as of 11:37, 3 August 2005 by Fluxtah (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

A Schedule is basically a list of Tasks the NPC is to perform, a schedule could be to go to a specific location, such as SCHED_FORCED_GO or a schedule to create an attack plan SCHED_PLAN_ATTACK. The NPC's schedule selection is governed by it's current State and Conditions.

Some interesting methods are shown below that make up CAI_BaseNPC class.


In CAI_BaseNPC the method SelectSchedule() determines what schedule the NPC should run depending on its state and conditions.

In CAI_BaseNPC, all of the default States are considered, and additional methods are called to select the schedule based on condition, for example, when the NPC is in the NPC_STATE_IDLE, the method SelectIdleSchedule() is called, this method is similar to SelectSchedule(), all it does is select a schedule based on the npc's state and conditions.

Child classes can implement these schedule selection methods to select their own custom schedules based on their own custom conditions.

For instance, we could create our own schedule SCHED_MEDICALPOINT_GO and a condition COND_NEEDS_MEDICAL_ASSISTANCE.

We could implement the schedule selection in SelectSchedule() or a schedule selection method variation as follows



The following switch statement has been taken from SelectSchedule() in CAI_BaseNPC, it shows how the different variations of schedule selection is chosen depending on the NPC's state.


switch( m_NPCState ) {

     case NPC_STATE_NONE: 
           DevWarning( 2, "NPC_STATE IS NONE!\n" ); 
     case NPC_STATE_PRONE: 
           return SCHED_IDLE_STAND; 
     case NPC_STATE_IDLE: 
           AssertMsgOnce( GetEnemy() == NULL, "NPC has enemy but is not in combat state?" ); 
           return SelectIdleSchedule(); 
     case NPC_STATE_ALERT: 
           AssertMsgOnce( GetEnemy() == NULL, "NPC has enemy but is not in combat state?" ); 
           return SelectAlertSchedule(); 
     case NPC_STATE_COMBAT: 
           return SelectCombatSchedule(); 
     case NPC_STATE_DEAD: 
           return SelectDeadSchedule(); 
     case NPC_STATE_SCRIPT: 
           return SelectScriptSchedule(); 
           DevWarning( 2, "Invalid State for SelectSchedule!\n" ); 



This method is called after the schedule selection, it can be used to translate parent NPC schedules to child specific schedules, it's useful if you want to change the default schedules to run your own ones instead.