[Orxonox-commit 6220] r10877 - in code/branches/campaignHS15: data/levels src/orxonox/controllers

gania at orxonox.net gania at orxonox.net
Fri Nov 27 16:42:14 CET 2015


Author: gania
Date: 2015-11-27 16:42:14 +0100 (Fri, 27 Nov 2015)
New Revision: 10877

Modified:
   code/branches/campaignHS15/data/levels/AITest.oxw
   code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
   code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
   code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
   code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
   code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
   code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h
   code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc
   code/branches/campaignHS15/src/orxonox/controllers/FightingController.h
   code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
   code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h
   code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h
   code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
   code/branches/campaignHS15/src/orxonox/controllers/SectionController.h
   code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
   code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h
Log:
CommonController now has static methods only. Replace with a namespace?

Modified: code/branches/campaignHS15/data/levels/AITest.oxw
===================================================================
--- code/branches/campaignHS15/data/levels/AITest.oxw	2015-11-27 15:19:06 UTC (rev 10876)
+++ code/branches/campaignHS15/data/levels/AITest.oxw	2015-11-27 15:42:14 UTC (rev 10877)
@@ -260,10 +260,19 @@
     </SpaceShip> 
     -->
 <!-- HERE ENDS DEMO FOR FORMATIONS -->
-    
-    
+    <!-- 
+    <SpaceShip position="2000, 2000, 2000" lookat="0,0,0" team=1 name="ss2">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <DivisionController team=1 formationMode="finger4">
+          
+        </DivisionController>
+      </controller>
+    </SpaceShip>
    
-
+ -->
   </Scene>
 </Level>
 

Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc	2015-11-27 15:19:06 UTC (rev 10876)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc	2015-11-27 15:42:14 UTC (rev 10877)
@@ -30,6 +30,7 @@
 
 #include "core/XMLPort.h"
 #include <algorithm>
+#include "worldentities/Actionpoint.h"
 
 
 namespace orxonox
@@ -37,18 +38,17 @@
 
     RegisterClass(ActionpointController);
 
-    //CommonController contains all common functionality of AI Controllers
     ActionpointController::ActionpointController(Context* context) : FightingController(context)
     {
-              this->bInLoop_ = false;
+        this->bInLoop_ = false;
         this->bLoop_ = false;
         this->bEndLoop_ = false;
         this->parsedActionpoints_.clear();
         this->bTakenOver_ = false;
         this->action_ = Action::NONE;
         this->squaredaccuracy_ = 2500;
+        this->bFirstTick_ = true;
 
-
         RegisterObject(ActionpointController);
 
     }
@@ -558,15 +558,15 @@
     {
         if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
         {
-            if ( (this->target_ && this->distance (this->getControllableEntity(), this->target_) > this->attackRange_) 
+            if ( (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_) 
                 || !this->target_ )
             {
                 Pawn* newTarget = this->closestTarget();
                 if ( newTarget && 
-                    this->distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))
+                    CommonController::distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))
                         <= this->attackRange_ )
                 {
-                    Point p = { Action::FIGHT, this->getName(newTarget), Vector3::ZERO, false };
+                    Point p = { Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO, false };
                     this->parsedActionpoints_.push_back(p);
                     this->executeActionpoint();
                 }

Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h	2015-11-27 15:19:06 UTC (rev 10876)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h	2015-11-27 15:42:14 UTC (rev 10877)
@@ -30,8 +30,9 @@
 #define _ActionpointController_H__
 
 #include "controllers/FightingController.h"
+#include "tools/Timer.h"
+#include "tools/interfaces/Tickable.h"
 
-
 namespace orxonox
 {
     namespace Action
@@ -50,7 +51,7 @@
         bool inLoop;
     } ;
 
-    class _OrxonoxExport ActionpointController : public FightingController
+    class _OrxonoxExport ActionpointController : public FightingController, public Tickable
     {
         public:
             //----[language demanded functions]----            
@@ -73,9 +74,15 @@
             void setAction (Action::Value action, const Vector3& target);
             void setAction (Action::Value action, const Vector3& target,  const Quaternion& orient );
 
-           
+            virtual bool setWingman(ActionpointController* wingman)
+                { return false; }
+            virtual bool hasWingman()
+                { return true; }
+            virtual bool setFollower(ActionpointController* myFollower)
+                { return false; }
+            virtual bool hasFollower()
+                { return true; }
 
-
         protected:
             void startAttackingEnemiesThatAreClose();
 
@@ -105,7 +112,8 @@
                 void fillLoopReversed();
                 void moveBackToTop();
             //----[Actionpoint methods]----          
-            
+                bool bFirstTick_; 
+
         private:
             
     };

Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	2015-11-27 15:19:06 UTC (rev 10876)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	2015-11-27 15:42:14 UTC (rev 10877)
@@ -26,56 +26,29 @@
  *
  */
 #include "controllers/CommonController.h"
-#include "core/XMLPort.h"
 
 //stuff for sameTeam function
-#include "worldentities/pawns/TeamBaseMatchBase.h"
 #include "gametypes/TeamDeathmatch.h"
-#include "gametypes/Dynamicmatch.h"
-#include "gametypes/Mission.h"
 #include "gametypes/Gametype.h"
-#include "controllers/WaypointPatrolController.h"
-#include "controllers/NewHumanController.h"
 #include "controllers/DroneController.h"
-#include "util/Math.h"
+#include "gametypes/Dynamicmatch.h"
 
+#include "worldentities/pawns/TeamBaseMatchBase.h"
+
 namespace orxonox
 {
 
     RegisterClass( CommonController );
-    const float SPEED = 0.9f/0.02f;
-    const float ROTATEFACTOR = 1.0f/0.02f;
 
-  
     CommonController::CommonController( Context* context ): Controller( context )
     {
-        this->bFirstTick_ = true;
-       
         RegisterObject( CommonController );
-
     }
     CommonController::~CommonController() 
     {
         
     }
-    void CommonController::tick(float dt)
-    {
-        
-        SUPER(CommonController, tick, dt);
-    }
 
-      
-    void CommonController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
-    {
-        SUPER( CommonController, XMLPort, xmlelement, mode );
-    }
- 
-    //"Virtual" methods
-    bool CommonController::setWingman ( CommonController* wingman )
-    { return false; }
-    bool CommonController::hasWingman() 
-    { return true; }
-
     float CommonController::randomInRange( float a, float b )
     {
         float random = rnd( 1.0f );

Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	2015-11-27 15:19:06 UTC (rev 10876)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	2015-11-27 15:42:14 UTC (rev 10877)
@@ -31,47 +31,30 @@
 
 
 #include "controllers/Controller.h"
+#include <limits>
+
 #include "worldentities/ControllableEntity.h"
 #include "worldentities/pawns/Pawn.h"
 
-#include "tools/Timer.h"
-#include "tools/interfaces/Tickable.h"
-#include <limits>
-#include "worldentities/Actionpoint.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport CommonController : public Controller, public Tickable
+    class _OrxonoxExport CommonController : public Controller
     {
 
         public:
-            static const float hardcoded_projectile_speed = 750;
             static const float ACTION_INTERVAL = 1.0f;
 
+            static const float hardcoded_projectile_speed = 750;
+
             CommonController(Context* context);
             virtual ~CommonController();
 
-            virtual void tick(float dt); 
-
-            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-                
-
-
-            virtual bool setWingman(CommonController* wingman);
-            virtual bool hasWingman();        
-
-
-            float randomInRange(float a, float b);
+            static float randomInRange(float a, float b);
             static float distance(ControllableEntity* entity1, ControllableEntity* entity2);
             static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt);
             static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ;
-            static std::string getName( Pawn* entity ) ;
-
-        protected:
-           
-            bool bFirstTick_; 
-            
-           
+            static std::string getName( Pawn* entity ) ;           
     };
 }
 

Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-11-27 15:19:06 UTC (rev 10876)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-11-27 15:42:14 UTC (rev 10877)
@@ -48,21 +48,6 @@
 
     DivisionController::~DivisionController()
     {
-        // if (!(this->parsedActionpoints_.empty() && this->loopActionpoints_.empty()))
-        // {
-        //     if (this->myFollower_)
-        //     {
-        //         this->myFollower_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);
-        //         if (this->myWingman_)
-        //         {
-        //             this->myWingman_->setAction(Action::FIGHTALL);
-        //         }
-        //     }
-        //     else if (this->myWingman_)
-        //     {
-        //         this->myWingman_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);
-        //     }    
-        // }
         for (size_t i = 0; i < this->actionpoints_.size(); ++i)
         {
             if(this->actionpoints_[i])
@@ -111,13 +96,13 @@
         ActionpointController::stayNearProtect();
     }
     
-    bool DivisionController::setWingman(CommonController* cwingman)
+    bool DivisionController::setWingman(ActionpointController* wingman)
     {
 
-        WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
+        WingmanController* newWingman = orxonox_cast<WingmanController*>(wingman);
         if (!this->myWingman_)
         {
-            this->myWingman_ = wingman;
+            this->myWingman_ = newWingman;
             return true;
         }
         else
@@ -125,11 +110,12 @@
             return false;
         }
     }
-    bool DivisionController::setFollower(LeaderController* myFollower)
+    bool DivisionController::setFollower(ActionpointController* myFollower)
     {
-         if (!this->myFollower_)
+        LeaderController* newFollower = orxonox_cast<LeaderController*> (myFollower);
+        if (!this->myFollower_)
         {
-            this->myFollower_ = myFollower;
+            this->myFollower_ = newFollower;
             return true;
         }
         else

Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h	2015-11-27 15:19:06 UTC (rev 10876)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h	2015-11-27 15:42:14 UTC (rev 10877)
@@ -51,8 +51,8 @@
             //----[orxonox demanded functions]----
 
             //----[own functions]----
-                virtual bool setFollower(LeaderController* myFollower);
-                virtual bool setWingman(CommonController* cwingman);
+                virtual bool setFollower(ActionpointController* myFollower);
+                virtual bool setWingman(ActionpointController* wingman);
                 virtual bool hasWingman();
                 virtual bool hasFollower();
                 

Modified: code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc	2015-11-27 15:19:06 UTC (rev 10876)
+++ code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc	2015-11-27 15:42:14 UTC (rev 10877)
@@ -125,7 +125,7 @@
         float diffLength = diffVector.length();
         Vector3 diffUnit = diffVector/diffLength;
 
-        bool bTargetIsLookingAtThis = this->isLooking ( this->target_, getControllableEntity(), math::pi/10.0f );
+        bool bTargetIsLookingAtThis = CommonController::isLooking ( this->target_, getControllableEntity(), math::pi/10.0f );
         
         //too far? well, come closer then
         if ( diffLength > this->attackRange_ )
@@ -166,18 +166,18 @@
     void FightingController::dodge(Vector3& thisPosition, Vector3& diffUnit)
     {
         float factorX = 0, factorY = 0, factorZ = 0;
-        float rand = randomInRange (0, 1);
+        float rand = CommonController::randomInRange (0, 1);
     
         if (rand <= 0.5)
         { factorX = 1; }
         else
         { factorX = -1; }
-        rand = randomInRange (0, 1);
+        rand = CommonController::randomInRange (0, 1);
         if (rand <= 0.5)
         { factorY = 1; }
         else
         { factorY = -1; }
-        rand = randomInRange (0, 1);
+        rand = CommonController::randomInRange (0, 1);
         if (rand <= 0.5)
         { factorZ = 1; }
         else
@@ -185,9 +185,9 @@
 
         Vector3 target = ( diffUnit )* 8000.0f;
         Vector3* randVector = new Vector3( 
-            factorX * randomInRange( 10000, 40000 ), 
-            factorY * randomInRange( 10000, 40000 ), 
-            factorZ * randomInRange( 10000, 40000 ) 
+            factorX * CommonController::randomInRange( 10000, 40000 ), 
+            factorY * CommonController::randomInRange( 10000, 40000 ), 
+            factorZ * CommonController::randomInRange( 10000, 40000 ) 
         );
         Vector3 projection = randVector->dotProduct( diffUnit )* diffUnit;
         *randVector -= projection;
@@ -244,7 +244,7 @@
     {
         if ( !this->getControllableEntity()  || !this->target_ )
             return false;
-        return this->isLooking(this->getControllableEntity(), this->getTarget(), angle);
+        return CommonController::isLooking(this->getControllableEntity(), this->getTarget(), angle);
     }
         void FightingController::setClosestTarget()
     {

Modified: code/branches/campaignHS15/src/orxonox/controllers/FightingController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FightingController.h	2015-11-27 15:19:06 UTC (rev 10876)
+++ code/branches/campaignHS15/src/orxonox/controllers/FightingController.h	2015-11-27 15:42:14 UTC (rev 10877)
@@ -34,9 +34,6 @@
 
 namespace orxonox
 {
-
-   
-
     class _OrxonoxExport FightingController : public FlyingController
     {
 

Modified: code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc	2015-11-27 15:19:06 UTC (rev 10876)
+++ code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc	2015-11-27 15:42:14 UTC (rev 10877)
@@ -44,6 +44,7 @@
     {
 
     }
+
     void FlyingController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
     {
         XMLPortParam( FlyingController, "spread", setSpread, getSpread,  xmlelement, mode );

Modified: code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h	2015-11-27 15:19:06 UTC (rev 10876)
+++ code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h	2015-11-27 15:42:14 UTC (rev 10877)
@@ -34,8 +34,6 @@
 
 namespace orxonox
 {   
-    const float SPEED = 0.9f/0.02f;
-    const float ROTATEFACTOR = 0.6f/0.02f;
     namespace FormationMode
     {
         enum Value
@@ -44,12 +42,13 @@
         };
     }
 
-    
-
     class _OrxonoxExport FlyingController : public CommonController
     {
 
         public:
+            static const float SPEED = 0.9f/0.02f;
+            static const float ROTATEFACTOR = 0.6f/0.02f;
+ 
             FlyingController(Context* context);
             virtual ~FlyingController();
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);

Modified: code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h	2015-11-27 15:19:06 UTC (rev 10876)
+++ code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h	2015-11-27 15:42:14 UTC (rev 10877)
@@ -46,12 +46,6 @@
             //----[language demanded functions]----            
                 virtual void tick(float dt); 
 
-            //----[pseudo virtual methods]----
-                virtual bool setFollower(LeaderController* myFollower)
-                    { return false; }
-                virtual bool hasFollower()
-                    { return true; }
-            //----[/pseudo virtual methods]----
 
 
         protected:

Modified: code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	2015-11-27 15:19:06 UTC (rev 10876)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	2015-11-27 15:42:14 UTC (rev 10877)
@@ -314,13 +314,13 @@
         }
         return 0;
     }
-    bool SectionController::setWingman(CommonController* cwingman)
+    bool SectionController::setWingman(ActionpointController* wingman)
     {
-        WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
+        WingmanController* newWingman = orxonox_cast<WingmanController*>(wingman);
 
         if (!this->myWingman_)
         {
-            this->myWingman_ = wingman;
+            this->myWingman_ = newWingman;
             return true;
         }
         else

Modified: code/branches/campaignHS15/src/orxonox/controllers/SectionController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.h	2015-11-27 15:19:06 UTC (rev 10876)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.h	2015-11-27 15:42:14 UTC (rev 10877)
@@ -52,7 +52,7 @@
             //----[own functions]----
                 LeaderController* findNewDivisionLeader();
 
-                virtual bool setWingman(CommonController* cwingman);
+                virtual bool setWingman(ActionpointController* wingman);
                 virtual bool hasWingman();
 
                 void chooseTarget();

Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc	2015-11-27 15:19:06 UTC (rev 10876)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc	2015-11-27 15:42:14 UTC (rev 10877)
@@ -110,7 +110,7 @@
         //----If no leader, find one----
         if (!this->myLeader_)
         {
-            ActionpointController* newLeader = orxonox_cast<ActionpointController*> (findNewLeader());
+            ActionpointController* newLeader = (findNewLeader());
             this->myLeader_ = newLeader;
            
         }
@@ -218,17 +218,18 @@
         return *targetRelativePosition;
     }
     //----POST: closest leader that is ready to take a new wingman is returned----
-    CommonController* WingmanController::findNewLeader()
+    ActionpointController* WingmanController::findNewLeader()
     {
 
         if (!this->getControllableEntity())
             return 0;
 
         //----vars for finding the closest leader----
-        CommonController* closestLeader = 0;
+        ActionpointController* closestLeader = 0;
         float minDistance =  std::numeric_limits<float>::infinity();
         Gametype* gt = this->getGametype();
-        for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)
+
+        for (ObjectList<ActionpointController>::iterator it = ObjectList<ActionpointController>::begin(); it; ++it)
         {
             //----0ptr or not a leader or dead?----
             if (!it || 
@@ -252,9 +253,13 @@
         if (closestLeader)
         {
             //----Racing conditions----
-            if (closestLeader->setWingman(orxonox_cast<CommonController*>(this)))
+            if (closestLeader->setWingman(orxonox_cast<ActionpointController*>(this)))
+            {
                 return closestLeader;
+            }
+
         }
+
         return 0;
     }
 

Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h	2015-11-27 15:19:06 UTC (rev 10876)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h	2015-11-27 15:42:14 UTC (rev 10877)
@@ -51,7 +51,7 @@
             //----[/orxonox demanded functions]----
 
             //----[own functions]----
-               CommonController* findNewLeader();
+               ActionpointController* findNewLeader();
             //----[/own functions]----
 
         protected:




More information about the Orxonox-commit mailing list