Index: code/branches/AI_HS15/data/levels/AITest.oxw
===================================================================
--- code/branches/AI_HS15/data/levels/AITest.oxw	(revision 10758)
+++ code/branches/AI_HS15/data/levels/AITest.oxw	(revision 10759)
@@ -62,5 +62,115 @@
     <?lua end ?>
   </!-->
+    <SpaceShip position="0,-10000,0" direction="0,-1,0" >
+     <templates>
+        <Template link=spaceshipassff />
+      </templates>
+     <controller>
+        <FleetController team=1>
+        </FleetController>
+      </controller>
+    </SpaceShip>
+    <?lua
+      for i = 0, 0, 1 do
+    ?>
+
     
+    <SpaceShip position="<?1000 ?>,<?lua print(1500+i*1000) ?>, -1000 ?>" lookat="0,0,0">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <DivisionController team=1 formationMode="DIAMOND">
+        </DivisionController>
+      </controller>
+    </SpaceShip>
+    <SpaceShip position="<?1000 ?>,<?lua print(1500+i*1000) ?>, -1600 ?>" lookat="0,0,0">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <WingmanController team=1>
+        </WingmanController>
+      </controller>
+    </SpaceShip>
+    <SpaceShip position="<?1000 ?>,<?lua print(1500+i*1000) ?>, -2200 ?>" lookat="0,0,0">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <WingmanController team=1>
+        </WingmanController>
+      </controller>
+    </SpaceShip>
+    <SpaceShip position="<?1000 ?>,<?lua print(1500+i*1000) ?>, -2800 ?>" lookat="0,0,0">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <SectionController team=1>
+        </SectionController>
+      </controller>
+    </SpaceShip>
+    <?lua end ?>
+   <!--  <SpaceShip position="4000, 1500, -1300 ?>" lookat="0,0,0">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <WingmanController team=2>
+        </WingmanController>
+      </controller>
+    </SpaceShip> -->
+<!-- 
+    <?lua
+      for i = 0, 0, 1 do
+    ?>
+
+    <StaticEntity position="1000,-10000,0" direction="0,-1,0" >
+     <controller>
+        <FleetController team=2>
+        </FleetController>
+      </controller>
+    </StaticEntity>
+    <SpaceShip position="<?50000 ?>,<?lua print(1500+i*1000) ?>, -1000 ?>" lookat="0,0,0">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <DivisionController team=2>
+        </DivisionController>
+      </controller>
+    </SpaceShip>
+    <SpaceShip position="<?50000 ?>,<?lua print(1500+i*1000) ?>, -1600 ?>" lookat="0,0,0">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <WingmanController team=2>
+        </WingmanController>
+      </controller>
+    </SpaceShip>
+    <SpaceShip position="<?50000 ?>,<?lua print(1500+i*1000) ?>, -2200 ?>" lookat="0,0,0">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <WingmanController team=2>
+        </WingmanController>
+      </controller>
+    </SpaceShip>
+    <SpaceShip position="<?50000 ?>,<?lua print(1500+i*1000) ?>, -2800 ?>" lookat="0,0,0">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <SectionController team=2>
+        </SectionController>
+      </controller>
+    </SpaceShip>
+    <?lua end ?> -->
+
+<!-- 
+
     <StaticEntity position = "-1000, -1000, -1000">
  
@@ -108,4 +218,50 @@
     </SpaceShip>
 
+
+      <StaticEntity position = "-1000, -1000, -2000">
+ 
+      <controller>
+        <FleetController accuracy=10 team=2 >
+        </FleetController>
+      </controller>
+    </StaticEntity>
+    
+    <SpaceShip position="4000, 1000, -1300 ?>" lookat="0,0,0">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <DivisionController team=2>
+        </DivisionController>
+      </controller>
+    </SpaceShip>
+    <SpaceShip position="4000, 1500, -1300 ?>" lookat="0,0,0">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <WingmanController team=2>
+        </WingmanController>
+      </controller>
+    </SpaceShip>
+    <SpaceShip position="4000, 1500, -1700 ?>" lookat="0,0,0">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <WingmanController team=2>
+        </WingmanController>
+      </controller>
+    </SpaceShip>
+    <SpaceShip position="4000, 1000, -1900 ?>" lookat="0,0,0">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <SectionController team=2>
+        </SectionController>
+      </controller>
+    </SpaceShip> -->
+
    
     <!-->
Index: code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	(revision 10758)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	(revision 10759)
@@ -27,5 +27,6 @@
  */
 #include "controllers/CommonController.h"
-/*
+#include "core/XMLPort.h"
+
 #include "weaponsystem/WeaponMode.h"
 #include "weaponsystem/WeaponPack.h"
@@ -34,5 +35,5 @@
 #include "weaponsystem/WeaponSlot.h"
 #include "worldentities/pawns/SpaceShip.h"
-*/
+
 
 namespace orxonox
@@ -40,10 +41,10 @@
 
     RegisterClass(CommonController);
-    static const float SPEED = 0.6f;
-    static const float ROTATEFACTOR = 0.2f;
+    float SPEED = 0.7f;
+    float ROTATEFACTOR = 0.3f;
 
     CommonController::CommonController(Context* context) : Controller(context)
     {
-        //this->bSetupWorked = false;
+        this->bSetupWorked = false;
 
         RegisterObject(CommonController);
@@ -55,6 +56,57 @@
     }
 
-
-
+    void CommonController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(CommonController, XMLPort, xmlelement, mode);
+        XMLPortParam(CommonController, "formationMode", setFormationModeXML, getFormationModeXML,  xmlelement, mode);
+
+    }
+    void CommonController::setFormationModeXML(std::string val)
+    {
+        const std::string valUpper = getUppercase(val);
+        FormationMode::Value value;
+        if (valUpper == "VEE")
+            value = FormationMode::VEE;
+        else if (valUpper == "WALL")
+            value = FormationMode::WALL;
+        else if (valUpper == "FINGER4")
+            value = FormationMode::FINGER4;
+        else if (valUpper == "DIAMOND")
+            value = FormationMode::DIAMOND;
+        else
+            ThrowException(ParseError, std::string("Attempting to set an unknown FormationMode: '") + val + "'.");
+        this->setFormationMode(value);
+       
+    }
+    std::string CommonController::getFormationModeXML()
+    {
+        switch (this->formationMode_)
+        {
+            case FormationMode::VEE:
+            {
+                return "VEE";
+                break;
+            }
+            case FormationMode::WALL:
+            {
+                return "WALL";
+                break;
+            }
+            case FormationMode::FINGER4:
+            {
+                return "FINGER4";
+                break;
+            }
+            case FormationMode::DIAMOND:
+            {
+                return "DIAMOND";
+                break;
+            }
+            default:
+                return "DIAMOND";
+                break;
+
+        }
+    }
 
     bool CommonController::setWingman (CommonController* wingman)
@@ -67,5 +119,11 @@
         return true;
     }
-
+    void CommonController::setTarget(ControllableEntity* target)
+    {
+        this->target_ = target;
+        orxout (internal_error) << " TARGET SET " << endl;
+        if (target)
+            this->targetPosition_ = target->getPosition();
+    }
 
 
@@ -113,5 +171,5 @@
         while(diff>math::twoPi) diff-=math::twoPi;
         while(diff<-math::twoPi) diff+=math::twoPi;
-        this->getControllableEntity()->rotateRoll(-diff);
+        this->getControllableEntity()->rotateRoll(diff*ROTATEFACTOR);
     }
     void CommonController::copyTargetOrientation()
@@ -134,8 +192,12 @@
         if (!this->getControllableEntity())
             return;
+        if (this->rank_ == Rank::DIVISIONLEADER)
+            SPEED *= 0.8;
+        if (this->rank_ == Rank::SECTIONLEADER)
+            SPEED *= 0.9;
         
         //100 is (so far) the smallest tolerance (empirically found) that can be reached, 
         //with smaller distance spaceships can't reach position and go circles around it instead
-        int tolerance = 100;
+        int tolerance = 60;
 
         ControllableEntity* entity = this->getControllableEntity();
@@ -160,5 +222,5 @@
 
             //300 works, maybe less is better
-            if (distance < 300)
+            if (distance < 400)
             {
                 //Change roll when close. When Spaceship faces target, roll doesn't affect it's trajectory
@@ -180,5 +242,5 @@
     }
 
-/*
+
     int CommonController::getFiremode(std::string name)
     {
@@ -227,13 +289,10 @@
     void CommonController::doFire()
     {
-        if(!this->bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ...
+          if(!this->bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ...
         {
             this->setupWeapons();
         }
-        else if(this->getControllableEntity() && 
-            weaponModes_.size()&&
-            this->bShooting_ && 
-            this->isCloseAtTarget((3)*1000) && 
-            this->isLookingAtTarget(math::pi / 20.0f))
+        else if(this->getControllableEntity() && weaponModes_.size()&&this->bShooting_ && 
+            this->isCloseAtTarget((1 + 2)*1000) && this->isLookingAtTarget(math::pi / 20.0f))
         {
             int firemode;
@@ -246,4 +305,5 @@
             else if ((firemode = getFiremode("HsW01")) > -1 ) //LASER: default weapon
                 this->getControllableEntity()->fire(firemode);
+        
         }
     }
@@ -269,5 +329,5 @@
         if (pawn)
             pawn->setAimPosition(aimPosition);
-    }*/
+    }
     
  
Index: code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	(revision 10758)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	(revision 10759)
@@ -33,9 +33,26 @@
 #include "controllers/Controller.h"
 #include "worldentities/ControllableEntity.h"
-/*#include "worldentities/pawns/Pawn.h"
-*/
+#include "worldentities/pawns/Pawn.h"
+
 
 namespace orxonox
 {
+
+    namespace FormationMode
+    {
+        enum Value
+        {
+            VEE, FINGER4, DIAMOND, WALL
+        };
+    }
+    namespace Rank
+    {
+        enum Value 
+        { 
+            NONE, SECTIONLEADER, DIVISIONLEADER, WINGMAN 
+        };
+
+    }
+
     class _OrxonoxExport CommonController : public Controller
     {
@@ -50,16 +67,19 @@
 
 
-            enum FormationMode { VEE, FINGER4, DIAMOND, WALL };
-            virtual void setFormationMode(FormationMode val)
+
+
+            virtual void setFormationMode(FormationMode::Value val)
                 { this->formationMode_ = val; }
-            inline FormationMode getFormationMode() const
+            inline FormationMode::Value getFormationMode() const
                 { return this->formationMode_; }
+            virtual void setFormationModeXML(std::string val);
+            virtual std::string getFormationModeXML();
 
-            enum Rank { NONE, SECTIONLEADER, DIVISIONLEADER, WINGMAN };
-            virtual void setRank(Rank val)
+            virtual void setRank(Rank::Value val)
                 { this->rank_ = val; }
-            inline Rank getRank() const
+            inline Rank::Value getRank() const
                 { return this->rank_; }
 
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
 
 
@@ -68,4 +88,5 @@
             virtual bool hasWingman();
 
+            void setTarget(ControllableEntity* target);
 
             void setTargetOrientation(const Quaternion& orient);
@@ -87,5 +108,5 @@
             void copyTargetOrientation();
 
-          /*  bool isCloseAtTarget(float distance) const;
+            bool isCloseAtTarget(float distance) const;
             void doFire();
             void aimAtTarget();
@@ -99,5 +120,5 @@
             bool bSetupWorked; //<! If false, setupWeapons() is called.
             int getFiremode(std::string name);
-*/
+
 
             bool bHasTargetPosition_;
@@ -111,6 +132,6 @@
 
 
-            FormationMode formationMode_;
-            Rank rank_;
+            FormationMode::Value formationMode_;
+            Rank::Value rank_;
 
 
Index: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	(revision 10758)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	(revision 10759)
@@ -38,12 +38,13 @@
     {
         RegisterObject(DivisionController);
-        this->setFormationMode(WALL);
+        
+        this->setFormationMode(FormationMode::DIAMOND);
 
         this->myFollower_ = 0;
         this->myWingman_ = 0;
         this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this)));
-        this->rank_ = DIVISIONLEADER;
-
-        Vector3* pos = new Vector3(500,500,-500);
+        this->rank_ = Rank::DIVISIONLEADER;
+
+        Vector3* pos = new Vector3(-4000,-1000,-2000);
         this->setTargetPosition(*pos);
 
@@ -58,10 +59,10 @@
     void DivisionController::tick(float dt)
     {
-        if (this->target_)
-        {
-            //this->aimAtTarget();
-            //this->doFire();
-            //this->bShooting_ = true;
-        }
+        /*if (this->target_)
+        {
+            this->aimAtTarget();
+            this->doFire();
+            this->bShooting_ = true;
+        }*/
      
         if (this->bHasTargetPosition_)
@@ -77,15 +78,21 @@
         setTargetPositionOfFollower();
         setTargetPositionOfWingman();
-/*
+
+        
+        if (this->myFollower_ && this->target_)
+            this->myFollower_->setTarget(this->target_);
+        if (this->target_ && this->myWingman_)
+            this->myWingman_->setTarget(this->target_);
+    /*            
         for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it)
         {
-            if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam())
-            {
-                this->target_=it->getControllableEntity();
-                this->setTargetPosition(this->target_->getWorldPosition());
+            if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) && (it)->getControllableEntity()->getTeam() != 0)
+            {
+                this->setTargetPosition(it->getControllableEntity()->getWorldPosition());
+                             
                 break;
             } 
-        }*/
-           
+        }
+           */
       
     }
@@ -99,19 +106,21 @@
         Vector3* targetRelativePositionOfWingman;
         switch (this->formationMode_){
-            case WALL:
+            case FormationMode::WALL:
             {
                 targetRelativePositionOfWingman = new Vector3 (400, 0, 0);  
                 break;
             }
-            case FINGER4: 
-            {
-                break;
-            }
-            case VEE: 
-            {
-                break;
-            }
-            case DIAMOND: 
-            {
+            case FormationMode::FINGER4: 
+            {
+                targetRelativePositionOfWingman = new Vector3 (400, 0, -200);  
+                break;
+            }
+            case FormationMode::VEE: 
+            {
+                break;
+            }
+            case FormationMode::DIAMOND: 
+            {
+                targetRelativePositionOfWingman = new Vector3 (400, 0, -200);                  
                 break;
             }
@@ -130,21 +139,25 @@
         if (!this->myFollower_)
             return;
+        this->myFollower_->setFormationMode(this->formationMode_);
+
         Vector3* targetRelativePositionOfFollower;
         switch (this->formationMode_){
-            case WALL:
+            case FormationMode::WALL:
             {
                 targetRelativePositionOfFollower = new Vector3 (-400, 0, 0);   
                 break;
             }
-            case FINGER4: 
-            {
-                break;
-            }
-            case VEE: 
-            {
-                break;
-            }
-            case DIAMOND: 
-            {
+            case FormationMode::FINGER4: 
+            {
+                targetRelativePositionOfFollower = new Vector3 (-400, 0, -200);   
+                break;
+            }
+            case FormationMode::VEE: 
+            {
+                break;
+            }
+            case FormationMode::DIAMOND: 
+            {
+                targetRelativePositionOfFollower = new Vector3 (-400, 0, -200);                   
                 break;
             }
Index: code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc	(revision 10758)
+++ code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc	(revision 10759)
@@ -44,5 +44,5 @@
         this->goalProtect_ = NULL;*/
         
-        //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&FleetController::action, this)));
+        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&FleetController::action, this)));
     }
 
@@ -56,5 +56,23 @@
     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 (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());   
+                }               
+                break;
+            } 
+        }*/
 
     }
Index: code/branches/AI_HS15/src/orxonox/controllers/FleetController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FleetController.h	(revision 10758)
+++ code/branches/AI_HS15/src/orxonox/controllers/FleetController.h	(revision 10759)
@@ -56,4 +56,6 @@
     {
         public:
+                      static const float ACTION_INTERVAL = 1.0f;
+
           FleetController(Context* context);
           virtual ~FleetController();
@@ -74,4 +76,5 @@
 
         protected:
+            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
 
             
@@ -81,9 +84,8 @@
             WeakPtr<Pawn> goalProtect_;
 
-            virtual void action();
         private:
         
             std::vector<WeakPtr<DivisionController> > divisions_;
-            //Timer actionTimer_; //<! Regularly calls action().
+            Timer actionTimer_; //<! Regularly calls action().
 
     };
Index: code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	(revision 10758)
+++ code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	(revision 10759)
@@ -37,10 +37,10 @@
     {
         RegisterObject(SectionController);
-        this->setFormationMode(WALL);
+        this->setFormationMode(FormationMode::FINGER4);
 
         this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&SectionController::action, this)));
         this->myWingman_ = 0;
         this->myDivisionLeader_ = 0;
-        this->rank_ = SECTIONLEADER;
+        this->rank_ = Rank::SECTIONLEADER;
 
         orxout(internal_error) << this << "Was created" << endl;
@@ -58,4 +58,10 @@
             return;
         
+        /*if (this->target_)
+        {
+            this->aimAtTarget();
+            this->doFire();
+            this->bShooting_ = true;
+        }*/
         if (this->bHasTargetPosition_)
         {
@@ -76,7 +82,14 @@
             if (newDivisionLeader)
                 orxout(internal_error) << "new DivisionLeader set" << endl;
+            else
+            {
+                
+            }
 
         }
         setTargetPositionOfWingman();
+        if (this->target_ && this->myWingman_)
+            this->myWingman_->setTarget(this->target_);
+                
 
     }
@@ -88,19 +101,21 @@
         Vector3* targetRelativePositionOfWingman;
         switch (this->formationMode_){
-            case WALL:
+            case FormationMode::WALL:
             {
                 targetRelativePositionOfWingman = new Vector3 (-400, 0, 0);  
                 break;
             }
-            case FINGER4: 
-            {
-                break;
-            }
-            case VEE: 
-            {
-                break;
-            }
-            case DIAMOND: 
-            {
+            case FormationMode::FINGER4: 
+            {
+                targetRelativePositionOfWingman = new Vector3 (-400, 0, -200);  
+                break;
+            }
+            case FormationMode::VEE: 
+            {
+                break;
+            }
+            case FormationMode::DIAMOND: 
+            {
+                targetRelativePositionOfWingman = new Vector3 (400, -200, 0);                  
                 break;
             }
@@ -127,5 +142,5 @@
         {
             //0ptr or not DivisionController?
-            if (!(it) || !((it)->getRank() == DIVISIONLEADER) || !(it->getControllableEntity()))
+            if (!(it) || !((it)->getRank() == Rank::DIVISIONLEADER) || !(it->getControllableEntity()))
                 continue;
             //same team?
Index: code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	(revision 10758)
+++ code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	(revision 10759)
@@ -41,5 +41,5 @@
         this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
         this->myLeader_ = 0;
-        this->rank_ = WINGMAN;
+        this->rank_ = Rank::WINGMAN;
 
     }
@@ -53,5 +53,10 @@
     {   
         //-------------------------------------------------------
-           
+       /* if (this->target_)
+        {
+            this->aimAtTarget();
+            this->doFire();
+            this->bShooting_ = true;
+        }*/
         
         if (!this->isActive())
@@ -88,5 +93,8 @@
                 orxout(internal_error) << "new Leader set" << endl;
             else
-                orxout(internal_error) << "0 leader" << endl;
+            {
+                //orxout(internal_error) << "0 leader" << endl;
+                
+            }
 
         }
@@ -113,5 +121,5 @@
             //0ptr?
             if (!it || 
-                (it->getRank() != SECTIONLEADER && it->getRank() != DIVISIONLEADER) || 
+                (it->getRank() != Rank::SECTIONLEADER && it->getRank() != Rank::DIVISIONLEADER) || 
                 !(it->getControllableEntity()))
                 continue;
