Index: /code/branches/AI_HS15/data/levels/AITest.oxw
===================================================================
--- /code/branches/AI_HS15/data/levels/AITest.oxw	(revision 10728)
+++ /code/branches/AI_HS15/data/levels/AITest.oxw	(revision 10729)
@@ -32,5 +32,5 @@
 
     <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
-    <SpawnPoint team=0 position="1000,1000,-1000" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
+    <SpawnPoint team=0 position="1000,1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
     <!-->
 
@@ -80,5 +80,5 @@
       </controller>
     </SpaceShip>
-    <SpaceShip position="1000, 1000, -1300 ?>" lookat="0,0,0">
+    <SpaceShip position="1000, 1500, -1300 ?>" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
@@ -89,5 +89,5 @@
       </controller>
     </SpaceShip>
-    <SpaceShip position="1000, 1000, -1700 ?>" lookat="0,0,0">
+    <SpaceShip position="1000, 1500, -1700 ?>" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
Index: /code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- /code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	(revision 10728)
+++ /code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	(revision 10729)
@@ -32,5 +32,9 @@
 
     RegisterClass(CommonController);
+    static const float SPEED = 0.6f;
+    static const float ROTATEFACTOR = 0.2f;
 
+    /*static const float SPEED_FREE = 0.8f;
+    static const float ROTATEFACTOR_FREE = 0.8f;*/
     
     bool CommonController::setWingman (CommonController* wingman)
@@ -51,5 +55,4 @@
 
         RegisterObject(CommonController);
-        //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this)));
     }
 
@@ -58,4 +61,40 @@
     {
     }
+    //copy the Roll orientation of given Quaternion.
+    void CommonController::copyOrientation(const Quaternion& orient)
+    {
+        //roll angle difference in radian
+        float diff=orient.getRoll(false).valueRadians()-(this->getControllableEntity()->getOrientation().getRoll(false).valueRadians());
+        while(diff>math::twoPi) diff-=math::twoPi;
+        while(diff<-math::twoPi) diff+=math::twoPi;
+        this->getControllableEntity()->rotateRoll(-diff);
+
+
+
+    }
+    void CommonController::setTargetPosition(const Vector3& target)
+    {
+        this->targetPosition_ = target;
+        this->bHasTargetPosition_ = true;
+    }
+
+    void CommonController::copyTargetOrientation()
+    {
+        if (bHasTargetOrientation_)
+        {   
+            copyOrientation(targetOrientation_);
+        }
+    }
+    void CommonController::setTargetOrientation(const Quaternion& orient)
+    {
+        this->targetOrientation_=orient;
+        this->bHasTargetOrientation_=true;
+    }
+    void CommonController::setTargetOrientation(ControllableEntity* target)
+    {
+        if (target)
+            setTargetOrientation(target->getOrientation());
+    }
+
 
     void CommonController::moveToPosition(const Vector3& target)
@@ -63,31 +102,54 @@
         if (!this->getControllableEntity())
             return;
+        
+        //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;
 
-        Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
+        ControllableEntity* entity = this->getControllableEntity();
+        Vector2 coord = get2DViewCoordinates
+            (entity->getPosition(), 
+            entity->getOrientation() * WorldEntity::FRONT, 
+            entity->getOrientation() * WorldEntity::UP, 
+            target);
+
         float distance = (target - this->getControllableEntity()->getPosition()).length();
+
+        //rotates should be in range [-1,+1], clamp cuts off all that is not
         float rotateX = clamp(coord.x * 10, -1.0f, 1.0f);
         float rotateY = clamp(coord.y * 10, -1.0f, 1.0f);
 
         
-        if (this->target_ || distance > 10)
+        if (distance > tolerance)
         {
-            this->getControllableEntity()->rotateYaw(-1.0f * 0.8f * rotateX);
-            this->getControllableEntity()->rotatePitch(0.8f * rotateY);
+            //Yaw and Pitch are enough to start facing the target
+            this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR * rotateX);
+            this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR * rotateY);
+
+            //300 works, maybe less is better
+            if (distance < 300)
+            {
+                //Change roll when close. When Spaceship faces target, roll doesn't affect it's trajectory
+                //It's important that roll is not changed in the process of changing yaw and pitch
+                //Wingmen won't face same direction as Leaders, but when Leaders start moving
+                //Yaw and Pitch will adapt.
+                if (bHasTargetOrientation_)
+                {
+                    copyTargetOrientation();
+                }
+            }
+            this->getControllableEntity()->moveFrontBack(1.2f*SPEED);
+        }
+        else
+        {      
+            bHasTargetPosition_ = false;
+            bHasTargetOrientation_ = false;
         }
 
-        if (this->target_ && distance <  200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
-        {
-            this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance
-        } 
-        else if (distance > 100)
-            this->getControllableEntity()->moveFrontBack(0.8f);
-        
-
-
-        if (distance < 100)
-        {
-            this->positionReached();
-            bHasTargetOrientation_=false;
-        }
+      
+    }
+    void CommonController::moveToTargetPosition()
+    {
+        this->moveToPosition(this->targetPosition_);
     }
  
Index: /code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
===================================================================
--- /code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	(revision 10728)
+++ /code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	(revision 10729)
@@ -39,4 +39,6 @@
     {
         public:
+            static const float ACTION_INTERVAL = 1.0f;
+
             enum FormationMode {VEE,FINGER4,DIAMOND, WALL};
             virtual void setFormationMode(FormationMode val)
@@ -50,6 +52,9 @@
             virtual bool setWingman(CommonController* wingman);
             virtual bool hasWingman();
-            Vector3* desiredRelativePosition_;
 
+
+            void setTargetOrientation(const Quaternion& orient);
+            void setTargetOrientation(ControllableEntity* target);
+            void setTargetPosition(const Vector3& target);
 
         protected:
@@ -57,26 +62,10 @@
             virtual void positionReached() {}
 
-        /*    void moveToTargetPosition();
-            void absoluteMoveToPosition(const Vector3& target);
+       
+            void moveToTargetPosition();
             void copyOrientation(const Quaternion& orient);
             void copyTargetOrientation();
 
-            void spin();
-            void turn180();
-            void follow();
-            void setTargetPosition(const Vector3& target);
 
-            void setTargetOrientation(const Quaternion& orient);
-            void setTargetOrientation(Pawn* target);
-
-
-
-            void setTarget(Pawn* target);
-
-            void searchNewTarget();
-            void forgetTarget();
-
-            void targetDied();
-*/
             bool bHasTargetPosition_;
             Vector3 targetPosition_;
@@ -91,9 +80,7 @@
 
 
-            //void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot.    
          
         private:
             
-            //Timer actionTimer_; //<! Regularly calls action().
                
     };
Index: /code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- /code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	(revision 10728)
+++ /code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	(revision 10729)
@@ -34,5 +34,4 @@
 
     RegisterClass(DivisionController);
-    static const float ACTION_INTERVAL = 1.0f;
 
     DivisionController::DivisionController(Context* context) : LeaderController(context)
@@ -45,4 +44,7 @@
         this->myWingman_ = 0;
         this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this)));
+       
+        /*Vector3* pos = new Vector3(500,500,-500);
+        this->setTargetPosition(*pos);*/
 
     }
@@ -54,4 +56,9 @@
     void DivisionController::tick(float dt)
     {
+        if (this->bHasTargetPosition_)
+        {
+            this->moveToTargetPosition();
+        }
+
         SUPER(DivisionController, tick, dt);
 
@@ -59,6 +66,6 @@
     void DivisionController::action()
     {
-/*        setDesiredPositionOfFollower();
-        setDesiredPositionOfWingman();*/
+        setTargetPositionOfFollower();
+        setTargetPositionOfWingman();
     }
 
@@ -76,13 +83,13 @@
     }
 
-   /* void DivisionController::setDesiredPositionOfWingman()
+    void DivisionController::setTargetPositionOfWingman()
     {
         if (!this->myWingman_)
             return;
-
+        Vector3* targetRelativePositionOfWingman;
         switch (this->formationMode_){
             case WALL:
             {
-                myWingman_->desiredRelativePosition_ = new Vector3 (200, 0, 0);   
+                targetRelativePositionOfWingman = new Vector3 (400, 0, 0);  
                 break;
             }
@@ -100,15 +107,22 @@
             }
         }
+        Quaternion orient = this->getControllableEntity()->getWorldOrientation();
+        
+        Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) + 
+        (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman)));
+        
+        myWingman_->setTargetOrientation(orient);
+        myWingman_->setTargetPosition(targetAbsolutePositionOfWingman);
        
     }
-    void DivisionController::setDesiredPositionOfFollower()
+    void DivisionController::setTargetPositionOfFollower()
     {
         if (!this->myFollower_)
             return;
-
+        Vector3* targetRelativePositionOfFollower;
         switch (this->formationMode_){
             case WALL:
             {
-                myWingman_->desiredRelativePosition_ = new Vector3 (-200, 0, 0);   
+                targetRelativePositionOfFollower = new Vector3 (-400, 0, 0);   
                 break;
             }
@@ -126,6 +140,13 @@
             }
         }
+        Quaternion orient = this->getControllableEntity()->getWorldOrientation();
+        
+        Vector3 targetAbsolutePositionOfFollower = ((this->getControllableEntity()->getWorldPosition()) + 
+        (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfFollower)));
+        
+        myFollower_->setTargetOrientation(orient);
+        myFollower_->setTargetPosition(targetAbsolutePositionOfFollower);
        
-    }*/
+    }
     void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
Index: /code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h
===================================================================
--- /code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h	(revision 10728)
+++ /code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h	(revision 10729)
@@ -51,6 +51,7 @@
      		
 			virtual bool setFollower(LeaderController* myFollower);
-			virtual bool setWingman(CommonController* wingman)
+			virtual bool setWingman(CommonController* cwingman)
             {
+                WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
                 if (!this->myWingman_)
                 {
@@ -83,14 +84,7 @@
 
         protected:
-            void setDesiredPositionOfWingman();
-            void setDesiredPositionOfFollower();
+            void setTargetPositionOfWingman();
+            void setTargetPositionOfFollower();
             virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
-
-	     	//Target enemy, set by fleet controller.
-	        
-			
-			
-	        
-
 	    
         private:
Index: /code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc
===================================================================
--- /code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc	(revision 10728)
+++ /code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc	(revision 10729)
@@ -47,18 +47,11 @@
         RegisterObject(LeaderController);
 
-        //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this)));
     }
 
-
+   
     LeaderController::~LeaderController()
     {
     }
 
-    
-//**********************************************NEW
-   /* void LeaderController::defaultBehaviour(float maxrand)
-    {  
-       
-    }*/
 
 }
Index: /code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h
===================================================================
--- /code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h	(revision 10728)
+++ /code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h	(revision 10729)
@@ -42,5 +42,4 @@
     {
         public:
-               static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000;
 
             LeaderController(Context* context);
@@ -63,5 +62,5 @@
                 return true;
             };
-            WeakPtr<CommonController> myWingman_;
+            WeakPtr<WingmanController> myWingman_;
 
             WeakPtr<LeaderController> myFollower_;
@@ -70,15 +69,7 @@
 
         protected:
-           
-
-
-            //void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot.    
          
         private:
             
-            
-            
-            //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 10728)
+++ /code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	(revision 10729)
@@ -33,10 +33,9 @@
 
     RegisterClass(SectionController);
-    static const float ACTION_INTERVAL = 1.0f;
 
     SectionController::SectionController(Context* context) : LeaderController(context)
     {
         RegisterObject(SectionController);
-                this->setFormationMode(WALL);
+        this->setFormationMode(WALL);
 
         bIsDivisionLeader_ = false;
@@ -44,5 +43,4 @@
         this->myWingman_ = 0;
         this->myDivisionLeader_ = 0;
-        this->desiredRelativePosition_ = 0;
 
         orxout(internal_error) << this << "Was created" << endl;
@@ -54,13 +52,13 @@
        
     }
-    /*void SectionController::setDesiredPositionOfWingman()
+    void SectionController::setTargetPositionOfWingman()
     {
         if (!this->myWingman_)
             return;
-
+        Vector3* targetRelativePositionOfWingman;
         switch (this->formationMode_){
             case WALL:
             {
-                myWingman_->desiredRelativePosition_ = new Vector3 (-200, 0, 0);   
+                targetRelativePositionOfWingman = new Vector3 (-400, 0, 0);  
                 break;
             }
@@ -78,7 +76,14 @@
             }
         }
+        Quaternion orient = this->getControllableEntity()->getWorldOrientation();
+        
+        Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) + 
+        (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman)));
+        
+        myWingman_->setTargetOrientation(orient);
+        myWingman_->setTargetPosition(targetAbsolutePositionOfWingman);
        
     }
-*/
+
     LeaderController* SectionController::findNewDivisionLeader()
     {
@@ -104,7 +109,4 @@
 
 
-            
-           
-
             float distance = ((it)->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
             
@@ -114,11 +116,5 @@
                 minDistance = distance;
             }
-           /* // is pawn in range?
-            if (distance < RADIUS_TO_SEARCH_FOR_LEADER)
-            {
-
-                if ((it)->setFollower(this))
-                    return (*it);
-            }*/
+          
         }
         if (closestLeader)
@@ -142,6 +138,7 @@
 
         }
-/*        setDesiredPositionOfWingman();
-*/    }
+        setTargetPositionOfWingman();
+
+    }
     /*
     Wingmen and Leaders attack target_, which is a member variable of their classes.
@@ -158,34 +155,15 @@
 
     */
-   /* void SectionController::keepDivisionTick()
-    {
-
-
-        if (this->myDivisionLeader_ && this->myDivisionLeader_->getControllableEntity() && desiredRelativePosition_)
-        {
-
-            Vector3 desiredAbsolutePosition = ((this->myDivisionLeader_->getControllableEntity()->getWorldPosition()) + 
-                (this->myDivisionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
-            this->moveToPosition (desiredAbsolutePosition);
-        }
-    }*/
+    
     void SectionController::tick(float dt)
     {
-        
-
-       /* 
         if (!this->isActive())
             return;
         
-        //--------------------------Stay in division--------------------------
-        this->keepDivisionTick();
-        */
-        //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) 
-        
+        if (this->bHasTargetPosition_)
+        {
+            this->moveToTargetPosition();
+        }
 
-        //orxout(internal_error) << "my Wingman is " << this->myWingman_ << endl;
         
         SUPER(SectionController, tick, dt);
Index: /code/branches/AI_HS15/src/orxonox/controllers/SectionController.h
===================================================================
--- /code/branches/AI_HS15/src/orxonox/controllers/SectionController.h	(revision 10728)
+++ /code/branches/AI_HS15/src/orxonox/controllers/SectionController.h	(revision 10729)
@@ -42,6 +42,8 @@
             SectionController(Context* context);
             virtual ~SectionController();
-            virtual bool setWingman(CommonController* wingman)
+            virtual bool setWingman(CommonController* cwingman)
             {
+                WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);
+
                 if (!this->myWingman_)
                 {
@@ -54,4 +56,5 @@
                 }
             }
+
 
             virtual bool hasWingman()
@@ -69,6 +72,5 @@
 
         protected:
-            void setDesiredPositionOfWingman();
-            void keepDivisionTick();
+            void setTargetPositionOfWingman();
             //A division is the biggest block of spaceships.
             //In division one section is leading, the other one always stays on the same position
Index: /code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- /code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	(revision 10728)
+++ /code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	(revision 10729)
@@ -34,6 +34,6 @@
 
     RegisterClass(WingmanController);
-    static const int RADIUS_TO_SEARCH_FOR_LEADER = 7000;
-    static const float ACTION_INTERVAL = 1.0f;
+    
+
     WingmanController::WingmanController(Context* context) : CommonController(context)
     {
@@ -41,5 +41,4 @@
         this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
         this->myLeader_ = 0;
-        this->desiredRelativePosition_ = 0;
     }
 
@@ -88,5 +87,4 @@
     void WingmanController::action()
     {
-        //this->target_ = this->sectionTarget_;
         if (!this->myLeader_)
         {
@@ -145,19 +143,8 @@
 
      
-    /*void WingmanController::keepSectionTick()
-    {
-        if (this->myLeader_ && this->myLeader_->getControllableEntity())
-                            //orxout(internal_error) << "MOVING" << endl;
-
-        if (this->myLeader_ && this->myLeader_->getControllableEntity() && desiredRelativePosition_)
-        {
-            Vector3 desiredAbsolutePosition = ((this->myLeader_->getControllableEntity()->getWorldPosition()) + 
-                (this->myLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
-            this->moveToPosition (desiredAbsolutePosition);
-        }
-    }*/
+   
     void WingmanController::tick(float dt)
     {   
-       /* //-------------------------------------------------------
+        //-------------------------------------------------------
            
         
@@ -165,6 +152,9 @@
             return;
         //--------------------------Stay in formation--------------------------
-        this->keepSectionTick();*/
-            
+        if (this->bHasTargetPosition_)
+        {
+            //targetPosition_ and targetOrientation_ are set by the Leader in its action()
+            this->moveToTargetPosition();
+        } 
         
         //--------------------------Attack same target as the Leader--------------------------
@@ -175,5 +165,5 @@
             this->doFire();
         }
-*/
+        */
         
         //orxout(internal_error) << "I am " << this << endl;
@@ -190,9 +180,5 @@
     }
 
-//**********************************************NEW
-    /*void WingmanController::defaultBehaviour(float maxrand)
-    {  
-       
-    }*/
+
 
 }
Index: /code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h
===================================================================
--- /code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h	(revision 10728)
+++ /code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h	(revision 10729)
@@ -60,13 +60,9 @@
 
             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:
-            //const float ACTION_INTERVAL;
-            void keepSectionTick();
 
-            //LeaderController* leader_;
 
             Timer actionTimer_; //<! Regularly calls action().
