Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 17, 2016, 10:29:21 PM (8 years ago)
Author:
landauf
Message:

merged branch cpp11_v3 back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/gametypes/Gametype.cc

    r10624 r11071  
    6666
    6767        this->defaultControllableEntity_ = Class(Spectator);
    68         this->scoreboard_ = 0;
     68        this->scoreboard_ = nullptr;
    6969
    7070        this->bAutoStart_ = false;
     
    9292                this->gtinfo_->destroy();
    9393
    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);
    9696        }
    9797    }
     
    139139        if (!this->gtinfo_->hasStarted())
    140140        {
    141             for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     141            for (const auto& mapEntry : this->players_)
    142142            {
    143143                // 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);
    146146            }
    147147
     
    169169        }
    170170
    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();
    176176
    177177                ControllableEntity* entity = this->defaultControllableEntity_.fabricate(oldentity->getContext());
     
    186186                    entity->setOrientation(oldentity->getWorldOrientation());
    187187                }
    188                 it->first->startControl(entity);
     188                mapEntry.first->startControl(entity);
    189189            }
    190190            else
    191                 this->spawnPlayerAsDefaultPawn(it->first);
     191                this->spawnPlayerAsDefaultPawn(mapEntry.first);
    192192        }
    193193    }
     
    337337        {
    338338            // Fallback spawn point if there is no active one, choose a random one.
    339             SpawnPoint* fallbackSpawnPoint = NULL;
     339            SpawnPoint* fallbackSpawnPoint = nullptr;
    340340            unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size())));
    341341            unsigned int index = 0;
    342342            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_)
    344344            {
    345345                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);
    350350
    351351                ++index;
     
    361361            return fallbackSpawnPoint;
    362362        }
    363         return 0;
     363        return nullptr;
    364364    }
    365365
    366366    void Gametype::assignDefaultPawnsIfNeeded()
    367367    {
    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;
    378378                }
    379379            }
     
    404404                    bool allplayersready = true;
    405405                    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_)
    407407                    {
    408                         if (!it->first->isReadyToSpawn())
     408                        if (!mapEntry.first->isReadyToSpawn())
    409409                            allplayersready = false;
    410                         if (it->first->isHumanPlayer())
     410                        if (mapEntry.first->isHumanPlayer())
    411411                            hashumanplayers = true;
    412412                    }
     
    430430    void Gametype::spawnPlayersIfRequested()
    431431    {
    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);
    436436        }
    437437    }
     
    439439    void Gametype::spawnDeadPlayersIfRequested()
    440440    {
    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);
    445445    }
    446446
     
    492492    {
    493493        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)); )
    495496        {
    496497            if (it->getGametype() == this)
     
    538539    GSLevelMementoState* Gametype::exportMementoState()
    539540    {
    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();
    545546
    546547                GametypeMementoState* state = new GametypeMementoState();
     
    552553        }
    553554
    554         return NULL;
     555        return nullptr;
    555556    }
    556557
     
    558559    {
    559560        // 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);
    564565            if (state)
    565566                break;
     
    570571
    571572        // 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;
    578579                break;
    579580            }
     
    587588
    588589        // 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())
    592593            {
    593594                ControllableEntity* entity = this->defaultControllableEntity_.fabricate(scene->getContext());
    594595                entity->setPosition(state->cameraPosition_);
    595596                entity->setOrientation(state->cameraOrientation_);
    596                 it->first->startControl(entity);
     597                mapEntry.first->startControl(entity);
    597598                break;
    598599            }
Note: See TracChangeset for help on using the changeset viewer.