- Timestamp:
- Oct 22, 2012, 5:05:14 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Racingbot/src/modules/gametypes/SpaceRaceManager.cc
r9399 r9412 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 RegisterObject(SpaceRaceManager); 49 47 RegisterObject(SpaceRaceManager) 48 ; this->race_ = orxonox_cast<SpaceRace*>(this->getGametype().get()); 49 assert(race_); 50 //amountOfPlayers=(race_->getPlayers()).size(); 50 51 this->firstcheckpointvisible_ = false; 52 this->players_ = this->race_->getPlayers(); 51 53 } 52 54 … … 54 56 { 55 57 for (size_t i = 0; i < this->checkpoints_.size(); ++i) 56 58 this->checkpoints_[i]->destroy(); 57 59 } 58 60 … … 61 63 SUPER(SpaceRaceManager, XMLPort, xmlelement, mode); 62 64 63 XMLPortObject(SpaceRaceManager, RaceCheckPoint, "checkpoints", addCheckpoint, getCheckpoint, 65 XMLPortObject(SpaceRaceManager, RaceCheckPoint, "checkpoints", addCheckpoint, getCheckpoint, xmlelement, mode); 64 66 } 65 67 … … 74 76 } 75 77 76 for ( size_t i = 0; i < this->checkpoints_.size(); ++i)78 for ( std::map< PlayerInfo*, Player>::iterator it = players_.begin(); it != players_.end(); ++it) 77 79 { 78 if (this->checkpoints_[i]->getPlayer() != NULL) 79 this->checkpointReached(this->checkpoints_[i], this->checkpoints_[i]->getPlayer()); 80 for (size_t i = 0; i < this->checkpoints_.size(); ++i) 81 { 82 if (this->checkpoints_[i]->playerWasHere(it->first)) 83 this->checkpointReached(this->checkpoints_[i], it->first /*this->checkpoints_[i]->getPlayer()*/); 84 } 80 85 } 86 81 87 } 82 88 … … 89 95 { 90 96 if (index < this->checkpoints_.size()) 91 97 return this->checkpoints_[index]; 92 98 else 93 99 return 0; 94 100 } 95 101 96 std::vector<RaceCheckPoint*> SpaceRaceManager::getAllCheckpoints(){ 102 std::vector<RaceCheckPoint*> SpaceRaceManager::getAllCheckpoints() 103 { 97 104 return checkpoints_; 98 105 } 99 106 100 107 /** 101 102 */108 @brief Returns the checkpoint with the given checkpoint-index (@see RaceCheckPoint::getCheckpointIndex). 109 */ 103 110 RaceCheckPoint* SpaceRaceManager::findCheckpoint(int index) const 104 111 { 105 112 for (size_t i = 0; i < this->checkpoints_.size(); ++i) 106 107 113 if (this->checkpoints_[i]->getCheckpointIndex() == index) 114 return this->checkpoints_[i]; 108 115 return 0; 109 116 } … … 111 118 bool SpaceRaceManager::reachedValidCheckpoint(RaceCheckPoint* oldCheckpoint, RaceCheckPoint* newCheckpoint, PlayerInfo* player) const 112 119 { 113 if (oldCheckpoint )120 if (oldCheckpoint != NULL) 114 121 { 115 122 // the player already visited an old checkpoint; see which checkpoints are possible now 116 123 const std::set<int>& possibleCheckpoints = oldCheckpoint->getNextCheckpoints(); 117 124 for (std::set<int>::const_iterator it = possibleCheckpoints.begin(); it != possibleCheckpoints.end(); ++it) 118 119 125 if (this->findCheckpoint(*it) == newCheckpoint) 126 return true; 120 127 return false; 121 128 } … … 132 139 assert(gametype); 133 140 if (!gametype) 134 141 return; 135 142 136 RaceCheckPoint* oldCheckpoint = gametype->getCheckpointReached(player); 143 RaceCheckPoint* oldCheckpoint = gametype->getCheckpointReached(player); // returns the last from player reached checkpoint 137 144 138 145 if (this->reachedValidCheckpoint(oldCheckpoint, newCheckpoint, player)) … … 160 167 } 161 168 162 newCheckpoint->resetPlayer();169 // newCheckpoint->resetPlayer(); loescht playerpointer TODO: check if problems occur 163 170 } 164 171 … … 169 176 const std::set<int>& oldVisible = oldCheckpoint->getNextCheckpoints(); 170 177 for (std::set<int>::const_iterator it = oldVisible.begin(); it != oldVisible.end(); ++it) 171 178 this->findCheckpoint(*it)->setRadarVisibility(false); 172 179 } 173 180 … … 178 185 const std::set<int>& newVisible = newCheckpoint->getNextCheckpoints(); 179 186 for (std::set<int>::const_iterator it = newVisible.begin(); it != newVisible.end(); ++it) 180 187 this->findCheckpoint(*it)->setRadarVisibility(true); 181 188 } 182 189 }
Note: See TracChangeset
for help on using the changeset viewer.