Planeshift
BehaviorSet Class Reference

This is the set of Behaviors available for an NPC. More...

#include <npcbehave.h>

Public Member Functions

bool Add (Behavior *behavior)
 Add a behavior to the brain. More...
 
void Advance (csTicks delta, NPC *npc)
 Advances the behaviors. More...
 
 BehaviorSet ()
 Constructor. More...
 
void ClearState (NPC *npc)
 Prepare the set after use. More...
 
void DeepCopy (BehaviorSet &other)
 Do a deap copy. More...
 
void DumpBehaviorList (csString &output, NPC *npc)
 Dump the behavior list for debug. More...
 
void Execute (NPC *npc, bool forceRunScript)
 Execute script operations. More...
 
BehaviorFind (const char *name)
 Find a behavior in the set. More...
 
BehaviorGetCurrentBehavior ()
 Return current active behavior. More...
 
float GetHighestNeed (NPC *npc)
 Return hight current or new need. More...
 
csString InfoBehaviors (NPC *npc)
 Info about the behavior list for debug. More...
 
void Interrupt (NPC *npc)
 Interrupt the current active behavior. More...
 
BehaviorSchedule (NPC *npc)
 Rearrange the behavior set based on need. More...
 
void UpdateNeeds (float delta, NPC *npc)
 Update needs for all behaviors. More...
 

Protected Attributes

Behavioractive
 Points to the current active behavior. More...
 
csPDelArray< Behaviorbehaviors
 The set of behavoirs for this NPCType. More...
 

Detailed Description

This is the set of Behaviors available for an NPC.

This is a collection of behaviors for a particular type of NPC. They represents the behaviors that this NPC is capable of.

Definition at line 69 of file npcbehave.h.

Constructor & Destructor Documentation

BehaviorSet::BehaviorSet ( )

Constructor.

Member Function Documentation

bool BehaviorSet::Add ( Behavior behavior)

Add a behavior to the brain.

Add a new behavior to the set. If a behavior with the same name exists, than the new behavior will substitude the existing behavior. This to support the nested structure of the behavoir scripts.

Parameters
behaviorThe new behavior to be added to this BehaviorSet.
Returns
Returns true if the behavior didn't already exist. Otherwise returns false and substitude the existing duplicate behavior.
void BehaviorSet::Advance ( csTicks  delta,
NPC npc 
)

Advances the behaviors.

Will calculate the need and select the active behavior.

Parameters
deltaThe numbers of ticks to advance this set.
npcThe NPC that own this BehaviorSet.
void BehaviorSet::ClearState ( NPC npc)

Prepare the set after use.

Called when the npc actor is deleted. Should reset all session depended stats. So that a new instance of the actor for the npc can start with a fresh brain.

Parameters
npcThe NPC that own this BehaviorSet.
void BehaviorSet::DeepCopy ( BehaviorSet other)

Do a deap copy.

Will do a deap copy of the BehaviorSet. The NPCType will contain a complete BehaviorSet for each type. When a new NPC is instantiated a deap copy of the set will be done before assigning it to the new NPC.

Parameters
otherThe source to be copied into this set.
void BehaviorSet::DumpBehaviorList ( csString &  output,
NPC npc 
)

Dump the behavior list for debug.

Parameters
npcThe NPC that own this BehaviorSet.
void BehaviorSet::Execute ( NPC npc,
bool  forceRunScript 
)

Execute script operations.

Will run script operations until they loop, fail, or need more time.

Parameters
npcThe NPC that own this BehaviorSet.
forceRunScriptForce running the script.
Behavior* BehaviorSet::Find ( const char *  name)

Find a behavior in the set.

Search the set for a behavior maching the given name.

Parameters
nameThe name of the behavior to find.
Returns
The found behavior or NULL if no behavior is found.
Behavior* BehaviorSet::GetCurrentBehavior ( )
inline

Return current active behavior.

Definition at line 167 of file npcbehave.h.

float BehaviorSet::GetHighestNeed ( NPC npc)

Return hight current or new need.

csString BehaviorSet::InfoBehaviors ( NPC npc)

Info about the behavior list for debug.

Parameters
npcThe NPC that own this BehaviorSet.
void BehaviorSet::Interrupt ( NPC npc)

Interrupt the current active behavior.

If there is an active behavior in this set that behavior will be interrupted by calling this function.

Parameters
npcThe NPC that own this BehaviorSet.
Behavior* BehaviorSet::Schedule ( NPC npc)

Rearrange the behavior set based on need.

Parameters
npcThe NPC that own this BehaviorSet.
void BehaviorSet::UpdateNeeds ( float  delta,
NPC npc 
)

Update needs for all behaviors.

Increase or decrease needs depended on the behaviors active state.

Parameters
deltaThe delta to add to the need for this behavior.
npcThe NPC that own this BehaviorSet.

Member Data Documentation

Behavior* BehaviorSet::active
protected

Points to the current active behavior.

Definition at line 73 of file npcbehave.h.

csPDelArray<Behavior> BehaviorSet::behaviors
protected

The set of behavoirs for this NPCType.

Definition at line 72 of file npcbehave.h.


The documentation for this class was generated from the following file: