Index: code/branches/ai/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/AIController.cc	(revision 6847)
+++ code/branches/ai/src/orxonox/controllers/AIController.cc	(revision 6850)
@@ -49,11 +49,4 @@
     AIController::~AIController()
     {
-COUT(0) << "~AIController 1" << std::endl;
-        if (this->state_ == MASTER) setNewMasterWithinFormation();
-COUT(0) << "~AIController 2" << std::endl;
-        if (this->state_ == SLAVE) unregisterSlave();
-COUT(0) << "~AIController 3" << std::endl;
-        this->slaves_.clear();
-COUT(0) << "~AIController 4" << std::endl;
     }
 
@@ -63,35 +56,19 @@
         float maxrand = 100.0f / ACTION_INTERVAL;
 
-        if (this->state_ == FREE)//FREE
-        {
-
-            //this->state_ = MASTER;
-            // search master
-            //random = rnd(maxrand);
-            //if (random < 101 && (!this->target_))
+        if (this->state_ == FREE)
+        {
+
+
+            // return to Master after being forced free
+            if (this->freedomCount_ == 1)   
+            {
+                this->state_ = SLAVE;
+                this->freedomCount_ = 0;
+            }
+
+            random = rnd(maxrand);
+            if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree()))
                 this->searchNewMaster();
 
-        }
-
-        if (this->state_ == SLAVE)//SLAVE
-        {
-               // this->bShooting_ = true;
-        }
-
-        if (this->state_ == MASTER)//MASTER
-        {
-
-            // command slaves
-            this->commandSlaves();
-
-
-            // lose master status (only if less than 4 slaves in formation)
-            random = rnd(maxrand);
-            if(random < 5/(this->slaves_.size()+1) && this->slaves_.size() < 5 ) 
-                this->loseMasterState();
-
-            // look out for outher masters if formation is small
-            if(this->slaves_.size() < 3)
-                this->searchNewMaster();
 
             // search enemy
@@ -125,14 +102,77 @@
                 this->searchRandomTargetPosition();
 
-            // shoot
-            /*random = rnd(maxrand);
+
+            random = rnd(maxrand);
             if (random < 75 && (this->target_ && !this->bShooting_))
                 this->bShooting_ = true;
-*/
+
             // stop shooting
             random = rnd(maxrand);
             if (random < 25 && (this->bShooting_))
                 this->bShooting_ = false;
-        }
+
+        }
+
+        if (this->state_ == SLAVE)
+        {
+               // this->bShooting_ = true;
+        }
+
+        if (this->state_ == MASTER)//MASTER
+        {
+
+
+            this->commandSlaves();
+
+
+            // lose master status (only if less than 4 slaves in formation)
+            random = rnd(maxrand);
+            if(random < 15/(this->slaves_.size()+1) && this->slaves_.size() < 5 ) 
+                this->loseMasterState();
+
+            // look out for outher masters if formation is small
+            random = rnd(maxrand);
+            if(this->slaves_.size() < 3 && random < 20)
+                this->searchNewMaster();
+
+            // search enemy
+            random = rnd(maxrand);
+            if (random < 15 && (!this->target_))
+                this->searchNewTarget();
+
+            // forget enemy
+            random = rnd(maxrand);
+            if (random < 5 && (this->target_))
+                this->forgetTarget();
+
+            // next enemy
+            random = rnd(maxrand);
+            if (random < 10 && (this->target_))
+                this->searchNewTarget();
+
+            // fly somewhere
+            random = rnd(maxrand);
+            if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
+                this->searchRandomTargetPosition();
+
+
+            // fly somewhere else
+            random = rnd(maxrand);
+            if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
+                this->searchRandomTargetPosition();
+
+            // shoot
+            random = rnd(maxrand);
+            if (random < 5 && (this->target_ && !this->bShooting_))
+            {
+                this->bShooting_ = true;
+                this->forceFreeSlaves();
+            }
+            // stop shooting
+            random = rnd(maxrand);
+            if (random < 25 && (this->bShooting_))
+                this->bShooting_ = false;
+        }
+
     }
 
@@ -160,6 +200,16 @@
                 this->moveToTargetPosition();
 
-        //this->getControllableEntity()->fire(0);
-
+        }
+
+         if (this->state_ == FREE)
+        {
+            if (this->target_)
+                this->aimAtTarget();
+
+            if (this->bHasTargetPosition_)
+                this->moveToTargetPosition();
+
+            if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
+                this->getControllableEntity()->fire(0);
         }
 
Index: code/branches/ai/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.cc	(revision 6847)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.cc	(revision 6850)
@@ -45,11 +45,10 @@
         this->target_ = 0;
         this->myMaster_ = 0;
-        //this->slaveNumber_ = -1;
-	this->team_ = -1;//new
-	this->state_ = FREE;//new
+        this->freedomCount_ = 0;
+	this->team_ = -1;
+	this->state_ = FREE;
         this->bShooting_ = false;
         this->bHasTargetPosition_ = false;
         this->targetPosition_ = Vector3::ZERO;
-        //this->slaves_ = new std::list<ArtificialController*>;
 
         this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this));
@@ -65,4 +64,22 @@
 
         XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(0);
+    }
+
+// gets called when Bot dies
+    void ArtificialController::changedControllableEntity()
+    {
+COUT(0) << "~changedControllableEntity 0" << std::endl;
+        if(!getControllableEntity()) 
+        {
+COUT(0) << "~changedControllableEntity 1" << std::endl;
+        if (this->state_ == SLAVE) unregisterSlave();
+COUT(0) << "~changedControllableEntity 2" << std::endl;
+         if (this->state_ == MASTER) setNewMasterWithinFormation();
+COUT(0) << "~changedControllableEntity 3" << std::endl;
+        this->slaves_.clear();
+COUT(0) << "~changedControllableEntity 4" << std::endl;
+        this->state_ = FREE;
+COUT(0) << "~changedControllableEntity 5" << std::endl;
+        }
     }
 
@@ -77,13 +94,26 @@
         if (this->target_ || distance > 10)
         {
-            // Multiply with 0.8 to make them a bit slower
-            this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x);
-            this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y);
+            // Multiply with rotateFactor to make them a bit slower
+            float rotateFactor;
+            if(this->state_ == SLAVE) rotateFactor = 1.0f;
+            if(this->state_ == MASTER) rotateFactor = 0.4f;
+            else rotateFactor = 0.8f;
+
+            this->getControllableEntity()->rotateYaw(-1.0f * rotateFactor * sgn(coord.x) * coord.x*coord.x);
+            this->getControllableEntity()->rotatePitch(rotateFactor * sgn(coord.y) * coord.y*coord.y);
+
+
+
         }
 
         if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
-            this->getControllableEntity()->moveFrontBack(-0.5f); // They don't brake with full power to give the player a chance
-        else
-            this->getControllableEntity()->moveFrontBack(0.8f);
+        {
+            if(this->state_ == SLAVE) this->getControllableEntity()->moveFrontBack(-0.8f);
+            else this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance
+        } else {
+            if(this->state_ == SLAVE) this->getControllableEntity()->moveFrontBack(2.5f);
+            if(this->state_ == MASTER) this->getControllableEntity()->moveFrontBack(0.4f);
+            else this->getControllableEntity()->moveFrontBack(0.8f);
+        }
     }
 
@@ -102,4 +132,5 @@
         {
             myMaster_->slaves_.remove(this);
+COUT(0) << "~unregister slave" << std::endl;
         }
     }
@@ -126,6 +157,7 @@
                 continue;
 
-            ArtificialController *controller = static_cast<ArtificialController*>(it->getController());
-            if (!controller || controller->getState() != MASTER)
+            ArtificialController *newMaster = static_cast<ArtificialController*>(it->getController());
+
+            if (!newMaster || newMaster->getState() != MASTER)
                 continue;
 
@@ -133,12 +165,18 @@
             if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity()) //&& it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) < 1000 
             {
-                if(controller->slaves_.size() > 9) continue;
-
-                this->freeAllSlaves();
+                if(newMaster->slaves_.size() > 6) continue;
+
+                //this->freeSlaves();
+
+                for(std::list<ArtificialController*>::iterator itSlave = this->slaves_.begin(); itSlave != this->slaves_.end(); itSlave++)
+                {
+                    (*itSlave)->myMaster_ = newMaster;
+                    newMaster->slaves_.push_back(*itSlave);
+                }
                 this->slaves_.clear();
                 this->state_ = SLAVE;
 
-                this->myMaster_ = controller;
-                controller->slaves_.push_back(this);
+                this->myMaster_ = newMaster;
+                newMaster->slaves_.push_back(this);
 
                 break;
@@ -148,5 +186,5 @@
         //hasn't encountered any masters in range? -> become a master
         if (state_!=SLAVE) state_ = MASTER; // keep in mind: what happens when two masters encounter eache other? -> has to be evaluated in the for loop within master mode in AIcontroller...
-
+COUT(0) << "~searcheNewMaster" << std::endl;
     }
 
@@ -157,19 +195,4 @@
             (*it)->setTargetPosition(this->getControllableEntity()->getPosition());
         }
-/*
-        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
-        {
-
-            if (!it->getController())
-                continue;
-
-            ArtificialController *controller = static_cast<ArtificialController*>(it->getController());
-            if (!controller || controller->getState() != SLAVE)
-                continue;
-            //controller->setTargetPosition(this->getControllableEntity()->getPosition());
-            controller->targetPosition_ = this->getControllableEntity()->getPosition();
-            controller->bHasTargetPosition_ = true;
-        }
-*/
     }
 
@@ -190,5 +213,5 @@
         newMaster->state_ = MASTER;
         newMaster->slaves_ = this->slaves_;
-        //this->slaves_.clear();
+        this->slaves_.clear();
 
         this->state_ = SLAVE;
@@ -205,28 +228,43 @@
     }
 
-    void ArtificialController::freeAllSlaves()
-    {
-
-
+    void ArtificialController::freeSlaves()
+    {
         for(std::list<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
         {
             (*it)->state_ = FREE;
         }
-/*
-        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
-        {
-            ArtificialController *controller = static_cast<ArtificialController*>(it->getController());
-            if (controller && controller->getState() != SLAVE)
-                continue;
-
-            controller->state_ = FREE;
-        }
-*/
+        this->slaves_.clear();
+    }
+
+    void ArtificialController::forceFreeSlaves()
+    {
+        for(std::list<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
+        {
+            (*it)->state_ = FREE;
+            (*it)->forceFreedom();
+            (*it)->targetPosition_ = this->targetPosition_;
+            (*it)->bShooting_ = true;
+            (*it)->getControllableEntity()->fire(0);
+        }
     }
 
     void ArtificialController::loseMasterState()
     {
-        this->freeAllSlaves();
+        this->freeSlaves();
         this->state_ = FREE;
+    }
+
+    void ArtificialController::forceFreedom()
+    {
+        this->freedomCount_ = 5;
+    }
+
+    bool ArtificialController::forcedFree()
+    {
+        if(this->freedomCount_ > 0) 
+        {
+            this->freedomCount_--;
+            return true;
+        } else return false;
     }
 
Index: code/branches/ai/src/orxonox/controllers/ArtificialController.h
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.h	(revision 6847)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.h	(revision 6850)
@@ -51,22 +51,32 @@
             inline int getTeam() const
                 { return this->team_; }
-            //virtual void changedControllableEntity();
+            virtual void changedControllableEntity();
 
 
         protected:
+
+            int team_;
+            int freedomCount_;
+            enum State {SLAVE, MASTER, FREE};
+            State state_;
+            std::list<ArtificialController*> slaves_;
+
             void targetDied();
 
             void moveToPosition(const Vector3& target);
+            //void speedToTargetPosition(const Vector3& target);
             void moveToTargetPosition();
 
-            enum State {SLAVE, MASTER, FREE};
             int getState();
-            std::list<ArtificialController*> slaves_;
+
             void unregisterSlave();
             void searchNewMaster();
             void commandSlaves();
             void setNewMasterWithinFormation();
-            void freeAllSlaves();
+            void freeSlaves();
+            void forceFreeSlaves();
             void loseMasterState();
+            void forceFreedom();
+            bool forcedFree();
 
             ArtificialController *myMaster_;
@@ -90,8 +100,4 @@
             bool bShooting_;
 
-
-            State state_;
-            int team_;
-
         private:
     };
Index: code/branches/ai/src/orxonox/controllers/CMakeLists.txt
===================================================================
--- code/branches/ai/src/orxonox/controllers/CMakeLists.txt	(revision 6847)
+++ code/branches/ai/src/orxonox/controllers/CMakeLists.txt	(revision 6850)
@@ -8,4 +8,4 @@
   WaypointController.cc
   WaypointPatrolController.cc
-  DroneController.cc
+  
 )
Index: code/branches/ai/src/orxonox/worldentities/CMakeLists.txt
===================================================================
--- code/branches/ai/src/orxonox/worldentities/CMakeLists.txt	(revision 6847)
+++ code/branches/ai/src/orxonox/worldentities/CMakeLists.txt	(revision 6850)
@@ -5,5 +5,4 @@
   MobileEntity.cc
   ControllableEntity.cc
-  Drone.cc
   BigExplosion.cc
   EffectContainer.cc
