[Orxonox-commit 6058] r10717 - in code/branches/AI_HS15: data/levels src/orxonox/controllers

gania at orxonox.net gania at orxonox.net
Thu Oct 29 11:53:46 CET 2015


Author: gania
Date: 2015-10-29 11:53:45 +0100 (Thu, 29 Oct 2015)
New Revision: 10717

Removed:
   code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
   code/branches/AI_HS15/src/orxonox/controllers/SectionController.h
Modified:
   code/branches/AI_HS15/data/levels/AITest.oxw
   code/branches/AI_HS15/src/orxonox/controllers/AIController.cc
   code/branches/AI_HS15/src/orxonox/controllers/AIController.h
   code/branches/AI_HS15/src/orxonox/controllers/ArtificialController.cc
   code/branches/AI_HS15/src/orxonox/controllers/ArtificialController.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/FormationController.cc
   code/branches/AI_HS15/src/orxonox/controllers/FormationController.h
   code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc
   code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h
   code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
   code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h
Log:
Wingmen and Leaders look for their leaders

Modified: code/branches/AI_HS15/data/levels/AITest.oxw
===================================================================
--- code/branches/AI_HS15/data/levels/AITest.oxw	2015-10-28 21:56:16 UTC (rev 10716)
+++ code/branches/AI_HS15/data/levels/AITest.oxw	2015-10-29 10:53:45 UTC (rev 10717)
@@ -77,10 +77,28 @@
         <Template link=spaceshipassff />
       </templates>
       <controller>
+        <DivisionController team=1>
+        </DivisionController>
+      </controller>
+    </SpaceShip>
+    <SpaceShip position="1000, 1000, -1900 ?>" lookat="0,0,0">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
         <WingmanController team=1>
         </WingmanController>
       </controller>
     </SpaceShip>
+    <SpaceShip position="1000, 1000, -1500 ?>" lookat="0,0,0">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <LeaderController team=1>
+        </LeaderController>
+      </controller>
+    </SpaceShip>
     <SpaceShip position="1000, 1000, -1900 ?>" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
@@ -90,6 +108,7 @@
         </WingmanController>
       </controller>
     </SpaceShip>
+    <!-->    
     <!-->
     <?lua
       for i = 0, 5, 1 do

Modified: code/branches/AI_HS15/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/AIController.cc	2015-10-28 21:56:16 UTC (rev 10716)
+++ code/branches/AI_HS15/src/orxonox/controllers/AIController.cc	2015-10-29 10:53:45 UTC (rev 10717)
@@ -43,6 +43,7 @@
     AIController::AIController(Context* context) : ArtificialController(context)
     {
         RegisterObject(AIController);
+
         this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&AIController::action, this)));
     }
 
@@ -60,107 +61,58 @@
             
             if (this->formationFlight_)
             {
-                //When this is a master and was destroyed, destructor might complain that there are slaves of this, although this was removed from formation
-                //race conditions?
-                //destructor takes care of slaves anyway, so no need to worry about internal_error
 
-
                 //changed order -> searchNewMaster MUSTN'T be called in SLAVE-state (bugfix for internal-error messages at quit)
                 random = rnd(maxrand);
                 if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree()))
                        this->searchNewMaster();
 
                 // return to Master after being forced free
-                if (this->freedomCount_ == ACTION_INTERVAL)
+                if (this->freedomCount_ == 1)
                 {
                     this->state_ = SLAVE;
-                    this->freedomCount_ = 0; // ACTION_INTERVAL is 1 sec, freedomCount is a remaining time of temp. freedom
+                    this->freedomCount_ = 0;
                 }
-            } else{
-                //form a formation 
-                if (!this->forcedFree())
-                    this->searchNewMaster();
             }
+
             this->defaultBehaviour(maxrand);
 
         }
 
-
         if (this->state_ == SLAVE && this->formationMode_ == ATTACK) 
         {
             // search enemy
-            if ((!this->target_))
+            random = rnd(maxrand);
+            if (random < (botlevel_*100) && (!this->target_))
                 this->searchNewTarget();
 
-            
+            // next enemy
+            random = rnd(maxrand);
+            if (random < (botlevel_*30) && (this->target_))
+                this->searchNewTarget();
+
             // shoot
-            if ((this->target_ && !this->bShooting_))
+            random = rnd(maxrand);
+            if (!(this->passive_) && random < (botlevel_*100) && (this->target_ && !this->bShooting_))
                 this->bShooting_ = true;
 
             // stop shooting
-            if (this->bShooting_ && !this->target_)
+            random = rnd(maxrand);
+            if (random < (1-botlevel_)*50 && (this->bShooting_))
                 this->bShooting_ = false;
 
         }
 
         if (this->state_ == MASTER)
         {
-            
-            //-------------------------------------------------------
-            //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;
+            this->commandSlaves();
 
-
-            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;
-            }
-            //-------------------------------------------------------
-            
-            //Decide which formationMode to choose
-            this->setFormationMode(ATTACK);
-            this->setDesiredPositionOfSlaves();
-
-            //this->commandSlaves();
-
             if  (this->specificMasterAction_ != NONE)
                     this->specificMasterActionHold();
 
             else {
 
                  // make 180 degree turn - a specific Master Action
-                /*
                 random = rnd(1000.0f);
                 if (random < 5)
                    this->turn180Init();
@@ -170,19 +122,16 @@
                 if (random < 5)
                    this->spinInit();
 
-                */
                 /*// follow a randomly chosen human - a specific Master Action
                 random = rnd(1000.0f);
                 if (random < 1)
                    this->followRandomHumanInit();
 */
-               /*
                  // lose master status (only if less than 4 slaves in formation)
                 random = rnd(maxrand);
                 if(random < 15/(this->slaves_.size()+1) && this->slaves_.size() < 4 )
                    this->loseMasterState();
-                */
-               
+
                 // look out for outher masters if formation is small
                 random = rnd(maxrand);
                 if(this->slaves_.size() < 3 && random < 20)
@@ -192,32 +141,17 @@
 
             }
         }
-        allies_.clear();
-        enemies_.clear();
+
     }
 
     void AIController::tick(float dt)
     {
-
         if (!this->isActive())
             return;
+
         float random;
         float maxrand = 100.0f / ACTION_INTERVAL;
         ControllableEntity* controllable = this->getControllableEntity();
-        if (this->state_ == SLAVE && controllable && this->mode_ == DEFAULT)
-        {
-            
-            if (this->myMaster_ && this->myMaster_->getControllableEntity() && desiredRelativePosition_){
-                Vector3 desiredAbsolutePosition = this->myMaster_->getControllableEntity()->getWorldPosition() + this->myMaster_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_);
-                this->moveToPosition (desiredAbsolutePosition);
-                //WorldEntity* waypoint = new WorldEntity(this->getContext());
-                //waypoint->setPosition(desiredAbsolutePosition);
-            
-                //this->addWaypoint(waypoint);
-            
-            }
-          
-        }
         //DOES: Either move to the waypoint or search for a Point of interest
         if (controllable && this->mode_ == DEFAULT)// bot is ready to move to a target
         {
@@ -254,7 +188,9 @@
                         else
                         {
                             this->aimAtTarget();
-                            this->follow();  //If a bot is shooting a player, it shouldn't let him go away easily.
+                            random = rnd(maxrand);
+                            if(this->botlevel_*70 > random && !this->isCloseAtTarget(100))
+                                this->follow();  //If a bot is shooting a player, it shouldn't let him go away easily.
                         }
                     }
 
@@ -315,17 +251,75 @@
                 this->setPreviousMode();//If bot dies -> getControllableEntity == NULL -> get out of ROCKET mode
         }//END_OF ROCKET MODE
 
-
         SUPER(AIController, tick, dt);
     }
 //**********************************************NEW
     void AIController::defaultBehaviour(float maxrand)
-    {  
-        if (!this->target_)
-            this->searchNewTarget();
-        if (!(this->passive_) && (this->target_ && !this->bShooting_))
-            this->bShooting_ = true;
-            
+    {       float random;
+            // search enemy
+            random = rnd(maxrand);
+            if (random < (botlevel_* 100) && (!this->target_))
+                this->searchNewTarget();
+
+            // forget enemy
+            random = rnd(maxrand);
+            if (random < ((1-botlevel_)*20) && (this->target_))
+                this->forgetTarget();
+
+            // next enemy
+            random = rnd(maxrand);
+            if (random < (botlevel_*30) && (this->target_))
+                this->searchNewTarget();
+
+            // fly somewhere
+            random = rnd(maxrand);
+            if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
+                this->searchRandomTargetPosition();
+
+            // stop flying
+            random = rnd(maxrand);
+            if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
+                this->bHasTargetPosition_ = false;
+
+            // fly somewhere else
+            random = rnd(maxrand);
+            if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
+                this->searchRandomTargetPosition();
+
+            if (this->state_ == MASTER) // master: shoot
+            {
+                random = rnd(maxrand);
+                if (!(this->passive_) && random < (100*botlevel_) && (this->target_ && !this->bShooting_))
+                {
+                    this->bShooting_ = true;
+                    this->forceFreeSlaves();
+                }
+            }
+            else
+            {
+                // shoot
+                random = rnd(maxrand);
+                if (!(this->passive_) && random < (botlevel_*100) && (this->target_ && !this->bShooting_))
+                    this->bShooting_ = true;
+            }
+
+            // stop shooting
+            random = rnd(maxrand);
+            if (random < ((1 - botlevel_)*50) && (this->bShooting_))
+                this->bShooting_ = false;
+
+            // boost
+            random = rnd(maxrand);
+            if (random < botlevel_*50 )
+                this->boostControl();
+
+            // update Checkpoints
+            /*random = rnd(maxrand);
+            if (this->defaultWaypoint_ && random > (maxrand-10))
+                this->manageWaypoints();
+            else //if(random > maxrand-10) //CHECK USABILITY!!*/
+            if (this->waypoints_.size() == 0 )
+                this->manageWaypoints();
     }
 
-}
\ No newline at end of file
+}

Modified: code/branches/AI_HS15/src/orxonox/controllers/AIController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/AIController.h	2015-10-28 21:56:16 UTC (rev 10716)
+++ code/branches/AI_HS15/src/orxonox/controllers/AIController.h	2015-10-29 10:53:45 UTC (rev 10717)
@@ -29,14 +29,12 @@
 #ifndef _AIController_H__
 #define _AIController_H__
 
-#include "OrxonoxPrereqs.h" 
+#include "OrxonoxPrereqs.h"
 
-#include "util/Math.h"
 #include "tools/Timer.h"
 #include "tools/interfaces/Tickable.h"
 #include "ArtificialController.h"
 
-
 namespace orxonox
 {
     class _OrxonoxExport AIController : public ArtificialController, public Tickable
@@ -55,9 +53,7 @@
             static const float ACTION_INTERVAL;
 
             Timer actionTimer_; //<! Regularly calls action().
-            std::vector<WeakPtr<AIController> > enemies_, allies_;
-           
     };
 }
 
-#endif /* _AIController_H__ */
\ No newline at end of file
+#endif /* _AIController_H__ */

Modified: code/branches/AI_HS15/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/ArtificialController.cc	2015-10-28 21:56:16 UTC (rev 10716)
+++ code/branches/AI_HS15/src/orxonox/controllers/ArtificialController.cc	2015-10-29 10:53:45 UTC (rev 10717)
@@ -81,8 +81,6 @@
     */
     void ArtificialController::changedControllableEntity()
     {
-        FormationController::changedControllableEntity(); // super
-
         if (!this->getControllableEntity())
             this->removeFromFormation();
     }
@@ -290,4 +288,4 @@
             this->updatePointsOfInterest("PickupSpawner", 20.0f); // take pickup en passant if there is a default waypoint
     }
 
-}
\ No newline at end of file
+}

Modified: code/branches/AI_HS15/src/orxonox/controllers/ArtificialController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/ArtificialController.h	2015-10-28 21:56:16 UTC (rev 10716)
+++ code/branches/AI_HS15/src/orxonox/controllers/ArtificialController.h	2015-10-29 10:53:45 UTC (rev 10717)
@@ -52,7 +52,7 @@
             inline float getBotLevel() const
                 { return this->botlevel_; }
             static void setAllBotLevel(float level);
-            //WAYPOINT FUNCTIONS`
+            //WAYPOINT FUNCTIONS
             void addWaypoint(WorldEntity* waypoint);
             WorldEntity* getWaypoint(unsigned int index) const;
 
@@ -73,7 +73,6 @@
             bool isLookingAtTarget(float angle) const;
 
             float botlevel_; //<! Makes the level of a bot configurable.
-            //botLevel_ is never used in XML (so far), is it redundant?
             enum Mode {DEFAULT, ROCKET, DEFENCE, MOVING};//TODO; implement DEFENCE, MOVING modes
             Mode mode_; //TODO: replace single value with stack-like implementation: std::vector<Mode> mode_;
             void setPreviousMode();
@@ -100,4 +99,4 @@
     };
 }
 
-#endif /* _ArtificialController_H__ */
\ No newline at end of file
+#endif /* _ArtificialController_H__ */

Modified: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	2015-10-28 21:56:16 UTC (rev 10716)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	2015-10-29 10:53:45 UTC (rev 10717)
@@ -37,6 +37,7 @@
     DivisionController::DivisionController(Context* context) : LeaderController(context)
     {
         RegisterObject(DivisionController);
+        bIsDivisionLeader_ = true;
     }
 
     DivisionController::~DivisionController()
@@ -46,9 +47,17 @@
            
         }
     }
-    void DivisionController::setLeader(LeaderController* leader)
+    bool DivisionController::setFollower(LeaderController* myFollower)
     {
-        this->leader_ = leader;
+         if (!this->myFollower_)
+        {
+            this->myFollower_ = myFollower;
+            return true;
+        }
+        else
+        {
+            return false;
+        }
     }
     /*void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {

Modified: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h	2015-10-28 21:56:16 UTC (rev 10716)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h	2015-10-29 10:53:45 UTC (rev 10717)
@@ -32,6 +32,9 @@
 #include "controllers/LeaderController.h"
 
 
+#include "util/Math.h"
+#include "tools/Timer.h"
+#include "tools/interfaces/Tickable.h"
 
 namespace orxonox
 {
@@ -48,7 +51,7 @@
         	void setFormationMode(FormationMode val);
      		inline FormationMode getFormationMode() const
            		{ return this->formationMode_; }
-			virtual void setLeader(LeaderController* leader);
+			virtual bool setFollower(LeaderController* myFollower);
 
 			
 
@@ -62,47 +65,8 @@
 			Quaternion targetOrientation_;
 			FormationMode formationMode_;
 			
-			/*void setTargetPosition(const Vector3& target);
-			void searchRandomTargetPosition();
-
-			void setTargetOrientation(const Quaternion& orient);
-			void setTargetOrientation(Pawn* target);
-
-			virtual void positionReached() {}
-
-
-
-			void setTarget(Pawn* target);
-
-			void searchNewTarget();
-		    void forgetTarget();
-
-			void targetDied();
-			bool bShooting_;
-			void aimAtTarget();
-
-            bool isCloseAtTarget(float distance) const;
-            bool isLookingAtTarget(float angle) const;
-
-	        //Has nothing to do with desiredRelativePosition_,
-	        //is set by fleet controller.
-	        Vector3* desiredAbsolutePosition_;
-
-    		enum Maneuver {NONE, SPIN, TURN180};
-    		Maneuver maneuver_;
-
-    		void moveToPosition(const Vector3& target);
-		    void moveToTargetPosition();
-		    void absoluteMoveToPosition(const Vector3& target);
-		    void copyOrientation(const Quaternion& orient);
-		    void copyTargetOrientation();
-
-			void turn180Init();
-		    void spinInit();
-		    void spin();
-      		void turn180();*/
-
-      		LeaderController* leader_;
+			
+      		LeaderController* myFollower_;
 	        
 
 	    

Modified: code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc	2015-10-28 21:56:16 UTC (rev 10716)
+++ code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc	2015-10-29 10:53:45 UTC (rev 10717)
@@ -62,7 +62,7 @@
     void FleetController::tick(float dt)
     {
 
-         if (nTicks_ == 30)
+         /*if (nTicks_ == 30)
          {
             std::vector<WeakPtr<WingmanController> > wingmen;
             std::vector<WeakPtr<LeaderController> > leaders;
@@ -142,7 +142,7 @@
          {
             nTicks_ += 1;
 
-         }
+         }*/
         SUPER(FleetController, tick, dt);
 
     }

Modified: code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc	2015-10-28 21:56:16 UTC (rev 10716)
+++ code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc	2015-10-29 10:53:45 UTC (rev 10717)
@@ -104,7 +104,6 @@
                     {
                         orxout(internal_error) << this << " is still master in " << (*it) << endl;
                         it->myMaster_ = 0;
-                        it->state_ = FREE;
                     }
 
                     while (true)
@@ -277,7 +276,7 @@
 //             return;
         }
 
-        Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
+        Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
         float distance = (target - this->getControllableEntity()->getPosition()).length();
         float rotateX = clamp(coord.x * 10, -1.0f, 1.0f);
         float rotateY = clamp(coord.y * 10, -1.0f, 1.0f);
@@ -472,7 +471,7 @@
         Quaternion orient = this->getControllableEntity()->getOrientation();
         Vector3 dest = this->getControllableEntity()->getPosition();
 
-        // only 1 slave: follow
+        // 1 slave: follow
         if (this->slaves_.size() == 1)
         {
             dest += 4*orient*WorldEntity::BACK;
@@ -702,35 +701,6 @@
             }
         }
     }
-     /**
-      @brief If master, set the desired relative position of slaves (Vector3) in respect to a master for all the slaves.
-    */
-    void FormationController::setDesiredPositionOfSlaves()
-    {
-        if (this->state_ != MASTER)
-            return;
-        switch (this->formationMode_){
-            case ATTACK:
-            {
-                float i = 0;
-                for(std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
-                {
-                    (*it)->desiredRelativePosition_ = new Vector3 ((i-slaves_.size()/2)*200, 0, 0);
-                    i++;
-                }
-                break;
-            }
-            case NORMAL: 
-            {
-                break;
-            }
-            case DEFEND: 
-            {
-                break;
-            }
-        }
-       
-    }
 
     /**
         @brief Used to continue a "specific master action" for a certain time and resuming normal behaviour after.
@@ -1098,7 +1068,7 @@
         if (!this->getControllableEntity())
             return;
 
-        Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
+        Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
         float distance = (target - this->getControllableEntity()->getPosition()).length();
 
             if (this->target_ || distance > minDistance)
@@ -1116,12 +1086,4 @@
         }
     }
 
-    void FormationController::changedControllableEntity()
-    {
-        Controller::changedControllableEntity(); // super
-
-        // when changing the controllable entity, ensure that the controller does not use the new entity as target
-        if (this->target_ && this->getControllableEntity() == static_cast<ControllableEntity*>(this->target_))
-            this->forgetTarget();
-    }
-}
\ No newline at end of file
+}

Modified: code/branches/AI_HS15/src/orxonox/controllers/FormationController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FormationController.h	2015-10-28 21:56:16 UTC (rev 10716)
+++ code/branches/AI_HS15/src/orxonox/controllers/FormationController.h	2015-10-29 10:53:45 UTC (rev 10717)
@@ -69,10 +69,6 @@
       inline int getFormationSize() const
            { return this->maxFormationSize_; }
 
-      /**
-      @brief If master, set the desired position of slaves (Vector2) for all the slaves.
-      */
-      void setDesiredPositionOfSlaves();
 
       inline void setPassive(bool passive)
            { this->passive_ = passive; }
@@ -95,17 +91,14 @@
       void setFormationMode(FormationMode val);
       inline FormationMode getFormationMode() const
            { return this->formationMode_; }
-      
+
       virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
 
       FormationController* getMaster( void ) { return myMaster_; }
       FormationController* getController( void ) { return this; }
       FormationController* getSlave( void ) { return this->slaves_.back(); }
 
-      virtual void changedControllableEntity();
-
   protected:
-      Vector3* desiredRelativePosition_;
       bool formationFlight_;
       bool passive_;
       unsigned int maxFormationSize_;
@@ -184,3 +177,4 @@
 }
 #endif /* _FormationController_h__ */
 
+

Modified: code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc	2015-10-28 21:56:16 UTC (rev 10716)
+++ code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc	2015-10-29 10:53:45 UTC (rev 10717)
@@ -29,16 +29,19 @@
 #include "LeaderController.h"
 
 
-
 namespace orxonox
 {
 
     RegisterClass(LeaderController);
 
-    LeaderController::LeaderController(Context* context) : WingmanController(context)
+    static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000;
+
+    LeaderController::LeaderController(Context* context) : CommonController(context)
     {
 
         RegisterObject(LeaderController);
+        bIsDivisionLeader_ = false;
+
         //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this)));
     }
 
@@ -47,9 +50,65 @@
     {
     }
 
+    LeaderController* LeaderController::findNewDivisionLeader()
+    {
+
+        if (!this->getControllableEntity())
+            return NULL;
+
+        
+        //go through all pawns
+        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+        {
+
+            //same team?
+            if (!(this->getControllableEntity()->getTeam() != static_cast<ControllableEntity*>(*it)->getTeam()))
+                continue;
+
+            //Does it have a Controller?
+            Controller* controller = 0;
+
+            if (it->getController())
+                controller = it->getController();
+            else if (it->getXMLController())
+                controller = it->getXMLController();
+
+            if (!controller)
+                continue;
+
+            //is equal to this?
+            if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
+                continue;
+
+
+            LeaderController* newLeader = orxonox_cast<LeaderController*>(controller);
+
+            //nullptr or not DivisionController?
+            if (!newLeader || !newLeader->bIsDivisionLeader_)
+                continue;
+
+            float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length();
+
+            // is pawn in range?
+            if (distance < RADIUS_TO_SEARCH_FOR_LEADER)
+            {
+
+                if (newLeader->setFollower(this))
+                    return newLeader;
+            }
+        }
+                return NULL;
+
+    }
     void LeaderController::action()
     {
         //this->target_ = this->sectionTarget_;        
+        if (!myDivisionLeader_)
+        {
+            LeaderController* newDivisionLeader = findNewDivisionLeader();
+            myDivisionLeader_ = newDivisionLeader;
+            orxout(internal_error) << "new DivisionLeader set" << endl;
+        }
     }
     /*
     Wingmen and Leaders attack target_, which is a member variable of their classes.
@@ -93,14 +152,26 @@
 
         }*/
 
-        orxout(internal_error) << "my Wingman is " << this->wingman_ << endl;
+        orxout(internal_error) << "my Wingman is " << this->myWingman_ << endl;
         
         SUPER(LeaderController, tick, dt);
     }
-    void LeaderController::setWingman(WingmanController* wingman)
+    bool LeaderController::setWingman(WingmanController* wingman)
     {
-        this->wingman_ = wingman;
+        if (!this->myWingman_)
+        {
+            this->myWingman_ = wingman;
+            return true;
+        }
+        else
+        {
+            return false;
+        }
     }
+    bool LeaderController::isLeader()
+    {
+        return true;
+    }
 //**********************************************NEW
    /* void LeaderController::defaultBehaviour(float maxrand)
     {  

Modified: code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h	2015-10-28 21:56:16 UTC (rev 10716)
+++ code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h	2015-10-29 10:53:45 UTC (rev 10717)
@@ -29,26 +29,33 @@
 #ifndef _LeaderController_H__
 #define _LeaderController_H__
 
+#include "controllers/CommonController.h"
 #include "controllers/WingmanController.h"
 
 
+#include "util/Math.h"
+#include "tools/Timer.h"
+#include "tools/interfaces/Tickable.h"
 
-
 namespace orxonox
 {
-    class _OrxonoxExport LeaderController : public WingmanController
+    class _OrxonoxExport LeaderController : public CommonController, public Tickable
     {
         public:
            
             LeaderController(Context* context);
             virtual ~LeaderController();
-            virtual void setWingman(WingmanController* wingman);
+            virtual bool isLeader();
+
+            virtual bool setWingman(WingmanController* wingman);
             virtual void tick(float dt); //<! Carrying out the targets set in action().
 
         protected:
            
-            
+            LeaderController* findNewDivisionLeader();
 
+            bool bIsDivisionLeader_;
+
             virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
             //void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot.    
          
@@ -56,8 +63,8 @@
             
             WeakPtr<Pawn> target_;
             
-            WingmanController* wingman_;
-
+            WingmanController* myWingman_;
+            LeaderController* myDivisionLeader_;
             //Timer actionTimer_; //<! Regularly calls action().
                
     };

Deleted: code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	2015-10-28 21:56:16 UTC (rev 10716)
+++ code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	2015-10-29 10:53:45 UTC (rev 10717)
@@ -1,59 +0,0 @@
-/*
- *   ORXONOX - the hottest 3D action shooter ever to exist
- *                    > www.orxonox.net <
- *
- *
- *   License notice:
- *
- *   This program is free software; you can redistribute it and/or
- *   modify it under the terms of the GNU General Public License
- *   as published by the Free Software Foundation; either version 2
- *   of the License, or (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- *   Author:
- *      Fabian 'x3n' Landau
- *   Co-authors:
- *      Dominik Solenicki
- *
- */
-
-#include "SectionController.h"
-
-namespace orxonox
-{
-
-    RegisterClass(SectionController);
-
-    SectionController::SectionController(Context* context) : DivisionController(context)
-    {
-        RegisterObject(SectionController);
-    }
-
-    SectionController::~SectionController()
-    {
-        if (this->isInitialized())
-        {
-           
-        }
-    }
-
-    /*void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
-    {
-        SUPER(SectionController, XMLPort, xmlelement, mode);
-
-        //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
-    }*/
-
-    
-   
-
-}

Deleted: code/branches/AI_HS15/src/orxonox/controllers/SectionController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/SectionController.h	2015-10-28 21:56:16 UTC (rev 10716)
+++ code/branches/AI_HS15/src/orxonox/controllers/SectionController.h	2015-10-29 10:53:45 UTC (rev 10717)
@@ -1,65 +0,0 @@
-/*
- *   ORXONOX - the hottest 3D action shooter ever to exist
- *                    > www.orxonox.net <
- *
- *
- *   License notice:
- *
- *   This program is free software; you can redistribute it and/or
- *   modify it under the terms of the GNU General Public License
- *   as published by the Free Software Foundation; either version 2
- *   of the License, or (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- *   Author:
- *      Fabian 'x3n' Landau
- *   Co-authors:
- *      Dominik Solenicki
- *
- */
-
-#ifndef _SectionController_H__
-#define _SectionController_H__
-
-#include "controllers/DivisionController.h"
-
-
-namespace orxonox
-{
-    class _OrxonoxExport SectionController : public DivisionController
-    {
-        public:
-            SectionController(Context* context);
-            virtual ~SectionController();
-
-            //virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-
-
-
-        protected:
-      
-            //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_
-            Vector3* desiredRelativePosition_;
-            
-
-
-            LeaderController* leader_;
-            WingmanController* wingman_;
-        
-        private:
-    };
-}
-
-#endif /* _SectionController_H__ */

Modified: code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	2015-10-28 21:56:16 UTC (rev 10716)
+++ code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	2015-10-29 10:53:45 UTC (rev 10717)
@@ -28,13 +28,21 @@
 
 #include "WingmanController.h"
 
+#include "core/CoreIncludes.h"
 
+#include "core/XMLPort.h"
+#include "core/command/ConsoleCommandIncludes.h"
+
+#include "worldentities/ControllableEntity.h"
+#include "worldentities/pawns/Pawn.h"
+
 namespace orxonox
 {
 
     RegisterClass(WingmanController);
+    static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000;
 
-    WingmanController::WingmanController(Context* context) : Controller(context)
+    WingmanController::WingmanController(Context* context) : CommonController(context)
     {
         RegisterObject(WingmanController);
         //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
@@ -51,13 +59,113 @@
         XMLPortParam(WingmanController, "accuracy", setAccuracy, getAccuracy, xmlelement, mode).defaultValues(100.0f);
         XMLPortObject(WingmanController, WorldEntity, "waypoints", addWaypoint, getWaypoint,  xmlelement, mode);
     }*/
+    CommonController* WingmanController::findNewLeader()
+    {
+
+        if (!this->getControllableEntity())
+            return NULL;
+
+        
+        //go through all pawns
+        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+        {
+
+            //same team?
+            if (!(this->getControllableEntity()->getTeam() != static_cast<ControllableEntity*>(*it)->getTeam()))
+                continue;
+
+            //Does it have a Controller?
+            Controller* controller = 0;
+
+            if (it->getController())
+                controller = it->getController();
+            else if (it->getXMLController())
+                controller = it->getXMLController();
+
+            if (!controller)
+                continue;
+
+            //is equal to this?
+            if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
+                continue;
+
+
+            CommonController* newLeader = orxonox_cast<CommonController*>(controller);
+
+            //nullptr?
+            if (!newLeader || !newLeader->isLeader())
+                continue;
+
+            float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length();
+
+            // is pawn in range?
+            if (distance < RADIUS_TO_SEARCH_FOR_LEADER)
+            {
+
+                if (newLeader->setWingman(this))
+                    return newLeader;
+            }
+        }
+        return NULL;
+    }
+    bool WingmanController::isLeader()
+    {
+        return false;
+    }
     void WingmanController::action()
     {
         //this->target_ = this->sectionTarget_;
+        if (!myLeader_)
+        {
+            CommonController* newLeader = findNewLeader();
+            myLeader_ = newLeader;
+            orxout(internal_error) << "new Leader set" << endl;
+        }
     }
 
     void WingmanController::tick(float dt)
-    {/*
+    {   
+        //-------------------------------------------------------
+            /*//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;
+            }*/
+    /*
         if (!this->isActive())
             return;
         //--------------------------Stay in formation--------------------------
@@ -82,6 +190,33 @@
             }
         }*/
          //orxout(internal_error) << "I am " << this << endl;
+
+       /* void FormationController::setDesiredPositionOfSlaves()
+    {
+        if (this->state_ != MASTER)
+            return;
+        switch (this->formationMode_){
+            case ATTACK:
+            {
+                float i = 0;
+                for(std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
+                {
+                    (*it)->desiredRelativePosition_ = new Vector3 ((i-slaves_.size()/2)*200, 0, 0);
+                    i++;
+                }
+                break;
+            }
+            case NORMAL: 
+            {
+                break;
+            }
+            case DEFEND: 
+            {
+                break;
+            }
+        }
+       
+    }*/
         
         SUPER(WingmanController, tick, dt);
     }

Modified: code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h	2015-10-28 21:56:16 UTC (rev 10716)
+++ code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h	2015-10-29 10:53:45 UTC (rev 10717)
@@ -30,46 +30,28 @@
 #define _WingmanController_H__
 
 
-#include "controllers/Controller.h"
+#include "controllers/CommonController.h"
 
 
-#include "OrxonoxPrereqs.h"
-#include "core/class/Super.h"
-#include "core/CoreIncludes.h"
-#include "core/XMLPort.h"
-#include "core/command/ConsoleCommandIncludes.h"
-#include "core/command/Executor.h"
-
-#include <vector>
 #include "util/Math.h"
-#include <climits>
-
 #include "tools/Timer.h"
 #include "tools/interfaces/Tickable.h"
 
-#include "worldentities/ControllableEntity.h"
-#include "worldentities/pawns/SpaceShip.h"
-#include "worldentities/pawns/Pawn.h"
-#include "worldentities/pawns/TeamBaseMatchBase.h"
 
-#include "gametypes/TeamDeathmatch.h"
-#include "gametypes/Dynamicmatch.h"
-#include "gametypes/Mission.h"
-#include "gametypes/Gametype.h"
-
-
-
 namespace orxonox
 {
-    class _OrxonoxExport WingmanController : public Controller, public Tickable
+    class _OrxonoxExport WingmanController : public CommonController, public Tickable
     {
         public:
             WingmanController(Context* context);
             virtual ~WingmanController();
-            //virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+            virtual bool isLeader();
+          //virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
             virtual void tick(float dt); //<! Carrying out the targets set in action().
 
         protected:
+            CommonController* findNewLeader();
+
             virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
             //void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot.
 
@@ -79,7 +61,7 @@
             //const float ACTION_INTERVAL;
             
             WeakPtr<Pawn> target_;
-            
+            CommonController* myLeader_;
             //LeaderController* leader_;
 
             //Timer actionTimer_; //<! Regularly calls action().




More information about the Orxonox-commit mailing list