src/tron/zone/zValidator.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023 
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #include "zValidator.h"
00029 
00030 
00031 
00032 
00033 zValidator::zValidator(Triad _positive, Triad _marked)
00034         : selectors(),
00035         monitorInfluences(),
00036         zoneInfluences(),
00037         positive(_positive),
00038         marked(_marked)
00039 { }
00040 
00041 zValidator::zValidator(zValidator const &other):
00042         selectors( other.selectors ),
00043         monitorInfluences( other.monitorInfluences ),
00044         zoneInfluences( other.zoneInfluences ),
00045         positive( other.getPositive() ),
00046         marked( other.getMarked() )
00047 {  }
00048 
00049 
00050 void zValidator::operator=(zValidator const &other)
00051 {
00052     if (this != &other) {
00053         positive = other.getPositive();
00054         marked   = other.getMarked();
00055     }
00056 }
00057 
00058 zValidator *zValidator::copy(void) const {
00059     return new zValidator(*this);
00060 }
00061 
00062 bool
00063 zValidator::isOwner(ePlayerNetID *possibleOwner, gVectorExtra< nNetObjectID > &owners)
00064 {
00065     gVectorExtra< nNetObjectID >::iterator iter;
00066     for (iter = owners.begin();
00067             iter != owners.end();
00068             ++iter)
00069     {
00070         if (bool(sn_netObjects[(*iter)]) && (*iter == possibleOwner->ID()) )
00071             return true;
00072     }
00073     return false;
00074 }
00075 
00076 bool
00077 zValidator::isTeamOwner(eTeam *possibleTeamOwner, gVectorExtra< nNetObjectID > &teamOwners)
00078 {
00079     gVectorExtra< nNetObjectID >::iterator iter;
00080     for (iter = teamOwners.begin();
00081             iter != teamOwners.end();
00082             ++iter)
00083     {
00084         // When in local game, the team id of all players is 0, which while not a valid reference, it still ok
00085         bool isValidID = ( (*iter) == 0 || bool(sn_netObjects[(*iter)]));
00086         if ( isValidID && (*iter == possibleTeamOwner->ID()) )
00087             return true;
00088     }
00089     return false;
00090 }
00091 
00092 void
00093 zValidator::validate(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, Triggerer possibleUser, const tPolynomial<nMessage> &tpValue) {
00094 
00095     if (isValid(owners, teamOwners, possibleUser.who) && validateTriad(possibleUser.positive, positive) && validateTriad(possibleUser.marked, marked)) {
00096         zSelectorPtrs::const_iterator iterSelector;
00097         for (iterSelector=selectors.begin();
00098                 iterSelector!=selectors.end();
00099                 ++iterSelector)
00100         {
00101             (*iterSelector)->apply(owners, teamOwners, possibleUser.who);
00102         }
00103 
00104         zMonitorInfluencePtrs::const_iterator iterMonitorInfluence;
00105         for (iterMonitorInfluence=monitorInfluences.begin();
00106                 iterMonitorInfluence!=monitorInfluences.end();
00107                 ++iterMonitorInfluence)
00108         {
00109             (*iterMonitorInfluence)->apply(owners, teamOwners, possibleUser.who, tpValue);
00110         }
00111 
00112         zZoneInfluencePtrs::const_iterator iterZoneInfluence;
00113         for (iterZoneInfluence=zoneInfluences.begin();
00114                 iterZoneInfluence!=zoneInfluences.end();
00115                 ++iterZoneInfluence)
00116         {
00117             // TODO:
00118             (*iterZoneInfluence)->apply( tpValue );
00119         }
00120     }
00121 }
00122 
00123 // *******************
00124 // zValidatorAll
00125 // *******************
00126 zValidator * zValidatorAll::create(Triad _positive, Triad _marked)
00127 {
00128     return new zValidatorAll(_positive, _marked);
00129 }
00130 
00131 zValidatorAll::zValidatorAll(Triad _positive, Triad _marked):
00132         zValidator(_positive, _marked)
00133 { }
00134 
00135 zValidatorAll::zValidatorAll(zValidatorAll const &other):
00136         zValidator(other)
00137 { }
00138 
00139 void zValidatorAll::operator=(zValidatorAll const &other)
00140 {
00141     this->zValidator::operator=(other);
00142 }
00143 
00144 zValidator *zValidatorAll::copy(void) const {
00145     return new zValidatorAll(*this);
00146 }
00147 
00148 // *******************
00149 // zValidatorOwner
00150 // *******************
00151 zValidator * zValidatorOwner::create(Triad _positive, Triad _marked)
00152 {
00153     return new zValidatorOwner(_positive, _marked);
00154 }
00155 
00156 zValidatorOwner::zValidatorOwner(Triad _positive, Triad _marked):
00157         zValidator(_positive, _marked)
00158 { }
00159 
00160 zValidatorOwner::zValidatorOwner(zValidatorOwner const &other):
00161         zValidator(other)
00162 { }
00163 
00164 void zValidatorOwner::operator=(zValidatorOwner const &other)
00165 {
00166     this->zValidator::operator=(other);
00167 }
00168 
00169 zValidator *zValidatorOwner::copy(void) const {
00170     return new zValidatorOwner(*this);
00171 }
00172 
00173 bool
00174 zValidatorOwner::isValid(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle* possibleUser)
00175 {
00176     return isOwner(possibleUser->Player(), owners);
00177 }
00178 
00179 // *******************
00180 // zValidatorOwnerTeam
00181 // *******************
00182 zValidator * zValidatorOwnerTeam::create(Triad _positive, Triad _marked)
00183 {
00184     return new zValidatorOwnerTeam(_positive, _marked);
00185 }
00186 
00187 zValidatorOwnerTeam::zValidatorOwnerTeam(Triad _positive, Triad _marked):
00188         zValidator(_positive, _marked)
00189 { }
00190 
00191 zValidatorOwnerTeam::zValidatorOwnerTeam(zValidatorOwnerTeam const &other):
00192         zValidator(other)
00193 { }
00194 
00195 void zValidatorOwnerTeam::operator=(zValidatorOwnerTeam const &other)
00196 {
00197     this->zValidator::operator=(other);
00198 }
00199 
00200 zValidator *zValidatorOwnerTeam::copy(void) const {
00201     return new zValidatorOwnerTeam(*this);
00202 }
00203 
00204 bool
00205 zValidatorOwnerTeam::isValid(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle* possibleUser)
00206 {
00207     return isTeamOwner(possibleUser->Player()->CurrentTeam(), teamOwners);
00208 }
00209 
00210 // *******************
00211 // zValidatorAllButOwner
00212 // *******************
00213 zValidator * zValidatorAllButOwner::create(Triad _positive, Triad _marked)
00214 {
00215     return new zValidatorAllButOwner(_positive, _marked);
00216 }
00217 
00218 zValidatorAllButOwner::zValidatorAllButOwner(Triad _positive, Triad _marked):
00219         zValidator(_positive, _marked)
00220 { }
00221 
00222 zValidatorAllButOwner::zValidatorAllButOwner(zValidatorAllButOwner const &other):
00223         zValidator(other)
00224 { }
00225 
00226 void zValidatorAllButOwner::operator=(zValidatorAllButOwner const &other)
00227 {
00228     this->zValidator::operator=(other);
00229 }
00230 
00231 zValidator *zValidatorAllButOwner::copy(void) const {
00232     return new zValidatorAllButOwner(*this);
00233 }
00234 
00235 bool
00236 zValidatorAllButOwner::isValid(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle* possibleUser)
00237 {
00238     return !isOwner(possibleUser->Player(), owners);
00239 }
00240 
00241 // *******************
00242 // zValidatorAllButTeamOwner
00243 // *******************
00244 zValidator * zValidatorAllButTeamOwner::create(Triad _positive, Triad _marked)
00245 {
00246     return new zValidatorAllButTeamOwner(_positive, _marked);
00247 }
00248 
00249 zValidatorAllButTeamOwner::zValidatorAllButTeamOwner(Triad _positive, Triad _marked):
00250         zValidator(_positive, _marked)
00251 { }
00252 
00253 zValidatorAllButTeamOwner::zValidatorAllButTeamOwner(zValidatorAllButTeamOwner const &other):
00254         zValidator(other)
00255 { }
00256 
00257 void zValidatorAllButTeamOwner::operator=(zValidatorAllButTeamOwner const &other)
00258 {
00259     this->zValidator::operator=(other);
00260 }
00261 
00262 zValidator *zValidatorAllButTeamOwner::copy(void) const {
00263     return new zValidatorAllButTeamOwner(*this);
00264 }
00265 
00266 bool
00267 zValidatorAllButTeamOwner::isValid(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle* possibleUser)
00268 {
00269     return !isTeamOwner(possibleUser->Player()->CurrentTeam(), teamOwners);
00270 }
00271 
00272 
00273 
00274 
00275 
00276 
00277 /*
00278 bool
00279 ::isValidUser(gCycle *possibleUser)
00280 {
00281     switch(d_userType)
00282     {
00283     case UserAll:
00284 // Everybody, irrevelantly of any settings, is allowed to
00285 // trigger this Zone. This will be the default behavior.
00286         return true;
00287     break;
00288     case UserOwner:
00289 // Only a player that has its id in the owner field of the
00290 // Zone can trigger it (revisit this when a decision is made about
00291 // multiple owners)
00292         return isOwner(possibleUser->Player());
00293     break;
00294     case UserOwnerTeam:
00295 // Only a player member of a team that has its id in the
00296 // ownerTeam field can trigger this Zone. Thus the Zone can be
00297 // triggered by any of the members of a team.
00298         return isTeamOwner(possibleUser->Player()->CurrentTeam());
00299     break;
00300     case UserAllButOwner:
00301 // Only the player that has its id in the owner field is
00302 // denied triggering the Zone. This is the opposite effect as
00303 // Owner. It is synonymous to "everybody but the owner of the Zone".
00304         return !isOwner(possibleUser->Player());
00305     break;
00306     case UserAllButTeamOwner:
00307 // Only players that are members of the team that
00308 // has its id in the ownerTeam field are denied triggering this
00309 // Zone. This is the opposite of OwnerTeam. It is synonymous to
00310 // "everybody but the team owner of the Zone".
00311         return !isTeamOwner(possibleUser->Player()->CurrentTeam());
00312     break;
00313     case UserAnotherTeammate:
00314 // This Zone is restricted to players that are
00315 // member of the same team as the player which id is stored in the
00316 // owner field. The triggering of the Zone is itself denied to the
00317 // player that has its id stored in the owner field. This is a
00318 // restricted version of OwnerTeam. It is synonymous to "only the
00319 // teammates of the owner can use this Zone, but even the owner is
00320 // denied".
00321         return !isOwner(possibleUser->Player()) && isTeamOwner(possibleUser->Player()->CurrentTeam());
00322     break;
00323     }
00324 
00325     return false;
00326 }
00327 */

Generated on Sat Mar 15 22:56:13 2008 for Armagetron Advanced by  doxygen 1.5.4