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

gania at orxonox.net gania at orxonox.net
Thu Oct 29 20:02:24 CET 2015


Author: gania
Date: 2015-10-29 20:02:23 +0100 (Thu, 29 Oct 2015)
New Revision: 10719

Added:
   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/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/CMakeLists.txt
   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/FormationController.cc
   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:
All compiling, WingmanControllers actually find LeaderControllers and connect to them, SectionControllers find DivisionControllers and connect. TODO: write tick functions, helper functions to CommonController

Modified: code/branches/AI_HS15/data/levels/AITest.oxw
===================================================================
--- code/branches/AI_HS15/data/levels/AITest.oxw	2015-10-29 12:17:02 UTC (rev 10718)
+++ code/branches/AI_HS15/data/levels/AITest.oxw	2015-10-29 19:02:23 UTC (rev 10719)
@@ -62,15 +62,13 @@
     <?lua end ?>
   </!-->
     
-    <SpaceShip position = "-1000, -1000, -1000">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
+    <StaticEntity position = "-1000, -1000, -1000">
+ 
       <controller>
         <FleetController accuracy=10 team=1 >
         </FleetController>
       </controller>
-    </SpaceShip>
+    </StaticEntity>
     
     <SpaceShip position="1000, 1000, -1500 ?>" lookat="0,0,0">
       <templates>
@@ -95,8 +93,8 @@
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <LeaderController team=1>
-        </LeaderController>
+        <SectionController team=1>
+        </SectionController>
       </controller>
     </SpaceShip>
     <SpaceShip position="1000, 1000, -1900 ?>" lookat="0,0,0">
@@ -108,7 +106,6 @@
         </WingmanController>
       </controller>
     </SpaceShip>
-    <!-->    
     <!-->
     <?lua
       for i = 0, 5, 1 do

Modified: code/branches/AI_HS15/src/orxonox/controllers/CMakeLists.txt
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CMakeLists.txt	2015-10-29 12:17:02 UTC (rev 10718)
+++ code/branches/AI_HS15/src/orxonox/controllers/CMakeLists.txt	2015-10-29 19:02:23 UTC (rev 10719)
@@ -14,4 +14,6 @@
   DivisionController.cc
   LeaderController.cc
   WingmanController.cc
+  SectionController.cc
+  CommonController.cc
 )

Added: code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	                        (rev 0)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	2015-10-29 19:02:23 UTC (rev 10719)
@@ -0,0 +1,59 @@
+/*
+ *   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 "controllers/CommonController.h"
+
+namespace orxonox
+{
+
+    RegisterClass(CommonController);
+
+    
+    bool CommonController::setWingman (CommonController* wingman)
+    {
+        return false;
+    }
+    bool CommonController::isLeader ()
+    {
+        return false;
+    }
+    CommonController::CommonController(Context* context) : Controller(context)
+    {
+
+        RegisterObject(CommonController);
+
+        //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this)));
+    }
+
+
+    CommonController::~CommonController()
+    {
+    }
+
+ 
+
+}

Added: code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	                        (rev 0)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	2015-10-29 19:02:23 UTC (rev 10719)
@@ -0,0 +1,59 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+
+#ifndef _CommonController_H__
+#define _CommonController_H__
+
+
+#include "controllers/Controller.h"
+#include "worldentities/ControllableEntity.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport CommonController : public Controller
+    {
+        public:
+           
+            CommonController(Context* context);
+            virtual ~CommonController();
+            virtual bool isLeader();
+            virtual bool setWingman(CommonController* wingman);
+
+
+        protected:
+
+            //void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot.    
+         
+        private:
+            
+            //Timer actionTimer_; //<! Regularly calls action().
+               
+    };
+}
+
+#endif /* _CommonController_H__ */

Modified: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	2015-10-29 12:17:02 UTC (rev 10718)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	2015-10-29 19:02:23 UTC (rev 10719)
@@ -63,12 +63,12 @@
             return false;
         }
     }
-    /*void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
         SUPER(DivisionController, XMLPort, xmlelement, mode);
 
         //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
-    }*/
+    }
 
     
    

Modified: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h	2015-10-29 12:17:02 UTC (rev 10718)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h	2015-10-29 19:02:23 UTC (rev 10719)
@@ -38,13 +38,13 @@
 
 namespace orxonox
 {
-    class _OrxonoxExport DivisionController : public LeaderController
+    class _OrxonoxExport DivisionController : public LeaderController, public Tickable
       {
         public:
         	DivisionController(Context* context);
         	virtual ~DivisionController();
 
-        	//virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+        	virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
 
         	//Using british military aircraft formations
         	enum FormationMode {VEE,FINGER4,DIAMOND, WALL};
@@ -52,6 +52,19 @@
      		inline FormationMode getFormationMode() const
            		{ return this->formationMode_; }
 			virtual bool setFollower(LeaderController* myFollower);
+			virtual bool setWingman(CommonController* wingman)
+            {
+                if (!this->myWingman_)
+                {
+                    this->myWingman_ = wingman;
+                    return true;
+                }
+                else
+                {
+                    return false;
+                }
+            };
+            virtual void tick(float dt); //<! Carrying out the targets set in action().
 
 			
 
@@ -65,7 +78,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 12:17:02 UTC (rev 10718)
+++ code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc	2015-10-29 19:02:23 UTC (rev 10719)
@@ -34,7 +34,7 @@
 
     RegisterClass(FleetController);
 
-    FleetController::FleetController(Context* context) : FormationController(context)
+    FleetController::FleetController(Context* context) : Controller(context)
     {
         RegisterObject(FleetController);
         

Modified: code/branches/AI_HS15/src/orxonox/controllers/FleetController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FleetController.h	2015-10-29 12:17:02 UTC (rev 10718)
+++ code/branches/AI_HS15/src/orxonox/controllers/FleetController.h	2015-10-29 19:02:23 UTC (rev 10719)
@@ -28,7 +28,6 @@
 
 #ifndef _FleetController_H__
 #define _FleetController_H__
-#include "controllers/FormationController.h"
 
 #include "controllers/Controller.h"
 #include "controllers/DivisionController.h"
@@ -57,7 +56,7 @@
 namespace orxonox
 {   
 
-    class _OrxonoxExport FleetController : public FormationController, public Tickable
+    class _OrxonoxExport FleetController : public Controller, public Tickable
     {
         public:
           FleetController(Context* context);

Modified: code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc	2015-10-29 12:17:02 UTC (rev 10718)
+++ code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc	2015-10-29 19:02:23 UTC (rev 10719)
@@ -276,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);
@@ -1068,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)

Modified: code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc	2015-10-29 12:17:02 UTC (rev 10718)
+++ code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc	2015-10-29 19:02:23 UTC (rev 10719)
@@ -40,13 +40,11 @@
 
     RegisterClass(LeaderController);
 
-    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)));
     }
@@ -56,128 +54,7 @@
     {
     }
 
-    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.
-    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 LeaderController::tick(float dt)
-    {/*
-        if (!this->isActive())
-            return;
-        
-        //--------------------------Stay in division--------------------------
-        this->keepDivisionTick();*/
-        /*keepDivisionTick(){
-            if (this->divisionLeader_ && this->divisionLeader_->getControllableEntity() && desiredRelativePosition_){
-                Vector3 desiredAbsolutePosition = ((this->divisionLeader_->getControllableEntity()->getWorldPosition()) + 
-                    (this->divisionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
-                this->moveToPosition (desiredAbsolutePosition);
-            }
-        }
-        */
-        /*//If ordered to attack -> follow target and shoot
-        if (this->bAttackOrder_)
-        {
- 
-        } 
-        //If ordered to move -> move to a target Point
-        
-        //No orders -> Don't move, but shoot at whatever is close, unless Boss is shooting at it. 
-        //(Section shoots same target, Boss's section shoots another target) 
-        {
-
-        }*/
-
-        orxout(internal_error) << "my Wingman is " << this->myWingman_ << endl;
-        
-        SUPER(LeaderController, tick, dt);
-    }
-    bool LeaderController::setWingman(WingmanController* 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-29 12:17:02 UTC (rev 10718)
+++ code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h	2015-10-29 19:02:23 UTC (rev 10719)
@@ -34,37 +34,39 @@
 
 
 #include "util/Math.h"
-#include "tools/Timer.h"
-#include "tools/interfaces/Tickable.h"
 
+
 namespace orxonox
 {
-    class _OrxonoxExport LeaderController : public CommonController,  virtual public Tickable
+    class _OrxonoxExport LeaderController : public CommonController
     {
         public:
-           
+               static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000;
+
             LeaderController(Context* context);
             virtual ~LeaderController();
-            virtual bool isLeader();
+            virtual bool isLeader()
+            {
+                return true;
+            }
+            bool bIsDivisionLeader_;
+            virtual bool setFollower(LeaderController* myFollower)
+            {
+                return false;
+            };
 
-            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.    
          
         private:
             
             WeakPtr<Pawn> target_;
             
-            WingmanController* myWingman_;
-            LeaderController* myDivisionLeader_;
+            
             //Timer actionTimer_; //<! Regularly calls action().
                
     };

Added: code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	                        (rev 0)
+++ code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	2015-10-29 19:02:23 UTC (rev 10719)
@@ -0,0 +1,163 @@
+/*
+ *   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);
+    static const float ACTION_INTERVAL = 1.0f;
+
+    SectionController::SectionController(Context* context) : LeaderController(context)
+    {
+        RegisterObject(SectionController);
+        bIsDivisionLeader_ = false;
+        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&SectionController::action, this)));
+
+
+    }
+   
+    SectionController::~SectionController()
+    {
+        if (this->isInitialized())
+        {
+           
+        }
+    }
+     LeaderController* SectionController::findNewDivisionLeader()
+    {
+
+        if (!this->getControllableEntity())
+            return NULL;
+
+        
+        //go through all pawns
+        for (ObjectList<LeaderController>::iterator it = ObjectList<LeaderController>::begin(); it; ++it)
+        {
+
+            //same team?
+            if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()))
+                continue;
+
+            //is equal to this?
+            if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
+                continue;
+
+
+            
+            //nullptr or not DivisionController?
+            if (!(it) || !(it)->bIsDivisionLeader_)
+                continue;
+
+            float distance = ((it)->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
+
+            // is pawn in range?
+            if (distance < RADIUS_TO_SEARCH_FOR_LEADER)
+            {
+
+                if ((it)->setFollower(this))
+                    return (*it);
+            }
+        }
+                return NULL;
+
+    }
+
+    void SectionController::action()
+    {
+        //this->target_ = this->sectionTarget_;        
+        if (!myDivisionLeader_)
+        {
+            LeaderController* newDivisionLeader = findNewDivisionLeader();
+            myDivisionLeader_ = newDivisionLeader;
+           /* if (newDivisionLeader)
+                orxout(internal_error) << "new DivisionLeader set" << endl;
+            else
+                orxout(internal_error) << "null division leader" << endl;*/
+        }
+    }
+    /*
+    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)
+    {/*
+        if (!this->isActive())
+            return;
+        
+        //--------------------------Stay in division--------------------------
+        this->keepDivisionTick();*/
+        /*keepDivisionTick(){
+            if (this->divisionLeader_ && this->divisionLeader_->getControllableEntity() && desiredRelativePosition_){
+                Vector3 desiredAbsolutePosition = ((this->divisionLeader_->getControllableEntity()->getWorldPosition()) + 
+                    (this->divisionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
+                this->moveToPosition (desiredAbsolutePosition);
+            }
+        }
+        */
+        /*//If ordered to attack -> follow target and shoot
+        if (this->bAttackOrder_)
+        {
+ 
+        } 
+        //If ordered to move -> move to a target Point
+        
+        //No orders -> Don't move, but shoot at whatever is close, unless Boss is shooting at it. 
+        //(Section shoots same target, Boss's section shoots another target) 
+        {
+
+        }*/
+
+        //orxout(internal_error) << "my Wingman is " << this->myWingman_ << endl;
+        
+        SUPER(SectionController, tick, dt);
+    }
+    
+
+    void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(SectionController, XMLPort, xmlelement, mode);
+
+        //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
+    }
+
+    
+   
+
+}

Added: code/branches/AI_HS15/src/orxonox/controllers/SectionController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/SectionController.h	                        (rev 0)
+++ code/branches/AI_HS15/src/orxonox/controllers/SectionController.h	2015-10-29 19:02:23 UTC (rev 10719)
@@ -0,0 +1,85 @@
+/*
+ *   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/LeaderController.h"
+
+#include "tools/Timer.h"
+#include "tools/interfaces/Tickable.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport SectionController : public LeaderController, public Tickable
+    {
+        public:
+            SectionController(Context* context);
+            virtual ~SectionController();
+            virtual bool setWingman(CommonController* wingman)
+            {
+                if (!this->myWingman_)
+                {
+                    this->myWingman_ = wingman;
+                    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.
+            //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().
+            CommonController* myWingman_;
+            LeaderController* myDivisionLeader_;
+            Vector3* desiredRelativePosition_;
+
+    };
+}
+
+#endif /* _SectionController_H__ */

Modified: code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	2015-10-29 12:17:02 UTC (rev 10718)
+++ code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	2015-10-29 19:02:23 UTC (rev 10719)
@@ -40,12 +40,12 @@
 {
 
     RegisterClass(WingmanController);
-    static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000;
-
+    static const int RADIUS_TO_SEARCH_FOR_LEADER = 7000;
+    static const float ACTION_INTERVAL = 1.0f;
     WingmanController::WingmanController(Context* context) : CommonController(context)
     {
         RegisterObject(WingmanController);
-        //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
+        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
     }
 
     WingmanController::~WingmanController()
@@ -67,51 +67,33 @@
 
         
         //go through all pawns
-        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+        for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)
         {
-
             //same team?
-            if (!(this->getControllableEntity()->getTeam() != static_cast<ControllableEntity*>(*it)->getTeam()))
+            if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->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())
+            if (it->getControllableEntity() == this->getControllableEntity())
                 continue;
 
 
-            CommonController* newLeader = orxonox_cast<CommonController*>(controller);
 
             //nullptr?
-            if (!newLeader || !newLeader->isLeader())
+            if (!it || !it->isLeader())
                 continue;
 
-            float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length();
+            float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
 
             // is pawn in range?
             if (distance < RADIUS_TO_SEARCH_FOR_LEADER)
             {
 
-                if (newLeader->setWingman(this))
-                    return newLeader;
+                if (it->setWingman(this))
+                    return *it;
             }
         }
         return NULL;
     }
-    bool WingmanController::isLeader()
-    {
-        return false;
-    }
     void WingmanController::action()
     {
         //this->target_ = this->sectionTarget_;
@@ -119,14 +101,19 @@
         {
             CommonController* newLeader = findNewLeader();
             myLeader_ = newLeader;
-            orxout(internal_error) << "new Leader set" << endl;
+           /* if (newLeader)
+                orxout(internal_error) << "new Leader set" << endl;
+            else
+                orxout(internal_error) << "null leader" << endl;
+*/
         }
+        else
+        {
+            //orxout(internal_error) << "already have a Leader" << endl;
+
+        }
     }
-
-    void WingmanController::tick(float dt)
-    {   
-        //-------------------------------------------------------
-            /*//collect data for AI behaviour
+ /*//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;
@@ -165,33 +152,8 @@
                 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--------------------------
-        if (bFollowLeader_)
-        {
-            this->keepSectionTick();*/
-            /*keepSectionTick(){
-                if (this->sectionLeader_ && this->sectionLeader_->getControllableEntity() && desiredRelativePosition_){
-                    Vector3 desiredAbsolutePosition = ((this->sectionLeader_->getControllableEntity()->getWorldPosition()) + 
-                        (this->sectionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
-                    this->moveToPosition (desiredAbsolutePosition);
-                }
-            }
-            */
-          /*  
-            //--------------------------Attack same target as the Leader--------------------------
 
-            if (this->target_)
-            {
-                this->aimAtTarget();
-                this->doFire();
-            }
-        }*/
-         //orxout(internal_error) << "I am " << this << endl;
-
-       /* void FormationController::setDesiredPositionOfSlaves()
+      /*  void FormationController::setDesiredPositionOfSlaves()
     {
         if (this->state_ != MASTER)
             return;
@@ -217,9 +179,49 @@
         }
        
     }*/
+    void WingmanController::tick(float dt)
+    {   
+        //-------------------------------------------------------
+           
+        /*
+        if (!this->isActive())
+            return;
+        //--------------------------Stay in formation--------------------------
+        if (bFollowLeader_)
+        {
+            this->keepSectionTick();
+            
+            keepSectionTick(){
+                if (this->sectionLeader_ && this->sectionLeader_->getControllableEntity() && desiredRelativePosition_){
+                    Vector3 desiredAbsolutePosition = ((this->sectionLeader_->getControllableEntity()->getWorldPosition()) + 
+                        (this->sectionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
+                    this->moveToPosition (desiredAbsolutePosition);
+                }
+            }
+            
+            
+            //--------------------------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);
+
+        //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
+    }
+
 //**********************************************NEW
     /*void WingmanController::defaultBehaviour(float maxrand)
     {  

Modified: code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h	2015-10-29 12:17:02 UTC (rev 10718)
+++ code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h	2015-10-29 19:02:23 UTC (rev 10719)
@@ -45,12 +45,15 @@
         public:
             WingmanController(Context* context);
             virtual ~WingmanController();
-            virtual bool isLeader();
-          //virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+            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();
 
         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.
@@ -64,7 +67,7 @@
             CommonController* myLeader_;
             //LeaderController* leader_;
 
-            //Timer actionTimer_; //<! Regularly calls action().
+            Timer actionTimer_; //<! Regularly calls action().
            
     };
 }




More information about the Orxonox-commit mailing list