Index: code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	(revision 10826)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	(revision 10832)
@@ -51,8 +51,6 @@
     CommonController::CommonController( Context* context ): Controller( context )
     {
-        this->bSetupWorked = false;
 
        
-        this->executingMoveToPoint_ = false;
         this->action_ = Action::FLY;
         this->stopLookingAtTarget();
@@ -71,5 +69,45 @@
         SUPER( CommonController, XMLPort, xmlelement, mode );
         XMLPortParam( CommonController, "formationMode", setFormationModeXML, getFormationModeXML,  xmlelement, mode );
-
+        XMLPortParam( CommonController, "action", setActionXML, getActionXML,  xmlelement, mode );
+
+    }
+    void CommonController::setActionXML( std::string val)
+    {
+        const std::string valUpper = getUppercase( val );
+        Action::Value value;
+        
+        if ( valUpper == "FIGHT" )
+            value = Action::FIGHT;
+        else if ( valUpper == "FLY" )
+            value = Action::FLY;
+        else if ( valUpper == "PROTECT" )
+            value = Action::PROTECT;
+        else
+            ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ val + "'." );
+        this->setAction( value );
+    }
+    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;
+            }
+            default:
+                return "FIGHT";
+                break;
+        }
     }
     void CommonController::setFormationModeXML( std::string val )
@@ -118,4 +156,8 @@
         return this->action_;
     }
+    void CommonController::setAction (Action::Value action)
+    {
+        this->action_ = action;
+    }
 
     void CommonController::setAction (Action::Value action, ControllableEntity* target)
@@ -156,10 +198,35 @@
         }
     }
+    void CommonController::setClosestTarget()
+    {
+        if (!this->getControllableEntity())
+            return;
+
+        Pawn* closestTarget = 0;
+        float minDistance =  std::numeric_limits<float>::infinity();
+        
+        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+        {
+            if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) )
+                continue;
+
+            float distance = CommonController::distance (*itP, this->getControllableEntity());
+            if (distance < minDistance)
+            {
+                closestTarget = *itP;
+                minDistance = distance;
+            }
+        }
+        if (closestTarget)
+        {
+           (this)->setTarget(static_cast<ControllableEntity*>(closestTarget));
+        }   
+    }
     void CommonController::maneuver() 
     {
-        counter++;
-
-        if (counter > 5)
-            counter = 0;
+        maneuverCounter_++;
+
+        if (maneuverCounter_ > 5)
+            maneuverCounter_ = 0;
         if ( this->target_ && this->getControllableEntity())
         {
@@ -183,5 +250,5 @@
 
             //bool bThisIsLookingAtTarget = this->isLooking ( getControllableEntity(), this->target_, math::pi/4 );
-            bool bTargetIsLookingAtThis = this->isLooking ( this->target_, getControllableEntity(), math::pi/5.0f );
+            bool bTargetIsLookingAtThis = this->isLooking ( this->target_, getControllableEntity(), math::pi/10.0f );
             
 
@@ -217,5 +284,5 @@
             {
                 this->setTargetPosition( this->positionOfTarget_ );
-              /*  if (counter == 0)
+              /*  if (maneuverCounter_ == 0)
                 {
                     this->setTargetPosition( this->positionOfTarget_ );   
@@ -231,5 +298,5 @@
             {   
             
-                if (counter == 0)
+                if (maneuverCounter_ == 0)
                 {
                     this->setTargetPosition( this->positionOfTarget_ );   
@@ -562,5 +629,5 @@
             this->getControllableEntity() ->getOrientation()  * WorldEntity::FRONT, this->positionOfTarget_ ) < angle );
     }
-    bool CommonController::isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle )const
+    bool CommonController::isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle )
     {
         if ( !entityThatLooks || !entityBeingLookedAt )
@@ -587,5 +654,5 @@
         float squaredDistance = squaredDistanceToTarget();
 
-        if ( squaredDistance < 9000000.0f && this->isLookingAtTarget( math::pi / 10.0f)) {
+        if ( squaredDistance < 9000000.0f && this->isLookingAtTarget( math::pi / 20.0f)) {
             return true;
         }
@@ -615,6 +682,4 @@
         }
       
-
-        
         Pawn* pawn = orxonox_cast<Pawn*>( this->getControllableEntity() );
 
