Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10854


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

Fixed some bugs, only DivisionController works for now

Location:
code/branches/campaignHS15
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/campaignHS15/data/levels/AITest.oxw

    r10851 r10854  
    6767      </templates>
    6868      <controller>
    69         <DivisionController team=0>
     69        <DivisionController team=0 formationMode="finger4">
    7070          <actionpoints>
    71             <Actionpoint position="-1000,750,-500" action="FLY" />
     71            <Actionpoint position="0,0,0" action="FLY" />
    7272            <Actionpoint position="-1000,750,-500" action="ATTACK" enemy="ss3" />
    7373            <Actionpoint position="-1000,750,-500" action="PROTECt" protect="fuck" />
     
    7676      </controller>
    7777    </SpaceShip>
    78     <SpaceShip position="-2000, 1800, -1000" lookat="0,0,0" team=0>
    79       <templates>
    80         <Template link=spaceshipassff />
    81       </templates>
    82       <controller>
    83         <WingmanController team=0>
    84         </WingmanController>
    85       </controller>
    86     </SpaceShip>
    87     <SpaceShip position="-2000, 2100, -1000" lookat="0,0,0" team=0>
    88       <templates>
    89         <Template link=spaceshipassff />
    90       </templates>
    91       <controller>
    92         <WingmanController team=0>
    93         </WingmanController>
    94       </controller>
    95     </SpaceShip>
    96     <SpaceShip position="-2000, 2400, -1000" lookat="0,0,0" team=0>
     78    <SpaceShip position="-2000, 1900, -1000" lookat="0,0,0" team=0>
    9779      <templates>
    9880        <Template link=spaceshipassff />
  • code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc

    r10851 r10854  
    6565        this->squaredaccuracy_ = 10000;
    6666        this->bFirstTick_ = true;
    67         this->tolerance_ = 65;
     67        this->tolerance_ = 50;
    6868        this->action_ = Action::NONE;
    6969        this->stopLookingAtTarget();
     
    7373    CommonController::~CommonController()
    7474    {
    75         for (size_t i = 0; i < this->actionpoints_.size(); ++i)
    76         {
    77             if(this->actionpoints_[i])
    78                 this->actionpoints_[i]->destroy();
    79         }
    80         this->parsedActionpoints_.clear();
    81         this->actionpoints_.clear();
     75       
    8276    }
    8377    void CommonController::tick(float dt)
     
    492486                }
    493487            }
    494             if (distance > 200 || (rotateX > -0.1 && rotateX < 0.1 && rotateY > -0.1 && rotateY < 0.1))
     488            if (distance > this->tolerance_*1.5f || (rotateX > -0.01 && rotateX < 0.01 && rotateY > -0.01 && rotateY < 0.01))
    495489                this->getControllableEntity() ->moveFrontBack( SPEED * dt );
    496490        }
     
    746740        return 0; 
    747741    }
    748     bool CommonController::startAttackingEnemiesThatAreClose()
     742    void CommonController::startAttackingEnemiesThatAreClose()
    749743    {
    750744        if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
     
    761755                    this->parsedActionpoints_.push_back(p);
    762756                    this->executeActionpoint();
    763                     return true;
    764                 }
    765             }
    766         }
    767         return false;
     757                }
     758            }
     759        }
    768760    }
    769761
     
    783775            {
    784776                case Action::FIGHT:
    785                 {               
     777                {
     778                    std::string targetName = this->parsedActionpoints_.back().name;
     779                    if (targetName == "")
     780                    {
     781                        break;
     782                    }
     783                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
     784                    {
     785                        if (CommonController::getName(*itP) == targetName)
     786                        {
     787                            this->setTarget (static_cast<ControllableEntity*>(*itP));
     788                        }
     789                    }         
    786790                    break;
    787791                }
     
    851855        }
    852856    }
     857    void CommonController::stayNearProtect()
     858    {
     859        Vector3* targetRelativePosition;
     860        targetRelativePosition = new Vector3 (0, 300, 300); 
     861        Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) +
     862            (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
     863        this->setTargetPosition(targetAbsolutePosition);
     864    }
    853865    void CommonController::nextActionpoint()
    854866    {
     
    859871        this->setAction(Action::NONE);
    860872    }
     873    void CommonController::action()
     874    {
     875        this->startAttackingEnemiesThatAreClose();
     876        //No action -> pop one from stack
     877        if (this->action_ == Action::NONE)
     878        {
     879            this->executeActionpoint();
     880        }
     881        //Action fightall -> fight till nobody alive
     882        if (this->action_ == Action::FIGHTALL)
     883        {
     884            if (!this->hasTarget())
     885            {
     886                //----find a target----
     887                ControllableEntity* newTarget = this->closestTarget();   
     888                if (newTarget)
     889                {
     890                    this->setAction (Action::FIGHTALL, newTarget);
     891                }
     892                else
     893                {
     894                    this->nextActionpoint();
     895                    return;
     896                }
     897            }
     898            else if (this->hasTarget())
     899            {
     900
     901            }
     902        }
     903        //Action fight -> fight as long as enemies in range
     904        else if (this->action_ == Action::FIGHT)
     905        {
     906            if (!this->hasTarget())
     907            {
     908                //----find a target----
     909                ControllableEntity* newTarget = this->closestTarget();   
     910                if (newTarget &&
     911                        CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
     912                {
     913                    this->setAction (Action::FIGHT, newTarget);
     914                }
     915                else
     916                {
     917                    this->nextActionpoint();
     918                    return;
     919                }
     920            }
     921            else if (this->hasTarget())
     922            {
     923                //----fly in formation if far enough----
     924                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
     925                   
     926                if (diffVector.length() > this->attackRange_)
     927                {
     928                    ControllableEntity* newTarget = this->closestTarget();
     929                   
     930                    if (newTarget &&
     931                        CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
     932                    {
     933                        this->setAction (Action::FIGHT, newTarget);
     934                    }
     935                    else
     936                    {
     937                        this->nextActionpoint();
     938                        return;
     939                    }
     940                }
     941            }
     942        }
     943        else if (this->action_ == Action::FLY)
     944        {
     945            if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
     946            {
     947                this->nextActionpoint();   
     948                return;
     949            }
     950        }
     951        else if (this->action_ == Action::PROTECT)
     952        {
     953            if (!this->getProtect())
     954            {
     955                this->nextActionpoint();
     956                return;
     957            }
     958            this->stayNearProtect();
     959        }
     960        else if (this->action_ == Action::ATTACK)
     961        {   
     962            if (!this->hasTarget())
     963            {
     964                this->nextActionpoint();
     965                return;
     966            }
     967        }
     968        if (this->hasTarget())
     969        {
     970            //----choose where to go----
     971            this->maneuver();
     972            //----fire if you can----
     973            this->bShooting_ = this->canFire();               
     974        }
     975    }
    861976}
  • code/branches/campaignHS15/src/orxonox/controllers/CommonController.h

    r10851 r10854  
    4141#include <algorithm>
    4242#include "worldentities/Actionpoint.h"
     43#include "worldentities/pawns/SpaceShip.h"
    4344
    4445namespace orxonox
     
    133134            //----[/Helper methods]----
    134135
    135              //----[Actionpoint information]----
    136 
    137                 std::vector<WeakPtr<WorldEntity> > actionpoints_;
    138                 float squaredaccuracy_;
    139                 std::vector<Point > parsedActionpoints_;
    140 
    141             //----[/Actionpoint information]----
    142                 //----[Actionpoint methods]----
    143                 void executeActionpoint();
    144                 void nextActionpoint();
    145             //----[Actionpoint methods]----
     136             
     137                virtual void stayNearProtect();
     138                virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
     139           
    146140        protected:
    147141            //----[Flying methods]----
     
    180174                void setClosestTarget();
    181175                Pawn* closestTarget();
    182                 bool startAttackingEnemiesThatAreClose();
     176                void startAttackingEnemiesThatAreClose();
    183177            //----[/Fighting methods]----           
    184178           
     
    203197            //----[/who-to-kill information]----
    204198
    205            
     199            //----[Actionpoint information]----
     200
     201                std::vector<WeakPtr<WorldEntity> > actionpoints_;
     202                float squaredaccuracy_;
     203                std::vector<Point > parsedActionpoints_;
     204
     205            //----[/Actionpoint information]----
     206            //----[Actionpoint methods]----
     207                void executeActionpoint();
     208                void nextActionpoint();
     209            //----[Actionpoint methods]----
    206210            //----["Private" variables]----
    207211                FormationMode::Value formationMode_;
  • 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    {
  • code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h

    r10843 r10854  
    5858
    5959                void setTargetPositionOfWingman();
    60                 void setTargetPositionOfFollower();
     60               
    6161            //----[/own functions]----
     62            virtual void stayNearProtect();
    6263
    6364        protected:
    6465            //----action must only be managed by this----
    6566            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
    66            
     67
    6768        private:
    6869            //----private variables-----
  • code/branches/campaignHS15/src/orxonox/controllers/LeaderController.cc

    r10843 r10854  
    5151    {
    5252    }
     53    void LeaderController::takeActionpoints (std::vector<Point > vector)
     54    {
     55      this->parsedActionpoints_ = vector;
     56      this->setAction (Action::NONE);
     57      this->setTarget(0);
     58      this->setTargetPosition (this->getControllableEntity()->getWorldPosition());
     59      orxout(internal_error) << "Top action is " << this->parsedActionpoints_.back().action << endl;
     60    }
    5361
    5462
  • code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h

    r10843 r10854  
    5353                    { return true; }
    5454            //----[/pseudo virtual methods]----
    55 
     55                virtual void takeActionpoints (std::vector<Point > vector);
    5656
    5757
  • code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc

    r10851 r10854  
    5151    SectionController::~SectionController()
    5252    {
    53        
     53       for (size_t i = 0; i < this->actionpoints_.size(); ++i)
     54        {
     55            if(this->actionpoints_[i])
     56                this->actionpoints_[i]->destroy();
     57        }
     58        this->parsedActionpoints_.clear();
     59        this->actionpoints_.clear();
    5460    }
    5561    void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     
    8692        if (!myDivisionLeader_)
    8793        {
    88             if (this->startAttackingEnemiesThatAreClose())
    89             {
    90                 Point p = { Action::FIGHT, "", Vector3::ZERO };
    91                
    92                 if (this->myWingman_)
     94            CommonController::action();
     95        }
     96        else if (myDivisionLeader_)
     97        {
     98            switch (myDivisionLeader_->getAction())
     99            {
     100                // case Action::FLY:
     101                // {
     102                //     // Vector3 targetRelativePosition = getFormationPosition();
     103                //     // Quaternion orient =
     104                //     //     this->myDivisionLeader_->getControllableEntity()->getWorldOrientation();
     105                //     // Vector3 targetAbsolutePosition =
     106                //     //     ((this->myDivisionLeader_->getControllableEntity()->getWorldPosition()) +
     107                //     //         (orient* (targetRelativePosition)));
     108                //     // this->setAction (Action::FLY, targetAbsolutePosition, orient);
     109                //     break;
     110                // }
     111                // case Action::FIGHT:
     112                // {
     113
     114                //     // this->setAction (Action::FLY, targetAbsolutePosition, orient);
     115                //     break;
     116                // }
     117                default:
    93118                {
    94                     this->myWingman_->parsedActionpoints_.push_back(p);
     119                    ControllableEntity* myEntity = this->getControllableEntity();
     120                    Vector3 myPosition = myEntity->getWorldPosition();
     121                    if (!this->myDivisionLeader_)
     122                    {
     123                        return;
     124                    }
     125                    ControllableEntity* leaderEntity = this->myDivisionLeader_->getControllableEntity();
     126                    Quaternion orient = leaderEntity->getWorldOrientation();
     127                    Vector3 leaderPosition = leaderEntity->getWorldPosition();
     128
     129                    Vector3 targetRelativePosition = getFormationPosition();
     130                    if (!this->myDivisionLeader_)
     131                    {
     132                        return;
     133                    }
     134                    Vector3 targetAbsolutePosition =
     135                        (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5)
     136                         + (orient* (targetRelativePosition)));
     137               
     138                    this->setAction (Action::FLY, targetAbsolutePosition, orient);
     139                    if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
     140                    {
     141                        this->boostControl();
     142                    }
     143                    else
     144                    {
     145                       this->getControllableEntity()->boost(false);
     146                    }
    95147                }
    96148            }
    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); 
     149        }
    203150     
    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                 }
    222                 //----fly in formation if far enough----
    223                 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
    224                 if (diffVector.length() > this->attackRange_)
    225                 {
    226                     this->setTargetPositionOfWingman();
    227                 }
    228                 else
    229                 {
    230                     //----wingmans shall support the fire of their leaders----
    231                     if (this->myWingman_)
    232                     {
    233                         this->myWingman_->setAction (Action::FIGHT, this->target_);     
    234                     }
    235      
    236                 }         
    237             }
    238             if (this->hasTarget())
    239             {
    240                 //----choose where to go----
    241                 this->maneuver();
    242                 //----fire if you can----
    243                 this->bShooting_ = this->canFire();               
    244             }
    245         }
    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;
     151    }
     152
     153    void SectionController::boostControl()
     154    {
     155        SpaceShip* ship = orxonox_cast<SpaceShip*>(this->getControllableEntity());
     156        if(ship == NULL) return;
     157        if(ship->getBoostPower()*1.5f > ship->getInitialBoostPower() ) //upper limit ->boost
     158        {
     159
     160            this->getControllableEntity()->boost(true);
     161        }
     162        else if(ship->getBoostPower()*4.0f < ship->getInitialBoostPower()) //lower limit ->do not boost
     163        {
     164           this->getControllableEntity()->boost(false);
    298165        }
    299166    }
     
    303170    {
    304171        //----If division leader fights, cover him by fighting emenies close to his target----
    305         if (this->myDivisionLeader_->getAction() == Action::FIGHT)
     172        Action::Value action = this->myDivisionLeader_->getAction();
     173       
     174        Pawn* target;
     175        if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK)
    306176        {
    307177            //----if he has a target----
     
    327197                        {
    328198                            foundTarget = true;
    329                             this->setAction(Action::FIGHT, (*itP));
     199                            target =  (*itP);
    330200                            //orxout(internal_error) << "Found target" << endl;
    331201                            break;
     
    335205                    if (!foundTarget)
    336206                    {
    337                         this->setAction(Action::FIGHT, this->myDivisionLeader_->getTarget());
     207                        target = orxonox_cast<Pawn*>(this->myDivisionLeader_->getTarget());
    338208                    }
    339209                }
     
    341211                else
    342212                {
    343                     this->setAction(Action::FIGHT, this->myDivisionLeader_->getTarget());
     213                    target = orxonox_cast<Pawn*>(this->myDivisionLeader_->getTarget());
    344214                }
    345215            }
     
    349219
    350220            }
     221            this->setAction (Action::FIGHT, orxonox_cast<ControllableEntity*>(target));
     222        }
     223        else
     224        {
    351225        }
     226    }
     227    Vector3 SectionController::getFormationPosition ()
     228    {
     229        this->setFormationMode( this->myDivisionLeader_->getFormationMode() );
     230        Vector3* targetRelativePosition;
     231        switch (this->formationMode_){
     232            case FormationMode::WALL:
     233            {
     234                targetRelativePosition = new Vector3 (-400, 0, 0);   
     235                break;
     236            }
     237            case FormationMode::FINGER4:
     238            {
     239                targetRelativePosition = new Vector3 (-400, 0, 200);   
     240                break;
     241            }
     242           
     243            case FormationMode::DIAMOND:
     244            {
     245                targetRelativePosition = new Vector3 (-400, 0, 200);                   
     246                break;
     247            }
     248        }
     249        return *targetRelativePosition;
    352250    }
    353251
  • code/branches/campaignHS15/src/orxonox/controllers/SectionController.h

    r10851 r10854  
    6363            //----action must only be managed by this----     
    6464                virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
    65 
     65                Vector3 getFormationPosition ();
     66                void boostControl();
    6667        private:
    6768            //----private variables-----
    6869                Timer actionTimer_; //<! Regularly calls action().
    6970                bool bFirstAction_;
    70            
     71
    7172
    7273    };
  • code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc

    r10851 r10854  
    4848    WingmanController::~WingmanController()
    4949    {
    50 
     50        for (size_t i = 0; i < this->actionpoints_.size(); ++i)
     51        {
     52            if(this->actionpoints_[i])
     53                this->actionpoints_[i]->destroy();
     54        }
     55        this->parsedActionpoints_.clear();
     56        this->actionpoints_.clear();
    5157    }
    5258 
     
    8692        if (!this->myLeader_)
    8793        {
    88             bool b = this->startAttackingEnemiesThatAreClose();
     94           CommonController::action();
     95        }
     96        else if (this->myLeader_)
     97        {
    8998
    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                        
    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             }
    18499        }
    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         }
     100       
    214101    }
    215102     
Note: See TracChangeset for help on using the changeset viewer.