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

    r9667 r10821  
    5656    void LastManStanding::spawnDeadPlayersIfRequested()
    5757    {
    58         for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    59             if (it->second.state_ == PlayerState::Dead)
    60             {
    61                 bool alive = (0<playerLives_[it->first]&&(inGame_[it->first]));
    62                 if (alive&&(it->first->isReadyToSpawn() || this->bForceSpawn_))
    63                 {
    64                     this->spawnPlayer(it->first);
     58        for (auto & elem : this->players_)
     59            if (elem.second.state_ == PlayerState::Dead)
     60            {
     61                bool alive = (0<playerLives_[elem.first]&&(inGame_[elem.first]));
     62                if (alive&&(elem.first->isReadyToSpawn() || this->bForceSpawn_))
     63                {
     64                    this->spawnPlayer(elem.first);
    6565                }
    6666            }
     
    114114    {
    115115        int min=lives;
    116         for (std::map<PlayerInfo*, int>::iterator it = this->playerLives_.begin(); it != this->playerLives_.end(); ++it)
    117         {
    118             if (it->second<=0)
     116        for (auto & elem : this->playerLives_)
     117        {
     118            if (elem.second<=0)
    119119                continue;
    120             if (it->second<lives)
    121                 min=it->second;
     120            if (elem.second<lives)
     121                min=elem.second;
    122122        }
    123123        return min;
     
    128128        Gametype::end();
    129129
    130         for (std::map<PlayerInfo*, int>::iterator it = this->playerLives_.begin(); it != this->playerLives_.end(); ++it)
    131         {
    132             if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
     130        for (auto & elem : this->playerLives_)
     131        {
     132            if (elem.first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
    133133                continue;
    134134
    135             if (it->second > 0)
    136                 this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
     135            if (elem.second > 0)
     136                this->gtinfo_->sendAnnounceMessage("You have won the match!", elem.first->getClientID());
    137137            else
    138                 this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
     138                this->gtinfo_->sendAnnounceMessage("You have lost the match!", elem.first->getClientID());
    139139        }
    140140    }
     
    237237                this->end();
    238238            }
    239             for (std::map<PlayerInfo*, float>::iterator it = this->timeToAct_.begin(); it != this->timeToAct_.end(); ++it)
    240             {
    241                 if (playerGetLives(it->first)<=0)//Players without lives shouldn't be affected by time.
     239            for (auto & elem : this->timeToAct_)
     240            {
     241                if (playerGetLives(elem.first)<=0)//Players without lives shouldn't be affected by time.
    242242                    continue;
    243                 it->second-=dt;//Decreases punishment time.
    244                 if (!inGame_[it->first])//Manages respawn delay - player is forced to respawn after the delaytime is used up.
    245                 {
    246                     playerDelayTime_[it->first]-=dt;
    247                     if (playerDelayTime_[it->first]<=0)
    248                     this->inGame_[it->first]=true;
    249 
    250                     if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
     243                elem.second-=dt;//Decreases punishment time.
     244                if (!inGame_[elem.first])//Manages respawn delay - player is forced to respawn after the delaytime is used up.
     245                {
     246                    playerDelayTime_[elem.first]-=dt;
     247                    if (playerDelayTime_[elem.first]<=0)
     248                    this->inGame_[elem.first]=true;
     249
     250                    if (elem.first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
    251251                        continue;
    252                     int output=1+(int)playerDelayTime_[it->first];
     252                    int output=1+(int)playerDelayTime_[elem.first];
    253253                    const std::string& message = "Respawn in " +multi_cast<std::string>(output)+ " seconds." ;//Countdown
    254                     this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
    255                 }
    256                 else if (it->second<0.0f)
    257                 {
    258                     it->second=timeRemaining+3.0f;//reset punishment-timer
    259                     if (playerGetLives(it->first)>0)
     254                    this->gtinfo_->sendFadingMessage(message,elem.first->getClientID());
     255                }
     256                else if (elem.second<0.0f)
     257                {
     258                    elem.second=timeRemaining+3.0f;//reset punishment-timer
     259                    if (playerGetLives(elem.first)>0)
    260260                    {
    261                         this->punishPlayer(it->first);
    262                         if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
     261                        this->punishPlayer(elem.first);
     262                        if (elem.first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
    263263                            return;
    264264                        const std::string& message = ""; // resets Camper-Warning-message
    265                         this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
     265                        this->gtinfo_->sendFadingMessage(message,elem.first->getClientID());
    266266                    }
    267267                }
    268                 else if (it->second<timeRemaining/5)//Warning message
    269                 {
    270                     if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
     268                else if (elem.second<timeRemaining/5)//Warning message
     269                {
     270                    if (elem.first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
    271271                        continue;
    272272                    const std::string& message = "Camper Warning! Don't forget to shoot.";
    273                     this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
     273                    this->gtinfo_->sendFadingMessage(message,elem.first->getClientID());
    274274                }
    275275            }
Note: See TracChangeset for help on using the changeset viewer.