Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 17, 2016, 10:29:21 PM (8 years ago)
Author:
landauf
Message:

merged branch cpp11_v3 back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/controllers/SectionController.cc

    r11052 r11071  
    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();
    5656        this->actionpoints_.clear();
    57     }
    58     void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    59     {
    60         SUPER(SectionController, XMLPort, xmlelement, mode);
    61     }
    62 
    63     //----in tick, move (or look) and shoot----
    64     void SectionController::tick(float dt)
    65     {
    66         if (!this->isActive())
    67             return;
    68    
    69         SUPER(SectionController, tick, dt);
    70        
    7157    }
    7258
     
    131117    {
    132118        //----If division leader fights, cover him by fighting emenies close to his target----
    133         Action::Value action = this->myDivisionLeader_->getAction();
     119        Action action = this->myDivisionLeader_->getAction();
    134120
    135121        if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK)
     
    147133                    Vector3 divisionTargetPosition = this->myDivisionLeader_->getTarget()->getWorldPosition();
    148134                    Gametype* gt = this->getGametype();
    149                     for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
     135                    for (Pawn* pawn : ObjectList<Pawn>())
    150136                    {
    151137                        //----is enemy?----
    152                         if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP), gt) )
     138                        if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(pawn), gt) )
    153139                            continue;           
    154140                        //----in range?----
    155                         if (((*itP)->getWorldPosition() - divisionTargetPosition).length() < 3000 &&
    156                             (*itP) != this->myDivisionLeader_->getTarget())
     141                        if ((pawn->getWorldPosition() - divisionTargetPosition).length() < 3000 &&
     142                            pawn != this->myDivisionLeader_->getTarget())
    157143                        {
    158144                            foundTarget = true;
    159                             target =  (*itP);
     145                            target = pawn;
    160146                            break;
    161147                        }
     
    188174        this->setFormationMode( this->myDivisionLeader_->getFormationMode() );
    189175        this->spread_ = this->myDivisionLeader_->getSpread();
    190         Vector3* targetRelativePosition;
    191176        switch (this->formationMode_){
    192177            case FormationMode::WALL:
    193             {
    194                 targetRelativePosition = new Vector3 (-2.0f*this->spread_, 0, 0);   
    195                 break;
    196             }
     178                return Vector3 (-2.0f*this->spread_, 0, 0);
     179
    197180            case FormationMode::FINGER4:
    198             {
    199                 targetRelativePosition = new Vector3 (-2.0f*this->spread_, 0, 1.0f*this->spread_);   
    200                 break;
    201             }
     181                return Vector3 (-2.0f*this->spread_, 0, 1.0f*this->spread_);
    202182           
    203183            case FormationMode::DIAMOND:
    204             {
    205                 targetRelativePosition = new Vector3 (-2.0f*this->spread_, 0, 1.0f*this->spread_);
    206                 break;
    207             }
    208         }
    209         Vector3 result = *targetRelativePosition;
    210         delete targetRelativePosition;
    211         return result;
     184                return Vector3 (-2.0f*this->spread_, 0, 1.0f*this->spread_);
     185
     186            default:
     187                return Vector3::ZERO;
     188        }
    212189    }
    213190
     
    226203
    227204        if (!this->getControllableEntity())
    228             return 0;
    229 
    230         ActionpointController* closestLeader = 0;
     205            return nullptr;
     206
     207        ActionpointController* closestLeader = nullptr;
    231208        float minDistance =  std::numeric_limits<float>::infinity();
    232209        //go through all pawns
    233         for (ObjectList<ActionpointController>::iterator it = ObjectList<ActionpointController>::begin(); it; ++it)
     210        for (ActionpointController* controller : ObjectList<ActionpointController>())
    234211        {
    235212            //0ptr or not DivisionController?
    236             if (!(it) || !((it)->getIdentifier()->getName() == "DivisionController") || !(it->getControllableEntity()))
     213            if (!controller || !(controller->getIdentifier()->getName() == "DivisionController") || !(controller->getControllableEntity()))
    237214                continue;
    238215            //same team?
    239             if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()))
     216            if ((this->getControllableEntity()->getTeam() != controller->getControllableEntity()->getTeam()))
    240217                continue;
    241218
    242219            //is equal to this?
    243             if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
     220            if (orxonox_cast<ControllableEntity*>(controller) == this->getControllableEntity())
    244221                continue;
    245222
    246             float distance = CommonController::distance (it->getControllableEntity(), this->getControllableEntity());
     223            float distance = CommonController::distance (controller->getControllableEntity(), this->getControllableEntity());
    247224           
    248             if (distance < minDistance && !(it->hasFollower()))
    249             {
    250                 closestLeader = *it;
     225            if (distance < minDistance && !(controller->hasFollower()))
     226            {
     227                closestLeader = controller;
    251228                minDistance = distance;
    252229            }
     
    258235                return closestLeader;
    259236        }
    260         return 0;
     237        return nullptr;
    261238    }
    262239
Note: See TracChangeset for help on using the changeset viewer.