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/TeamGametype.cc

    r9941 r11071  
    7575    void TeamGametype::playerEntered(PlayerInfo* player)
    7676    {
    77         if(player == NULL) return; // catch null pointers
     77        if(player == nullptr) return; // catch null pointers
    7878        Gametype::playerEntered(player);
    7979        this->findAndSetTeam(player);
     
    9696    void TeamGametype::findAndSetTeam(PlayerInfo* player)
    9797    {
    98         if(player == NULL) return; // catch null pointers
     98        if(player == nullptr) return; // catch null pointers
    9999        std::vector<unsigned int> playersperteam(this->teams_, 0);
    100100
    101         for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
    102             if (it->second < static_cast<int>(this->teams_) && it->second >= 0)
    103                 playersperteam[it->second]++;
     101        for (const auto& mapEntry : this->teamnumbers_)
     102            if (mapEntry.second < static_cast<int>(this->teams_) && mapEntry.second >= 0)
     103                playersperteam[mapEntry.second]++;
    104104
    105105        unsigned int minplayers = static_cast<unsigned int>(-1);
     
    123123        if( (this->players_.size() >= maxPlayers_) && (allowedInGame_[player] == true) ) // if there's a "waiting list"
    124124        {
    125             for (std::map<PlayerInfo*, bool>::iterator it = this->allowedInGame_.begin(); it != this->allowedInGame_.end(); ++it)
    126             {
    127                  if(it->second == false) // waiting player found
    128                  {it->second = true; break;} // allow player to enter
     125            for (auto& mapEntry : this->allowedInGame_)
     126            {
     127                 if(mapEntry.second == false) // waiting player found
     128                 {mapEntry.second = true; break;} // allow player to enter
    129129            }
    130130        }
     
    141141    void TeamGametype::spawnDeadPlayersIfRequested()
    142142    {
    143         for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)\
    144         {
    145             if(allowedInGame_[it->first] == false)//check if dead player is allowed to enter
     143        for (const auto& mapEntry : this->players_)\
     144        {
     145            if(allowedInGame_[mapEntry.first] == false)//check if dead player is allowed to enter
    146146            {
    147147                continue;
    148148            }
    149             if (it->second.state_ == PlayerState::Dead)
    150             {
    151                 if ((it->first->isReadyToSpawn() || this->bForceSpawn_))
     149            if (mapEntry.second.state_ == PlayerState::Dead)
     150            {
     151                if ((mapEntry.first->isReadyToSpawn() || this->bForceSpawn_))
    152152                {
    153                    this->spawnPlayer(it->first);
     153                   this->spawnPlayer(mapEntry.first);
    154154                }
    155155            }
     
    178178        if(!player || this->getTeam(player) == -1)
    179179            return 0;
    180         for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    181         {
    182             if ( this->getTeam(it->first) ==  this->getTeam(player) )
    183             {
    184                 teamscore += it->second.frags_;
     180        for (const auto& mapEntry : this->players_)
     181        {
     182            if ( this->getTeam(mapEntry.first) ==  this->getTeam(player) )
     183            {
     184                teamscore += mapEntry.second.frags_;
    185185            }
    186186        }
     
    191191    {
    192192        int teamSize = 0;
    193         for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
    194         {
    195             if (it->second == team)
     193        for (const auto& mapEntry : this->teamnumbers_)
     194        {
     195            if (mapEntry.second == team)
    196196                teamSize++;
    197197        }
     
    202202    {
    203203        int teamSize = 0;
    204         for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
    205         {
    206             if (it->second == team  && it->first->isHumanPlayer())
     204        for (const auto& mapEntry : this->teamnumbers_)
     205        {
     206            if (mapEntry.second == team  && mapEntry.first->isHumanPlayer())
    207207                teamSize++;
    208208        }
     
    235235        }
    236236
    237         SpawnPoint* fallbackSpawnPoint = NULL;
     237        SpawnPoint* fallbackSpawnPoint = nullptr;
    238238        if (teamSpawnPoints.size() > 0)
    239239        {
     
    241241            unsigned int index = 0;
    242242            // Get random fallback spawnpoint in case there is no active SpawnPoint.
    243             for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it)
     243            for (SpawnPoint* teamSpawnPoint : teamSpawnPoints)
    244244            {
    245245                if (index == randomspawn)
    246246                {
    247                     fallbackSpawnPoint = (*it);
     247                    fallbackSpawnPoint = teamSpawnPoint;
    248248                    break;
    249249                }
     
    266266            randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size())));
    267267            index = 0;
    268             for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it)
     268            for (SpawnPoint* teamSpawnPoint : teamSpawnPoints)
    269269            {
    270270                if (index == randomspawn)
    271                     return (*it);
     271                    return teamSpawnPoint;
    272272
    273273                ++index;
     
    277277        }
    278278
    279         return 0;
     279        return nullptr;
    280280    }
    281281
     
    328328    void TeamGametype::setDefaultObjectColour(Pawn* pawn)
    329329    {
    330         if(pawn == NULL)
     330        if(pawn == nullptr)
    331331            return;
    332332
     
    340340        ControllableEntity* entity = orxonox_cast<ControllableEntity*>(pawn);
    341341
    342         Controller* controller = 0;
     342        Controller* controller = nullptr;
    343343        if (entity->getController())
    344344            controller = entity->getController();
     
    350350        ArtificialController* artificial =  orxonox_cast<ArtificialController*>(controller);
    351351        //get Teamnumber - get the data
    352         if(artificial == NULL)
     352        if(artificial == nullptr)
    353353            return;
    354354        teamnumber= artificial->getTeam();
     
    360360    void TeamGametype::colourPawn(Pawn* pawn, int teamNr)
    361361    {// catch: no-colouring-case and wrong input
    362         if(teamNr < 0 || teamNr+1 > int(this->teamcolours_.size()) ||pawn == NULL) return;
     362        if(teamNr < 0 || teamNr+1 > int(this->teamcolours_.size()) ||pawn == nullptr) return;
    363363        pawn->setRadarObjectColour(this->teamcolours_[teamNr]);
    364364
    365365        std::set<WorldEntity*> pawnAttachments = pawn->getAttachedObjects();
    366         for (std::set<WorldEntity*>::iterator it = pawnAttachments.begin(); it != pawnAttachments.end(); ++it)
    367         {
    368             if ((*it)->isA(Class(TeamColourable)))
    369             {
    370                 TeamColourable* tc = orxonox_cast<TeamColourable*>(*it);
     366        for (WorldEntity* pawnAttachment : pawnAttachments)
     367        {
     368            if (pawnAttachment->isA(Class(TeamColourable)))
     369            {
     370                TeamColourable* tc = orxonox_cast<TeamColourable*>(pawnAttachment);
    371371                tc->setTeamColour(this->teamcolours_[teamNr]);
    372372            }
     
    376376    void TeamGametype::announceTeamWin(int winnerTeam)
    377377    {
    378         for (std::map<PlayerInfo*, int>::iterator it3 = this->teamnumbers_.begin(); it3 != this->teamnumbers_.end(); ++it3)
    379         {
    380             if (it3->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
     378        for (const auto& mapEntry : this->teamnumbers_)
     379        {
     380            if (mapEntry.first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
    381381                continue;
    382             if (it3->second == winnerTeam)
    383             {
    384                 this->gtinfo_->sendAnnounceMessage("Your team has won the match!", it3->first->getClientID());
     382            if (mapEntry.second == winnerTeam)
     383            {
     384                this->gtinfo_->sendAnnounceMessage("Your team has won the match!", mapEntry.first->getClientID());
    385385            }
    386386            else
    387387            {
    388                 this->gtinfo_->sendAnnounceMessage("Your team has lost the match!", it3->first->getClientID());
     388                this->gtinfo_->sendAnnounceMessage("Your team has lost the match!", mapEntry.first->getClientID());
    389389            }
    390390        }   
Note: See TracChangeset for help on using the changeset viewer.