Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10826


Ignore:
Timestamp:
Nov 22, 2015, 5:06:38 PM (8 years ago)
Author:
gania
Message:

some comments added

Location:
code/branches/AI_HS15
Files:
2 deleted
12 edited

Legend:

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

    r10805 r10826  
    7979      </controller>
    8080    </SpaceShip>
    81     <SpaceShip position="6000, 1500, -2800" lookat="0,0,0">
     81    <SpaceShip position="4000, 1500, -2800 " lookat="0,0,0">
    8282      <templates>
    8383        <Template link=spaceshipassff />
     
    8888      </controller>
    8989    </SpaceShip>
    90     <SpaceShip position="6000, 1500, -1000" lookat="0,0,0">
    91       <templates>
    92         <Template link=spaceshipassff />
    93       </templates>
    94       <controller>
    95         <DivisionController team=1 formationMode="DIAMOND">
    96         </DivisionController>
    97       </controller>
    98     </SpaceShip>
    99     <SpaceShip position="6000 ,1500, -1600 " lookat="0,0,0">
    100       <templates>
    101         <Template link=spaceshipassff />
    102       </templates>
    103       <controller>
    104         <WingmanController team=1>
    105         </WingmanController>
    106       </controller>
    107     </SpaceShip>
    108     <SpaceShip position="6000, 1500, -2200" lookat="0,0,0">
    109       <templates>
    110         <Template link=spaceshipassff />
    111       </templates>
    112       <controller>
    113         <WingmanController team=1>
    114         </WingmanController>
    115       </controller>
    116     </SpaceShip>
    117     <SpaceShip position="6000, 1500, -2800" lookat="0,0,0">
    118       <templates>
    119         <Template link=spaceshipassff />
    120       </templates>
    121       <controller>
    122         <SectionController team=1>
    123         </SectionController>
    124       </controller>
    125     </SpaceShip>
    126  
    12790   
    12891    <SpaceShip position="-4000, 1500, -5000" lookat="0,0,0">
     
    163126    </SpaceShip>
    164127
    165        <SpaceShip position="-6000, 1500, -5000" lookat="0,0,0">
    166       <templates>
    167         <Template link=spaceshipassff />
    168       </templates>
    169       <controller>
    170         <DivisionController team=2 formationMode="FINGER4">
    171         </DivisionController>
    172       </controller>
    173     </SpaceShip>
    174     <SpaceShip position="-6000 , 1500, -5600" lookat="0,0,0">
    175       <templates>
    176         <Template link=spaceshipassff />
    177       </templates>
    178       <controller>
    179         <WingmanController team=2>
    180         </WingmanController>
    181       </controller>
    182     </SpaceShip>
    183     <SpaceShip position="-6000, 1500, -6200" lookat="0,0,0">
    184       <templates>
    185         <Template link=spaceshipassff />
    186       </templates>
    187       <controller>
    188         <WingmanController team=2>
    189         </WingmanController>
    190       </controller>
    191     </SpaceShip>
    192     <SpaceShip position="-6000, 1500, -6800 " lookat="0,0,0">
    193       <templates>
    194         <Template link=spaceshipassff />
    195       </templates>
    196       <controller>
    197         <SectionController team=2>
    198         </SectionController>
    199       </controller>
    200     </SpaceShip>
    201 
    202 
    203128   
    204129   
  • code/branches/AI_HS15/src/orxonox/controllers/CMakeLists.txt

    r10719 r10826  
    1111  FormationController.cc
    1212  ControllerDirector.cc
    13   FleetController.cc
    1413  DivisionController.cc
    1514  LeaderController.cc
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc

    r10805 r10826  
    4646
    4747    RegisterClass( CommonController );
    48     float SPEED = 0.9f/0.02f;
    49     float ROTATEFACTOR = 1.0f/0.02f;
     48    const float SPEED = 0.9f/0.02f;
     49    const float ROTATEFACTOR = 1.0f/0.02f;
    5050
    5151    CommonController::CommonController( Context* context ): Controller( context )
     
    5353        this->bSetupWorked = false;
    5454
    55         this->executingManeuver_ = false;
     55       
    5656        this->executingMoveToPoint_ = false;
    5757        this->action_ = Action::FLY;
    5858        this->stopLookingAtTarget();
    59         this->maneuverType_ = ManeuverType::NONE;
     59       
    6060        RegisterObject( CommonController );
    6161    }
     
    6464    CommonController::~CommonController()
    6565    {
    66         orxout(internal_error) << "I died, my Rank is " << rank_ << endl;
     66        //orxout(internal_error) << "I died, my Rank is " << rank_ << endl;
    6767    }
    6868
     
    7777        const std::string valUpper = getUppercase( val );
    7878        FormationMode::Value value;
    79         if ( valUpper == "VEE" )
    80             value = FormationMode::VEE;
    81         else if ( valUpper == "WALL" )
     79       
     80        if ( valUpper == "WALL" )
    8281            value = FormationMode::WALL;
    8382        else if ( valUpper == "FINGER4" )
     
    9493        switch ( this->formationMode_ )
    9594        {
    96             case FormationMode::VEE:
    97             {
    98                 return "VEE";
    99                 break;
    100             }
    10195            case FormationMode::WALL:
    10296            {
     
    246240            }
    247241        }
    248         if ( this->getControllableEntity()  && !this->target_ )
    249         {
    250 
    251             this->maneuverType_ = ManeuverType::NONE;
    252         }
     242       
    253243        //orxout ( internal_error ) << "ManeuverType = " << this->maneuverType_ << endl;
    254244    }
     
    606596
    607597    }
     598    float CommonController::distance (ControllableEntity* entity1, ControllableEntity* entity2)
     599    {
     600        if (!entity1 || !entity2)
     601            return std::numeric_limits<float>::infinity();
     602        return ( entity1->getPosition() - entity2->getPosition() ).length();
     603    }
     604    bool CommonController::sameTeam (ControllableEntity* entity1, ControllableEntity* entity2)
     605    {
     606        if (!entity1 || !entity2)
     607            return false;
     608        return entity1->getTeam() == entity2->getTeam();
     609    }
    608610    void CommonController::doFire()
    609611    {
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.h

    r10805 r10826  
    3434#include "worldentities/ControllableEntity.h"
    3535#include "worldentities/pawns/Pawn.h"
    36 #include "core/ClassTreeMask.h"
     36#include <limits>
    3737
    3838
     
    4444        enum Value
    4545        {
    46             VEE, FINGER4, DIAMOND, WALL
     46            FINGER4, DIAMOND, WALL
    4747        };
    4848    }
     
    5555
    5656    }
    57     //none for a formation flight without attacking, neutral when opponent and this have no
    58     //advantage over each other, offensive when this spotted opponent first,
    59     //defensive otherwise
    60     namespace ManeuverType
    61     {
    62         enum Value
    63         {
    64             NONE, NEUTRAL, OFFENSIVE, DEFENCIVE
    65         };
    66 
    67     }
    6857    namespace Action
    6958    { 
     
    7362        };
    7463    }
    75     //none for a formation flight
    76     namespace Maneuver
    77     {
    78         enum Value
    79         {
    80             NONE, GUNSD, SCISSORS, COMBATSPREAD, DEFENSIVESPLIT, BREAK, BARRELROLL, SWOOP, IMMELMANN,
    81             WINGOVER, LOWYOYO, HIGHYOYO, LAGDISPLACEMENTROLL
    82         };
    83     }
    84 
     64 
    8565
    8666    class _OrxonoxExport CommonController : public Controller
     
    11898            virtual bool setWingman(CommonController* wingman);
    11999            virtual bool hasWingman();
    120 
     100            static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2);
    121101            void setTarget(ControllableEntity* target);
    122102            bool hasTarget();
     
    147127            void copyTargetOrientation(float dt);
    148128
     129            static float distance(ControllableEntity* entity1, ControllableEntity* entity2);
    149130            float squaredDistanceToTarget() const;
    150131            void doFire();
     
    202183            FormationMode::Value formationMode_;
    203184            Rank::Value rank_;
    204             ManeuverType::Value maneuverType_;
    205             Maneuver::Value maneuver_;
    206 
    207             bool executingManeuver_;
     185       
    208186            bool executingMoveToPoint_;
    209187         
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc

    r10805 r10826  
    3535    RegisterClass(DivisionController);
    3636
     37    //Leaders share the fact that they have Wingmans
    3738    DivisionController::DivisionController(Context* context) : LeaderController(context)
    3839    {
     
    5354    }
    5455
     56    void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     57    {
     58        SUPER(DivisionController, XMLPort, xmlelement, mode);
     59
     60        //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
     61    }
     62
    5563   
    5664    void DivisionController::tick(float dt)
     
    7684    void DivisionController::action()
    7785    {
    78         if (!this->target_)
     86        //----find a target----
     87        if ( !this->hasTarget() )
    7988        {
    8089            for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
    8190            {
    82                 if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())
     91                if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) )
    8392                    continue;           
    8493
    8594               
    86                 if (static_cast<ControllableEntity*>(*itP) != (this)->getControllableEntity() && !(this)->hasTarget()
    87                     && ((*itP)->getWorldPosition() - (this)->getControllableEntity()->getWorldPosition()).length() < 10000)
     95                if (static_cast<ControllableEntity*>(*itP) != (this)->getControllableEntity()
     96                    && CommonController::distance (*itP, this->getControllableEntity()) < 10000)
    8897                {
    8998                    (this)->setAction(Action::FIGHT, *itP);
     
    94103        if (this->action_ == Action::FIGHT)
    95104        {
     105            //----choose where to go----
    96106            this->maneuver();
     107            //----fire if you can----
    97108            this->bShooting_ = this->canFire();
     109
    98110            if (this->target_)
    99111            {
    100112                if (this->myWingman_)
    101113                {
     114                    //----wingmans shall support the fire of their leaders----
    102115                    this->myWingman_->setAction (Action::FIGHT, this->target_);                   
    103116                }
    104117               
     118                //----fly in formation if far enough----
    105119                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
    106120                if (diffVector.length() > 3000)
     
    141155                break;
    142156            }
    143             case FormationMode::VEE:
    144             {
    145                 break;
    146             }
     157         
    147158            case FormationMode::DIAMOND:
    148159            {
     
    177188                break;
    178189            }
    179             case FormationMode::VEE:
    180             {
    181                 break;
    182             }
     190           
    183191            case FormationMode::DIAMOND:
    184192            {
     
    239247
    240248
    241     void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    242     {
    243         SUPER(DivisionController, XMLPort, xmlelement, mode);
    244 
    245         //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
    246     }
    247 
    248249   
    249250   
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h

    r10731 r10826  
    4242      {
    4343        public:
     44            //----[language demanded functions]----           
     45                DivisionController(Context* context);
    4446
    45                 DivisionController(Context* context);
    46                 virtual ~DivisionController();
     47                virtual ~DivisionController();
     48            //----[/language demanded functions]----           
    4749
    48             virtual void tick(float dt); //<! Carrying out the targets set in action().
     50            //----[orxonox demanded functions]----
     51                virtual void tick(float dt);
    4952
    50                
    51                         virtual bool setFollower(LeaderController* myFollower);
    52                         virtual bool setWingman(CommonController* cwingman);
    53             virtual bool hasWingman();
    54             virtual bool hasFollower();
     53                virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);         
     54            //----[orxonox demanded functions]----
    5555
    56             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);         
     56            //----[own functions]----
     57                virtual bool setFollower(LeaderController* myFollower);
     58                virtual bool setWingman(CommonController* cwingman);
     59                virtual bool hasWingman();
     60                virtual bool hasFollower();
     61
     62                void setTargetPositionOfWingman();
     63                void setTargetPositionOfFollower();
     64            //----[/own functions]----
    5765
    5866        protected:
    59            
    60             void setTargetPositionOfWingman();
    61             void setTargetPositionOfFollower();
    62 
    63             virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
     67            //----action must only be managed by this----
     68            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
    6469           
    6570        private:
    66 
     71            //----private variables-----
    6772            Timer actionTimer_; //<! Regularly calls action().
    6873
  • code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc

    r10729 r10826  
    4141    RegisterClass(LeaderController);
    4242
    43 
     43    //CommonController contains all common functionality of AI Controllers
    4444    LeaderController::LeaderController(Context* context) : CommonController(context)
    4545    {
  • code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h

    r10731 r10826  
    4242    {
    4343        public:
     44            //----[language demanded functions]----           
     45                LeaderController(Context* context);
     46                virtual ~LeaderController();
     47            //----[language demanded functions]----           
    4448
    45             LeaderController(Context* context);
    46             virtual ~LeaderController();
    47            
    48             virtual bool setFollower(LeaderController* myFollower)
    49                 { return false; }
    50            
    51             virtual bool hasFollower()
    52                 { return true; }
    53            
     49            //----[pseudo virtual methods]----
     50                virtual bool setFollower(LeaderController* myFollower)
     51                    { return false; }
     52                virtual bool hasFollower()
     53                    { return true; }
     54            //----[/pseudo virtual methods]----
    5455
    5556
    5657
    5758        protected:
    58          
    59             WeakPtr<WingmanController> myWingman_;
    60 
    61             WeakPtr<LeaderController> myFollower_;
    62             WeakPtr<LeaderController> myDivisionLeader_;
     59            //----private variables-----
     60                WeakPtr<WingmanController> myWingman_;
     61                WeakPtr<LeaderController> myFollower_;
     62                WeakPtr<LeaderController> myDivisionLeader_;
    6363
    6464           
  • code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc

    r10805 r10826  
    3434    RegisterClass(SectionController);
    3535
     36    //Leaders share the fact that they have Wingmans
    3637    SectionController::SectionController(Context* context) : LeaderController(context)
    3738    {
     
    4445        this->rank_ = Rank::SECTIONLEADER;
    4546
    46         orxout(internal_error) << this << "Was created" << endl;
     47        //orxout(internal_error) << this << "Was created" << endl;
    4748
    4849    }
     
    5253       
    5354    }
    54 
     55    void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     56    {
     57        SUPER(SectionController, XMLPort, xmlelement, mode);
     58
     59        //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
     60    }
     61
     62    //----in tick, move (or look) and shoot----
    5563    void SectionController::tick(float dt)
    5664    {
     
    7583    void SectionController::action()
    7684    {
    77         //this->target_ = this->sectionTarget_;       
     85        //----If no leader, find one---- 
    7886        if (!myDivisionLeader_)
    7987        {
    8088            LeaderController* newDivisionLeader = findNewDivisionLeader();
    8189            this->myDivisionLeader_ = newDivisionLeader;
     90
    8291            if (newDivisionLeader)
    83                 orxout(internal_error) << "new DivisionLeader set" << endl;
     92            {
     93                //orxout(internal_error) << "new DivisionLeader set" << endl;
     94            }
     95            //----If no leader found, attack someone----
     96            //----TODO: find closest enemy----
    8497            else
    8598            {
    86                 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
    87                 {
    88                     if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())
    89                         continue;           
    90 
    91                     if (!this->myDivisionLeader_)
     99                if ( !this->hasTarget() || this->action_ != Action::FIGHT )
     100                {
     101                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
    92102                    {
     103                        if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) )
     104                            continue;
     105
    93106                        this->setAction(Action::FIGHT, (*itP));
    94                         break;
     107                        break;   
     108                    }   
     109                }
     110               
     111            }
     112
     113        }
     114        //----If have leader----
     115        else
     116        {
     117            this->chooseTarget();
     118        }
     119
     120        //----action was set to fight----
     121        if (this->action_ == Action::FIGHT)
     122        {
     123            //----choose where to go----
     124            this->maneuver();
     125            //----fire if you can----
     126            this->bShooting_ = this->canFire();
     127
     128            if (this->target_)
     129            {
     130                //----wingmans shall support the fire of their leaders----
     131                if (this->myWingman_)
     132                {
     133                    this->myWingman_->setAction (Action::FIGHT, this->target_);                   
     134                }
     135                //----fly in formation if far enough----
     136                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
     137                if (diffVector.length() > 3000)
     138                {
     139                    this->setTargetPositionOfWingman();
     140                }   
     141            }
     142        }
     143
     144        //----action was set to fly----
     145        else if (this->action_ == Action::FLY)
     146        {
     147            this->setTargetPositionOfWingman();
     148        }
     149
     150        //----action was set to protect----
     151        else if (this->action_ == Action::PROTECT)
     152        {
     153
     154        }
     155               
     156
     157    }
     158    //PRE: myDivisionLeader_ != 0
     159    //POST: this->target_ is set unless division leader doesn't have one
     160    void SectionController::chooseTarget()
     161    {
     162        //----If division leader fights, cover him by fighting emenies close to his target----
     163        if (this->myDivisionLeader_->getAction() == Action::FIGHT)
     164        {
     165            //----if he has a target----
     166            if (this->myDivisionLeader_->hasTarget())
     167            {
     168                //----try to find a new target if division leader has wingman (doing fine) and no good target already set----
     169                if ( this->myDivisionLeader_->hasWingman() &&
     170                    !( this->hasTarget() && this->getTarget() != this->myDivisionLeader_->getTarget() ) )
     171                {
     172
     173                    bool foundTarget = false;
     174                    //----new target should be close to division's target----
     175                    Vector3 divisionTargetPosition = this->myDivisionLeader_->getTarget()->getWorldPosition();
     176                   
     177                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
     178                    {
     179                        //----is enemy?----
     180                        if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) )
     181                            continue;           
     182                        //----in range?----
     183                        if (((*itP)->getWorldPosition() - divisionTargetPosition).length() < 3000 &&
     184                            (*itP) != this->myDivisionLeader_->getTarget())
     185                        {
     186                            foundTarget = true;
     187                            this->setAction(Action::FIGHT, (*itP));
     188                            //orxout(internal_error) << "Found target" << endl;
     189                            break;
     190                        }
    95191                    }
    96                    
    97                 }
    98             }
    99 
    100         }
    101         else
    102         {
    103             if (this->myDivisionLeader_->getAction() == Action::FIGHT)
    104             {
    105                 if (this->myDivisionLeader_->hasTarget())
    106                 {
    107                     if (this->myDivisionLeader_->hasWingman() && (!this->hasTarget() || this->getTarget() == this->myDivisionLeader_->getTarget()))
     192                    //----no target? then attack same target as division leader----
     193                    if (!foundTarget)
    108194                    {
    109                         bool foundTarget = false;
    110                         Vector3 divisionTargetPosition = this->myDivisionLeader_->getTarget()->getWorldPosition();
    111                         for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
    112                         {
    113                             if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())
    114                                 continue;           
    115 
    116                             if (((*itP)->getWorldPosition() - divisionTargetPosition).length() < 3000 &&
    117                                 ((*itP)->getWorldPosition() - divisionTargetPosition).length() > 1000 &&
    118                                 (*itP) != this->myDivisionLeader_->getTarget())
    119                             {
    120                                 foundTarget = true;
    121                                 this->setAction(Action::FIGHT, (*itP));
    122                                 orxout(internal_error) << "Found target" << endl;
    123                                 break;
    124                             }
    125                         }
    126                         if (!foundTarget)
    127                         {
    128                             this->setAction(Action::FIGHT, this->myDivisionLeader_->getTarget());
    129                         }
    130 
     195                        this->setAction(Action::FIGHT, this->myDivisionLeader_->getTarget());
    131196                    }
    132197                }
    133             }   
    134         }
    135        
    136         if (this->action_ == Action::FIGHT)
    137         {
    138             this->maneuver();
    139             this->bShooting_ = this->canFire();
    140             if (this->target_)
    141             {
    142                 if (this->myWingman_)
    143                 {
    144                     this->myWingman_->setAction (Action::FIGHT, this->target_);                   
     198                //----if division leader doesn't have a wingman, support his fire----
     199                else
     200                {
     201                    this->setAction(Action::FIGHT, this->myDivisionLeader_->getTarget());
    145202                }
    146                 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
    147                 if (diffVector.length() > 3000)
    148                 {
    149                     this->setTargetPositionOfWingman();
    150                 }   
    151             }
    152         }
    153         else if (this->action_ == Action::FLY)
    154         {
    155             this->setTargetPositionOfWingman();
    156         }
    157         else if (this->action_ == Action::PROTECT)
    158         {
    159 
    160         }
    161                
    162 
    163     }
    164    
     203            }
     204            //----If he fights but doesn't have a target, wait for him to get one----
     205            else
     206            {
     207
     208            }
     209        }
     210    }
     211
     212    //----stay in formation----
    165213    void SectionController::setTargetPositionOfWingman()
    166214    {
     
    177225            {
    178226                targetRelativePositionOfWingman = new Vector3 (-400, 0, -200); 
    179                 break;
    180             }
    181             case FormationMode::VEE:
    182             {
    183227                break;
    184228            }
     
    197241       
    198242    }
     243
    199244    LeaderController* SectionController::findNewDivisionLeader()
    200245    {
     
    219264                continue;
    220265
    221 
    222             float distance = ((it)->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
     266            float distance = CommonController::distance (it->getControllableEntity(), this->getControllableEntity());
    223267           
    224268            if (distance < minDistance && !(it->hasFollower()))
     
    260304    }
    261305
    262     void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    263     {
    264         SUPER(SectionController, XMLPort, xmlelement, mode);
    265 
    266         //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
    267     }
    268 
     306   
    269307   
    270308   
  • code/branches/AI_HS15/src/orxonox/controllers/SectionController.h

    r10731 r10826  
    4040    {
    4141        public:
     42            //----[language demanded functions]----           
     43                SectionController(Context* context);
    4244
    43             SectionController(Context* context);
    44             virtual ~SectionController();
     45                virtual ~SectionController();
     46            //----[/language demanded functions]----
    4547           
    46             virtual void tick(float dt); //<! Carrying out the targets set in action().
     48            //----[orxonox demanded functions]----
     49                virtual void tick(float dt);
     50               
     51                virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     52            //----[/orxonox demanded functions]----
    4753           
     54            //----[own functions]----
     55                LeaderController* findNewDivisionLeader();
     56                void setTargetPositionOfWingman();
    4857
    49             LeaderController* findNewDivisionLeader();
    50             virtual bool setWingman(CommonController* cwingman);
    51             virtual bool hasWingman();
    52            
    53             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     58                virtual bool setWingman(CommonController* cwingman);
     59                virtual bool hasWingman();
    5460
    55         protected:
     61                void chooseTarget();
     62            //----[/own functions]----
    5663
    57             void setTargetPositionOfWingman();
    58            
    59             virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
     64        protected:       
     65            //----action must only be managed by this----     
     66                virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
    6067
    6168        private:
    62 
    63             Timer actionTimer_; //<! Regularly calls action().
     69            //----private variables-----
     70                Timer actionTimer_; //<! Regularly calls action().
    6471           
    6572
  • code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc

    r10805 r10826  
    3535    RegisterClass(WingmanController);
    3636   
    37 
     37    //CommonController contains all common functionality of AI Controllers
    3838    WingmanController::WingmanController(Context* context) : CommonController(context)
    3939    {
     
    4242        this->myLeader_ = 0;
    4343        this->rank_ = Rank::WINGMAN;
    44 
    4544    }
    4645
     
    4948
    5049    }
    51     // void WingmanController::chooseManeuver()
    52     // {
    53     //     if (this->maneuverType_ == ManeuverType::NONE)
    54     //     switch (this->maneuverType_ )
    55     //     {
    56     //         case ManeuverType::NONE:
    57     //         {
     50 
     51    void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     52    {
     53        SUPER(WingmanController, XMLPort, xmlelement, mode);
    5854
    59     //             break;
    60     //         }
    61     //         case ManeuverType::NEUTRAL:
    62     //         {
    63 
    64     //             break;
    65     //         }
    66     //         case ManeuverType::OFFENSIVE:
    67     //         {
    68 
    69     //             break;
    70     //         }
    71     //         case ManeuverType::DEFENSIVE:
    72     //         {
    73 
    74     //             break;
    75     //         }
    76     //     }
    77     //     if (!this->myWingman_)
    78     //         return;
    79     //     Vector3* targetRelativePositionOfWingman;
    80     //     switch (this->formationMode_){
    81     //         case FormationMode::WALL:
    82     //         {
    83     //             targetRelativePositionOfWingman = new Vector3 (-400, 0, 0); 
    84     //             break;
    85     //         }
    86     //         case FormationMode::FINGER4:
    87     //         {
    88     //             targetRelativePositionOfWingman = new Vector3 (-400, 0, -200); 
    89     //             break;
    90     //         }
    91     //         case FormationMode::VEE:
    92     //         {
    93     //             break;
    94     //         }
    95     //         case FormationMode::DIAMOND:
    96     //         {
    97     //             targetRelativePositionOfWingman = new Vector3 (400, -200, 0);                 
    98     //             break;
    99     //         }
    100     //     }
    101     //     Quaternion orient = this->getControllableEntity()->getWorldOrientation();
    102        
    103     //     Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) +
    104     //     (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman)));
    105        
    106     //     myWingman_->setTargetOrientation(orient);
    107     //     myWingman_->setTargetPosition(targetAbsolutePositionOfWingman);
    108        
    109     // }
    110 
     55        //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
     56    }
     57   
     58    //----in tick, move (or look) and shoot----
    11159    void WingmanController::tick(float dt)
    11260    {   
     
    12977    }
    13078   
     79    //----action for hard calculations----
    13180    void WingmanController::action()
    13281    {
     82        //----If no leader, find one----
    13383        if (!this->myLeader_)
    13484        {
     
    13686            this->myLeader_ = newLeader;
    13787            if (newLeader)
    138                 orxout(internal_error) << "new Leader set" << endl;
     88            {
     89                //orxout(internal_error) << "new Leader set" << endl;
     90            }
     91            //----If no leader found, attack someone----
     92            //----TODO: find closest enemy----
    13993            else
    14094            {
    141                 if (!this->target_){
     95                if ( !this->hasTarget() || this->action_ != Action::FIGHT )
     96                {
    14297                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
    14398                    {
    144                         if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())
     99                        if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) )
    145100                            continue;   
    146101                        this->setAction(Action::FIGHT, (*itP));
     
    149104                }
    150105            }
    151 
    152106        }
     107        //----If have leader, he will deal with logic----
    153108        else
    154109        {
    155110
    156111        }
    157        
     112
     113
     114        //----action was set to fight----
    158115        if (this->action_ == Action::FIGHT)
    159116        {
     117            //----choose where to go----
    160118            this->maneuver();
     119            //----fire if you can----
    161120            this->bShooting_ = this->canFire();
    162             if (this->target_)
    163             {
    164                 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
    165                 if (diffVector.length() > 5000)
    166                 {
    167                  
    168                 }   
    169             }
    170121        }
     122        //----action was set to fly, leader handles the logic----
    171123        else if (this->action_ == Action::FLY)
    172124        {
    173125
    174126        }
     127        //----TODO: implement protect----
    175128        else if (this->action_ == Action::PROTECT)
    176129        {
     
    182135   
    183136   
    184 
     137    //----POST: closest leader that is ready to take a new wingman is returned----
    185138    CommonController* WingmanController::findNewLeader()
    186139    {
     
    189142            return 0;
    190143
     144        //----vars for finding the closest leader----
    191145        CommonController* closestLeader = 0;
    192146        float minDistance =  std::numeric_limits<float>::infinity();
     
    194148        for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)
    195149        {
    196             //0ptr?
     150            //----0ptr or not a leader or dead?----
    197151            if (!it ||
    198152                (it->getRank() != Rank::SECTIONLEADER && it->getRank() != Rank::DIVISIONLEADER) ||
    199153                !(it->getControllableEntity()))
    200154                continue;
    201             //same team?
    202             if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam())
     155           
     156            //----same team?----
     157            if ( !CommonController::sameTeam (this->getControllableEntity(), (it)->getControllableEntity()) )
    203158                continue;
    204             //is equal to this?
    205             if (it->getControllableEntity() == this->getControllableEntity())
    206                 continue;
    207 
    208             float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
     159           
     160            //----check distance----
     161            float distance = CommonController::distance (it->getControllableEntity(), this->getControllableEntity());
    209162            if (distance < minDistance && !(it->hasWingman()))
    210163            {
     
    216169        if (closestLeader)
    217170        {
     171            //----Racing conditions----
    218172            if (closestLeader->setWingman(this))
    219173                return closestLeader;
     
    222176    }
    223177
    224     void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    225     {
    226         SUPER(WingmanController, XMLPort, xmlelement, mode);
    227 
    228         //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
    229     }
    230178
    231179
  • code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h

    r10731 r10826  
    3232
    3333#include "controllers/CommonController.h"
    34 #include <limits>
    3534
    3635
     
    4544    {
    4645        public:
    47             WingmanController(Context* context);
    48             virtual ~WingmanController();
    49            
    50             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    51             virtual void tick(float dt); //<! Carrying out the targets set in action().
    52             CommonController* findNewLeader();
     46            //----[language demanded functions]----
     47                WingmanController(Context* context);
     48               
     49                virtual ~WingmanController();
     50            //----[/language demanded functions]----
     51           
     52            //----[orxonox demanded functions]----
     53                virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     54
     55                virtual void tick(float dt);
     56            //----[/orxonox demanded functions]----
     57
     58            //----[own functions]----
     59               CommonController* findNewLeader();
     60            //----[/own functions]----
    5361
    5462        protected:
    55             WeakPtr<CommonController> myLeader_;
     63            //----action must only be managed by this----
     64                virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
    5665
    57             virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
    58 
    59 
    60                      
    6166        private:
    62 
    63 
    64             Timer actionTimer_; //<! Regularly calls action().
    65            
     67            //----private variables-----
     68                WeakPtr<CommonController> myLeader_;
     69                Timer actionTimer_; //<! Regularly calls action().
     70              
    6671    };
    6772}
Note: See TracChangeset for help on using the changeset viewer.