Index: /code/branches/ai/src/orxonox/controllers/AIController.cc
===================================================================
--- /code/branches/ai/src/orxonox/controllers/AIController.cc	(revision 6794)
+++ /code/branches/ai/src/orxonox/controllers/AIController.cc	(revision 6795)
@@ -49,7 +49,11 @@
     AIController::~AIController()
     {
-        if (this->state_ == MASTER) freeAllSlaves();
+COUT(0) << "~AIController 1" << std::endl;
+        if (this->state_ == MASTER) setNewMasterWithinFormation();
+COUT(0) << "~AIController 2" << std::endl;
         if (this->state_ == SLAVE) unregisterSlave();
-        this->slaves.clear();
+COUT(0) << "~AIController 3" << std::endl;
+        this->slaves_.clear();
+COUT(0) << "~AIController 4" << std::endl;
     }
 
@@ -84,9 +88,9 @@
             // 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 ) 
+            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)
+            if(this->slaves_.size() < 3)
                 this->searchNewMaster();
 
Index: /code/branches/ai/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- /code/branches/ai/src/orxonox/controllers/ArtificialController.cc	(revision 6794)
+++ /code/branches/ai/src/orxonox/controllers/ArtificialController.cc	(revision 6795)
@@ -51,4 +51,5 @@
         this->bHasTargetPosition_ = false;
         this->targetPosition_ = Vector3::ZERO;
+        //this->slaves_ = new std::list<ArtificialController*>;
 
         this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this));
@@ -100,5 +101,5 @@
         if(myMaster_)
         {
-            myMaster_->slaves.remove(this);
+            myMaster_->slaves_.remove(this);
         }
     }
@@ -132,12 +133,12 @@
             if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity()) //&& it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) < 1000 
             {
-                if(controller->slaves.size() > 9) continue;
+                if(controller->slaves_.size() > 9) continue;
 
                 this->freeAllSlaves();
-                this->slaves.clear();
+                this->slaves_.clear();
                 this->state_ = SLAVE;
 
                 this->myMaster_ = controller;
-                controller->slaves.push_back(this);
+                controller->slaves_.push_back(this);
 
                 break;
@@ -152,5 +153,5 @@
     void ArtificialController::commandSlaves() {
 
-        for(std::list<ArtificialController*>::iterator it = slaves.begin(); it != slaves.end(); it++)
+        for(std::list<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
         {
             (*it)->setTargetPosition(this->getControllableEntity()->getPosition());
@@ -173,9 +174,40 @@
     }
 
+    // binds slaves to new Master within formation
+    void ArtificialController::setNewMasterWithinFormation()
+    {
+COUT(0) << "~setNewMasterWithinFormation 1" << std::endl;
+        if (this->slaves_.empty())
+            return;
+COUT(0) << "~setNewMasterWithinFormation 1b" << std::endl;
+
+        ArtificialController *newMaster = this->slaves_.back();
+COUT(0) << "~setNewMasterWithinFormation 2" << std::endl;
+        this->slaves_.pop_back();
+COUT(0) << "~setNewMasterWithinFormation 3" << std::endl;
+        if(!newMaster) return;
+COUT(0) << "~setNewMasterWithinFormation 4" << std::endl;
+        newMaster->state_ = MASTER;
+        newMaster->slaves_ = this->slaves_;
+        //this->slaves_.clear();
+
+        this->state_ = SLAVE;
+        this->myMaster_ = newMaster;
+
+COUT(0) << "~setNewMasterWithinFormation 5" << std::endl;
+        for(std::list<ArtificialController*>::iterator it = newMaster->slaves_.begin(); it != newMaster->slaves_.end(); it++)
+        {
+COUT(0) << "~setNewMasterWithinFormation 6" << std::endl;
+            (*it)->myMaster_ = newMaster;
+        }
+COUT(0) << "~setNewMasterWithinFormation 7" << std::endl;
+
+    }
+
     void ArtificialController::freeAllSlaves()
     {
 
 
-        for(std::list<ArtificialController*>::iterator it = slaves.begin(); it != slaves.end(); it++)
+        for(std::list<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
         {
             (*it)->state_ = FREE;
Index: /code/branches/ai/src/orxonox/controllers/ArtificialController.h
===================================================================
--- /code/branches/ai/src/orxonox/controllers/ArtificialController.h	(revision 6794)
+++ /code/branches/ai/src/orxonox/controllers/ArtificialController.h	(revision 6795)
@@ -47,8 +47,9 @@
             void abandonTarget(Pawn* target);
 
-            inline void setTeam(int team)//new
+            inline void setTeam(int team)
                 { this->team_ = team; }
             inline int getTeam() const
                 { return this->team_; }
+            virtual void changedControllableEntity();
 
 
@@ -61,8 +62,9 @@
             enum State {SLAVE, MASTER, FREE};
             int getState();
-            std::list<ArtificialController*> slaves;
+            std::list<ArtificialController*> slaves_;
             void unregisterSlave();
             void searchNewMaster();
             void commandSlaves();
+            void setNewMasterWithinFormation();
             void freeAllSlaves();
             void loseMasterState();
@@ -89,6 +91,6 @@
 
 
-            State state_;//new master: 1 slave: -1  free: 0 
-            int team_;//new
+            State state_;
+            int team_;
 
         private:
