23 #ifndef __NPCBEHAVE_H__ 24 #define __NPCBEHAVE_H__ 28 #include <csgeom/matrix3.h> 29 #include <csutil/array.h> 30 #include <iutil/document.h> 225 bool Load(iDocumentNode* node);
226 bool Load(iResultRow &node);
229 return name.GetDataSafe();
241 return behaviors.
Find(name);
261 csString InfoReactions(
NPC* npc);
267 void DumpReactionList(csString &output,
NPC* npc);
284 float GetAngularVelocity(
NPC* npc);
290 float GetVelocity(
NPC* npc);
298 const csString &GetCollisionPerception()
const;
304 const csString &GetOutOfBoundsPerception()
const;
310 const csString &GetInBoundsPerception()
const;
314 const csString &GetFallingPerception()
const;
322 void AddReaction(
Reaction* reaction);
328 void InsertReaction(
Reaction* reaction);
392 bool Load(iDocumentNode* node);
394 bool LoadScript(iDocumentNode* node,
bool top_level=
true);
396 void UpdateNeed(
float delta,
NPC* npc);
416 void CommitAdvance();
428 void ApplyNeedDelta(
NPC* npc,
float deltaDesire);
442 void ApplyNeedAbsolute(
NPC* npc,
float absoluteDesire);
460 void SetCurrentStep(
int step);
467 return sequence.GetSize();
471 current_need = new_need = init_need;
474 bool ApplicableToNPCState(
NPC* npc);
475 void DoCompletionDecay(
NPC* npc);
478 void StartScript(
NPC* npc);
481 void OperationCompleted(
NPC* npc);
484 void OperationFailed(
NPC* npc);
486 void InterruptScript(
NPC* npc);
497 this->completion_decay = completion_decay;
512 if(strcmp(name,other.
name)>0)
521 this->need_decay_rate = need_decay_rate;
526 this->need_growth_rate = need_growth_rate;
531 this->init_need = init_need;
552 static void GetPosition(
gemNPCObject*
object, csVector3 &pos,
float &yrot, iSector* §or);
560 static void GetPosition(
gemNPCObject*
object, csVector3 &pos, iSector* §or);
562 static void SetPosition(
gemNPCObject* objecty,
const csVector3 &pos, iSector* = NULL);
563 static void SetRotationAngle(
gemNPCObject*
object,
float angle);
568 GetPosition(
object,pos,yrot,sector);
573 static float CalculateIncidentAngle(
const csVector3 &pos,
const csVector3 &dest);
576 static void ClampRadians(
float &target_angle);
579 static void NormalizeRadians(
float &target_angle);
581 static csVector3 DisplaceTargetPos(
const iSector* mySector,
const csVector3 &myPos,
582 const iSector* targetSector,
const csVector3 &targetPos,
584 static csVector3 DisplaceTargetPos(
const iSector* mySector,
const csVector3 &myPos,
585 const iSector* targetSector,
const csVector3 &targetPos,
586 float offset,
float angle);
588 static float Calc2DDistance(
const csVector3 &a,
const csVector3 &b);
598 static csString ReplaceNPCVariables(
NPC* npc,
const csString &
object);
608 static bool ReplaceNPCVariablesBool(
NPC* npc,
const csString &
object);
This is the base class for all operations in action scripts.
csString collisionPerception
Global perception value for falling.
This embodies any perception an NPC might have, or any game event of interest.
csString failurePerception
Perception to fire if any operation fails without own failure perception.
void DeepCopy(BehaviorSet &other)
Do a deap copy.
csString fallingPerception
Global perception value for falling.
csPDelArray< Behavior > behaviors
The set of behavoirs for this NPCType.
Behavior * SetGrowth(float need_growth_rate)
float current_need
The current need of this behavior after last advance.
csString InfoBehaviors(NPC *npc)
Info about the behavior list for debug.
void DumpBehaviorList(csString &output, NPC *npc)
Behavior * GetCurrentBehavior()
Return current active behavior.
bool is_applicable_when_dead
csString interruptPerception
Perception to fire if interrupted.
float need_decay_rate
need lessens while performing behavior
float GetHighestNeed(NPC *npc)
Return hight current or new need.
A set of operations building a generic behavior for a NPC.
float ang_vel
Default ang_vel for this NPCType. < Will be used for all behaviors unless overriden < by each behavio...
A waypoint is a specified circle on the map with a name, location, and a list of waypoints it is conn...
bool resume_after_interrupt
Resume at active step after interrupt.
float completion_decay
need lessens AFTER behavior script is complete. Use -1 to remove all need
csString name
The name of this behavior.
csPDelArray< Reaction > reactions
The reactions available for this NPCType.
void Advance(csTicks delta, NPC *npc)
Advances the behaviors.
bool Add(Behavior *behavior)
Add a behavior to the brain.
Behavior * SetDecay(float need_decay_rate)
void DumpBehaviorList(csString &output, NPC *npc)
Dump the behavior list for debug.
csString InfoBehaviors(NPC *npc)
Used to indicate that an behavior has more steps.
float need_growth_rate
need grows while not performing behavior
Behavior * Find(const char *name)
Find a behavior in the set.
bool interrupted
Set to true if this behavior is interruped by another in a BehaviorSet.
bool minLimitValid
True if a minimum limit for the need for this behavior has been set.
This behavior will complete at a later stage.
csString outOfBoundsPerception
Global perception value for falling.
void UpdateNeeds(float delta, NPC *npc)
Update needs for all behaviors.
bool maxLimitValid
True if a maximum limit for the need for this behavior has been set.
Behavior * GetCurrentBehavior()
csPDelArray< ScriptOperation > sequence
Sequence of ScriptOperations.
void Interrupt(NPC *npc)
Interrupt the current active behavior.
A reaction embodies the change in desire which occurs in an NPC when he perceives something...
NPC * npc
Pointer to the NPC for this brain.
float new_need
The accumulated change to the need after last advance.
This object represents each NPC managed by this superclient.
Behavior * Find(const char *name)
Find a behavior in the set.
float init_need
starting need, also used in ClearState resets
BehaviorSet behaviors
The set of behaviors available for this NPCType.
csString inBoundsPerception
Global perception value for falling.
size_t current_step
The ScriptOperation in the sequence that is currently executed.
A collection of behaviors and reactions will represent a type of npc.
Behavior * Schedule(NPC *npc)
Rearrange the behavior set based on need.
void Execute(NPC *npc, bool forceRunScript)
Execute script operations.
Behavior * SetCompletionDecay(float completion_decay)
void SetIsActive(bool flag)
float minLimit
The minimum value to limit the need if minLimitValid has been set true.
size_t stepCount
The number of script operation done in this periode.
bool loop
True if this behavior should start over when completed all operations.
bool IsActive()
Used to check if the behavior is active.
void ClearState(NPC *npc)
Prepare the set after use.
bool operator<(Behavior &other)
Behavior * SetInitial(float init_need)
csString name
The name of this NPC type.
static void GetRotationAngle(gemNPCObject *object, float &yrot)
This is the set of Behaviors available for an NPC.
BehaviorSet()
Constructor.
This class handles all queueing and invoking of timed events, such as combat, spells, NPC dialog responses, range weapons, or NPC respawning.
bool operator==(const Behavior &other)
Behavior * active
Points to the current active behavior.
float maxLimit
The maximum value to limit the need if maxLimitValid has been set true.
bool isActive
Set to true when this behavior is active.