Condition: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (clean up)
mNo edit summary
Line 5: Line 5:


NPC's can implement their own custom conditions to deal with things unique to that NPC, for instance, you could use a <code>COND_ON_FIRE</code> to determine if the NPC is on fire and select specific schedules on this condition such as <code>SCHED_JUMP_IN_WATER</code>.
NPC's can implement their own custom conditions to deal with things unique to that NPC, for instance, you could use a <code>COND_ON_FIRE</code> to determine if the NPC is on fire and select specific schedules on this condition such as <code>SCHED_JUMP_IN_WATER</code>.
==GatherConditions==
<code>GatherConditions</code> can be overridden in child classes to implement the selection of custom conditions; the function sets the NPC's conditions appropriate at the time based on game state.
The following condition has been taken from the headcrabs <code>GatherConditions()</code> method.
<pre>
if( m_lifeState == LIFE_ALIVE && GetWaterLevel() > 1 )
{
          // Start Drowning!
        SetCondition( COND_HEADCRAB_IN_WATER );
}
</pre>
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.
==BuildScheduleTestBits==
<code>BuildScheduleTestBits</code> can be overridden to set custom condition to interrupt schedules. If you want to see your NPC react to conditions, this needs to be overriden so the NPC reacts to fire (COND_ON_FIRE) or start drowing (COND_HEADCRAB_IN_WATER) right away, not after the current schedule ends.
Here is code from the headcrabs <code>BuildScheduleTestBits()</code>
<pre>
if ( !IsCurSchedule(SCHED_HEADCRAB_DROWN) )
{
// Interrupt any schedule unless already drowning.
SetCustomInterruptCondition( COND_HEADCRAB_IN_WATER );
}
else
{
// Don't stop drowning just because you're in water!
ClearCustomInterruptCondition( COND_HEADCRAB_IN_WATER );
}
</pre>
If the condition <code>COND_HEADCRAB_IN_WATER</code> is set, it interrupts the current schedule unless it is already drowning. Then this is handled in <code>SelectSchedule()</code> to choose the appropriate schedule (<code>SCHED_HEADCRAB_DROWN</code>) that will end up drowning the headcrab.
==See Also==
==See Also==
* [[Shared conditions]] - a list of conditions inherited by all NPCs
* [[Shared conditions]] - a list of conditions inherited by all NPCs

Revision as of 18:36, 10 June 2006

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.

See Also