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

    r10843 r10851  
    4444        this->myDivisionLeader_ = 0;
    4545        this->rank_ = Rank::SECTIONLEADER;
    46 
     46        this->bFirstAction_ = true;
    4747        //orxout(internal_error) << this << "Was created" << endl;
    4848
     
    7272    void SectionController::action()
    7373    {
     74
    7475        //----If no leader, find one---- 
    7576        if (!myDivisionLeader_)
     
    8384        {
    8485        }
    85 
    86         //----action was set to fight----
    87         if (this->action_ == Action::FIGHT)
    88         {
    89             if (!this->hasTarget())
    90             {
    91                 if (this->myDivisionLeader_)
    92                 {
    93                     this->chooseTarget();               
    94                 }
    95                 else
    96                 {
    97                     this->setClosestTarget();
    98                 }
    99             }
    100             else
    101             {
     86        if (!myDivisionLeader_)
     87        {
     88            if (this->startAttackingEnemiesThatAreClose())
     89            {
     90                Point p = { Action::FIGHT, "", Vector3::ZERO };
    10291               
     92                if (this->myWingman_)
     93                {
     94                    this->myWingman_->parsedActionpoints_.push_back(p);
     95                }
     96            }
     97            if (this->action_ == Action::NONE)
     98            {
     99                this->executeActionpoint();
     100            }
     101            if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL)
     102            {
     103                if (!this->hasTarget())
     104                {
     105                    //----find a target----
     106                    ControllableEntity* newTarget = this->closestTarget();
     107                    if (this->action_ == Action::FIGHT)
     108                    {
     109                        if (newTarget &&
     110                                CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
     111                        {
     112                            this->setAction (Action::FIGHT, newTarget);
     113                        }
     114                        else
     115                        {
     116                            this->nextActionpoint();
     117                            if (this->myWingman_)
     118                            {
     119                                this->myWingman_->nextActionpoint();
     120                            }
     121               
     122                            return;
     123                        }
     124                    }
     125                    else if (this->action_ == Action::FIGHTALL)
     126                    {
     127                        if (newTarget && newTarget->getController())
     128                        {
     129                            this->setAction (Action::FIGHTALL, newTarget);
     130                        }
     131                        else
     132                        {
     133                            this->nextActionpoint();
     134                            if (this->myWingman_)
     135                            {
     136                                this->myWingman_->nextActionpoint();
     137                            }
     138                            return;
     139                        }
     140                    }
     141
     142                }
     143                else if (this->hasTarget())
     144                {
     145                    //----fly in formation if far enough----
     146                    Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
     147                       
     148                    if (diffVector.length() > this->attackRange_)
     149                    {
     150                        if (this->action_ == Action::FIGHT)
     151                        {
     152                            this->nextActionpoint();
     153                            if (this->myWingman_)
     154                            {
     155                                this->myWingman_->nextActionpoint();
     156                            }
     157                            return;
     158                        }
     159                        else
     160                        {
     161                            this->setTargetPositionOfWingman();
     162                        }
     163                    }
     164                    else
     165                    {
     166                        //----wingmans shall support the fire of their leaders----
     167                        if (this->myWingman_)
     168                        {
     169                            this->myWingman_->setAction (Action::FIGHT, this->target_);     
     170                        }
     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                    return;
     185                }
     186                this->setTargetPositionOfWingman();
     187            }
     188            else if (this->action_ == Action::PROTECT)
     189            {
     190                if (!this->getProtect())
     191                {
     192                    this->nextActionpoint();
     193                    if (this->myWingman_)
     194                    {
     195                        this->myWingman_->nextActionpoint();
     196                    }
     197                    return;
     198                }
     199
     200                Vector3* targetRelativePosition;
     201                   
     202                targetRelativePosition = new Vector3 (0, 300, 300); 
     203     
     204                Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) +
     205                    (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
     206                this->setTargetPosition(targetAbsolutePosition);
     207               
     208                this->setTargetPositionOfWingman();
     209
     210            }
     211            else if (this->action_ == Action::ATTACK)
     212            {   
     213                if (!this->hasTarget())
     214                {
     215                    this->nextActionpoint();
     216                    if (this->myWingman_)
     217                    {
     218                        this->myWingman_->nextActionpoint();
     219                    }
     220                    return;
     221                }
    103222                //----fly in formation if far enough----
    104223                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
    105                 if (diffVector.length() > 3000)
     224                if (diffVector.length() > this->attackRange_)
    106225                {
    107226                    this->setTargetPositionOfWingman();
    108                 }   
     227                }
    109228                else
    110229                {
     
    112231                    if (this->myWingman_)
    113232                    {
    114                         this->myWingman_->setAction (Action::FIGHT, this->target_);                   
    115                     }
    116                 }
     233                        this->myWingman_->setAction (Action::FIGHT, this->target_);     
     234                    }
     235     
     236                }         
    117237            }
    118238            if (this->hasTarget())
     
    124244            }
    125245        }
    126 
    127         //----action was set to fly----
    128         else if (this->action_ == Action::FLY)
    129         {
    130             this->setTargetPositionOfWingman();
    131         }
    132 
    133         //----action was set to protect----
    134         else if (this->action_ == Action::PROTECT)
    135         {
    136            /* if (this->myWingman_)
    137                 this->myWingman_->setAction (Action::PROTECT, this->getProtect());
    138 */
    139             this->setTargetPositionOfWingman();
    140 
    141         }
    142                
    143 
     246        //----If have leader----
     247        else
     248        {
     249            //----action was set to fight----
     250            if (this->action_ == Action::FIGHT)
     251            {
     252                if (!this->hasTarget())
     253                {
     254                    this->chooseTarget();
     255                }
     256                else
     257                {
     258                    //----fly in formation if far enough----
     259                    Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
     260                    if (diffVector.length() > this->attackRange_)
     261                    {
     262                        this->setTargetPositionOfWingman();
     263                    }   
     264                    else
     265                    {
     266                        //----wingmans shall support the fire of their leaders----
     267                        if (this->myWingman_)
     268                        {
     269                            this->myWingman_->setAction (Action::FIGHT, this->target_);                   
     270                        }
     271                    }
     272                }
     273                if (this->hasTarget())
     274                {
     275                    //----choose where to go----
     276                    this->maneuver();
     277                    //----fire if you can----
     278                    this->bShooting_ = this->canFire();               
     279                }
     280            }
     281
     282            //----action was set to fly----
     283            else if (this->action_ == Action::FLY)
     284            {
     285                this->setTargetPositionOfWingman();
     286                Pawn* newTarget = this->closestTarget();
     287                if ( newTarget &&  this->distance (this->getControllableEntity(),
     288                                                    static_cast<ControllableEntity*>(newTarget)) <= this->attackRange_ )
     289                {
     290                    this->setAction (Action::FIGHT, static_cast<ControllableEntity*>(newTarget));
     291                }
     292            }       
     293        }
     294        if (this->bFirstAction_ && this->myDivisionLeader_)
     295        {
     296            this->parsedActionpoints_ = this->myDivisionLeader_->parsedActionpoints_;
     297            this->bFirstAction_ = false;
     298        }
    144299    }
    145300    //PRE: myDivisionLeader_ != 0 && myDivisionLeader_->action_ == Action::FIGHT
     
    267422        }
    268423        return 0;
    269 
    270424    }
    271425    bool SectionController::setWingman(CommonController* cwingman)
     
    291445            return false;
    292446    }
    293 
    294    
    295    
    296    
    297 
    298447}
Note: See TracChangeset for help on using the changeset viewer.