Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 24, 2015, 10:37:28 PM (8 years ago)
Author:
gania
Message:

works for the most part, still need to fix Section and Wingman

File:
1 edited

Legend:

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

    r10850 r10851  
    4646        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this)));
    4747        this->rank_ = Rank::DIVISIONLEADER;
    48 
    49 
    5048    }
    5149
     
    6058        //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
    6159    }
    62 
    63    
    6460    void DivisionController::tick(float dt)
    6561    {   
    66 
    6762        if (!this->isActive())
    6863            return;
    69        
    70        
    7164        SUPER(DivisionController, tick, dt);
    72 
    7365    }
    7466    void DivisionController::action()
    75     {
    76         //----Whatever ship is doing, if there are targets close to it and its own target is far away, fight them----
    77         //analog to attack move
    78         if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
    79         {
    80             if ( (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_)
    81                 || !this->target_ )
    82             {
    83                 Pawn* newTarget = this->closestTarget();
    84                 if ( newTarget &&
    85                     CommonController::distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))
    86                         <= this->attackRange_ )
    87                 {
    88                     // this->backupAction();
    89                     // this->setAction (Action::FIGHT, newTarget);
    90                     Point p = { Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO };
    91                     this->parsedActionpoints_.push_back(p);
    92                     this->executeActionpoint();
    93                 }
    94             }
    95         }
    96 
    97         //action is NONE whenever ships finishes current action,
    98         //if it was fighting before because enemies were close, resume what it was doing
    99         //otherwise try to execute next 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
    10082        if (this->action_ == Action::NONE)
    10183        {
    10284            this->executeActionpoint();
    10385        }
    104 
    105 
    106         //this->action_ is what I am actually executing, this->target_ is what I am
    107         //actually attacking, etc.
    108 
    109         //after action is finished, .pop_back() is to be called.
    11086        if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL)
    11187        {
     
    11692                if (this->action_ == Action::FIGHT)
    11793                {
    118                     if (newTarget && CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
     94                    if (newTarget &&
     95                            CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
    11996                    {
    12097                        this->setAction (Action::FIGHT, newTarget);
     
    123100                    {
    124101                        this->nextActionpoint();
     102                        if (this->myWingman_)
     103                        {
     104                            this->myWingman_->nextActionpoint();
     105                        }
     106                        if (this->myFollower_)
     107                        {
     108                            this->myFollower_->nextActionpoint();
     109                        }
    125110                        return;
    126111                    }
     
    135120                    {
    136121                        this->nextActionpoint();
     122                        if (this->myWingman_)
     123                        {
     124                            this->myWingman_->nextActionpoint();
     125                        }
     126                        if (this->myFollower_)
     127                        {
     128                            this->myFollower_->nextActionpoint();
     129                        }
    137130                        return;
    138131                    }
     
    144137                //----fly in formation if far enough----
    145138                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
    146                
    147139                   
    148140                if (diffVector.length() > this->attackRange_)
     
    151143                    {
    152144                        this->nextActionpoint();
     145                        if (this->myWingman_)
     146                        {
     147                            this->myWingman_->nextActionpoint();
     148                        }
     149                        if (this->myFollower_)
     150                        {
     151                            this->myFollower_->nextActionpoint();
     152                        }
    153153                        return;
    154154                    }
     
    158158                        this->setTargetPositionOfFollower();                   
    159159                    }
    160 
    161160                }
    162161                else
     
    165164                    if (this->myWingman_)
    166165                    {
    167                         this->myWingman_->setAction (this->action_, this->target_);     
     166                        this->myWingman_->setAction (Action::FIGHT, this->target_);     
    168167                    }
    169168                    if (this->myFollower_)
    170169                    {
    171                         this->myFollower_->setAction (this->action_);                                   
    172                     }
    173 
    174                 }
    175                
    176             }
    177             if (this->hasTarget())
    178             {
    179                 //----choose where to go----
    180                 this->maneuver();
    181                 //----fire if you can----
    182                 this->bShooting_ = this->canFire();               
    183             }
    184 
     170                        this->myFollower_->setAction (Action::FIGHT);                                   
     171                    }
     172                }
     173            }
    185174        }
    186175        else if (this->action_ == Action::FLY)
    187176        {
    188 
    189177            if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
    190178            {
    191                 orxout(internal_error) << "arrived";
    192179                this->nextActionpoint();
     180                if (this->myWingman_)
     181                {
     182                    this->myWingman_->nextActionpoint();
     183                }
     184                if (this->myFollower_)
     185                {
     186                    this->myFollower_->nextActionpoint();
     187                }
    193188                return;
    194189            }
     
    201196            {
    202197                this->nextActionpoint();
     198                if (this->myWingman_)
     199                {
     200                    this->myWingman_->nextActionpoint();
     201                }
     202                if (this->myFollower_)
     203                {
     204                    this->myFollower_->nextActionpoint();
     205                }
    203206                return;
    204207            }
    205            /* if (this->myWingman_)
    206                 this->myWingman_->setAction (Action::PROTECT, this->getProtect());
    207             if (this->myFollower_)
    208                 this->myFollower_->setAction (Action::PROTECT, this->getProtect());
    209             */
     208
    210209            Vector3* targetRelativePosition;
    211210               
    212             targetRelativePosition = new Vector3 (0, 0, 500); 
     211            targetRelativePosition = new Vector3 (0, 300, 300); 
    213212 
    214213            Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) +
     
    225224            {
    226225                this->nextActionpoint();
     226                if (this->myWingman_)
     227                {
     228                    this->myWingman_->nextActionpoint();
     229                }
     230                if (this->myFollower_)
     231                {
     232                    this->myFollower_->nextActionpoint();
     233                }
    227234                return;
    228235            }
     
    239246                if (this->myWingman_)
    240247                {
    241                     this->myWingman_->setAction (this->action_, this->target_);     
     248                    this->myWingman_->setAction (Action::FIGHT, this->target_);     
    242249                }
    243250                if (this->myFollower_)
    244251                {
    245                     this->myFollower_->setAction (this->action_);                                   
    246                 }
    247 
    248             }
    249            
     252                    this->myFollower_->setAction (Action::FIGHT);                                   
     253                }
     254            }         
     255        }
     256        if (this->hasTarget())
     257        {
    250258            //----choose where to go----
    251259            this->maneuver();
     
    253261            this->bShooting_ = this->canFire();               
    254262        }
    255 
    256     }
    257 
     263    }
    258264   
    259 
    260265    void DivisionController::setTargetPositionOfWingman()
    261266    {
     
    321326        myFollower_->setAction ( Action::FLY, targetAbsolutePositionOfFollower, orient );       
    322327    }
    323 
    324 
    325328    bool DivisionController::setWingman(CommonController* cwingman)
    326329    {
     
    336339            return false;
    337340        }
    338    
    339341    }
    340342    bool DivisionController::setFollower(LeaderController* myFollower)
     
    364366            return false;
    365367    }
    366 
    367 
    368    
    369    
    370 
    371368}
Note: See TracChangeset for help on using the changeset viewer.