Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 25, 2015, 12:07:22 PM (8 years ago)
Author:
gania
Message:

Fixed some bugs, only DivisionController works for now

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc

    r10851 r10854  
    5050    DivisionController::~DivisionController()
    5151    {
     52        if (this->myFollower_)
     53        {
     54            this->myFollower_->takeActionpoints(this->parsedActionpoints_);
     55        }
     56        for (size_t i = 0; i < this->actionpoints_.size(); ++i)
     57        {
     58            if(this->actionpoints_[i])
     59                this->actionpoints_[i]->destroy();
     60        }
     61        this->parsedActionpoints_.clear();
     62        this->actionpoints_.clear();
    5263    }
    5364
     
    6576    }
    6677    void DivisionController::action()
    67     {       
    68         if (this->startAttackingEnemiesThatAreClose())
    69         {
    70             Point p = { Action::FIGHT, "", Vector3::ZERO };
    71            
    72             if (this->myWingman_)
    73             {
    74                 this->myWingman_->parsedActionpoints_.push_back(p);
    75             }
    76             if (this->myFollower_)
    77             {
    78                 this->myFollower_->parsedActionpoints_.push_back(p);
    79             }
    80         }
    81 
    82         if (this->action_ == Action::NONE)
    83         {
    84             this->executeActionpoint();
    85         }
    86         if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL)
    87         {
    88             if (!this->hasTarget())
    89             {
    90                 //----find a target----
    91                 ControllableEntity* newTarget = this->closestTarget();
    92                 if (this->action_ == Action::FIGHT)
    93                 {
    94                     if (newTarget &&
    95                             CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
    96                     {
    97                         this->setAction (Action::FIGHT, newTarget);
    98                     }
    99                     else
    100                     {
    101                         this->nextActionpoint();
    102                         if (this->myWingman_)
    103                         {
    104                             this->myWingman_->nextActionpoint();
    105                         }
    106                         if (this->myFollower_)
    107                         {
    108                             this->myFollower_->nextActionpoint();
    109                         }
    110                         return;
    111                     }
    112                 }
    113                 else if (this->action_ == Action::FIGHTALL)
    114                 {
    115                     if (newTarget && newTarget->getController())
    116                     {
    117                         this->setAction (Action::FIGHTALL, newTarget);
    118                     }
    119                     else
    120                     {
    121                         this->nextActionpoint();
    122                         if (this->myWingman_)
    123                         {
    124                             this->myWingman_->nextActionpoint();
    125                         }
    126                         if (this->myFollower_)
    127                         {
    128                             this->myFollower_->nextActionpoint();
    129                         }
    130                         return;
    131                     }
    132                 }
    133 
    134             }
    135             else if (this->hasTarget())
    136             {
    137                 //----fly in formation if far enough----
    138                 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
    139                    
    140                 if (diffVector.length() > this->attackRange_)
    141                 {
    142                     if (this->action_ == Action::FIGHT)
    143                     {
    144                         this->nextActionpoint();
    145                         if (this->myWingman_)
    146                         {
    147                             this->myWingman_->nextActionpoint();
    148                         }
    149                         if (this->myFollower_)
    150                         {
    151                             this->myFollower_->nextActionpoint();
    152                         }
    153                         return;
    154                     }
    155                     else
    156                     {
    157                         this->setTargetPositionOfWingman();
    158                         this->setTargetPositionOfFollower();                   
    159                     }
    160                 }
    161                 else
    162                 {
    163                     //----wingmans shall support the fire of their leaders----
    164                     if (this->myWingman_)
    165                     {
    166                         this->myWingman_->setAction (Action::FIGHT, this->target_);     
    167                     }
    168                     if (this->myFollower_)
    169                     {
    170                         this->myFollower_->setAction (Action::FIGHT);                                   
    171                     }
    172                 }
    173             }
    174         }
    175         else if (this->action_ == Action::FLY)
    176         {
    177             if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
    178             {
    179                 this->nextActionpoint();
    180                 if (this->myWingman_)
    181                 {
    182                     this->myWingman_->nextActionpoint();
    183                 }
    184                 if (this->myFollower_)
    185                 {
    186                     this->myFollower_->nextActionpoint();
    187                 }
    188                 return;
    189             }
    190             this->setTargetPositionOfWingman();
    191             this->setTargetPositionOfFollower();
    192         }
    193         else if (this->action_ == Action::PROTECT)
    194         {
    195             if (!this->getProtect())
    196             {
    197                 this->nextActionpoint();
    198                 if (this->myWingman_)
    199                 {
    200                     this->myWingman_->nextActionpoint();
    201                 }
    202                 if (this->myFollower_)
    203                 {
    204                     this->myFollower_->nextActionpoint();
    205                 }
    206                 return;
    207             }
    208 
    209             Vector3* targetRelativePosition;
    210                
    211             targetRelativePosition = new Vector3 (0, 300, 300); 
    212  
    213             Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) +
    214                 (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
    215             this->setTargetPosition(targetAbsolutePosition);
    216            
    217             this->setTargetPositionOfWingman();
    218             this->setTargetPositionOfFollower();
    219 
    220         }
    221         else if (this->action_ == Action::ATTACK)
    222         {   
    223             if (!this->hasTarget())
    224             {
    225                 this->nextActionpoint();
    226                 if (this->myWingman_)
    227                 {
    228                     this->myWingman_->nextActionpoint();
    229                 }
    230                 if (this->myFollower_)
    231                 {
    232                     this->myFollower_->nextActionpoint();
    233                 }
    234                 return;
    235             }
    236             //----fly in formation if far enough----
    237             Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
    238             if (diffVector.length() > this->attackRange_)
    239             {
    240                 this->setTargetPositionOfWingman();
    241                 this->setTargetPositionOfFollower();                   
    242             }
    243             else
    244             {
    245                 //----wingmans shall support the fire of their leaders----
    246                 if (this->myWingman_)
    247                 {
    248                     this->myWingman_->setAction (Action::FIGHT, this->target_);     
    249                 }
    250                 if (this->myFollower_)
    251                 {
    252                     this->myFollower_->setAction (Action::FIGHT);                                   
    253                 }
    254             }         
    255         }
    256         if (this->hasTarget())
    257         {
    258             //----choose where to go----
    259             this->maneuver();
    260             //----fire if you can----
    261             this->bShooting_ = this->canFire();               
    262         }
     78    {   
     79        CommonController::action();
     80       
    26381    }
    264    
     82    void DivisionController::stayNearProtect()
     83    {
     84        CommonController::stayNearProtect();
     85    }
    26586    void DivisionController::setTargetPositionOfWingman()
    26687    {
     
    294115       
    295116    }
    296     void DivisionController::setTargetPositionOfFollower()
    297     {
    298         if (!this->myFollower_)
    299             return;
    300         this->myFollower_->setFormationMode(this->formationMode_);
    301 
    302         Vector3* targetRelativePositionOfFollower;
    303         switch (this->formationMode_){
    304             case FormationMode::WALL:
    305             {
    306                 targetRelativePositionOfFollower = new Vector3 (-400, 0, 0);   
    307                 break;
    308             }
    309             case FormationMode::FINGER4:
    310             {
    311                 targetRelativePositionOfFollower = new Vector3 (-400, 0, 200);   
    312                 break;
    313             }
    314            
    315             case FormationMode::DIAMOND:
    316             {
    317                 targetRelativePositionOfFollower = new Vector3 (-400, 0, 200);                   
    318                 break;
    319             }
    320         }
    321         Quaternion orient = this->getControllableEntity()->getWorldOrientation();
    322        
    323         Vector3 targetAbsolutePositionOfFollower = ((this->getControllableEntity()->getWorldPosition()) +
    324         (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfFollower)));
    325        
    326         myFollower_->setAction ( Action::FLY, targetAbsolutePositionOfFollower, orient );       
    327     }
     117   
    328118    bool DivisionController::setWingman(CommonController* cwingman)
    329119    {
Note: See TracChangeset for help on using the changeset viewer.