Index: /code/branches/campaignHS15/data/levels/AITest.oxw
===================================================================
--- /code/branches/campaignHS15/data/levels/AITest.oxw	(revision 10870)
+++ /code/branches/campaignHS15/data/levels/AITest.oxw	(revision 10871)
@@ -35,9 +35,9 @@
     
 <!-- HERE STARTS DEMO FOR THE "WAYPOINTS" -->
-    <!--   
+      <!-- 
     <Model mesh="cube.mesh" scale=8 position="  0,2000,-600" />
-    <Model mesh="cube.mesh" scale=8 position="  0,2000,-700" />
-    <Model mesh="cube.mesh" scale=8 position="100,2000,-700" />
-    <Model mesh="cube.mesh" scale=8 position="100,2000,-600" />
+    <Model mesh="cube.mesh" scale=8 position="  0,2000,-800" />
+    <Model mesh="cube.mesh" scale=8 position="200,2000,-800" />
+    <Model mesh="cube.mesh" scale=8 position="200,2000,-600" />
     <Model mesh="cube.mesh" scale=8 position="0,0,0" />
 
@@ -50,7 +50,7 @@
           <actionpoints>
             <Actionpoint position="  0,2000,-600" action="FLY" loopStart=true/>
-            <Actionpoint position="  0,2000,-700" action="FLY"  />
-            <Actionpoint position="100,2000,-700" action="FLY" />
-            <Actionpoint position="100,2000,-600" action="FLY" loopEnd=true />
+            <Actionpoint position="  0,2000,-800" action="FLY"  />
+            <Actionpoint position="200,2000,-800" action="FLY" />
+            <Actionpoint position="200,2000,-600" action="FLY" loopEnd=true />
           </actionpoints>
         </DivisionController>
@@ -62,5 +62,5 @@
 <!-- HERE STARTS DEMO FOR THE ACTIONPOINTS. 
 P.S. Never set protectMe in the first actionpoint: if human didn't spawn, that actionpoint will be skipped -->
-       <!-- 
+       
     <Model mesh="cube.mesh" scale=8 position="0,0,0" />
 
@@ -123,5 +123,5 @@
       </templates>
     </SpaceShip> 
-  -->
+ 
    
 <!-- HERE ENDS DEMO FOR THE ACTIONPOINTS -->
@@ -210,5 +210,5 @@
 <!-- HERE ENDS DEMO FOR FIGHTING -->
 <!-- HERE STARTS DEMO FOR FORMATIONS -->
-    
+    <!-- 
     <Model mesh="cube.mesh" scale=8 position="   0,2000,    0" />
     <Model mesh="cube.mesh" scale=8 position="   0,2000,-2000" />
@@ -259,5 +259,5 @@
       </controller>
     </SpaceShip> 
-   
+    -->
 <!-- HERE ENDS DEMO FOR FORMATIONS -->
     
Index: /code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc	(revision 10870)
+++ /code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc	(revision 10871)
@@ -39,5 +39,5 @@
 
     //CommonController contains all common functionality of AI Controllers
-    ActionpointController::ActionpointController(Context* context) : CommonController(context)
+    ActionpointController::ActionpointController(Context* context) : FightingController(context)
     {
               this->bInLoop_ = false;
@@ -87,5 +87,6 @@
     ActionpointController::~ActionpointController()
     {
-      parsedActionpoints_.clear();
+        loopActionpoints_.clear();
+        parsedActionpoints_.clear();
         actionpoints_.clear();
     }
Index: /code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h	(revision 10870)
+++ /code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h	(revision 10871)
@@ -30,5 +30,5 @@
 #define _ActionpointController_H__
 
-#include "controllers/CommonController.h"
+#include "controllers/FightingController.h"
 
 
@@ -51,5 +51,5 @@
     } ;
 
-    class _OrxonoxExport ActionpointController : public CommonController
+    class _OrxonoxExport ActionpointController : public FightingController
     {
         public:
@@ -95,4 +95,6 @@
                 void setProtect (ControllableEntity* protect);
                 ControllableEntity* getProtect (); 
+                WeakPtr<ControllableEntity> protect_;     
+
                 void setClosestTarget();
                 Pawn* closestTarget();
Index: /code/branches/campaignHS15/src/orxonox/controllers/CMakeLists.txt
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/CMakeLists.txt	(revision 10870)
+++ /code/branches/campaignHS15/src/orxonox/controllers/CMakeLists.txt	(revision 10871)
@@ -17,3 +17,5 @@
   CommonController.cc
   ActionpointController.cc
+  FlyingController.cc
+  FightingController.cc
 )
Index: /code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	(revision 10870)
+++ /code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	(revision 10871)
@@ -39,10 +39,4 @@
 #include "controllers/DroneController.h"
 
-//Today, on 25th of November, 2015, I hereby officially declare my code a huge pack of bullshit that I do not understand.
-//#Almost2KLines
-//#SpaghettiCode
-//#ISworeiWouldNever
-//#ItAllStartedSoWell
-
 namespace orxonox
 {
@@ -52,24 +46,9 @@
     const float ROTATEFACTOR = 1.0f/0.02f;
 
-    //Table of content:
-    //Constructor, Destructor & tick
-    //XML methods
-    //World interaction
-    //Helper methods
-    //Flying methods
-    //Fighting methods
-    //Actionpoint methods
-
-
-    //------------------------------------------------------------------------------
-    //------------------------Constructor, Destructor & tick------------------------
-    //------------------------------------------------------------------------------
-    
+  
     CommonController::CommonController( Context* context ): Controller( context )
     {
         this->bFirstTick_ = true;
-        this->tolerance_ = 50;
-        this->stopLookingAtTarget();
-        this->attackRange_ = 2500;
+       
         RegisterObject( CommonController );
 
@@ -85,55 +64,10 @@
     }
 
-    //------------------------------------------------------------------------------
-    //----------------------------------XML methods---------------------------------
-    //------------------------------------------------------------------------------
-    
+      
     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 == "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::WALL:
-            { return "WALL"; break; }
-            case FormationMode::FINGER4:
-            { return "FINGER4"; break; }
-            case FormationMode::DIAMOND:
-            { return "DIAMOND"; break; }
-            default:
-                return "DIAMOND"; break;
-        }
-    }
-    void CommonController::setFormationMode(FormationMode::Value val)
-    { 
-        this->formationMode_ = val; 
-    }
-    FormationMode::Value CommonController::getFormationMode() const
-    { 
-        return this->formationMode_; 
-    }
-    
-    //------------------------------------------------------------------------------
-    //-------------------------------World interaction------------------------------
-    //------------------------------------------------------------------------------
-
+    }
+ 
     //"Virtual" methods
     bool CommonController::setWingman ( CommonController* wingman )
@@ -141,19 +75,4 @@
     bool CommonController::hasWingman() 
     { return true; }
-    bool CommonController::hasTarget() 
-    {
-        if ( this->target_ )
-            return true;
-        return false;
-    }
-    ControllableEntity* CommonController::getTarget()
-    {
-        return this->target_;
-    }
-  
-
-    //------------------------------------------------------------------------------
-    //--------------------------------Helper methods--------------------------------
-    //------------------------------------------------------------------------------
 
     float CommonController::randomInRange( float a, float b )
@@ -300,295 +219,5 @@
         return name;
     }
-    float CommonController::squaredDistanceToTarget()  const
-    {
-        if ( !this->getControllableEntity()  )
-            return 0;
-        if ( !this->target_ || !this->getControllableEntity() )
-            return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->targetPosition_ ) );
-        else
-            return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->positionOfTarget_ ) );
-    }
-    bool CommonController::isLookingAtTarget( float angle )
-    {
-        if ( !this->getControllableEntity()  || !this->target_ )
-            return false;
-        return this->isLooking(this->getControllableEntity(), this->getTarget(), angle);
-    }
-
-
-    //------------------------------------------------------------------------------
-    //--------------------------------Flying methods--------------------------------
-    //------------------------------------------------------------------------------
-
-    void CommonController::stopMoving()
-    {
-        this->bHasTargetPosition_ = false;
-    }
-    void CommonController::stopLookingAtTarget()
-    {
-        this->bLookAtTarget_ = false;
-    }
-    void CommonController::startLookingAtTarget()
-    {
-        this->bLookAtTarget_ = true;
-    }
-    void CommonController::moveToPosition( const Vector3& target, float dt )
-    {
-        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();
-        float rotateX = -clamp( coord.x * 10, -1.0f, 1.0f );
-        float rotateY = clamp( coord.y * 10, -1.0f, 1.0f );
-
-        if ( distance > this->tolerance_ )
-        {
-            this->getControllableEntity() ->rotateYaw( ROTATEFACTOR * rotateX * dt );
-            this->getControllableEntity() ->rotatePitch( ROTATEFACTOR * rotateY * dt );
-
-            if ( distance < 300 )
-            {
-                if ( bHasTargetOrientation_ )
-                {
-                    copyTargetOrientation( dt );
-                }
-            }
-            if (distance > this->tolerance_*1.5f || (rotateX > -0.01 && rotateX < 0.01 && rotateY > -0.01 && rotateY < 0.01))
-                this->getControllableEntity() ->moveFrontBack( SPEED * dt );
-        }
-        else
-        {      
-            bHasTargetPosition_ = false;
-            bHasTargetOrientation_ = false;
-        }
-    }
-    void CommonController::moveToTargetPosition(float dt)
-    {
-        this->moveToPosition (this->targetPosition_, dt);
-    }
-    void CommonController::copyOrientation( const Quaternion& orient, float dt )
-    {
-        //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*0.2f*ROTATEFACTOR * dt );
-    }
-    void CommonController::copyTargetOrientation( float dt )
-    {
-        if ( bHasTargetOrientation_ )
-        {   
-            copyOrientation( targetOrientation_, dt );
-        }
-    }
-    void CommonController::lookAtTarget(float dt)
-    {
-        ControllableEntity* entity = this->getControllableEntity();
-        if ( !entity )
-            return;
-        Vector2 coord = get2DViewCoordinates
-            ( entity->getPosition() , 
-            entity->getOrientation()  * WorldEntity::FRONT, 
-            entity->getOrientation()  * WorldEntity::UP, 
-            positionOfTarget_ );
-
-        //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 ); 
-   
-        //Yaw and Pitch are enough to start facing the target
-        this->getControllableEntity() ->rotateYaw( ROTATEFACTOR * rotateX * dt );
-        this->getControllableEntity() ->rotatePitch( ROTATEFACTOR * rotateY * dt );
-    }
-    void CommonController::setTargetPosition( const Vector3& target )
-    {
-        this->targetPosition_ = target;
-        this->bHasTargetPosition_ = true;
-    }
-
-    void CommonController::setTargetOrientation( const Quaternion& orient )
-    {
-        this->targetOrientation_=orient;
-        this->bHasTargetOrientation_=true;
-    }
-
-    void CommonController::setTargetOrientation( ControllableEntity* target )
-    {
-        if ( target )
-            setTargetOrientation( target->getOrientation() );
-    }
-
-    //------------------------------------------------------------------------------
-    //-------------------------------Fighting methods-------------------------------
-    //------------------------------------------------------------------------------
-
-    void CommonController::setTarget( ControllableEntity* target )
-    {
-        this->target_ = target;        
-        if ( this->target_ )
-        {
-            this->setPositionOfTarget( target_->getWorldPosition() );
-        }
-    }
-    void CommonController::setPositionOfTarget( const Vector3& target )
-    {
-        this->positionOfTarget_ = target;
-        this->bHasPositionOfTarget_ = true;
-    }
-    void CommonController::setOrientationOfTarget( const Quaternion& orient )
-    {
-        this->orientationOfTarget_=orient;
-        this->bHasOrientationOfTarget_=true;
-    }
-    
-    void CommonController::maneuver() 
-    {
-        maneuverCounter_++;
-        if (maneuverCounter_ > 5)
-            maneuverCounter_ = 0;
-
-        if ( !this->target_ || !this->getControllableEntity())
-            return;
-        
-        Vector3 thisPosition = this->getControllableEntity()->getWorldPosition();
-        this->setPositionOfTarget( getPredictedPosition( 
-            thisPosition, 
-            hardcoded_projectile_speed, 
-            this->target_->getWorldPosition() , 
-            this->target_->getVelocity()  
-            )  );
-        this->setOrientationOfTarget( this->target_->getOrientation() );
-
-        Vector3 diffVector = this->positionOfTarget_ - thisPosition;
-        float diffLength = diffVector.length();
-        Vector3 diffUnit = diffVector/diffLength;
-
-        bool bTargetIsLookingAtThis = this->isLooking ( this->target_, getControllableEntity(), math::pi/10.0f );
-        
-        //too far? well, come closer then
-        if ( diffLength > this->attackRange_ )
-        {
-            this->setTargetPosition( this->positionOfTarget_ );
-        }
-        //too close? How do u expect to dodge anything? Just attack!
-        else if ( diffLength < 500 )
-        {   
-            //at this point, just look and shoot
-            if ( diffLength < 250 )
-            {
-                this->stopMoving();
-                this->startLookingAtTarget();
-            }
-            else
-            {
-                this->setTargetPosition( this->positionOfTarget_ );
-            }
-        }
-        //Good distance? Check if target looks at us. It doesn't? Go hunt!
-        else if ( !bTargetIsLookingAtThis )
-        {
-            this->setTargetPosition( this->positionOfTarget_ );
-        }
-        //That's unfortunate, he is looking and probably shooting... try to dodge what we can...  
-        else 
-        {   
-            if (maneuverCounter_ == 0)
-            {
-                this->setTargetPosition( this->positionOfTarget_ );   
-                return;
-            }
-            dodge( thisPosition, diffUnit );
-        }
-    }
-    
-    void CommonController::dodge(Vector3& thisPosition, Vector3& diffUnit)
-    {
-        float factorX = 0, factorY = 0, factorZ = 0;
-        float rand = randomInRange (0, 1);
-    
-        if (rand <= 0.5)
-        { factorX = 1; }
-        else
-        { factorX = -1; }
-        rand = randomInRange (0, 1);
-        if (rand <= 0.5)
-        { factorY = 1; }
-        else
-        { factorY = -1; }
-        rand = randomInRange (0, 1);
-        if (rand <= 0.5)
-        { factorZ = 1; }
-        else
-        { factorZ = -1; }
-
-        Vector3 target = ( diffUnit )* 8000.0f;
-        Vector3* randVector = new Vector3( 
-            factorX * randomInRange( 10000, 40000 ), 
-            factorY * randomInRange( 10000, 40000 ), 
-            factorZ * randomInRange( 10000, 40000 ) 
-        );
-        Vector3 projection = randVector->dotProduct( diffUnit )* diffUnit;
-        *randVector -= projection;
-        target += *randVector;
-        this->setTargetPosition( thisPosition + target );
-    }
-    bool CommonController::canFire() 
-    {
-        //no target? why fire?
-        if ( !this->target_ )
-            return false;
-
-        Vector3 newPositionOfTarget = getPredictedPosition( this->getControllableEntity() ->getWorldPosition() , 
-            hardcoded_projectile_speed, this->target_->getWorldPosition() , this->target_->getVelocity() );
-        if ( newPositionOfTarget != Vector3::ZERO )
-        {
-            this->setPositionOfTarget( newPositionOfTarget );
-        }
-
-        float squaredDistance = squaredDistanceToTarget();
-
-        if ( squaredDistance < this->attackRange_*this->attackRange_ && this->isLookingAtTarget( math::pi / 20.0f)) 
-        {
-            return true;
-        }
-        else
-        {
-            return false;
-        }
-    }
-    void CommonController::doFire() 
-    {
-        if ( !this->target_ || !this->getControllableEntity() )
-        {
-            return;
-        }
-      
-        Pawn* pawn = orxonox_cast<Pawn*>( this->getControllableEntity() );
-
-        if ( pawn )
-            pawn->setAimPosition( this->positionOfTarget_ );
-        this->getControllableEntity() ->fire( 0 );
-    }
-
-
-    
-    void CommonController::boostControl()
-    {
-        SpaceShip* ship = orxonox_cast<SpaceShip*>(this->getControllableEntity());
-        if(ship == NULL) return;
-        if(ship->getBoostPower()*1.5f > ship->getInitialBoostPower() ) //upper limit ->boost
-        {
-
-            this->getControllableEntity()->boost(true);
-        }
-        else if(ship->getBoostPower()*4.0f < ship->getInitialBoostPower()) //lower limit ->do not boost
-        {
-           this->getControllableEntity()->boost(false);
-        }
-    }
+  
+
 }
Index: /code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	(revision 10870)
+++ /code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	(revision 10871)
@@ -45,17 +45,4 @@
 namespace orxonox
 {
-
-    namespace FormationMode
-    {
-        enum Value
-        {
-            FINGER4, DIAMOND, WALL
-        };
-    }
-
-
-    
- 
-
     class _OrxonoxExport CommonController : public Controller, public Tickable
     {
@@ -70,105 +57,22 @@
             virtual void tick(float dt); 
 
-            //----[XML methods]----
-                virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
                 
-                void setFormationModeXML(std::string val);
-                std::string getFormationModeXML();
-                void setFormationMode(FormationMode::Value val);
-                FormationMode::Value getFormationMode() const;
-
-               
-
-            //----[/XML methods]----
-
-            //----[Interaction with other Controllers]----
-                virtual bool setWingman(CommonController* wingman);
-                virtual bool hasWingman();        
-                
-                bool hasTarget();
-                ControllableEntity* getTarget();
-                      
-             //----[/Interaction with other Controllers]----
-
-            //----[Helper methods]----
-                float randomInRange(float a, float b);
-                static float distance(ControllableEntity* entity1, ControllableEntity* entity2);
-                static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt);
-                static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ;
-                static std::string getName( Pawn* entity ) ;
-
-                float squaredDistanceToTarget() const;
-                bool isLookingAtTarget(float angle);
-            //----[/Helper methods]----
-
-  
-        protected:
-            //----[Flying methods]----
-                void stopMoving();
-                void stopLookingAtTarget();
-                void startLookingAtTarget();
-
-                void moveToPosition(const Vector3& target, float dt);
-                void moveToTargetPosition(float dt);
-
-                void copyOrientation(const Quaternion& orient, float dt);
-                void copyTargetOrientation(float dt);
-
-                void lookAtTarget(float dt);
-
-                void setTargetPosition(const Vector3& target);
-                void setTargetOrientation(const Quaternion& orient);
-                void setTargetOrientation(ControllableEntity* target);
-                virtual void boostControl();
 
 
-            //----[/Flying methods]----
-            
-            //----[Fighting methods]----
-                void setTarget(ControllableEntity* target);
-
-                void setPositionOfTarget(const Vector3& target);
-                void setOrientationOfTarget(const Quaternion& orient);
+            virtual bool setWingman(CommonController* wingman);
+            virtual bool hasWingman();        
 
 
-                void maneuver();
-                void dodge(Vector3& thisPosition, Vector3& diffUnit);
-                bool canFire();
-                void doFire();
+            float randomInRange(float a, float b);
+            static float distance(ControllableEntity* entity1, ControllableEntity* entity2);
+            static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt);
+            static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ;
+            static std::string getName( Pawn* entity ) ;
 
-            //----[/Fighting methods]----            
+        protected:
+           
+            bool bFirstTick_; 
             
-            //----[where-to-fly information]----
-                
-                bool bHasTargetPosition_;
-                Vector3 targetPosition_;
-                bool bHasTargetOrientation_;
-                Quaternion targetOrientation_;
-                
-            //----[/where-to-fly information]----
-            //----[protect information]----
-                WeakPtr<ControllableEntity> protect_;
-            //----[/protect information]----
-            //----[who-to-kill information]----
-                WeakPtr<ControllableEntity> target_;
-               
-                bool bHasPositionOfTarget_;
-                Vector3 positionOfTarget_;
-                bool bHasOrientationOfTarget_;
-                Quaternion orientationOfTarget_;
-            //----[/who-to-kill information]----
-
-
-            //----["Private" variables]----
-                FormationMode::Value formationMode_;
-
-                int attackRange_;
-                bool bLookAtTarget_;        
-                bool bShooting_;
-                int maneuverCounter_;
-                int tolerance_; 
-                bool bFirstTick_; 
-            
-            //----[/"Private" variables]----    
            
     };
Index: /code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc	(revision 10871)
+++ /code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc	(revision 10871)
@@ -0,0 +1,280 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or ( at your option )any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      Dominik Solenicki
+ *
+ */
+#include "controllers/FightingController.h"
+#include "core/XMLPort.h"
+#include <limits>								//for finding closest target
+
+
+namespace orxonox
+{
+
+    RegisterClass (FightingController);
+    
+    FightingController::FightingController( Context* context ): FlyingController( context )
+    {
+    	this->attackRange_ = 2500;
+        this->stopLookingAtTarget();
+
+        RegisterObject( FightingController );
+    }
+    FightingController::~FightingController() 
+    {
+        
+    }
+    void FightingController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
+    {
+        SUPER( FightingController, XMLPort, xmlelement, mode );
+    }
+    void FightingController::lookAtTarget(float dt)
+    {
+        ControllableEntity* entity = this->getControllableEntity();
+        if ( !entity )
+            return;
+        Vector2 coord = get2DViewCoordinates
+            ( entity->getPosition() , 
+            entity->getOrientation()  * WorldEntity::FRONT, 
+            entity->getOrientation()  * WorldEntity::UP, 
+            positionOfTarget_ );
+
+        //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 ); 
+   
+        //Yaw and Pitch are enough to start facing the target
+        this->getControllableEntity() ->rotateYaw( ROTATEFACTOR * rotateX * dt );
+        this->getControllableEntity() ->rotatePitch( ROTATEFACTOR * rotateY * dt );
+    }
+    void FightingController::stopLookingAtTarget()
+    {
+        this->bLookAtTarget_ = false;
+    }
+    void FightingController::startLookingAtTarget()
+    {
+        this->bLookAtTarget_ = true;
+    }
+    bool FightingController::hasTarget() 
+    {
+        if ( this->target_ )
+            return true;
+        return false;
+    }
+
+    void FightingController::setTarget( ControllableEntity* target )
+    {
+        this->target_ = target;        
+        if ( this->target_ )
+        {
+            this->setPositionOfTarget( target_->getWorldPosition() );
+        }
+    }
+    void FightingController::setPositionOfTarget( const Vector3& target )
+    {
+        this->positionOfTarget_ = target;
+        this->bHasPositionOfTarget_ = true;
+    }
+    void FightingController::setOrientationOfTarget( const Quaternion& orient )
+    {
+        this->orientationOfTarget_=orient;
+        this->bHasOrientationOfTarget_=true;
+    }
+    
+    void FightingController::maneuver() 
+    {
+        maneuverCounter_++;
+        if (maneuverCounter_ > 5)
+            maneuverCounter_ = 0;
+
+        if ( !this->target_ || !this->getControllableEntity())
+            return;
+        
+        Vector3 thisPosition = this->getControllableEntity()->getWorldPosition();
+        this->setPositionOfTarget( getPredictedPosition( 
+            thisPosition, 
+            hardcoded_projectile_speed, 
+            this->target_->getWorldPosition() , 
+            this->target_->getVelocity()  
+            )  );
+        this->setOrientationOfTarget( this->target_->getOrientation() );
+
+        Vector3 diffVector = this->positionOfTarget_ - thisPosition;
+        float diffLength = diffVector.length();
+        Vector3 diffUnit = diffVector/diffLength;
+
+        bool bTargetIsLookingAtThis = this->isLooking ( this->target_, getControllableEntity(), math::pi/10.0f );
+        
+        //too far? well, come closer then
+        if ( diffLength > this->attackRange_ )
+        {
+            this->setTargetPosition( this->positionOfTarget_ );
+        }
+        //too close? How do u expect to dodge anything? Just attack!
+        else if ( diffLength < 500 )
+        {   
+            //at this point, just look and shoot
+            if ( diffLength < 250 )
+            {
+                this->stopMoving();
+                this->startLookingAtTarget();
+            }
+            else
+            {
+                this->setTargetPosition( this->positionOfTarget_ );
+            }
+        }
+        //Good distance? Check if target looks at us. It doesn't? Go hunt!
+        else if ( !bTargetIsLookingAtThis )
+        {
+            this->setTargetPosition( this->positionOfTarget_ );
+        }
+        //That's unfortunate, he is looking and probably shooting... try to dodge what we can...  
+        else 
+        {   
+            if (maneuverCounter_ == 0)
+            {
+                this->setTargetPosition( this->positionOfTarget_ );   
+                return;
+            }
+            dodge( thisPosition, diffUnit );
+        }
+    }
+    
+    void FightingController::dodge(Vector3& thisPosition, Vector3& diffUnit)
+    {
+        float factorX = 0, factorY = 0, factorZ = 0;
+        float rand = randomInRange (0, 1);
+    
+        if (rand <= 0.5)
+        { factorX = 1; }
+        else
+        { factorX = -1; }
+        rand = randomInRange (0, 1);
+        if (rand <= 0.5)
+        { factorY = 1; }
+        else
+        { factorY = -1; }
+        rand = randomInRange (0, 1);
+        if (rand <= 0.5)
+        { factorZ = 1; }
+        else
+        { factorZ = -1; }
+
+        Vector3 target = ( diffUnit )* 8000.0f;
+        Vector3* randVector = new Vector3( 
+            factorX * randomInRange( 10000, 40000 ), 
+            factorY * randomInRange( 10000, 40000 ), 
+            factorZ * randomInRange( 10000, 40000 ) 
+        );
+        Vector3 projection = randVector->dotProduct( diffUnit )* diffUnit;
+        *randVector -= projection;
+        target += *randVector;
+        this->setTargetPosition( thisPosition + target );
+    }
+    bool FightingController::canFire() 
+    {
+        //no target? why fire?
+        if ( !this->target_ )
+            return false;
+
+        Vector3 newPositionOfTarget = getPredictedPosition( this->getControllableEntity() ->getWorldPosition() , 
+            hardcoded_projectile_speed, this->target_->getWorldPosition() , this->target_->getVelocity() );
+        if ( newPositionOfTarget != Vector3::ZERO )
+        {
+            this->setPositionOfTarget( newPositionOfTarget );
+        }
+
+        float squaredDistance = squaredDistanceToTarget();
+
+        if ( squaredDistance < this->attackRange_*this->attackRange_ && this->isLookingAtTarget( math::pi / 20.0f)) 
+        {
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+    void FightingController::doFire() 
+    {
+        if ( !this->target_ || !this->getControllableEntity() )
+        {
+            return;
+        }
+      
+        Pawn* pawn = orxonox_cast<Pawn*>( this->getControllableEntity() );
+
+        if ( pawn )
+            pawn->setAimPosition( this->positionOfTarget_ );
+        this->getControllableEntity() ->fire( 0 );
+    }
+    float FightingController::squaredDistanceToTarget()  const
+    {
+        if ( !this->getControllableEntity()  )
+            return 0;
+        if ( !this->target_ || !this->getControllableEntity() )
+            return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->targetPosition_ ) );
+        else
+            return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->positionOfTarget_ ) );
+    }
+    bool FightingController::isLookingAtTarget( float angle )
+    {
+        if ( !this->getControllableEntity()  || !this->target_ )
+            return false;
+        return this->isLooking(this->getControllableEntity(), this->getTarget(), angle);
+    }
+        void FightingController::setClosestTarget()
+    {
+        this->setTarget (static_cast<ControllableEntity*>( closestTarget() ) ); 
+    }
+    
+    Pawn* FightingController::closestTarget()
+    {
+        if (!this->getControllableEntity())
+            return 0;
+
+        Pawn* closestTarget = 0;
+        float minDistance =  std::numeric_limits<float>::infinity();
+        Gametype* gt = this->getGametype();
+        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+        {
+            if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP), gt) )
+                continue;
+
+            float distance = CommonController::distance (*itP, this->getControllableEntity());
+            if (distance < minDistance)
+            {
+                closestTarget = *itP;
+                minDistance = distance;
+            }
+        }
+        if (closestTarget)
+        {
+           return closestTarget;
+        } 
+        return 0;  
+    }
+}
Index: /code/branches/campaignHS15/src/orxonox/controllers/FightingController.h
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/FightingController.h	(revision 10871)
+++ /code/branches/campaignHS15/src/orxonox/controllers/FightingController.h	(revision 10871)
@@ -0,0 +1,84 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _FightingController_H__
+#define _FightingController_H__
+
+
+#include "controllers/FlyingController.h"
+
+namespace orxonox
+{
+
+   
+
+    class _OrxonoxExport FightingController : public FlyingController
+    {
+
+        public:
+            FightingController(Context* context);
+            virtual ~FightingController();
+            
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+       
+            float squaredDistanceToTarget() const;
+            bool isLookingAtTarget(float angle);
+            bool hasTarget();
+            ControllableEntity* getTarget()
+                { return this->target_; }
+           
+        protected:
+            void setTarget(ControllableEntity* target);
+
+            void setPositionOfTarget(const Vector3& target);
+            void setOrientationOfTarget(const Quaternion& orient);
+            void stopLookingAtTarget();
+            void startLookingAtTarget();
+            void lookAtTarget(float dt);
+
+            void maneuver();
+            void dodge(Vector3& thisPosition, Vector3& diffUnit);
+            bool canFire();
+            void doFire();
+            WeakPtr<ControllableEntity> target_;
+            void setClosestTarget();
+         
+            bool bHasPositionOfTarget_;
+            Vector3 positionOfTarget_;
+            bool bHasOrientationOfTarget_;
+            Quaternion orientationOfTarget_;
+            Pawn* closestTarget();
+
+            int attackRange_;
+            bool bShooting_;
+            int maneuverCounter_;   
+            bool bLookAtTarget_;           
+    };
+}
+
+#endif /* _FightingController_H__ */
Index: /code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc	(revision 10871)
+++ /code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc	(revision 10871)
@@ -0,0 +1,177 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or ( at your option )any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      Dominik Solenicki
+ *
+ */
+#include "controllers/FlyingController.h"
+#include "core/XMLPort.h"
+#include "worldentities/pawns/SpaceShip.h"
+
+namespace orxonox
+{    
+    RegisterClass (FlyingController);
+    
+    FlyingController::FlyingController( Context* context ): CommonController( context )
+    {
+        this->spread_ = 200;
+        this->tolerance_ = 80;
+        RegisterObject( FlyingController );
+    }
+    FlyingController::~FlyingController() 
+    {
+
+    }
+    void FlyingController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
+    {
+        XMLPortParam( FlyingController, "spread", setSpread, getSpread,  xmlelement, mode );
+        XMLPortParam( FlyingController, "formationMode", setFormationModeXML, getFormationModeXML,  xmlelement, mode );
+        SUPER( FlyingController, XMLPort, xmlelement, mode );
+    }
+   
+    void FlyingController::setFormationModeXML( std::string val )
+    {
+        const std::string valUpper = getUppercase( val );
+        FormationMode::Value value;
+        
+        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 FlyingController::getFormationModeXML() 
+    {
+        switch ( this->formationMode_ )
+        {
+            case FormationMode::WALL:
+            { return "WALL"; break; }
+            case FormationMode::FINGER4:
+            { return "FINGER4"; break; }
+            case FormationMode::DIAMOND:
+            { return "DIAMOND"; break; }
+            default:
+                return "DIAMOND"; break;
+        }
+    }
+
+    
+
+    void FlyingController::stopMoving()
+    {
+        this->bHasTargetPosition_ = false;
+    }
+
+    void FlyingController::moveToPosition( const Vector3& target, float dt )
+    {
+        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();
+        float rotateX = -clamp( coord.x * 10, -1.0f, 1.0f );
+        float rotateY = clamp( coord.y * 10, -1.0f, 1.0f );
+
+        if ( distance > this->tolerance_ )
+        {
+            this->getControllableEntity() ->rotateYaw( ROTATEFACTOR * rotateX * dt );
+            this->getControllableEntity() ->rotatePitch( ROTATEFACTOR * rotateY * dt );
+
+            if ( distance < 300 )
+            {
+                if ( bHasTargetOrientation_ )
+                {
+                    copyTargetOrientation( dt );
+                }
+            }
+            if (distance > this->tolerance_*1.5f || (rotateX > -0.01 && rotateX < 0.01 && rotateY > -0.01 && rotateY < 0.01))
+                this->getControllableEntity() ->moveFrontBack( SPEED * dt );
+        }
+        else
+        {      
+            bHasTargetPosition_ = false;
+            bHasTargetOrientation_ = false;
+        }
+    }
+    void FlyingController::moveToTargetPosition(float dt)
+    {
+        this->moveToPosition (this->targetPosition_, dt);
+    }
+    void FlyingController::copyOrientation( const Quaternion& orient, float dt )
+    {
+        //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*0.2f*ROTATEFACTOR * dt );
+    }
+    void FlyingController::copyTargetOrientation( float dt )
+    {
+        if ( bHasTargetOrientation_ )
+        {   
+            copyOrientation( targetOrientation_, dt );
+        }
+    }
+    
+    void FlyingController::setTargetPosition( const Vector3& target )
+    {
+        this->targetPosition_ = target;
+        this->bHasTargetPosition_ = true;
+    }
+
+    void FlyingController::setTargetOrientation( const Quaternion& orient )
+    {
+        this->targetOrientation_=orient;
+        this->bHasTargetOrientation_=true;
+    }
+
+    void FlyingController::setTargetOrientation( ControllableEntity* target )
+    {
+        if ( target )
+            setTargetOrientation( target->getOrientation() );
+    }
+    void FlyingController::boostControl()
+    {
+        SpaceShip* ship = orxonox_cast<SpaceShip*>(this->getControllableEntity());
+        if(ship == NULL) return;
+        if(ship->getBoostPower()*1.5f > ship->getInitialBoostPower() ) //upper limit ->boost
+        {
+
+            this->getControllableEntity()->boost(true);
+        }
+        else if(ship->getBoostPower()*4.0f < ship->getInitialBoostPower()) //lower limit ->do not boost
+        {
+           this->getControllableEntity()->boost(false);
+        }
+    }
+    
+}
Index: /code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h	(revision 10871)
+++ /code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h	(revision 10871)
@@ -0,0 +1,95 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _FlyingController_H__
+#define _FlyingController_H__
+
+
+#include "controllers/CommonController.h"
+
+namespace orxonox
+{   
+    const float SPEED = 0.9f/0.02f;
+    const float ROTATEFACTOR = 1.0f/0.02f;
+    namespace FormationMode
+    {
+        enum Value
+        {
+            FINGER4, DIAMOND, WALL
+        };
+    }
+
+    
+
+    class _OrxonoxExport FlyingController : public CommonController
+    {
+
+        public:
+            FlyingController(Context* context);
+            virtual ~FlyingController();
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+
+            void setSpread (int spread)
+                { this->spread_ = spread; }
+            int getSpread ()
+                { return this->spread_; }
+
+            void setFormationModeXML(std::string val);
+            std::string getFormationModeXML();
+
+            void setFormationMode(FormationMode::Value val)
+                { this->formationMode_ = val; }
+            FormationMode::Value getFormationMode() const
+                { return this->formationMode_; }
+
+        protected:
+            void stopMoving();
+
+            void moveToPosition(const Vector3& target, float dt);
+            void moveToTargetPosition(float dt);
+
+            void copyOrientation(const Quaternion& orient, float dt);
+            void copyTargetOrientation(float dt);
+
+            void setTargetPosition(const Vector3& target);
+            void setTargetOrientation(const Quaternion& orient);
+            void setTargetOrientation(ControllableEntity* target);
+            virtual void boostControl();        
+            FormationMode::Value formationMode_;
+          
+  
+            bool bHasTargetPosition_;
+            Vector3 targetPosition_;
+            bool bHasTargetOrientation_;
+            Quaternion targetOrientation_; 
+            int spread_;
+            int tolerance_; 
+    };
+}
+
+#endif /* _FlyingController_H__ */
