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

    r9941 r10821  
    145145    void LastTeamStanding::spawnDeadPlayersIfRequested()
    146146    {
    147         for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    148             if (it->second.state_ == PlayerState::Dead)
    149             {
    150                 bool alive = (0 < playerLives_[it->first]&&(inGame_[it->first]));
    151                 if (alive&&(it->first->isReadyToSpawn() || this->bForceSpawn_))
    152                 {
    153                     this->spawnPlayer(it->first);
     147        for (auto & elem : this->players_)
     148            if (elem.second.state_ == PlayerState::Dead)
     149            {
     150                bool alive = (0 < playerLives_[elem.first]&&(inGame_[elem.first]));
     151                if (alive&&(elem.first->isReadyToSpawn() || this->bForceSpawn_))
     152                {
     153                    this->spawnPlayer(elem.first);
    154154                }
    155155            }
     
    184184                this->end();
    185185            }
    186             for (std::map<PlayerInfo*, float>::iterator it = this->timeToAct_.begin(); it != this->timeToAct_.end(); ++it)
    187             {
    188                 if (playerGetLives(it->first) <= 0)//Players without lives shouldn't be affected by time.
     186            for (auto & elem : this->timeToAct_)
     187            {
     188                if (playerGetLives(elem.first) <= 0)//Players without lives shouldn't be affected by time.
    189189                    continue;
    190                 it->second -= dt;//Decreases punishment time.
    191                 if (!inGame_[it->first])//Manages respawn delay - player is forced to respawn after the delaytime is used up.
    192                 {
    193                     playerDelayTime_[it->first] -= dt;
    194                     if (playerDelayTime_[it->first] <= 0)
    195                     this->inGame_[it->first] = true;
    196 
    197                     if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
     190                elem.second -= dt;//Decreases punishment time.
     191                if (!inGame_[elem.first])//Manages respawn delay - player is forced to respawn after the delaytime is used up.
     192                {
     193                    playerDelayTime_[elem.first] -= dt;
     194                    if (playerDelayTime_[elem.first] <= 0)
     195                    this->inGame_[elem.first] = true;
     196
     197                    if (elem.first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
    198198                        continue;
    199                     int output = 1 + (int)playerDelayTime_[it->first];
     199                    int output = 1 + (int)playerDelayTime_[elem.first];
    200200                    const std::string& message = "Respawn in " +multi_cast<std::string>(output)+ " seconds." ;//Countdown
    201                     this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
    202                 }
    203                 else if (it->second < 0.0f)
    204                 {
    205                     it->second = timeRemaining + 3.0f;//reset punishment-timer
    206                     if (playerGetLives(it->first) > 0)
     201                    this->gtinfo_->sendFadingMessage(message,elem.first->getClientID());
     202                }
     203                else if (elem.second < 0.0f)
     204                {
     205                    elem.second = timeRemaining + 3.0f;//reset punishment-timer
     206                    if (playerGetLives(elem.first) > 0)
    207207                    {
    208                         this->punishPlayer(it->first);
    209                         if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
     208                        this->punishPlayer(elem.first);
     209                        if (elem.first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
    210210                            return;
    211211                        const std::string& message = ""; // resets Camper-Warning-message
    212                         this->gtinfo_->sendFadingMessage(message, it->first->getClientID());
     212                        this->gtinfo_->sendFadingMessage(message, elem.first->getClientID());
    213213                    }
    214214                }
    215                 else if (it->second < timeRemaining/5)//Warning message
    216                 {
    217                   if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
     215                else if (elem.second < timeRemaining/5)//Warning message
     216                {
     217                  if (elem.first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
    218218                        continue;
    219219                    const std::string& message = "Camper Warning! Don't forget to shoot.";
    220                     this->gtinfo_->sendFadingMessage(message, it->first->getClientID());
     220                    this->gtinfo_->sendFadingMessage(message, elem.first->getClientID());
    221221                }
    222222            }
     
    229229        int party = -1;
    230230        //find a player who survived
    231         for (std::map<PlayerInfo*, int>::iterator it = this->playerLives_.begin(); it != this->playerLives_.end(); ++it)
    232         {
    233           if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
     231        for (auto & elem : this->playerLives_)
     232        {
     233          if (elem.first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
    234234                continue;
    235235
    236             if (it->second > 0)//a player that is alive
     236            if (elem.second > 0)//a player that is alive
    237237            {
    238238                //which party has survived?
    239                 std::map<PlayerInfo*, int>::iterator it2 = this->teamnumbers_.find(it->first);
     239                std::map<PlayerInfo*, int>::iterator it2 = this->teamnumbers_.find(elem.first);
    240240                if (it2 != this->teamnumbers_.end())
    241241                {
     
    255255    {
    256256        int min = lives;
    257         for (std::map<PlayerInfo*, int>::iterator it = this->playerLives_.begin(); it != this->playerLives_.end(); ++it)
    258         {
    259             if (it->second <= 0)
     257        for (auto & elem : this->playerLives_)
     258        {
     259            if (elem.second <= 0)
    260260                continue;
    261             if (it->second < lives)
    262                 min = it->second;
     261            if (elem.second < lives)
     262                min = elem.second;
    263263        }
    264264        return min;
Note: See TracChangeset for help on using the changeset viewer.