Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 24, 2015, 5:21:03 PM (8 years ago)
Author:
gania
Message:

major change: introduced Actionpoints, look AITest.oxw. Only FLY works for now

File:
1 edited

Legend:

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

    r10848 r10849  
    2828
    2929#include "DivisionController.h"
    30 
     30#include "infos/PlayerInfo.h"
    3131
    3232namespace orxonox
     
    9393        if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
    9494        {
    95             if ((this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_) ||
    96              !this->target_)
    97             {
    98                 ControllableEntity* newTarget = this->closestTarget();
     95            if ( (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_)
     96                || !this->target_ )
     97            {
     98                Pawn* newTarget = this->closestTarget();
    9999                if ( newTarget &&
    100                     CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_ )
     100                    CommonController::distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))
     101                        <= this->attackRange_ )
    101102                {
    102103                    // this->backupAction();
    103104                    // this->setAction (Action::FIGHT, newTarget);
    104                     this->parsedActionpoints_.push_back(
    105                         std::make_tuple (Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO) );
     105                    Point p = { Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO };
     106                    this->parsedActionpoints_.push_back(p);
     107                    this->executeActionpoint();
    106108                }
    107109            }
     
    113115        if (this->action_ == Action::NONE)
    114116        {
    115 
    116         }
    117 
    118         this->executeActionpoint();
     117            this->executeActionpoint();
     118        }
     119
    119120
    120121        //this->action_ is what I am actually executing, this->target_ is what I am
     
    142143                else if (this->action_ == Action::FIGHTALL)
    143144                {
    144                     if (newTarget)
     145                    if (newTarget && newTarget->getController())
    145146                    {
    146147                        this->setAction (Action::FIGHTALL, newTarget);
     
    158159                //----fly in formation if far enough----
    159160                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
     161               
     162                   
    160163                if (diffVector.length() > this->attackRange_)
    161164                {
     
    198201        else if (this->action_ == Action::FLY)
    199202        {
     203
     204            if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
     205            {
     206                orxout(internal_error) << "arrived";
     207                this->nextActionpoint();
     208                return;
     209            }
    200210            this->setTargetPositionOfWingman();
    201211            this->setTargetPositionOfFollower();
     
    203213        else if (this->action_ == Action::PROTECT)
    204214        {
     215            if (!this->getProtect())
     216            {
     217                this->nextActionpoint();
     218                return;
     219            }
    205220           /* if (this->myWingman_)
    206221                this->myWingman_->setAction (Action::PROTECT, this->getProtect());
     
    218233            this->setTargetPositionOfWingman();
    219234            this->setTargetPositionOfFollower();
     235
    220236        }
    221237        else if (this->action_ == Action::ATTACK)
    222238        {   
    223             if (this->hasTarget())
    224             {
    225                 //----fly in formation if far enough----
    226                 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
    227                 if (diffVector.length() > this->attackRange_)
    228                 {
    229                     this->setTargetPositionOfWingman();
    230                     this->setTargetPositionOfFollower();                   
    231                 }
    232                 else
    233                 {
    234                     //----wingmans shall support the fire of their leaders----
    235                     if (this->myWingman_)
    236                     {
    237                         this->myWingman_->setAction (this->action_, this->target_);     
    238                     }
    239                     if (this->myFollower_)
    240                     {
    241                         this->myFollower_->setAction (this->action_);                                   
    242                     }
    243 
    244                 }
    245                
    246             }
    247             if (this->hasTarget())
    248             {
    249                 //----choose where to go----
    250                 this->maneuver();
    251                 //----fire if you can----
    252                 this->bShooting_ = this->canFire();               
    253             }
     239            if (!this->hasTarget())
     240            {
     241                this->nextActionpoint();
     242                return;
     243            }
     244            //----fly in formation if far enough----
     245            Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
     246            if (diffVector.length() > this->attackRange_)
     247            {
     248                this->setTargetPositionOfWingman();
     249                this->setTargetPositionOfFollower();                   
     250            }
     251            else
     252            {
     253                //----wingmans shall support the fire of their leaders----
     254                if (this->myWingman_)
     255                {
     256                    this->myWingman_->setAction (this->action_, this->target_);     
     257                }
     258                if (this->myFollower_)
     259                {
     260                    this->myFollower_->setAction (this->action_);                                   
     261                }
     262
     263            }
     264           
     265            //----choose where to go----
     266            this->maneuver();
     267            //----fire if you can----
     268            this->bShooting_ = this->canFire();               
    254269        }
    255270
Note: See TracChangeset for help on using the changeset viewer.