Schedule: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Return of the Apostrophe Alignment Militia!)
No edit summary
Line 1: Line 1:
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 <code>SCHED_FORCED_GO</code> or a schedule to create an attack plan <code>SCHED_PLAN_ATTACK</code>. The NPC's schedule selection is governed by its current [[States|State]] and [[Conditions]].


Some interesting methods are described below that make up CAI_BaseNPC class.
'''SelectSchedule()'''
In <code>CAI_BaseNPC</code> the method <code>SelectSchedule()</code> determines what schedule the NPC should run depending on its state and conditions.
In <code>CAI_BaseNPC</code>, 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 <code>NPC_STATE_IDLE</code>, the method <code>SelectIdleSchedule()</code> is called, this method is similar to <code>SelectSchedule()</code>, 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 <code>SCHED_MEDICALPOINT_GO</code> and a condition <code>COND_NEEDS_MEDICAL_ASSISTANCE</code>.
We could implement the schedule selection in <code>SelectSchedule()</code> or a schedule selection method variation as follows
<pre>
if(HasCondition(COND_NEEDS_MEDICAL_ASSISTANCE))
    return SCHED_MEDICALPOINT_GO;
</pre>
The following switch statement has been taken from <code>SelectSchedule()</code> in <code>CAI_BaseNPC</code>, it shows how the different variations of schedule selection is chosen depending on the NPC's state.
<pre>
switch( m_NPCState )
{
      case NPC_STATE_NONE:
            DevWarning( 2, "NPC_STATE IS NONE!\n" );
            break;
     
      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();
      default:
            DevWarning( 2, "Invalid State for SelectSchedule!\n" );
            break;
}
</pre>
'''TranslateSchedule()'''
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.

Revision as of 16:32, 3 August 2005