00001 #include <iostream>
00002 #include <vector>
00003
00004 #include "zMonitor.h"
00005 #include "tMath.h"
00006 #include "defs.h"
00007 #include "nNetwork.h"
00008
00009
00010
00011
00012 void
00013 zMonitor::affectSlide(gCycle* user, tPolynomial<nMessage> triggererInfluence, Triad marked) {
00014 Triggerer triggerer;
00015 triggerer.who = user;
00016
00017
00018 triggerer.marked = marked;
00019
00020 contributors.push_back(triggerer);
00021 totalInfluence += triggererInfluence;
00022
00023 }
00024
00025
00026
00027
00028
00029
00030
00034
00035
00036 bool zMonitor::Timestep( REAL time )
00037 {
00038 tPolynomial<nMessage> prevValueEq = valueEq;
00039
00040 if ( totalInfluence != previousTotalInfluenceSlide ) {
00041
00042 for (int i=1; i<totalInfluence.Len(); i++) {
00043 valueEq.changeRate(totalInfluence[i], i, time);
00044 }
00045
00046 for (int i=totalInfluence.Len(); i<valueEq.Len(); i++) {
00047 valueEq.changeRate(0.0, i, time);
00048 }
00049
00050 previousTotalInfluenceSlide = totalInfluence;
00051 }
00052
00053 valueEq = valueEq.clamp(minValue, maxValue, time);
00054
00055
00056
00057
00058
00059
00060
00061 totalInfluence = drift;
00062
00063
00064
00065
00066
00067 zMonitorRulePtrs::const_iterator iter;
00068 for (iter = rules.begin();
00069 iter != rules.end();
00070 ++iter)
00071 {
00072
00073 if ((*iter)->isValid(valueEq.evaluate(time))) {
00074 (*iter)->applyRule(contributors, time, valueEq);
00075 }
00076 }
00077
00078
00079
00080 contributors.erase(contributors.begin(), contributors.end());
00081
00082
00083 lastTime = time;
00084
00085 return false;
00086 }
00087
00088
00089 void
00090 zMonitor::addRule(zMonitorRulePtr aRule) {
00091
00092
00093
00094
00095 rules.push_back(aRule);
00096 }
00097
00098
00099
00100
00101 void zMonitorRule::applyRule(triggerers &contributors, REAL time, const tPolynomial<nMessage> &valueEq) {
00102
00103
00104
00105
00106 std::vector<zEffectGroupPtr>::iterator iter;
00107 for (iter = effectGroupList.begin();
00108 iter != effectGroupList.end();
00109 ++iter)
00110 {
00111
00112 triggerers::const_iterator iter2;
00113 for (iter2 = contributors.begin();
00114 iter2 != contributors.end();
00115 ++iter2)
00116 {
00117 (*iter)->apply(*iter2, time, valueEq);
00118 }
00119 }
00120
00121 gVectorExtra< nNetObjectID > owners;
00122 gVectorExtra< nNetObjectID > teamOwners;
00123
00124 zMonitorInfluencePtrs::const_iterator iterMonitorInfluence;
00125 for (iterMonitorInfluence=monitorInfluences.begin();
00126 iterMonitorInfluence!=monitorInfluences.end();
00127 ++iterMonitorInfluence)
00128 {
00129
00130 (*iterMonitorInfluence)->apply(owners, teamOwners, (gCycle*)0, valueEq);
00131 }
00132
00133 zZoneInfluencePtrs::const_iterator iterZoneInfluence;
00134 for (iterZoneInfluence=zoneInfluences.begin();
00135 iterZoneInfluence!=zoneInfluences.end();
00136 ++iterZoneInfluence)
00137 {
00138 (*iterZoneInfluence)->apply(valueEq);
00139 }
00140 }
00141
00142
00143
00144
00145 bool
00146 zMonitorRuleOver::isValid(float monitorValue) {
00147 return (monitorValue>=limit);
00148 }
00149
00150
00151
00152
00153 bool
00154 zMonitorRuleUnder::isValid(float monitorValue) {
00155 return (monitorValue<=limit);
00156 }
00157
00158
00159
00160
00161
00162 bool
00163 zMonitorRuleInRange::isValid(float monitorValue) {
00164 return (lowLimit<= monitorValue && monitorValue<=highLimit);
00165 }
00166
00167
00168
00169
00170 bool
00171 zMonitorRuleOutsideRange::isValid(float monitorValue) {
00172 return (monitorValue <= lowLimit || highLimit <= monitorValue);
00173 }
00174
00175 void
00176 zMonitorInfluence::apply(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle * user, const tPolynomial<nMessage> &valueEq) {
00177
00178
00179 tPolynomial<nMessage> tf = influence.marshal(valueEq);
00180 monitor->affectSlide(user, tf, marked);
00181
00182 }