Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10731


Ignore:
Timestamp:
Oct 31, 2015, 4:07:29 PM (8 years ago)
Author:
gania
Message:

added a little bit of firing functionality

Location:
code/branches/AI_HS15
Files:
14 edited

Legend:

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

    r10729 r10731  
    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="1000,1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
     34    <SpawnPoint team=0 position="-1000,-1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
    3535    <!-->
    3636
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc

    r10729 r10731  
    3535    static const float ROTATEFACTOR = 0.2f;
    3636
    37     /*static const float SPEED_FREE = 0.8f;
    38     static const float ROTATEFACTOR_FREE = 0.8f;*/
    39    
     37    CommonController::CommonController(Context* context) : Controller(context)
     38    {
     39
     40        RegisterObject(CommonController);
     41    }
     42
     43
     44    CommonController::~CommonController()
     45    {
     46    }
     47
     48
     49
     50
    4051    bool CommonController::setWingman (CommonController* wingman)
    4152    {
    4253        return false;
    4354    }
    44     bool CommonController::isLeader ()
    45     {
    46         return false;
    47     }
     55   
    4856    bool CommonController::hasWingman()
    4957    {
     
    5159    }
    5260
    53     CommonController::CommonController(Context* context) : Controller(context)
    54     {
    55 
    56         RegisterObject(CommonController);
    57     }
    58 
    59 
    60     CommonController::~CommonController()
    61     {
    62     }
     61
     62
     63
     64    void CommonController::setTargetPosition(const Vector3& target)
     65    {
     66        this->targetPosition_ = target;
     67        this->bHasTargetPosition_ = true;
     68    }
     69
     70    void CommonController::setTargetOrientation(const Quaternion& orient)
     71    {
     72        this->targetOrientation_=orient;
     73        this->bHasTargetOrientation_=true;
     74    }
     75
     76    void CommonController::setTargetOrientation(ControllableEntity* target)
     77    {
     78        if (target)
     79            setTargetOrientation(target->getOrientation());
     80    }
     81
     82    /*void CommonController::spin()
     83    {
     84        this->moveToTargetPosition();
     85        this->getControllableEntity()->rotateRoll(8.0f);
     86    }
     87    void CommonController::turn180()
     88    {
     89        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
     90
     91        this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x);
     92        this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y);
     93
     94        this->getControllableEntity()->moveFrontBack(SPEED);
     95    }*/
     96
     97
     98
    6399    //copy the Roll orientation of given Quaternion.
    64100    void CommonController::copyOrientation(const Quaternion& orient)
     
    69105        while(diff<-math::twoPi) diff+=math::twoPi;
    70106        this->getControllableEntity()->rotateRoll(-diff);
    71 
    72 
    73 
    74     }
    75     void CommonController::setTargetPosition(const Vector3& target)
    76     {
    77         this->targetPosition_ = target;
    78         this->bHasTargetPosition_ = true;
    79     }
    80 
     107    }
    81108    void CommonController::copyTargetOrientation()
    82109    {
     
    86113        }
    87114    }
    88     void CommonController::setTargetOrientation(const Quaternion& orient)
    89     {
    90         this->targetOrientation_=orient;
    91         this->bHasTargetOrientation_=true;
    92     }
    93     void CommonController::setTargetOrientation(ControllableEntity* target)
    94     {
    95         if (target)
    96             setTargetOrientation(target->getOrientation());
    97     }
    98 
    99 
     115
     116
     117
     118
     119    void CommonController::moveToTargetPosition()
     120    {
     121        this->moveToPosition(this->targetPosition_);
     122    }
    100123    void CommonController::moveToPosition(const Vector3& target)
    101124    {
     
    146169            bHasTargetOrientation_ = false;
    147170        }
    148 
    149      
    150     }
    151     void CommonController::moveToTargetPosition()
    152     {
    153         this->moveToPosition(this->targetPosition_);
    154     }
     171    }
     172    void CommonController::doFire()
     173    {
     174         if (this->isLookingAtTarget(math::pi / 20.0f))
     175            this->getControllableEntity()->fire(0); //ai uses lens flare if they're close enough to the target
     176    }
     177    bool CommonController::isLookingAtTarget(float angle) const
     178    {
     179        if (!this->getControllableEntity())
     180            return false;
     181
     182        return (getAngle(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->targetPosition_) < angle);
     183    }
     184
     185    void CommonController::aimAtTarget()
     186    {
     187        if (!this->target_ || !this->getControllableEntity())
     188            return;
     189
     190        static const float hardcoded_projectile_speed = 750;
     191
     192        Vector3 aimPosition = getPredictedPosition(this->getControllableEntity()->getWorldPosition(),
     193            hardcoded_projectile_speed, this->target_->getWorldPosition(), this->target_->getVelocity());
     194
     195        Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
     196        if (pawn)
     197            pawn->setAimPosition(aimPosition);
     198    }
     199   
    155200 
    156201
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.h

    r10729 r10731  
    3333#include "controllers/Controller.h"
    3434#include "worldentities/ControllableEntity.h"
     35#include "worldentities/pawns/Pawn.h"
     36
    3537
    3638namespace orxonox
     
    3941    {
    4042        public:
     43
    4144            static const float ACTION_INTERVAL = 1.0f;
    4245
    43             enum FormationMode {VEE,FINGER4,DIAMOND, WALL};
     46
     47            CommonController(Context* context);
     48            virtual ~CommonController();
     49
     50
     51
     52            enum FormationMode { VEE, FINGER4, DIAMOND, WALL };
    4453            virtual void setFormationMode(FormationMode val)
    4554                { this->formationMode_ = val; }
     
    4756                { return this->formationMode_; }
    4857
    49             CommonController(Context* context);
    50             virtual ~CommonController();
    51             virtual bool isLeader();
     58            enum Rank { NONE, SECTIONLEADER, DIVISIONLEADER, WINGMAN };
     59            virtual void setRank(Rank val)
     60                { this->rank_ = val; }
     61            inline Rank getRank() const
     62                { return this->rank_; }
     63
     64
     65
     66
    5267            virtual bool setWingman(CommonController* wingman);
    5368            virtual bool hasWingman();
     
    5873            void setTargetPosition(const Vector3& target);
    5974
     75            /*void spin();
     76            void turn180();*/
     77
     78
    6079        protected:
     80
    6181            void moveToPosition(const Vector3& target);
    62             virtual void positionReached() {}
     82            void moveToTargetPosition();
    6383
    64        
    65             void moveToTargetPosition();
     84
    6685            void copyOrientation(const Quaternion& orient);
    6786            void copyTargetOrientation();
    6887
     88            void doFire();
     89            void aimAtTarget();
     90            bool isLookingAtTarget(float angle) const;
    6991
    7092            bool bHasTargetPosition_;
     
    7395            Quaternion targetOrientation_;
    7496
     97
    7598            WeakPtr<ControllableEntity> target_;
    7699            bool bShooting_;
    77100
     101
    78102            FormationMode formationMode_;
    79 
     103            Rank rank_;
    80104
    81105
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc

    r10729 r10731  
    4040        this->setFormationMode(WALL);
    4141
    42         bIsDivisionLeader_ = true;
    4342        this->myFollower_ = 0;
    4443        this->myWingman_ = 0;
    4544        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this)));
    46        
    47         /*Vector3* pos = new Vector3(500,500,-500);
    48         this->setTargetPosition(*pos);*/
     45        this->rank_ = DIVISIONLEADER;
     46
     47        Vector3* pos = new Vector3(500,500,-500);
     48        this->setTargetPosition(*pos);
    4949
    5050    }
     
    5454     
    5555    }
     56
     57   
    5658    void DivisionController::tick(float dt)
    5759    {
     60        if (this->target_)
     61        {
     62            this->aimAtTarget();
     63            this->doFire();
     64        }
     65     
    5866        if (this->bHasTargetPosition_)
    5967        {
     
    6876        setTargetPositionOfFollower();
    6977        setTargetPositionOfWingman();
    70     }
    71 
    72     bool DivisionController::setFollower(LeaderController* myFollower)
    73     {
    74          if (!this->myFollower_)
    75         {
    76             this->myFollower_ = myFollower;
    77             return true;
    78         }
    79         else
    80         {
    81             return false;
    82         }
    83     }
     78
     79        for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it)
     80        {
     81            if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam())
     82            {
     83                this->target_=it->getControllableEntity();
     84                this->setTargetPosition(this->target_->getWorldPosition());
     85                break;
     86            }
     87        }
     88           
     89     
     90    }
     91
     92   
    8493
    8594    void DivisionController::setTargetPositionOfWingman()
     
    149158       
    150159    }
     160
     161
     162    bool DivisionController::setWingman(CommonController* cwingman)
     163    {
     164
     165        WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
     166        if (!this->myWingman_)
     167        {
     168            this->myWingman_ = wingman;
     169            return true;
     170        }
     171        else
     172        {
     173            return false;
     174        }
     175   
     176    }
     177    bool DivisionController::setFollower(LeaderController* myFollower)
     178    {
     179         if (!this->myFollower_)
     180        {
     181            this->myFollower_ = myFollower;
     182            return true;
     183        }
     184        else
     185        {
     186            return false;
     187        }
     188    }
     189    bool DivisionController::hasWingman()
     190    {
     191        if (this->myWingman_)
     192            return true;
     193        else
     194            return false;
     195    }
     196    bool DivisionController::hasFollower()
     197    {
     198        if (this->myFollower_)
     199            return true;
     200        else
     201            return false;
     202    }
     203
     204
    151205    void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    152206    {
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h

    r10729 r10731  
    4242      {
    4343        public:
     44
    4445                DivisionController(Context* context);
    4546                virtual ~DivisionController();
    4647
    47                 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     48            virtual void tick(float dt); //<! Carrying out the targets set in action().
    4849
    49                 //Using british military aircraft formations
    50                
    5150               
    5251                        virtual bool setFollower(LeaderController* myFollower);
    53                         virtual bool setWingman(CommonController* cwingman)
    54             {
    55                 WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
    56                 if (!this->myWingman_)
    57                 {
    58                     this->myWingman_ = wingman;
    59                     return true;
    60                 }
    61                 else
    62                 {
    63                     return false;
    64                 }
    65             };
    66             virtual bool hasWingman()
    67             {
    68                 if (this->myWingman_)
    69                     return true;
    70                 else
    71                     return false;
    72             }
    73             virtual bool hasFollower()
    74             {
    75                 if (this->myFollower_)
    76                     return true;
    77                 else
    78                     return false;
    79             };
    80            
     52                        virtual bool setWingman(CommonController* cwingman);
     53            virtual bool hasWingman();
     54            virtual bool hasFollower();
    8155
    82             virtual void tick(float dt); //<! Carrying out the targets set in action().
    83 
     56            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);         
    8457
    8558        protected:
     59           
    8660            void setTargetPositionOfWingman();
    8761            void setTargetPositionOfFollower();
     62
    8863            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
    8964           
    9065        private:
     66
    9167            Timer actionTimer_; //<! Regularly calls action().
    9268
  • code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc

    r10722 r10731  
    4343      /*  this->goalTarget_ = NULL;
    4444        this->goalProtect_ = NULL;*/
    45         this->nTicks_ = 0;
    46         this->bTicked_ = false;
     45       
    4746        //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&FleetController::action, this)));
    4847    }
     
    6362    {
    6463
    65          /*if (nTicks_ == 30)
    66          {
    67             std::vector<WeakPtr<WingmanController> > wingmen;
    68             std::vector<WeakPtr<LeaderController> > leaders;
    69 
    70             //--------------------------Put all WingmanController's in a vector--------------------------
    71             for (ObjectList<WingmanController>::iterator it = ObjectList<WingmanController>::begin(); it; ++it)
    72             {
    73 
    74                
    75                 if ((*it)->getTeam() == this->getTeam())
    76                 {
    77                     orxout(internal_error) << "ANOTHER SUCKER" << endl;
    78                     wingmen.push_back(*it);
    79                 }
    80                
    81             }
    82             //--------------------------Substitute half of WingmanController's with LeaderController--------------------------
    83 
    84             bool nowLeader = true;
    85             LeaderController* leader;
    86 
    87             for (std::vector<WeakPtr<WingmanController> >::iterator it = wingmen.begin() ; it != wingmen.end(); ++it)
    88             {
    89                 if (nowLeader)
    90                 {
    91                     leader = new LeaderController(this->getContext());
    92                     leader->setTeam(this->team_);
    93 
    94                     (*it)->getControllableEntity()->setController(leader);
    95                     leaders.push_back(leader);
    96                     nowLeader = !nowLeader;
    97                     orxout(internal_error) << "NEW SUCKER" << endl;
    98 
    99                 }
    100                 else
    101                 {
    102                     if (leader)
    103                     {
    104                         leader->setWingman(*it);
    105                         nowLeader = !nowLeader;
    106                         orxout(internal_error) << "I OWN THE SUCKER" << endl;
    107 
    108                     }
    109                 }
    110             }
    111 
    112             //--------------------------Substitute half of LeaderController's with DivisionController--------------------------
    113             bool nowDivision = true;
    114             DivisionController* division;
    115 
    116             for (std::vector<WeakPtr<LeaderController> >::iterator it = leaders.begin() ; it != leaders.end(); ++it)
    117             {
    118                 if (nowDivision)
    119                 {
    120                     division = new DivisionController(this->getContext());
    121                     division->setTeam(this->team_);
    122 
    123                     (*it)->getControllableEntity()->setController(division);
    124 
    125                     divisions_.push_back(division);
    126 
    127                     nowDivision = !nowDivision;
    128                 }
    129                 else
    130                 {
    131                     if (division)
    132                     {
    133                         division->setLeader(*it);
    134                         nowDivision = !nowDivision;
    135                     }
    136                 }
    137             }
    138             bTicked_ = true;
    139             nTicks_ += 1;
    140          }
    141          else if (!bTicked_)
    142          {
    143             nTicks_ += 1;
    144 
    145          }*/
    14664        SUPER(FleetController, tick, dt);
    14765
  • code/branches/AI_HS15/src/orxonox/controllers/FleetController.h

    r10722 r10731  
    8383            virtual void action();
    8484        private:
    85             int nTicks_;
    86             bool bTicked_;
    87 
     85       
    8886            std::vector<WeakPtr<DivisionController> > divisions_;
    8987            //Timer actionTimer_; //<! Regularly calls action().
  • code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h

    r10729 r10731  
    4545            LeaderController(Context* context);
    4646            virtual ~LeaderController();
    47             virtual bool isLeader()
    48             {
    49                 return true;
    50             };
    51             bool bIsDivisionLeader_;
     47           
    5248            virtual bool setFollower(LeaderController* myFollower)
    53             {
    54                 return false;
    55             };
    56             virtual bool bIsDivisionLeader()
    57             {
    58                 return bIsDivisionLeader_;
    59             };
     49                { return false; }
     50           
    6051            virtual bool hasFollower()
    61             {
    62                 return true;
    63             };
     52                { return true; }
     53           
     54
     55
     56
     57        protected:
     58         
    6459            WeakPtr<WingmanController> myWingman_;
    6560
     
    6762            WeakPtr<LeaderController> myDivisionLeader_;
    6863
    69 
    70         protected:
    71          
     64           
    7265        private:
    7366           
  • code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc

    r10729 r10731  
    3939        this->setFormationMode(WALL);
    4040
    41         bIsDivisionLeader_ = false;
    4241        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&SectionController::action, this)));
    4342        this->myWingman_ = 0;
    4443        this->myDivisionLeader_ = 0;
     44        this->rank_ = SECTIONLEADER;
    4545
    4646        orxout(internal_error) << this << "Was created" << endl;
     
    5252       
    5353    }
     54
     55    void SectionController::tick(float dt)
     56    {
     57        if (!this->isActive())
     58            return;
     59       
     60        if (this->bHasTargetPosition_)
     61        {
     62            this->moveToTargetPosition();
     63        }
     64
     65       
     66        SUPER(SectionController, tick, dt);
     67    }
     68
     69    void SectionController::action()
     70    {
     71        //this->target_ = this->sectionTarget_;       
     72        if (!myDivisionLeader_)
     73        {
     74            LeaderController* newDivisionLeader = findNewDivisionLeader();
     75            this->myDivisionLeader_ = newDivisionLeader;
     76            if (newDivisionLeader)
     77                orxout(internal_error) << "new DivisionLeader set" << endl;
     78
     79        }
     80        setTargetPositionOfWingman();
     81
     82    }
     83   
    5484    void SectionController::setTargetPositionOfWingman()
    5585    {
     
    85115       
    86116    }
    87 
    88117    LeaderController* SectionController::findNewDivisionLeader()
    89118    {
     
    98127        {
    99128            //0ptr or not DivisionController?
    100             if (!(it) || !(it)->bIsDivisionLeader_ || !(it->getControllableEntity()))
     129            if (!(it) || !((it)->getRank() == DIVISIONLEADER) || !(it->getControllableEntity()))
    101130                continue;
    102131            //same team?
     
    126155
    127156    }
     157    bool SectionController::setWingman(CommonController* cwingman)
     158    {
     159        WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
    128160
    129     void SectionController::action()
    130     {
    131         //this->target_ = this->sectionTarget_;       
    132         if (!myDivisionLeader_)
     161        if (!this->myWingman_)
    133162        {
    134             LeaderController* newDivisionLeader = findNewDivisionLeader();
    135             this->myDivisionLeader_ = newDivisionLeader;
    136             if (newDivisionLeader)
    137                 orxout(internal_error) << "new DivisionLeader set" << endl;
    138 
     163            this->myWingman_ = wingman;
     164            return true;
    139165        }
    140         setTargetPositionOfWingman();
    141 
    142     }
    143     /*
    144     Wingmen and Leaders attack target_, which is a member variable of their classes.
    145     Wingmen's target_ is set to sectionTarget_, which is a member variable of SectionController class, unless
    146     Wingman covers Leader's rear.
    147     Leader's target_ must always equal sectionTarget_.
    148     if section has a target, its Leader shoots at it, but doesn't follow.
    149     Every section is a part of division. Division consisting of one Section is still a division.
    150     Division's leader's target_ must always equal divisionTarget_, which is a member variable of DivisionController.
    151     Division leader ONLY can follow target_ while in formation flight.
    152     If Division doesn't have a target, Division Leader stays in place, unless it has a waypoint.
    153     Division Leader's sectionTarget_ must equal divisionTarget_,
    154     but the other section, that is not a leading section, can attack any target that is near divisonTarget_
    155 
    156     */
    157    
    158     void SectionController::tick(float dt)
    159     {
    160         if (!this->isActive())
    161             return;
    162        
    163         if (this->bHasTargetPosition_)
     166        else
    164167        {
    165             this->moveToTargetPosition();
     168            return false;
    166169        }
    167 
    168        
    169         SUPER(SectionController, tick, dt);
    170170    }
    171171   
     172    bool SectionController::hasWingman()
     173    {
     174        if (this->myWingman_)
     175            return true;
     176        else
     177            return false;
     178    }
    172179
    173180    void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
  • code/branches/AI_HS15/src/orxonox/controllers/SectionController.h

    r10729 r10731  
    4040    {
    4141        public:
     42
    4243            SectionController(Context* context);
    4344            virtual ~SectionController();
    44             virtual bool setWingman(CommonController* cwingman)
    45             {
    46                 WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
     45           
     46            virtual void tick(float dt); //<! Carrying out the targets set in action().
     47           
    4748
    48                 if (!this->myWingman_)
    49                 {
    50                     this->myWingman_ = wingman;
    51                     return true;
    52                 }
    53                 else
    54                 {
    55                     return false;
    56                 }
    57             }
    58 
    59 
    60             virtual bool hasWingman()
    61             {
    62                 if (this->myWingman_)
    63                     return true;
    64                 else
    65                     return false;
    66             }
    67 
    68             virtual void tick(float dt); //<! Carrying out the targets set in action().
    69 
     49            LeaderController* findNewDivisionLeader();
     50            virtual bool setWingman(CommonController* cwingman);
     51            virtual bool hasWingman();
     52           
    7053            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    71             LeaderController* findNewDivisionLeader();
    7254
    7355        protected:
     56
    7457            void setTargetPositionOfWingman();
    75             //A division is the biggest block of spaceships.
    76             //In division one section is leading, the other one always stays on the same position
    77             //relative to the Leader of the leading section.
    78             //In section a Wingman always stays on same position relative to the Leader.
    79             //That position is desiredRelativePosition_
     58           
    8059            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
    8160
     61        private:
    8262
    83            
    84 
    85        
    86         private:
    8763            Timer actionTimer_; //<! Regularly calls action().
    8864           
  • code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc

    r10729 r10731  
    4141        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
    4242        this->myLeader_ = 0;
     43        this->rank_ = WINGMAN;
     44
    4345    }
    4446
     
    4850    }
    4951
    50     CommonController* WingmanController::findNewLeader()
    51     {
    52 
    53         if (!this->getControllableEntity())
    54             return 0;
    55 
    56         CommonController* closestLeader = 0;
    57         float minDistance =  std::numeric_limits<float>::infinity();
    58 
    59         for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)
    60         {
    61             //0ptr?
    62             if (!it || !it->isLeader() || !(it->getControllableEntity()))
    63                 continue;
    64             //same team?
    65             if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam())
    66                 continue;
    67             //is equal to this?
    68             if (it->getControllableEntity() == this->getControllableEntity())
    69                 continue;
    70 
    71             float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
    72             if (distance < minDistance && !(it->hasWingman()))
    73             {
    74                 closestLeader = *it;
    75                 minDistance = distance;
    76             }
    77            
    78         }
    79         if (closestLeader)
    80         {
    81             if (closestLeader->setWingman(this))
    82                 return closestLeader;
    83         }
    84         return 0;
    85     }
    86    
    87     void WingmanController::action()
    88     {
    89         if (!this->myLeader_)
    90         {
    91             CommonController* newLeader = findNewLeader();
    92             this->myLeader_ = newLeader;
    93             if (newLeader)
    94                 orxout(internal_error) << "new Leader set" << endl;
    95             else
    96                 orxout(internal_error) << "0 leader" << endl;
    97 
    98         }
    99         else
    100         {
    101 
    102         }
    103     }
    104  /*//collect data for AI behaviour
    105             Vector3* meanOfEnemiesPtr = new Vector3(0.0,0.0,0.0);
    106             Vector3* meanOfAlliesPtr  = new Vector3(0.0,0.0,0.0);
    107             Vector3 meanOfAllies = *meanOfAlliesPtr;
    108             Vector3 meanOfEnemies = *meanOfEnemiesPtr;
    109 
    110 
    111             for (ObjectList<AIController>::iterator it = ObjectList<AIController>::begin(); it; ++it)
    112             {
    113 
    114                 Gametype* gt=this->getGametype();
    115                 if (!gt)
    116                 {
    117                     gt=it->getGametype();
    118                 }
    119                 if (!FormationController::sameTeam(this->getControllableEntity(), it->getControllableEntity(),gt))
    120                 {
    121                     enemies_.push_back(*it);
    122                 }
    123                 else {
    124                     allies_.push_back(*it);
    125                 }
    126             }
    127             if (enemies_.size() != 0 && allies_.size() != 0){
    128                 for (std::vector<WeakPtr<AIController> >::iterator it = enemies_.begin() ; it != enemies_.end(); ++it)
    129                     meanOfEnemies += (*it)->getControllableEntity()->getWorldPosition();
    130 
    131                 meanOfEnemies /= enemies_.size();
    132 
    133                 for (std::vector<WeakPtr<AIController> >::iterator it = allies_.begin() ; it != allies_.end(); ++it)
    134                     meanOfAllies += (*it)->getControllableEntity()->getWorldPosition();
    135 
    136                 meanOfAllies /= allies_.size();
    137 
    138                 //orxout(internal_error) << "There are " << enemies_Counter << " enemies_, mean position is " << meanOfEnemies << endl;
    139                 orxout(internal_error) << "Distance is " << (meanOfEnemies-meanOfAllies).length() << endl;
    140                 orxout(internal_error) << "mean of allies_ is " << meanOfAllies << ", with a size " << allies_.size() << endl;
    141                 orxout(internal_error) << "mean of enemies_ is " << meanOfEnemies << ", with a size " << enemies_.size() << endl;
    142             }*/
    143 
    144      
    145    
    14652    void WingmanController::tick(float dt)
    14753    {   
     
    17278        SUPER(WingmanController, tick, dt);
    17379    }
     80   
     81    void WingmanController::action()
     82    {
     83        if (!this->myLeader_)
     84        {
     85            CommonController* newLeader = findNewLeader();
     86            this->myLeader_ = newLeader;
     87            if (newLeader)
     88                orxout(internal_error) << "new Leader set" << endl;
     89            else
     90                orxout(internal_error) << "0 leader" << endl;
     91
     92        }
     93        else
     94        {
     95
     96        }
     97    }
     98     
     99   
     100   
     101
     102    CommonController* WingmanController::findNewLeader()
     103    {
     104
     105        if (!this->getControllableEntity())
     106            return 0;
     107
     108        CommonController* closestLeader = 0;
     109        float minDistance =  std::numeric_limits<float>::infinity();
     110
     111        for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)
     112        {
     113            //0ptr?
     114            if (!it ||
     115                (it->getRank() != SECTIONLEADER && it->getRank() != DIVISIONLEADER) ||
     116                !(it->getControllableEntity()))
     117                continue;
     118            //same team?
     119            if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam())
     120                continue;
     121            //is equal to this?
     122            if (it->getControllableEntity() == this->getControllableEntity())
     123                continue;
     124
     125            float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
     126            if (distance < minDistance && !(it->hasWingman()))
     127            {
     128                closestLeader = *it;
     129                minDistance = distance;
     130            }
     131           
     132        }
     133        if (closestLeader)
     134        {
     135            if (closestLeader->setWingman(this))
     136                return closestLeader;
     137        }
     138        return 0;
     139    }
    174140
    175141    void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
  • code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h

    r10729 r10731  
    4747            WingmanController(Context* context);
    4848            virtual ~WingmanController();
    49             virtual bool isLeader()
    50             {
    51                 return false;
    52             };
    53 
     49           
    5450            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5551            virtual void tick(float dt); //<! Carrying out the targets set in action().
  • code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.cc

    r10725 r10731  
    320320    }
    321321
     322
    322323    void Pawn::death()
    323324    {
     
    325326        if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_))
    326327        {
    327             // Set bAlive_ to false and wait for destroyLater() to do the destruction
     328            // Set bAlive_ to false and wait for PawnManager to do the destruction
    328329            this->bAlive_ = false;
    329             this->destroyLater();
    330330
    331331            this->setDestroyWhenPlayerLeft(false);
     
    367367            if (GameMode::isMaster())
    368368            {
    369                 this->deatheffect();
     369//                this->deathEffect();
    370370                this->goWithStyle();
    371371            }
     
    387387    {
    388388        // play death effect
    389         /*{
     389        {
    390390            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
    391391            effect->setPosition(this->getPosition());
     
    410410            effect->setSource("Orxonox/sparks");
    411411            effect->setLifetime(4.0f);
    412         }*/
    413        
    414        
    415         {
    416             ParticleSpawner* effect = new ParticleSpawner(this->getContext());
    417             effect->setPosition(this->getPosition());
    418             effect->setOrientation(this->getOrientation());
    419             effect->setDestroyAfterLife(true);
    420             effect->setSource("orxonox/explosion_flash2");
    421             effect->setLifetime(5.0f);
    422         }
    423         {
    424             ParticleSpawner* effect = new ParticleSpawner(this->getContext());
    425             effect->setPosition(this->getPosition());
    426             effect->setOrientation(this->getOrientation());
    427             effect->setDestroyAfterLife(true);
    428             effect->setSource("orxonox/explosion_flame2");
    429             effect->setLifetime(5.0f);
    430         }
    431         {
    432             ParticleSpawner* effect = new ParticleSpawner(this->getContext());
    433             effect->setPosition(this->getPosition());
    434             effect->setOrientation(this->getOrientation());
    435             effect->setDestroyAfterLife(true);
    436             effect->setSource("orxonox/explosion_shockwave2");
    437             effect->scale(20);
    438             effect->setLifetime(5.0f);
    439         }{
    440             ParticleSpawner* effect = new ParticleSpawner(this->getContext());
    441             effect->setPosition(this->getPosition());
    442             effect->setOrientation(this->getOrientation());
    443             effect->setDestroyAfterLife(true);
    444             effect->setSource("orxonox/explosion_sparks2");
    445             effect->setLifetime(5.0f);
    446         }
    447         {
    448             ParticleSpawner* effect = new ParticleSpawner(this->getContext());
    449             effect->setPosition(this->getPosition());
    450             effect->setOrientation(this->getOrientation());
    451             effect->setDestroyAfterLife(true);
    452             effect->setSource("orxonox/explosion_streak2");
    453             effect->setLifetime(5.0f);
    454         }
    455         {
    456             ParticleSpawner* effect = new ParticleSpawner(this->getContext());
    457             effect->setPosition(this->getPosition());
    458             effect->setOrientation(this->getOrientation());
    459             effect->setDestroyAfterLife(true);
    460             effect->setSource("orxonox/explosion_afterglow");
    461             effect->scale(20);
    462             effect->setLifetime(5.0f);
    463         }
    464        
    465        
     412        }
    466413        for (unsigned int i = 0; i < this->numexplosionchunks_; ++i)
    467414        {
  • code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.h

    r10437 r10731  
    3939
    4040namespace orxonox // tolua_export
    41 {
    42     /**
    43     @brief
    44         Everything in Orxonoy that has a health attribute is a Pawn. After a Pawn is spawned its health is set to
    45         its initial health. In every call of the Pawns tick function the game checks whether the pawns health is at
    46         or below zero. If it is, the pawn gets killed.
    47 
    48         Pawns can carry pickups and fire weapons. The can also have shields.
    49 
    50         Notice that every Pawn is a ControllableEntity.
    51     */
    52 
    53     // tolua_export
     41{ // tolua_export
    5442    class _OrxonoxExport Pawn // tolua_export
    5543        : public ControllableEntity, public RadarViewable, public PickupCarrier
Note: See TracChangeset for help on using the changeset viewer.