Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 21, 2015, 7:05:53 PM (8 years ago)
Author:
muemart
Message:

Run clang-modernize -loop-convert

  • Again, not all possible loops were converted
  • It can do pretty cool transformations, but I had to fix a few compile errors, so there might be some runtime errors lurking around too
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/orxonox/gametypes/TeamGametype.cc

    r10768 r10821  
    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 (auto & elem : this->teamnumbers_)
     102            if (elem.second < static_cast<int>(this->teams_) && elem.second >= 0)
     103                playersperteam[elem.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 & elem : this->allowedInGame_)
     126            {
     127                 if(elem.second == false) // waiting player found
     128                 {elem.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 (auto & elem : this->players_)\
     144        {
     145            if(allowedInGame_[elem.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 (elem.second.state_ == PlayerState::Dead)
     150            {
     151                if ((elem.first->isReadyToSpawn() || this->bForceSpawn_))
    152152                {
    153                    this->spawnPlayer(it->first);
     153                   this->spawnPlayer(elem.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 (auto & elem : this->players_)
     181        {
     182            if ( this->getTeam(elem.first) ==  this->getTeam(player) )
     183            {
     184                teamscore += elem.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 (auto & elem : this->teamnumbers_)
     194        {
     195            if (elem.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 (auto & elem : this->teamnumbers_)
     205        {
     206            if (elem.second == team  && elem.first->isHumanPlayer())
    207207                teamSize++;
    208208        }
     
    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 (const auto & 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 (const auto & teamSpawnPoint : teamSpawnPoints)
    269269            {
    270270                if (index == randomspawn)
    271                     return (*it);
     271                    return (teamSpawnPoint);
    272272
    273273                ++index;
     
    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 (const auto & 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 (auto & elem : this->teamnumbers_)
     379        {
     380            if (elem.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 (elem.second == winnerTeam)
     383            {
     384                this->gtinfo_->sendAnnounceMessage("Your team has won the match!", elem.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!", elem.first->getClientID());
    389389            }
    390390        }   
Note: See TracChangeset for help on using the changeset viewer.