State: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
The NPC's State and [[Conditions|Condition]], helps the NPC decide on an ideal [[Schedule]]. At any given time the NPC will only ever be in one state. | The NPC's State and [[Conditions|Condition]], helps the NPC decide on an ideal [[Schedule]]. At any given time the NPC will only ever be in one state. | ||
< | <pre> | ||
NPC_STATE_INVALID | NPC_STATE_INVALID | ||
NPC_STATE_NONE | NPC_STATE_NONE | ||
Line 11: | Line 11: | ||
NPC_STATE_PRONE | NPC_STATE_PRONE | ||
NPC_STATE_DEAD | NPC_STATE_DEAD | ||
</ | </pre> | ||
One interesting method that deals with states is the SelectIdealState() method. | One interesting method that deals with states is the SelectIdealState() method. This method chooses a state based on it's current state and conditions. | ||
The method implementation has a switch statement that reverts Ideal state selection to specific functions to the current state. | The method implementation has a switch statement that reverts Ideal state selection to specific functions to the current state. | ||
< | <pre> | ||
switch ( m_NPCState ) | switch ( m_NPCState ) | ||
{ | { | ||
Line 60: | Line 58: | ||
return NPC_STATE_DEAD; | return NPC_STATE_DEAD; | ||
} | } | ||
</pre> | |||
</ | |||
We can see the switch statement in the case of NPC_STATE_IDLE state selection will be reverted to SelectIdleIdealState() method. | We can see the switch statement in the case of NPC_STATE_IDLE state selection will be reverted to SelectIdleIdealState() method. |
Revision as of 12:20, 3 August 2005
The NPC's State and Condition, helps the NPC decide on an ideal Schedule. At any given time the NPC will only ever be in one state.
NPC_STATE_INVALID NPC_STATE_NONE NPC_STATE_IDLE NPC_STATE_ALERT NPC_STATE_COMBAT NPC_STATE_SCRIPT NPC_STATE_PLAYDEAD NPC_STATE_PRONE NPC_STATE_DEAD
One interesting method that deals with states is the SelectIdealState() method. This method chooses a state based on it's current state and conditions.
The method implementation has a switch statement that reverts Ideal state selection to specific functions to the current state.
switch ( m_NPCState ) { case NPC_STATE_IDLE: { NPC_STATE nState = SelectIdleIdealState(); if ( nState != NPC_STATE_INVALID ) return nState; } break; case NPC_STATE_ALERT: { NPC_STATE nState = SelectAlertIdealState(); if ( nState != NPC_STATE_INVALID ) return nState; } break; case NPC_STATE_COMBAT: { // COMBAT goes to ALERT upon death of enemy if ( GetEnemy() == NULL ) { return NPC_STATE_ALERT; } break; } case NPC_STATE_SCRIPT: { NPC_STATE nState = SelectScriptIdealState(); if ( nState != NPC_STATE_INVALID ) return nState; } break; case NPC_STATE_DEAD: return NPC_STATE_DEAD; }
We can see the switch statement in the case of NPC_STATE_IDLE state selection will be reverted to SelectIdleIdealState() method.