- Timestamp:
- Jan 10, 2016, 1:54:11 PM (8 years ago)
- Location:
- code/branches/cpp11_v3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/cpp11_v3
- Property svn:mergeinfo changed
-
code/branches/cpp11_v3/src/orxonox/gametypes/Gametype.cc
r10624 r11054 66 66 67 67 this->defaultControllableEntity_ = Class(Spectator); 68 this->scoreboard_ = 0;68 this->scoreboard_ = nullptr; 69 69 70 70 this->bAutoStart_ = false; … … 92 92 this->gtinfo_->destroy(); 93 93 94 ModifyConsoleCommand(__CC_addBots_name).setObject( NULL);95 ModifyConsoleCommand(__CC_killBots_name).setObject( NULL);94 ModifyConsoleCommand(__CC_addBots_name).setObject(nullptr); 95 ModifyConsoleCommand(__CC_killBots_name).setObject(nullptr); 96 96 } 97 97 } … … 139 139 if (!this->gtinfo_->hasStarted()) 140 140 { 141 for ( std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)141 for (const auto& mapEntry : this->players_) 142 142 { 143 143 // Inform the GametypeInfo that the player is ready to spawn. 144 if( it->first->isHumanPlayer() && it->first->isReadyToSpawn())145 this->gtinfo_->playerReadyToSpawn( it->first);144 if(mapEntry.first->isHumanPlayer() && mapEntry.first->isReadyToSpawn()) 145 this->gtinfo_->playerReadyToSpawn(mapEntry.first); 146 146 } 147 147 … … 169 169 } 170 170 171 for ( std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)172 { 173 if ( it->first->getControllableEntity())174 { 175 ControllableEntity* oldentity = it->first->getControllableEntity();171 for (const auto& mapEntry : this->players_) 172 { 173 if (mapEntry.first->getControllableEntity()) 174 { 175 ControllableEntity* oldentity = mapEntry.first->getControllableEntity(); 176 176 177 177 ControllableEntity* entity = this->defaultControllableEntity_.fabricate(oldentity->getContext()); … … 186 186 entity->setOrientation(oldentity->getWorldOrientation()); 187 187 } 188 it->first->startControl(entity);188 mapEntry.first->startControl(entity); 189 189 } 190 190 else 191 this->spawnPlayerAsDefaultPawn( it->first);191 this->spawnPlayerAsDefaultPawn(mapEntry.first); 192 192 } 193 193 } … … 337 337 { 338 338 // Fallback spawn point if there is no active one, choose a random one. 339 SpawnPoint* fallbackSpawnPoint = NULL;339 SpawnPoint* fallbackSpawnPoint = nullptr; 340 340 unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size()))); 341 341 unsigned int index = 0; 342 342 std::vector<SpawnPoint*> activeSpawnPoints; 343 for ( std::set<SpawnPoint*>::const_iterator it = this->spawnpoints_.begin(); it != this->spawnpoints_.end(); ++it)343 for (SpawnPoint* spawnpoint : this->spawnpoints_) 344 344 { 345 345 if (index == randomspawn) 346 fallbackSpawnPoint = (*it);347 348 if ( *it != NULL && (*it)->isActive())349 activeSpawnPoints.push_back( *it);346 fallbackSpawnPoint = spawnpoint; 347 348 if (spawnpoint != nullptr && spawnpoint->isActive()) 349 activeSpawnPoints.push_back(spawnpoint); 350 350 351 351 ++index; … … 361 361 return fallbackSpawnPoint; 362 362 } 363 return 0;363 return nullptr; 364 364 } 365 365 366 366 void Gametype::assignDefaultPawnsIfNeeded() 367 367 { 368 for ( std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)369 { 370 if (! it->first->getControllableEntity())371 { 372 it->second.state_ = PlayerState::Dead;373 374 if (! it->first->isReadyToSpawn() || !this->gtinfo_->hasStarted())375 { 376 this->spawnPlayerAsDefaultPawn( it->first);377 it->second.state_ = PlayerState::Dead;368 for (auto& mapEntry : this->players_) 369 { 370 if (!mapEntry.first->getControllableEntity()) 371 { 372 mapEntry.second.state_ = PlayerState::Dead; 373 374 if (!mapEntry.first->isReadyToSpawn() || !this->gtinfo_->hasStarted()) 375 { 376 this->spawnPlayerAsDefaultPawn(mapEntry.first); 377 mapEntry.second.state_ = PlayerState::Dead; 378 378 } 379 379 } … … 404 404 bool allplayersready = true; 405 405 bool hashumanplayers = false; 406 for ( std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)406 for (const auto& mapEntry : this->players_) 407 407 { 408 if (! it->first->isReadyToSpawn())408 if (!mapEntry.first->isReadyToSpawn()) 409 409 allplayersready = false; 410 if ( it->first->isHumanPlayer())410 if (mapEntry.first->isHumanPlayer()) 411 411 hashumanplayers = true; 412 412 } … … 430 430 void Gametype::spawnPlayersIfRequested() 431 431 { 432 for ( std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)433 { 434 if ( it->first->isReadyToSpawn() || this->bForceSpawn_)435 this->spawnPlayer( it->first);432 for (const auto& mapEntry : this->players_) 433 { 434 if (mapEntry.first->isReadyToSpawn() || this->bForceSpawn_) 435 this->spawnPlayer(mapEntry.first); 436 436 } 437 437 } … … 439 439 void Gametype::spawnDeadPlayersIfRequested() 440 440 { 441 for ( std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)442 if ( it->second.state_ == PlayerState::Dead)443 if ( it->first->isReadyToSpawn() || this->bForceSpawn_)444 this->spawnPlayer( it->first);441 for (const auto& mapEntry : this->players_) 442 if (mapEntry.second.state_ == PlayerState::Dead) 443 if (mapEntry.first->isReadyToSpawn() || this->bForceSpawn_) 444 this->spawnPlayer(mapEntry.first); 445 445 } 446 446 … … 492 492 { 493 493 unsigned int i = 0; 494 for (ObjectList<Bot>::iterator it = ObjectList<Bot>::begin(); (it != ObjectList<Bot>::end()) && ((amount == 0) || (i < amount)); ) 494 ObjectList<Bot> list; 495 for (ObjectList<Bot>::iterator it = list.begin(); (it != list.end()) && ((amount == 0) || (i < amount)); ) 495 496 { 496 497 if (it->getGametype() == this) … … 538 539 GSLevelMementoState* Gametype::exportMementoState() 539 540 { 540 for ( std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)541 { 542 if ( it->first->isHumanPlayer() && it->first->getControllableEntity() && it->first->getControllableEntity()->getCamera())543 { 544 Camera* camera = it->first->getControllableEntity()->getCamera();541 for (const auto& mapEntry : this->players_) 542 { 543 if (mapEntry.first->isHumanPlayer() && mapEntry.first->getControllableEntity() && mapEntry.first->getControllableEntity()->getCamera()) 544 { 545 Camera* camera = mapEntry.first->getControllableEntity()->getCamera(); 545 546 546 547 GametypeMementoState* state = new GametypeMementoState(); … … 552 553 } 553 554 554 return NULL;555 return nullptr; 555 556 } 556 557 … … 558 559 { 559 560 // find correct memento state 560 GametypeMementoState* state = NULL;561 for ( size_t i = 0; i < states.size(); ++i)562 { 563 state = dynamic_cast<GametypeMementoState*>( states[i]);561 GametypeMementoState* state = nullptr; 562 for (GSLevelMementoState* temp : states) 563 { 564 state = dynamic_cast<GametypeMementoState*>(temp); 564 565 if (state) 565 566 break; … … 570 571 571 572 // find correct scene 572 Scene* scene = NULL;573 for ( ObjectList<Scene>::iterator it = ObjectList<Scene>::begin(); it != ObjectList<Scene>::end(); ++it)574 { 575 if ( it->getName() == state->sceneName_)576 { 577 scene = *it;573 Scene* scene = nullptr; 574 for (Scene* someScene : ObjectList<Scene>()) 575 { 576 if (someScene->getName() == state->sceneName_) 577 { 578 scene = someScene; 578 579 break; 579 580 } … … 587 588 588 589 // find correct player and assign default entity with original position & orientation 589 for ( std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)590 { 591 if ( it->first->isHumanPlayer())590 for (const auto& mapEntry : this->players_) 591 { 592 if (mapEntry.first->isHumanPlayer()) 592 593 { 593 594 ControllableEntity* entity = this->defaultControllableEntity_.fabricate(scene->getContext()); 594 595 entity->setPosition(state->cameraPosition_); 595 596 entity->setOrientation(state->cameraOrientation_); 596 it->first->startControl(entity);597 mapEntry.first->startControl(entity); 597 598 break; 598 599 }
Note: See TracChangeset
for help on using the changeset viewer.