Index: code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	(revision 10798)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	(revision 10799)
@@ -9,5 +9,5 @@
  *   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.
+ *   of the License, or ( at your option )any later version.
  *
  *   This program is distributed in the hope that it will be useful,
@@ -44,9 +44,9 @@
 {
 
-    RegisterClass(CommonController);
+    RegisterClass( CommonController );
     float SPEED = 0.7f/0.02f;
     float ROTATEFACTOR = 0.3f/0.02f;
 
-    CommonController::CommonController(Context* context) : Controller(context)
+    CommonController::CommonController( Context* context ): Controller( context )
     {
         this->bSetupWorked = false;
@@ -56,38 +56,38 @@
 
         this->maneuverType_ = ManeuverType::NONE;
-        RegisterObject(CommonController);
-    }
-
-
-    CommonController::~CommonController()
-    {
-    }
-
-    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);
+        RegisterObject( CommonController );
+    }
+
+
+    CommonController::~CommonController() 
+    {
+    }
+
+    void CommonController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
+    {
+        SUPER( CommonController, XMLPort, xmlelement, mode );
+        XMLPortParam( CommonController, "formationMode", setFormationModeXML, getFormationModeXML,  xmlelement, mode );
+
+    }
+    void CommonController::setFormationModeXML( std::string val )
+    {
+        const std::string valUpper = getUppercase( val );
         FormationMode::Value value;
-        if (valUpper == "VEE")
+        if ( valUpper == "VEE" )
             value = FormationMode::VEE;
-        else if (valUpper == "WALL")
+        else if ( valUpper == "WALL" )
             value = FormationMode::WALL;
-        else if (valUpper == "FINGER4")
+        else if ( valUpper == "FINGER4" )
             value = FormationMode::FINGER4;
-        else if (valUpper == "DIAMOND")
+        else if ( valUpper == "DIAMOND" )
             value = FormationMode::DIAMOND;
         else
-            ThrowException(ParseError, std::string("Attempting to set an unknown FormationMode: '") + val + "'.");
-        this->setFormationMode(value);
+            ThrowException( ParseError, std::string( "Attempting to set an unknown FormationMode: '" )+ val + "'." );
+        this->setFormationMode( value );
        
     }
-    std::string CommonController::getFormationModeXML()
-    {
-        switch (this->formationMode_)
+    std::string CommonController::getFormationModeXML() 
+    {
+        switch ( this->formationMode_ )
         {
             case FormationMode::VEE:
@@ -117,26 +117,40 @@
         }
     }
-    void CommonController::maneuver()
-    {
-
-        if (this->target_ && this->bHasPositionOfTarget_ && this->getControllableEntity())
-        {
-            Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
+    void CommonController::maneuver() 
+    {
+
+        if ( this->target_ && this->bHasPositionOfTarget_ && 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->setPositionOfTarget( this->target_->getWorldPosition()  );
+            this->setOrientationOfTarget( this->target_->getControllableEntity() ->getOrientation() );
+
+
+            Vector3 diffVector = this->positionOfTarget_ - thisPosition;
             float diffLength = diffVector.length();
             Vector3 diffUnit = diffVector/diffLength;
 
-            Vector3 myForwardVector = this->getControllableEntity()->getOrientation() * WorldEntity::FRONT;
-            float myDotProduct = diffVector.dotProduct(myForwardVector);
-
-            Vector3 opponentForwardVector = this->target_->getOrientation() * WorldEntity::FRONT;
-            float opponentDotProduct = diffVector.dotProduct(opponentForwardVector);            
-
-            float myAngle = math::arccos ( myForwardVector.dotProduct(diffVector)/(diffLength) );
-            float targetAngle = math::arccos ( opponentForwardVector.dotProduct(-diffVector)/(diffLength) );
+            Vector3 thisForwardVector = thisOrientation * WorldEntity::FRONT;
+            float thisDotProduct = diffVector.dotProduct( thisForwardVector );
+
+            Vector3 targetForwardVector = this->orientationOfTarget_ * WorldEntity::FRONT;
+            float targetDotProduct = diffVector.dotProduct( targetForwardVector );            
+
+            float thisAngle = getAngle( thisPosition, thisForwardVector, this->positionOfTarget_ ); 
+            float targetAngle = getAngle( this->positionOfTarget_, targetForwardVector, thisPosition ); 
+
+
+            bool bThisIsLookingAtTarget = ( thisAngle/( diffLength*diffLength ) < math::pi/8000000.0f );
+            bool bTargetIsLookingAtThis = ( targetAngle/( diffLength*diffLength ) < math::pi/8000000.0f );
             
-            bool bThisIsLookingAtTarget = (myAngle/(diffLength*diffLength) < math::pi/8000000.0f);
-            bool bTargetIsLookingAtThis = (targetAngle/(diffLength*diffLength) < math::pi/8000000.0f);
-            
-            float angleDiff = targetAngle - myAngle;
+            float angleDiff = targetAngle - thisAngle;
 
             //if his angle is bigger than mine
@@ -152,5 +166,5 @@
                         moveToPoint( 
                             *target, 
-                            randomInRange(45, 180) 
+                            randomInRange( 45, 180 )
                             );
                     }
@@ -158,16 +172,16 @@
                     else
                     {
-                        Vector3 target = (diffUnit) * 150.0f
+                        Vector3 target = ( diffUnit )* 150.0f
                         Vector3* randVector = new Vector3( 
-                            randomInRange(-300, 300), 
-                            randomInRange(-300, 300), 
-                            randomInRange(-300, 300)  
+                            randomInRange( -300, 300 ), 
+                            randomInRange( -300, 300 ), 
+                            randomInRange( -300, 300 ) 
                         );
-                        Vector3 projection = randVector.dotProduct(diffUnit) * diffUnit;
+                        Vector3 projection = randVector.dotProduct( diffUnit )* diffUnit;
                         *randVector -= projection;
                         target += randVector;
                         moveToPoint( 
                             *target, 
-                            randomInRange(45, 180) 
+                            randomInRange( 45, 180 )
                             );
                     }
@@ -179,10 +193,10 @@
                     if ( diffLength < 300 )
                     {
-                        this->setTargetPosition( this->getControllableEntity()->getWorldPosition() );
+                        this->setTargetPosition( this->getControllableEntity() ->getWorldPosition()  );
                     }
                     //move closer
                     else
                     {
-                        this->setTargetPosition( this->positionOfTarget_ - 0.6f*diffVector);
+                        this->setTargetPosition( this->positionOfTarget_ - 0.6f*diffVector );
                     }
                 }
@@ -190,28 +204,28 @@
            
         }
-        if (this->getControllableEntity() && !this->target_)
+        if ( this->getControllableEntity()  && !this->target_ )
         {
             this->maneuverType_ = ManeuverType::NONE;
         }
-        orxout (internal_error) << "ManeuverType = " << this->maneuverType_ << endl;
-    }
-    void CommonController::chooseManeuverType()
-    {
-
-        if (this->target_ && this->bHasPositionOfTarget_ && this->getControllableEntity())
-        {
-            Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
-            Vector3 myForwardVector = this->getControllableEntity()->getOrientation() * WorldEntity::FRONT;
-            float myDotProduct = diffVector.dotProduct(myForwardVector);
-
-            Vector3 opponentForwardVector = this->target_->getOrientation() * WorldEntity::FRONT;
-            float opponentDotProduct = diffVector.dotProduct(opponentForwardVector);            
-
-
-            switch ((myDotProduct > 0) - (myDotProduct < 0))
+        orxout ( internal_error ) << "ManeuverType = " << this->maneuverType_ << endl;
+    }
+    void CommonController::chooseManeuverType() 
+    {
+
+        if ( this->target_ && this->bHasPositionOfTarget_ && this->getControllableEntity() )
+        {
+            Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity() ->getWorldPosition();
+            Vector3 thisForwardVector = this->getControllableEntity() ->getOrientation()  * WorldEntity::FRONT;
+            float thisDotProduct = diffVector.dotProduct( thisForwardVector );
+
+            Vector3 targetForwardVector = this->target_->getOrientation()  * WorldEntity::FRONT;
+            float targetDotProduct = diffVector.dotProduct( targetForwardVector );            
+
+
+            switch ( ( thisDotProduct > 0 )- ( thisDotProduct < 0 ))
             {
                 case 1:
                 {
-                    switch ((opponentDotProduct > 0) - (opponentDotProduct < 0))
+                    switch ( ( targetDotProduct > 0 )- ( targetDotProduct < 0 ))
                     {
                         case 1:
@@ -235,5 +249,5 @@
                 case 0:
                 {
-                    switch ((opponentDotProduct > 0) - (opponentDotProduct < 0))
+                    switch ( ( targetDotProduct > 0 )- ( targetDotProduct < 0 ))
                     {
                         case 1:
@@ -258,5 +272,5 @@
                 case -1:
                 {
-                    switch ((opponentDotProduct > 0) - (opponentDotProduct < 0))
+                    switch ( ( targetDotProduct > 0 )- ( targetDotProduct < 0 ))
                     {
                         case 1:
@@ -280,42 +294,42 @@
             }
         }
-        if (this->getControllableEntity() && !this->target_)
+        if ( this->getControllableEntity()  && !this->target_ )
         {
             this->maneuverType_ = ManeuverType::NONE;
         }
-        orxout (internal_error) << "ManeuverType = " << this->maneuverType_ << endl;
-    }
-    bool CommonController::setWingman (CommonController* wingman)
+        orxout ( internal_error ) << "ManeuverType = " << this->maneuverType_ << endl;
+    }
+    bool CommonController::setWingman ( CommonController* wingman )
     {
         return false;
     }
    
-    bool CommonController::hasWingman()
+    bool CommonController::hasWingman() 
     {
         return true;
     }
-    void CommonController::setTarget(ControllableEntity* target)
+    void CommonController::setTarget( ControllableEntity* target )
     {
         this->target_ = target;
-        orxout (internal_error) << " TARGET SET " << endl;
+        orxout ( internal_error ) << " TARGET SET " << endl;
         
-        if (this->target_ )
-        {
-            this->setPositionOfTarget(target_->getWorldPosition());
-
-        }
-    }
-    bool CommonController::hasTarget()
-    {
-        if (this->target_)
+        if ( this->target_ )
+        {
+            this->setPositionOfTarget( target_->getWorldPosition() );
+
+        }
+    }
+    bool CommonController::hasTarget() 
+    {
+        if ( this->target_ )
             return true;
         return false;
     }
-    void CommonController::setPositionOfTarget(const Vector3& target)
+    void CommonController::setPositionOfTarget( const Vector3& target )
     {
         this->positionOfTarget_ = target;
         this->bHasPositionOfTarget_ = true;
     }
-    void CommonController::setOrientationOfTarget(const Quaternion& orient)
+    void CommonController::setOrientationOfTarget( const Quaternion& orient )
     {
         this->orientationOfTarget_=orient;
@@ -323,5 +337,5 @@
     }
 
-    void CommonController::setTargetPosition(const Vector3& target)
+    void CommonController::setTargetPosition( const Vector3& target )
     {
         this->targetPosition_ = target;
@@ -329,5 +343,5 @@
     }
 
-    void CommonController::setTargetOrientation(const Quaternion& orient)
+    void CommonController::setTargetOrientation( const Quaternion& orient )
     {
         this->targetOrientation_=orient;
@@ -335,23 +349,23 @@
     }
 
-    void CommonController::setTargetOrientation(ControllableEntity* target)
-    {
-        if (target)
-            setTargetOrientation(target->getOrientation());
-    }
-
-    /*void CommonController::spin()
+    void CommonController::setTargetOrientation( ControllableEntity* target )
+    {
+        if ( target )
+            setTargetOrientation( target->getOrientation() );
+    }
+
+    /*void CommonController::spin() 
     {
         this->moveToTargetPosition();
-        this->getControllableEntity()->rotateRoll(8.0f);
-    }
-    void CommonController::turn180()
-    {
-        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
-
-        this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x);
-        this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y);
-
-        this->getControllableEntity()->moveFrontBack(SPEED);
+        this->getControllableEntity() ->rotateRoll( 8.0f );
+    }
+    void CommonController::turn180() 
+    {
+        Vector2 coord = get2DViewdirection( this->getControllableEntity() ->getPosition() , this->getControllableEntity() ->getOrientation()  * WorldEntity::FRONT, this->getControllableEntity() ->getOrientation()  * WorldEntity::UP, this->targetPosition_ );
+
+        this->getControllableEntity() ->rotateYaw( -2.0f * sgn( coord.x )* coord.x*coord.x );
+        this->getControllableEntity() ->rotatePitch( 2.0f * sgn( coord.y )* coord.y*coord.y );
+
+        this->getControllableEntity() ->moveFrontBack( SPEED );
     }*/
 
@@ -359,38 +373,38 @@
 
     //copy the Roll orientation of given Quaternion.
-    void CommonController::copyOrientation(const Quaternion& orient, float 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_)
+        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)
+            copyOrientation( targetOrientation_, dt );
+        }
+    }
+
+
+
+
+    void CommonController::moveToTargetPosition( float dt )
+    {
+        this->moveToPosition( this->targetPosition_, dt );
+    }
+    void CommonController::moveToPosition( const Vector3& target, float dt )
     {
         float factor = 1;
-        if (!this->getControllableEntity())
+        if ( !this->getControllableEntity() )
             return;
-        if (this->rank_ == Rank::DIVISIONLEADER)
+        if ( this->rank_ == Rank::DIVISIONLEADER )
             factor = 0.8;
-        if (this->rank_ == Rank::SECTIONLEADER)
+        if ( this->rank_ == Rank::SECTIONLEADER )
             factor = 0.9;
         
-        //100 is (so far) the smallest tolerance (empirically found) that can be reached, 
+        //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 = 60;
@@ -398,24 +412,24 @@
         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();
+            ( 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);
+        float rotateX = clamp( coord.x * 10, -1.0f, 1.0f );
+        float rotateY = clamp( coord.y * 10, -1.0f, 1.0f );
 
         
-        if (distance > tolerance)
+        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);
+            this->getControllableEntity() ->rotateYaw( -2.0f * ROTATEFACTOR * rotateX * dt );
+            this->getControllableEntity() ->rotatePitch( 2.0f * ROTATEFACTOR * rotateY * dt );
 
             //300 works, maybe less is better
-            if (distance < 400)
+            if ( distance < 400 )
             {
                 //Change roll when close. When Spaceship faces target, roll doesn't affect it's trajectory
@@ -423,11 +437,11 @@
                 //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(1.2f*SPEED*factor * dt);
+                if ( bHasTargetOrientation_ )
+                {
+                    copyTargetOrientation( dt );
+                }
+            }
+
+            this->getControllableEntity() ->moveFrontBack( 1.2f*SPEED*factor * dt );
         }
         else
@@ -437,40 +451,40 @@
         }
     }
-    float CommonController::randomInRange(float a, float b)
-    {
-        float random = rnd(1.0f);
+    float CommonController::randomInRange( float a, float b )
+    {
+        float random = rnd( 1.0f );
         float diff = b - a;
         float r = random * diff;
         return a + r;
     }
-    void CommonController::attack()
-    {
-        if ( !this->getControllableEntity() )
+    void CommonController::attack() 
+    {
+        if ( !this->getControllableEntity()  )
             return;
         if ( this->target_ )
         {
             this->positionOfTarget_ = getPredictedPosition( 
-                this->getControllableEntity()->getWorldPosition(), 
+                this->getControllableEntity() ->getWorldPosition() , 
                 hardcoded_projectile_speed, 
-                this->target_->getWorldPosition(), 
-                this->target_->getVelocity() 
+                this->target_->getWorldPosition() , 
+                this->target_->getVelocity()  
                 );
-            Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
+            Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity() ->getWorldPosition();
             float diffLength = diffVector.length();
-            if (diffLength < 100)
+            if ( diffLength < 100 )
             {
                 Vector3* targetPosition;
                 targetPosition = new Vector3 ( 
-                    //randomInRange(200, 300), 
+                    //randomInRange( 200, 300 ), 
                     0,
-                    //randomInRange(-300, -200), 
+                    //randomInRange( -300, -200 ), 
                     0,
-                    randomInRange(-300, -400) 
+                    randomInRange( -300, -400 )
                     );
-                Quaternion rotationToTarget = (this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).getRotationTo(diffVector);
-                Vector3 target = rotationToTarget * (*targetPosition);
+                Quaternion rotationToTarget = ( this->getControllableEntity() ->getOrientation()  * WorldEntity::FRONT ).getRotationTo( diffVector );
+                Vector3 target = rotationToTarget * ( *targetPosition );
                 moveToPoint( 
                     target, 
-                    randomInRange(45, 180) 
+                    randomInRange( 45, 180 )
                     );
                 executingMoveToPoint_ = true; 
@@ -479,8 +493,8 @@
             this->bShooting_ = true;
             this->positionOfTarget_ = getPredictedPosition( 
-                this->getControllableEntity()->getWorldPosition(), 
+                this->getControllableEntity() ->getWorldPosition() , 
                 hardcoded_projectile_speed, 
-                this->target_->getWorldPosition(), 
-                this->target_->getVelocity() 
+                this->target_->getWorldPosition() , 
+                this->target_->getVelocity()  
                 );
             this->targetPosition_ = positionOfTarget_;
@@ -492,25 +506,25 @@
         }
     }
-    void CommonController::scissors()
-    {
-        if ( !this->getControllableEntity() )
+    void CommonController::scissors() 
+    {
+        if ( !this->getControllableEntity()  )
             return;
         if ( this->target_ )
         {
             this->positionOfTarget_ = getPredictedPosition( 
-                this->getControllableEntity()->getWorldPosition(), 
+                this->getControllableEntity() ->getWorldPosition() , 
                 hardcoded_projectile_speed, 
-                this->target_->getWorldPosition(), 
-                this->target_->getVelocity() 
+                this->target_->getWorldPosition() , 
+                this->target_->getVelocity()  
                 );
-            Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
+            Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity() ->getWorldPosition();
             float diffLength = diffVector.length();
-            Vector3 opponentForwardVector = this->target_->getOrientation() * WorldEntity::FRONT;
-            float opponentDotProduct = diffVector.dotProduct(opponentForwardVector);            
+            Vector3 targetForwardVector = this->target_->getOrientation()  * WorldEntity::FRONT;
+            float targetDotProduct = diffVector.dotProduct( targetForwardVector );            
             
-            int f = (int) rnd(100.0f);
-            f = (f % 2 == 0 ? 1 : -1);
-
-            if(!this->executingMoveToPoint_)
+            int f = ( int )rnd( 100.0f );
+            f = ( f % 2 == 0 ? 1 : -1 );
+
+            if( !this->executingMoveToPoint_ )
             {
                 Vector3* targetPosition;
@@ -518,9 +532,9 @@
                 {
                     targetPosition = new Vector3 ( 
-                        //f * randomInRange(200, 300), 
-                        0,
-                        //f * randomInRange(-300, -200), 
-                        0,
-                        //randomInRange(-300, -400) 
+                        //f * randomInRange( 200, 300 ), 
+                        0,
+                        //f * randomInRange( -300, -200 ), 
+                        0,
+                        //randomInRange( -300, -400 )
                         0
                         );
@@ -528,12 +542,12 @@
                 else
                 {
-                    if ( opponentDotProduct < 0 )
+                    if ( targetDotProduct < 0 )
                     {
                         targetPosition = new Vector3 ( 
-                        //f * randomInRange(200, 300), 
-                        0,
-                        //f * randomInRange(-300, -200), 
-                        0,
-                        //randomInRange(-300, -400) 
+                        //f * randomInRange( 200, 300 ), 
+                        0,
+                        //f * randomInRange( -300, -200 ), 
+                        0,
+                        //randomInRange( -300, -400 )
                         -300
                         );
@@ -542,18 +556,18 @@
                     {
                         targetPosition = new Vector3 ( 
-                        //f * randomInRange(200, 300), 
-                        0,
-                        //f * randomInRange(-300, -200), 
-                        0,
-                        //randomInRange(-300, -400) 
+                        //f * randomInRange( 200, 300 ), 
+                        0,
+                        //f * randomInRange( -300, -200 ), 
+                        0,
+                        //randomInRange( -300, -400 )
                         300
                         );
                     }
                 }
-                Quaternion rotationToTarget = (this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).getRotationTo(diffVector);
-                Vector3 target = rotationToTarget * (*targetPosition);
+                Quaternion rotationToTarget = ( this->getControllableEntity() ->getOrientation()  * WorldEntity::FRONT ).getRotationTo( diffVector );
+                Vector3 target = rotationToTarget * ( *targetPosition );
                 moveToPoint( 
                     target, 
-                    randomInRange(45, 180) 
+                    randomInRange( 45, 180 )
                     );
                 executingMoveToPoint_ = true;  
@@ -566,19 +580,19 @@
         }
     }
-    void CommonController::gunsD()
-    {
-        if ( !this->getControllableEntity() )
+    void CommonController::gunsD() 
+    {
+        if ( !this->getControllableEntity()  )
             return;
         if ( this->target_ )
         {
             this->positionOfTarget_ = getPredictedPosition( 
-                this->getControllableEntity()->getWorldPosition(), 
+                this->getControllableEntity() ->getWorldPosition() , 
                 hardcoded_projectile_speed, 
-                this->target_->getWorldPosition(), 
-                this->target_->getVelocity() 
+                this->target_->getWorldPosition() , 
+                this->target_->getVelocity()  
                 );
-            Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
+            Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity() ->getWorldPosition();
             float diffLength = diffVector.length();
-            if(!this->executingMoveToPoint_)
+            if( !this->executingMoveToPoint_ )
             {
                 Vector3* targetPosition;
@@ -586,9 +600,9 @@
                 {
                     targetPosition = new Vector3 ( 
-                        //f * randomInRange(200, 300), 
-                        0,
-                        //f * randomInRange(-300, -200), 
-                        0,
-                        //randomInRange(-300, -400) 
+                        //f * randomInRange( 200, 300 ), 
+                        0,
+                        //f * randomInRange( -300, -200 ), 
+                        0,
+                        //randomInRange( -300, -400 )
                         0
                         );
@@ -597,9 +611,9 @@
                 {
                     targetPosition = new Vector3 ( 
-                        //randomInRange(100, 200), 
-                        0,
-                        //randomInRange(-200, -100), 
-                        0,
-                        //randomInRange(-400, -600) 
+                        //randomInRange( 100, 200 ), 
+                        0,
+                        //randomInRange( -200, -100 ), 
+                        0,
+                        //randomInRange( -400, -600 )
                         500
                         );
@@ -608,17 +622,17 @@
                 {
                     targetPosition = new Vector3 ( 
-                        //randomInRange(200, 300), 
-                        0,
-                        //randomInRange(-300, -200), 
-                        0,
-                        //randomInRange(-400, -600) 
+                        //randomInRange( 200, 300 ), 
+                        0,
+                        //randomInRange( -300, -200 ), 
+                        0,
+                        //randomInRange( -400, -600 )
                         500
                         );
                 }
-                Quaternion rotationToTarget = (this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).getRotationTo(diffVector);
-                Vector3 target = rotationToTarget * (*targetPosition);
+                Quaternion rotationToTarget = ( this->getControllableEntity() ->getOrientation()  * WorldEntity::FRONT ).getRotationTo( diffVector );
+                Vector3 target = rotationToTarget * ( *targetPosition );
                 moveToPoint( 
                     target, 
-                    randomInRange(45, 180) 
+                    randomInRange( 45, 180 )
                     );
                 executingMoveToPoint_ = true;  
@@ -633,17 +647,17 @@
     //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)
+    //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)
+        if ( !entity )
             return;
         Quaternion orient = entity->getWorldOrientation();
-        Quaternion rotation = Quaternion(Degree(angleRoll), Vector3::UNIT_Z);
+        Quaternion rotation = Quaternion( Degree( angleRoll ), Vector3::UNIT_Z );
 
         Vector3 target = orient * relativeTargetPosition + entity->getWorldPosition();
-        setTargetPosition(target);
+        setTargetPosition( target );
         orient = orient * rotation;
-        this->setTargetOrientation(orient);
+        this->setTargetOrientation( orient );
        
     }
@@ -657,45 +671,45 @@
     //otherwise returns true
     //dt is normally around 0.02f, which makes it 1/0.02 = 50 frames/sec
-    bool CommonController::moveAndRoll(float dt)
+    bool CommonController::moveAndRoll( float dt )
     {
         float factor = 1;
-        if (!this->getControllableEntity())
+        if ( !this->getControllableEntity() )
             return false;
-        if (this->rank_ == Rank::DIVISIONLEADER)
+        if ( this->rank_ == Rank::DIVISIONLEADER )
             factor = 0.8;
-        if (this->rank_ == Rank::SECTIONLEADER)
+        if ( this->rank_ == Rank::SECTIONLEADER )
             factor = 0.9;
         int tolerance = 60;
         
         ControllableEntity* entity = this->getControllableEntity();
-        if (!entity)
+        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();
+            ( 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);
+        float rotateX = clamp( coord.x * 10, -1.0f, 1.0f );
+        float rotateY = clamp( coord.y * 10, -1.0f, 1.0f );
 
         
-        if (distance > tolerance)
+        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);
+            this->getControllableEntity() ->rotateYaw( -2.0f * ROTATEFACTOR * rotateX * dt );
+            this->getControllableEntity() ->rotatePitch( 2.0f * ROTATEFACTOR * rotateY * dt );
             
             //Roll
-            if (bHasTargetOrientation_)
-            {
-                copyTargetOrientation(dt);
+            if ( bHasTargetOrientation_ )
+            {
+                copyTargetOrientation( dt );
             }
           
             //Move
-            this->getControllableEntity()->moveFrontBack(1.2f * SPEED * factor * dt);
+            this->getControllableEntity() ->moveFrontBack( 1.2f * SPEED * factor * dt );
             //if still moving, return false
             return false;
@@ -709,26 +723,26 @@
     }
 
-    float CommonController::squaredDistanceToTarget() const
-    {
-        if ( !this->getControllableEntity() )
+    float CommonController::squaredDistanceToTarget()  const
+    {
+        if ( !this->getControllableEntity()  )
             return 0;
         if ( !this->target_ )
-            return ( this->getControllableEntity()->getPosition().squaredDistance(this->targetPosition_) );
+            return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->targetPosition_ ) );
         else
-            return ( this->getControllableEntity()->getPosition().squaredDistance(this->target_->getPosition()) );
+            return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->target_->getPosition() ) );
     }
     
-    bool CommonController::isLookingAtTarget(float angle) const
-    {
-        if (!this->getControllableEntity())
+    bool CommonController::isLookingAtTarget( float angle )const
+    {
+        if ( !this->getControllableEntity() )
             return false;
 
-        return (getAngle(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->targetPosition_) < angle);
-    }
-
-    bool CommonController::canFire()
+        return ( getAngle( this->getControllableEntity() ->getPosition() , this->getControllableEntity() ->getOrientation()  * WorldEntity::FRONT, this->targetPosition_ ) < angle );
+    }
+
+    bool CommonController::canFire() 
     {
         float squaredDistance = squaredDistanceToTarget();
-        if ( this->bShooting_ && squaredDistance < 9000000 && squaredDistance > 10000 && this->isLookingAtTarget(math::pi /(0.0002f*squaredDistance)) )
+        if ( this->bShooting_ && squaredDistance < 9000000 && squaredDistance > 10000 && this->isLookingAtTarget( math::pi /( 0.0002f*squaredDistance )) )
         {
             return true;
@@ -740,20 +754,20 @@
 
     }
-    void CommonController::doFire()
-    {
-        if (!this->target_ || !this->getControllableEntity())
+    void CommonController::doFire() 
+    {
+        if ( !this->target_ || !this->getControllableEntity() )
             return;
         static const float hardcoded_projectile_speed = 750;
 
-        this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), hardcoded_projectile_speed, this->target_->getWorldPosition(), this->target_->getVelocity());
-        this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO);
-
-        Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
-
-        if (pawn)
-            //pawn->setAimPosition(this->getControllableEntity()->getWorldPosition() + 4000*(this->getControllableEntity()->getOrientation() * WorldEntity::FRONT));
-            pawn->setAimPosition(this->targetPosition_);
+        this->targetPosition_ = getPredictedPosition( this->getControllableEntity() ->getWorldPosition() , hardcoded_projectile_speed, this->target_->getWorldPosition() , this->target_->getVelocity() );
+        this->bHasTargetPosition_ = ( this->targetPosition_ != Vector3::ZERO );
+
+        Pawn* pawn = orxonox_cast<Pawn*>( this->getControllableEntity() );
+
+        if ( pawn )
+            //pawn->setAimPosition( this->getControllableEntity() ->getWorldPosition()  + 4000*( this->getControllableEntity() ->getOrientation()  * WorldEntity::FRONT ));
+            pawn->setAimPosition( this->targetPosition_ );
     
-        this->getControllableEntity()->fire(0);
+        this->getControllableEntity() ->fire( 0 );
     }
    
