Index: code/branches/ai/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/AIController.cc	(revision 6601)
+++ code/branches/ai/src/orxonox/controllers/AIController.cc	(revision 6640)
@@ -56,43 +56,63 @@
         float maxrand = 100.0f / ACTION_INTERVAL;
 
-        // search enemy
-        random = rnd(maxrand);
-        if (random < 15 && (!this->target_))
-            this->searchNewTarget();
+        if (this->state_==0)
+        {
 
-        // forget enemy
-        random = rnd(maxrand);
-        if (random < 5 && (this->target_))
-            this->forgetTarget();
+            // search master
+            random = rnd(maxrand);
+            if (random < 50 && (!this->target_))
+                this->searchNewMaster();
 
-        // next enemy
-        random = rnd(maxrand);
-        if (random < 10 && (this->target_))
-            this->searchNewTarget();
+            //this->state_=1;
 
-        // fly somewhere
-        random = rnd(maxrand);
-        if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
-            this->searchRandomTargetPosition();
+        }
 
-        // stop flying
-        random = rnd(maxrand);
-        if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
-            this->bHasTargetPosition_ = false;
+        if (this->state_==-1)
+        {
+            
+        }
 
-        // fly somewhere else
-        random = rnd(maxrand);
-        if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
-            this->searchRandomTargetPosition();
+        if (this->state_==1)
+        {
+            // search enemy
+            random = rnd(maxrand);
+            if (random < 15 && (!this->target_))
+                this->searchNewTarget();
 
-        // shoot
-        random = rnd(maxrand);
-        if (random < 75 && (this->target_ && !this->bShooting_))
-            this->bShooting_ = true;
+            // forget enemy
+            random = rnd(maxrand);
+            if (random < 5 && (this->target_))
+                this->forgetTarget();
 
-        // stop shooting
-        random = rnd(maxrand);
-        if (random < 25 && (this->bShooting_))
-            this->bShooting_ = false;
+            // 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();
+
+            // stop flying
+            random = rnd(maxrand);
+            if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
+                this->bHasTargetPosition_ = false;
+
+            // fly somewhere else
+            random = rnd(maxrand);
+            if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
+                this->searchRandomTargetPosition();
+
+            // shoot
+            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;
+        }
     }
 
@@ -102,12 +122,22 @@
             return;
 
-        if (this->target_)
-            this->aimAtTarget();
+        if (this->state_==1)
+        {
+            if (this->target_)
+                this->aimAtTarget();
 
-        if (this->bHasTargetPosition_)
-            this->moveToTargetPosition();
+            if (this->bHasTargetPosition_)
+                this->moveToTargetPosition();
 
-        if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
-            this->getControllableEntity()->fire(0);
+            if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
+                this->getControllableEntity()->fire(0);
+        }
+
+        if (this->state_==-1)
+        {
+            //this->state_=1;
+
+
+        }
 
         SUPER(AIController, tick, dt);
Index: code/branches/ai/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.cc	(revision 6601)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.cc	(revision 6640)
@@ -44,6 +44,6 @@
 
         this->target_ = 0;
-	this->team_ = 0;//new
-	this->isMaster_ = false;//new
+	this->team_ = -1;//new
+	this->state_ = 0;//new
         this->bShooting_ = false;
         this->bHasTargetPosition_ = false;
@@ -88,4 +88,44 @@
     {
         this->moveToPosition(this->targetPosition_);
+    }
+
+    int ArtificialController::getState()
+    {
+        return this->state_;
+    }
+
+    void ArtificialController::searchNewMaster()
+    {
+        if (!this->getControllableEntity())
+            return;
+
+        this->targetPosition_ = this->getControllableEntity()->getPosition();
+        this->forgetTarget();
+
+        //go through all pawns
+        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+        {
+            //same team? no: continue
+            if (!ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
+                continue;
+
+            //has it an ArtificialController and is it a master? no: continue
+
+            ArtificialController *controller = static_cast<ArtificialController*>(it->getController());
+            if (controller && controller->getState()!=1)
+                continue;
+
+            //is pawn oneself? && is pawn in range?
+            if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity() /*&& it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) < 1000 */)
+            {
+                //this->target_ = (*it);
+                //this->targetPosition_ = it->getPosition();
+                this->state_ = -1;
+
+            }
+        }//for
+
+        //hasn't encountered any masters in range? -> become a master
+        if (state_!=-1) state_=1; // keep in mind: what happens when two masters encounter eache other? -> has to be evaluated in the for loop of within master mode in AIcontroller...
     }
 
Index: code/branches/ai/src/orxonox/controllers/ArtificialController.h
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.h	(revision 6601)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.h	(revision 6640)
@@ -59,4 +59,7 @@
             void moveToTargetPosition();
 
+            int getState();
+            void searchNewMaster();
+
             void setTargetPosition(const Vector3& target);
             void searchRandomTargetPosition();
@@ -77,5 +80,5 @@
             bool bShooting_;
 
-            bool isMaster_;//new
+            int state_;//new master: 1 slave: -1  free: 0 
             int team_;//new
 
