Index: /code/branches/formation/src/orxonox/controllers/AIController.cc
===================================================================
--- /code/branches/formation/src/orxonox/controllers/AIController.cc	(revision 8964)
+++ /code/branches/formation/src/orxonox/controllers/AIController.cc	(revision 8965)
@@ -123,4 +123,9 @@
             }
 
+            // next enemy
+            random = rnd(maxrand);
+            if (random < 10 && (this->target_))
+                this->searchNewTarget();
+
             // shoot
             random = rnd(maxrand);
Index: /code/branches/formation/src/orxonox/controllers/HumanController.cc
===================================================================
--- /code/branches/formation/src/orxonox/controllers/HumanController.cc	(revision 8964)
+++ /code/branches/formation/src/orxonox/controllers/HumanController.cc	(revision 8965)
@@ -174,5 +174,12 @@
     {
         if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
+        {
             HumanController::localController_s->controllableEntity_->fire(firemode);
+            //if human fires, set slaves free. See Masterable::forceFreeSlaves()
+            if (HumanController::localController_s->state_==MASTER && HumanController::localController_s->mode_==NORMAL)
+            {
+                HumanController::localController_s->forceFreeSlaves();
+            }
+        }
     }
 
@@ -324,13 +331,15 @@
                 break;
             }
-            changedMode();
-        }
-    }
-
-    void HumanController::changedMode()
-    {
-
-    }
-    
+        }
+    }
+
+
+    //used, when slaves are in DEFEND mode.
+    void HumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage)
+    {
+        if (!this->formationFlight_ || this->state_!=MASTER || this->mode_!=DEFEND) return;
+            this->masterAttacked(originator);
+    }
+
     void HumanController::addBots(unsigned int amount)
     {
Index: /code/branches/formation/src/orxonox/controllers/HumanController.h
===================================================================
--- /code/branches/formation/src/orxonox/controllers/HumanController.h	(revision 8964)
+++ /code/branches/formation/src/orxonox/controllers/HumanController.h	(revision 8965)
@@ -88,5 +88,6 @@
             static void toggleFormationFlight();
             static void FFChangeMode();
-            static void changedMode();
+            virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
+
 
             static void addBots(unsigned int amount);
Index: /code/branches/formation/src/orxonox/controllers/Masterable.cc
===================================================================
--- /code/branches/formation/src/orxonox/controllers/Masterable.cc	(revision 8964)
+++ /code/branches/formation/src/orxonox/controllers/Masterable.cc	(revision 8965)
@@ -319,7 +319,7 @@
 			copyTargetOrientation();
 		    }
-                if (distance < 40)
-                {
-                    this->getControllableEntity()->moveFrontBack(0.2f*SPEED_MASTER);
+                if (distance < 100)
+                {   //linear speed reduction
+                    this->getControllableEntity()->moveFrontBack(distance/100.0f*0.4f*SPEED_MASTER);
 		   
                 } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
@@ -451,7 +451,5 @@
             this->state_ = MASTER;
             this->myMaster_ = 0;
-            orxout(debug_output) << "search new master: no master found, but "<<teamSize<<" teammates"<< endl;
-        } else if (this->state_ != SLAVE)
-            orxout(debug_output) << "search new master: no master found, no teammates..."<< endl;
+        }
     }
  /**
@@ -620,7 +618,8 @@
                  (*it)->myMaster_=this;
             }
+            this->myMaster_=0;
             this->state_=MASTER;
         }
-        //debug
+        /*/debug
         if (this->state_==SLAVE)
            {orxout(debug_output) << this << " is slave "<< endl;}
@@ -628,6 +627,11 @@
            {orxout(debug_output) << this << " is now a master of "<<this->slaves_.size()<<" slaves."<< endl;}
         if (this->state_==FREE)
-           {orxout(debug_output) << this << " is free "<< endl;}
-    }
+           {orxout(debug_output) << this << " is free "<< endl;}*/
+    }
+
+    void Masterable::masterAttacked(Pawn* originator)
+    {
+       orxout(debug_output)<<"slaves, attack!"<<endl;
+    }     
 
 
@@ -904,16 +908,35 @@
     }
 
-/*
-    bool Masterable::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
-    {
-        if (!entity1 || !entity2) return false;
-        if (entity1 == entity2) return true;
-
-        if (!gametype)
-            orxout(debug_output) << "gametype NULL"<< endl;
+  bool Masterable::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
+    {
+        if (entity1 == entity2)
+            return true;
 
         int team1 = -1;
         int team2 = -1;
 
+        Controller* controller = 0;
+        if (entity1->getController())
+            controller = entity1->getController();
+        else
+            controller = entity1->getXMLController();
+        if (controller)
+        {
+            Masterable* ac = orxonox_cast<Masterable*>(controller);
+            if (ac)
+                team1 = ac->getTeam();
+        }
+
+        if (entity2->getController())
+            controller = entity2->getController();
+        else
+            controller = entity2->getXMLController();
+        if (controller)
+        {
+            Masterable* ac = orxonox_cast<Masterable*>(controller);
+            if (ac)
+                team2 = ac->getTeam();
+        }
+
         TeamDeathmatch* tdm = orxonox_cast<TeamDeathmatch*>(gametype);
         if (tdm)
@@ -924,14 +947,6 @@
             if (entity2->getPlayer())
                 team2 = tdm->getTeam(entity2->getPlayer());
-             orxout(debug_output) << "teamdeath okay"<< endl;
-        }
-
-        if (team1!=-1 && team2!=-1)
-        {
-            orxout(debug_output) << "Sameteam: decided in TeamDeathmatch. return "<<(team1 == team2 && team1 != -1)<< endl;
-            return (team1 == team2 && team1 != -1); 
-        }
-        team1=team2=-1;
-        orxout(debug_output) << "Sameteam: not in teamdeathmatch."<< endl;
+        }
+
         TeamBaseMatchBase* base = 0;
         base = orxonox_cast<TeamBaseMatchBase*>(entity1);
@@ -967,9 +982,4 @@
             }
         }
-
-        if (team1!=-1 && team2!=-1)
-            return (team1 == team2 && team1 != -1); 
-        team1=team2=-1;
-
 
         DroneController* droneController = 0;
@@ -1004,114 +1014,4 @@
 
         return (team1 == team2 && team1 != -1);
-
-    }*/
-
-  bool Masterable::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
-    {
-        if (entity1 == entity2)
-            return true;
-
-        int team1 = -1;
-        int team2 = -1;
-
-        Controller* controller = 0;
-        if (entity1->getController())
-            controller = entity1->getController();
-        else
-            controller = entity1->getXMLController();
-        if (controller)
-        {
-            Masterable* ac = orxonox_cast<Masterable*>(controller);
-            if (ac)
-                team1 = ac->getTeam();
-        }
-
-        if (entity2->getController())
-            controller = entity2->getController();
-        else
-            controller = entity2->getXMLController();
-        if (controller)
-        {
-            Masterable* ac = orxonox_cast<Masterable*>(controller);
-            if (ac)
-                team2 = ac->getTeam();
-        }
-
-        TeamDeathmatch* tdm = orxonox_cast<TeamDeathmatch*>(gametype);
-        if (tdm)
-        {
-            if (entity1->getPlayer())
-                team1 = tdm->getTeam(entity1->getPlayer());
-
-            if (entity2->getPlayer())
-                team2 = tdm->getTeam(entity2->getPlayer());
-            return (team1 == team2 && team1 != -1); //temp solution
-        }
-
-        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);
     }
 
Index: /code/branches/formation/src/orxonox/controllers/Masterable.h
===================================================================
--- /code/branches/formation/src/orxonox/controllers/Masterable.h	(revision 8964)
+++ /code/branches/formation/src/orxonox/controllers/Masterable.h	(revision 8965)
@@ -78,5 +78,5 @@
       inline void setTeam(int team)
            { this->team_ = team; 
-             orxout(debug_output) << "Set team to: "<<team<<" in "<<this<< endl;}
+             orxout(debug_output) << "Set team to: "<<team<<" in "<<this<< endl;} 
       inline int getTeam() const
            { return this->team_; }
@@ -134,4 +134,5 @@
 
       void takeLeadOfFormation();
+      void masterAttacked(Pawn* originator);      
 
       void specificMasterActionHold();
Index: /code/branches/formation/src/orxonox/controllers/NewHumanController.cc
===================================================================
--- /code/branches/formation/src/orxonox/controllers/NewHumanController.cc	(revision 8964)
+++ /code/branches/formation/src/orxonox/controllers/NewHumanController.cc	(revision 8965)
@@ -297,4 +297,7 @@
     void NewHumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage)
     {
+        //Used in HumanController for formationFlight
+        HumanController::hit(originator,contactpoint,damage);
+        
         if (this->showDamageOverlay_ && !this->controlPaused_ && this->controllableEntity_ && !this->controllableEntity_->isInMouseLook())
         {
