Planeshift
reaction.h
Go to the documentation of this file.
1 /*
2 * reaction.h by Anders Reggestad <andersr@pvv.org>
3 *
4 * Copyright (C) 2013 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5 *
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation (version 2 of the License)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 */
19 
20 #ifndef __REACTION_H__
21 #define __REACTION_H__
22 
23 //=============================================================================
24 // Crystal Space Includes
25 //=============================================================================
26 #include <csutil/csstring.h>
27 #include <csutil/array.h>
28 #include <iutil/document.h>
29 
30 //=============================================================================
31 // Library Includes
32 //=============================================================================
33 #include "util/psconst.h"
34 #include "util/mathscript.h"
35 
40 class Perception;
41 class Behavior;
42 class NPC;
43 class BehaviorSet;
44 class gemNPCObject;
45 
46 
51 class Reaction
52 {
53 protected:
54  friend class NPCType;
55 
56  // members making up the "if statement"
57  csString eventType;
58  float range;
60  csString oper;
61  csString condition;
63  bool activeOnly;
68  csArray<bool> valuesValid;
69  csArray<int> values;
70  csArray<bool>randomsValid;
71  csArray<int> randoms;
72  csString type;
73  csArray<csString> onlyInterrupt;
74  csArray<csString> doNotInterrupt;
75 
76  // members making up the "then statement"
77  csArray<Behavior*> affected;
78 
80  {
85  };
86 
88  float desireValue;
89  float weight;
90 
91  csString lastTriggered;
92 
93 public:
94  Reaction();
96  {
97  DeepCopy(other,behaviors);
98  }
99 
100  void DeepCopy(Reaction &other, BehaviorSet &behaviors);
101 
102  bool Load(iDocumentNode* node, BehaviorSet &behaviors);
103  void React(NPC* who, Perception* pcpt);
104 
113  bool ShouldReact(gemNPCObject* entity);
114 
121  bool DoNotInterrupt(Behavior* behavior);
122 
132  bool OnlyInterrupt(Behavior* behavior);
133 
134  const csString &GetEventType() const;
135  float GetRange()
136  {
137  return range;
138  }
140  {
141  return factionDiff;
142  }
143  bool GetValueValid(int i);
144  int GetValue(int i);
145  bool GetRandomValid(int i);
151  bool SetValue(int i, int value);
152  csString GetValue();
153  int GetRandom(int i);
154  const csString GetType(NPC* npc) const;
155  char GetOp();
156  csString GetAffectedBehaviors();
157  const csString &GetLastTriggerd()
158  {
159  return lastTriggered;
160  }
161 
162 };
163 
166 #endif
167 
bool GetRandomValid(int i)
float GetRange()
Definition: reaction.h:135
This embodies any perception an NPC might have, or any game event of interest.
Definition: perceptions.h:55
csString eventType
Definition: reaction.h:57
const csString GetType(NPC *npc) const
DesireType
Definition: reaction.h:79
bool reactWhenInvisible
Definition: reaction.h:66
csString GetAffectedBehaviors()
float weight
The weight to apply to deltas.
Definition: reaction.h:89
A MathScript is a mini-program to run.
Definition: mathscript.h:442
csString condition
Definition: reaction.h:61
int GetRandom(int i)
csArray< Behavior * > affected
Definition: reaction.h:77
csArray< bool > randomsValid
Definition: reaction.h:70
int GetFactionDiff()
Definition: reaction.h:139
bool SetValue(int i, int value)
Setting the value.
A set of operations building a generic behavior for a NPC.
Definition: npcbehave.h:340
bool ShouldReact(gemNPCObject *entity)
Check if the player should react to this reaction.
csString type
Definition: reaction.h:72
void React(NPC *who, Perception *pcpt)
bool inactiveOnly
Definition: reaction.h:64
bool Load(iDocumentNode *node, BehaviorSet &behaviors)
char GetOp()
bool DoNotInterrupt(Behavior *behavior)
Check if this is a behavior that shouldn&#39;t be interrupted.
csString lastTriggered
Used for debug, show when this was last triggered.
Definition: reaction.h:91
csArray< csString > doNotInterrupt
Definition: reaction.h:74
bool GetValueValid(int i)
DesireType desireType
Indicate the type of desire change this reaction has.
Definition: reaction.h:87
int factionDiff
Definition: reaction.h:59
A reaction embodies the change in desire which occurs in an NPC when he perceives something...
Definition: reaction.h:51
MathScript * calcCondition
This is the particular calculation for condition.
Definition: reaction.h:62
NPC * npc
Pointer to the NPC for this brain.
Definition: npcbehave.h:200
csArray< int > values
Definition: reaction.h:69
csArray< bool > valuesValid
Definition: reaction.h:68
This object represents each NPC managed by this superclient.
Definition: npc.h:126
csString GetValue()
bool OnlyInterrupt(Behavior *behavior)
Check if this is a behavior is on the only interrupt list if set.
bool activeOnly
Definition: reaction.h:63
BehaviorSet behaviors
The set of behaviors available for this NPCType.
Definition: npcbehave.h:203
csArray< int > randoms
Definition: reaction.h:71
const csString & GetLastTriggerd()
Definition: reaction.h:157
csArray< csString > onlyInterrupt
Definition: reaction.h:73
csString oper
Definition: reaction.h:60
A collection of behaviors and reactions will represent a type of npc.
Definition: npcbehave.h:197
bool reactWhenInvincible
Definition: reaction.h:67
float desireValue
The value to use for the desire type.
Definition: reaction.h:88
bool reactWhenDead
Definition: reaction.h:65
Reaction(Reaction &other, BehaviorSet &behaviors)
Definition: reaction.h:95
This is the set of Behaviors available for an NPC.
Definition: npcbehave.h:69
float range
Definition: reaction.h:58
void DeepCopy(Reaction &other, BehaviorSet &behaviors)
const csString & GetEventType() const