Changeset 9526 for code/trunk/src/modules/gametypes/SpaceRaceManager.cc
- Timestamp:
- Feb 19, 2013, 10:25:42 AM (11 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/modules/gametypes/SpaceRaceManager.cc
r9348 r9526 38 38 #include "util/Math.h" 39 39 40 41 42 40 namespace orxonox 43 41 { 44 42 CreateFactory(SpaceRaceManager); 45 43 46 SpaceRaceManager::SpaceRaceManager(BaseObject* creator) : BaseObject(creator) 44 SpaceRaceManager::SpaceRaceManager(BaseObject* creator) : 45 BaseObject(creator) 47 46 { 48 47 RegisterObject(SpaceRaceManager); 49 48 this->race_ = orxonox_cast<SpaceRace*>(this->getGametype().get()); 49 assert(race_); 50 //amountOfPlayers=(race_->getPlayers()).size(); 50 51 this->firstcheckpointvisible_ = false; 51 52 } … … 54 55 { 55 56 for (size_t i = 0; i < this->checkpoints_.size(); ++i) 56 57 this->checkpoints_[i]->destroy(); 57 58 } 58 59 … … 61 62 SUPER(SpaceRaceManager, XMLPort, xmlelement, mode); 62 63 63 XMLPortObject(SpaceRaceManager, RaceCheckPoint, "checkpoints", addCheckpoint, getCheckpoint, 64 XMLPortObject(SpaceRaceManager, RaceCheckPoint, "checkpoints", addCheckpoint, getCheckpoint, xmlelement, mode); 64 65 } 65 66 … … 67 68 { 68 69 SUPER(SpaceRaceManager,tick,dt); 70 71 this->players_ = this->race_->getPlayers(); 69 72 70 73 if (this->checkpoints_[0] != NULL && !this->firstcheckpointvisible_) … … 74 77 } 75 78 76 for ( size_t i = 0; i < this->checkpoints_.size(); ++i)79 for ( std::map< PlayerInfo*, Player>::iterator it = players_.begin(); it != players_.end(); ++it) 77 80 { 78 if (this->checkpoints_[i]->getPlayer() != NULL) 79 this->checkpointReached(this->checkpoints_[i], this->checkpoints_[i]->getPlayer()); 81 82 for (size_t i = 0; i < this->checkpoints_.size(); ++i) 83 { 84 if (this->checkpoints_[i]->playerWasHere(it->first)){ 85 this->checkpointReached(this->checkpoints_[i], it->first /*this->checkpoints_[i]->getPlayer()*/); 86 } 87 } 80 88 } 89 81 90 } 82 91 … … 89 98 { 90 99 if (index < this->checkpoints_.size()) 91 100 return this->checkpoints_[index]; 92 101 else 93 return 0; 102 return 0; 103 } 104 105 std::vector<RaceCheckPoint*> SpaceRaceManager::getAllCheckpoints() 106 { 107 return checkpoints_; 94 108 } 95 109 96 110 /** 97 98 */111 @brief Returns the checkpoint with the given checkpoint-index (@see RaceCheckPoint::getCheckpointIndex). 112 */ 99 113 RaceCheckPoint* SpaceRaceManager::findCheckpoint(int index) const 100 114 { 101 115 for (size_t i = 0; i < this->checkpoints_.size(); ++i) 102 103 116 if (this->checkpoints_[i]->getCheckpointIndex() == index) 117 return this->checkpoints_[i]; 104 118 return 0; 105 119 } … … 107 121 bool SpaceRaceManager::reachedValidCheckpoint(RaceCheckPoint* oldCheckpoint, RaceCheckPoint* newCheckpoint, PlayerInfo* player) const 108 122 { 109 if (oldCheckpoint )123 if (oldCheckpoint != NULL) 110 124 { 111 125 // the player already visited an old checkpoint; see which checkpoints are possible now 112 126 const std::set<int>& possibleCheckpoints = oldCheckpoint->getNextCheckpoints(); 113 127 for (std::set<int>::const_iterator it = possibleCheckpoints.begin(); it != possibleCheckpoints.end(); ++it) 114 115 128 if (this->findCheckpoint(*it) == newCheckpoint) 129 return true; 116 130 return false; 117 131 } … … 128 142 assert(gametype); 129 143 if (!gametype) 130 144 return; 131 145 132 RaceCheckPoint* oldCheckpoint = gametype->getCheckpointReached(player); 146 RaceCheckPoint* oldCheckpoint = gametype->getCheckpointReached(player); // returns the last from player reached checkpoint 133 147 134 148 if (this->reachedValidCheckpoint(oldCheckpoint, newCheckpoint, player)) … … 152 166 // adjust the radarvisibility 153 167 gametype->newCheckpointReached(newCheckpoint, player); 154 this->updateRadarVisibility(oldCheckpoint, newCheckpoint); 168 if(player->isHumanPlayer()) 169 this->updateRadarVisibility(oldCheckpoint, newCheckpoint); 155 170 } 156 171 } 157 172 158 newCheckpoint->resetPlayer();173 // newCheckpoint->resetPlayer(); loescht playerpointer TODO: check if problems occur 159 174 } 160 175 … … 165 180 const std::set<int>& oldVisible = oldCheckpoint->getNextCheckpoints(); 166 181 for (std::set<int>::const_iterator it = oldVisible.begin(); it != oldVisible.end(); ++it) 167 182 this->findCheckpoint(*it)->setRadarVisibility(false); 168 183 } 169 184 … … 174 189 const std::set<int>& newVisible = newCheckpoint->getNextCheckpoints(); 175 190 for (std::set<int>::const_iterator it = newVisible.begin(); it != newVisible.end(); ++it) 176 191 this->findCheckpoint(*it)->setRadarVisibility(true); 177 192 } 178 193 }
Note: See TracChangeset
for help on using the changeset viewer.