Index: code/branches/ai/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/AIController.cc	(revision 6891)
+++ code/branches/ai/src/orxonox/controllers/AIController.cc	(revision 6919)
@@ -59,16 +59,17 @@
         {
 
-
+            if (this->formationFlight_)
+            {
             // return to Master after being forced free
-            if (this->freedomCount_ == 1)   
-            {
+                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();
-
+                }
+
+                random = rnd(maxrand);
+                if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree()))
+                    this->searchNewMaster();
+            }
 
             // search enemy
@@ -116,5 +117,5 @@
         if (this->state_ == SLAVE)
         {
-               // this->bShooting_ = true;
+
         }
 
@@ -125,52 +126,78 @@
             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() < 4 ) 
-//                 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_))
+            if  (this->specificMasterAction_ != NONE) 
             {
+                if (this->specificMasterAction_  == HOLD)
+                    this->specificMasterActionHold();
+
+                if (this->specificMasterAction_  == TURN180)
+                    this->turn180();
+
+                if (this->specificMasterAction_ == SPIN)
+                    this->spin();
+            }
+
+            else {
+
+                 // make 180 degree turn - a specific Master Action
+                random = rnd(maxrand);
+                if (random < 5)
+                   this->specificMasterAction_ = TURN180;
+
+                // spin around - a specific Master Action
+                random = rnd(maxrand);
+                if (random < 5)
+                   this->specificMasterAction_ = SPIN;
+
+                 // lose master status (only if less than 4 slaves in formation)
+                random = rnd(maxrand);
+                if(random < 15/(this->slaves_.size()+1) && this->slaves_.size() < 4 ) 
+                   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;
+                this->forceFreeSlaves();
+                }
+
+                // stop shooting
+                random = rnd(maxrand);
+                if (random < 25 && (this->bShooting_))
+                    this->bShooting_ = false;
+
+            }
         }
 
@@ -189,4 +216,26 @@
             if (this->bHasTargetPosition_)
                 this->moveToTargetPosition();
+            if (this->specificMasterAction_ ==  NONE)
+            {
+                if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
+                    this->getControllableEntity()->fire(0);
+            }
+        }
+
+        if (this->state_ == SLAVE)
+        {
+
+            if (this->bHasTargetPosition_)
+                this->moveToTargetPosition();
+
+        }
+
+         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))
@@ -194,24 +243,4 @@
         }
 
-        if (this->state_ == SLAVE)
-        {
-
-            if (this->bHasTargetPosition_)
-                this->moveToTargetPosition();
-
-        }
-
-         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);
-        }
-
         SUPER(AIController, tick, dt);
     }
