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

gania at orxonox.net gania at orxonox.net
Fri Oct 30 12:08:30 CET 2015


Author: gania
Date: 2015-10-30 12:08:30 +0100 (Fri, 30 Oct 2015)
New Revision: 10722

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
Log:
created destructor functions and improved findNewLeader and findNewDivisionLeader

Modified: code/branches/AI_HS15/data/levels/AITest.oxw
===================================================================
--- code/branches/AI_HS15/data/levels/AITest.oxw	2015-10-29 22:27:32 UTC (rev 10721)
+++ code/branches/AI_HS15/data/levels/AITest.oxw	2015-10-30 11:08:30 UTC (rev 10722)
@@ -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="-2000,-1000,3000" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
+    <SpawnPoint team=0 position="1000,1000,-1000" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
     <!-->
 
     <?lua
@@ -70,16 +70,17 @@
       </controller>
     </StaticEntity>
     
-    <SpaceShip position="1000, 1000, -1500 ?>" lookat="0,0,0">
+   
+    <SpaceShip position="1000, 1000, -1300 ?>" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <DivisionController team=1>
-        </DivisionController>
+        <SectionController team=1>
+        </SectionController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="1000, 1000, -1900 ?>" lookat="0,0,0">
+    <SpaceShip position="1000, 1000, -1600 ?>" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
@@ -88,7 +89,7 @@
         </WingmanController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="1000, 1000, -1500 ?>" lookat="0,0,0">
+    <SpaceShip position="1000, 1000, -1900 ?>" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
@@ -97,15 +98,8 @@
         </SectionController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="1000, 1000, -1900 ?>" lookat="0,0,0">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <WingmanController team=1>
-        </WingmanController>
-      </controller>
-    </SpaceShip>
+
+   
     <!-->
     <?lua
       for i = 0, 5, 1 do

Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	2015-10-29 22:27:32 UTC (rev 10721)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	2015-10-30 11:08:30 UTC (rev 10722)
@@ -41,6 +41,11 @@
     {
         return false;
     }
+    bool CommonController::hasWingman()
+    {
+        return true;
+    }
+
     CommonController::CommonController(Context* context) : Controller(context)
     {
 

Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	2015-10-29 22:27:32 UTC (rev 10721)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	2015-10-30 11:08:30 UTC (rev 10722)
@@ -43,7 +43,10 @@
             virtual ~CommonController();
             virtual bool isLeader();
             virtual bool setWingman(CommonController* wingman);
+            virtual bool hasWingman();
+            CommonController* myWingman_;
 
+            CommonController* myLeader_;
 
         protected:
 

Modified: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	2015-10-29 22:27:32 UTC (rev 10721)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	2015-10-30 11:08:30 UTC (rev 10722)
@@ -44,11 +44,14 @@
     {
         if (this->isInitialized())
         {
-           
+            if (this->myFollower_)
+                this->myFollower_->myDivisionLeader_ = 0;
+            if (this->myWingman_)
+                this->myWingman_->myLeader_ = 0;
         }
     } void DivisionController::tick(float dt)
     {
-                SUPER(DivisionController, tick, dt);
+        SUPER(DivisionController, tick, dt);
 
     }
     bool DivisionController::setFollower(LeaderController* myFollower)

Modified: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h	2015-10-29 22:27:32 UTC (rev 10721)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h	2015-10-30 11:08:30 UTC (rev 10722)
@@ -64,9 +64,24 @@
                     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 void tick(float dt); //<! Carrying out the targets set in action().
 
-			
 
         protected:
 
@@ -78,8 +93,7 @@
 			Quaternion targetOrientation_;
 			FormationMode formationMode_;
 			
-			CommonController* myWingman_;
-      		LeaderController* myFollower_;
+			
 	        
 
 	    

Modified: code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc	2015-10-29 22:27:32 UTC (rev 10721)
+++ code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc	2015-10-30 11:08:30 UTC (rev 10722)
@@ -40,8 +40,8 @@
         
         this->gameGoal_ = DOMINATE;
         this->goalPosition_ = NULL;
-        this->goalTarget_ = NULL;
-        this->goalProtect_ = NULL;
+      /*  this->goalTarget_ = NULL;
+        this->goalProtect_ = NULL;*/
         this->nTicks_ = 0;
         this->bTicked_ = false;
         //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&FleetController::action, this)));

Modified: code/branches/AI_HS15/src/orxonox/controllers/FleetController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FleetController.h	2015-10-29 22:27:32 UTC (rev 10721)
+++ code/branches/AI_HS15/src/orxonox/controllers/FleetController.h	2015-10-30 11:08:30 UTC (rev 10722)
@@ -47,12 +47,8 @@
 #include "tools/interfaces/Tickable.h"
 
 #include "worldentities/ControllableEntity.h"
-#include "worldentities/pawns/SpaceShip.h"
-#include "worldentities/pawns/Pawn.h"
-#include "worldentities/pawns/TeamBaseMatchBase.h"
 
 
-
 namespace orxonox
 {   
 

Modified: code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h	2015-10-29 22:27:32 UTC (rev 10721)
+++ code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h	2015-10-30 11:08:30 UTC (rev 10722)
@@ -48,12 +48,22 @@
             virtual bool isLeader()
             {
                 return true;
-            }
+            };
             bool bIsDivisionLeader_;
             virtual bool setFollower(LeaderController* myFollower)
             {
                 return false;
             };
+            virtual bool bIsDivisionLeader()
+            {
+                return bIsDivisionLeader_;
+            };
+            virtual bool hasFollower()
+            {
+                return true;
+            };
+            LeaderController* myFollower_;
+            LeaderController* myDivisionLeader_;
 
 
         protected:

Modified: code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	2015-10-29 22:27:32 UTC (rev 10721)
+++ code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	2015-10-30 11:08:30 UTC (rev 10722)
@@ -47,20 +47,27 @@
     {
         if (this->isInitialized())
         {
-           
+            if (this->myDivisionLeader_)
+                this->myDivisionLeader_->myFollower_ = 0;
+            if(this->myWingman_)
+                this->myWingman_->myLeader_ = 0;
         }
     }
-     LeaderController* SectionController::findNewDivisionLeader()
+   
+    LeaderController* SectionController::findNewDivisionLeader()
     {
 
         if (!this->getControllableEntity())
-            return NULL;
+            return 0;
 
-        
+        LeaderController* closestLeader = 0;
+        float minDistance =  std::numeric_limits<float>::infinity();
         //go through all pawns
         for (ObjectList<LeaderController>::iterator it = ObjectList<LeaderController>::begin(); it; ++it)
         {
-
+            //0ptr or not DivisionController?
+            if (!(it) || !(it)->bIsDivisionLeader_ || !(it->getControllableEntity()))
+                continue;
             //same team?
             if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()))
                 continue;
@@ -71,21 +78,29 @@
 
 
             
-            //nullptr or not DivisionController?
-            if (!(it) || !(it)->bIsDivisionLeader_)
-                continue;
+           
 
             float distance = ((it)->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
-
-            // is pawn in range?
+            
+            if (distance < minDistance && !(it->hasFollower()))
+            {
+                closestLeader = *it;
+                minDistance = distance;
+            }
+           /* // is pawn in range?
             if (distance < RADIUS_TO_SEARCH_FOR_LEADER)
             {
 
                 if ((it)->setFollower(this))
                     return (*it);
-            }
+            }*/
         }
-                return NULL;
+        if (closestLeader)
+        {
+            if (closestLeader->setFollower(this))
+                return closestLeader;
+        }
+        return 0;
 
     }
 
@@ -95,11 +110,11 @@
         if (!myDivisionLeader_)
         {
             LeaderController* newDivisionLeader = findNewDivisionLeader();
-            myDivisionLeader_ = newDivisionLeader;
-           /* if (newDivisionLeader)
+            this->myDivisionLeader_ = newDivisionLeader;
+            /*if (newDivisionLeader)
                 orxout(internal_error) << "new DivisionLeader set" << endl;
             else
-                orxout(internal_error) << "null division leader" << endl;*/
+                orxout(internal_error) << "0 division leader" << endl;*/
         }
     }
     /*

Modified: code/branches/AI_HS15/src/orxonox/controllers/SectionController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/SectionController.h	2015-10-29 22:27:32 UTC (rev 10721)
+++ code/branches/AI_HS15/src/orxonox/controllers/SectionController.h	2015-10-30 11:08:30 UTC (rev 10722)
@@ -53,13 +53,19 @@
                     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();
- 
 
-
         protected:
 
             //A division is the biggest block of spaceships.
@@ -75,8 +81,7 @@
         
         private:
             Timer actionTimer_; //<! Regularly calls action().
-            CommonController* myWingman_;
-            LeaderController* myDivisionLeader_;
+            
             Vector3* desiredRelativePosition_;
 
     };

Modified: code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	2015-10-29 22:27:32 UTC (rev 10721)
+++ code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	2015-10-30 11:08:30 UTC (rev 10722)
@@ -28,14 +28,7 @@
 
 #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
 {
 
@@ -50,27 +43,26 @@
 
     WingmanController::~WingmanController()
     {
+        if (this->myLeader_)
+            this->myLeader_->myWingman_ = 0;
     }
 
-   /* void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
-    {
-        SUPER(WingmanController, XMLPort, xmlelement, mode);
-
-        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;
+            return 0;
 
-        
-        //go through all pawns
+        CommonController* closestLeader = 0;
+        float minDistance =  std::numeric_limits<float>::infinity();
+
         for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)
         {
+            //0ptr?
+            if (!it || !it->isLeader() || !(it->getControllableEntity()))
+                continue;
             //same team?
-            if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()))
+            if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam())
                 continue;
             //is equal to this?
             if (it->getControllableEntity() == this->getControllableEntity())
@@ -78,37 +70,46 @@
 
 
 
-            //nullptr?
-            if (!it || !it->isLeader())
-                continue;
+          
 
             float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
-
-            // is pawn in range?
+            if (distance < minDistance && !(it->hasWingman()))
+            {
+                closestLeader = *it;
+                minDistance = distance;
+            }
+            /*// is pawn in range?
             if (distance < RADIUS_TO_SEARCH_FOR_LEADER)
             {
 
                 if (it->setWingman(this))
                     return *it;
-            }
+            }*/
         }
-        return NULL;
+        if (closestLeader)
+        {
+            if (closestLeader->setWingman(this))
+                return closestLeader;
+        }
+        return 0;
     }
+    
     void WingmanController::action()
     {
         //this->target_ = this->sectionTarget_;
-        if (!myLeader_)
+        if (!this->myLeader_)
         {
             CommonController* newLeader = findNewLeader();
-            myLeader_ = newLeader;
-           /* if (newLeader)
+            this->myLeader_ = newLeader;
+            if (newLeader)
                 orxout(internal_error) << "new Leader set" << endl;
             else
-                orxout(internal_error) << "null leader" << endl;
-*/
+                orxout(internal_error) << "0 leader" << endl;
+
         }
         else
         {
+
             //orxout(internal_error) << "already have a Leader" << endl;
 
         }

Modified: code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h	2015-10-29 22:27:32 UTC (rev 10721)
+++ code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h	2015-10-30 11:08:30 UTC (rev 10722)
@@ -31,6 +31,7 @@
 
 
 #include "controllers/CommonController.h"
+#include <limits>
 
 
 #include "util/Math.h"
@@ -49,6 +50,7 @@
             {
                 return false;
             };
+
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
             virtual void tick(float dt); //<! Carrying out the targets set in action().
             CommonController* findNewLeader();
@@ -64,7 +66,6 @@
             //const float ACTION_INTERVAL;
             
             WeakPtr<Pawn> target_;
-            CommonController* myLeader_;
             //LeaderController* leader_;
 
             Timer actionTimer_; //<! Regularly calls action().




More information about the Orxonox-commit mailing list