Planeshift

reaction.h

Go to the documentation of this file.
00001 /*
00002 * reaction.h by Anders Reggestad <[email protected]>
00003 *
00004 * Copyright (C) 2013 Atomic Blue ([email protected], http://www.atomicblue.org)
00005 *
00006 *
00007 * This program is free software; you can redistribute it and/or
00008 * modify it under the terms of the GNU General Public License
00009 * as published by the Free Software Foundation (version 2 of the License)
00010 * This program is distributed in the hope that it will be useful,
00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 * GNU General Public License for more details.
00014 * You should have received a copy of the GNU General Public License
00015 * along with this program; if not, write to the Free Software
00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 *
00018 */
00019 
00020 #ifndef __REACTION_H__
00021 #define __REACTION_H__
00022 
00023 //=============================================================================
00024 // Crystal Space Includes
00025 //=============================================================================
00026 #include <csutil/csstring.h>
00027 #include <csutil/array.h>
00028 #include <iutil/document.h>
00029 
00030 //=============================================================================
00031 // Library Includes
00032 //=============================================================================
00033 #include "util/psconst.h"
00034 #include "util/mathscript.h"
00035 
00040 class Perception;
00041 class Behavior;
00042 class NPC;
00043 class BehaviorSet;
00044 class gemNPCObject;
00045 
00046 
00051 class Reaction
00052 {
00053 protected:
00054     friend class NPCType;
00055 
00056     // members making up the "if statement"
00057     csString  eventType;
00058     float     range;
00059     int       factionDiff;
00060     csString  oper;
00061     csString  condition;
00062     MathScript* calcCondition; 
00063     bool      activeOnly;
00064     bool      inactiveOnly;
00065     bool      reactWhenDead;
00066     bool      reactWhenInvisible;
00067     bool      reactWhenInvincible;
00068     csArray<bool> valuesValid;
00069     csArray<int> values;
00070     csArray<bool>randomsValid;
00071     csArray<int> randoms;
00072     csString  type;
00073     csArray<csString> onlyInterrupt;
00074     csArray<csString> doNotInterrupt;
00075 
00076     // members making up the "then statement"
00077     csArray<Behavior*> affected;
00078 
00079     enum DesireType
00080     {
00081         DESIRE_NONE,
00082         DESIRE_DELTA,
00083         DESIRE_ABSOLUTE,
00084         DESIRE_GUARANTEED
00085     };
00086 
00087     DesireType desireType;    
00088     float      desireValue;   
00089     float      weight;        
00090 
00091     csString   lastTriggered; 
00092 
00093 public:
00094     Reaction();
00095     Reaction(Reaction &other, BehaviorSet &behaviors)
00096     {
00097         DeepCopy(other,behaviors);
00098     }
00099 
00100     void DeepCopy(Reaction &other, BehaviorSet &behaviors);
00101 
00102     bool Load(iDocumentNode* node, BehaviorSet &behaviors);
00103     void React(NPC* who, Perception* pcpt);
00104 
00113     bool ShouldReact(gemNPCObject* entity);
00114 
00121     bool DoNotInterrupt(Behavior* behavior);
00122 
00132     bool OnlyInterrupt(Behavior* behavior);
00133 
00134     const csString &GetEventType() const;
00135     float           GetRange()
00136     {
00137         return range;
00138     }
00139     int             GetFactionDiff()
00140     {
00141         return factionDiff;
00142     }
00143     bool            GetValueValid(int i);
00144     int             GetValue(int i);
00145     bool            GetRandomValid(int i);
00151     bool            SetValue(int i, int value);
00152     csString        GetValue();
00153     int             GetRandom(int i);
00154     const csString  GetType(NPC* npc) const;
00155     char            GetOp();
00156     csString        GetAffectedBehaviors();
00157     const csString &GetLastTriggerd()
00158     {
00159         return lastTriggered;
00160     }
00161 
00162 };
00163 
00166 #endif
00167