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

    r10843 r10851  
    4242        this->myLeader_ = 0;
    4343        this->rank_ = Rank::WINGMAN;
     44        this->bFirstAction_ = true;
     45
    4446    }
    4547
     
    6971    void WingmanController::action()
    7072    {
     73
    7174        //----If no leader, find one----
    7275        if (!this->myLeader_)
     
    7982        else
    8083        {
    81             this->action_ = this->myLeader_->getAction();
    82         }
    83 
    84 
    85         //----action was set to fight----
    86         if (this->action_ == Action::FIGHT)
    87         {
    88             //----If no leader found, attack someone----
    89             if (!this->hasTarget() && !this->myLeader_)
    90             {
    91                 this->setClosestTarget();
     84
     85        }
     86        if (!this->myLeader_)
     87        {
     88            bool b = this->startAttackingEnemiesThatAreClose();
     89
     90            if (this->action_ == Action::NONE)
     91            {
     92                this->executeActionpoint();
     93            }
     94            if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL)
     95            {
     96                if (!this->hasTarget())
     97                {
     98                    //----find a target----
     99                    ControllableEntity* newTarget = this->closestTarget();
     100                    if (this->action_ == Action::FIGHT)
     101                    {
     102                        if (newTarget &&
     103                                CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
     104                        {
     105                            this->setAction (Action::FIGHT, newTarget);
     106                        }
     107                        else
     108                        {
     109                            this->nextActionpoint();
     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                            return;
     123                        }
     124                    }
     125
     126                }
     127                else if (this->hasTarget())
     128                {
     129                    //----fly in formation if far enough----
     130                    Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
     131                       
     132                    if (diffVector.length() > this->attackRange_)
     133                    {
     134                        if (this->action_ == Action::FIGHT)
     135                        {
     136                            this->nextActionpoint();
     137                            return;
     138                        }
     139                    }
     140                }
     141            }
     142            else if (this->action_ == Action::FLY)
     143            {
     144                if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
     145                {
     146                    this->nextActionpoint();
     147                    return;
     148                }
     149            }
     150            else if (this->action_ == Action::PROTECT)
     151            {
     152                if (!this->getProtect())
     153                {
     154                    this->nextActionpoint();
     155                    return;
     156                }
     157
     158                Vector3* targetRelativePosition;
     159                   
     160                targetRelativePosition = new Vector3 (0, 300, 300); 
     161     
     162                Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) +
     163                    (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
     164                this->setTargetPosition(targetAbsolutePosition);
     165               
     166
     167            }
     168            else if (this->action_ == Action::ATTACK)
     169            {   
     170                if (!this->hasTarget())
     171                {
     172                    this->nextActionpoint();
     173                    return;
     174                }
     175                       
    92176            }
    93177            if (this->hasTarget())
     
    99183            }
    100184        }
    101         //----action was set to fly, leader handles the logic----
    102         else if (this->action_ == Action::FLY)
    103         {
    104 
    105         }
    106         //----gani-TODO: implement protect----
    107         else if (this->action_ == Action::PROTECT)
    108         {
    109 
    110         }
    111          
     185        else
     186        {
     187            //----action was set to fight----
     188            if (this->action_ == Action::FIGHT)
     189            {
     190                //----If no leader found, attack someone----
     191                if (!this->hasTarget())
     192                {
     193                    this->setClosestTarget();
     194                }
     195                if (this->hasTarget())
     196                {
     197                    //----choose where to go----
     198                    this->maneuver();
     199                    //----fire if you can----
     200                    this->bShooting_ = this->canFire();               
     201                }
     202            }
     203            //----action was set to fly, leader handles the logic----
     204            else if (this->action_ == Action::FLY)
     205            {
     206
     207            }
     208        }
     209        if (this->bFirstAction_ && this->myLeader_)
     210        {
     211            this->parsedActionpoints_ = this->myLeader_->parsedActionpoints_;
     212            this->bFirstAction_ = false;
     213        }
    112214    }
    113215     
Note: See TracChangeset for help on using the changeset viewer.