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

gania at orxonox.net gania at orxonox.net
Sun Nov 22 17:06:39 CET 2015


Author: gania
Date: 2015-11-22 17:06:38 +0100 (Sun, 22 Nov 2015)
New Revision: 10826

Removed:
   code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
   code/branches/AI_HS15/src/orxonox/controllers/FleetController.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/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/LeaderController.cc
   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:
some comments added

Modified: code/branches/AI_HS15/data/levels/AITest.oxw
===================================================================
--- code/branches/AI_HS15/data/levels/AITest.oxw	2015-11-22 15:55:02 UTC (rev 10825)
+++ code/branches/AI_HS15/data/levels/AITest.oxw	2015-11-22 16:06:38 UTC (rev 10826)
@@ -78,7 +78,7 @@
         </WingmanController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="6000, 1500, -2800" lookat="0,0,0">
+    <SpaceShip position="4000, 1500, -2800 " lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
@@ -87,43 +87,6 @@
         </SectionController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="6000, 1500, -1000" lookat="0,0,0">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <DivisionController team=1 formationMode="DIAMOND">
-        </DivisionController>
-      </controller>
-    </SpaceShip>
-    <SpaceShip position="6000 ,1500, -1600 " lookat="0,0,0">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <WingmanController team=1>
-        </WingmanController>
-      </controller>
-    </SpaceShip>
-    <SpaceShip position="6000, 1500, -2200" lookat="0,0,0">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <WingmanController team=1>
-        </WingmanController>
-      </controller>
-    </SpaceShip>
-    <SpaceShip position="6000, 1500, -2800" lookat="0,0,0">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <SectionController team=1>
-        </SectionController>
-      </controller>
-    </SpaceShip>
-  
     
     <SpaceShip position="-4000, 1500, -5000" lookat="0,0,0">
       <templates>
@@ -162,44 +125,6 @@
       </controller>
     </SpaceShip>
 
-       <SpaceShip position="-6000, 1500, -5000" lookat="0,0,0">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <DivisionController team=2 formationMode="FINGER4">
-        </DivisionController>
-      </controller>
-    </SpaceShip>
-    <SpaceShip position="-6000 , 1500, -5600" lookat="0,0,0">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <WingmanController team=2>
-        </WingmanController>
-      </controller>
-    </SpaceShip>
-    <SpaceShip position="-6000, 1500, -6200" lookat="0,0,0">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <WingmanController team=2>
-        </WingmanController>
-      </controller>
-    </SpaceShip>
-    <SpaceShip position="-6000, 1500, -6800 " lookat="0,0,0">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <SectionController team=2>
-        </SectionController>
-      </controller>
-    </SpaceShip>
-
-
     
    
 

Modified: code/branches/AI_HS15/src/orxonox/controllers/CMakeLists.txt
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CMakeLists.txt	2015-11-22 15:55:02 UTC (rev 10825)
+++ code/branches/AI_HS15/src/orxonox/controllers/CMakeLists.txt	2015-11-22 16:06:38 UTC (rev 10826)
@@ -10,7 +10,6 @@
   DroneController.cc
   FormationController.cc
   ControllerDirector.cc
-  FleetController.cc
   DivisionController.cc
   LeaderController.cc
   WingmanController.cc

Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	2015-11-22 15:55:02 UTC (rev 10825)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	2015-11-22 16:06:38 UTC (rev 10826)
@@ -45,25 +45,25 @@
 {
 
     RegisterClass( CommonController );
-    float SPEED = 0.9f/0.02f;
-    float ROTATEFACTOR = 1.0f/0.02f;
+    const float SPEED = 0.9f/0.02f;
+    const float ROTATEFACTOR = 1.0f/0.02f;
 
     CommonController::CommonController( Context* context ): Controller( context )
     {
         this->bSetupWorked = false;
 
-        this->executingManeuver_ = false;
+       
         this->executingMoveToPoint_ = false;
         this->action_ = Action::FLY;
         this->stopLookingAtTarget();
-        this->maneuverType_ = ManeuverType::NONE;
+       
         RegisterObject( CommonController );
     }
 
 
     CommonController::~CommonController() 
     {
-        orxout(internal_error) << "I died, my Rank is " << rank_ << endl;
+        //orxout(internal_error) << "I died, my Rank is " << rank_ << endl;
     }
 
     void CommonController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
@@ -76,9 +76,8 @@
     {
         const std::string valUpper = getUppercase( val );
         FormationMode::Value value;
-        if ( valUpper == "VEE" )
-            value = FormationMode::VEE;
-        else if ( valUpper == "WALL" )
+        
+        if ( valUpper == "WALL" )
             value = FormationMode::WALL;
         else if ( valUpper == "FINGER4" )
             value = FormationMode::FINGER4;
@@ -93,11 +92,6 @@
     {
         switch ( this->formationMode_ )
         {
-            case FormationMode::VEE:
-            {
-                return "VEE";
-                break;
-            }
             case FormationMode::WALL:
             {
                 return "WALL";
@@ -245,11 +239,7 @@
                 
             }
         }
-        if ( this->getControllableEntity()  && !this->target_ )
-        {
-
-            this->maneuverType_ = ManeuverType::NONE;
-        }
+        
         //orxout ( internal_error ) << "ManeuverType = " << this->maneuverType_ << endl;
     }
     ControllableEntity* CommonController::getTarget()
@@ -605,6 +595,18 @@
         }
 
     }
+    float CommonController::distance (ControllableEntity* entity1, ControllableEntity* entity2)
+    {
+        if (!entity1 || !entity2)
+            return std::numeric_limits<float>::infinity();
+        return ( entity1->getPosition() - entity2->getPosition() ).length();
+    }
+    bool CommonController::sameTeam (ControllableEntity* entity1, ControllableEntity* entity2)
+    {
+        if (!entity1 || !entity2)
+            return false;
+        return entity1->getTeam() == entity2->getTeam();
+    }
     void CommonController::doFire() 
     {
         if ( !this->target_ || !this->getControllableEntity() )

Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	2015-11-22 15:55:02 UTC (rev 10825)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	2015-11-22 16:06:38 UTC (rev 10826)
@@ -33,7 +33,7 @@
 #include "controllers/Controller.h"
 #include "worldentities/ControllableEntity.h"
 #include "worldentities/pawns/Pawn.h"
-#include "core/ClassTreeMask.h"
+#include <limits>
 
 
 namespace orxonox
@@ -43,7 +43,7 @@
     {
         enum Value
         {
-            VEE, FINGER4, DIAMOND, WALL
+            FINGER4, DIAMOND, WALL
         };
     }
     namespace Rank
@@ -54,17 +54,6 @@
         };
 
     }
-    //none for a formation flight without attacking, neutral when opponent and this have no 
-    //advantage over each other, offensive when this spotted opponent first,
-    //defensive otherwise
-    namespace ManeuverType
-    {
-        enum Value 
-        { 
-            NONE, NEUTRAL, OFFENSIVE, DEFENCIVE 
-        };
-
-    }
     namespace Action
     {  
         enum Value
@@ -72,17 +61,8 @@
             FLY, FIGHT, PROTECT
         };
     }
-    //none for a formation flight
-    namespace Maneuver
-    {
-        enum Value
-        {
-            NONE, GUNSD, SCISSORS, COMBATSPREAD, DEFENSIVESPLIT, BREAK, BARRELROLL, SWOOP, IMMELMANN, 
-            WINGOVER, LOWYOYO, HIGHYOYO, LAGDISPLACEMENTROLL
-        };
-    }
+ 
 
-
     class _OrxonoxExport CommonController : public Controller
     {
 
@@ -117,7 +97,7 @@
 
             virtual bool setWingman(CommonController* wingman);
             virtual bool hasWingman();
-
+            static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2);
             void setTarget(ControllableEntity* target);
             bool hasTarget();
             ControllableEntity* getTarget();
@@ -146,6 +126,7 @@
             void copyOrientation(const Quaternion& orient, float dt);
             void copyTargetOrientation(float dt);
 
+            static float distance(ControllableEntity* entity1, ControllableEntity* entity2);
             float squaredDistanceToTarget() const;
             void doFire();
             void aimAtTarget();
@@ -201,10 +182,7 @@
             void scissors();
             FormationMode::Value formationMode_;
             Rank::Value rank_;
-            ManeuverType::Value maneuverType_;
-            Maneuver::Value maneuver_;
-
-            bool executingManeuver_;
+        
             bool executingMoveToPoint_;
          
         private:

Modified: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	2015-11-22 15:55:02 UTC (rev 10825)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	2015-11-22 16:06:38 UTC (rev 10826)
@@ -34,6 +34,7 @@
 
     RegisterClass(DivisionController);
 
+    //Leaders share the fact that they have Wingmans
     DivisionController::DivisionController(Context* context) : LeaderController(context)
     {
         RegisterObject(DivisionController);
@@ -52,6 +53,13 @@
     {
     } 
 
+    void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(DivisionController, XMLPort, xmlelement, mode);
+
+        //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
+    }
+
     
     void DivisionController::tick(float dt)
     {   
@@ -75,16 +83,17 @@
     }
     void DivisionController::action()
     {
-        if (!this->target_)
+        //----find a target----
+        if ( !this->hasTarget() )
         {
             for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
             {
-                if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())
+                if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) )
                     continue;           
 
                 
-                if (static_cast<ControllableEntity*>(*itP) != (this)->getControllableEntity() && !(this)->hasTarget()
-                    && ((*itP)->getWorldPosition() - (this)->getControllableEntity()->getWorldPosition()).length() < 10000)
+                if (static_cast<ControllableEntity*>(*itP) != (this)->getControllableEntity()
+                    && CommonController::distance (*itP, this->getControllableEntity())  < 10000)
                 {
                     (this)->setAction(Action::FIGHT, *itP);
                 }   
@@ -93,15 +102,20 @@
         
         if (this->action_ == Action::FIGHT)
         {
+            //----choose where to go----
             this->maneuver();
+            //----fire if you can----
             this->bShooting_ = this->canFire();
+
             if (this->target_)
             {
                 if (this->myWingman_)
                 {
+                    //----wingmans shall support the fire of their leaders----
                     this->myWingman_->setAction (Action::FIGHT, this->target_);                    
                 }
                 
+                //----fly in formation if far enough----
                 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
                 if (diffVector.length() > 3000)
                 {
@@ -140,10 +154,7 @@
                 targetRelativePositionOfWingman = new Vector3 (400, 0, -200);  
                 break;
             }
-            case FormationMode::VEE: 
-            {
-                break;
-            }
+         
             case FormationMode::DIAMOND: 
             {
                 targetRelativePositionOfWingman = new Vector3 (400, 0, -200);                  
@@ -176,10 +187,7 @@
                 targetRelativePositionOfFollower = new Vector3 (-400, 0, -200);   
                 break;
             }
-            case FormationMode::VEE: 
-            {
-                break;
-            }
+            
             case FormationMode::DIAMOND: 
             {
                 targetRelativePositionOfFollower = new Vector3 (-400, 0, -200);                   
@@ -238,13 +246,6 @@
     }
 
 
-    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-11-22 15:55:02 UTC (rev 10825)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h	2015-11-22 16:06:38 UTC (rev 10826)
@@ -41,29 +41,34 @@
     class _OrxonoxExport DivisionController : public LeaderController, public Tickable
       {
         public:
+            //----[language demanded functions]----            
+            	DivisionController(Context* context);
 
-        	DivisionController(Context* context);
-        	virtual ~DivisionController();
+            	virtual ~DivisionController();
+            //----[/language demanded functions]----            
 
-            virtual void tick(float dt); //<! Carrying out the targets set in action().
+            //----[orxonox demanded functions]----
+                virtual void tick(float dt); 
 
-     		
-			virtual bool setFollower(LeaderController* myFollower);
-			virtual bool setWingman(CommonController* cwingman);
-            virtual bool hasWingman();
-            virtual bool hasFollower();
+                virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);          
+            //----[orxonox demanded functions]----
 
-            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);          
+            //----[own functions]----
+                virtual bool setFollower(LeaderController* myFollower);
+                virtual bool setWingman(CommonController* cwingman);
+                virtual bool hasWingman();
+                virtual bool hasFollower();
 
+                void setTargetPositionOfWingman();
+                void setTargetPositionOfFollower();
+            //----[/own functions]----
+
         protected:
-            
-            void setTargetPositionOfWingman();
-            void setTargetPositionOfFollower();
-
-            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
+            //----action must only be managed by this----
+            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
 	    
         private:
-
+            //----private variables-----
             Timer actionTimer_; //<! Regularly calls action().
 
     };

Deleted: code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc	2015-11-22 15:55:02 UTC (rev 10825)
+++ code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc	2015-11-22 16:06:38 UTC (rev 10826)
@@ -1,125 +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 "FleetController.h"
-
-
-namespace orxonox
-{
-
-    RegisterClass(FleetController);
-
-    FleetController::FleetController(Context* context) : Controller(context)
-    {
-        RegisterObject(FleetController);
-        
-        this->gameGoal_ = DOMINATE;
-        this->goalPosition_ = NULL;
-      /*  this->goalTarget_ = NULL;
-        this->goalProtect_ = NULL;*/
-        
-        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&FleetController::action, this)));
-    }
-
-    FleetController::~FleetController()
-    {
-        if (this->isInitialized())
-        {
-           
-        }
-    }
-    void FleetController::action()
-    {
-        this->divisions_.clear();
-        
-        for (ObjectList<DivisionController>::iterator it = ObjectList<DivisionController>::begin(); it; ++it)
-        {
-            if ((this->getControllableEntity()->getTeam() == (it)->getControllableEntity()->getTeam()))
-            {
-                this->divisions_.push_back(*(it));
-            } 
-        }
-        /*for(std::vector<WeakPtr<DivisionController> >::iterator it2 = divisions_.begin(); it2 != divisions_.end(); ++it2) 
-        {
-            (*it2)->setTargetPosition(this->getControllableEntity()->getWorldPosition());   
-        }*/ 
-        /*for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it)
-        {
-            if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) && (it)->getControllableEntity()->getTeam() == 0)
-            {
-                for(std::vector<WeakPtr<DivisionController> >::iterator it2 = divisions_.begin(); it2 != divisions_.end(); ++it2) {
-                    (*it2)->setTarget(it->getControllableEntity());   
-                    (*it2)->setTargetPosition(it->getControllableEntity()->getWorldPosition());
-                }               
-                break;
-            } 
-        }*/
-        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
-        {
-            if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())
-                continue;           
-
-            for(std::vector<WeakPtr<DivisionController> >::iterator it = divisions_.begin(); it != divisions_.end(); ++it) 
-            {
-                if (static_cast<ControllableEntity*>(*itP) != (*it)->getControllableEntity() && !(*it)->hasTarget()
-                    && ((*itP)->getWorldPosition() - (*it)->getControllableEntity()->getWorldPosition()).length() < 10000)
-                {
-                    (*it)->setAction(Action::FIGHT, *itP);
-                }
-                
-            }   
-           
-        }
-        /*for(std::vector<WeakPtr<DivisionController> >::iterator it = divisions_.begin(); it != divisions_.end(); ++it) 
-        {
-            Vector3* target = new Vector3 (0, 0, 2000);
-            (*it)->setAction (Action::FLY, *target);           
-        }   
-*/
-    }
-    void FleetController::tick(float dt)
-    {
-
-        SUPER(FleetController, tick, dt);
-
-    }
-    void FleetController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
-    {
-        SUPER(FleetController, XMLPort, xmlelement, mode);
-
-        //XMLPortObject(FleetController, GameGoal, "gameGoal", setGameGoal, getGameGoal, xmlelement, mode).defaultValues(DOMINATE);
-        //XMLPortParam(FleetController, "goalPosition", setGoalPosition, getGoalPosition, xmlelement, mode).defaultValues(NULL);
-        //XMLPortParam(FleetController, "goalTarget", setGoalTarget, getGoalTarget, xmlelement, mode).defaultValues(NULL);
-        //XMLPortParam(FleetController, "goalProtect", setGoalProtect, getGoalProtect, xmlelement, mode).defaultValues(NULL);
-
-    }
-
-    
-   
-
-}

Deleted: code/branches/AI_HS15/src/orxonox/controllers/FleetController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FleetController.h	2015-11-22 15:55:02 UTC (rev 10825)
+++ code/branches/AI_HS15/src/orxonox/controllers/FleetController.h	2015-11-22 16:06:38 UTC (rev 10826)
@@ -1,94 +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 _FleetController_H__
-#define _FleetController_H__
-
-#include "controllers/Controller.h"
-#include "controllers/DivisionController.h"
-#include "controllers/LeaderController.h"
-#include "controllers/WingmanController.h"
-
-#include "OrxonoxPrereqs.h"
-#include "core/class/Super.h"
-#include "core/CoreIncludes.h"
-
-
-#include <vector>
-#include "util/Math.h"
-#include <climits>
-
-#include "tools/Timer.h"
-#include "tools/interfaces/Tickable.h"
-
-#include "worldentities/ControllableEntity.h"
-
-
-namespace orxonox
-{   
-
-    class _OrxonoxExport FleetController : public Controller, public Tickable
-    {
-        public:
-                      static const float ACTION_INTERVAL = 1.0f;
-
-          FleetController(Context* context);
-          virtual ~FleetController();
-
-          virtual void tick(float dt); //<! Carrying out the targets set in action().
-
-          virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-
-          //gameGoal_ is to be set in XML
-          //DOMINATE is default, makes AI want to be the only team alive
-          //MOVE makes a fleet move to a set absolute position (set in variable goalPosition_)
-          //DESTROY makes a fleet destroy a target (set in variable goalTarget_)
-          //PROTECT makes a fleet protect a target (set in variable goalProtect_)
-          enum GameGoal {DOMINATE, MOVE, DESTROY, PROTECT};
-          
-          
-
-
-        protected:
-            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
-
-            
-            GameGoal gameGoal_;
-            Vector3* goalPosition_;
-            WeakPtr<Pawn> goalTarget_;
-            WeakPtr<Pawn> goalProtect_;
-
-        private:
-        
-            std::vector<WeakPtr<DivisionController> > divisions_;
-            Timer actionTimer_; //<! Regularly calls action().
-
-    };
-}
-
-#endif /* _FleetController_H__ */

Modified: code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc	2015-11-22 15:55:02 UTC (rev 10825)
+++ code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc	2015-11-22 16:06:38 UTC (rev 10826)
@@ -40,7 +40,7 @@
 
     RegisterClass(LeaderController);
 
-
+    //CommonController contains all common functionality of AI Controllers
     LeaderController::LeaderController(Context* context) : CommonController(context)
     {
 

Modified: code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h	2015-11-22 15:55:02 UTC (rev 10825)
+++ code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h	2015-11-22 16:06:38 UTC (rev 10826)
@@ -41,26 +41,26 @@
     class _OrxonoxExport LeaderController : public CommonController
     {
         public:
+            //----[language demanded functions]----            
+                LeaderController(Context* context);
+                virtual ~LeaderController();
+            //----[language demanded functions]----            
 
-            LeaderController(Context* context);
-            virtual ~LeaderController();
-           
-            virtual bool setFollower(LeaderController* myFollower)
-                { return false; }
-           
-            virtual bool hasFollower()
-                { return true; }
-            
+            //----[pseudo virtual methods]----
+                virtual bool setFollower(LeaderController* myFollower)
+                    { return false; }
+                virtual bool hasFollower()
+                    { return true; }
+            //----[/pseudo virtual methods]----
 
 
 
         protected:
-         
-            WeakPtr<WingmanController> myWingman_;
+            //----private variables-----
+                WeakPtr<WingmanController> myWingman_;
+                WeakPtr<LeaderController> myFollower_;
+                WeakPtr<LeaderController> myDivisionLeader_;
 
-            WeakPtr<LeaderController> myFollower_;
-            WeakPtr<LeaderController> myDivisionLeader_;
-
             
         private:
             

Modified: code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	2015-11-22 15:55:02 UTC (rev 10825)
+++ code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	2015-11-22 16:06:38 UTC (rev 10826)
@@ -33,6 +33,7 @@
 
     RegisterClass(SectionController);
 
+    //Leaders share the fact that they have Wingmans
     SectionController::SectionController(Context* context) : LeaderController(context)
     {
         RegisterObject(SectionController);
@@ -43,7 +44,7 @@
         this->myDivisionLeader_ = 0;
         this->rank_ = Rank::SECTIONLEADER;
 
-        orxout(internal_error) << this << "Was created" << endl;
+        //orxout(internal_error) << this << "Was created" << endl;
 
     }
    
@@ -51,7 +52,14 @@
     {
        
     }
+    void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(SectionController, XMLPort, xmlelement, mode);
 
+        //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
+    }
+
+    //----in tick, move (or look) and shoot----
     void SectionController::tick(float dt)
     {
          if (!this->isActive())
@@ -74,75 +82,57 @@
 
     void SectionController::action()
     {
-        //this->target_ = this->sectionTarget_;        
+        //----If no leader, find one----  
         if (!myDivisionLeader_)
         {
             LeaderController* newDivisionLeader = findNewDivisionLeader();
             this->myDivisionLeader_ = newDivisionLeader;
+
             if (newDivisionLeader)
-                orxout(internal_error) << "new DivisionLeader set" << endl;
+            {
+                //orxout(internal_error) << "new DivisionLeader set" << endl;
+            }
+            //----If no leader found, attack someone----
+            //----TODO: find closest enemy----
             else
             {
-                for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+                if ( !this->hasTarget() || this->action_ != Action::FIGHT )
                 {
-                    if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())
-                        continue;           
+                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+                    {
+                        if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) )
+                            continue;
 
-                    if (!this->myDivisionLeader_)
-                    {
                         this->setAction(Action::FIGHT, (*itP));
-                        break;
-                    }
-                   
+                        break;   
+                    }    
                 }
+                
             }
 
         }
+        //----If have leader----
         else
         {
-            if (this->myDivisionLeader_->getAction() == Action::FIGHT)
-            {
-                if (this->myDivisionLeader_->hasTarget())
-                {
-                    if (this->myDivisionLeader_->hasWingman() && (!this->hasTarget() || this->getTarget() == this->myDivisionLeader_->getTarget()))
-                    {
-                        bool foundTarget = false;
-                        Vector3 divisionTargetPosition = this->myDivisionLeader_->getTarget()->getWorldPosition();
-                        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
-                        {
-                            if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())
-                                continue;           
+            this->chooseTarget();
+        }
 
-                            if (((*itP)->getWorldPosition() - divisionTargetPosition).length() < 3000 &&
-                                ((*itP)->getWorldPosition() - divisionTargetPosition).length() > 1000 && 
-                                (*itP) != this->myDivisionLeader_->getTarget())
-                            {
-                                foundTarget = true;
-                                this->setAction(Action::FIGHT, (*itP));
-                                orxout(internal_error) << "Found target" << endl;
-                                break; 
-                            }
-                        }
-                        if (!foundTarget)
-                        {
-                            this->setAction(Action::FIGHT, this->myDivisionLeader_->getTarget());
-                        }
-
-                    }
-                }
-            }   
-        }
-        
+        //----action was set to fight----
         if (this->action_ == Action::FIGHT)
         {
+            //----choose where to go----
             this->maneuver();
+            //----fire if you can----
             this->bShooting_ = this->canFire();
+
             if (this->target_)
             {
+                //----wingmans shall support the fire of their leaders----
                 if (this->myWingman_)
                 {
                     this->myWingman_->setAction (Action::FIGHT, this->target_);                    
                 }
+                //----fly in formation if far enough----
                 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
                 if (diffVector.length() > 3000)
                 {
@@ -150,10 +140,14 @@
                 }   
             }
         }
+
+        //----action was set to fly----
         else if (this->action_ == Action::FLY)
         {
             this->setTargetPositionOfWingman();
         }
+
+        //----action was set to protect----
         else if (this->action_ == Action::PROTECT)
         {
 
@@ -161,7 +155,61 @@
                 
 
     }
-    
+    //PRE: myDivisionLeader_ != 0
+    //POST: this->target_ is set unless division leader doesn't have one
+    void SectionController::chooseTarget()
+    {
+        //----If division leader fights, cover him by fighting emenies close to his target----
+        if (this->myDivisionLeader_->getAction() == Action::FIGHT)
+        {
+            //----if he has a target----
+            if (this->myDivisionLeader_->hasTarget())
+            {
+                //----try to find a new target if division leader has wingman (doing fine) and no good target already set----
+                if ( this->myDivisionLeader_->hasWingman() && 
+                    !( this->hasTarget() && this->getTarget() != this->myDivisionLeader_->getTarget() ) )
+                {
+
+                    bool foundTarget = false;
+                    //----new target should be close to division's target----
+                    Vector3 divisionTargetPosition = this->myDivisionLeader_->getTarget()->getWorldPosition();
+                    
+                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+                    {
+                        //----is enemy?----
+                        if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) )
+                            continue;           
+                        //----in range?----
+                        if (((*itP)->getWorldPosition() - divisionTargetPosition).length() < 3000 && 
+                            (*itP) != this->myDivisionLeader_->getTarget())
+                        {
+                            foundTarget = true;
+                            this->setAction(Action::FIGHT, (*itP));
+                            //orxout(internal_error) << "Found target" << endl;
+                            break; 
+                        }
+                    }
+                    //----no target? then attack same target as division leader----
+                    if (!foundTarget)
+                    {
+                        this->setAction(Action::FIGHT, this->myDivisionLeader_->getTarget());
+                    }
+                }
+                //----if division leader doesn't have a wingman, support his fire----
+                else
+                {
+                    this->setAction(Action::FIGHT, this->myDivisionLeader_->getTarget());
+                }
+            }
+            //----If he fights but doesn't have a target, wait for him to get one----
+            else
+            {
+
+            }
+        } 
+    }
+
+    //----stay in formation----
     void SectionController::setTargetPositionOfWingman()
     {
         if (!this->myWingman_)
@@ -178,10 +226,6 @@
                 targetRelativePositionOfWingman = new Vector3 (-400, 0, -200);  
                 break;
             }
-            case FormationMode::VEE: 
-            {
-                break;
-            }
             case FormationMode::DIAMOND: 
             {
                 targetRelativePositionOfWingman = new Vector3 (400, -200, 0);                  
@@ -196,6 +240,7 @@
         myWingman_->setAction (Action::FLY, targetAbsolutePositionOfWingman, orient);
        
     }
+
     LeaderController* SectionController::findNewDivisionLeader()
     {
 
@@ -218,8 +263,7 @@
             if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
                 continue;
 
-
-            float distance = ((it)->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
+            float distance = CommonController::distance (it->getControllableEntity(), this->getControllableEntity());
             
             if (distance < minDistance && !(it->hasFollower()))
             {
@@ -259,14 +303,8 @@
             return false;
     }
 
-    void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
-    {
-        SUPER(SectionController, XMLPort, xmlelement, mode);
-
-        //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
-    }
-
     
+    
    
 
 }

Modified: code/branches/AI_HS15/src/orxonox/controllers/SectionController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/SectionController.h	2015-11-22 15:55:02 UTC (rev 10825)
+++ code/branches/AI_HS15/src/orxonox/controllers/SectionController.h	2015-11-22 16:06:38 UTC (rev 10826)
@@ -39,28 +39,35 @@
     class _OrxonoxExport SectionController : public LeaderController, public Tickable
     {
         public:
+            //----[language demanded functions]----            
+                SectionController(Context* context);
 
-            SectionController(Context* context);
-            virtual ~SectionController();
+                virtual ~SectionController();
+            //----[/language demanded functions]----
             
-            virtual void tick(float dt); //<! Carrying out the targets set in action().
+            //----[orxonox demanded functions]----
+                virtual void tick(float dt); 
+                
+                virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+            //----[/orxonox demanded functions]----
             
+            //----[own functions]----
+                LeaderController* findNewDivisionLeader();
+                void setTargetPositionOfWingman();
 
-            LeaderController* findNewDivisionLeader();
-            virtual bool setWingman(CommonController* cwingman);
-            virtual bool hasWingman();
-            
-            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+                virtual bool setWingman(CommonController* cwingman);
+                virtual bool hasWingman();
 
-        protected:
+                void chooseTarget();
+            //----[/own functions]----
 
-            void setTargetPositionOfWingman();
-            
-            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
+        protected:       
+            //----action must only be managed by this----     
+                virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
 
         private:
-
-            Timer actionTimer_; //<! Regularly calls action().
+            //----private variables-----
+                Timer actionTimer_; //<! Regularly calls action().
             
 
     };

Modified: code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	2015-11-22 15:55:02 UTC (rev 10825)
+++ code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	2015-11-22 16:06:38 UTC (rev 10826)
@@ -34,80 +34,28 @@
 
     RegisterClass(WingmanController);
     
-
+    //CommonController contains all common functionality of AI Controllers
     WingmanController::WingmanController(Context* context) : CommonController(context)
     {
         RegisterObject(WingmanController);
         this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
         this->myLeader_ = 0;
         this->rank_ = Rank::WINGMAN;
-
     }
 
     WingmanController::~WingmanController()
     {
 
     }
-    // void WingmanController::chooseManeuver()
-    // {
-    //     if (this->maneuverType_ == ManeuverType::NONE)
-    //     switch (this->maneuverType_ )
-    //     {
-    //         case ManeuverType::NONE:
-    //         {
+  
+    void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(WingmanController, XMLPort, xmlelement, mode);
 
-    //             break;
-    //         }
-    //         case ManeuverType::NEUTRAL:
-    //         {
-
-    //             break;
-    //         }
-    //         case ManeuverType::OFFENSIVE:
-    //         {
-
-    //             break;
-    //         }
-    //         case ManeuverType::DEFENSIVE:
-    //         {
-
-    //             break;
-    //         }
-    //     }
-    //     if (!this->myWingman_)
-    //         return;
-    //     Vector3* targetRelativePositionOfWingman;
-    //     switch (this->formationMode_){
-    //         case FormationMode::WALL:
-    //         {
-    //             targetRelativePositionOfWingman = new Vector3 (-400, 0, 0);  
-    //             break;
-    //         }
-    //         case FormationMode::FINGER4: 
-    //         {
-    //             targetRelativePositionOfWingman = new Vector3 (-400, 0, -200);  
-    //             break;
-    //         }
-    //         case FormationMode::VEE: 
-    //         {
-    //             break;
-    //         }
-    //         case FormationMode::DIAMOND: 
-    //         {
-    //             targetRelativePositionOfWingman = new Vector3 (400, -200, 0);                  
-    //             break;
-    //         }
-    //     }
-    //     Quaternion orient = this->getControllableEntity()->getWorldOrientation();
-        
-    //     Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) + 
-    //     (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman)));
-        
-    //     myWingman_->setTargetOrientation(orient);
-    //     myWingman_->setTargetPosition(targetAbsolutePositionOfWingman);
-       
-    // }
-
+        //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
+    }
+    
+    //----in tick, move (or look) and shoot----
     void WingmanController::tick(float dt)
     {   
         if (!this->isActive())
@@ -128,50 +76,55 @@
         SUPER(WingmanController, tick, dt);
     }
     
+    //----action for hard calculations----
     void WingmanController::action()
     {
+        //----If no leader, find one----
         if (!this->myLeader_)
         {
             CommonController* newLeader = findNewLeader();
             this->myLeader_ = newLeader;
             if (newLeader)
-                orxout(internal_error) << "new Leader set" << endl;
+            {
+                //orxout(internal_error) << "new Leader set" << endl;
+            }
+            //----If no leader found, attack someone----
+            //----TODO: find closest enemy----
             else
             {
-                if (!this->target_){
+                if ( !this->hasTarget() || this->action_ != Action::FIGHT )
+                {
                     for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
                     {
-                        if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())
+                        if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) )
                             continue;   
                         this->setAction(Action::FIGHT, (*itP));
                         break;
                     }
                 }
             }
-
         }
+        //----If have leader, he will deal with logic----
         else
         {
 
         }
-        
+
+
+        //----action was set to fight----
         if (this->action_ == Action::FIGHT)
         {
+            //----choose where to go----
             this->maneuver();
+            //----fire if you can----
             this->bShooting_ = this->canFire();
-            if (this->target_)
-            {
-                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
-                if (diffVector.length() > 5000)
-                {
-                  
-                }   
-            }
         }
+        //----action was set to fly, leader handles the logic----
         else if (this->action_ == Action::FLY)
         {
 
         }
+        //----TODO: implement protect----
         else if (this->action_ == Action::PROTECT)
         {
 
@@ -181,31 +134,31 @@
      
    
     
-
+    //----POST: closest leader that is ready to take a new wingman is returned----
     CommonController* WingmanController::findNewLeader()
     {
 
         if (!this->getControllableEntity())
             return 0;
 
+        //----vars for finding the closest leader----
         CommonController* closestLeader = 0;
         float minDistance =  std::numeric_limits<float>::infinity();
 
         for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)
         {
-            //0ptr?
+            //----0ptr or not a leader or dead?----
             if (!it || 
                 (it->getRank() != Rank::SECTIONLEADER && it->getRank() != Rank::DIVISIONLEADER) || 
                 !(it->getControllableEntity()))
                 continue;
-            //same team?
-            if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam())
+            
+            //----same team?----
+            if ( !CommonController::sameTeam (this->getControllableEntity(), (it)->getControllableEntity()) )
                 continue;
-            //is equal to this?
-            if (it->getControllableEntity() == this->getControllableEntity())
-                continue;
-
-            float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
+            
+            //----check distance----
+            float distance = CommonController::distance (it->getControllableEntity(), this->getControllableEntity());
             if (distance < minDistance && !(it->hasWingman()))
             {
                 closestLeader = *it;
@@ -215,19 +168,14 @@
         }
         if (closestLeader)
         {
+            //----Racing conditions----
             if (closestLeader->setWingman(this))
                 return closestLeader;
         }
         return 0;
     }
 
-    void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
-    {
-        SUPER(WingmanController, XMLPort, xmlelement, mode);
 
-        //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
-    }
 
 
-
 }

Modified: code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h	2015-11-22 15:55:02 UTC (rev 10825)
+++ code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h	2015-11-22 16:06:38 UTC (rev 10826)
@@ -31,7 +31,6 @@
 
 
 #include "controllers/CommonController.h"
-#include <limits>
 
 
 #include "util/Math.h"
@@ -44,25 +43,31 @@
     class _OrxonoxExport WingmanController : public CommonController, public Tickable
     {
         public:
-            WingmanController(Context* context);
-            virtual ~WingmanController();
-           
-            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-            virtual void tick(float dt); //<! Carrying out the targets set in action().
-            CommonController* findNewLeader();
+            //----[language demanded functions]----
+                WingmanController(Context* context);
+                
+                virtual ~WingmanController();
+            //----[/language demanded functions]----
+            
+            //----[orxonox demanded functions]----
+                virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
 
-        protected:
-            WeakPtr<CommonController> myLeader_;
+                virtual void tick(float dt); 
+            //----[/orxonox demanded functions]----
 
-            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
+            //----[own functions]----
+               CommonController* findNewLeader();
+            //----[/own functions]----
 
+        protected:
+            //----action must only be managed by this----
+                virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
 
-                     
         private:
-
-
-            Timer actionTimer_; //<! Regularly calls action().
-           
+            //----private variables-----
+                WeakPtr<CommonController> myLeader_;
+                Timer actionTimer_; //<! Regularly calls action().
+               
     };
 }
 




More information about the Orxonox-commit mailing list