Changeset 8571
- Timestamp:
- May 25, 2011, 6:07:35 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/spacerace/src/orxonox/gametypes/Gametype.cc
r8079 r8571 306 306 SpawnPoint* Gametype::getBestSpawnPoint(PlayerInfo* player) const 307 307 { 308 // If there is at least one SpawnPoint. 308 309 if (this->spawnpoints_.size() > 0) 309 310 { 311 // Fallback spawn point if there is no active one, choose a random one. 310 312 SpawnPoint* fallbackSpawnPoint = NULL; 311 313 unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size()))); 312 314 unsigned int index = 0; 313 std:: set<SpawnPoint*> activeSpawnPoints = this->spawnpoints_;315 std::vector<SpawnPoint*> activeSpawnPoints; 314 316 for (std::set<SpawnPoint*>::const_iterator it = this->spawnpoints_.begin(); it != this->spawnpoints_.end(); ++it) 315 317 { … … 317 319 fallbackSpawnPoint = (*it); 318 320 319 if ( !(*it)->isActive())320 activeSpawnPoints. erase(*it);321 if (*it != NULL && (*it)->isActive()) 322 activeSpawnPoints.push_back(*it); 321 323 322 324 ++index; 323 325 } 324 326 325 randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size()))); 326 index = 0; 327 for (std::set<SpawnPoint*>::const_iterator it = activeSpawnPoints.begin(); it != activeSpawnPoints.end(); ++it) 328 { 329 if (index == randomspawn) 330 return (*it); 331 332 ++index; 333 } 334 327 if(activeSpawnPoints.size() > 0) 328 { 329 randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(activeSpawnPoints.size()))); 330 return activeSpawnPoints[randomspawn]; 331 } 332 333 COUT(2) << "Warning: Fallback SpawnPoint was used, because there were no active SpawnPoints." << endl; 335 334 return fallbackSpawnPoint; 336 335 }
Note: See TracChangeset
for help on using the changeset viewer.