Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10722


Ignore:
Timestamp:
Oct 30, 2015, 12:08:30 PM (8 years ago)
Author:
gania
Message:

created destructor functions and improved findNewLeader and findNewDivisionLeader

Location:
code/branches/AI_HS15
Files:
12 edited

Legend:

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

    r10719 r10722  
    3232
    3333    <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
    34     <SpawnPoint team=0 position="-2000,-1000,3000" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
     34    <SpawnPoint team=0 position="1000,1000,-1000" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
    3535    <!-->
    3636
     
    7171    </StaticEntity>
    7272   
    73     <SpaceShip position="1000, 1000, -1500 ?>" lookat="0,0,0">
     73   
     74    <SpaceShip position="1000, 1000, -1300 ?>" lookat="0,0,0">
    7475      <templates>
    7576        <Template link=spaceshipassff />
    7677      </templates>
    7778      <controller>
    78         <DivisionController team=1>
    79         </DivisionController>
     79        <SectionController team=1>
     80        </SectionController>
    8081      </controller>
    8182    </SpaceShip>
    82     <SpaceShip position="1000, 1000, -1900 ?>" lookat="0,0,0">
     83    <SpaceShip position="1000, 1000, -1600 ?>" lookat="0,0,0">
    8384      <templates>
    8485        <Template link=spaceshipassff />
     
    8990      </controller>
    9091    </SpaceShip>
    91     <SpaceShip position="1000, 1000, -1500 ?>" lookat="0,0,0">
     92    <SpaceShip position="1000, 1000, -1900 ?>" lookat="0,0,0">
    9293      <templates>
    9394        <Template link=spaceshipassff />
     
    9899      </controller>
    99100    </SpaceShip>
    100     <SpaceShip position="1000, 1000, -1900 ?>" lookat="0,0,0">
    101       <templates>
    102         <Template link=spaceshipassff />
    103       </templates>
    104       <controller>
    105         <WingmanController team=1>
    106         </WingmanController>
    107       </controller>
    108     </SpaceShip>
     101
     102   
    109103    <!-->
    110104    <?lua
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc

    r10719 r10722  
    4242        return false;
    4343    }
     44    bool CommonController::hasWingman()
     45    {
     46        return true;
     47    }
     48
    4449    CommonController::CommonController(Context* context) : Controller(context)
    4550    {
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.h

    r10719 r10722  
    4444            virtual bool isLeader();
    4545            virtual bool setWingman(CommonController* wingman);
     46            virtual bool hasWingman();
     47            CommonController* myWingman_;
    4648
     49            CommonController* myLeader_;
    4750
    4851        protected:
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc

    r10719 r10722  
    4545        if (this->isInitialized())
    4646        {
    47            
     47            if (this->myFollower_)
     48                this->myFollower_->myDivisionLeader_ = 0;
     49            if (this->myWingman_)
     50                this->myWingman_->myLeader_ = 0;
    4851        }
    4952    } void DivisionController::tick(float dt)
    5053    {
    51                 SUPER(DivisionController, tick, dt);
     54        SUPER(DivisionController, tick, dt);
    5255
    5356    }
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h

    r10719 r10722  
    6565                }
    6666            };
     67            virtual bool hasWingman()
     68            {
     69                if (this->myWingman_)
     70                    return true;
     71                else
     72                    return false;
     73            }
     74            virtual bool hasFollower()
     75            {
     76                if (this->myFollower_)
     77                    return true;
     78                else
     79                    return false;
     80            };
     81           
     82
    6783            virtual void tick(float dt); //<! Carrying out the targets set in action().
    6884
    69                        
    7085
    7186        protected:
     
    7994                        FormationMode formationMode_;
    8095                       
    81                         CommonController* myWingman_;
    82                 LeaderController* myFollower_;
     96                       
    8397               
    8498
  • code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc

    r10719 r10722  
    4141        this->gameGoal_ = DOMINATE;
    4242        this->goalPosition_ = NULL;
    43         this->goalTarget_ = NULL;
    44         this->goalProtect_ = NULL;
     43      /*  this->goalTarget_ = NULL;
     44        this->goalProtect_ = NULL;*/
    4545        this->nTicks_ = 0;
    4646        this->bTicked_ = false;
  • code/branches/AI_HS15/src/orxonox/controllers/FleetController.h

    r10719 r10722  
    4848
    4949#include "worldentities/ControllableEntity.h"
    50 #include "worldentities/pawns/SpaceShip.h"
    51 #include "worldentities/pawns/Pawn.h"
    52 #include "worldentities/pawns/TeamBaseMatchBase.h"
    53 
    5450
    5551
  • code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h

    r10719 r10722  
    4949            {
    5050                return true;
    51             }
     51            };
    5252            bool bIsDivisionLeader_;
    5353            virtual bool setFollower(LeaderController* myFollower)
     
    5555                return false;
    5656            };
     57            virtual bool bIsDivisionLeader()
     58            {
     59                return bIsDivisionLeader_;
     60            };
     61            virtual bool hasFollower()
     62            {
     63                return true;
     64            };
     65            LeaderController* myFollower_;
     66            LeaderController* myDivisionLeader_;
    5767
    5868
  • code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc

    r10719 r10722  
    4848        if (this->isInitialized())
    4949        {
    50            
     50            if (this->myDivisionLeader_)
     51                this->myDivisionLeader_->myFollower_ = 0;
     52            if(this->myWingman_)
     53                this->myWingman_->myLeader_ = 0;
    5154        }
    5255    }
    53      LeaderController* SectionController::findNewDivisionLeader()
     56   
     57    LeaderController* SectionController::findNewDivisionLeader()
    5458    {
    5559
    5660        if (!this->getControllableEntity())
    57             return NULL;
     61            return 0;
    5862
    59        
     63        LeaderController* closestLeader = 0;
     64        float minDistance =  std::numeric_limits<float>::infinity();
    6065        //go through all pawns
    6166        for (ObjectList<LeaderController>::iterator it = ObjectList<LeaderController>::begin(); it; ++it)
    6267        {
    63 
     68            //0ptr or not DivisionController?
     69            if (!(it) || !(it)->bIsDivisionLeader_ || !(it->getControllableEntity()))
     70                continue;
    6471            //same team?
    6572            if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()))
     
    7279
    7380           
    74             //nullptr or not DivisionController?
    75             if (!(it) || !(it)->bIsDivisionLeader_)
    76                 continue;
     81           
    7782
    7883            float distance = ((it)->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
    79 
    80             // is pawn in range?
     84           
     85            if (distance < minDistance && !(it->hasFollower()))
     86            {
     87                closestLeader = *it;
     88                minDistance = distance;
     89            }
     90           /* // is pawn in range?
    8191            if (distance < RADIUS_TO_SEARCH_FOR_LEADER)
    8292            {
     
    8494                if ((it)->setFollower(this))
    8595                    return (*it);
    86             }
     96            }*/
    8797        }
    88                 return NULL;
     98        if (closestLeader)
     99        {
     100            if (closestLeader->setFollower(this))
     101                return closestLeader;
     102        }
     103        return 0;
    89104
    90105    }
     
    96111        {
    97112            LeaderController* newDivisionLeader = findNewDivisionLeader();
    98             myDivisionLeader_ = newDivisionLeader;
    99            /* if (newDivisionLeader)
     113            this->myDivisionLeader_ = newDivisionLeader;
     114            /*if (newDivisionLeader)
    100115                orxout(internal_error) << "new DivisionLeader set" << endl;
    101116            else
    102                 orxout(internal_error) << "null division leader" << endl;*/
     117                orxout(internal_error) << "0 division leader" << endl;*/
    103118        }
    104119    }
  • code/branches/AI_HS15/src/orxonox/controllers/SectionController.h

    r10719 r10722  
    5454                }
    5555            };
     56            virtual bool hasWingman()
     57            {
     58                if (this->myWingman_)
     59                    return true;
     60                else
     61                    return false;
     62            }
     63
    5664            virtual void tick(float dt); //<! Carrying out the targets set in action().
    5765
    5866            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5967            LeaderController* findNewDivisionLeader();
    60  
    61 
    6268
    6369        protected:
     
    7682        private:
    7783            Timer actionTimer_; //<! Regularly calls action().
    78             CommonController* myWingman_;
    79             LeaderController* myDivisionLeader_;
     84           
    8085            Vector3* desiredRelativePosition_;
    8186
  • code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc

    r10719 r10722  
    2929#include "WingmanController.h"
    3030
    31 #include "core/CoreIncludes.h"
    32 
    33 #include "core/XMLPort.h"
    34 #include "core/command/ConsoleCommandIncludes.h"
    35 
    36 #include "worldentities/ControllableEntity.h"
    37 #include "worldentities/pawns/Pawn.h"
    3831
    3932namespace orxonox
     
    5144    WingmanController::~WingmanController()
    5245    {
    53     }
    54 
    55    /* void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    56     {
    57         SUPER(WingmanController, XMLPort, xmlelement, mode);
    58 
    59         XMLPortParam(WingmanController, "accuracy", setAccuracy, getAccuracy, xmlelement, mode).defaultValues(100.0f);
    60         XMLPortObject(WingmanController, WorldEntity, "waypoints", addWaypoint, getWaypoint,  xmlelement, mode);
    61     }*/
     46        if (this->myLeader_)
     47            this->myLeader_->myWingman_ = 0;
     48    }
     49
    6250    CommonController* WingmanController::findNewLeader()
    6351    {
    6452
    6553        if (!this->getControllableEntity())
    66             return NULL;
    67 
    68        
    69         //go through all pawns
     54            return 0;
     55
     56        CommonController* closestLeader = 0;
     57        float minDistance =  std::numeric_limits<float>::infinity();
     58
    7059        for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)
    7160        {
     61            //0ptr?
     62            if (!it || !it->isLeader() || !(it->getControllableEntity()))
     63                continue;
    7264            //same team?
    73             if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()))
     65            if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam())
    7466                continue;
    7567            //is equal to this?
     
    7971
    8072
    81             //nullptr?
    82             if (!it || !it->isLeader())
    83                 continue;
     73         
    8474
    8575            float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
    86 
    87             // is pawn in range?
     76            if (distance < minDistance && !(it->hasWingman()))
     77            {
     78                closestLeader = *it;
     79                minDistance = distance;
     80            }
     81            /*// is pawn in range?
    8882            if (distance < RADIUS_TO_SEARCH_FOR_LEADER)
    8983            {
     
    9185                if (it->setWingman(this))
    9286                    return *it;
    93             }
    94         }
    95         return NULL;
    96     }
     87            }*/
     88        }
     89        if (closestLeader)
     90        {
     91            if (closestLeader->setWingman(this))
     92                return closestLeader;
     93        }
     94        return 0;
     95    }
     96   
    9797    void WingmanController::action()
    9898    {
    9999        //this->target_ = this->sectionTarget_;
    100         if (!myLeader_)
     100        if (!this->myLeader_)
    101101        {
    102102            CommonController* newLeader = findNewLeader();
    103             myLeader_ = newLeader;
    104            /* if (newLeader)
     103            this->myLeader_ = newLeader;
     104            if (newLeader)
    105105                orxout(internal_error) << "new Leader set" << endl;
    106106            else
    107                 orxout(internal_error) << "null leader" << endl;
    108 */
     107                orxout(internal_error) << "0 leader" << endl;
     108
    109109        }
    110110        else
    111111        {
     112
    112113            //orxout(internal_error) << "already have a Leader" << endl;
    113114
  • code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h

    r10719 r10722  
    3232
    3333#include "controllers/CommonController.h"
     34#include <limits>
    3435
    3536
     
    5051                return false;
    5152            };
     53
    5254            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5355            virtual void tick(float dt); //<! Carrying out the targets set in action().
     
    6567           
    6668            WeakPtr<Pawn> target_;
    67             CommonController* myLeader_;
    6869            //LeaderController* leader_;
    6970
Note: See TracChangeset for help on using the changeset viewer.