Condition: Difference between revisions
No edit summary |
No edit summary |
||
Line 3: | Line 3: | ||
An example of a condition is <code>COND_LIGHT_DAMAGE</code> which may cause the NPC to go to an alert state and select a schedule appropriate to this condition. | An example of a condition is <code>COND_LIGHT_DAMAGE</code> which may cause the NPC to go to an alert state and select a schedule appropriate to this condition. | ||
NPC's can implement their own custom conditions to deal with things unique to that NPC, for instance, you could use a COND_ON_FIRE to determine if the NPC is on fire and select specific schedules on this condition such as SCHED_JUMP_IN_WATER. | NPC's can implement their own custom conditions to deal with things unique to that NPC, for instance, you could use a COND_ON_FIRE to determine if the NPC is on fire and select specific schedules on this condition such as <code>SCHED_JUMP_IN_WATER</code>. | ||
An interesting method is the <code>GatherConditions()</code> method, it can be overridden in child classes to implement the selection of custom conditions, the method basically sets the NPC's conditions appropriate at the time based on game state. | An interesting method is the <code>GatherConditions()</code> method, it can be overridden in child classes to implement the selection of custom conditions, the method basically sets the NPC's conditions appropriate at the time based on game state. | ||
Line 18: | Line 18: | ||
This if block checks to see if the headcrab is alive but submerged in water, if so a condition COND_HEADCRAB_IN_WATER is set, this is probably then handled in <code>SelectSchedule()</code> to choose the appropriate schedule that will end up drowning the headcrab. | This if block checks to see if the headcrab is alive but submerged in water, if so a condition <code>COND_HEADCRAB_IN_WATER</code> is set, this is probably then handled in <code>SelectSchedule()</code> to choose the appropriate schedule that will end up drowning the headcrab. |
Revision as of 12:43, 3 August 2005
Multiple conditions can be set on an NPC which help the NPC determine what schedule should be run (handled in SelectSchedule()
or variants).
An example of a condition is COND_LIGHT_DAMAGE
which may cause the NPC to go to an alert state and select a schedule appropriate to this condition.
NPC's can implement their own custom conditions to deal with things unique to that NPC, for instance, you could use a COND_ON_FIRE to determine if the NPC is on fire and select specific schedules on this condition such as SCHED_JUMP_IN_WATER
.
An interesting method is the GatherConditions()
method, it can be overridden in child classes to implement the selection of custom conditions, the method basically sets the NPC's conditions appropriate at the time based on game state.
The following condition has been taken from the headcrabs GatherConditions()
method.
if( m_lifeState == LIFE_ALIVE && GetWaterLevel() > 1 ) { // Start Drowning! SetCondition( COND_HEADCRAB_IN_WATER ); }
This if block checks to see if the headcrab is alive but submerged in water, if so a condition COND_HEADCRAB_IN_WATER
is set, this is probably then handled in SelectSchedule()
to choose the appropriate schedule that will end up drowning the headcrab.