Index: /code/branches/campaignHS15/data/levels/AITest.oxw
===================================================================
--- /code/branches/campaignHS15/data/levels/AITest.oxw	(revision 10850)
+++ /code/branches/campaignHS15/data/levels/AITest.oxw	(revision 10851)
@@ -62,17 +62,43 @@
       </controller>
     </SpaceShip> -->
-    <SpaceShip position="-2000, 1500, -1000" lookat="0,0,0" team=1 name="ss2">
+    <SpaceShip position="-2000, 1500, -1000" lookat="0,0,0" team=0 name="ss2">
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <DivisionController team=1>
+        <DivisionController team=0>
           <actionpoints>
+            <Actionpoint position="-1000,750,-500" action="FLY" />
+            <Actionpoint position="-1000,750,-500" action="ATTACK" enemy="ss3" />
             <Actionpoint position="-1000,750,-500" action="PROTECt" protect="fuck" />
-            <Actionpoint position="-1000,750,-500" action="ATTACK" enemy="ss3" />
-            <Actionpoint position="-1000,750,-500" action="FLY" />
-            <Actionpoint position="0,0,0" action="FLY" />
           </actionpoints>
         </DivisionController>
+      </controller>
+    </SpaceShip>
+    <SpaceShip position="-2000, 1800, -1000" lookat="0,0,0" team=0>
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <WingmanController team=0>
+        </WingmanController>
+      </controller>
+    </SpaceShip>
+    <SpaceShip position="-2000, 2100, -1000" lookat="0,0,0" team=0>
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <WingmanController team=0>
+        </WingmanController>
+      </controller>
+    </SpaceShip>
+    <SpaceShip position="-2000, 2400, -1000" lookat="0,0,0" team=0>
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <SectionController team=0>
+        </SectionController>
       </controller>
     </SpaceShip>
@@ -87,5 +113,5 @@
       </templates>
     </SpaceShip>
-    <SpaceShip position="-500, -300, -300" lookat="0,0,0" team=1 name="fuck">
+    <SpaceShip position="-500, -300, -300" lookat="0,0,0" team=0 name="fuck">
       <templates>
         <Template link=spaceshipassff />
Index: /code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	(revision 10850)
+++ /code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	(revision 10851)
@@ -26,17 +26,8 @@
  *
  */
-//bug or feature? Press 4 control keys from {Q,W,E,A,S,D,C} at the same time or 3 keys from {Q,E,A,D}, spaceship goes in free fly mode
 #include "controllers/CommonController.h"
 #include "core/XMLPort.h"
 
-#include "weaponsystem/WeaponMode.h"
-#include "weaponsystem/WeaponPack.h"
-#include "weaponsystem/Weapon.h"
-#include "weaponsystem/WeaponSlot.h"
-#include "weaponsystem/WeaponSlot.h"
-#include "worldentities/pawns/SpaceShip.h"
-
-#include "Scene.h"
-
+//stuff for sameTeam function
 #include "worldentities/pawns/TeamBaseMatchBase.h"
 #include "gametypes/TeamDeathmatch.h"
@@ -56,20 +47,66 @@
     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->squaredaccuracy_ = 500;
+        this->squaredaccuracy_ = 10000;
+        this->bFirstTick_ = true;
+        this->tolerance_ = 65;
         this->action_ = Action::NONE;
         this->stopLookingAtTarget();
-        this->attackRange_ = 800;
+        this->attackRange_ = 2500;
         RegisterObject( CommonController );
     }
-
-
     CommonController::~CommonController() 
     {
-        //orxout(internal_error) << "I died, my Rank is " << rank_ << endl;
-    }
+        for (size_t i = 0; i < this->actionpoints_.size(); ++i)
+        {
+            if(this->actionpoints_[i])
+                this->actionpoints_[i]->destroy();
+        }
+        this->parsedActionpoints_.clear();
+        this->actionpoints_.clear();
+    }
+    void CommonController::tick(float dt)
+    {
+        if (this->bHasTargetPosition_)
+        {
+            this->moveToTargetPosition(dt);
+        }
+        else if (this->bLookAtTarget_)
+        {
+            this->lookAtTarget(dt);
+        }
+        if (bShooting_)
+        {
+            this->doFire();
+        }
+        if (this->bFirstTick_)
+        {
+            std::reverse(parsedActionpoints_.begin(), parsedActionpoints_.end());
+            std::reverse(actionpoints_.begin(), actionpoints_.end());
+        }
+        if (this->bFirstTick_)
+            this->bFirstTick_ = false;
+        SUPER(CommonController, tick, dt);
+    }
+
+    //------------------------------------------------------------------------------
+    //----------------------------------XML methods---------------------------------
+    //------------------------------------------------------------------------------
     
-  
     void CommonController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
     {
@@ -77,90 +114,4 @@
         XMLPortParam( CommonController, "formationMode", setFormationModeXML, getFormationModeXML,  xmlelement, mode );
         XMLPortObject(CommonController, WorldEntity, "actionpoints", addActionpoint, getActionpoint,  xmlelement, mode);
-
-    }
-   
-    void CommonController::tick(float dt)
-    {
-        if (this->bHasTargetPosition_)
-        {
-            this->moveToTargetPosition(dt);
-        }
-        else if (this->bLookAtTarget_)
-        {
-            this->lookAtTarget(dt);
-        }
-        if (bShooting_)
-        {
-            this->doFire();
-        }
-        SUPER(CommonController, tick, dt);
-    }
-
-    std::string CommonController::getProtectXML ()
-    {
-        if (!this->getProtect())
-            return "noProtectWasSet";
-        return CommonController::getName (orxonox_cast<Pawn*>(this->getProtect()));
-    }
-    std::string CommonController::getName(Pawn* entity)
-    {
-        std::string name = entity->getName();
-        if (name == "")
-        {
-            const void * address = static_cast<const void*>(entity);
-            std::stringstream ss;
-            ss << address;  
-            name = ss.str();            
-        }
-        return name;
-
-    }
-    void CommonController::setProtect (ControllableEntity* protect)
-    {
-        this->protect_ = protect;
-    }
-    ControllableEntity* CommonController::getProtect ()
-    {
-        return this->protect_;
-    }
-  
-    std::string CommonController::getActionXML()
-    {
-        switch ( this->action_ )
-        {
-            case Action::FIGHT:
-            {
-                return "FIGHT";
-                break;
-            }
-            case Action::FLY:
-            {
-                return "FLY";
-                break;
-            }
-            case Action::PROTECT:
-            {
-                return "PROTECT";
-                break;
-            }
-            case Action::NONE:
-            {
-                return "NONE";
-                break;
-            }
-            case Action::FIGHTALL:
-            {
-                return "FIGHTALL";
-                break;
-            }
-            case Action::ATTACK:
-            {
-                return "ATTACK";
-                break;
-            }
-            default:
-                return "NONE";
-                break;
-        }
     }
     void CommonController::setFormationModeXML( std::string val )
@@ -178,5 +129,4 @@
             ThrowException( ParseError, std::string( "Attempting to set an unknown FormationMode: '" )+ val + "'." );
         this->setFormationMode( value );
-       
     }
     std::string CommonController::getFormationModeXML() 
@@ -185,27 +135,119 @@
         {
             case FormationMode::WALL:
-            {
-                return "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_; 
+    }
+    void CommonController::setRank(Rank::Value val)
+    { 
+        this->rank_ = val; 
+    }
+    Rank::Value CommonController::getRank() const
+    { 
+        return this->rank_; 
+    }
+    void CommonController::addActionpoint(WorldEntity* actionpoint)
+    {
+        std::string actionName;
+        Vector3 position;
+        std::string targetName;
+        Point p;
+        if (static_cast<Actionpoint*> (actionpoint))
+        {
+            Actionpoint* ap = static_cast<Actionpoint*> (actionpoint);
+            actionName = ap->getActionXML();
+            targetName = ap->getName();
+            position = ap->getWorldPosition();
+
+            Action::Value value;
+            
+            if ( actionName == "FIGHT" )
+            { value = Action::FIGHT; }
+            else if ( actionName == "FLY" )
+            { value = Action::FLY; }
+            else if ( actionName == "PROTECT" )
+            { value = Action::PROTECT; }
+            else if ( actionName == "NONE" )
+            { value = Action::NONE; }
+            else if ( actionName == "FIGHTALL" )
+            { value = Action::FIGHTALL; }
+            else if ( actionName == "ATTACK" )
+            { value = Action::ATTACK; }
+            else
+                ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ actionName + "'." );
+            p.action = value; p.name = targetName; p.position = position;
+            parsedActionpoints_.push_back(p);
+        }
+        else
+        {
+            p.action = Action::FLY; p.name = ""; p.position = actionpoint->getWorldPosition();
+        }
+            parsedActionpoints_.push_back(p);
+            this->actionpoints_.push_back(actionpoint);
+    }
+    WorldEntity* CommonController::getActionpoint(unsigned int index) const
+    {
+        if (index < this->actionpoints_.size())
+            return this->actionpoints_[index];
+        else
+            return 0;
+    }
+
+    //------------------------------------------------------------------------------
+    //-------------------------------World interaction------------------------------
+    //------------------------------------------------------------------------------
+
+    //"Virtual" methods
+    bool CommonController::setWingman ( CommonController* wingman )
+    { return false; }
+    bool CommonController::hasWingman() 
+    { return true; }
+    bool CommonController::hasTarget() 
+    {
+        if ( this->target_ )
+            return true;
+        return false;
+    }
+    ControllableEntity* CommonController::getTarget()
+    {
+        return this->target_;
+    }
+    Action::Value CommonController::getAction ()
+    {
+        return this->action_;
+    }
+    std::string CommonController::getActionName()
+    {
+        switch ( this->action_ )
+        {
+            case Action::FIGHT:
+            { return "FIGHT"; break; }
+            case Action::FLY:
+            { return "FLY"; break; }
+            case Action::PROTECT:
+            { return "PROTECT"; break; }
+            case Action::NONE:
+            { return "NONE"; break; }
+            case Action::FIGHTALL:
+            { return "FIGHTALL"; break; }
+            case Action::ATTACK:
+            { return "ATTACK"; break; }
+            default:
+                return "NONE";
                 break;
-            }
-            case FormationMode::FINGER4:
-            {
-                return "FINGER4";
-                break;
-            }
-            case FormationMode::DIAMOND:
-            {
-                return "DIAMOND";
-                break;
-            }
-            default:
-                return "DIAMOND";
-                break;
-
-        }
-    }
-    Action::Value CommonController::getAction ()
-    {
-        return this->action_;
+        }
     }
     void CommonController::setAction (Action::Value action)
@@ -213,5 +255,4 @@
         this->action_ = action;
     }
-
     void CommonController::setAction (Action::Value action, ControllableEntity* target)
     {
@@ -235,5 +276,4 @@
             this->setTargetPosition (target);
         }
-        
     }
     void CommonController::setAction (Action::Value action, const Vector3& target,  const Quaternion& orient )
@@ -244,77 +284,435 @@
             this->setTargetPosition (target);
             this->setTargetOrientation (orient);
-        }
-       
-    }
-    void CommonController::addActionpoint(WorldEntity* actionpoint)
-    {
-        std::string actionName;
-        Vector3 position;
-        std::string targetName;
-
-        if (static_cast<Actionpoint*> (actionpoint))
-        {
-            Actionpoint* ap = static_cast<Actionpoint*> (actionpoint);
-            
-            actionName = ap->getActionXML();
-            targetName = ap->getName();
-            position = ap->getWorldPosition();
-
-            Action::Value value;
-            
-            if ( actionName == "FIGHT" )
+        }  
+    }
+
+    //------------------------------------------------------------------------------
+    //--------------------------------Helper methods--------------------------------
+    //------------------------------------------------------------------------------
+
+    float CommonController::randomInRange( float a, float b )
+    {
+        float random = rnd( 1.0f );
+        float diff = b - a;
+        float r = random * diff;
+        return a + r;
+    }
+    float CommonController::distance (ControllableEntity* entity1, ControllableEntity* entity2)
+    {
+        if (!entity1 || !entity2)
+            return std::numeric_limits<float>::infinity();
+        return ( entity1->getPosition() - entity2->getPosition() ).length();
+    }
+    bool CommonController::sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
+    {
+        /*if (!entity1 || !entity2)
+            return false;
+        return entity1->getTeam() == entity2->getTeam();*/
+        if (entity1 == entity2)
+            return true;
+
+        int team1 = entity1->getTeam();
+        int team2 = entity2->getTeam();
+
+        Controller* controller = 0;
+        if (entity1->getController())
+            controller = entity1->getController();
+        else
+            controller = entity1->getXMLController();
+        if (controller)
+        {
+            CommonController* ac = orxonox_cast<CommonController*>(controller);
+            if (ac)
+                team1 = ac->getTeam();
+        }
+
+        if (entity2->getController())
+            controller = entity2->getController();
+        else
+            controller = entity2->getXMLController();
+        if (controller)
+        {
+            CommonController* ac = orxonox_cast<CommonController*>(controller);
+            if (ac)
+                team2 = ac->getTeam();
+        }
+
+        TeamGametype* tdm = orxonox_cast<TeamGametype*>(gametype);
+        if (tdm)
+        {
+            if (entity1->getPlayer())
+                team1 = tdm->getTeam(entity1->getPlayer());
+
+            if (entity2->getPlayer())
+                team2 = tdm->getTeam(entity2->getPlayer());
+        }
+
+        TeamBaseMatchBase* base = 0;
+        base = orxonox_cast<TeamBaseMatchBase*>(entity1);
+        if (base)
+        {
+            switch (base->getState())
             {
-                value = Action::FIGHT;
-
+                case BaseState::ControlTeam1:
+                    team1 = 0;
+                    break;
+                case BaseState::ControlTeam2:
+                    team1 = 1;
+                    break;
+                case BaseState::Uncontrolled:
+                default:
+                    team1 = -1;
             }
-            else if ( actionName == "FLY" )
+        }
+        base = orxonox_cast<TeamBaseMatchBase*>(entity2);
+        if (base)
+        {
+            switch (base->getState())
             {
-                value = Action::FLY;
-
+                case BaseState::ControlTeam1:
+                    team2 = 0;
+                    break;
+                case BaseState::ControlTeam2:
+                    team2 = 1;
+                    break;
+                case BaseState::Uncontrolled:
+                default:
+                    team2 = -1;
             }
-            else if ( actionName == "PROTECT" )
+        }
+
+        DroneController* droneController = 0;
+        droneController = orxonox_cast<DroneController*>(entity1->getController());
+        if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity2)
+            return true;
+        droneController = orxonox_cast<DroneController*>(entity2->getController());
+        if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1)
+            return true;
+        DroneController* droneController1 = orxonox_cast<DroneController*>(entity1->getController());
+        DroneController* droneController2 = orxonox_cast<DroneController*>(entity2->getController());
+        if (droneController1 && droneController2 && droneController1->getOwner() == droneController2->getOwner())
+            return true;
+
+        Dynamicmatch* dynamic = orxonox_cast<Dynamicmatch*>(gametype);
+        if (dynamic)
+        {
+            if (dynamic->notEnoughPigs||dynamic->notEnoughKillers||dynamic->notEnoughChasers) {return false;}
+
+            if (entity1->getPlayer())
+                team1 = dynamic->getParty(entity1->getPlayer());
+
+            if (entity2->getPlayer())
+                team2 = dynamic->getParty(entity2->getPlayer());
+
+            if (team1 ==-1 ||team2 ==-1 ) {return false;}
+            else if (team1 == dynamic->chaser && team2 != dynamic->chaser) {return false;}
+            else if (team1 == dynamic->piggy && team2 == dynamic->chaser) {return false;}
+            else if (team1 == dynamic->killer && team2 == dynamic->chaser) {return false;}
+            else return true;
+        }
+
+        return (team1 == team2 && team1 != -1);
+    }
+    bool CommonController::isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle )
+    {
+        if ( !entityThatLooks || !entityBeingLookedAt )
+            return false;
+        return ( getAngle( entityThatLooks ->getPosition() , 
+            entityThatLooks->getOrientation()  * WorldEntity::FRONT, 
+            entityBeingLookedAt->getWorldPosition() ) < angle );
+    }
+    std::string CommonController::getName(Pawn* entity)
+    {
+        std::string name = entity->getName();
+        if (name == "")
+        {
+            const void * address = static_cast<const void*>(entity);
+            std::stringstream ss;
+            ss << address;  
+            name = ss.str();            
+        }
+        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 )
             {
-                value = Action::PROTECT;
-
+                if ( bHasTargetOrientation_ )
+                {
+                    copyTargetOrientation( dt );
+                }
             }
-            else if ( actionName == "NONE" )
+            if (distance > 200 || (rotateX > -0.1 && rotateX < 0.1 && rotateY > -0.1 && rotateY < 0.1))
+                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*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::setProtect (ControllableEntity* protect)
+    {
+        this->protect_ = protect;
+    }
+    ControllableEntity* CommonController::getProtect ()
+    {
+        return this->protect_;
+    }
+    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 )
             {
-                value = Action::NONE;
-
-            }
-            else if ( actionName == "FIGHTALL" )
-            {
-                value = Action::FIGHTALL;
-
-            }
-            else if ( actionName == "ATTACK" )
-            {
-                value = Action::ATTACK;
-
-
+                this->stopMoving();
+                this->startLookingAtTarget();
             }
             else
-                ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ actionName + "'." );
-            //this->setAction( value );
-            Point p = { value, targetName, position };
-            parsedActionpoints_.push_back(p);
-            orxout(internal_error) << "Pushed " << p.action << endl;
-        }
-        else
-        {
-            Point p = { Action::FLY, "", actionpoint->getWorldPosition() };
-            parsedActionpoints_.push_back(p);
-        }
-            this->actionpoints_.push_back(actionpoint);
-
-        
-    }
-
-    WorldEntity* CommonController::getActionpoint(unsigned int index) const
-    {
-        if (index < this->actionpoints_.size())
-            return this->actionpoints_[index];
-        else
-            return 0;
+            {
+                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::setClosestTarget()
@@ -348,4 +746,30 @@
         return 0;  
     }
+    bool CommonController::startAttackingEnemiesThatAreClose()
+    {
+        if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
+        {
+            if ( (this->target_ && this->distance (this->getControllableEntity(), this->target_) > this->attackRange_) 
+                || !this->target_ )
+            {
+                Pawn* newTarget = this->closestTarget();
+                if ( newTarget && 
+                    this->distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))
+                        <= this->attackRange_ )
+                {
+                    Point p = { Action::FIGHT, this->getName(newTarget), Vector3::ZERO };
+                    this->parsedActionpoints_.push_back(p);
+                    this->executeActionpoint();
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    //------------------------------------------------------------------------------
+    //------------------------------Actionpoint methods-----------------------------
+    //------------------------------------------------------------------------------
+
     //POST: this starts doing what was asked by the last element of parsedActionpoints_,
     //if last element was failed to be parsed, next element will be executed.
@@ -406,9 +830,8 @@
                         if (CommonController::getName(*itP) == targetName)
                         {
-                            orxout(internal_error) << "Attacking" << endl;
                             this->setTarget (static_cast<ControllableEntity*>(*itP));
                         }
                     }
-                    if (!this->getTarget())
+                    if (!this->hasTarget())
                     {
                         this->nextActionpoint();
@@ -420,6 +843,4 @@
                     break;
             }
-            
-
         }
         else
@@ -429,5 +850,4 @@
             this->action_ = Action::NONE;
         }
-        orxout(internal_error) << "Executing action " << this->getActionXML() << endl;
     }
     void CommonController::nextActionpoint()
@@ -439,577 +859,3 @@
         this->setAction(Action::NONE);
     }
-
-    void CommonController::maneuver() 
-    {
-        maneuverCounter_++;
-
-        if (maneuverCounter_ > 5)
-            maneuverCounter_ = 0;
-        if ( this->target_ && this->getControllableEntity())
-        {
-            Vector3 thisPosition = this->getControllableEntity()->getWorldPosition();
-            //Quaternion thisOrientation = this->getControllableEntity()->getOrientation();
-
-            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 bThisIsLookingAtTarget = this->isLooking ( getControllableEntity(), this->target_, math::pi/4 );
-            bool bTargetIsLookingAtThis = this->isLooking ( this->target_, getControllableEntity(), math::pi/10.0f );
-            
-
-
-            //too far? well, come closer then
-            if ( diffLength > 3000 )
-            {
-                if (diffLength < 6000)
-                {
-
-                }
-                else
-                {
-                }
-                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_ );
-              /*  if (maneuverCounter_ == 0)
-                {
-                    this->setTargetPosition( this->positionOfTarget_ );   
-                    return;
-                }
-                else
-                {
-                    dodge( thisPosition, diffUnit );
-                }*/
-            }
-            //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 );
-                
-            }
-        }
-        
-        //orxout ( internal_error ) << "ManeuverType = " << this->maneuverType_ << endl;
-    }
-    ControllableEntity* CommonController::getTarget()
-    {
-        return this->target_;
-    }
-    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 );
-    }
-    void CommonController::stopMoving()
-    {
-        this->bHasTargetPosition_ = false;
-    }
-    void CommonController::startLookingAtTarget()
-    {
-        this->bLookAtTarget_ = true;
-    }
-    void CommonController::stopLookingAtTarget()
-    {
-        this->bLookAtTarget_ = false;
-    }
-    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 );
-        
-           
-    }
-   
-    bool CommonController::setWingman ( CommonController* wingman )
-    {
-        return false;
-    }
-   
-    bool CommonController::hasWingman() 
-    {
-        return true;
-    }
-    void CommonController::setTarget( ControllableEntity* target )
-    {
-        this->target_ = target;
-        //orxout ( internal_error ) << " TARGET SET " << endl;
-        
-        if ( this->target_ )
-        {
-            this->setPositionOfTarget( target_->getWorldPosition() );
-
-        }
-    }
-    bool CommonController::hasTarget() 
-    {
-        if ( this->target_ )
-            return true;
-        return false;
-    }
-    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::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() );
-    }
-
-
-
-    //copy the Roll orientation of given Quaternion.
-    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*ROTATEFACTOR * dt );
-    }
-    void CommonController::copyTargetOrientation( float dt )
-    {
-        if ( bHasTargetOrientation_ )
-        {   
-            copyOrientation( targetOrientation_, dt );
-        }
-    }
-
-
-
-
-    void CommonController::moveToTargetPosition( float dt )
-    {
-        this->moveToPosition( this->targetPosition_, dt );
-    }
-    void CommonController::moveToPosition( const Vector3& target, float dt )
-    {
-     
-        
-        //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 = 65;
-
-        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 ( distance > tolerance )
-        {
-            //Yaw and Pitch are enough to start facing the target
-            this->getControllableEntity() ->rotateYaw( ROTATEFACTOR * rotateX * dt );
-            this->getControllableEntity() ->rotatePitch( ROTATEFACTOR * rotateY * dt );
-
-            //300 works, maybe less is better
-            if ( distance < 400 )
-            {
-                //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( dt );
-                }
-            }
-
-            this->getControllableEntity() ->moveFrontBack( SPEED * dt );
-        }
-        else
-        {      
-            bHasTargetPosition_ = false;
-            bHasTargetOrientation_ = false;
-        }
-    }
-    float CommonController::randomInRange( float a, float b )
-    {
-        float random = rnd( 1.0f );
-        float diff = b - a;
-        float r = random * diff;
-        return a + r;
-    }
-    
-
-    //to be called in action
-    //PRE: relativeTargetPosition is desired position relative to the spaceship,
-    //angleRoll is the angle in degrees of Roll that should be applied by the end of the movement
-    //POST: target orientation and position are set, so that it can be used by MoveAndRoll() 
-    void CommonController::moveToPoint( const Vector3& relativeTargetPosition, float angleRoll )
-    {
-        ControllableEntity* entity = this->getControllableEntity();
-        if ( !entity )
-            return;
-        Quaternion orient = entity->getWorldOrientation();
-        Quaternion rotation = Quaternion( Degree( angleRoll ), Vector3::UNIT_Z );
-
-        Vector3 target = orient * relativeTargetPosition + entity->getWorldPosition();
-        setTargetPosition( target );
-        orient = orient * rotation;
-        this->setTargetOrientation( orient );
-       
-    }
-    //to be called in tick
-    //PRE: MoveToPoint was called
-    //POST: spaceship changes its yaw and pitch to point towards targetPosition_,
-    //moves towards targetPosition_ by amount depending on dt and its speed,
-    //rolls by amount depending on the difference between angleRoll_ and angleRolled_, dt, and 
-    //angular speed
-    //if position reached with a certain tolerance, and angleRolled_ = angleRoll_, returns false,
-    //otherwise returns true
-    //dt is normally around 0.02f, which makes it 1/0.02 = 50 frames/sec
-    bool CommonController::moveAndRoll( float dt )
-    {
-        float factor = 1;
-        if ( !this->getControllableEntity() )
-            return false;
-        if ( this->rank_ == Rank::DIVISIONLEADER )
-            factor = 0.8;
-        if ( this->rank_ == Rank::SECTIONLEADER )
-            factor = 0.9;
-        int tolerance = 60;
-        
-        ControllableEntity* entity = this->getControllableEntity();
-        if ( !entity )
-            return true;
-        Vector2 coord = get2DViewCoordinates
-            ( entity->getPosition() , 
-            entity->getOrientation()  * WorldEntity::FRONT, 
-            entity->getOrientation()  * WorldEntity::UP, 
-            targetPosition_ );
-
-        float distance = ( targetPosition_ - 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 ( distance > tolerance )
-        {
-            //Yaw and Pitch are enough to start facing the target
-            this->getControllableEntity() ->rotateYaw( -2.0f * ROTATEFACTOR * rotateX * dt );
-            this->getControllableEntity() ->rotatePitch( 2.0f * ROTATEFACTOR * rotateY * dt );
-            
-            //Roll
-            if ( bHasTargetOrientation_ )
-            {
-                copyTargetOrientation( dt );
-            }
-          
-            //Move
-            this->getControllableEntity() ->moveFrontBack( 1.2f * SPEED * factor * dt );
-            //if still moving, return false
-            return false;
-        }
-        else
-        {     
-            
-            //if finished, return true;
-            return true;
-        }
-    }
-
-    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 )const
-    {
-        if ( !this->getControllableEntity()  || !this->target_ )
-            return false;
-
-        return ( getAngle( this->getControllableEntity() ->getPosition() , 
-            this->getControllableEntity() ->getOrientation()  * WorldEntity::FRONT, this->positionOfTarget_ ) < angle );
-    }
-    bool CommonController::isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle )
-    {
-        if ( !entityThatLooks || !entityBeingLookedAt )
-            return false;
-        return ( getAngle( entityThatLooks ->getPosition() , 
-            entityThatLooks->getOrientation()  * WorldEntity::FRONT, 
-            entityBeingLookedAt->getWorldPosition() ) < angle );
-    }
-
-    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 < 9000000.0f && this->isLookingAtTarget( math::pi / 20.0f)) {
-            return true;
-        }
-        else
-        {
-            return false;
-        }
-
-    }
-    float CommonController::distance (ControllableEntity* entity1, ControllableEntity* entity2)
-    {
-        if (!entity1 || !entity2)
-            return std::numeric_limits<float>::infinity();
-        return ( entity1->getPosition() - entity2->getPosition() ).length();
-    }
-    bool CommonController::sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
-    {
-        /*if (!entity1 || !entity2)
-            return false;
-        return entity1->getTeam() == entity2->getTeam();*/
-        if (entity1 == entity2)
-            return true;
-
-        int team1 = entity1->getTeam();
-        int team2 = entity2->getTeam();
-
-        Controller* controller = 0;
-        if (entity1->getController())
-            controller = entity1->getController();
-        else
-            controller = entity1->getXMLController();
-        if (controller)
-        {
-            CommonController* ac = orxonox_cast<CommonController*>(controller);
-            if (ac)
-                team1 = ac->getTeam();
-        }
-
-        if (entity2->getController())
-            controller = entity2->getController();
-        else
-            controller = entity2->getXMLController();
-        if (controller)
-        {
-            CommonController* ac = orxonox_cast<CommonController*>(controller);
-            if (ac)
-                team2 = ac->getTeam();
-        }
-
-        TeamGametype* tdm = orxonox_cast<TeamGametype*>(gametype);
-        if (tdm)
-        {
-            if (entity1->getPlayer())
-                team1 = tdm->getTeam(entity1->getPlayer());
-
-            if (entity2->getPlayer())
-                team2 = tdm->getTeam(entity2->getPlayer());
-        }
-
-        TeamBaseMatchBase* base = 0;
-        base = orxonox_cast<TeamBaseMatchBase*>(entity1);
-        if (base)
-        {
-            switch (base->getState())
-            {
-                case BaseState::ControlTeam1:
-                    team1 = 0;
-                    break;
-                case BaseState::ControlTeam2:
-                    team1 = 1;
-                    break;
-                case BaseState::Uncontrolled:
-                default:
-                    team1 = -1;
-            }
-        }
-        base = orxonox_cast<TeamBaseMatchBase*>(entity2);
-        if (base)
-        {
-            switch (base->getState())
-            {
-                case BaseState::ControlTeam1:
-                    team2 = 0;
-                    break;
-                case BaseState::ControlTeam2:
-                    team2 = 1;
-                    break;
-                case BaseState::Uncontrolled:
-                default:
-                    team2 = -1;
-            }
-        }
-
-        DroneController* droneController = 0;
-        droneController = orxonox_cast<DroneController*>(entity1->getController());
-        if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity2)
-            return true;
-        droneController = orxonox_cast<DroneController*>(entity2->getController());
-        if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1)
-            return true;
-        DroneController* droneController1 = orxonox_cast<DroneController*>(entity1->getController());
-        DroneController* droneController2 = orxonox_cast<DroneController*>(entity2->getController());
-        if (droneController1 && droneController2 && droneController1->getOwner() == droneController2->getOwner())
-            return true;
-
-        Dynamicmatch* dynamic = orxonox_cast<Dynamicmatch*>(gametype);
-        if (dynamic)
-        {
-            if (dynamic->notEnoughPigs||dynamic->notEnoughKillers||dynamic->notEnoughChasers) {return false;}
-
-            if (entity1->getPlayer())
-                team1 = dynamic->getParty(entity1->getPlayer());
-
-            if (entity2->getPlayer())
-                team2 = dynamic->getParty(entity2->getPlayer());
-
-            if (team1 ==-1 ||team2 ==-1 ) {return false;}
-            else if (team1 == dynamic->chaser && team2 != dynamic->chaser) {return false;}
-            else if (team1 == dynamic->piggy && team2 == dynamic->chaser) {return false;}
-            else if (team1 == dynamic->killer && team2 == dynamic->chaser) {return false;}
-            else return true;
-        }
-
-        return (team1 == team2 && team1 != -1);
-    }
-    void CommonController::doFire() 
-    {
-        if ( !this->target_ || !this->getControllableEntity() )
-        {
-            return;
-        }
-      
-        Pawn* pawn = orxonox_cast<Pawn*>( this->getControllableEntity() );
-
-        if ( pawn )
-            //pawn->setAimPosition( this->getControllableEntity() ->getWorldPosition()  + 4000*( this->getControllableEntity() ->getOrientation()  * WorldEntity::FRONT ));
-            pawn->setAimPosition( this->positionOfTarget_ );
-    
-        this->getControllableEntity() ->fire( 0 );
-    }
-   
-
 }
Index: /code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	(revision 10850)
+++ /code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	(revision 10851)
@@ -39,4 +39,5 @@
 #include "tools/interfaces/Tickable.h"
 #include <limits>
+#include <algorithm>
 #include "worldentities/Actionpoint.h"
 
@@ -90,58 +91,36 @@
             virtual void tick(float dt); 
 
-            //----[XML data]----
+            //----[XML methods]----
                 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-                //----[Action data]----
-                    Action::Value getAction ();
-                    void setAction (Action::Value action);
-                    void setAction (Action::Value action, ControllableEntity* target);
-                    void setAction (Action::Value action, const Vector3& target);
-                    void setAction (Action::Value action, const Vector3& target,  const Quaternion& orient );
-                    void setActionXML( std::string val);
-                    std::string getActionXML();
-                //----[/Action data]----
-                //----[Formation data]----
-                    virtual void setFormationModeXML(std::string val);
-                    virtual std::string getFormationModeXML();
-                    virtual void setFormationMode(FormationMode::Value val)
-                        { this->formationMode_ = val; }
-                    inline FormationMode::Value getFormationMode() const
-                        { return this->formationMode_; }
-                //----[/Formation data]----
-                //----[Rank data]----
-                    virtual void setRank(Rank::Value val)
-                        { this->rank_ = val; }
-                    inline Rank::Value getRank() const
-                        { return this->rank_; }
-                //----[/Rank data]----
-                //----[Protect data]----
-                    void setProtectXML( std::string val );
-                    std::string getProtectXML ();
-                    void setProtect (ControllableEntity* protect);
-                    ControllableEntity* getProtect ();
-                //----[/Protect data]----
-                //----[Actionpoint data]----
+                
+                    void setFormationModeXML(std::string val);
+                    std::string getFormationModeXML();
+                    void setFormationMode(FormationMode::Value val);
+                    FormationMode::Value getFormationMode() const;
+
+                    void setRank(Rank::Value val);
+                    Rank::Value getRank() const;
+               
                     void addActionpoint(WorldEntity* waypoint);
                     WorldEntity* getActionpoint(unsigned int index) const;
-                //----[/Actionpoint data]----
-            //----[/XML data]----
+            //----[/XML methods]----
 
             //----[Interaction with other Controllers]----
                 virtual bool setWingman(CommonController* wingman);
                 virtual bool hasWingman();        
-
-                void setPositionOfTarget(const Vector3& target);
-                void setOrientationOfTarget(const Quaternion& orient);
-
-                void setTarget(ControllableEntity* target);
+                
+                bool hasTarget();
                 ControllableEntity* getTarget();
-                bool hasTarget();
-
-                void setTargetPosition(const Vector3& target);
-                void setTargetOrientation(const Quaternion& orient);
-                void setTargetOrientation(ControllableEntity* target);
+                      
+                Action::Value getAction ();
+                std::string getActionName();
+
+                void setAction (Action::Value action);
+                void setAction (Action::Value action, ControllableEntity* target);
+                void setAction (Action::Value action, const Vector3& target);
+                void setAction (Action::Value action, const Vector3& target,  const Quaternion& orient );
             //----[/Interaction with other Controllers]----
 
-            //----[Helper functions]----
+            //----[Helper methods]----
                 float randomInRange(float a, float b);
                 static float distance(ControllableEntity* entity1, ControllableEntity* entity2);
@@ -151,13 +130,23 @@
 
                 float squaredDistanceToTarget() const;
-                bool isLookingAtTarget(float angle) const;
-            //----[/Helper functions]----
-
+                bool isLookingAtTarget(float angle);
+            //----[/Helper methods]----
+
+             //----[Actionpoint information]----
+
+                std::vector<WeakPtr<WorldEntity> > actionpoints_;
+                float squaredaccuracy_;
+                std::vector<Point > parsedActionpoints_;
+
+            //----[/Actionpoint information]----
+                //----[Actionpoint methods]----
+                void executeActionpoint();
+                void nextActionpoint();
+            //----[Actionpoint methods]----
         protected:
-            //----[Flying functionality]----
+            //----[Flying methods]----
                 void stopMoving();
-
-                void moveToPoint(const Vector3& relativeTargetPosition, float angleRoll);
-                bool moveAndRoll(float dt);
+                void stopLookingAtTarget();
+                void startLookingAtTarget();
 
                 void moveToPosition(const Vector3& target, float dt);
@@ -168,24 +157,32 @@
 
                 void lookAtTarget(float dt);
-                void stopLookingAtTarget();
-                void startLookingAtTarget();
-
-                bool bLookAtTarget_;        
-            //----[/Flying functionality]----
+
+                void setTargetPosition(const Vector3& target);
+                void setTargetOrientation(const Quaternion& orient);
+                void setTargetOrientation(ControllableEntity* target);
+
+
+            //----[/Flying methods]----
             
-            //----[Fighting functionality]----
+            //----[Fighting methods]----
+                void setTarget(ControllableEntity* target);
+
+                void setPositionOfTarget(const Vector3& target);
+                void setOrientationOfTarget(const Quaternion& orient);
+
+                void setProtect (ControllableEntity* protect);
+                ControllableEntity* getProtect (); 
+
                 void maneuver();
                 void dodge(Vector3& thisPosition, Vector3& diffUnit);
-                void aimAtTarget();           
                 bool canFire();
                 void doFire();
                 void setClosestTarget();
                 Pawn* closestTarget();
-
-                bool bShooting_;
-                int maneuverCounter_;         
-            //----[/Fighting functionality]----            
+                bool startAttackingEnemiesThatAreClose();
+            //----[/Fighting methods]----            
             
             //----[where-to-fly information]----
+                
                 bool bHasTargetPosition_;
                 Vector3 targetPosition_;
@@ -193,5 +190,4 @@
                 Quaternion targetOrientation_;
                 
-               
             //----[/where-to-fly information]----
             //----[protect information]----
@@ -207,12 +203,5 @@
             //----[/who-to-kill information]----
 
-            //----[Actionpoint information]----
-                std::vector<WeakPtr<WorldEntity> > actionpoints_;
-                float squaredaccuracy_;
-                Point  currentActionpoint_;
-                std::vector<Point > parsedActionpoints_;
-                void executeActionpoint();
-                void nextActionpoint();
-            //----[/Actionpoint information]----
+           
             //----["Private" variables]----
                 FormationMode::Value formationMode_;
@@ -222,5 +211,9 @@
                 Action::Value action_;
                 int attackRange_;
-                
+                bool bLookAtTarget_;        
+                bool bShooting_;
+                int maneuverCounter_;
+                int tolerance_; 
+                bool bFirstTick_;                        
             //----[/"Private" variables]----               
     };
Index: /code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	(revision 10850)
+++ /code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	(revision 10851)
@@ -46,6 +46,4 @@
         this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this)));
         this->rank_ = Rank::DIVISIONLEADER;
-
-
     }
 
@@ -60,52 +58,30 @@
         //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
     }
-
-    
     void DivisionController::tick(float dt)
     {   
-
         if (!this->isActive())
             return;
-        
-        
         SUPER(DivisionController, tick, dt);
-
     }
     void DivisionController::action()
-    {
-        //----Whatever ship is doing, if there are targets close to it and its own target is far away, fight them----
-        //analog to attack move
-        if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
-        {
-            if ( (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_) 
-                || !this->target_ )
-            {
-                Pawn* newTarget = this->closestTarget();
-                if ( newTarget && 
-                    CommonController::distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))
-                        <= this->attackRange_ )
-                {
-                    // this->backupAction();
-                    // this->setAction (Action::FIGHT, newTarget);
-                    Point p = { Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO };
-                    this->parsedActionpoints_.push_back(p);
-                    this->executeActionpoint();
-                }
-            }
-        }
-
-        //action is NONE whenever ships finishes current action, 
-        //if it was fighting before because enemies were close, resume what it was doing
-        //otherwise try to execute next action
+    {        
+        if (this->startAttackingEnemiesThatAreClose())
+        {
+            Point p = { Action::FIGHT, "", Vector3::ZERO };
+            
+            if (this->myWingman_)
+            {
+                this->myWingman_->parsedActionpoints_.push_back(p);
+            }
+            if (this->myFollower_)
+            {
+                this->myFollower_->parsedActionpoints_.push_back(p);
+            }
+        }
+
         if (this->action_ == Action::NONE)
         {
             this->executeActionpoint();
         }
-
-
-        //this->action_ is what I am actually executing, this->target_ is what I am 
-        //actually attacking, etc.
-
-        //after action is finished, .pop_back() is to be called.
         if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL)
         {
@@ -116,5 +92,6 @@
                 if (this->action_ == Action::FIGHT)
                 {
-                    if (newTarget && CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
+                    if (newTarget && 
+                            CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
                     {
                         this->setAction (Action::FIGHT, newTarget);
@@ -123,4 +100,12 @@
                     {
                         this->nextActionpoint();
+                        if (this->myWingman_)
+                        {
+                            this->myWingman_->nextActionpoint();
+                        }
+                        if (this->myFollower_)
+                        {
+                            this->myFollower_->nextActionpoint();
+                        }
                         return;
                     }
@@ -135,4 +120,12 @@
                     {
                         this->nextActionpoint();
+                        if (this->myWingman_)
+                        {
+                            this->myWingman_->nextActionpoint();
+                        }
+                        if (this->myFollower_)
+                        {
+                            this->myFollower_->nextActionpoint();
+                        }
                         return;
                     }
@@ -144,5 +137,4 @@
                 //----fly in formation if far enough----
                 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
-                
                     
                 if (diffVector.length() > this->attackRange_)
@@ -151,4 +143,12 @@
                     {
                         this->nextActionpoint();
+                        if (this->myWingman_)
+                        {
+                            this->myWingman_->nextActionpoint();
+                        }
+                        if (this->myFollower_)
+                        {
+                            this->myFollower_->nextActionpoint();
+                        }
                         return;
                     }
@@ -158,5 +158,4 @@
                         this->setTargetPositionOfFollower();                    
                     }
-
                 }
                 else
@@ -165,30 +164,26 @@
                     if (this->myWingman_)
                     {
-                        this->myWingman_->setAction (this->action_, this->target_);     
+                        this->myWingman_->setAction (Action::FIGHT, this->target_);     
                     }
                     if (this->myFollower_)
                     {
-                        this->myFollower_->setAction (this->action_);                                    
-                    }
-
-                }
-                
-            }
-            if (this->hasTarget())
-            {
-                //----choose where to go----
-                this->maneuver();
-                //----fire if you can----
-                this->bShooting_ = this->canFire();                
-            }
-
+                        this->myFollower_->setAction (Action::FIGHT);                                    
+                    }
+                }
+            }
         }
         else if (this->action_ == Action::FLY)
         {
-
             if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
             {
-                orxout(internal_error) << "arrived";
                 this->nextActionpoint();
+                if (this->myWingman_)
+                {
+                    this->myWingman_->nextActionpoint();
+                }
+                if (this->myFollower_)
+                {
+                    this->myFollower_->nextActionpoint();
+                }
                 return;
             }
@@ -201,14 +196,18 @@
             {
                 this->nextActionpoint();
+                if (this->myWingman_)
+                {
+                    this->myWingman_->nextActionpoint();
+                }
+                if (this->myFollower_)
+                {
+                    this->myFollower_->nextActionpoint();
+                }
                 return;
             }
-           /* if (this->myWingman_)
-                this->myWingman_->setAction (Action::PROTECT, this->getProtect());
-            if (this->myFollower_)
-                this->myFollower_->setAction (Action::PROTECT, this->getProtect());
-            */
+
             Vector3* targetRelativePosition;
                 
-            targetRelativePosition = new Vector3 (0, 0, 500);  
+            targetRelativePosition = new Vector3 (0, 300, 300);  
  
             Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) + 
@@ -225,4 +224,12 @@
             {
                 this->nextActionpoint();
+                if (this->myWingman_)
+                {
+                    this->myWingman_->nextActionpoint();
+                }
+                if (this->myFollower_)
+                {
+                    this->myFollower_->nextActionpoint();
+                }
                 return;
             }
@@ -239,13 +246,14 @@
                 if (this->myWingman_)
                 {
-                    this->myWingman_->setAction (this->action_, this->target_);     
+                    this->myWingman_->setAction (Action::FIGHT, this->target_);     
                 }
                 if (this->myFollower_)
                 {
-                    this->myFollower_->setAction (this->action_);                                    
-                }
-
-            }
-            
+                    this->myFollower_->setAction (Action::FIGHT);                                    
+                }
+            }          
+        }
+        if (this->hasTarget())
+        {
             //----choose where to go----
             this->maneuver();
@@ -253,9 +261,6 @@
             this->bShooting_ = this->canFire();                
         }
-
-    }
-
+    }
     
-
     void DivisionController::setTargetPositionOfWingman()
     {
@@ -321,6 +326,4 @@
         myFollower_->setAction ( Action::FLY, targetAbsolutePositionOfFollower, orient );       
     }
-
-
     bool DivisionController::setWingman(CommonController* cwingman)
     {
@@ -336,5 +339,4 @@
             return false;
         }
-    
     }
     bool DivisionController::setFollower(LeaderController* myFollower)
@@ -364,8 +366,3 @@
             return false;
     }
-
-
-    
-   
-
 }
Index: /code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	(revision 10850)
+++ /code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	(revision 10851)
@@ -44,5 +44,5 @@
         this->myDivisionLeader_ = 0;
         this->rank_ = Rank::SECTIONLEADER;
-
+        this->bFirstAction_ = true;
         //orxout(internal_error) << this << "Was created" << endl;
 
@@ -72,4 +72,5 @@
     void SectionController::action()
     {
+
         //----If no leader, find one----  
         if (!myDivisionLeader_)
@@ -83,28 +84,146 @@
         {
         }
-
-        //----action was set to fight----
-        if (this->action_ == Action::FIGHT)
-        {
-            if (!this->hasTarget())
-            {
-                if (this->myDivisionLeader_)
-                {
-                    this->chooseTarget();                
-                }
-                else
-                {
-                    this->setClosestTarget(); 
-                }
-            }
-            else
-            {
+        if (!myDivisionLeader_)
+        {
+            if (this->startAttackingEnemiesThatAreClose())
+            {
+                Point p = { Action::FIGHT, "", Vector3::ZERO };
                 
+                if (this->myWingman_)
+                {
+                    this->myWingman_->parsedActionpoints_.push_back(p);
+                }
+            }
+            if (this->action_ == Action::NONE)
+            {
+                this->executeActionpoint();
+            }
+            if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL)
+            {
+                if (!this->hasTarget())
+                {
+                    //----find a target----
+                    ControllableEntity* newTarget = this->closestTarget();
+                    if (this->action_ == Action::FIGHT)
+                    {
+                        if (newTarget && 
+                                CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
+                        {
+                            this->setAction (Action::FIGHT, newTarget);
+                        }
+                        else
+                        {
+                            this->nextActionpoint();
+                            if (this->myWingman_)
+                            {
+                                this->myWingman_->nextActionpoint();
+                            }
+                
+                            return;
+                        }
+                    }
+                    else if (this->action_ == Action::FIGHTALL)
+                    {
+                        if (newTarget && newTarget->getController())
+                        {
+                            this->setAction (Action::FIGHTALL, newTarget);
+                        }
+                        else
+                        {
+                            this->nextActionpoint();
+                            if (this->myWingman_)
+                            {
+                                this->myWingman_->nextActionpoint();
+                            }
+                            return;
+                        }
+                    }
+
+                }
+                else if (this->hasTarget())
+                {
+                    //----fly in formation if far enough----
+                    Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
+                        
+                    if (diffVector.length() > this->attackRange_)
+                    {
+                        if (this->action_ == Action::FIGHT)
+                        {
+                            this->nextActionpoint();
+                            if (this->myWingman_)
+                            {
+                                this->myWingman_->nextActionpoint();
+                            }
+                            return;
+                        }
+                        else
+                        {
+                            this->setTargetPositionOfWingman();
+                        }
+                    }
+                    else
+                    {
+                        //----wingmans shall support the fire of their leaders----
+                        if (this->myWingman_)
+                        {
+                            this->myWingman_->setAction (Action::FIGHT, this->target_);     
+                        }
+                        
+                    }
+                }
+            }
+            else if (this->action_ == Action::FLY)
+            {
+                if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
+                {
+                    this->nextActionpoint();
+                    if (this->myWingman_)
+                    {
+                        this->myWingman_->nextActionpoint();
+                    }
+                    return;
+                }
+                this->setTargetPositionOfWingman();
+            }
+            else if (this->action_ == Action::PROTECT)
+            {
+                if (!this->getProtect())
+                {
+                    this->nextActionpoint();
+                    if (this->myWingman_)
+                    {
+                        this->myWingman_->nextActionpoint();
+                    }
+                    return;
+                }
+
+                Vector3* targetRelativePosition;
+                    
+                targetRelativePosition = new Vector3 (0, 300, 300);  
+     
+                Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) + 
+                    (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
+                this->setTargetPosition(targetAbsolutePosition);
+                
+                this->setTargetPositionOfWingman();
+
+            }
+            else if (this->action_ == Action::ATTACK)
+            {   
+                if (!this->hasTarget())
+                {
+                    this->nextActionpoint();
+                    if (this->myWingman_)
+                    {
+                        this->myWingman_->nextActionpoint();
+                    }
+                    return;
+                }
                 //----fly in formation if far enough----
                 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
-                if (diffVector.length() > 3000)
+                if (diffVector.length() > this->attackRange_)
                 {
                     this->setTargetPositionOfWingman();
-                }   
+                }
                 else
                 {
@@ -112,7 +231,8 @@
                     if (this->myWingman_)
                     {
-                        this->myWingman_->setAction (Action::FIGHT, this->target_);                    
-                    }
-                }
+                        this->myWingman_->setAction (Action::FIGHT, this->target_);     
+                    }
+      
+                }          
             }
             if (this->hasTarget())
@@ -124,22 +244,57 @@
             }
         }
-
-        //----action was set to fly----
-        else if (this->action_ == Action::FLY)
-        {
-            this->setTargetPositionOfWingman();
-        }
-
-        //----action was set to protect----
-        else if (this->action_ == Action::PROTECT)
-        {
-           /* if (this->myWingman_)
-                this->myWingman_->setAction (Action::PROTECT, this->getProtect());
-*/
-            this->setTargetPositionOfWingman();
-
-        }
-                
-
+        //----If have leader----
+        else
+        {
+            //----action was set to fight----
+            if (this->action_ == Action::FIGHT)
+            {
+                if (!this->hasTarget())
+                {
+                    this->chooseTarget();
+                }
+                else
+                {
+                    //----fly in formation if far enough----
+                    Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
+                    if (diffVector.length() > this->attackRange_)
+                    {
+                        this->setTargetPositionOfWingman();
+                    }   
+                    else
+                    {
+                        //----wingmans shall support the fire of their leaders----
+                        if (this->myWingman_)
+                        {
+                            this->myWingman_->setAction (Action::FIGHT, this->target_);                    
+                        }
+                    }
+                }
+                if (this->hasTarget())
+                {
+                    //----choose where to go----
+                    this->maneuver();
+                    //----fire if you can----
+                    this->bShooting_ = this->canFire();                
+                }
+            }
+
+            //----action was set to fly----
+            else if (this->action_ == Action::FLY)
+            {
+                this->setTargetPositionOfWingman();
+                Pawn* newTarget = this->closestTarget();
+                if ( newTarget &&  this->distance (this->getControllableEntity(), 
+                                                    static_cast<ControllableEntity*>(newTarget)) <= this->attackRange_ )
+                {
+                    this->setAction (Action::FIGHT, static_cast<ControllableEntity*>(newTarget));
+                }
+            }       
+        }
+        if (this->bFirstAction_ && this->myDivisionLeader_)
+        {
+            this->parsedActionpoints_ = this->myDivisionLeader_->parsedActionpoints_;
+            this->bFirstAction_ = false;
+        }
     }
     //PRE: myDivisionLeader_ != 0 && myDivisionLeader_->action_ == Action::FIGHT
@@ -267,5 +422,4 @@
         }
         return 0;
-
     }
     bool SectionController::setWingman(CommonController* cwingman)
@@ -291,8 +445,3 @@
             return false;
     }
-
-    
-    
-   
-
 }
Index: /code/branches/campaignHS15/src/orxonox/controllers/SectionController.h
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/SectionController.h	(revision 10850)
+++ /code/branches/campaignHS15/src/orxonox/controllers/SectionController.h	(revision 10851)
@@ -67,4 +67,5 @@
             //----private variables-----
                 Timer actionTimer_; //<! Regularly calls action().
+                bool bFirstAction_;
             
 
Index: /code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc	(revision 10850)
+++ /code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc	(revision 10851)
@@ -42,4 +42,6 @@
         this->myLeader_ = 0;
         this->rank_ = Rank::WINGMAN;
+        this->bFirstAction_ = true;
+
     }
 
@@ -69,4 +71,5 @@
     void WingmanController::action()
     {
+
         //----If no leader, find one----
         if (!this->myLeader_)
@@ -79,15 +82,96 @@
         else
         {
-            this->action_ = this->myLeader_->getAction();
-        }
-
-
-        //----action was set to fight----
-        if (this->action_ == Action::FIGHT)
-        {
-            //----If no leader found, attack someone----
-            if (!this->hasTarget() && !this->myLeader_)
-            {
-                this->setClosestTarget(); 
+
+        }
+        if (!this->myLeader_)
+        {
+            bool b = this->startAttackingEnemiesThatAreClose();
+
+            if (this->action_ == Action::NONE)
+            {
+                this->executeActionpoint();
+            }
+            if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL)
+            {
+                if (!this->hasTarget())
+                {
+                    //----find a target----
+                    ControllableEntity* newTarget = this->closestTarget();
+                    if (this->action_ == Action::FIGHT)
+                    {
+                        if (newTarget && 
+                                CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
+                        {
+                            this->setAction (Action::FIGHT, newTarget);
+                        }
+                        else
+                        {
+                            this->nextActionpoint();
+                            return;
+                        }
+                    }
+                    else if (this->action_ == Action::FIGHTALL)
+                    {
+                        if (newTarget && newTarget->getController())
+                        {
+                            this->setAction (Action::FIGHTALL, newTarget);
+                        }
+                        else
+                        {
+                            this->nextActionpoint();
+                            return;
+                        }
+                    }
+
+                }
+                else if (this->hasTarget())
+                {
+                    //----fly in formation if far enough----
+                    Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
+                        
+                    if (diffVector.length() > this->attackRange_)
+                    {
+                        if (this->action_ == Action::FIGHT)
+                        {
+                            this->nextActionpoint();
+                            return;
+                        }
+                    }
+                }
+            }
+            else if (this->action_ == Action::FLY)
+            {
+                if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
+                {
+                    this->nextActionpoint();
+                    return;
+                }
+            }
+            else if (this->action_ == Action::PROTECT)
+            {
+                if (!this->getProtect())
+                {
+                    this->nextActionpoint();
+                    return;
+                }
+
+                Vector3* targetRelativePosition;
+                    
+                targetRelativePosition = new Vector3 (0, 300, 300);  
+     
+                Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) + 
+                    (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
+                this->setTargetPosition(targetAbsolutePosition);
+                
+
+            }
+            else if (this->action_ == Action::ATTACK)
+            {   
+                if (!this->hasTarget())
+                {
+                    this->nextActionpoint();
+                    return;
+                }
+                        
             }
             if (this->hasTarget())
@@ -99,15 +183,33 @@
             }
         }
-        //----action was set to fly, leader handles the logic----
-        else if (this->action_ == Action::FLY)
-        {
-
-        }
-        //----gani-TODO: implement protect----
-        else if (this->action_ == Action::PROTECT)
-        {
-
-        }
-          
+        else
+        {
+            //----action was set to fight----
+            if (this->action_ == Action::FIGHT)
+            {
+                //----If no leader found, attack someone----
+                if (!this->hasTarget())
+                {
+                    this->setClosestTarget(); 
+                }
+                if (this->hasTarget())
+                {
+                    //----choose where to go----
+                    this->maneuver();
+                    //----fire if you can----
+                    this->bShooting_ = this->canFire();                
+                }
+            }
+            //----action was set to fly, leader handles the logic----
+            else if (this->action_ == Action::FLY)
+            {
+
+            }
+        } 
+        if (this->bFirstAction_ && this->myLeader_)
+        {
+            this->parsedActionpoints_ = this->myLeader_->parsedActionpoints_;
+            this->bFirstAction_ = false;
+        }
     }
      
Index: /code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h
===================================================================
--- /code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h	(revision 10850)
+++ /code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h	(revision 10851)
@@ -63,5 +63,6 @@
                 WeakPtr<CommonController> myLeader_;
                 Timer actionTimer_; //<! Regularly calls action().
-               
+                bool bFirstAction_;
+
     };
 }
