Index: code/branches/ai/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/AIController.cc	(revision 6918)
+++ 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);
     }
Index: code/branches/ai/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.cc	(revision 6918)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.cc	(revision 6919)
@@ -42,5 +42,7 @@
 {
 
-    static const unsigned int MAX_FORMATION_SIZE = 6;
+    static const unsigned int MAX_FORMATION_SIZE = 7;
+    static const int FORMATION_LENGTH =  10;
+    static const int FORMATION_WIDTH =  110;
     static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy
     static const float SPEED_MASTER = 0.6f;
@@ -54,8 +56,11 @@
 
         this->target_ = 0;
+        this->formationFlight_  =  true;
         this->myMaster_ = 0;
         this->freedomCount_ = 0;
 	this->team_ = -1;
 	this->state_ = FREE;
+        this->specificMasterAction_ = NONE;
+        this->specificMasterActionHoldCount_  = 0;
         this->bShooting_ = false;
         this->bHasTargetPosition_ = false;
@@ -73,5 +78,6 @@
         SUPER(ArtificialController, XMLPort, xmlelement, mode);
 
-        XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(0);
+        XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(-1);
+//         XMLPortParam(ArtificialController, "formation", setFormationFlight, getFormationFlight, xmlelement, mode).defaultValues(true);
     }
 
@@ -134,26 +140,21 @@
         if(this->state_ == SLAVE)
         {
-//             if (this->target_ || distance > 10)
-//             {
-                float rotateFactor;
-                if(this->state_ == SLAVE) rotateFactor = 1.0f;
-
-
-                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 < 500 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
-            {
-                if (this->target_ && distance < 60)
+
+           this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
+           this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
+
+
+
+
+
+            if (distance < 300)
+            {
+                if (distance < 40)
                 {
-                    this->getControllableEntity()->setVelocity(0.8f*this->target_->getVelocity());
-                } else this->getControllableEntity()->moveFrontBack(-1.0f*exp(distance/100.0));
+                    this->getControllableEntity()->moveFrontBack(0.8f*SPEED_MASTER);
+                } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
 
             } else {
-                this->getControllableEntity()->moveFrontBack(1.0f + distance/500.0f);
+                this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f);
             }
         }
@@ -176,5 +177,5 @@
             if( it != myMaster_->slaves_.end() )
                 myMaster_->slaves_.erase(it);
-//COUT(0) << "~unregister slave" << std::endl;
+// COUT(0) << "~unregister slave" << std::endl;
         }
     }
@@ -188,5 +189,5 @@
         this->targetPosition_ = this->getControllableEntity()->getPosition();
         this->forgetTarget();
-
+        int teamSize = 0;
         //go through all pawns
         for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
@@ -197,10 +198,17 @@
                 continue;
 
-            //has it an ArtificialController and is it a master?
+            //has it an ArtificialController?
             if (!it->getController())
                 continue;
 
+            //is pawn oneself?
+            if (static_cast<ControllableEntity*>(*it) == this->getControllableEntity())
+                continue;
+
+            teamSize++;
+
             ArtificialController *newMaster = static_cast<ArtificialController*>(it->getController());
 
+            //is it a master?
             if (!newMaster || newMaster->getState() != MASTER)
                 continue;
@@ -208,6 +216,6 @@
             float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length();
 
-            //is pawn oneself? && is pawn in range?
-            if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity() && distance < 5000) 
+            // is pawn in range?
+            if (distance < 5000)
             {
                 if(newMaster->slaves_.size() > MAX_FORMATION_SIZE) continue;
@@ -227,7 +235,7 @@
             }
         }//for
-
         //hasn't encountered any masters in range? -> become a master
-        if (state_!=SLAVE) state_ = MASTER;//master encounters master? ->done
+        if (state_ != SLAVE  && teamSize != 0) state_ = MASTER;//master encounters master? ->done
+
     }
 
@@ -243,18 +251,26 @@
             this->slaves_.front()->setTargetPosition(dest);
         }
-
-        // 2 slaves: triangle
-         if (this->slaves_.size() == 2) 
-        {
-            dest += 10*orient*WorldEntity::BACK;
-            this->slaves_[0]->setTargetPosition(dest + 10*orient*WorldEntity::LEFT);
-            this->slaves_[1]->setTargetPosition(dest + 10*orient*WorldEntity::RIGHT);
-        }
-
-        if (this->slaves_.size() > MAX_FORMATION_SIZE)
-        {
+        else 
+        {
+            dest += 1.0f*orient*WorldEntity::BACK;
+            Vector3 pos = Vector3::ZERO;
+            int i = 1;
+
             for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
             {
-                (*it)->setTargetPosition(this->getControllableEntity()->getPosition());
+                pos = Vector3::ZERO;
+                if (i <= 1) pos += dest  + FORMATION_WIDTH*WorldEntity::LEFT;
+                if (i == 2) pos += dest  + FORMATION_WIDTH*WorldEntity::RIGHT;
+                if (i == 3) pos += dest  + FORMATION_WIDTH*WorldEntity::UP;
+                if (i >= 4)
+                {
+                    pos += dest  + FORMATION_WIDTH*WorldEntity::DOWN;
+                    i = 1;
+                    dest += FORMATION_LENGTH*orient*WorldEntity::BACK;
+                    (*it)->setTargetPosition(pos);
+                    continue;
+                }
+                i++;
+                (*it)->setTargetPosition(pos);
             }
         }
@@ -326,4 +342,21 @@
         } else return false;
     }
+
+    void ArtificialController::specificMasterActionHold()
+    {
+        if (specificMasterActionHoldCount_ == 0) this->specificMasterAction_ = NONE;
+        else specificMasterActionHoldCount_--;
+    }
+
+    void ArtificialController::turn180()
+    {
+        this->specificMasterAction_  =  NONE;
+    }
+
+    void ArtificialController::spin()
+    {
+        this->specificMasterAction_  =  NONE;
+    }
+
 
     void ArtificialController::setTargetPosition(const Vector3& target)
Index: code/branches/ai/src/orxonox/controllers/ArtificialController.h
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.h	(revision 6918)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.h	(revision 6919)
@@ -53,4 +53,8 @@
             inline int getTeam() const
                 { return this->team_; }
+            inline void setFormationFlight(bool formation)
+                { this->formationFlight_ = formation; }
+            inline bool getFormationFlight() const
+                { return this->formationFlight_; }
             virtual void changedControllableEntity();
 
@@ -59,8 +63,13 @@
 
             int team_;
+            bool formationFlight_;
             int freedomCount_;
             enum State {SLAVE, MASTER, FREE};
             State state_;
             std::vector<ArtificialController*> slaves_;
+            ArtificialController *myMaster_;
+            enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180};
+            SpecificMasterAction specificMasterAction_;
+            int specificMasterActionHoldCount_;
 
             void targetDied();
@@ -80,6 +89,7 @@
             void forceFreedom();
             bool forcedFree();
-
-            ArtificialController *myMaster_;
+            void specificMasterActionHold();
+            void turn180();
+            void spin();
 
             void setTargetPosition(const Vector3& target);
