00001 #ifndef ArmageTron_Monitor_H
00002 #define ArmageTron_Monitor_H
00003
00004 #include <boost/shared_ptr.hpp>
00005 #include <vector>
00006 #include "defs.h"
00007 #include "eGameObject.h"
00008 #include "gVectorExtra.h"
00009 #include "gCycle.h"
00010 #include "zone/zMisc.h"
00011 #include "zone/zEffectGroup.h"
00012 #include "tFunction.h"
00013 #include "tPolynomial.h"
00014 #include "tPolynomialMarshaler.h"
00015 #include "zone/zZoneInfluence.h"
00016
00017 class zMonitorRule;
00018 class zMonitor;
00019
00020 typedef tJUST_CONTROLLED_PTR<zMonitor> zMonitorPtr;
00021
00022 typedef boost::shared_ptr<zMonitorRule> zMonitorRulePtr;
00023 typedef std::vector<zMonitorRulePtr> zMonitorRulePtrs;
00024
00025 typedef gVectorExtra<Triggerer> triggerers;
00026
00027 class zMonitor: public eReferencableGameObject {
00028 public:
00029 zMonitor(eGrid * _grid):
00030 eReferencableGameObject( _grid, eCoord( 1,1 ), eCoord( 0,0 ), NULL, true ),
00031 totalInfluence(0),
00032 contributors(),
00033 rules(),
00034 valueEq(),
00035 drift(0),
00036 minValue(0.0),
00037 maxValue(1.0),
00038 previousTotalInfluenceSlide(0)
00039 {
00040
00041 this->AddToList();
00042 };
00043
00044 ~zMonitor() {
00045
00046
00047 };
00048
00049 virtual void RemoveFromGame(){
00050 RemoveFromListsAll();
00051 };
00052
00053 void setName(string name) {
00054 this->name = name;
00055 };
00056 void addRule(zMonitorRulePtr aRule);
00057
00058 void setInit(tPolynomial<nMessage> v) {
00059 valueEq = v;
00060 };
00061 void setDrift(tPolynomial<nMessage> d) {
00062 drift = d;
00063 };
00064 void setClampLow(REAL l) {
00065 minValue = l;
00066 };
00067 void setClampHigh(REAL h) {
00068 maxValue = h;
00069 };
00070
00071 void affectSlide(gCycle* user, tPolynomial<nMessage> triggererInfluenceSlide, Triad marked);
00072
00073 protected:
00074 tPolynomial<nMessage> totalInfluence;
00075
00076 virtual bool Timestep(REAL currentTime);
00077
00078 triggerers contributors;
00079
00080 zMonitorRulePtrs rules;
00081
00082 tPolynomial<nMessage> valueEq;
00083 tPolynomial<nMessage> drift;
00084
00085 REAL minValue;
00086 REAL maxValue;
00087
00088 string name;
00089
00090
00091 tPolynomial<nMessage> previousValue;
00092 tPolynomial<nMessage> previousTotalInfluenceSlide;
00093
00094
00095 };
00096
00097
00098 class zMonitorRule {
00099 public:
00100 zMonitorRule() { };
00101 virtual bool isValid(float monitorValue) {
00102 return true;
00103 };
00104 virtual ~zMonitorRule() { };
00105
00106 void addEffectGroup(zEffectGroupPtr anEffectGroupPtr) {
00107 effectGroupList.push_back(anEffectGroupPtr);
00108 };
00109 void applyRule(triggerers &contributors, REAL time, const tPolynomial<nMessage> &valueEq) ;
00110
00111 void addMonitorInfluence(zMonitorInfluencePtr newInfluence) {
00112 monitorInfluences.push_back( newInfluence );
00113 };
00114 void addZoneInfluence(zZoneInfluencePtr aZoneInfluencePtr) {
00115 zoneInfluences.push_back(aZoneInfluencePtr);
00116 };
00117 protected:
00118 zEffectGroupPtrs effectGroupList;
00119
00120 zMonitorInfluencePtrs monitorInfluences;
00121 zZoneInfluencePtrs zoneInfluences;
00122 };
00123
00124
00125
00126
00127 class zMonitorRuleOver : public zMonitorRule {
00128 REAL limit;
00129 public:
00130 zMonitorRuleOver(REAL _limit):zMonitorRule(),limit(_limit) {};
00131 virtual ~zMonitorRuleOver() {};
00132 bool isValid(float monitorValue);
00133 };
00134
00135
00136
00137
00138 class zMonitorRuleUnder : public zMonitorRule {
00139 REAL limit;
00140 public:
00141 zMonitorRuleUnder(REAL _limit):zMonitorRule(),limit(_limit) {};
00142 virtual ~zMonitorRuleUnder() {};
00143 bool isValid(float monitorValue);
00144 };
00145
00146
00147
00148
00149
00150 class zMonitorRuleInRange : public zMonitorRule {
00151 REAL lowLimit;
00152 REAL highLimit;
00153 public:
00154 zMonitorRuleInRange(REAL _lowLimit, REAL _highLimit):zMonitorRule(),lowLimit(_lowLimit),highLimit(_highLimit) {};
00155 virtual ~zMonitorRuleInRange() {};
00156 bool isValid(float monitorValue);
00157 };
00158
00159
00160
00161
00162 class zMonitorRuleOutsideRange : public zMonitorRule {
00163 REAL lowLimit;
00164 REAL highLimit;
00165 public:
00166 zMonitorRuleOutsideRange(REAL _lowLimit, REAL _highLimit):zMonitorRule(),lowLimit(_lowLimit),highLimit(_highLimit) {};
00167 virtual ~zMonitorRuleOutsideRange() {};
00168 bool isValid(float monitorValue);
00169 };
00170
00171
00172
00173
00174
00175 class zMonitorInfluence {
00176 zMonitorPtr monitor;
00177 tPolynomialMarshaler<nMessage> influence;
00178 tPolynomial<nMessage> influenceSlide;
00179
00180 bool influenceSlideAvailable;
00181
00182 Triad marked;
00183
00184 public:
00185 zMonitorInfluence(zMonitorPtr aMonitor):
00186 monitor(aMonitor),
00187 influence(),
00188 influenceSlide(),
00189 influenceSlideAvailable(false),
00190 marked(_ignore)
00191 { };
00192 ~zMonitorInfluence() { };
00193
00194 void apply(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle* triggerer, const tPolynomial<nMessage> &valueEq);
00195
00196 void setMarked(Triad mark) {
00197 marked = mark;
00198 };
00199 void setInfluence(tPolynomialMarshaler<nMessage> infl) {
00200 influence = infl;
00201 }
00202
00203 void setInfluenceSlide(tPolynomial<nMessage> infl) {
00204 influenceSlide = infl;
00205 influenceSlideAvailable=true;
00206 };
00207
00208 };
00209
00210
00211 #endif //ArmageTron_Monitor_H