Index: code/branches/AI_HS15/data/levels/AITest.oxw
===================================================================
--- code/branches/AI_HS15/data/levels/AITest.oxw	(revision 10827)
+++ code/branches/AI_HS15/data/levels/AITest.oxw	(revision 10832)
@@ -57,5 +57,5 @@
       </templates>
       <controller>
-        <DivisionController team=1 formationMode="DIAMOND">
+        <DivisionController team=1 formationMode="wall" action="FIGHT">
         </DivisionController>
       </controller>
@@ -94,5 +94,5 @@
       </templates>
       <controller>
-        <DivisionController team=2 formationMode="FINGER4">
+        <DivisionController team=2 formationMode="wall" action="FIGHT">
         </DivisionController>
       </controller>
Index: code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	(revision 10827)
+++ 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() );
 
Index: code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	(revision 10827)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	(revision 10832)
@@ -73,124 +73,118 @@
         public:
             static const float hardcoded_projectile_speed = 750;
-
             static const float ACTION_INTERVAL = 1.0f;
-
 
             CommonController(Context* context);
             virtual ~CommonController();
 
+            //----[XML data]----
+                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]----
+            //----[/XML data]----
 
+            //----[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);
+                ControllableEntity* getTarget();
+                bool hasTarget();
 
-            virtual void setFormationMode(FormationMode::Value val)
-                { this->formationMode_ = val; }
-            inline FormationMode::Value getFormationMode() const
-                { return this->formationMode_; }
-            virtual void setFormationModeXML(std::string val);
-            virtual std::string getFormationModeXML();
+                void setTargetPosition(const Vector3& target);
+                void setTargetOrientation(const Quaternion& orient);
+                void setTargetOrientation(ControllableEntity* target);
+            //----[/Interaction with other Controllers]----
 
-            virtual void setRank(Rank::Value val)
-                { this->rank_ = val; }
-            inline Rank::Value getRank() const
-                { return this->rank_; }
+            //----[Helper functions]----
+                float randomInRange(float a, float b);
+                static float distance(ControllableEntity* entity1, ControllableEntity* entity2);
+                static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2);
+                static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ;
 
-            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-
-
-
-            virtual bool setWingman(CommonController* wingman);
-            virtual bool hasWingman();
-            static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2);
-            void setTarget(ControllableEntity* target);
-            bool hasTarget();
-            ControllableEntity* getTarget();
-            void setTargetOrientation(const Quaternion& orient);
-            void setTargetOrientation(ControllableEntity* target);
-            void setTargetPosition(const Vector3& target);
-
-            /*void spin();
-            void turn180();*/
-            Action::Value getAction ();
-            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 );
+                float squaredDistanceToTarget() const;
+                bool isLookingAtTarget(float angle) const;
+            //----[/Helper functions]----
 
         protected:
-            void dodge(Vector3& thisPosition, Vector3& diffUnit);
-            int counter;
-            void moveToPoint(const Vector3& relativeTargetPosition, float angleRoll);
-            bool moveAndRoll(float dt);
+            //----[Flying functionality]----
+                void stopMoving();
 
-            void moveToPosition(const Vector3& target, float dt);
-            void moveToTargetPosition(float dt);
-            //enum Mode {ROCKET, ATTACK, MOVE, HOLD};//TODO; implement DEFENCE, MOVING modes
+                void moveToPoint(const Vector3& relativeTargetPosition, float angleRoll);
+                bool moveAndRoll(float dt);
 
-            //Mode mode_;
-            void copyOrientation(const Quaternion& orient, float dt);
-            void copyTargetOrientation(float dt);
+                void moveToPosition(const Vector3& target, float dt);
+                void moveToTargetPosition(float dt);
 
-            static float distance(ControllableEntity* entity1, ControllableEntity* entity2);
-            float squaredDistanceToTarget() const;
-            void doFire();
-            void aimAtTarget();
-            bool isLookingAtTarget(float angle) const;
-            bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle )const;
+                void copyOrientation(const Quaternion& orient, float dt);
+                void copyTargetOrientation(float dt);
 
-            //checks if spaceship points at enemy and if there are allies inbetween
-            bool canFire();
-            std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode - managed by setupWeapons()
-            //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons()
-            float timeout_; //<! Timeout for rocket usage. (If a rocket misses, a bot should stop using it.)
-            void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed.
-            bool bSetupWorked; //<! If false, setupWeapons() is called.
-            int getFiremode(std::string name);
+                void lookAtTarget(float dt);
+                void stopLookingAtTarget();
+                void startLookingAtTarget();
 
-            float randomInRange(float a, float b);
-            bool bHasTargetPosition_;
-            Vector3 targetPosition_;
-            bool bHasTargetOrientation_;
-            Quaternion targetOrientation_;
+                bool bLookAtTarget_;        
+            //----[/Flying functionality]----
+            
+            //----[Fighting functionality]----
+                void maneuver();
+                void dodge(Vector3& thisPosition, Vector3& diffUnit);
+                void aimAtTarget();           
+                bool canFire();
+                void doFire();
+                void setClosestTarget();
 
-            Vector3 destination_;
-            bool bHasDestination;
+                bool bShooting_;
+                int maneuverCounter_;         
+            //----[/Fighting functionality]----            
+            
+            //----[where-to-fly information]----
+                bool bHasTargetPosition_;
+                Vector3 targetPosition_;
+                bool bHasTargetOrientation_;
+                Quaternion targetOrientation_;
+                // Vector3 destination_;
+                // bool bHasDestination;
+            //----[/where-to-fly information]----
+            
+            //----[who-to-kill information]----
+                WeakPtr<ControllableEntity> target_;
+                //WeakPtr<ControllableEntity> objectiveTarget_;
 
+                bool bHasPositionOfTarget_;
+                Vector3 positionOfTarget_;
+                bool bHasOrientationOfTarget_;
+                Quaternion orientationOfTarget_;
+            //----[/who-to-kill information]----
 
-            void stopMoving();
-            void setPositionOfTarget(const Vector3& target);
-            void setOrientationOfTarget(const Quaternion& orient);
-            bool bHasPositionOfTarget_;
-            Vector3 positionOfTarget_;
-            bool bHasOrientationOfTarget_;
-            Quaternion orientationOfTarget_;
-
-
-            WeakPtr<ControllableEntity> target_;
-            //WeakPtr<ControllableEntity> thisEntity_;
-
-           
-
-            Action::Value action_;
-            bool bEngaging_;
-            bool bShooting_;
-            WeakPtr<ControllableEntity> objectiveTarget_;
-
-            void lookAtTarget(float dt);
-            void stopLookingAtTarget();
-            void startLookingAtTarget();
-            bool bLookAtTarget_;
-            void maneuver();
-            void chooseManeuverType();
-            void gunsD();
-            void attack();
-            void scissors();
-            FormationMode::Value formationMode_;
-            Rank::Value rank_;
-        
-            bool executingMoveToPoint_;
-         
-        private:
-            
-               
+            //----["Private" variables]----
+                FormationMode::Value formationMode_;
+                Rank::Value rank_;
+                Action::Value action_;
+            //----[/"Private" variables]----               
     };
 }
Index: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	(revision 10827)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	(revision 10832)
@@ -84,36 +84,15 @@
     void DivisionController::action()
     {
-        //----find a target----
-        if ( !this->hasTarget() )
-        {
-            for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
-            {
-                if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) )
-                    continue;           
-
-                
-                if (static_cast<ControllableEntity*>(*itP) != (this)->getControllableEntity()
-                    && CommonController::distance (*itP, this->getControllableEntity())  < 10000)
-                {
-                    (this)->setAction(Action::FIGHT, *itP);
-                }   
-            }
-        }
+
         
         if (this->action_ == Action::FIGHT)
         {
-            //----choose where to go----
-            this->maneuver();
-            //----fire if you can----
-            this->bShooting_ = this->canFire();
-
-            if (this->target_)
-            {
-                if (this->myWingman_)
-                {
-                    //----wingmans shall support the fire of their leaders----
-                    this->myWingman_->setAction (Action::FIGHT, this->target_);                    
-                }
-                
+            if (!this->hasTarget())
+            {
+                //----find a target----
+                this->setClosestTarget(); 
+            }
+            else
+            {
                 //----fly in formation if far enough----
                 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
@@ -121,7 +100,29 @@
                 {
                     this->setTargetPositionOfWingman();
-                    //this->setTargetPositionOfFollower();                    
-                }   
-            }
+                    this->setTargetPositionOfFollower();                    
+                }
+                else
+                {
+                    //----wingmans shall support the fire of their leaders----
+                    if (this->myWingman_)
+                    {
+                        this->myWingman_->setAction (Action::FIGHT, this->target_);     
+                    }
+                    if (this->myFollower_)
+                    {
+                        this->myFollower_->setAction (Action::FIGHT);                                    
+                    }
+
+                }
+                
+            }
+            if (this->hasTarget())
+            {
+                //----choose where to go----
+                this->maneuver();
+                //----fire if you can----
+                this->bShooting_ = this->canFire();                
+            }
+
         }
         else if (this->action_ == Action::FLY)
@@ -152,5 +153,5 @@
             case FormationMode::FINGER4: 
             {
-                targetRelativePositionOfWingman = new Vector3 (400, 0, -200);  
+                targetRelativePositionOfWingman = new Vector3 (400, 0, 200);  
                 break;
             }
@@ -158,5 +159,5 @@
             case FormationMode::DIAMOND: 
             {
-                targetRelativePositionOfWingman = new Vector3 (400, 0, -200);                  
+                targetRelativePositionOfWingman = new Vector3 (400, 0, 200);                  
                 break;
             }
@@ -185,5 +186,5 @@
             case FormationMode::FINGER4: 
             {
-                targetRelativePositionOfFollower = new Vector3 (-400, 0, -200);   
+                targetRelativePositionOfFollower = new Vector3 (-400, 0, 200);   
                 break;
             }
@@ -191,5 +192,5 @@
             case FormationMode::DIAMOND: 
             {
-                targetRelativePositionOfFollower = new Vector3 (-400, 0, -200);                   
+                targetRelativePositionOfFollower = new Vector3 (-400, 0, 200);                   
                 break;
             }
Index: code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	(revision 10827)
+++ code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	(revision 10832)
@@ -89,31 +89,8 @@
             this->myDivisionLeader_ = newDivisionLeader;
 
-            if (newDivisionLeader)
-            {
-                //orxout(internal_error) << "new DivisionLeader set" << endl;
-            }
-            //----If no leader found, attack someone----
-            //----TODO: find closest enemy----
-            else
-            {
-                if ( !this->hasTarget() || this->action_ != Action::FIGHT )
-                {
-                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
-                    {
-                        if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) )
-                            continue;
-
-                        this->setAction(Action::FIGHT, (*itP));
-                        break;   
-                    }    
-                }
-                
-            }
-
         }
         //----If have leader----
         else
         {
-            this->chooseTarget();
         }
 
@@ -121,16 +98,18 @@
         if (this->action_ == Action::FIGHT)
         {
-            //----choose where to go----
-            this->maneuver();
-            //----fire if you can----
-            this->bShooting_ = this->canFire();
-
-            if (this->target_)
-            {
-                //----wingmans shall support the fire of their leaders----
-                if (this->myWingman_)
-                {
-                    this->myWingman_->setAction (Action::FIGHT, this->target_);                    
-                }
+            if (!this->hasTarget())
+            {
+                if (this->myDivisionLeader_)
+                {
+                    this->chooseTarget();                
+                }
+                else
+                {
+                    this->setClosestTarget(); 
+                }
+            }
+            else
+            {
+                
                 //----fly in formation if far enough----
                 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
@@ -139,4 +118,19 @@
                     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();                
             }
         }
@@ -156,5 +150,5 @@
 
     }
-    //PRE: myDivisionLeader_ != 0
+    //PRE: myDivisionLeader_ != 0 && myDivisionLeader_->action_ == Action::FIGHT
     //POST: this->target_ is set unless division leader doesn't have one
     void SectionController::chooseTarget()
@@ -211,4 +205,5 @@
 
     //----stay in formation----
+    //gani-TODO: sum targetAbso... and this->predicted position 
     void SectionController::setTargetPositionOfWingman()
     {
@@ -224,5 +219,5 @@
             case FormationMode::FINGER4: 
             {
-                targetRelativePositionOfWingman = new Vector3 (-400, 0, -200);  
+                targetRelativePositionOfWingman = new Vector3 (-400, 0, 200);  
                 break;
             }
Index: code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	(revision 10827)
+++ code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	(revision 10832)
@@ -85,28 +85,10 @@
             CommonController* newLeader = findNewLeader();
             this->myLeader_ = newLeader;
-            if (newLeader)
-            {
-                //orxout(internal_error) << "new Leader set" << endl;
-            }
-            //----If no leader found, attack someone----
-            //----TODO: find closest enemy----
-            else
-            {
-                if ( !this->hasTarget() || this->action_ != Action::FIGHT )
-                {
-                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
-                    {
-                        if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) )
-                            continue;   
-                        this->setAction(Action::FIGHT, (*itP));
-                        break;
-                    }
-                }
-            }
+           
         }
         //----If have leader, he will deal with logic----
         else
         {
-
+            this->action_ = this->myLeader_->getAction();
         }
 
@@ -115,8 +97,16 @@
         if (this->action_ == Action::FIGHT)
         {
-            //----choose where to go----
-            this->maneuver();
-            //----fire if you can----
-            this->bShooting_ = this->canFire();
+            //----If no leader found, attack someone----
+            if (!this->hasTarget() && !this->myLeader_)
+            {
+                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----
@@ -125,5 +115,5 @@
 
         }
-        //----TODO: implement protect----
+        //----gani-TODO: implement protect----
         else if (this->action_ == Action::PROTECT)
         {
