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

    r11052 r11071  
    3939    {
    4040        RegisterObject(WingmanController);
    41         this->myLeader_ = 0;
     41        this->myLeader_ = nullptr;
    4242        this->bFirstAction_ = true;
    4343
     
    4646    WingmanController::~WingmanController()
    4747    {
    48         for (size_t i = 0; i < this->actionpoints_.size(); ++i)
     48        for (WorldEntity* actionpoint : this->actionpoints_)
    4949        {
    50             if(this->actionpoints_[i])
    51                 this->actionpoints_[i]->destroy();
     50            if (actionpoint)
     51                actionpoint->destroy();
    5252        }
    5353        this->parsedActionpoints_.clear();
    5454        this->actionpoints_.clear();
    55     }
    56  
    57     void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    58     {
    59         SUPER(WingmanController, XMLPort, xmlelement, mode);
    60     }
    61    
    62     //----in tick, move (or look) and shoot----
    63     void WingmanController::tick(float dt)
    64     {   
    65         if (!this->isActive())
    66             return;
    67        
    68         SUPER(WingmanController, tick, dt);
    69 
    7055    }
    7156   
     
    122107    Vector3 WingmanController::getFormationPosition ()
    123108    {
    124 
    125 
    126109        this->setFormationMode( this->myLeader_->getFormationMode() );
    127         Vector3* targetRelativePosition;
    128110        this->spread_ = this->myLeader_->getSpread();
    129111        if (this->myLeader_->getIdentifier()->getName() == "DivisionController")
     
    131113            switch (this->formationMode_){
    132114                case FormationMode::WALL:
    133                 {
    134                     targetRelativePosition = new Vector3 (2.0f*this->spread_, 0, 0 - 1.0f*this->tolerance_);
    135                     break;
    136                 }
     115                    return Vector3 (2.0f*this->spread_, 0, 0 - 1.0f*this->tolerance_);
    137116                case FormationMode::FINGER4:
    138                 {
    139                     targetRelativePosition = new Vector3 (2.0f*this->spread_, 0, this->spread_ - 1.0f*this->tolerance_);
    140                     break;
    141                 }
     117                    return Vector3 (2.0f*this->spread_, 0, this->spread_ - 1.0f*this->tolerance_);
    142118                case FormationMode::DIAMOND:
    143                 {
    144                     targetRelativePosition = new Vector3 (2.0f*this->spread_, 0, this->spread_ - 1.0f*this->tolerance_);
    145                     break;
    146                 }
     119                    return Vector3 (2.0f*this->spread_, 0, this->spread_ - 1.0f*this->tolerance_);
     120                default:
     121                    return Vector3::ZERO;
    147122            }
    148123        }
     
    151126            switch (this->formationMode_){
    152127                case FormationMode::WALL:
    153                 {
    154                     targetRelativePosition = new Vector3 (-2.0f*this->spread_, 0, 0 - 1.0f*this->tolerance_);
    155                     break;
    156                 }
     128                    return Vector3 (-2.0f*this->spread_, 0, 0 - 1.0f*this->tolerance_);
    157129                case FormationMode::FINGER4:
    158                 {
    159                     targetRelativePosition = new Vector3 (-2.0f*this->spread_, 0, this->spread_ - 1.0f*this->tolerance_);
    160                     break;
    161                 }
     130                    return Vector3 (-2.0f*this->spread_, 0, this->spread_ - 1.0f*this->tolerance_);
    162131                case FormationMode::DIAMOND:
    163                 {
    164                     targetRelativePosition = new Vector3 (2.0f*this->spread_, -1.0f*this->spread_, 0 - 1.0f*this->tolerance_);
    165                     break;
    166                 }
     132                    return Vector3 (2.0f*this->spread_, -1.0f*this->spread_, 0 - 1.0f*this->tolerance_);
     133                default:
     134                    return Vector3::ZERO;
    167135            }
    168136        }
    169         Vector3 result = *targetRelativePosition;
    170         delete targetRelativePosition;
    171         return result;
    172137    }
    173138    void WingmanController::keepFormation()
     
    185150
    186151        if (!this->getControllableEntity())
    187             return 0;
     152            return nullptr;
    188153
    189154        //----vars for finding the closest leader----
    190         ActionpointController* closestLeader = 0;
     155        ActionpointController* closestLeader = nullptr;
    191156        float minDistance =  std::numeric_limits<float>::infinity();
    192157        Gametype* gt = this->getGametype();
    193158
    194         for (ObjectList<ActionpointController>::iterator it = ObjectList<ActionpointController>::begin(); it; ++it)
     159        for (ActionpointController* controller : ObjectList<ActionpointController>())
    195160        {
    196161            //----0ptr or not a leader or dead?----
    197             if (!it ||
    198                 (it->getIdentifier()->getName() != "SectionController" && it->getIdentifier()->getName() != "DivisionController") ||
    199                 !(it->getControllableEntity()))
     162            if (!controller ||
     163                (controller->getIdentifier()->getName() != "SectionController" && controller->getIdentifier()->getName() != "DivisionController") ||
     164                !(controller->getControllableEntity()))
    200165                continue;
    201166           
    202167            //----same team?----
    203             if ( !CommonController::sameTeam (this->getControllableEntity(), (it)->getControllableEntity(), gt) )
     168            if ( !CommonController::sameTeam (this->getControllableEntity(), controller->getControllableEntity(), gt) )
    204169                continue;
    205170           
    206171            //----check distance----
    207             float distance = CommonController::distance (it->getControllableEntity(), this->getControllableEntity());
    208             if (distance < minDistance && !(it->hasWingman()))
     172            float distance = CommonController::distance (controller->getControllableEntity(), this->getControllableEntity());
     173            if (distance < minDistance && !(controller->hasWingman()))
    209174            {
    210                 closestLeader = *it;
     175                closestLeader = controller;
    211176                minDistance = distance;
    212177            }
     
    222187            }
    223188        }
    224         return 0;
     189        return nullptr;
    225190    }
    226191
Note: See TracChangeset for help on using the changeset viewer.