Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 17, 2016, 1:59:00 PM (8 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/SectionController.cc

    r11058 r11065  
    4040        this->setFormationMode(FormationMode::FINGER4);
    4141
    42         this->myWingman_ = 0;
    43         this->myDivisionLeader_ = 0;
     42        this->myWingman_ = nullptr;
     43        this->myDivisionLeader_ = nullptr;
    4444        this->bFirstAction_ = true;
    4545
     
    4848    SectionController::~SectionController()
    4949    {
    50        for (size_t i = 0; i < this->actionpoints_.size(); ++i)
    51         {
    52             if(this->actionpoints_[i])
    53                 this->actionpoints_[i]->destroy();
     50        for (WorldEntity* actionpoint : this->actionpoints_)
     51        {
     52            if (actionpoint)
     53                actionpoint->destroy();
    5454        }
    5555        this->parsedActionpoints_.clear();
     
    117117    {
    118118        //----If division leader fights, cover him by fighting emenies close to his target----
    119         Action::Value action = this->myDivisionLeader_->getAction();
     119        Action action = this->myDivisionLeader_->getAction();
    120120
    121121        if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK)
     
    133133                    Vector3 divisionTargetPosition = this->myDivisionLeader_->getTarget()->getWorldPosition();
    134134                    Gametype* gt = this->getGametype();
    135                     for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>().begin(); itP; ++itP)
     135                    for (Pawn* pawn : ObjectList<Pawn>())
    136136                    {
    137137                        //----is enemy?----
    138                         if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP), gt) )
     138                        if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(pawn), gt) )
    139139                            continue;           
    140140                        //----in range?----
    141                         if (((*itP)->getWorldPosition() - divisionTargetPosition).length() < 3000 &&
    142                             (*itP) != this->myDivisionLeader_->getTarget())
     141                        if ((pawn->getWorldPosition() - divisionTargetPosition).length() < 3000 &&
     142                            pawn != this->myDivisionLeader_->getTarget())
    143143                        {
    144144                            foundTarget = true;
    145                             target =  (*itP);
     145                            target = pawn;
    146146                            break;
    147147                        }
     
    212212
    213213        if (!this->getControllableEntity())
    214             return 0;
    215 
    216         ActionpointController* closestLeader = 0;
     214            return nullptr;
     215
     216        ActionpointController* closestLeader = nullptr;
    217217        float minDistance =  std::numeric_limits<float>::infinity();
    218218        //go through all pawns
    219         for (ObjectList<ActionpointController>::iterator it = ObjectList<ActionpointController>().begin(); it; ++it)
     219        for (ActionpointController* controller : ObjectList<ActionpointController>())
    220220        {
    221221            //0ptr or not DivisionController?
    222             if (!(it) || !((it)->getIdentifier()->getName() == "DivisionController") || !(it->getControllableEntity()))
     222            if (!controller || !(controller->getIdentifier()->getName() == "DivisionController") || !(controller->getControllableEntity()))
    223223                continue;
    224224            //same team?
    225             if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()))
     225            if ((this->getControllableEntity()->getTeam() != controller->getControllableEntity()->getTeam()))
    226226                continue;
    227227
    228228            //is equal to this?
    229             if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
     229            if (orxonox_cast<ControllableEntity*>(controller) == this->getControllableEntity())
    230230                continue;
    231231
    232             float distance = CommonController::distance (it->getControllableEntity(), this->getControllableEntity());
     232            float distance = CommonController::distance (controller->getControllableEntity(), this->getControllableEntity());
    233233           
    234             if (distance < minDistance && !(it->hasFollower()))
    235             {
    236                 closestLeader = *it;
     234            if (distance < minDistance && !(controller->hasFollower()))
     235            {
     236                closestLeader = controller;
    237237                minDistance = distance;
    238238            }
     
    244244                return closestLeader;
    245245        }
    246         return 0;
     246        return nullptr;
    247247    }
    248248
Note: See TracChangeset for help on using the changeset viewer.