Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 17, 2016, 1:59:00 PM (9 years ago)
Author:
landauf
Message:

added c++11 features to code that was added in presentationHS15

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v3/src/orxonox/controllers/FightingController.cc

    r11057 r11065  
    238238    {
    239239        if (!this || !this->getControllableEntity())
    240             return 0;
    241 
    242         Pawn* closestTarget = 0;
     240            return nullptr;
     241
     242        Pawn* closestTarget = nullptr;
    243243        float minDistance =  std::numeric_limits<float>::infinity();
    244244        Gametype* gt = this->getGametype();
    245         for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>().begin(); itP; ++itP)
    246         {
    247             if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP), gt) )
     245        for (Pawn* pawn : ObjectList<Pawn>())
     246        {
     247            if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(pawn), gt) )
    248248                continue;
    249249
    250             float distance = CommonController::distance (*itP, this->getControllableEntity());
     250            float distance = CommonController::distance (pawn, this->getControllableEntity());
    251251            if (distance < minDistance)
    252252            {
    253                 closestTarget = *itP;
     253                closestTarget = pawn;
    254254                minDistance = distance;
    255255            }
     
    259259           return closestTarget;
    260260        }
    261         return 0; 
     261        return nullptr;
    262262    }
    263263    //I checked it out, rockets DO NOT cause any problems! this->getControllableEntity() is always a SpaceShip
     
    335335            {
    336336                this->weaponModes_.clear(); // reset previous weapon information
    337                 WeaponSlot* wSlot = 0;
     337                WeaponSlot* wSlot = nullptr;
    338338                for(int l=0; (wSlot = pawn->getWeaponSlot(l)) ; l++)
    339339                {
    340                     WeaponMode* wMode = 0;
     340                    WeaponMode* wMode = nullptr;
    341341                    for(int i=0; (wMode = wSlot->getWeapon()->getWeaponmode(i)) ; i++)
    342342                    {
     
    356356    }
    357357
    358     int FightingController::getFiremode(std::string name)
    359     {
    360         for (std::map< std::string, int >::iterator it = this->weaponModes_.begin(); it != this->weaponModes_.end(); ++it)
    361         {
    362             if (it->first == name)
    363                 return it->second;
     358    int FightingController::getFiremode(const std::string& name)
     359    {
     360        for (const auto& mapEntry : this->weaponModes_)
     361        {
     362            if (mapEntry.first == name)
     363                return mapEntry.second;
    364364        }
    365365        return -1;
Note: See TracChangeset for help on using the changeset viewer.