Index: code/trunk/src/orxonox/controllers/AIController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/AIController.cc	(revision 6598)
+++ code/trunk/src/orxonox/controllers/AIController.cc	(revision 7163)
@@ -23,5 +23,5 @@
  *      Fabian 'x3n' Landau
  *   Co-authors:
- *      ...
+ *      Dominik Solenicki
  *
  */
@@ -33,4 +33,5 @@
 #include "core/Executor.h"
 #include "worldentities/ControllableEntity.h"
+#include "worldentities/pawns/Pawn.h"
 
 namespace orxonox
@@ -56,43 +57,146 @@
         float maxrand = 100.0f / ACTION_INTERVAL;
 
-        // 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();
-
-        // 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;
+        if (this->state_ == FREE)
+        {
+
+            if (this->formationFlight_)
+            {
+                // 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();
+            }
+
+            // 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();
+
+            // 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 (!(this->passive_) && 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)
+        {
+
+        }
+
+        if (this->state_ == MASTER)
+        {
+
+
+            this->commandSlaves();
+
+            if  (this->specificMasterAction_ != NONE)
+                    this->specificMasterActionHold();
+
+            else {
+
+                 // make 180 degree turn - a specific Master Action
+                random = rnd(1000.0f);
+                if (random < 5)
+                   this->turn180Init();
+
+                // spin around - a specific Master Action
+                random = rnd(1000.0f);
+                if (random < 5)
+                   this->spinInit();
+
+                // follow a randomly chosen human - a specific Master Action
+                random = rnd(1000.0f);
+                if (random < 1)
+                   this->followRandomHumanInit();
+
+                 // 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 (!(this->passive_) && random < 9 && (this->target_ && !this->bShooting_))
+                {
+                this->bShooting_ = true;
+                this->forceFreeSlaves();
+                }
+
+                // stop shooting
+                random = rnd(maxrand);
+                if (random < 25 && (this->bShooting_))
+                    this->bShooting_ = false;
+
+            }
+        }
+
     }
 
@@ -102,12 +206,54 @@
             return;
 
-        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);
+        if (this->state_ == MASTER)
+        {
+            if (this->specificMasterAction_ ==  NONE)
+            {
+                if (this->target_)
+                {
+				if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
+                	this->forgetTarget();
+                else 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);
+            }
+
+            if (this->specificMasterAction_  == TURN180)
+                    this->turn180();
+
+            if (this->specificMasterAction_ == SPIN)
+                    this->spin();
+            if (this->specificMasterAction_ == FOLLOW)
+                    this->follow();
+        }
+
+        if (this->state_ == SLAVE)
+        {
+
+            if (this->bHasTargetPosition_)
+                this->moveToTargetPosition();
+
+        }
+
+         if (this->state_ == FREE)
+        {
+            if (this->target_)
+            {
+				if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
+                	this->forgetTarget();
+                else 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/trunk/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/ArtificialController.cc	(revision 6598)
+++ code/trunk/src/orxonox/controllers/ArtificialController.cc	(revision 7163)
@@ -23,5 +23,5 @@
  *      Fabian 'x3n' Landau
  *   Co-authors:
- *      ...
+ *      Dominik Solenicki
  *
  */
@@ -29,13 +29,39 @@
 #include "ArtificialController.h"
 
+#include <vector>
+#include <climits>
+
+#include "util/Math.h"
+#include "core/ConsoleCommand.h"
 #include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
 #include "worldentities/ControllableEntity.h"
 #include "worldentities/pawns/Pawn.h"
 #include "worldentities/pawns/TeamBaseMatchBase.h"
 #include "gametypes/TeamDeathmatch.h"
+#include "gametypes/Dynamicmatch.h"
 #include "controllers/WaypointPatrolController.h"
+#include "controllers/NewHumanController.h"
+#include "controllers/DroneController.h"
 
 namespace orxonox
 {
+    SetConsoleCommand(ArtificialController, formationflight, true);
+    SetConsoleCommand(ArtificialController, masteraction, true);
+    SetConsoleCommand(ArtificialController, followme, true);
+    SetConsoleCommand(ArtificialController, passivebehaviour, true);
+    SetConsoleCommand(ArtificialController, formationsize, true);
+
+    static const unsigned int STANDARD_MAX_FORMATION_SIZE = 7;
+    static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000;
+    static const int FORMATION_LENGTH =  130;
+    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;
+    static const float ROTATEFACTOR_MASTER = 0.2f;
+    static const float SPEED_FREE = 0.8f;
+    static const float ROTATEFACTOR_FREE = 0.8f;
+
+
     ArtificialController::ArtificialController(BaseObject* creator) : Controller(creator)
     {
@@ -43,6 +69,16 @@
 
         this->target_ = 0;
+        this->formationFlight_ = true;
+        this->passive_ = false;
+        this->maxFormationSize_ = STANDARD_MAX_FORMATION_SIZE;
+        this->myMaster_ = 0;
+        this->freedomCount_ = 0;
+        this->team_ = -1;
+        this->state_ = FREE;
+        this->specificMasterAction_ = NONE;
+        this->specificMasterActionHoldCount_  = 0;
         this->bShooting_ = false;
         this->bHasTargetPosition_ = false;
+        this->speedCounter_ = 0.2f;
         this->targetPosition_ = Vector3::ZERO;
 
@@ -52,4 +88,229 @@
     ArtificialController::~ArtificialController()
     {
+        if (this->isInitialized())
+        {
+            this->removeFromFormation();
+
+            for (ObjectList<ArtificialController>::iterator it = ObjectList<ArtificialController>::begin(); it; ++it)
+            {
+                if (*it != this)
+                {
+                    if (it->myMaster_ == this)
+                    {
+                        COUT(1) << "error: " << this << " is still master in " << (*it) << std::endl;
+                        it->myMaster_ = 0;
+                    }
+
+                    while (true)
+                    {
+                        std::vector<ArtificialController*>::iterator it2 = std::find(it->slaves_.begin(), it->slaves_.end(), this);
+                        if (it2 != it->slaves_.end())
+                        {
+                            COUT(1) << "error: " << this << " is still slave in " << (*it) << std::endl;
+                            it->slaves_.erase(it2);
+                        }
+                        else
+                            break;
+                    }
+                }
+            }
+        }
+    }
+
+    void ArtificialController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(ArtificialController, XMLPort, xmlelement, mode);
+
+        XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(-1);
+        XMLPortParam(ArtificialController, "formationFlight", setFormationFlight, getFormationFlight, xmlelement, mode).defaultValues(false);
+        XMLPortParam(ArtificialController, "formationSize", setFormationSize, getFormationSize, xmlelement, mode).defaultValues(STANDARD_MAX_FORMATION_SIZE);
+        XMLPortParam(ArtificialController, "passive", setPassive, getPassive, xmlelement, mode).defaultValues(false);
+    }
+
+// Documentation only here to get a faster overview for creating a useful documentation...
+
+    /**
+        @brief Activates / deactivates formationflight behaviour
+        @param form activate formflight if form is true
+    */
+    void ArtificialController::formationflight(const bool form)
+    {
+        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+        {
+            Controller* controller = 0;
+
+            if (it->getController())
+                controller = it->getController();
+            else if (it->getXMLController())
+                controller = it->getXMLController();
+
+            if (!controller)
+                continue;
+
+            ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
+
+            if (aiController)
+            {
+                aiController->formationFlight_ = form;
+                if (!form)
+                {
+                    aiController->removeFromFormation();
+                }
+            }
+        }
+    }
+
+    /**
+        @brief Get all masters to do a "specific master action"
+        @param action which action to perform (integer, so it can be called with a console command (tmp solution))
+    */
+    void ArtificialController::masteraction(const int action)
+    {
+        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+        {
+            Controller* controller = 0;
+
+            if (it->getController())
+                controller = it->getController();
+            else if (it->getXMLController())
+                controller = it->getXMLController();
+
+            if (!controller)
+                continue;
+
+            ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
+
+            if(aiController && aiController->state_ == MASTER)
+            {
+                if (action == 1)
+                    aiController->spinInit();
+                if (action == 2)
+                    aiController->turn180Init();
+            }
+        }
+    }
+
+    /**
+        @brief A human player gets followed by its nearest master. Initiated by console command, so far intended for demonstration puproses (possible future pickup).
+    */
+    void ArtificialController::followme()
+    {
+
+        Pawn *humanPawn = NULL;
+        NewHumanController *currentHumanController = NULL;
+        std::vector<ArtificialController*> allMasters;
+
+        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+        {
+            Controller* controller = 0;
+
+            if (it->getController())
+                controller = it->getController();
+            else if (it->getXMLController())
+                controller = it->getXMLController();
+
+            if (!controller)
+                continue;
+
+            currentHumanController = orxonox_cast<NewHumanController*>(controller);
+
+            if(currentHumanController) humanPawn = *it;
+
+            ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
+
+            if(aiController && aiController->state_ == MASTER)
+                allMasters.push_back(aiController);
+
+        }
+
+        if((humanPawn != NULL) && (allMasters.size() != 0))
+        {
+                float posHuman = humanPawn->getPosition().length();
+                float distance = 0.0f;
+                float minDistance = FLT_MAX;
+                int index = 0;
+                int i = 0;
+
+                for(std::vector<ArtificialController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++, i++)
+                    {
+                        if (!ArtificialController::sameTeam((*it)->getControllableEntity(), humanPawn, (*it)->getGametype())) continue;
+                        distance = posHuman - (*it)->getControllableEntity()->getPosition().length();
+                        if(distance < minDistance) index = i;
+                    }
+                allMasters[index]->followInit(humanPawn);
+            }
+
+    }
+
+    /**
+        @brief Sets shooting behaviour of pawns.
+        @param passive if true, bots won't shoot.
+    */
+    void ArtificialController::passivebehaviour(const bool passive)
+    {
+        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+        {
+            Controller* controller = 0;
+
+            if (it->getController())
+                controller = it->getController();
+            else if (it->getXMLController())
+                controller = it->getXMLController();
+
+            if (!controller)
+                continue;
+
+            ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
+
+            if(aiController)
+            {
+                aiController->passive_ = passive;
+            }
+        }
+    }
+
+
+    /**
+        @brief Sets maximal formation size
+        @param size maximal formation size.
+    */
+    void ArtificialController::formationsize(const int size)
+    {
+        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+        {
+            Controller* controller = 0;
+
+            if (it->getController())
+                controller = it->getController();
+            else if (it->getXMLController())
+                controller = it->getXMLController();
+
+            if (!controller)
+                continue;
+
+            ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
+
+            if(aiController)
+            {
+                aiController->maxFormationSize_ = size;
+            }
+        }
+    }
+
+    /**
+        @brief Gets called when ControllableEntity is being changed. Resets the bot when it dies.
+    */
+    void ArtificialController::changedControllableEntity()
+    {
+        if (!this->getControllableEntity())
+            this->removeFromFormation();
+    }
+
+    void ArtificialController::removeFromFormation()
+    {
+        if (this->state_ == SLAVE || this->myMaster_) // slaves can also be temporary free, so check if myMaster_ is set
+            this->unregisterSlave();
+        else if (this->state_ == MASTER)
+            this->setNewMasterWithinFormation();
     }
 
@@ -59,24 +320,488 @@
             return;
 
+        // Slave uses special movement if its master is in FOLLOW mode
+        if(this->state_ == SLAVE && this->myMaster_ && this->myMaster_->specificMasterAction_ == FOLLOW)
+        {
+//             this->followForSlaves(target);
+//             return;
+        }
+
         Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
         float distance = (target - this->getControllableEntity()->getPosition()).length();
 
-        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);
-        }
-
-        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
+
+        if(this->state_ == FREE)
+        {
+            if (this->target_ || distance > 10)
+            {
+                // Multiply with ROTATEFACTOR_FREE to make them a bit slower
+                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);
+                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);
+            }
+
+            if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
+            {
+              this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance
+            } else this->getControllableEntity()->moveFrontBack(SPEED_FREE);
+        }
+
+
+
+        if(this->state_ == MASTER)
+        {
+            if (this->target_ || distance > 10)
+            {
+                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
+                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
+            }
+
+            if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
+            {
+                this->getControllableEntity()->moveFrontBack(-0.05f);
+            } else this->getControllableEntity()->moveFrontBack(SPEED_MASTER);
+        }
+
+
+
+        if(this->state_ == SLAVE)
+        {
+
+           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()->moveFrontBack(0.8f*SPEED_MASTER);
+                } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
+
+            } else {
+                this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f);
+            }
+        }
+    }
+
+    void ArtificialController::moveToTargetPosition()
+    {
+        this->moveToPosition(this->targetPosition_);
+    }
+
+
+    /**
+        @brief Unregisters a slave from its master. Initiated by a slave.
+    */
+    void ArtificialController::unregisterSlave()
+    {
+        if (this->myMaster_)
+        {
+            std::vector<ArtificialController*>::iterator it = std::find(this->myMaster_->slaves_.begin(), this->myMaster_->slaves_.end(), this);
+            if (it != this->myMaster_->slaves_.end())
+                this->myMaster_->slaves_.erase(it);
+        }
+
+        this->myMaster_ = 0;
+        this->state_ = FREE;
+    }
+
+    void ArtificialController::searchNewMaster()
+    {
+
+        if (!this->getControllableEntity())
+            return;
+
+        this->targetPosition_ = this->getControllableEntity()->getPosition();
+        this->forgetTarget();
+        int teamSize = 0;
+        //go through all pawns
+        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+        {
+            //same team?
+            if (!ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
+                continue;
+
+            //has it an ArtificialController?
+            Controller* controller = 0;
+
+            if (it->getController())
+                controller = it->getController();
+            else if (it->getXMLController())
+                controller = it->getXMLController();
+
+            if (!controller)
+                continue;
+
+            //is pawn oneself?
+            if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
+                continue;
+
+            teamSize++;
+
+            ArtificialController *newMaster = orxonox_cast<ArtificialController*>(controller);
+
+            //is it a master?
+            if (!newMaster || newMaster->state_ != MASTER)
+                continue;
+
+            float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length();
+
+            // is pawn in range?
+            if (distance < RADIUS_TO_SEARCH_FOR_MASTERS)
+            {
+                if(newMaster->slaves_.size() > this->maxFormationSize_) continue;
+
+                for(std::vector<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_ = newMaster;
+                newMaster->slaves_.push_back(this);
+
+                break;
+            }
+        }
+
+        if (this->state_ != SLAVE  && teamSize != 0)
+        {
+            this->state_ = MASTER;
+            this->myMaster_ = 0;
+        }
+    }
+
+    /**
+        @brief Commands the slaves of a master into a formation. Sufficiently fast not to be called within tick. Initiated by a master.
+    */
+    void ArtificialController::commandSlaves()
+    {
+        if(this->state_ != MASTER) return;
+
+        Quaternion orient = this->getControllableEntity()->getOrientation();
+        Vector3 dest = this->getControllableEntity()->getPosition();
+
+        // 1 slave: follow
+        if (this->slaves_.size() == 1)
+        {
+            dest += 4*orient*WorldEntity::BACK;
+            this->slaves_.front()->setTargetPosition(dest);
+        }
         else
-            this->getControllableEntity()->moveFrontBack(0.8f);
-    }
-
-    void ArtificialController::moveToTargetPosition()
-    {
-        this->moveToPosition(this->targetPosition_);
-    }
+        {
+            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++)
+            {
+                pos = Vector3::ZERO;
+                if (i <= 1) pos += dest  + FORMATION_WIDTH*(orient*WorldEntity::LEFT);
+                if (i == 2) pos += dest  + FORMATION_WIDTH*(orient*WorldEntity::RIGHT);
+                if (i == 3) pos += dest  + FORMATION_WIDTH*(orient*WorldEntity::UP);
+                if (i >= 4)
+                {
+                    pos += dest  + FORMATION_WIDTH*(orient*WorldEntity::DOWN);
+                    i = 1;
+                    dest += FORMATION_LENGTH*(orient*WorldEntity::BACK);
+                    (*it)->setTargetPosition(pos);
+                    continue;
+                }
+                i++;
+                (*it)->setTargetPosition(pos);
+            }
+        }
+    }
+
+    /**
+        @brief Sets a new master within the formation. Called by a master.
+    */
+    void ArtificialController::setNewMasterWithinFormation()
+    {
+        if(this->state_ != MASTER) return;
+
+        if (!this->slaves_.empty())
+        {
+            ArtificialController *newMaster = this->slaves_.back();
+            this->slaves_.pop_back();
+
+            newMaster->state_ = MASTER;
+            newMaster->slaves_ = this->slaves_;
+            newMaster->myMaster_ = 0;
+
+            for(std::vector<ArtificialController*>::iterator it = newMaster->slaves_.begin(); it != newMaster->slaves_.end(); it++)
+            {
+                (*it)->myMaster_ = newMaster;
+            }
+        }
+
+        this->slaves_.clear();
+        this->specificMasterAction_ = NONE;
+        this->state_ = FREE;
+    }
+
+    /**
+        @brief Frees all slaves form a master. Initiated by a master.
+    */
+    void ArtificialController::freeSlaves()
+    {
+        if(this->state_ != MASTER) return;
+
+        for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
+        {
+            (*it)->state_ = FREE;
+            (*it)->myMaster_ = 0;
+        }
+        this->slaves_.clear();
+    }
+
+    /**
+        @brief Master sets its slaves free for @var FREEDOM_COUNT seconds.
+    */
+    void ArtificialController::forceFreeSlaves()
+    {
+        if(this->state_ != MASTER) return;
+
+        for(std::vector<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);// fire once for fun
+        }
+    }
+
+    void ArtificialController::loseMasterState()
+    {
+        this->freeSlaves();
+        this->state_ = FREE;
+    }
+
+
+    void ArtificialController::forceFreedom()
+    {
+        this->freedomCount_ = FREEDOM_COUNT;
+    }
+
+    /**
+        @brief Checks wether caller has been forced free, decrements time to stay forced free.
+        @return true if forced free.
+    */
+    bool ArtificialController::forcedFree()
+    {
+        if(this->freedomCount_ > 0)
+        {
+            this->freedomCount_--;
+            return true;
+        } else return false;
+    }
+
+    /**
+        @brief Used to continue a "specific master action" for a certain time and resuming normal behaviour after.
+    */
+    void ArtificialController::specificMasterActionHold()
+    {
+        if(this->state_ != MASTER) return;
+
+        if (specificMasterActionHoldCount_ == 0)
+         {
+            this->specificMasterAction_ = NONE;
+            this->searchNewTarget();
+         }
+        else specificMasterActionHoldCount_--;
+    }
+
+    /**
+        @brief Master initializes a 180 degree turn. Leads to a "specific master action".
+    */
+    void ArtificialController::turn180Init()
+    {
+        if(this->state_ != MASTER) return;
+
+        Quaternion orient = this->getControllableEntity()->getOrientation();
+
+        this->setTargetPosition(this->getControllableEntity()->getPosition() + 1000.0f*orient*WorldEntity::BACK);
+
+        this->specificMasterActionHoldCount_ = 4;
+
+        this->specificMasterAction_ = TURN180;
+    }
+
+    /**
+        @brief Execute the 180 degree turn. Called within tick.
+    */
+    void ArtificialController::turn180()
+    {
+            Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
+
+            this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x);
+            this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y);
+
+            this->getControllableEntity()->moveFrontBack(SPEED_MASTER);
+    }
+
+    /**
+        @brief Master initializes a spin around its looking direction axis. Leads to a "specific master action".
+    */
+    void ArtificialController::spinInit()
+    {
+        if(this->state_ != MASTER) return;
+        this->specificMasterAction_ = SPIN;
+        this->specificMasterActionHoldCount_ = 10;
+    }
+
+    /**
+        @brief Execute the spin. Called within tick.
+    */
+    void ArtificialController::spin()
+    {
+            this->moveToTargetPosition();
+            this->getControllableEntity()->rotateRoll(0.8f);
+    }
+
+    /**
+        @brief Master begins to follow a pawn. Is a "specific master action".
+        @param pawn pawn to follow.
+        @param alaways follows pawn forever if true (false if omitted).
+        @param secondsToFollow seconds to follow the pawn if always is false. Will follow pawn 100 seconds if omitted (set in header).
+    */
+    void ArtificialController::followInit(Pawn* pawn, const bool always, const int secondsToFollow)
+    {
+        if (pawn == NULL || this->state_ != MASTER)
+            return;
+        this->specificMasterAction_  =  FOLLOW;
+
+        this->setTarget(pawn);
+        if (!always)
+            this->specificMasterActionHoldCount_ = secondsToFollow;
+        else
+            this->specificMasterActionHoldCount_ = INT_MAX; //for now...
+
+    }
+
+
+    /**
+        @brief Master begins to follow a randomly chosen human player of the same team. Is a "specific master action".
+    */
+    void ArtificialController::followRandomHumanInit()
+    {
+
+        Pawn *humanPawn = NULL;
+        NewHumanController *currentHumanController = NULL;
+
+        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+        {
+            if (!it->getController())
+                continue;
+
+            currentHumanController = orxonox_cast<NewHumanController*>(it->getController());
+            if(currentHumanController)
+            {
+                if (!ArtificialController::sameTeam(this->getControllableEntity(), *it, this->getGametype())) continue;
+                humanPawn = *it;
+                break;
+            }
+        }
+
+        if((humanPawn != NULL))
+                this->followInit(humanPawn);
+    }
+
+    /**
+        @brief Master follows target with adjusted speed. Called within tick.
+    */
+    void ArtificialController::follow()
+    {
+        if (this->target_)
+            this->moveToPosition(this->target_->getPosition());
+        else
+            this->specificMasterActionHoldCount_ = 0;
+/*
+        if (!this->getControllableEntity())
+            return;
+
+        float distance = (this->target_->getPosition() - this->getControllableEntity()->getPosition()).length();
+
+        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->target_->getPosition());
+
+
+        this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x);
+        this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y);
+
+        float speedDiv = this->getControllableEntity()->getVelocity().squaredLength() - this->target_->getVelocity().squaredLength();
+
+COUT(0) << "~follow distance: " << distance << "SpeedCounter: " << this->speedCounter_ << "~speedDiv: " << speedDiv << std::endl;
+        if (distance < 800)
+        {
+            if (distance < 200)
+            {
+                this->speedCounter_ -= 0.5f;
+                if(this->speedCounter_ < 0) this->speedCounter_ = 0.0f;
+                this->getControllableEntity()->moveFrontBack(speedCounter_);
+            } else {
+                if(speedDiv < 0)
+                    this->speedCounter_ +=  0.01f;
+                else
+                    this->speedCounter_ -= 0.05f;
+                this->getControllableEntity()->moveFrontBack(speedCounter_);
+            }
+
+        } else {
+            this->speedCounter_ += 0.05f;
+            this->getControllableEntity()->moveFrontBack(speedCounter_ + distance/300.0f);
+        }
+//         if (this->getControllableEntity()->getVelocity().squaredLength() > 50.0f) this->speedCounter_ = 0;
+
+*/
+    }
+
+
+    /**
+        @brief Slave moving behaviour when master is following a pawn, gets redirected from moveToPosition(const Vector3& target)). Called within tick.
+    */
+    void ArtificialController::followForSlaves(const Vector3& target)
+    {
+
+/*
+        if (!this->getControllableEntity() && !this->myMaster_ && this->myMaster_->state_ != FOLLOW && !this->myMaster_->target_)
+            return;
+
+        float distance = (target - this->getControllableEntity()->getPosition()).length();
+
+        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
+
+
+        this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x);
+        this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y);
+
+
+        float speedDiv = this->getControllableEntity()->getVelocity().squaredLength() - this->myMaster_->target_->getVelocity().squaredLength();
+
+
+         if (distance < 800)
+        {
+            if (distance < 200)
+            {
+                this->speedCounter_ -= 5.0f;
+                if(this->speedCounter_ < 0) this->speedCounter_ = 0.0f;
+                this->getControllableEntity()->moveFrontBack(speedCounter_);
+            } else {
+                if(speedDiv < 0)
+                    this->speedCounter_ +=  0.01f;
+                else
+                    this->speedCounter_ -= 0.05f;
+                this->getControllableEntity()->moveFrontBack(speedCounter_);
+            }
+
+        } else {
+            this->speedCounter_ += 0.05f;
+            this->getControllableEntity()->moveFrontBack(speedCounter_ + distance/300.0f);
+        }
+//         if (this->getControllableEntity()->getVelocity().squaredLength() > 50.0f) this->speedCounter_ = 0;
+*/
+    }
+
 
     void ArtificialController::setTargetPosition(const Vector3& target)
@@ -111,4 +836,8 @@
         {
             if (ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
+                continue;
+
+            /* So AI won't choose invisible Spaceships as target */
+            if (!it->getRadarVisibility())
                 continue;
 
@@ -144,5 +873,5 @@
         this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO);
 
-        Pawn* pawn = dynamic_cast<Pawn*>(this->getControllableEntity());
+        Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
         if (pawn)
             pawn->setAimPosition(this->targetPosition_);
@@ -188,15 +917,25 @@
         int team2 = -1;
 
-        if (entity1->getXMLController())
-        {
-            WaypointPatrolController* wpc = orxonox_cast<WaypointPatrolController*>(entity1->getXMLController());
-            if (wpc)
-                team1 = wpc->getTeam();
-        }
-        if (entity2->getXMLController())
-        {
-            WaypointPatrolController* wpc = orxonox_cast<WaypointPatrolController*>(entity2->getXMLController());
-            if (wpc)
-                team2 = wpc->getTeam();
+        Controller* controller = 0;
+        if (entity1->getController())
+            controller = entity1->getController();
+        else
+            controller = entity1->getXMLController();
+        if (controller)
+        {
+            ArtificialController* ac = orxonox_cast<ArtificialController*>(controller);
+            if (ac)
+                team1 = ac->getTeam();
+        }
+
+        if (entity2->getController())
+            controller = entity2->getController();
+        else
+            controller = entity2->getXMLController();
+        if (controller)
+        {
+            ArtificialController* ac = orxonox_cast<ArtificialController*>(controller);
+            if (ac)
+                team2 = ac->getTeam();
         }
 
@@ -245,4 +984,34 @@
         }
 
+        DroneController* droneController = 0;
+        droneController = orxonox_cast<DroneController*>(entity1->getController());
+        if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity2)
+            return true;
+        droneController = orxonox_cast<DroneController*>(entity2->getController());
+        if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1)
+            return true;
+        DroneController* droneController1 = orxonox_cast<DroneController*>(entity1->getController());
+        DroneController* droneController2 = orxonox_cast<DroneController*>(entity2->getController());
+        if (droneController1 && droneController2 && droneController1->getOwner() == droneController2->getOwner())
+            return true;
+
+        Dynamicmatch* dynamic = orxonox_cast<Dynamicmatch*>(gametype);
+        if (dynamic)
+        {
+            if (dynamic->notEnoughPigs||dynamic->notEnoughKillers||dynamic->notEnoughChasers) {return false;}
+
+            if (entity1->getPlayer())
+                team1 = dynamic->getParty(entity1->getPlayer());
+
+            if (entity2->getPlayer())
+                team2 = dynamic->getParty(entity2->getPlayer());
+
+            if (team1 ==-1 ||team2 ==-1 ) {return false;}
+            else if (team1 == dynamic->chaser && team2 != dynamic->chaser) {return false;}
+            else if (team1 == dynamic->piggy && team2 == dynamic->chaser) {return false;}
+            else if (team1 == dynamic->killer && team2 == dynamic->chaser) {return false;}
+            else return true;
+        }
+
         return (team1 == team2 && team1 != -1);
     }
Index: code/trunk/src/orxonox/controllers/ArtificialController.h
===================================================================
--- code/trunk/src/orxonox/controllers/ArtificialController.h	(revision 6598)
+++ code/trunk/src/orxonox/controllers/ArtificialController.h	(revision 7163)
@@ -23,5 +23,5 @@
  *      Fabian 'x3n' Landau
  *   Co-authors:
- *      ...
+ *      Dominik Solenicki
  *
  */
@@ -32,6 +32,9 @@
 #include "OrxonoxPrereqs.h"
 
+#include <vector>
+
 #include "util/Math.h"
 #include "Controller.h"
+#include "controllers/NewHumanController.h"
 
 namespace orxonox
@@ -43,11 +46,76 @@
             virtual ~ArtificialController();
 
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+
             void abandonTarget(Pawn* target);
 
+            inline void setTeam(int team)
+                { this->team_ = team; }
+            inline int getTeam() const
+                { return this->team_; }
+
+            inline void setFormationFlight(bool formation)
+                { this->formationFlight_ = formation; }
+            inline bool getFormationFlight() const
+                { return this->formationFlight_; }
+
+            inline void setFormationSize(int size)
+                { this->maxFormationSize_ = size; }
+            inline int getFormationSize() const
+                { return this->maxFormationSize_; }
+
+            inline void setPassive(bool passive)
+                { this->passive_ = passive; }
+            inline bool getPassive() const
+                { return this->passive_; }
+
+            virtual void changedControllableEntity();
+
+            static void formationflight(const bool form);
+            static void masteraction(const int action);
+            static void followme();
+            static void passivebehaviour(const bool passive);
+            static void formationsize(const int size);
+
         protected:
-            void targetDied();
+
+            int team_;
+            bool formationFlight_;
+            bool passive_;
+            unsigned int maxFormationSize_;
+            int freedomCount_;
+            enum State {SLAVE, MASTER, FREE};
+            State state_;
+            std::vector<ArtificialController*> slaves_;
+            ArtificialController *myMaster_;
+            enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW};
+            SpecificMasterAction specificMasterAction_;
+            int specificMasterActionHoldCount_;
+            float speedCounter_; //for speed adjustment when following
 
             void moveToPosition(const Vector3& target);
             void moveToTargetPosition();
+
+            void removeFromFormation();
+            void unregisterSlave();
+            void searchNewMaster();
+            void commandSlaves();
+            void setNewMasterWithinFormation();
+
+            void freeSlaves();
+            void forceFreeSlaves();
+            void loseMasterState();
+            void forceFreedom();
+            bool forcedFree();
+
+            void specificMasterActionHold();
+            void turn180Init();
+            void turn180();
+            void spinInit();
+            void spin();
+            void followInit(Pawn* pawn, const bool always = false, const int secondsToFollow = 100);
+            void followRandomHumanInit();
+            void follow();
+            void followForSlaves(const Vector3& target);
 
             void setTargetPosition(const Vector3& target);
@@ -61,4 +129,6 @@
             bool isCloseAtTarget(float distance) const;
             bool isLookingAtTarget(float angle) const;
+
+            void targetDied();
 
             static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack
Index: code/trunk/src/orxonox/controllers/CMakeLists.txt
===================================================================
--- code/trunk/src/orxonox/controllers/CMakeLists.txt	(revision 6598)
+++ code/trunk/src/orxonox/controllers/CMakeLists.txt	(revision 7163)
@@ -8,3 +8,4 @@
   WaypointController.cc
   WaypointPatrolController.cc
+  DroneController.cc
 )
Index: code/trunk/src/orxonox/controllers/DroneController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/DroneController.cc	(revision 7163)
+++ code/trunk/src/orxonox/controllers/DroneController.cc	(revision 7163)
@@ -0,0 +1,149 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Oli Scheuss
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "DroneController.h"
+#include "worldentities/Drone.h"
+#include "util/Math.h"
+
+#include "core/CoreIncludes.h"
+#include "core/Executor.h"
+#include "worldentities/ControllableEntity.h"
+
+namespace orxonox
+{
+    /**
+    @brief
+        Constructor.
+    */
+    CreateFactory(DroneController);
+
+    static const float ACTION_INTERVAL = 1.0f;
+
+    DroneController::DroneController(BaseObject* creator) : ArtificialController(creator)
+    {
+        RegisterObject(DroneController);
+
+        this->owner_ = 0;
+        this->drone_ = 0;
+        this->isShooting_ = false;
+
+        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DroneController::action, this)));
+
+        this->owner_.setCallback(createFunctor(&DroneController::ownerDied, this));
+    }
+
+    DroneController::~DroneController()
+    {
+    }
+
+    void DroneController::setOwner(Pawn* owner){
+        this->owner_ = owner;
+    }
+
+    void DroneController::setDrone(Drone* drone)
+    {
+        this->drone_ = drone;
+        this->setControllableEntity(drone);
+    }
+
+    void DroneController::action()
+    {
+        float random;
+        float maxrand = 100.0f / ACTION_INTERVAL;
+        float distanceToTargetSquared = 0;
+
+        if (this->target_)
+            distanceToTargetSquared = (getDrone()->getWorldPosition() - this->target_->getWorldPosition()).squaredLength();
+
+        random = rnd(maxrand);
+        if ( random < 30 || (!this->target_) || distanceToTargetSquared > (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange()))
+            this->searchNewTarget();
+    }
+
+    /**
+    @brief
+        The controlling happens here. This method defines what the controller has to do each tick.
+    @param dt
+        The duration of the tick.
+    */
+    void DroneController::tick(float dt)
+    {
+        if (this->getDrone() && this->getOwner())
+        {
+            if (this->target_)
+            {
+                float distanceToTargetSquared = (this->getDrone()->getWorldPosition() - this->target_->getWorldPosition()).squaredLength();
+                if (distanceToTargetSquared < (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange()))
+                {
+                    this->isShooting_ = true;
+                    this->aimAtTarget();
+                    this->getDrone()->fire(0);
+                }
+            }
+
+            float maxDistanceSquared = this->getDrone()->getMaxDistanceToOwner()*this->getDrone()->getMaxDistanceToOwner();
+            float minDistanceSquared = this->getDrone()->getMinDistanceToOwner()*this->getDrone()->getMinDistanceToOwner();
+            if ((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength()  > maxDistanceSquared)
+            {
+                this->moveToPosition(this->getOwner()->getWorldPosition()); //fly towards owner
+            }
+            else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared)
+            {
+                this->moveToPosition(-this->getOwner()->getWorldPosition()); //fly away from owner
+            }
+            else if (!this->isShooting_)
+            {
+                float random = rnd(2.0f);
+                float randomSelection = rnd(6.0f);
+                if((int)randomSelection==0) drone_->moveUpDown(random);
+                else if((int)randomSelection==1) drone_->moveRightLeft(random);
+                else if((int)randomSelection==2) drone_->moveFrontBack(random);
+                else if((int)randomSelection==3) drone_->rotateYaw(random);
+                else if((int)randomSelection==4) drone_->rotatePitch(random);
+                else if((int)randomSelection==5) drone_->rotateRoll(random);
+            }
+
+            this->isShooting_ = false;
+        }
+
+        SUPER(AIController, tick, dt);
+
+    }
+
+    void DroneController::ownerDied()
+    {
+//         if (this->target_) {            //Drone has some kind of Stockholm-Syndrom --> gets attached to Owners Killer
+//             this->setOwner(target_);
+//             this->searchNewTarget();
+//         }
+        if (this->drone_)
+            this->drone_->destroy();
+        else
+            this->destroy();
+    }
+}
Index: code/trunk/src/orxonox/controllers/DroneController.h
===================================================================
--- code/trunk/src/orxonox/controllers/DroneController.h	(revision 7163)
+++ code/trunk/src/orxonox/controllers/DroneController.h	(revision 7163)
@@ -0,0 +1,77 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Oli Scheuss
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _DroneController_H__
+#define _DroneController_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "AIController.h"
+#include "core/WeakPtr.h"
+#include "tools/interfaces/Tickable.h"
+
+#include "tools/Timer.h"
+
+
+namespace orxonox
+{
+    /**
+    @brief
+        Controller for the Drone of the PPS tutorial.
+    @author
+        Oli Scheuss
+    */
+    class _OrxonoxExport DroneController : public ArtificialController, public Tickable
+    {
+        public:
+            DroneController(BaseObject* creator);
+            virtual ~DroneController();
+
+            virtual void tick(float dt); //!< The controlling happens here. This method defines what the controller has to do each tick.
+
+            void setOwner(Pawn* owner);
+            inline Pawn* getOwner() const
+                { return this->owner_; }
+
+            void setDrone(Drone*  drone);
+            inline Drone* getDrone() const
+                { return this->drone_; }
+
+        protected:
+            virtual void action();
+            void ownerDied();
+            bool isShooting_;
+
+        private:
+            Timer actionTimer_;
+            WeakPtr<Pawn> owner_;
+            Drone* drone_;
+    };
+}
+
+#endif /* _DroneController_H__ */
Index: code/trunk/src/orxonox/controllers/HumanController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/HumanController.cc	(revision 6598)
+++ code/trunk/src/orxonox/controllers/HumanController.cc	(revision 7163)
@@ -35,5 +35,4 @@
 #include "gametypes/Gametype.h"
 #include "infos/PlayerInfo.h"
-#include "overlays/Map.h"
 #include "Radar.h"
 #include "Scene.h"
@@ -116,10 +115,4 @@
     void HumanController::yaw(const Vector2& value)
     {
-        //Hack to enable mouselook in map
-        if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() )
-        {
-            Map::getSingletonPtr()->rotateYaw(value);
-            return;
-        }
         if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
             HumanController::localController_s->controllableEntity_->rotateYaw(value);
@@ -128,10 +121,4 @@
     void HumanController::pitch(const Vector2& value)
     {
-        //Hack to enable mouselook in map
-        if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() )
-        {
-            Map::getSingletonPtr()->rotatePitch(value);
-            return;
-        }
         if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
             HumanController::localController_s->controllableEntity_->rotatePitch(value);
Index: code/trunk/src/orxonox/controllers/NewHumanController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/NewHumanController.cc	(revision 6598)
+++ code/trunk/src/orxonox/controllers/NewHumanController.cc	(revision 7163)
@@ -217,4 +217,9 @@
                     if (this->getControllableEntity() && (this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket"))))
                         this->showOverlays();
+                    else if (this->getControllableEntity() &&  this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer")))
+                    {
+                        this->showOverlays();
+                        this->hideArrows();
+                    }
 
                     this->crossHairOverlay_->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5f-overlaySize_/2, static_cast<float>(this->currentPitch_)/2*-1+.5f-overlaySize_/2));
@@ -364,12 +369,27 @@
         Ogre::RaySceneQueryResult& result = rsq->execute();
         Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
+        WorldEntity* myWe = static_cast<WorldEntity*>(this->getControllableEntity());
 
         Ogre::RaySceneQueryResult::iterator itr;
         for (itr = result.begin(); itr != result.end(); ++itr)
         {
-            if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 500)
+//             CCOUT(0) << "testing object as target" << endl;
+            if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" /*&& itr->distance > 500*/)
             {
                 // Try to cast the user pointer
-                WorldEntity* wePtr = dynamic_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny()));
+                WorldEntity* wePtr;
+                try
+                {
+                    wePtr = dynamic_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny()));
+                }
+                catch (...)
+                {
+                    continue;
+                }
+
+                // make sure we don't shoot ourselves
+                if( wePtr==myWe )
+                    continue;
+
                 if (wePtr)
                 {
@@ -379,5 +399,5 @@
                     while (parent)
                     {
-                        if (this->targetMask_.isExcluded(parent->getIdentifier()))
+                        if (this->targetMask_.isExcluded(parent->getIdentifier()) || parent==myWe)
                         {
                             parent = parent->getParent();
@@ -430,5 +450,6 @@
             HumanController::yaw(value);
 
-        this->currentYaw_ = value.x;
+        if (this->getControllableEntity() && !this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer")))
+            this->currentYaw_ = value.x;
     }
 
@@ -439,5 +460,6 @@
             HumanController::pitch(value);
 
-        this->currentPitch_ = value.x;
+        if (this->getControllableEntity() && !this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer")))
+            this->currentPitch_ = value.x;
     }
 
@@ -579,3 +601,8 @@
         }
     }
+
+
+
+
+
 }
Index: code/trunk/src/orxonox/controllers/NewHumanController.h
===================================================================
--- code/trunk/src/orxonox/controllers/NewHumanController.h	(revision 6598)
+++ code/trunk/src/orxonox/controllers/NewHumanController.h	(revision 7163)
@@ -67,4 +67,5 @@
             virtual void doResumeControl();
 
+
         protected:
             void updateTarget();
Index: code/trunk/src/orxonox/controllers/WaypointPatrolController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/WaypointPatrolController.cc	(revision 6598)
+++ code/trunk/src/orxonox/controllers/WaypointPatrolController.cc	(revision 7163)
@@ -42,5 +42,5 @@
         RegisterObject(WaypointPatrolController);
 
-        this->team_ = 0;
+        //this->team_ = 0;
         this->alertnessradius_ = 500;
 
@@ -53,5 +53,5 @@
 
         XMLPortParam(WaypointPatrolController, "alertnessradius", setAlertnessRadius, getAlertnessRadius, xmlelement, mode).defaultValues(500.0f);
-        XMLPortParam(WaypointPatrolController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(0);
+//        XMLPortParam(WaypointPatrolController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(0);
     }
 
Index: code/trunk/src/orxonox/controllers/WaypointPatrolController.h
===================================================================
--- code/trunk/src/orxonox/controllers/WaypointPatrolController.h	(revision 6598)
+++ code/trunk/src/orxonox/controllers/WaypointPatrolController.h	(revision 7163)
@@ -46,8 +46,8 @@
             virtual void tick(float dt);
 
-            inline void setTeam(int team)
+           /* inline void setTeam(int team)
                 { this->team_ = team; }
             inline int getTeam() const
-                { return this->team_; }
+                { return this->team_; } */
 
             inline void setAlertnessRadius(float radius)
@@ -59,5 +59,5 @@
             void searchEnemy();
 
-            int team_;
+            //int team_;
             float alertnessradius_;
             Timer patrolTimer_;
