Changeset 9263 for code/trunk/src/modules/gametypes/SpaceRaceManager.cc
- Timestamp:
- Jun 3, 2012, 12:04:35 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/gametypes/SpaceRaceManager.cc
r9262 r9263 105 105 } 106 106 107 void SpaceRaceManager::checkpointReached(RaceCheckPoint* check, PlayerInfo* player) 107 bool SpaceRaceManager::reachedValidCheckpoint(RaceCheckPoint* oldCheckpoint, RaceCheckPoint* newCheckpoint, PlayerInfo* player) const 108 { 109 if (oldCheckpoint) 110 { 111 // the player already visited an old checkpoint; see which checkpoints are possible now 112 const std::set<int>& possibleCheckpoints = oldCheckpoint->getNextCheckpoints(); 113 for (std::set<int>::const_iterator it = possibleCheckpoints.begin(); it != possibleCheckpoints.end(); ++it) 114 if (this->findCheckpoint(*it) == newCheckpoint) 115 return true; 116 return false; 117 } 118 else 119 { 120 // the player hasn't visited a checkpoint yet, so he must reach the checkpoint with index 0 (hack?) 121 return (newCheckpoint->getCheckpointIndex() == 0); 122 } 123 } 124 125 void SpaceRaceManager::checkpointReached(RaceCheckPoint* newCheckpoint, PlayerInfo* player) 108 126 { 109 127 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); 110 128 assert(gametype); 129 if (!gametype) 130 return; 111 131 112 bool reachedValidCheckpoint = false;132 RaceCheckPoint* oldCheckpoint = gametype->getCheckpointReached(player); 113 133 114 int index = gametype->getCheckpointReached(player); 115 if (index > -1) 134 if (this->reachedValidCheckpoint(oldCheckpoint, newCheckpoint, player)) 116 135 { 117 Vector3 v = this->findCheckpoint(index)->getNextcheckpoint(); 118 119 if (this->findCheckpoint(v.x) == check) 120 { 121 reachedValidCheckpoint = true; 122 } 123 if (this->findCheckpoint(v.y) == check) 124 { 125 reachedValidCheckpoint = true; 126 } 127 if (this->findCheckpoint(v.z) == check) 128 { 129 reachedValidCheckpoint = true; 130 } 131 } 132 else 133 { 134 reachedValidCheckpoint = (check->getCheckpointIndex() == 0); 135 } 136 137 if (gametype && reachedValidCheckpoint) 138 { 136 // the player reached a valid checkpoint 139 137 gametype->getClock().capture(); 140 138 float time = gametype->getClock().getSecondsPrecise(); 141 if ( check->getTimeLimit() != 0 && time > check->getTimeLimit())139 if (newCheckpoint->getTimeLimit() != 0 && time > newCheckpoint->getTimeLimit()) 142 140 { 141 // time's up - the player has lost the game 143 142 gametype->setTimeIsUp(); 144 143 gametype->end(); 145 144 } 146 else if (check->isLast()) 145 else if (newCheckpoint->isLast()) 146 { 147 // the last checkpoint was reached - the player has won the game 147 148 gametype->end(); 149 } 148 150 else 149 151 { 150 if (index > -1) 151 this->setRadarVisibility(player, false); 152 else 153 this->findCheckpoint(0)->setRadarVisibility(false); 154 155 gametype->newCheckpointReached(check, player); 156 this->setRadarVisibility(player, true); 152 // adjust the radarvisibility 153 gametype->newCheckpointReached(newCheckpoint, player); 154 this->updateRadarVisibility(oldCheckpoint, newCheckpoint); 157 155 } 158 156 } 159 157 160 check->resetPlayer();158 newCheckpoint->resetPlayer(); 161 159 } 162 160 163 void SpaceRaceManager:: setRadarVisibility(PlayerInfo* player, bool bVisible)161 void SpaceRaceManager::updateRadarVisibility(RaceCheckPoint* oldCheckpoint, RaceCheckPoint* newCheckpoint) const 164 162 { 165 SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get()); 166 assert(gametype); 167 int index = gametype->getCheckpointReached(player); 168 Vector3 v = this->findCheckpoint(index)->getNextcheckpoint(); 163 if (oldCheckpoint) 164 { 165 const std::set<int>& oldVisible = oldCheckpoint->getNextCheckpoints(); 166 for (std::set<int>::const_iterator it = oldVisible.begin(); it != oldVisible.end(); ++it) 167 this->findCheckpoint(*it)->setRadarVisibility(false); 168 } 169 169 170 if ( v.x > -1)170 if (newCheckpoint) 171 171 { 172 this->findCheckpoint(v.x)->setRadarVisibility(bVisible); 173 this->findCheckpoint(v.x)->settingsChanged(); 174 } 175 if (v.y > -1) 176 { 177 this->findCheckpoint(v.y)->setRadarVisibility(bVisible); 178 this->findCheckpoint(v.y)->settingsChanged(); 179 } 180 if (v.z > -1) 181 { 182 this->findCheckpoint(v.z)->setRadarVisibility(bVisible); 183 this->findCheckpoint(v.z)->settingsChanged(); 172 newCheckpoint->setRadarVisibility(false); 173 174 const std::set<int>& newVisible = newCheckpoint->getNextCheckpoints(); 175 for (std::set<int>::const_iterator it = newVisible.begin(); it != newVisible.end(); ++it) 176 this->findCheckpoint(*it)->setRadarVisibility(true); 184 177 } 185 178 }
Note: See TracChangeset
for help on using the changeset viewer.