Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10719


Ignore:
Timestamp:
Oct 29, 2015, 8:02:23 PM (8 years ago)
Author:
gania
Message:

All compiling, WingmanControllers actually find LeaderControllers and connect to them, SectionControllers find DivisionControllers and connect. TODO write tick functions, helper functions to CommonController

Location:
code/branches/AI_HS15
Files:
4 added
11 edited

Legend:

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

    r10717 r10719  
    6363  </!-->
    6464   
    65     <SpaceShip position = "-1000, -1000, -1000">
    66       <templates>
    67         <Template link=spaceshipassff />
    68       </templates>
     65    <StaticEntity position = "-1000, -1000, -1000">
     66 
    6967      <controller>
    7068        <FleetController accuracy=10 team=1 >
    7169        </FleetController>
    7270      </controller>
    73     </SpaceShip>
     71    </StaticEntity>
    7472   
    7573    <SpaceShip position="1000, 1000, -1500 ?>" lookat="0,0,0">
     
    9694      </templates>
    9795      <controller>
    98         <LeaderController team=1>
    99         </LeaderController>
     96        <SectionController team=1>
     97        </SectionController>
    10098      </controller>
    10199    </SpaceShip>
     
    109107      </controller>
    110108    </SpaceShip>
    111     <!-->   
    112109    <!-->
    113110    <?lua
  • code/branches/AI_HS15/src/orxonox/controllers/CMakeLists.txt

    r10709 r10719  
    1515  LeaderController.cc
    1616  WingmanController.cc
     17  SectionController.cc
     18  CommonController.cc
    1719)
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc

    r10718 r10719  
    6464        }
    6565    }
    66     /*void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     66    void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    6767    {
    6868        SUPER(DivisionController, XMLPort, xmlelement, mode);
    6969
    7070        //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
    71     }*/
     71    }
    7272
    7373   
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h

    r10718 r10719  
    3939namespace orxonox
    4040{
    41     class _OrxonoxExport DivisionController : public LeaderController
     41    class _OrxonoxExport DivisionController : public LeaderController, public Tickable
    4242      {
    4343        public:
     
    4545                virtual ~DivisionController();
    4646
    47                 //virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     47                virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4848
    4949                //Using british military aircraft formations
     
    5353                        { return this->formationMode_; }
    5454                        virtual bool setFollower(LeaderController* myFollower);
     55                        virtual bool setWingman(CommonController* wingman)
     56            {
     57                if (!this->myWingman_)
     58                {
     59                    this->myWingman_ = wingman;
     60                    return true;
     61                }
     62                else
     63                {
     64                    return false;
     65                }
     66            };
     67            virtual void tick(float dt); //<! Carrying out the targets set in action().
    5568
    5669                       
     
    6679                        FormationMode formationMode_;
    6780                       
    68                        
     81                        CommonController* myWingman_;
    6982                LeaderController* myFollower_;
    7083               
  • code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc

    r10717 r10719  
    3535    RegisterClass(FleetController);
    3636
    37     FleetController::FleetController(Context* context) : FormationController(context)
     37    FleetController::FleetController(Context* context) : Controller(context)
    3838    {
    3939        RegisterObject(FleetController);
  • code/branches/AI_HS15/src/orxonox/controllers/FleetController.h

    r10709 r10719  
    2929#ifndef _FleetController_H__
    3030#define _FleetController_H__
    31 #include "controllers/FormationController.h"
    3231
    3332#include "controllers/Controller.h"
     
    5857{   
    5958
    60     class _OrxonoxExport FleetController : public FormationController, public Tickable
     59    class _OrxonoxExport FleetController : public Controller, public Tickable
    6160    {
    6261        public:
  • code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc

    r10717 r10719  
    277277        }
    278278
    279         Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
     279        Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
    280280        float distance = (target - this->getControllableEntity()->getPosition()).length();
    281281        float rotateX = clamp(coord.x * 10, -1.0f, 1.0f);
     
    10691069            return;
    10701070
    1071         Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
     1071        Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
    10721072        float distance = (target - this->getControllableEntity()->getPosition()).length();
    10731073
  • code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc

    r10718 r10719  
    4141    RegisterClass(LeaderController);
    4242
    43     static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000;
    4443
    4544    LeaderController::LeaderController(Context* context) : CommonController(context)
     
    4746
    4847        RegisterObject(LeaderController);
    49         bIsDivisionLeader_ = false;
    5048
    5149        //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this)));
     
    5755    }
    5856
    59     LeaderController* LeaderController::findNewDivisionLeader()
    60     {
    61 
    62         if (!this->getControllableEntity())
    63             return NULL;
    64 
    65        
    66         //go through all pawns
    67         for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    68         {
    69 
    70             //same team?
    71             if (!(this->getControllableEntity()->getTeam() != static_cast<ControllableEntity*>(*it)->getTeam()))
    72                 continue;
    73 
    74             //Does it have a Controller?
    75             Controller* controller = 0;
    76 
    77             if (it->getController())
    78                 controller = it->getController();
    79             else if (it->getXMLController())
    80                 controller = it->getXMLController();
    81 
    82             if (!controller)
    83                 continue;
    84 
    85             //is equal to this?
    86             if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
    87                 continue;
    88 
    89 
    90             LeaderController* newLeader = orxonox_cast<LeaderController*>(controller);
    91 
    92             //nullptr or not DivisionController?
    93             if (!newLeader || !newLeader->bIsDivisionLeader_)
    94                 continue;
    95 
    96             float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length();
    97 
    98             // is pawn in range?
    99             if (distance < RADIUS_TO_SEARCH_FOR_LEADER)
    100             {
    101 
    102                 if (newLeader->setFollower(this))
    103                     return newLeader;
    104             }
    105         }
    106                 return NULL;
    107 
    108     }
    109     void LeaderController::action()
    110     {
    111         //this->target_ = this->sectionTarget_;       
    112         if (!myDivisionLeader_)
    113         {
    114             LeaderController* newDivisionLeader = findNewDivisionLeader();
    115             myDivisionLeader_ = newDivisionLeader;
    116             orxout(internal_error) << "new DivisionLeader set" << endl;
    117         }
    118     }
    119     /*
    120     Wingmen and Leaders attack target_, which is a member variable of their classes.
    121     Wingmen's target_ is set to sectionTarget_, which is a member variable of SectionController class, unless
    122     Wingman covers Leader's rear.
    123     Leader's target_ must always equal sectionTarget_.
    124     if section has a target, its Leader shoots at it, but doesn't follow.
    125     Every section is a part of division. Division consisting of one Section is still a division.
    126     Division's leader's target_ must always equal divisionTarget_, which is a member variable of DivisionController.
    127     Division leader ONLY can follow target_ while in formation flight.
    128     If Division doesn't have a target, Division Leader stays in place, unless it has a waypoint.
    129     Division Leader's sectionTarget_ must equal divisionTarget_,
    130     but the other section, that is not a leading section, can attack any target that is near divisonTarget_
    131 
    132     */
    133     void LeaderController::tick(float dt)
    134     {/*
    135         if (!this->isActive())
    136             return;
    137        
    138         //--------------------------Stay in division--------------------------
    139         this->keepDivisionTick();*/
    140         /*keepDivisionTick(){
    141             if (this->divisionLeader_ && this->divisionLeader_->getControllableEntity() && desiredRelativePosition_){
    142                 Vector3 desiredAbsolutePosition = ((this->divisionLeader_->getControllableEntity()->getWorldPosition()) +
    143                     (this->divisionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
    144                 this->moveToPosition (desiredAbsolutePosition);
    145             }
    146         }
    147         */
    148         /*//If ordered to attack -> follow target and shoot
    149         if (this->bAttackOrder_)
    150         {
    151  
    152         }
    153         //If ordered to move -> move to a target Point
    154        
    155         //No orders -> Don't move, but shoot at whatever is close, unless Boss is shooting at it.
    156         //(Section shoots same target, Boss's section shoots another target)
    157         {
    158 
    159         }*/
    160 
    161         orxout(internal_error) << "my Wingman is " << this->myWingman_ << endl;
    162        
    163         SUPER(LeaderController, tick, dt);
    164     }
    165     bool LeaderController::setWingman(WingmanController* wingman)
    166     {
    167         if (!this->myWingman_)
    168         {
    169             this->myWingman_ = wingman;
    170             return true;
    171         }
    172         else
    173         {
    174             return false;
    175         }
    176     }
    177     bool LeaderController::isLeader()
    178     {
    179         return true;
    180     }
     57   
    18158//**********************************************NEW
    18259   /* void LeaderController::defaultBehaviour(float maxrand)
  • code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h

    r10718 r10719  
    3535
    3636#include "util/Math.h"
    37 #include "tools/Timer.h"
    38 #include "tools/interfaces/Tickable.h"
     37
    3938
    4039namespace orxonox
    4140{
    42     class _OrxonoxExport LeaderController : public CommonController,  virtual public Tickable
     41    class _OrxonoxExport LeaderController : public CommonController
    4342    {
    4443        public:
    45            
     44               static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000;
     45
    4646            LeaderController(Context* context);
    4747            virtual ~LeaderController();
    48             virtual bool isLeader();
     48            virtual bool isLeader()
     49            {
     50                return true;
     51            }
     52            bool bIsDivisionLeader_;
     53            virtual bool setFollower(LeaderController* myFollower)
     54            {
     55                return false;
     56            };
    4957
    50             virtual bool setWingman(WingmanController* wingman);
    51             virtual void tick(float dt); //<! Carrying out the targets set in action().
    5258
    5359        protected:
    5460           
    55             LeaderController* findNewDivisionLeader();
    5661
    57             bool bIsDivisionLeader_;
    5862
    59             virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
    6063            //void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot.   
    6164         
     
    6467            WeakPtr<Pawn> target_;
    6568           
    66             WingmanController* myWingman_;
    67             LeaderController* myDivisionLeader_;
     69           
    6870            //Timer actionTimer_; //<! Regularly calls action().
    6971               
  • code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc

    r10717 r10719  
    4141
    4242    RegisterClass(WingmanController);
    43     static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000;
    44 
     43    static const int RADIUS_TO_SEARCH_FOR_LEADER = 7000;
     44    static const float ACTION_INTERVAL = 1.0f;
    4545    WingmanController::WingmanController(Context* context) : CommonController(context)
    4646    {
    4747        RegisterObject(WingmanController);
    48         //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
     48        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
    4949    }
    5050
     
    6868       
    6969        //go through all pawns
    70         for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    71         {
    72 
     70        for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)
     71        {
    7372            //same team?
    74             if (!(this->getControllableEntity()->getTeam() != static_cast<ControllableEntity*>(*it)->getTeam()))
     73            if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()))
    7574                continue;
    76 
    77             //Does it have a Controller?
    78             Controller* controller = 0;
    79 
    80             if (it->getController())
    81                 controller = it->getController();
    82             else if (it->getXMLController())
    83                 controller = it->getXMLController();
    84 
    85             if (!controller)
     75            //is equal to this?
     76            if (it->getControllableEntity() == this->getControllableEntity())
    8677                continue;
    8778
    88             //is equal to this?
    89             if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
     79
     80
     81            //nullptr?
     82            if (!it || !it->isLeader())
    9083                continue;
    9184
    92 
    93             CommonController* newLeader = orxonox_cast<CommonController*>(controller);
    94 
    95             //nullptr?
    96             if (!newLeader || !newLeader->isLeader())
    97                 continue;
    98 
    99             float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length();
     85            float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
    10086
    10187            // is pawn in range?
     
    10389            {
    10490
    105                 if (newLeader->setWingman(this))
    106                     return newLeader;
     91                if (it->setWingman(this))
     92                    return *it;
    10793            }
    10894        }
    10995        return NULL;
    110     }
    111     bool WingmanController::isLeader()
    112     {
    113         return false;
    11496    }
    11597    void WingmanController::action()
     
    120102            CommonController* newLeader = findNewLeader();
    121103            myLeader_ = newLeader;
    122             orxout(internal_error) << "new Leader set" << endl;
    123         }
    124     }
    125 
    126     void WingmanController::tick(float dt)
    127     {   
    128         //-------------------------------------------------------
    129             /*//collect data for AI behaviour
     104           /* if (newLeader)
     105                orxout(internal_error) << "new Leader set" << endl;
     106            else
     107                orxout(internal_error) << "null leader" << endl;
     108*/
     109        }
     110        else
     111        {
     112            //orxout(internal_error) << "already have a Leader" << endl;
     113
     114        }
     115    }
     116 /*//collect data for AI behaviour
    130117            Vector3* meanOfEnemiesPtr = new Vector3(0.0,0.0,0.0);
    131118            Vector3* meanOfAlliesPtr  = new Vector3(0.0,0.0,0.0);
     
    166153                orxout(internal_error) << "mean of enemies_ is " << meanOfEnemies << ", with a size " << enemies_.size() << endl;
    167154            }*/
    168     /*
    169         if (!this->isActive())
    170             return;
    171         //--------------------------Stay in formation--------------------------
    172         if (bFollowLeader_)
    173         {
    174             this->keepSectionTick();*/
    175             /*keepSectionTick(){
    176                 if (this->sectionLeader_ && this->sectionLeader_->getControllableEntity() && desiredRelativePosition_){
    177                     Vector3 desiredAbsolutePosition = ((this->sectionLeader_->getControllableEntity()->getWorldPosition()) +
    178                         (this->sectionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
    179                     this->moveToPosition (desiredAbsolutePosition);
    180                 }
    181             }
    182             */
    183           /* 
    184             //--------------------------Attack same target as the Leader--------------------------
    185 
    186             if (this->target_)
    187             {
    188                 this->aimAtTarget();
    189                 this->doFire();
    190             }
    191         }*/
    192          //orxout(internal_error) << "I am " << this << endl;
    193 
    194        /* void FormationController::setDesiredPositionOfSlaves()
     155
     156      /*  void FormationController::setDesiredPositionOfSlaves()
    195157    {
    196158        if (this->state_ != MASTER)
     
    218180       
    219181    }*/
     182    void WingmanController::tick(float dt)
     183    {   
     184        //-------------------------------------------------------
     185           
     186        /*
     187        if (!this->isActive())
     188            return;
     189        //--------------------------Stay in formation--------------------------
     190        if (bFollowLeader_)
     191        {
     192            this->keepSectionTick();
     193           
     194            keepSectionTick(){
     195                if (this->sectionLeader_ && this->sectionLeader_->getControllableEntity() && desiredRelativePosition_){
     196                    Vector3 desiredAbsolutePosition = ((this->sectionLeader_->getControllableEntity()->getWorldPosition()) +
     197                        (this->sectionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
     198                    this->moveToPosition (desiredAbsolutePosition);
     199                }
     200            }
     201           
     202           
     203            //--------------------------Attack same target as the Leader--------------------------
     204
     205            if (this->target_)
     206            {
     207                this->aimAtTarget();
     208                this->doFire();
     209            }
     210        }
     211        */
     212         //orxout(internal_error) << "I am " << this << endl;
     213
    220214       
    221215        SUPER(WingmanController, tick, dt);
    222216    }
     217
     218    void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     219    {
     220        SUPER(WingmanController, XMLPort, xmlelement, mode);
     221
     222        //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
     223    }
     224
    223225//**********************************************NEW
    224226    /*void WingmanController::defaultBehaviour(float maxrand)
  • code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h

    r10717 r10719  
    4646            WingmanController(Context* context);
    4747            virtual ~WingmanController();
    48             virtual bool isLeader();
    49           //virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     48            virtual bool isLeader()
     49            {
     50                return false;
     51            };
     52            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5053            virtual void tick(float dt); //<! Carrying out the targets set in action().
     54            CommonController* findNewLeader();
    5155
    5256        protected:
    53             CommonController* findNewLeader();
    5457
    5558            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
     
    6568            //LeaderController* leader_;
    6669
    67             //Timer actionTimer_; //<! Regularly calls action().
     70            Timer actionTimer_; //<! Regularly calls action().
    6871           
    6972    };
Note: See TracChangeset for help on using the changeset viewer.