src/tron/zone/zSelector.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 "zSelector.h"
00029 #include "tRandom.h"
00030 
00031 
00032 //
00033 // Copy all the valid players from source and copy them in result. Valid depends on the condition
00034 // living.
00035 //
00036 std::vector <ePlayerNetID *>
00037 zSelector::getAllValid(std::vector <ePlayerNetID *> &results, std::vector <ePlayerNetID *> const &sources, LivingStatus living)
00038 {
00039     unsigned short int max = sources.size();
00040     for(unsigned short int i=0;i<max;i++)
00041     {
00042         ePlayerNetID *p=sources[i];
00043         switch (living) {
00044         case _either:
00045             results.push_back(p);
00046             break;
00047         case _alive:
00048             if ( p->Object() && p->Object()->Alive() )
00049             {
00050                 results.push_back(p);
00051             }
00052             break;
00053         case _dead:
00054             if(  !(p->Object()) || !(p->Object()->Alive()) )
00055             {
00056                 results.push_back(p);
00057             }
00058             break;
00059         }
00060     }
00061     return results;
00062 }
00063 
00064 zSelector::zSelector()
00065 { }
00066 
00067 zSelector::zSelector(zSelector const &other)
00068 { }
00069 
00070 void zSelector::operator=(zSelector const &other)
00071 {
00072     if(this != &other) {
00073     }
00074 }
00075 
00076 zSelector * zSelector::copy(void) const
00077 {
00078     return new zSelector(*this);
00079 }
00080 
00081 gVectorExtra<ePlayerNetID *> zSelector::select(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle * triggerer)
00082 {
00083     gVectorExtra<ePlayerNetID *> empty;
00084     return empty;
00085 }
00086 
00087 void
00088 zSelector::apply(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle * triggerer)
00089 {
00090     if (count == -1 || count > 0)
00091     {
00092         gVectorExtra<ePlayerNetID *> d_calculatedTargets = select(owners, teamOwners, triggerer);
00093         zEffectorPtrs::const_iterator iter;
00094         for(iter=effectors.begin();
00095                 iter!=effectors.end();
00096                 ++iter)
00097         {
00098             (*iter)->apply(d_calculatedTargets);
00099         }
00100         if (count > 0)
00101             count --;
00102     }
00103 }
00104 
00105 //
00106 // TargetSelf
00107 //
00108 zSelector* zSelectorSelf::create()
00109 {
00110     return new zSelectorSelf();
00111 }
00112 
00113 zSelectorSelf::zSelectorSelf():
00114         zSelector()
00115 { }
00116 
00117 zSelectorSelf::zSelectorSelf(zSelectorSelf const &other):
00118         zSelector(other)
00119 { }
00120 
00121 void zSelectorSelf::operator=(zSelectorSelf const &other)
00122 {
00123     this->zSelector::operator=(other);
00124 }
00125 
00126 zSelectorSelf * zSelectorSelf::copy(void) const
00127 {
00128     return new zSelectorSelf(*this);
00129 }
00130 
00131 gVectorExtra<ePlayerNetID *> zSelectorSelf::select(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle * triggerer)
00132 {
00133     gVectorExtra<ePlayerNetID *> self;
00134     ePlayerNetID* triggererPlayer =  triggerer->Player();
00135     if (triggererPlayer != 0)
00136         self.push_back( triggererPlayer );
00137 
00138     return self;
00139 }
00140 
00141 
00142 //
00143 // zSelectorTeammate
00144 //
00145 zSelector* zSelectorTeammate::create()
00146 {
00147     return new zSelectorTeammate();
00148 }
00149 
00150 zSelectorTeammate::zSelectorTeammate():
00151         zSelector()
00152 { }
00153 
00154 zSelectorTeammate::zSelectorTeammate(zSelectorTeammate const &other):
00155         zSelector(other)
00156 { }
00157 
00158 void zSelectorTeammate::operator=(zSelectorTeammate const &other)
00159 {
00160     this->zSelector::operator=(other);
00161 }
00162 
00163 zSelectorTeammate * zSelectorTeammate::copy(void) const
00164 {
00165     return new zSelectorTeammate(*this);
00166 }
00167 
00168 gVectorExtra<ePlayerNetID *> zSelectorTeammate::select(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle * triggerer)
00169 {
00170     // A single, randomly selected player that is member of the team of
00171     // the player that triggered the Zone receives the effect. This
00172     // includes the player that triggered the Zone as a candidate.
00173     gVectorExtra <ePlayerNetID *> teammates;
00174     gVectorExtra <ePlayerNetID *> singleTeammate;
00175 
00176     ePlayerNetID* triggererPlayer =  triggerer->Player();
00177     if (triggererPlayer != 0) {
00178         getAllValid(teammates, triggererPlayer->CurrentTeam()->GetAllMembers(), _alive);
00179 
00180         // Remove the triggerer if it is there
00181         teammates.remove(triggererPlayer);
00182 
00183         // Who is our lucky candidate ?
00184         if(teammates.size() != 0)
00185             singleTeammate.push_back(pickOne(teammates));
00186     }
00187     return singleTeammate;
00188 }
00189 
00190 //
00191 // zSelectorTeam
00192 //
00193 zSelector* zSelectorTeam::create()
00194 {
00195     return new zSelectorTeam();
00196 }
00197 
00198 zSelectorTeam::zSelectorTeam():
00199         zSelector()
00200 { }
00201 
00202 zSelectorTeam::zSelectorTeam(zSelectorTeam const &other):
00203         zSelector(other)
00204 { }
00205 
00206 void zSelectorTeam::operator=(zSelectorTeam const &other)
00207 {
00208     this->zSelector::operator=(other);
00209 }
00210 
00211 zSelectorTeam * zSelectorTeam::copy(void) const
00212 {
00213     return new zSelectorTeam(*this);
00214 }
00215 
00216 gVectorExtra<ePlayerNetID *> zSelectorTeam::select(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle * triggerer)
00217 {
00218     // All the members of the team of the player triggering the
00219     // Zone will receive its effect.
00220 
00221     gVectorExtra <ePlayerNetID *> allMemberOfTeam;
00222 
00223     ePlayerNetID* triggererPlayer =  triggerer->Player();
00224     if (triggererPlayer != 0) {
00225         getAllValid(allMemberOfTeam, triggererPlayer->CurrentTeam()->GetAllMembers(), _alive);
00226     }
00227 
00228     return allMemberOfTeam;
00229 }
00230 
00231 //
00232 // zSelectorAll
00233 //
00234 zSelector* zSelectorAll::create()
00235 {
00236     return new zSelectorAll();
00237 }
00238 
00239 zSelectorAll::zSelectorAll():
00240         zSelector()
00241 { }
00242 
00243 zSelectorAll::zSelectorAll(zSelectorAll const &other):
00244         zSelector(other)
00245 { }
00246 
00247 void zSelectorAll::operator=(zSelectorAll const &other)
00248 {
00249     this->zSelector::operator=(other);
00250 }
00251 
00252 zSelectorAll * zSelectorAll::copy(void) const
00253 {
00254     return new zSelectorAll(*this);
00255 }
00256 
00257 gVectorExtra<ePlayerNetID *> zSelectorAll::select(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle * triggerer)
00258 {
00259     // Everybody in the game receives the effect.
00260     gVectorExtra<ePlayerNetID *> everybody;
00261     for (int i=0; i<se_PlayerNetIDs.Len(); i++) {
00262         everybody.push_back( se_PlayerNetIDs(i) );
00263     }
00264 
00265     gVectorExtra<ePlayerNetID *> everybodyValid;
00266     getAllValid(everybodyValid, everybody, _alive);
00267 
00268     return everybodyValid;
00269 }
00270 
00271 //
00272 // zSelectorAllButSelf
00273 //
00274 zSelector* zSelectorAllButSelf::create()
00275 {
00276     return new zSelectorAllButSelf();
00277 }
00278 
00279 zSelectorAllButSelf::zSelectorAllButSelf():
00280         zSelector()
00281 { }
00282 
00283 zSelectorAllButSelf::zSelectorAllButSelf(zSelectorAllButSelf const &other):
00284         zSelector(other)
00285 { }
00286 
00287 void zSelectorAllButSelf::operator=(zSelectorAllButSelf const &other)
00288 {
00289     this->zSelector::operator=(other);
00290 }
00291 
00292 zSelectorAllButSelf * zSelectorAllButSelf::copy(void) const
00293 {
00294     return new zSelectorAllButSelf(*this);
00295 }
00296 
00297 gVectorExtra<ePlayerNetID *> zSelectorAllButSelf::select(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle * triggerer)
00298 {
00299     // Everybody in the game but the player who triggered the
00300     // Zone receives the effect. This excludes the player
00301     // that triggered the Zone.
00302 
00303     gVectorExtra<ePlayerNetID *> everybody;
00304     for (int i=0; i<se_PlayerNetIDs.Len(); i++) {
00305         everybody.push_back( se_PlayerNetIDs(i) );
00306     }
00307 
00308     gVectorExtra<ePlayerNetID *> everybodyValid;
00309     getAllValid(everybodyValid, everybody, _alive);
00310     // Remove the triggerer from the list of targets
00311 
00312     ePlayerNetID* triggererPlayer =  triggerer->Player();
00313     if (triggererPlayer != 0) {
00314         everybodyValid.remove(triggererPlayer);
00315     }
00316 
00317     return everybodyValid;
00318 }
00319 
00320 /*
00321 //
00322 // zSelectorAllButTeam
00323 //
00324 zSelector* zSelectorAllButTeam::create() 
00325 {
00326   return new zSelectorAllButTeam();
00327 }
00328 
00329 zSelectorAllButTeam::zSelectorAllButTeam(): 
00330   zSelector()
00331 { }
00332 
00333 zSelectorAllButTeam::zSelectorAllButTeam(zSelectorAllButTeam const &other):
00334   zSelector(other)
00335 { }
00336 
00337 void zSelectorAllButTeam::operator=(zSelectorAllButTeam const &other)
00338 { 
00339   this->zSelector::operator=(other);
00340 }
00341 
00342 zSelectorAllButTeam * zSelectorAllButTeam::copy(void) const
00343 {
00344   return new zSelectorAllButTeam(*this);
00345 }
00346 
00347 gVectorExtra<ePlayerNetID *> zSelectorAllButTeam::select(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle * triggerer)
00348 {
00349 
00350 
00351   // Everybody in the game but members of the team of the
00352   // player who triggered the Zone receive the effect. 
00353   gVectorExtra<ePlayerNetID *> everybody;
00354   for (int i=0; i<se_PlayerNetIDs.Len(); i++) {
00355     everybody.push_back( se_PlayerNetIDs(i) );
00356   }
00357 
00358   gVectorExtra<ePlayerNetID *> everybodyValid;
00359   getAllValid(everybodyValid, everybody, _alive);
00360 
00361   // Remove the trigerer's team member
00362   gVectorExtra<ePlayerNetID *> teamMember;
00363   everybodyValid.removeAll(getTeammembers(teamMember, triggerer));
00364 
00365   return everybodyValid;
00366 }
00367 
00368 */
00369 
00370 //
00371 // zSelectorAnother
00372 //
00373 
00374 zSelector* zSelectorAnother::create()
00375 {
00376     return new zSelectorAnother();
00377 }
00378 
00379 zSelectorAnother::zSelectorAnother():
00380         zSelector()
00381 { }
00382 
00383 zSelectorAnother::zSelectorAnother(zSelectorAnother const &other):
00384         zSelector(other)
00385 { }
00386 
00387 void zSelectorAnother::operator=(zSelectorAnother const &other)
00388 {
00389     this->zSelector::operator=(other);
00390 }
00391 
00392 zSelectorAnother * zSelectorAnother::copy(void) const
00393 {
00394     return new zSelectorAnother(*this);
00395 }
00396 
00397 gVectorExtra<ePlayerNetID *> zSelectorAnother::select(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle * triggerer)
00398 {
00399     // Another single, randomly selected player that is the the one that
00400     // triggered the Zone receive the effect. This excludes the player
00401     // that triggered the Zone.
00402 
00403     gVectorExtra <ePlayerNetID *> allValidPlayer;
00404     gVectorExtra <ePlayerNetID *> anotherPlayer;
00405 
00406     gVectorExtra <ePlayerNetID *> allPlayer;
00407     for (int i=0; i<se_PlayerNetIDs.Len(); i++) {
00408         allPlayer.push_back( se_PlayerNetIDs(i) );
00409     }
00410 
00411     getAllValid(allValidPlayer, allPlayer, _alive);
00412 
00413     ePlayerNetID* triggererPlayer =  triggerer->Player();
00414     if (triggererPlayer != 0) {
00415         allValidPlayer.remove(triggererPlayer);
00416     }
00417 
00418     if(allValidPlayer.size() != 0)
00419         anotherPlayer.push_back(pickOne(allValidPlayer));
00420 
00421     return anotherPlayer;
00422 }
00423 
00424 //
00425 // zSelectorOwner
00426 //
00427 
00428 zSelector* zSelectorOwner::create()
00429 {
00430     return new zSelectorOwner();
00431 }
00432 
00433 zSelectorOwner::zSelectorOwner():
00434         zSelector()
00435 { }
00436 
00437 zSelectorOwner::zSelectorOwner(zSelectorOwner const &other):
00438         zSelector(other)
00439 { }
00440 
00441 void zSelectorOwner::operator=(zSelectorOwner const &other)
00442 {
00443     this->zSelector::operator=(other);
00444 }
00445 
00446 zSelectorOwner * zSelectorOwner::copy(void) const
00447 {
00448     return new zSelectorOwner(*this);
00449 }
00450 
00451 gVectorExtra<ePlayerNetID *> zSelectorOwner::select(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle * triggerer)
00452 {
00453     // The owner of the Zone receives the effect upon trigger,
00454     // irrelevantly of the user who triggers it.
00455     gVectorExtra<ePlayerNetID *> owningPlayers;
00456 
00457     for(gVectorExtra< nNetObjectID >::const_iterator iter=owners.begin();
00458             iter!=owners.end();
00459             ++iter) {
00460         // Is the object still there
00461         if(bool(sn_netObjects[(*iter)]))
00462         {
00463             ePlayerNetID * anOwner = static_cast< ePlayerNetID* >( static_cast< nNetObject* >( sn_netObjects[ (*iter) ] ) ) ;
00464             if(anOwner != 0)
00465                 owningPlayers.push_back( anOwner );
00466         }
00467     }
00468     return owningPlayers;
00469 }
00470 
00471 //
00472 // zSelectorOwnerTeam
00473 //
00474 
00475 zSelector* zSelectorOwnerTeam::create()
00476 {
00477     return new zSelectorOwnerTeam();
00478 }
00479 
00480 zSelectorOwnerTeam::zSelectorOwnerTeam():
00481         zSelector()
00482 { }
00483 
00484 zSelectorOwnerTeam::zSelectorOwnerTeam(zSelectorOwnerTeam const &other):
00485         zSelector(other)
00486 { }
00487 
00488 void zSelectorOwnerTeam::operator=(zSelectorOwnerTeam const &other)
00489 {
00490     this->zSelector::operator=(other);
00491 }
00492 
00493 zSelectorOwnerTeam * zSelectorOwnerTeam::copy(void) const
00494 {
00495     return new zSelectorOwnerTeam(*this);
00496 }
00497 
00498 gVectorExtra<ePlayerNetID *> zSelectorOwnerTeam::select(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle * triggerer)
00499 {
00500     // The members of the team that owns the Zone receives the
00501     // effect upon trigger, irrelevantly of the user who triggers it.
00502 
00503     // Pick all the members of the teams
00504     gVectorExtra <ePlayerNetID *> allOwnerTeamMembers;
00505     gVectorExtra< nNetObjectID >::const_iterator iter;
00506     for(iter = teamOwners.begin();
00507             iter != teamOwners.end();
00508             ++iter)
00509     {
00510         // Is the object still there
00511         if(bool(sn_netObjects[(*iter)]))
00512         {
00513             eTeam * aTeam = static_cast< eTeam* >( static_cast< nNetObject* >( sn_netObjects[ (*iter) ] ) ) ;
00514             if(aTeam != 0)
00515                 allOwnerTeamMembers.insertAll(aTeam->GetAllMembers());
00516 
00517         }
00518     }
00519 
00520     // Keep only the valid ones
00521     gVectorExtra <ePlayerNetID *> OwnerTeamMembers;
00522     getAllValid(OwnerTeamMembers, allOwnerTeamMembers, _alive);
00523 
00524     return OwnerTeamMembers;
00525 }
00526 
00527 
00528 //
00529 // zSelectorOwnerTeamTeammate
00530 //
00531 zSelector* zSelectorOwnerTeamTeammate::create()
00532 {
00533     return new zSelectorOwnerTeamTeammate();
00534 }
00535 
00536 zSelectorOwnerTeamTeammate::zSelectorOwnerTeamTeammate():
00537         zSelector()
00538 { }
00539 
00540 zSelectorOwnerTeamTeammate::zSelectorOwnerTeamTeammate(zSelectorOwnerTeamTeammate const &other):
00541         zSelector(other)
00542 { }
00543 
00544 void zSelectorOwnerTeamTeammate::operator=(zSelectorOwnerTeamTeammate const &other)
00545 {
00546     this->zSelector::operator=(other);
00547 }
00548 
00549 zSelectorOwnerTeamTeammate * zSelectorOwnerTeamTeammate::copy(void) const
00550 {
00551     return new zSelectorOwnerTeamTeammate(*this);
00552 }
00553 
00554 gVectorExtra<ePlayerNetID *> zSelectorOwnerTeamTeammate::select(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle * triggerer)
00555 {
00556     // Pick all the members of the teams
00557     gVectorExtra <ePlayerNetID *> allTeammates;
00558     gVectorExtra< nNetObjectID >::const_iterator iter;
00559     for(iter = teamOwners.begin();
00560             iter != teamOwners.end();
00561             ++iter)
00562     {
00563         // Is the object still there
00564         if(bool(sn_netObjects[(*iter)]))
00565         {
00566             eTeam * aTeam = static_cast< eTeam* >( static_cast< nNetObject* >( sn_netObjects[ (*iter) ] ) ) ;
00567             if(aTeam != 0)
00568                 allTeammates.insertAll(aTeam->GetAllMembers());
00569         }
00570     }
00571 
00572     // Keep only the valid ones
00573     gVectorExtra <ePlayerNetID *> teammates;
00574     getAllValid(teammates, allTeammates, _alive);
00575 
00576     // Select a random one
00577     gVectorExtra<ePlayerNetID *> singleTeammate;
00578     if(teammates.size() != 0)
00579         singleTeammate.push_back(pickOne(teammates));
00580     return singleTeammate;
00581 }
00582 
00583 //
00584 // zSelectorAnyDead
00585 //
00586 zSelector* zSelectorAnyDead::create()
00587 {
00588     return new zSelectorAnyDead();
00589 }
00590 
00591 zSelectorAnyDead::zSelectorAnyDead():
00592         zSelector()
00593 { }
00594 
00595 zSelectorAnyDead::zSelectorAnyDead(zSelectorAnyDead const &other):
00596         zSelector(other)
00597 { }
00598 
00599 void zSelectorAnyDead::operator=(zSelectorAnyDead const &other)
00600 {
00601     this->zSelector::operator=(other);
00602 }
00603 
00604 zSelectorAnyDead * zSelectorAnyDead::copy(void) const
00605 {
00606     return new zSelectorAnyDead(*this);
00607 }
00608 
00609 gVectorExtra<ePlayerNetID *> zSelectorAnyDead::select(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle * triggerer)
00610 {
00611     // A single, randomly selected dead player receives the
00612     // effect.
00613 
00614     gVectorExtra<ePlayerNetID *> everybody;
00615     for (int i=0; i<se_PlayerNetIDs.Len(); i++) {
00616         everybody.push_back( se_PlayerNetIDs(i) );
00617     }
00618 
00619     gVectorExtra<ePlayerNetID *> everybodyDead;
00620     getAllValid(everybodyDead, everybody, _dead);
00621 
00622     gVectorExtra<ePlayerNetID *> singleDead;
00623     if(everybodyDead.size() != 0)
00624         singleDead.push_back(pickOne(everybodyDead));
00625 
00626     return singleDead;
00627 }
00628 
00629 //
00630 // zSelectorAllDead
00631 //
00632 zSelector* zSelectorAllDead::create()
00633 {
00634     return new zSelectorAllDead();
00635 }
00636 
00637 zSelectorAllDead::zSelectorAllDead():
00638         zSelector()
00639 { }
00640 
00641 zSelectorAllDead::zSelectorAllDead(zSelectorAllDead const &other):
00642         zSelector(other)
00643 { }
00644 
00645 void zSelectorAllDead::operator=(zSelectorAllDead const &other)
00646 {
00647     this->zSelector::operator=(other);
00648 }
00649 
00650 zSelectorAllDead * zSelectorAllDead::copy(void) const
00651 {
00652     return new zSelectorAllDead(*this);
00653 }
00654 
00655 gVectorExtra<ePlayerNetID *> zSelectorAllDead::select(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle * triggerer)
00656 {
00657     // All dead players receives the effect.
00658 
00659     gVectorExtra<ePlayerNetID *> everybody;
00660     for (int i=0; i<se_PlayerNetIDs.Len(); i++) {
00661         everybody.push_back( se_PlayerNetIDs(i) );
00662     }
00663 
00664     gVectorExtra<ePlayerNetID *> everybodyDead;
00665     getAllValid(everybodyDead, everybody, _dead);
00666 
00667     return everybodyDead;
00668 }
00669 
00670 //
00671 // zSelectorSingleDeadOwner
00672 //
00673 zSelector* zSelectorSingleDeadOwner::create()
00674 {
00675     return new zSelectorSingleDeadOwner();
00676 }
00677 
00678 zSelectorSingleDeadOwner::zSelectorSingleDeadOwner():
00679         zSelector()
00680 { }
00681 
00682 zSelectorSingleDeadOwner::zSelectorSingleDeadOwner(zSelectorSingleDeadOwner const &other):
00683         zSelector(other)
00684 { }
00685 
00686 void zSelectorSingleDeadOwner::operator=(zSelectorSingleDeadOwner const &other)
00687 {
00688     this->zSelector::operator=(other);
00689 }
00690 
00691 zSelectorSingleDeadOwner * zSelectorSingleDeadOwner::copy(void) const
00692 {
00693     return new zSelectorSingleDeadOwner(*this);
00694 }
00695 
00696 gVectorExtra<ePlayerNetID *> zSelectorSingleDeadOwner::select(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle * triggerer)
00697 {
00698     // A single, randomly selected dead member of
00699     // the team of the player that triggered the Zone receives the
00700     // effect.
00701 
00702     gVectorExtra <ePlayerNetID *> owningPlayers;
00703     gVectorExtra <ePlayerNetID *> deadOwners;
00704     gVectorExtra <ePlayerNetID *> singleDeadOwner;
00705 
00706     // Transform the list of owners' id into a list of ePlayer
00707     for(gVectorExtra< nNetObjectID >::const_iterator iter=owners.begin();
00708             iter!=owners.end();
00709             ++iter) {
00710         // Is the object still there
00711         if(bool(sn_netObjects[(*iter)]))
00712         {
00713             ePlayerNetID * aPlayer = static_cast< ePlayerNetID* >( static_cast< nNetObject* >( sn_netObjects[ (*iter) ] ) ) ;
00714             if(aPlayer != 0)
00715                 owningPlayers.push_back( aPlayer );
00716         }
00717     }
00718 
00719     // Preserve only the dead players
00720     getAllValid(deadOwners, owningPlayers, _dead);
00721 
00722     // Who is our lucky candidate ?
00723     if(deadOwners.size() != 0)
00724         singleDeadOwner.push_back(pickOne(deadOwners));
00725 
00726     return singleDeadOwner;
00727 }
00728 
00729 
00730 
00731 //
00732 // zSelectorAnotherTeammateDead
00733 //
00734 zSelector* zSelectorAnotherTeammateDead::create()
00735 {
00736     return new zSelectorAnotherTeammateDead();
00737 }
00738 
00739 zSelectorAnotherTeammateDead::zSelectorAnotherTeammateDead():
00740         zSelector()
00741 { }
00742 
00743 zSelectorAnotherTeammateDead::zSelectorAnotherTeammateDead(zSelectorAnotherTeammateDead const &other):
00744         zSelector(other)
00745 { }
00746 
00747 void zSelectorAnotherTeammateDead::operator=(zSelectorAnotherTeammateDead const &other)
00748 {
00749     this->zSelector::operator=(other);
00750 }
00751 
00752 zSelectorAnotherTeammateDead * zSelectorAnotherTeammateDead::copy(void) const
00753 {
00754     return new zSelectorAnotherTeammateDead(*this);
00755 }
00756 
00757 gVectorExtra<ePlayerNetID *> zSelectorAnotherTeammateDead::select(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle * triggerer)
00758 {
00759     // A single, randomly selected dead member of
00760     // the team of the player that triggered the Zone receives the
00761     // effect.
00762 
00763     gVectorExtra <ePlayerNetID *> deadTeammates;
00764     gVectorExtra <ePlayerNetID *> singleDeadTeammate;
00765 
00766     ePlayerNetID* triggererPlayer =  triggerer->Player();
00767     if (triggererPlayer != 0) {
00768         getAllValid(deadTeammates, triggererPlayer->CurrentTeam()->GetAllMembers(), _dead);
00769 
00770         // Remove the triggerer if it is there
00771         deadTeammates.remove(triggererPlayer);
00772 
00773         // Who is our lucky candidate ?
00774         if(deadTeammates.size() != 0)
00775             singleDeadTeammate.push_back(pickOne(deadTeammates));
00776     }
00777     return singleDeadTeammate;
00778 }
00779 
00780 
00781 //
00782 // zSelectorAnotherNotTeammateDead
00783 //
00784 zSelector* zSelectorAnotherNotTeammateDead::create()
00785 {
00786     return new zSelectorAnotherNotTeammateDead();
00787 }
00788 
00789 zSelectorAnotherNotTeammateDead::zSelectorAnotherNotTeammateDead():
00790         zSelector()
00791 { }
00792 
00793 zSelectorAnotherNotTeammateDead::zSelectorAnotherNotTeammateDead(zSelectorAnotherNotTeammateDead const &other):
00794         zSelector(other)
00795 { }
00796 
00797 void zSelectorAnotherNotTeammateDead::operator=(zSelectorAnotherNotTeammateDead const &other)
00798 {
00799     this->zSelector::operator=(other);
00800 }
00801 
00802 zSelectorAnotherNotTeammateDead * zSelectorAnotherNotTeammateDead::copy(void) const
00803 {
00804     return new zSelectorAnotherNotTeammateDead(*this);
00805 }
00806 
00807 gVectorExtra<ePlayerNetID *> zSelectorAnotherNotTeammateDead::select(gVectorExtra< nNetObjectID > &owners, gVectorExtra< nNetObjectID > &teamOwners, gCycle * triggerer)
00808 {
00809     // A single, randomly selected dead player receives the
00810     // effect.
00811 
00812     // Get all the dead players
00813     gVectorExtra<ePlayerNetID *> everybody;
00814     for (int i=0; i<se_PlayerNetIDs.Len(); i++) {
00815         everybody.push_back( se_PlayerNetIDs(i) );
00816     }
00817     gVectorExtra<ePlayerNetID *> everybodyDead;
00818     getAllValid(everybodyDead, everybody, _dead);
00819 
00820     gVectorExtra <ePlayerNetID *> singleDeadNotTeammate;
00821     if (everybodyDead.size() != 0)
00822     {
00823         gVectorExtra <ePlayerNetID *> teammates;
00824         // Remove all the teammates
00825         ePlayerNetID* triggererPlayer =  triggerer->Player();
00826         if (triggererPlayer != 0)
00827         {
00828             getAllValid(teammates, triggererPlayer->CurrentTeam()->GetAllMembers(), _either);
00829 
00830             // Remove the teammates
00831             everybodyDead.removeAll(teammates);
00832 
00833             // Who is our lucky candidate ?
00834             if(everybodyDead.size() != 0)
00835                 singleDeadNotTeammate.push_back(pickOne(everybodyDead));
00836         }
00837     }
00838     return singleDeadNotTeammate;
00839 }
00840 
00841 
00842 
00843 
00844 
00845 
00846 
00847 
00848 
00849 
00850 
00851 
00852 
00853 
00854 
00855 
00856 
00857 
00858 
00859 
00860 
00861 
00862 
00863 
00864 
00865 //
00866 // Count the number of other alive players in the same team as thePlayer, ie: excluding thePlayer
00867 //
00868 /*
00869 unsigned short int
00870 zSelector::countAliveTeammates(ePlayerNetID *thePlayer, bool requiredAlive){
00871     int alivemates=0;
00872     eTeam *playersTeam = thePlayer->CurrentTeam();
00873     unsigned short max = playersTeam->NumPlayers();
00874 
00875     if(thePlayer && playersTeam)
00876     {
00877         for(unsigned short int i=0; i<max; i++){
00878             ePlayerNetID *p = playersTeam->Player(i);
00879             if(p->Object() && ( p->Object()->Alive() || !requiredAlive ) && p != thePlayer)
00880                 alivemates++;
00881         }
00882     }
00883     return alivemates;
00884 }
00885 */
00886 
00887 //
00888 // Count the total of alive players in the same team as thePlayer, ie: including thePlayer, if it is alive.
00889 //
00890 /*
00891 unsigned short int
00892 zSelector::countAliveTeamMembers(ePlayerNetID *thePlayer, bool requiredAlive){
00893     int alivemates=0;
00894     eTeam *playersTeam = thePlayer->CurrentTeam();
00895     unsigned short max = playersTeam->NumPlayers();
00896 
00897     if(thePlayer && playersTeam)
00898     {
00899         for(unsigned short int i=0; i<max; i++){
00900             ePlayerNetID *p=playersTeam->Player(i);
00901             if(p->Object() && ( p->Object()->Alive() || !requiredAlive ))
00902                 alivemates++;
00903         }
00904     }
00905     return alivemates;
00906 }
00907 */
00908 
00909 
00910 //
00911 // Given a list, will pick a single element at random
00912 // If result is given, the element is added to it.
00913 // In all cases, the element choosen is returned by the method
00914 //
00915 template <typename T>
00916 T
00917 zSelector::pickOne(std::vector <T> const &sources)
00918 {
00919     int number = sources.size();
00920     tRandomizer & randomizer = tRandomizer::GetInstance();
00921     int ran = randomizer.Get(number);
00922 
00923     return sources[ran];
00924 }
00925 
00926 /*
00927 std::vector <ePlayerNetID *>
00928 ::getCalculatedTarget( gCycle * triggerer )
00929 {
00930     gVectorExtra<ePlayerNetID*> targets;
00931 
00932     switch(d_triggererType)
00933     {
00934     case TargetSelf: 
00935       // Only the player that caused the trigger will be receipient
00936       // of the effect of the Zone. This has been the effect of the WinZone
00937       // and DeathZone. This will be the default behavior.
00938         targets.push_back(triggerer->Player());
00939     break;
00940     case TargetTeammate:
00941       {
00942         // A single, randomly selected player that is member of the team of
00943         // the player that triggered the Zone receives the effect. This
00944         // includes the player that triggered the Zone as a candidate.
00945         gVectorExtra <ePlayerNetID *> teammates;
00946         getAllValid(teammates, triggerer->Player()->CurrentTeam()->GetAllMembers(), true);
00947 
00948         // Remove the triggerer if it is there 
00949         teammates.remove(triggerer->Player());
00950 
00951         // Who is our lucky candidate ? 
00952         targets.push_back(pickOne(teammates));
00953       }
00954     break; 
00955     case TargetTeam:
00956       {
00957         // All the members of the team of the player triggering the
00958         // Zone will receive its effect. 
00959         gVectorExtra <ePlayerNetID *> temp;
00960         getAllValid(temp, triggerer->Player()->CurrentTeam()->GetAllMembers(), true);
00961         targets.insert(targets.end(), temp.begin(), temp.end()+1);
00962       }
00963     break; 
00964     case TargetAll: 
00965       {
00966         // Everybody in the game receives the effect.
00967         gVectorExtra<ePlayerNetID *> temp;
00968         for (int i=0; i<se_PlayerNetIDs.Len(); i++) {
00969           temp.push_back( se_PlayerNetIDs(i) );
00970         }
00971 
00972         getAllValid(targets, temp, true);
00973       }
00974     break; 
00975     case TargetAllButSelf: 
00976       {
00977         // Everybody in the game but the player who triggered the
00978         // Zone receives the effect. This excludes the player
00979         // that triggered the Zone.
00980         gVectorExtra<ePlayerNetID *> temp;
00981         for (int i=0; i<se_PlayerNetIDs.Len(); i++) {
00982           temp.push_back( se_PlayerNetIDs(i) );
00983         }
00984         getAllValid(targets, temp, true);
00985         targets.remove(triggerer->Player());
00986       }
00987     break; 
00988     case TargetAllButTeam: 
00989       // Everybody in the game but members of the team of the
00990       // player who triggered the Zone receive the effect. 
00991 
00992       //
00993       // targets.insertAll(se_PlayerNetIDs);
00994       // targets.removeAll(getTeammembers(temp, triggerer));
00995       //
00996     break; 
00997     case TargetAnother: 
00998       // Another single, randomly selected player that is the the one that
00999       // triggered the Zone receive the effect. This excludes the player
01000       // that triggered the Zone.
01001 
01002       //
01003       // gVectorExtra <ePlayerNetID *> temp;
01004       // getAllValid(temp, se_PlayerNetIDs, true);
01005       // temp.remove(triggerer);
01006       // targets.push_back(pickOne(temp));
01007       //
01008     break; 
01009     case TargetAnotherTeam: 
01010       // All the members of a single, randomly selected team that is
01011       // not the team of the player who triggered the effect receives the
01012       // effect. 
01013 
01014       //
01015       // gVectorExtra <eTeam *> temp(teams);
01016       // temp.remove(triggerer->Player()->CurrentTeam());
01017       // getAllValid(targets, pickOne(temp)->GetAllMembers(), true);
01018       //
01019     break; 
01020     case TargetAnotherTeammate: 
01021       // A single, randomly selected member of the team of the
01022       // player that triggered the Zone receive the effect. This exclude
01023       // the player that triggered the Zone.
01024     break; 
01025     case TargetAnotherNotTeammate: 
01026       // A single, randomly selected player that is not member
01027       // of the team of the player that triggered the Zone receives the effect.
01028     break; 
01029     case TargetOwner: 
01030       // The owner of the Zone receives the effect upon trigger,
01031       // irrelevantly of the user who triggers it.
01032     break; 
01033     case TargetOwnerTeam: 
01034       // The members of the team that owns the Zone receives the
01035       // effect upon trigger, irrelevantly of the user who triggers it.
01036     break; 
01037     case TargetOwnerTeamTeammate:
01038       // A single, randomly selected member of the team that owns the Zone receives the
01039       // effect upon trigger, irrelevantly of the user who triggers it.
01040     break;
01041 
01042     // Target types that select among the players that are dead
01043     case TargetAnyDead: 
01044       // A single, randomly selected dead player receives the
01045       // effect.
01046     break; 
01047     case TargetAllDead: 
01048       // All dead players receives the effect.
01049     break; 
01050     case TargetAnotherTeammateDead: 
01051       // A single, randomly selected dead member of
01052       // the team of the player that triggered the Zone receives the
01053       // effect.
01054     break; 
01055     case TargetAnotherNotTeammateDead: 
01056       // A single, randomly selected dead player
01057       // that is not memeber of the team of the player that triggered the
01058       // Zone receives the effect.
01059     break;
01060     }
01061     return targets;
01062 }
01063 */

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