[Orxonox-commit 6073] r10731 - in code/branches/AI_HS15: data/levels src/orxonox/controllers src/orxonox/worldentities/pawns

gania at orxonox.net gania at orxonox.net
Sat Oct 31 16:07:30 CET 2015


Author: gania
Date: 2015-10-31 16:07:29 +0100 (Sat, 31 Oct 2015)
New Revision: 10731

Modified:
   code/branches/AI_HS15/data/levels/AITest.oxw
   code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
   code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
   code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
   code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h
   code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
   code/branches/AI_HS15/src/orxonox/controllers/FleetController.h
   code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h
   code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
   code/branches/AI_HS15/src/orxonox/controllers/SectionController.h
   code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
   code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h
   code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.cc
   code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.h
Log:
added a little bit of firing functionality

Modified: code/branches/AI_HS15/data/levels/AITest.oxw
===================================================================
--- code/branches/AI_HS15/data/levels/AITest.oxw	2015-10-31 12:51:45 UTC (rev 10730)
+++ code/branches/AI_HS15/data/levels/AITest.oxw	2015-10-31 15:07:29 UTC (rev 10731)
@@ -31,7 +31,7 @@
   >
 
     <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"/>
-    <SpawnPoint team=0 position="1000,1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
+    <SpawnPoint team=0 position="-1000,-1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
     <!-->
 
     <?lua

Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	2015-10-31 12:51:45 UTC (rev 10730)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	2015-10-31 15:07:29 UTC (rev 10731)
@@ -34,32 +34,68 @@
     static const float SPEED = 0.6f;
     static const float ROTATEFACTOR = 0.2f;
 
-    /*static const float SPEED_FREE = 0.8f;
-    static const float ROTATEFACTOR_FREE = 0.8f;*/
-    
-    bool CommonController::setWingman (CommonController* wingman)
+    CommonController::CommonController(Context* context) : Controller(context)
     {
-        return false;
+
+        RegisterObject(CommonController);
     }
-    bool CommonController::isLeader ()
+
+
+    CommonController::~CommonController()
     {
+    }
+
+
+
+
+    bool CommonController::setWingman (CommonController* wingman)
+    {
         return false;
     }
+   
     bool CommonController::hasWingman()
     {
         return true;
     }
 
-    CommonController::CommonController(Context* context) : Controller(context)
+
+
+
+    void CommonController::setTargetPosition(const Vector3& target)
     {
+        this->targetPosition_ = target;
+        this->bHasTargetPosition_ = true;
+    }
 
-        RegisterObject(CommonController);
+    void CommonController::setTargetOrientation(const Quaternion& orient)
+    {
+        this->targetOrientation_=orient;
+        this->bHasTargetOrientation_=true;
     }
 
+    void CommonController::setTargetOrientation(ControllableEntity* target)
+    {
+        if (target)
+            setTargetOrientation(target->getOrientation());
+    }
 
-    CommonController::~CommonController()
+    /*void CommonController::spin()
     {
+        this->moveToTargetPosition();
+        this->getControllableEntity()->rotateRoll(8.0f);
     }
+    void CommonController::turn180()
+    {
+        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
+
+        this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x);
+        this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y);
+
+        this->getControllableEntity()->moveFrontBack(SPEED);
+    }*/
+
+
+
     //copy the Roll orientation of given Quaternion.
     void CommonController::copyOrientation(const Quaternion& orient)
     {
@@ -68,16 +104,7 @@
         while(diff>math::twoPi) diff-=math::twoPi;
         while(diff<-math::twoPi) diff+=math::twoPi;
         this->getControllableEntity()->rotateRoll(-diff);
-
-
-
     }
-    void CommonController::setTargetPosition(const Vector3& target)
-    {
-        this->targetPosition_ = target;
-        this->bHasTargetPosition_ = true;
-    }
-
     void CommonController::copyTargetOrientation()
     {
         if (bHasTargetOrientation_)
@@ -85,18 +112,14 @@
             copyOrientation(targetOrientation_);
         }
     }
-    void CommonController::setTargetOrientation(const Quaternion& orient)
+
+
+
+
+    void CommonController::moveToTargetPosition()
     {
-        this->targetOrientation_=orient;
-        this->bHasTargetOrientation_=true;
+        this->moveToPosition(this->targetPosition_);
     }
-    void CommonController::setTargetOrientation(ControllableEntity* target)
-    {
-        if (target)
-            setTargetOrientation(target->getOrientation());
-    }
-
-
     void CommonController::moveToPosition(const Vector3& target)
     {
         if (!this->getControllableEntity())
@@ -145,13 +168,35 @@
             bHasTargetPosition_ = false;
             bHasTargetOrientation_ = false;
         }
+    }
+    void CommonController::doFire()
+    {
+         if (this->isLookingAtTarget(math::pi / 20.0f))
+            this->getControllableEntity()->fire(0); //ai uses lens flare if they're close enough to the target
+    }
+    bool CommonController::isLookingAtTarget(float angle) const
+    {
+        if (!this->getControllableEntity())
+            return false;
 
-      
+        return (getAngle(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->targetPosition_) < angle);
     }
-    void CommonController::moveToTargetPosition()
+
+    void CommonController::aimAtTarget()
     {
-        this->moveToPosition(this->targetPosition_);
+        if (!this->target_ || !this->getControllableEntity())
+            return;
+
+        static const float hardcoded_projectile_speed = 750;
+
+        Vector3 aimPosition = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), 
+            hardcoded_projectile_speed, this->target_->getWorldPosition(), this->target_->getVelocity());
+
+        Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
+        if (pawn)
+            pawn->setAimPosition(aimPosition);
     }
+    
  
 
 }

Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	2015-10-31 12:51:45 UTC (rev 10730)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	2015-10-31 15:07:29 UTC (rev 10731)
@@ -32,23 +32,38 @@
 
 #include "controllers/Controller.h"
 #include "worldentities/ControllableEntity.h"
+#include "worldentities/pawns/Pawn.h"
 
+
 namespace orxonox
 {
     class _OrxonoxExport CommonController : public Controller
     {
         public:
+
             static const float ACTION_INTERVAL = 1.0f;
 
-            enum FormationMode {VEE,FINGER4,DIAMOND, WALL};
+
+            CommonController(Context* context);
+            virtual ~CommonController();
+
+
+
+            enum FormationMode { VEE, FINGER4, DIAMOND, WALL };
             virtual void setFormationMode(FormationMode val)
                 { this->formationMode_ = val; }
             inline FormationMode getFormationMode() const
                 { return this->formationMode_; }
 
-            CommonController(Context* context);
-            virtual ~CommonController();
-            virtual bool isLeader();
+            enum Rank { NONE, SECTIONLEADER, DIVISIONLEADER, WINGMAN };
+            virtual void setRank(Rank val)
+                { this->rank_ = val; }
+            inline Rank getRank() const
+                { return this->rank_; }
+
+
+
+
             virtual bool setWingman(CommonController* wingman);
             virtual bool hasWingman();
 
@@ -57,28 +72,37 @@
             void setTargetOrientation(ControllableEntity* target);
             void setTargetPosition(const Vector3& target);
 
+            /*void spin();
+            void turn180();*/
+
+
         protected:
+
             void moveToPosition(const Vector3& target);
-            virtual void positionReached() {}
+            void moveToTargetPosition();
 
-       
-            void moveToTargetPosition();
+
             void copyOrientation(const Quaternion& orient);
             void copyTargetOrientation();
 
+            void doFire();
+            void aimAtTarget();
+            bool isLookingAtTarget(float angle) const;
 
             bool bHasTargetPosition_;
             Vector3 targetPosition_;
             bool bHasTargetOrientation_;
             Quaternion targetOrientation_;
 
+
             WeakPtr<ControllableEntity> target_;
             bool bShooting_;
 
+
             FormationMode formationMode_;
+            Rank rank_;
 
 
-
          
         private:
             

Modified: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	2015-10-31 12:51:45 UTC (rev 10730)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	2015-10-31 15:07:29 UTC (rev 10731)
@@ -39,22 +39,30 @@
         RegisterObject(DivisionController);
         this->setFormationMode(WALL);
 
-        bIsDivisionLeader_ = true;
         this->myFollower_ = 0;
         this->myWingman_ = 0;
         this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this)));
-       
-        /*Vector3* pos = new Vector3(500,500,-500);
-        this->setTargetPosition(*pos);*/
+        this->rank_ = DIVISIONLEADER;
 
+        Vector3* pos = new Vector3(500,500,-500);
+        this->setTargetPosition(*pos);
+
     }
 
     DivisionController::~DivisionController()
     {
       
     } 
+
+    
     void DivisionController::tick(float dt)
     {
+        if (this->target_)
+        {
+            this->aimAtTarget();
+            this->doFire();
+        }
+     
         if (this->bHasTargetPosition_)
         {
             this->moveToTargetPosition();
@@ -67,21 +75,22 @@
     {
         setTargetPositionOfFollower();
         setTargetPositionOfWingman();
-    }
 
-    bool DivisionController::setFollower(LeaderController* myFollower)
-    {
-         if (!this->myFollower_)
+        for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it)
         {
-            this->myFollower_ = myFollower;
-            return true;
+            if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam())
+            {
+                this->target_=it->getControllableEntity();
+                this->setTargetPosition(this->target_->getWorldPosition());
+                break;
+            } 
         }
-        else
-        {
-            return false;
-        }
+           
+      
     }
 
+    
+
     void DivisionController::setTargetPositionOfWingman()
     {
         if (!this->myWingman_)
@@ -148,6 +157,51 @@
         myFollower_->setTargetPosition(targetAbsolutePositionOfFollower);
        
     }
+
+
+    bool DivisionController::setWingman(CommonController* cwingman)
+    {
+
+        WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
+        if (!this->myWingman_)
+        {
+            this->myWingman_ = wingman;
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    
+    }
+    bool DivisionController::setFollower(LeaderController* myFollower)
+    {
+         if (!this->myFollower_)
+        {
+            this->myFollower_ = myFollower;
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+    bool DivisionController::hasWingman()
+    {
+        if (this->myWingman_)
+            return true;
+        else
+            return false;
+    }
+    bool DivisionController::hasFollower()
+    {
+        if (this->myFollower_)
+            return true;
+        else
+            return false;
+    }
+
+
     void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
         SUPER(DivisionController, XMLPort, xmlelement, mode);

Modified: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h	2015-10-31 12:51:45 UTC (rev 10730)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h	2015-10-31 15:07:29 UTC (rev 10731)
@@ -41,53 +41,29 @@
     class _OrxonoxExport DivisionController : public LeaderController, public Tickable
       {
         public:
+
         	DivisionController(Context* context);
         	virtual ~DivisionController();
 
-        	virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+            virtual void tick(float dt); //<! Carrying out the targets set in action().
 
-        	//Using british military aircraft formations
-        	
      		
 			virtual bool setFollower(LeaderController* myFollower);
-			virtual bool setWingman(CommonController* cwingman)
-            {
-                WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
-                if (!this->myWingman_)
-                {
-                    this->myWingman_ = wingman;
-                    return true;
-                }
-                else
-                {
-                    return false;
-                }
-            };
-            virtual bool hasWingman()
-            {
-                if (this->myWingman_)
-                    return true;
-                else
-                    return false;
-            }
-            virtual bool hasFollower()
-            {
-                if (this->myFollower_)
-                    return true;
-                else
-                    return false;
-            };
-            
+			virtual bool setWingman(CommonController* cwingman);
+            virtual bool hasWingman();
+            virtual bool hasFollower();
 
-            virtual void tick(float dt); //<! Carrying out the targets set in action().
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);          
 
-
         protected:
+            
             void setTargetPositionOfWingman();
             void setTargetPositionOfFollower();
+
             virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
 	    
         private:
+
             Timer actionTimer_; //<! Regularly calls action().
 
     };

Modified: code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc	2015-10-31 12:51:45 UTC (rev 10730)
+++ code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc	2015-10-31 15:07:29 UTC (rev 10731)
@@ -42,8 +42,7 @@
         this->goalPosition_ = NULL;
       /*  this->goalTarget_ = NULL;
         this->goalProtect_ = NULL;*/
-        this->nTicks_ = 0;
-        this->bTicked_ = false;
+        
         //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&FleetController::action, this)));
     }
 
@@ -62,87 +61,6 @@
     void FleetController::tick(float dt)
     {
 
-         /*if (nTicks_ == 30)
-         {
-            std::vector<WeakPtr<WingmanController> > wingmen;
-            std::vector<WeakPtr<LeaderController> > leaders;
-
-            //--------------------------Put all WingmanController's in a vector--------------------------
-            for (ObjectList<WingmanController>::iterator it = ObjectList<WingmanController>::begin(); it; ++it)
-            {
-
-               
-                if ((*it)->getTeam() == this->getTeam())
-                {
-                    orxout(internal_error) << "ANOTHER SUCKER" << endl;
-                    wingmen.push_back(*it);
-                } 
-                
-            }
-            //--------------------------Substitute half of WingmanController's with LeaderController--------------------------
-
-            bool nowLeader = true;
-            LeaderController* leader;
-
-            for (std::vector<WeakPtr<WingmanController> >::iterator it = wingmen.begin() ; it != wingmen.end(); ++it)
-            {
-                if (nowLeader)
-                {
-                    leader = new LeaderController(this->getContext());
-                    leader->setTeam(this->team_);
-
-                    (*it)->getControllableEntity()->setController(leader);
-                    leaders.push_back(leader);
-                    nowLeader = !nowLeader;
-                    orxout(internal_error) << "NEW SUCKER" << endl;
-
-                }
-                else
-                {
-                    if (leader)
-                    {
-                        leader->setWingman(*it);
-                        nowLeader = !nowLeader;
-                        orxout(internal_error) << "I OWN THE SUCKER" << endl;
-
-                    }
-                }
-            }
-
-            //--------------------------Substitute half of LeaderController's with DivisionController--------------------------
-            bool nowDivision = true;
-            DivisionController* division;
-
-            for (std::vector<WeakPtr<LeaderController> >::iterator it = leaders.begin() ; it != leaders.end(); ++it)
-            {
-                if (nowDivision)
-                {
-                    division = new DivisionController(this->getContext());
-                    division->setTeam(this->team_);
-
-                    (*it)->getControllableEntity()->setController(division);
-
-                    divisions_.push_back(division);
-
-                    nowDivision = !nowDivision;
-                }
-                else
-                {
-                    if (division)
-                    {
-                        division->setLeader(*it);
-                        nowDivision = !nowDivision;
-                    }
-                }
-            }
-            bTicked_ = true;
-            nTicks_ += 1;
-         }
-         else if (!bTicked_)
-         {
-            nTicks_ += 1;
-
-         }*/
         SUPER(FleetController, tick, dt);
 
     }

Modified: code/branches/AI_HS15/src/orxonox/controllers/FleetController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FleetController.h	2015-10-31 12:51:45 UTC (rev 10730)
+++ code/branches/AI_HS15/src/orxonox/controllers/FleetController.h	2015-10-31 15:07:29 UTC (rev 10731)
@@ -82,9 +82,7 @@
 
             virtual void action();
         private:
-            int nTicks_;
-            bool bTicked_;
-
+        
             std::vector<WeakPtr<DivisionController> > divisions_;
             //Timer actionTimer_; //<! Regularly calls action().
 

Modified: code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h	2015-10-31 12:51:45 UTC (rev 10730)
+++ code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h	2015-10-31 15:07:29 UTC (rev 10731)
@@ -44,31 +44,24 @@
 
             LeaderController(Context* context);
             virtual ~LeaderController();
-            virtual bool isLeader()
-            {
-                return true;
-            };
-            bool bIsDivisionLeader_;
+           
             virtual bool setFollower(LeaderController* myFollower)
-            {
-                return false;
-            };
-            virtual bool bIsDivisionLeader()
-            {
-                return bIsDivisionLeader_;
-            };
+                { return false; }
+           
             virtual bool hasFollower()
-            {
-                return true;
-            };
-            WeakPtr<WingmanController> myWingman_;
+                { return true; }
+            
 
-            WeakPtr<LeaderController> myFollower_;
-            WeakPtr<LeaderController> myDivisionLeader_;
 
 
         protected:
          
+            WeakPtr<WingmanController> myWingman_;
+
+            WeakPtr<LeaderController> myFollower_;
+            WeakPtr<LeaderController> myDivisionLeader_;
+
+            
         private:
             
     };

Modified: code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	2015-10-31 12:51:45 UTC (rev 10730)
+++ code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	2015-10-31 15:07:29 UTC (rev 10731)
@@ -38,10 +38,10 @@
         RegisterObject(SectionController);
         this->setFormationMode(WALL);
 
-        bIsDivisionLeader_ = false;
         this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&SectionController::action, this)));
         this->myWingman_ = 0;
         this->myDivisionLeader_ = 0;
+        this->rank_ = SECTIONLEADER;
 
         orxout(internal_error) << this << "Was created" << endl;
 
@@ -51,6 +51,36 @@
     {
        
     }
+
+    void SectionController::tick(float dt)
+    {
+        if (!this->isActive())
+            return;
+        
+        if (this->bHasTargetPosition_)
+        {
+            this->moveToTargetPosition();
+        }
+
+        
+        SUPER(SectionController, tick, dt);
+    }
+
+    void SectionController::action()
+    {
+        //this->target_ = this->sectionTarget_;        
+        if (!myDivisionLeader_)
+        {
+            LeaderController* newDivisionLeader = findNewDivisionLeader();
+            this->myDivisionLeader_ = newDivisionLeader;
+            if (newDivisionLeader)
+                orxout(internal_error) << "new DivisionLeader set" << endl;
+
+        }
+        setTargetPositionOfWingman();
+
+    }
+    
     void SectionController::setTargetPositionOfWingman()
     {
         if (!this->myWingman_)
@@ -84,7 +114,6 @@
         myWingman_->setTargetPosition(targetAbsolutePositionOfWingman);
        
     }
-
     LeaderController* SectionController::findNewDivisionLeader()
     {
 
@@ -97,7 +126,7 @@
         for (ObjectList<LeaderController>::iterator it = ObjectList<LeaderController>::begin(); it; ++it)
         {
             //0ptr or not DivisionController?
-            if (!(it) || !(it)->bIsDivisionLeader_ || !(it->getControllableEntity()))
+            if (!(it) || !((it)->getRank() == DIVISIONLEADER) || !(it->getControllableEntity()))
                 continue;
             //same team?
             if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()))
@@ -125,50 +154,28 @@
         return 0;
 
     }
+    bool SectionController::setWingman(CommonController* cwingman)
+    {
+        WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
 
-    void SectionController::action()
-    {
-        //this->target_ = this->sectionTarget_;        
-        if (!myDivisionLeader_)
+        if (!this->myWingman_)
         {
-            LeaderController* newDivisionLeader = findNewDivisionLeader();
-            this->myDivisionLeader_ = newDivisionLeader;
-            if (newDivisionLeader)
-                orxout(internal_error) << "new DivisionLeader set" << endl;
-
+            this->myWingman_ = wingman;
+            return true;
         }
-        setTargetPositionOfWingman();
-
+        else
+        {
+            return false;
+        }
     }
-    /*
-    Wingmen and Leaders attack target_, which is a member variable of their classes.
-    Wingmen's target_ is set to sectionTarget_, which is a member variable of SectionController class, unless
-    Wingman covers Leader's rear.
-    Leader's target_ must always equal sectionTarget_.
-    if section has a target, its Leader shoots at it, but doesn't follow.
-    Every section is a part of division. Division consisting of one Section is still a division.
-    Division's leader's target_ must always equal divisionTarget_, which is a member variable of DivisionController.
-    Division leader ONLY can follow target_ while in formation flight.
-    If Division doesn't have a target, Division Leader stays in place, unless it has a waypoint.
-    Division Leader's sectionTarget_ must equal divisionTarget_,
-    but the other section, that is not a leading section, can attack any target that is near divisonTarget_
-
-    */
     
-    void SectionController::tick(float dt)
+    bool SectionController::hasWingman()
     {
-        if (!this->isActive())
-            return;
-        
-        if (this->bHasTargetPosition_)
-        {
-            this->moveToTargetPosition();
-        }
-
-        
-        SUPER(SectionController, tick, dt);
+        if (this->myWingman_)
+            return true;
+        else
+            return false;
     }
-    
 
     void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {

Modified: code/branches/AI_HS15/src/orxonox/controllers/SectionController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/SectionController.h	2015-10-31 12:51:45 UTC (rev 10730)
+++ code/branches/AI_HS15/src/orxonox/controllers/SectionController.h	2015-10-31 15:07:29 UTC (rev 10731)
@@ -39,51 +39,27 @@
     class _OrxonoxExport SectionController : public LeaderController, public Tickable
     {
         public:
+
             SectionController(Context* context);
             virtual ~SectionController();
-            virtual bool setWingman(CommonController* cwingman)
-            {
-                WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
-
-                if (!this->myWingman_)
-                {
-                    this->myWingman_ = wingman;
-                    return true;
-                }
-                else
-                {
-                    return false;
-                }
-            }
-
-
-            virtual bool hasWingman()
-            {
-                if (this->myWingman_)
-                    return true;
-                else
-                    return false;
-            }
-
+            
             virtual void tick(float dt); //<! Carrying out the targets set in action().
+            
 
-            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
             LeaderController* findNewDivisionLeader();
+            virtual bool setWingman(CommonController* cwingman);
+            virtual bool hasWingman();
+            
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
 
         protected:
+
             void setTargetPositionOfWingman();
-            //A division is the biggest block of spaceships.
-            //In division one section is leading, the other one always stays on the same position
-            //relative to the Leader of the leading section.
-            //In section a Wingman always stays on same position relative to the Leader.
-            //That position is desiredRelativePosition_
+            
             virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
 
-
-           
-
-        
         private:
+
             Timer actionTimer_; //<! Regularly calls action().
             
 

Modified: code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	2015-10-31 12:51:45 UTC (rev 10730)
+++ code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	2015-10-31 15:07:29 UTC (rev 10731)
@@ -40,6 +40,8 @@
         RegisterObject(WingmanController);
         this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
         this->myLeader_ = 0;
+        this->rank_ = WINGMAN;
+
     }
 
     WingmanController::~WingmanController()
@@ -47,6 +49,56 @@
 
     }
 
+    void WingmanController::tick(float dt)
+    {   
+        //-------------------------------------------------------
+           
+        
+        if (!this->isActive())
+            return;
+        //--------------------------Stay in formation--------------------------
+        if (this->bHasTargetPosition_)
+        {
+            //targetPosition_ and targetOrientation_ are set by the Leader in its action()
+            this->moveToTargetPosition();
+        } 
+        
+        //--------------------------Attack same target as the Leader--------------------------
+
+        /*if (this->target_)
+        {
+            this->aimAtTarget();
+            this->doFire();
+        }
+        */
+        
+        //orxout(internal_error) << "I am " << this << endl;
+
+        
+        SUPER(WingmanController, tick, dt);
+    }
+    
+    void WingmanController::action()
+    {
+        if (!this->myLeader_)
+        {
+            CommonController* newLeader = findNewLeader();
+            this->myLeader_ = newLeader;
+            if (newLeader)
+                orxout(internal_error) << "new Leader set" << endl;
+            else
+                orxout(internal_error) << "0 leader" << endl;
+
+        }
+        else
+        {
+
+        }
+    }
+     
+   
+    
+
     CommonController* WingmanController::findNewLeader()
     {
 
@@ -59,7 +111,9 @@
         for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)
         {
             //0ptr?
-            if (!it || !it->isLeader() || !(it->getControllableEntity()))
+            if (!it || 
+                (it->getRank() != SECTIONLEADER && it->getRank() != DIVISIONLEADER) || 
+                !(it->getControllableEntity()))
                 continue;
             //same team?
             if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam())
@@ -83,95 +137,7 @@
         }
         return 0;
     }
-    
-    void WingmanController::action()
-    {
-        if (!this->myLeader_)
-        {
-            CommonController* newLeader = findNewLeader();
-            this->myLeader_ = newLeader;
-            if (newLeader)
-                orxout(internal_error) << "new Leader set" << endl;
-            else
-                orxout(internal_error) << "0 leader" << endl;
 
-        }
-        else
-        {
-
-        }
-    }
- /*//collect data for AI behaviour
-            Vector3* meanOfEnemiesPtr = new Vector3(0.0,0.0,0.0);
-            Vector3* meanOfAlliesPtr  = new Vector3(0.0,0.0,0.0);
-            Vector3 meanOfAllies = *meanOfAlliesPtr;
-            Vector3 meanOfEnemies = *meanOfEnemiesPtr;
-
-
-            for (ObjectList<AIController>::iterator it = ObjectList<AIController>::begin(); it; ++it)
-            {
-
-                Gametype* gt=this->getGametype();
-                if (!gt)
-                {
-                    gt=it->getGametype();
-                }
-                if (!FormationController::sameTeam(this->getControllableEntity(), it->getControllableEntity(),gt))
-                {
-                    enemies_.push_back(*it);
-                } 
-                else {
-                    allies_.push_back(*it);
-                } 
-            }
-            if (enemies_.size() != 0 && allies_.size() != 0){
-                for (std::vector<WeakPtr<AIController> >::iterator it = enemies_.begin() ; it != enemies_.end(); ++it)
-                    meanOfEnemies += (*it)->getControllableEntity()->getWorldPosition();
-
-                meanOfEnemies /= enemies_.size();
-
-                for (std::vector<WeakPtr<AIController> >::iterator it = allies_.begin() ; it != allies_.end(); ++it)
-                    meanOfAllies += (*it)->getControllableEntity()->getWorldPosition();
-
-                meanOfAllies /= allies_.size();
-
-                //orxout(internal_error) << "There are " << enemies_Counter << " enemies_, mean position is " << meanOfEnemies << endl;
-                orxout(internal_error) << "Distance is " << (meanOfEnemies-meanOfAllies).length() << endl;
-                orxout(internal_error) << "mean of allies_ is " << meanOfAllies << ", with a size " << allies_.size() << endl;
-                orxout(internal_error) << "mean of enemies_ is " << meanOfEnemies << ", with a size " << enemies_.size() << endl;
-            }*/
-
-     
-   
-    void WingmanController::tick(float dt)
-    {   
-        //-------------------------------------------------------
-           
-        
-        if (!this->isActive())
-            return;
-        //--------------------------Stay in formation--------------------------
-        if (this->bHasTargetPosition_)
-        {
-            //targetPosition_ and targetOrientation_ are set by the Leader in its action()
-            this->moveToTargetPosition();
-        } 
-        
-        //--------------------------Attack same target as the Leader--------------------------
-
-        /*if (this->target_)
-        {
-            this->aimAtTarget();
-            this->doFire();
-        }
-        */
-        
-        //orxout(internal_error) << "I am " << this << endl;
-
-        
-        SUPER(WingmanController, tick, dt);
-    }
-
     void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
         SUPER(WingmanController, XMLPort, xmlelement, mode);

Modified: code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h	2015-10-31 12:51:45 UTC (rev 10730)
+++ code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h	2015-10-31 15:07:29 UTC (rev 10731)
@@ -46,11 +46,7 @@
         public:
             WingmanController(Context* context);
             virtual ~WingmanController();
-            virtual bool isLeader()
-            {
-                return false;
-            };
-
+           
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
             virtual void tick(float dt); //<! Carrying out the targets set in action().
             CommonController* findNewLeader();

Modified: code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.cc	2015-10-31 12:51:45 UTC (rev 10730)
+++ code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.cc	2015-10-31 15:07:29 UTC (rev 10731)
@@ -319,14 +319,14 @@
         }
     }
 
+
     void Pawn::death()
     {
         this->setHealth(1);
         if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_))
         {
-            // Set bAlive_ to false and wait for destroyLater() to do the destruction
+            // Set bAlive_ to false and wait for PawnManager to do the destruction
             this->bAlive_ = false;
-            this->destroyLater();
 
             this->setDestroyWhenPlayerLeft(false);
 
@@ -366,7 +366,7 @@
             }
             if (GameMode::isMaster())
             {
-                this->deatheffect();
+//                this->deathEffect();
                 this->goWithStyle();
             }
         }
@@ -386,7 +386,7 @@
     void Pawn::deatheffect()
     {
         // play death effect
-        /*{
+        {
             ParticleSpawner* effect = new ParticleSpawner(this->getContext());
             effect->setPosition(this->getPosition());
             effect->setOrientation(this->getOrientation());
@@ -409,60 +409,7 @@
             effect->setDestroyAfterLife(true);
             effect->setSource("Orxonox/sparks");
             effect->setLifetime(4.0f);
-        }*/
-        
-        
-        {
-            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
-            effect->setPosition(this->getPosition());
-            effect->setOrientation(this->getOrientation());
-            effect->setDestroyAfterLife(true);
-            effect->setSource("orxonox/explosion_flash2");
-            effect->setLifetime(5.0f);
         }
-        {
-            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
-            effect->setPosition(this->getPosition());
-            effect->setOrientation(this->getOrientation());
-            effect->setDestroyAfterLife(true);
-            effect->setSource("orxonox/explosion_flame2");
-            effect->setLifetime(5.0f);
-        }
-        {
-            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
-            effect->setPosition(this->getPosition());
-            effect->setOrientation(this->getOrientation());
-            effect->setDestroyAfterLife(true);
-            effect->setSource("orxonox/explosion_shockwave2");
-            effect->scale(20);
-            effect->setLifetime(5.0f);
-        }{
-            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
-            effect->setPosition(this->getPosition());
-            effect->setOrientation(this->getOrientation());
-            effect->setDestroyAfterLife(true);
-            effect->setSource("orxonox/explosion_sparks2");
-            effect->setLifetime(5.0f);
-        }
-        {
-            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
-            effect->setPosition(this->getPosition());
-            effect->setOrientation(this->getOrientation());
-            effect->setDestroyAfterLife(true);
-            effect->setSource("orxonox/explosion_streak2");
-            effect->setLifetime(5.0f);
-        }
-        {
-            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
-            effect->setPosition(this->getPosition());
-            effect->setOrientation(this->getOrientation());
-            effect->setDestroyAfterLife(true);
-            effect->setSource("orxonox/explosion_afterglow");
-            effect->scale(20);
-            effect->setLifetime(5.0f);
-        }
-        
-        
         for (unsigned int i = 0; i < this->numexplosionchunks_; ++i)
         {
             ExplosionChunk* chunk = new ExplosionChunk(this->getContext());

Modified: code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.h	2015-10-31 12:51:45 UTC (rev 10730)
+++ code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.h	2015-10-31 15:07:29 UTC (rev 10731)
@@ -38,19 +38,7 @@
 
 
 namespace orxonox // tolua_export
-{
-    /**
-    @brief
-        Everything in Orxonoy that has a health attribute is a Pawn. After a Pawn is spawned its health is set to
-        its initial health. In every call of the Pawns tick function the game checks whether the pawns health is at
-        or below zero. If it is, the pawn gets killed.
-
-        Pawns can carry pickups and fire weapons. The can also have shields.
-
-        Notice that every Pawn is a ControllableEntity.
-    */
-
-    // tolua_export
+{ // tolua_export
     class _OrxonoxExport Pawn // tolua_export
         : public ControllableEntity, public RadarViewable, public PickupCarrier
     { // tolua_export




More information about the Orxonox-commit mailing list