Planeshift
Public Types | Public Member Functions | Protected Attributes

Behavior Class Reference

A set of operations building a generic behavior for a NPC. More...

#include <npcbehave.h>

List of all members.

Public Types

enum  BehaviorResult { BEHAVIOR_NOT_COMPLETED, BEHAVIOR_COMPLETED, BEHAVIOR_WILL_COMPLETE_LATER, BEHAVIOR_FAILED }

Public Member Functions

BehaviorResult Advance (float delta, NPC *npc)
bool ApplicableToNPCState (NPC *npc)
void ApplyNeedAbsolute (NPC *npc, float absoluteDesire)
 Set the new need of the behavior to the given desire.
void ApplyNeedDelta (NPC *npc, float deltaDesire)
 Update the new need of the behavior with a delta desire.
 Behavior ()
 Behavior (const char *n)
 Behavior (Behavior &other)
void ClearInterrupted ()
void CommitAdvance ()
 Update the current_need of the behavour after it has been advanced.
float CurrentNeed ()
void DeepCopy (Behavior &other)
void DoCompletionDecay (NPC *npc)
void Failure (NPC *npc, ScriptOperation *op)
 Called when a operation with no failure perception fails.
size_t GetCurrentStep ()
size_t GetLastStep ()
const char * GetName ()
void InterruptScript (NPC *npc)
bool IsActive ()
 Used to check if the behavior is active.
bool IsInterrupted ()
bool Load (iDocumentNode *node)
bool LoadScript (iDocumentNode *node, bool top_level=true)
float NewNeed ()
void OperationCompleted (NPC *npc)
 Handle stuff to do when an operation has completed.
void OperationFailed (NPC *npc)
 Handle stuff to do when an operation has failed.
bool operator< (Behavior &other)
bool operator== (const Behavior &other)
void ResetNeed ()
BehaviorSetCompletionDecay (float completion_decay)
void SetCurrentStep (int step)
BehaviorSetDecay (float need_decay_rate)
BehaviorSetGrowth (float need_growth_rate)
BehaviorSetInitial (float init_need)
void SetIsActive (bool flag)
void SetStartStep ()
void StartScript (NPC *npc)
 Prepare a script to be run.
void UpdateNeed (float delta, NPC *npc)
virtual ~Behavior ()

Protected Attributes

float completion_decay
 need lessens AFTER behavior script is complete. Use -1 to remove all need
float current_need
 The current need of this behavior after last advance.
size_t current_step
 The ScriptOperation in the sequence that is currently executed.
csString failurePerception
 Perception to fire if any operation fails without own failure perception.
float init_need
 starting need, also used in ClearState resets
bool interrupted
 Set to true if this behavior is interruped by another in a BehaviorSet.
csString interruptPerception
 Perception to fire if interrupted.
bool is_applicable_when_dead
bool isActive
 Set to true when this behavior is active.
bool loop
 True if this behavior should start over when completed all operations.
float maxLimit
 The maximum value to limit the need if maxLimitValid has been set true.
bool maxLimitValid
 True if a maximum limit for the need for this behavior has been set.
float minLimit
 The minimum value to limit the need if minLimitValid has been set true.
bool minLimitValid
 True if a minimum limit for the need for this behavior has been set.
csString name
 The name of this behavior.
float need_decay_rate
 need lessens while performing behavior
float need_growth_rate
 need grows while not performing behavior
float new_need
 The accumulated change to the need after last advance.
bool resume_after_interrupt
 Resume at active step after interrupt.
csPDelArray< ScriptOperationsequence
 Sequence of ScriptOperations.
size_t stepCount
 The number of script operation done in this periode.

Detailed Description

A set of operations building a generic behavior for a NPC.

A Behavior is a general activity of an NPC. Guarding, smithing, talking to a player, fighting, fleeing, eating, sleeping are all behaviors. They consists of a set of ScriptOperations loaded from file.

Definition at line 340 of file npcbehave.h.


Member Enumeration Documentation

Enumerator:
BEHAVIOR_NOT_COMPLETED 

Used to indicate that an behavior has more steps.

BEHAVIOR_COMPLETED 

This behavior completed.

BEHAVIOR_WILL_COMPLETE_LATER 

This behavior will complete at a later stage.

BEHAVIOR_FAILED 

The behavior failed.

Definition at line 344 of file npcbehave.h.


Constructor & Destructor Documentation

Behavior::Behavior ( )
Behavior::Behavior ( const char *  n)
Behavior::Behavior ( Behavior other)
virtual Behavior::~Behavior ( ) [inline, virtual]

Definition at line 384 of file npcbehave.h.


Member Function Documentation

BehaviorResult Behavior::Advance ( float  delta,
NPC npc 
)
bool Behavior::ApplicableToNPCState ( NPC npc)
void Behavior::ApplyNeedAbsolute ( NPC npc,
float  absoluteDesire 
)

Set the new need of the behavior to the given desire.

The need is set to the given desire. Ignoring whatever value the new need of the behavoir might have had previous.

Parameters:
npcInclude NPC for debug outputs.
absoluteDesireThe absolute desire to be used for this behavior
Note:
Will limit the new_need if limits has been given for the need of this behavior.
void Behavior::ApplyNeedDelta ( NPC npc,
float  deltaDesire 
)

Update the new need of the behavior with a delta desire.

The need is adjusted by the given delta value.

Parameters:
npcInclude NPC for debug outputs.
deltaDesireThe delta in desire for this behavior
Note:
Will limit the new_need if limits has been given for the need of this behavior.
void Behavior::ClearInterrupted ( ) [inline]

Definition at line 491 of file npcbehave.h.

void Behavior::CommitAdvance ( )

Update the current_need of the behavour after it has been advanced.

If the new_need has been updating during advance make the new_need the current need of this behavior. The current_need will allways be the value held right after last advance of the behavior. During advance and between advance the new_need will be updated by the advance function and reactions based on matched perceptions.

float Behavior::CurrentNeed ( ) [inline]

Definition at line 398 of file npcbehave.h.

void Behavior::DeepCopy ( Behavior other)
void Behavior::DoCompletionDecay ( NPC npc)
void Behavior::Failure ( NPC npc,
ScriptOperation op 
)

Called when a operation with no failure perception fails.

Will call the global failure perception for this operation if it exists.

size_t Behavior::GetCurrentStep ( ) [inline]

Definition at line 461 of file npcbehave.h.

size_t Behavior::GetLastStep ( ) [inline]

Definition at line 465 of file npcbehave.h.

const char* Behavior::GetName ( ) [inline]

Definition at line 386 of file npcbehave.h.

void Behavior::InterruptScript ( NPC npc)
bool Behavior::IsActive ( ) [inline]

Used to check if the behavior is active.

An active behavior is an behavior that will be advanced and decay in need.

Definition at line 455 of file npcbehave.h.

bool Behavior::IsInterrupted ( ) [inline]

Definition at line 487 of file npcbehave.h.

bool Behavior::Load ( iDocumentNode *  node)
bool Behavior::LoadScript ( iDocumentNode *  node,
bool  top_level = true 
)
float Behavior::NewNeed ( ) [inline]

Definition at line 402 of file npcbehave.h.

void Behavior::OperationCompleted ( NPC npc)

Handle stuff to do when an operation has completed.

void Behavior::OperationFailed ( NPC npc)

Handle stuff to do when an operation has failed.

bool Behavior::operator< ( Behavior other) [inline]

Definition at line 506 of file npcbehave.h.

bool Behavior::operator== ( const Behavior other) [inline]

Definition at line 501 of file npcbehave.h.

void Behavior::ResetNeed ( ) [inline]

Definition at line 469 of file npcbehave.h.

Behavior* Behavior::SetCompletionDecay ( float  completion_decay) [inline]

Definition at line 495 of file npcbehave.h.

void Behavior::SetCurrentStep ( int  step)
Behavior* Behavior::SetDecay ( float  need_decay_rate) [inline]

Definition at line 519 of file npcbehave.h.

Behavior* Behavior::SetGrowth ( float  need_growth_rate) [inline]

Definition at line 524 of file npcbehave.h.

Behavior* Behavior::SetInitial ( float  init_need) [inline]

Definition at line 529 of file npcbehave.h.

void Behavior::SetIsActive ( bool  flag) [inline]

Definition at line 444 of file npcbehave.h.

void Behavior::SetStartStep ( )
void Behavior::StartScript ( NPC npc)

Prepare a script to be run.

void Behavior::UpdateNeed ( float  delta,
NPC npc 
)

Member Data Documentation

need lessens AFTER behavior script is complete. Use -1 to remove all need

Definition at line 362 of file npcbehave.h.

The current need of this behavior after last advance.

Definition at line 367 of file npcbehave.h.

size_t Behavior::current_step [protected]

The ScriptOperation in the sequence that is currently executed.

Definition at line 355 of file npcbehave.h.

csString Behavior::failurePerception [protected]

Perception to fire if any operation fails without own failure perception.

Definition at line 376 of file npcbehave.h.

starting need, also used in ClearState resets

Definition at line 363 of file npcbehave.h.

bool Behavior::interrupted [protected]

Set to true if this behavior is interruped by another in a BehaviorSet.

Definition at line 370 of file npcbehave.h.

csString Behavior::interruptPerception [protected]

Perception to fire if interrupted.

Definition at line 365 of file npcbehave.h.

Definition at line 359 of file npcbehave.h.

bool Behavior::isActive [protected]

Set to true when this behavior is active.

Definition at line 358 of file npcbehave.h.

bool Behavior::loop [protected]

True if this behavior should start over when completed all operations.

Definition at line 357 of file npcbehave.h.

The maximum value to limit the need if maxLimitValid has been set true.

Definition at line 375 of file npcbehave.h.

bool Behavior::maxLimitValid [protected]

True if a maximum limit for the need for this behavior has been set.

Definition at line 374 of file npcbehave.h.

The minimum value to limit the need if minLimitValid has been set true.

Definition at line 373 of file npcbehave.h.

bool Behavior::minLimitValid [protected]

True if a minimum limit for the need for this behavior has been set.

Definition at line 372 of file npcbehave.h.

csString Behavior::name [protected]

The name of this behavior.

Definition at line 352 of file npcbehave.h.

need lessens while performing behavior

Definition at line 360 of file npcbehave.h.

need grows while not performing behavior

Definition at line 361 of file npcbehave.h.

The accumulated change to the need after last advance.

Definition at line 368 of file npcbehave.h.

Resume at active step after interrupt.

Definition at line 364 of file npcbehave.h.

csPDelArray<ScriptOperation> Behavior::sequence [protected]

Sequence of ScriptOperations.

Definition at line 354 of file npcbehave.h.

size_t Behavior::stepCount [protected]

The number of script operation done in this periode.

Definition at line 356 of file npcbehave.h.


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