Index: code/trunk/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- code/trunk/src/orxonox/OrxonoxPrereqs.h	(revision 3039)
+++ code/trunk/src/orxonox/OrxonoxPrereqs.h	(revision 3049)
@@ -196,4 +196,6 @@
     class AIController;
     class ScriptController;
+    class WaypointController;
+    class WaypointPatrolController;
     class PongAI;
 
Index: code/trunk/src/orxonox/objects/controllers/AIController.cc
===================================================================
--- code/trunk/src/orxonox/objects/controllers/AIController.cc	(revision 3039)
+++ code/trunk/src/orxonox/objects/controllers/AIController.cc	(revision 3049)
@@ -108,7 +108,7 @@
 
         if (this->bHasTargetPosition_)
-            this->moveToTargetPosition(dt);
+            this->moveToTargetPosition();
 
-        if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(500) && this->isLookingAtTarget(Ogre::Math::PI / 20.0))
+        if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0))
             this->getControllableEntity()->fire(WeaponMode::fire);
 
Index: code/trunk/src/orxonox/objects/controllers/ArtificialController.cc
===================================================================
--- code/trunk/src/orxonox/objects/controllers/ArtificialController.cc	(revision 3039)
+++ code/trunk/src/orxonox/objects/controllers/ArtificialController.cc	(revision 3049)
@@ -34,4 +34,7 @@
 #include "objects/worldentities/pawns/Pawn.h"
 
+#include "objects/gametypes/TeamDeathmatch.h"
+#include "objects/controllers/WaypointPatrolController.h"
+
 namespace orxonox
 {
@@ -50,11 +53,11 @@
     }
 
-    void ArtificialController::moveToTargetPosition(float dt)
+    void ArtificialController::moveToPosition(const Vector3& target)
     {
         if (!this->getControllableEntity())
             return;
 
-        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
-        float distance = (this->targetPosition_ - this->getControllableEntity()->getPosition()).length();
+        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)
@@ -71,4 +74,15 @@
     }
 
+    void ArtificialController::moveToTargetPosition()
+    {
+        this->moveToPosition(this->targetPosition_);
+    }
+
+    void ArtificialController::setTargetPosition(const Vector3& target)
+    {
+        this->targetPosition_ = target;
+        this->bHasTargetPosition_ = true;
+    }
+
     void ArtificialController::searchRandomTargetPosition()
     {
@@ -77,4 +91,12 @@
     }
 
+    void ArtificialController::setTarget(Pawn* target)
+    {
+        this->target_ = target;
+
+        if (target)
+            this->targetPosition_ = target->getPosition();
+    }
+
     void ArtificialController::searchNewTarget()
     {
@@ -87,5 +109,7 @@
         for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
         {
-//            if (it->getTeamNr() != this->getTeamNr())
+            if (ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
+                continue;
+
             if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity())
             {
@@ -147,3 +171,37 @@
         }
     }
+
+    bool ArtificialController::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
+    {
+        if (entity1 == entity2)
+            return true;
+
+        int team1 = -1;
+        int team2 = -1;
+
+        if (entity1->getXMLController())
+        {
+            WaypointPatrolController* wpc = dynamic_cast<WaypointPatrolController*>(entity1->getXMLController());
+            if (wpc)
+                team1 = wpc->getTeam();
+        }
+        if (entity2->getXMLController())
+        {
+            WaypointPatrolController* wpc = dynamic_cast<WaypointPatrolController*>(entity2->getXMLController());
+            if (wpc)
+                team2 = wpc->getTeam();
+        }
+
+        TeamDeathmatch* tdm = dynamic_cast<TeamDeathmatch*>(gametype);
+        if (tdm)
+        {
+            if (entity1->getPlayer())
+                team1 = tdm->getTeam(entity1->getPlayer());
+
+            if (entity2->getPlayer())
+                team2 = tdm->getTeam(entity2->getPlayer());
+        }
+
+        return (team1 == team2 && team1 != -1);
+    }
 }
Index: code/trunk/src/orxonox/objects/controllers/ArtificialController.h
===================================================================
--- code/trunk/src/orxonox/objects/controllers/ArtificialController.h	(revision 3039)
+++ code/trunk/src/orxonox/objects/controllers/ArtificialController.h	(revision 3049)
@@ -47,6 +47,11 @@
 
         protected:
-            void moveToTargetPosition(float dt);
+            void moveToPosition(const Vector3& target);
+            void moveToTargetPosition();
+
+            void setTargetPosition(const Vector3& target);
             void searchRandomTargetPosition();
+
+            void setTarget(Pawn* target);
             void searchNewTarget();
             void forgetTarget();
@@ -55,4 +60,6 @@
             bool isCloseAtTarget(float distance) const;
             bool isLookingAtTarget(float angle) const;
+
+            static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack
 
             bool bHasTargetPosition_;
Index: code/trunk/src/orxonox/objects/controllers/CMakeLists.txt
===================================================================
--- code/trunk/src/orxonox/objects/controllers/CMakeLists.txt	(revision 3039)
+++ code/trunk/src/orxonox/objects/controllers/CMakeLists.txt	(revision 3049)
@@ -5,4 +5,6 @@
   AIController.cc
   ScriptController.cc
+  WaypointController.cc
+  WaypointPatrolController.cc
   PongAI.cc
 )
Index: code/trunk/src/orxonox/objects/controllers/WaypointController.cc
===================================================================
--- code/trunk/src/orxonox/objects/controllers/WaypointController.cc	(revision 3049)
+++ code/trunk/src/orxonox/objects/controllers/WaypointController.cc	(revision 3049)
@@ -0,0 +1,90 @@
+/*
+ *   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:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "WaypointController.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+
+namespace orxonox
+{
+    CreateFactory(WaypointController);
+
+    WaypointController::WaypointController(BaseObject* creator) : ArtificialController(creator)
+    {
+        RegisterObject(WaypointController);
+
+        this->currentWaypoint_ = 0;
+        this->setAccuracy(100);
+    }
+
+    WaypointController::~WaypointController()
+    {
+        if (this->isInitialized())
+        {
+            for (size_t i = 0; i < this->waypoints_.size(); ++i)
+                delete this->waypoints_[i];
+        }
+    }
+
+    void WaypointController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(WaypointController, XMLPort, xmlelement, mode);
+
+        XMLPortParam(WaypointController, "accuracy", setAccuracy, getAccuracy, xmlelement, mode).defaultValues(100.0f);
+        XMLPortObject(WaypointController, WorldEntity, "waypoints", addWaypoint, getWaypoint,  xmlelement, mode);
+    }
+
+    void WaypointController::tick(float dt)
+    {
+        if (!this->isActive())
+            return;
+
+        if (this->waypoints_.size() == 0 || !this->getControllableEntity())
+            return;
+
+        if (this->waypoints_[this->currentWaypoint_]->getWorldPosition().squaredDistance(this->getControllableEntity()->getPosition()) <= this->squaredaccuracy_)
+            this->currentWaypoint_ = (this->currentWaypoint_ + 1) % this->waypoints_.size();
+
+        this->moveToPosition(this->waypoints_[this->currentWaypoint_]->getWorldPosition());
+    }
+
+    void WaypointController::addWaypoint(WorldEntity* waypoint)
+    {
+        this->waypoints_.push_back(waypoint);
+    }
+
+    WorldEntity* WaypointController::getWaypoint(unsigned int index) const
+    {
+        if (index < this->waypoints_.size())
+            return this->waypoints_[index];
+        else
+            return 0;
+    }
+}
Index: code/trunk/src/orxonox/objects/controllers/WaypointController.h
===================================================================
--- code/trunk/src/orxonox/objects/controllers/WaypointController.h	(revision 3049)
+++ code/trunk/src/orxonox/objects/controllers/WaypointController.h	(revision 3049)
@@ -0,0 +1,65 @@
+/*
+ *   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:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _WaypointController_H__
+#define _WaypointController_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include <vector>
+
+#include "ArtificialController.h"
+#include "objects/Tickable.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport WaypointController : public ArtificialController, public Tickable
+    {
+        public:
+            WaypointController(BaseObject* creator);
+            virtual ~WaypointController();
+
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+            virtual void tick(float dt);
+
+            void addWaypoint(WorldEntity* waypoint);
+            WorldEntity* getWaypoint(unsigned int index) const;
+
+            inline void setAccuracy(float accuracy)
+                { this->squaredaccuracy_ = accuracy*accuracy; }
+            inline float getAccuracy() const
+                { return sqrt(this->squaredaccuracy_); }
+
+        protected:
+            std::vector<WorldEntity*> waypoints_;
+            size_t currentWaypoint_;
+            float squaredaccuracy_;
+    };
+}
+
+#endif /* _WaypointController_H__ */
Index: code/trunk/src/orxonox/objects/controllers/WaypointPatrolController.cc
===================================================================
--- code/trunk/src/orxonox/objects/controllers/WaypointPatrolController.cc	(revision 3049)
+++ code/trunk/src/orxonox/objects/controllers/WaypointPatrolController.cc	(revision 3049)
@@ -0,0 +1,104 @@
+/*
+ *   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:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "WaypointPatrolController.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+
+namespace orxonox
+{
+    CreateFactory(WaypointPatrolController);
+
+    WaypointPatrolController::WaypointPatrolController(BaseObject* creator) : WaypointController(creator)
+    {
+        RegisterObject(WaypointPatrolController);
+
+        this->team_ = 0;
+        this->alertnessradius_ = 500;
+
+        this->patrolTimer_.setTimer(rnd(), true, this, createExecutor(createFunctor(&WaypointPatrolController::searchEnemy)));
+    }
+
+    void WaypointPatrolController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(WaypointPatrolController, XMLPort, xmlelement, mode);
+
+        XMLPortParam(WaypointPatrolController, "alertnessradius", setAlertnessRadius, getAlertnessRadius, xmlelement, mode).defaultValues(500.0f);
+        XMLPortParam(WaypointPatrolController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(0);
+    }
+
+    void WaypointPatrolController::tick(float dt)
+    {
+        if (!this->isActive())
+            return;
+
+        if (this->target_)
+        {
+            this->aimAtTarget();
+
+            if (this->bHasTargetPosition_)
+                this->moveToTargetPosition();
+
+            if (this->getControllableEntity() && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0))
+                this->getControllableEntity()->fire(WeaponMode::fire);
+        }
+        else
+        {
+            SUPER(WaypointPatrolController, tick, dt);
+        }
+    }
+
+    void WaypointPatrolController::searchEnemy()
+    {
+        this->patrolTimer_.setInterval(rnd());
+
+        if (!this->getControllableEntity())
+            return;
+
+        Vector3 myposition = this->getControllableEntity()->getPosition();
+        float shortestsqdistance = (unsigned int)-1;
+
+        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
+        {
+            if (ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
+                continue;
+
+            float sqdistance = it->getPosition().squaredDistance(myposition);
+            if (sqdistance < shortestsqdistance)
+            {
+                shortestsqdistance = sqdistance;
+                this->target_ = (*it);
+            }
+        }
+
+        if (shortestsqdistance > (this->alertnessradius_ * this->alertnessradius_))
+            this->target_ = 0;
+    }
+}
Index: code/trunk/src/orxonox/objects/controllers/WaypointPatrolController.h
===================================================================
--- code/trunk/src/orxonox/objects/controllers/WaypointPatrolController.h	(revision 3049)
+++ code/trunk/src/orxonox/objects/controllers/WaypointPatrolController.h	(revision 3049)
@@ -0,0 +1,67 @@
+/*
+ *   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:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _WaypointPatrolController_H__
+#define _WaypointPatrolController_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "WaypointController.h"
+#include "tools/Timer.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport WaypointPatrolController : public WaypointController
+    {
+        public:
+            WaypointPatrolController(BaseObject* creator);
+            virtual ~WaypointPatrolController() {}
+
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+            virtual void tick(float dt);
+
+            inline void setTeam(int team)
+                { this->team_ = team; }
+            inline int getTeam() const
+                { return this->team_; }
+
+            inline void setAlertnessRadius(float radius)
+                { this->alertnessradius_ = radius; }
+            inline float getAlertnessRadius() const
+                { return this->alertnessradius_; }
+
+        protected:
+            void searchEnemy();
+
+            int team_;
+            float alertnessradius_;
+            Timer<WaypointPatrolController> patrolTimer_;
+    };
+}
+
+#endif /* _WaypointPatrolController_H__ */
Index: code/trunk/src/orxonox/objects/gametypes/TeamDeathmatch.cc
===================================================================
--- code/trunk/src/orxonox/objects/gametypes/TeamDeathmatch.cc	(revision 3039)
+++ code/trunk/src/orxonox/objects/gametypes/TeamDeathmatch.cc	(revision 3049)
@@ -164,4 +164,6 @@
             if (pawn)
             {
+                pawn->setRadarObjectColour(this->teamcolours_[it_player->second]);
+
                 std::set<WorldEntity*> pawnAttachments = pawn->getAttachedObjects();
                 for (std::set<WorldEntity*>::iterator it = pawnAttachments.begin(); it != pawnAttachments.end(); ++it)
Index: code/trunk/src/orxonox/objects/gametypes/TeamDeathmatch.h
===================================================================
--- code/trunk/src/orxonox/objects/gametypes/TeamDeathmatch.h	(revision 3039)
+++ code/trunk/src/orxonox/objects/gametypes/TeamDeathmatch.h	(revision 3049)
@@ -55,4 +55,6 @@
             virtual void playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn);
 
+            int getTeam(PlayerInfo* player);
+
             inline const ColourValue& getTeamColour(int teamnr) const
                 { return this->teamcolours_[teamnr]; }
@@ -61,5 +63,4 @@
             virtual SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
             bool pawnsAreInTheSameTeam(Pawn* pawn1, Pawn* pawn2);
-            int getTeam(PlayerInfo* player);
 
             std::map<PlayerInfo*, int> teamnumbers_;
Index: code/trunk/src/orxonox/objects/worldentities/ControllableEntity.cc
===================================================================
--- code/trunk/src/orxonox/objects/worldentities/ControllableEntity.cc	(revision 3039)
+++ code/trunk/src/orxonox/objects/worldentities/ControllableEntity.cc	(revision 3049)
@@ -40,4 +40,5 @@
 #include "objects/Scene.h"
 #include "objects/infos/PlayerInfo.h"
+#include "objects/controllers/Controller.h"
 #include "objects/worldentities/Camera.h"
 #include "objects/worldentities/CameraPosition.h"
@@ -61,4 +62,5 @@
         this->hud_ = 0;
         this->camera_ = 0;
+        this->xmlcontroller_ = 0;
         this->bDestroyWhenPlayerLeft_ = false;
         this->cameraPositionRootNode_ = this->node_->createChildSceneNode();
@@ -93,4 +95,7 @@
                 this->getPlayer()->stopControl();
 
+            if (this->xmlcontroller_)
+                delete this->xmlcontroller_;
+
             if (this->hud_)
                 delete this->hud_;
@@ -115,4 +120,5 @@
 
         XMLPortObject(ControllableEntity, CameraPosition, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode);
+        XMLPortObject(ControllableEntity, Controller,     "controller",      setXMLController,  getXMLController,  xmlelement, mode);
     }
 
@@ -304,4 +310,16 @@
     }
 
+    void ControllableEntity::setXMLController(Controller* controller)
+    {
+        if (!this->xmlcontroller_)
+        {
+            this->xmlcontroller_ = controller;
+            this->bHasLocalController_ = true;
+            this->xmlcontroller_->setControllableEntity(this);
+        }
+        else
+            COUT(2) << "Warning: ControllableEntity \"" << this->getName() << "\" already has a Controller." << std::endl;
+    }
+
     void ControllableEntity::parentChanged()
     {
Index: code/trunk/src/orxonox/objects/worldentities/ControllableEntity.h
===================================================================
--- code/trunk/src/orxonox/objects/worldentities/ControllableEntity.h	(revision 3039)
+++ code/trunk/src/orxonox/objects/worldentities/ControllableEntity.h	(revision 3049)
@@ -130,4 +130,7 @@
                 { return this->mouseLookSpeed_; }
 
+            inline Controller* getXMLController() const
+                { return this->xmlcontroller_; }
+
         protected:
             virtual void setPlayer(PlayerInfo* player); // don't call this directly, use friend class PlayerInfo instead
@@ -142,4 +145,6 @@
 
         private:
+            void setXMLController(Controller* controller);
+
             void overwrite();
             void processOverwrite();
@@ -188,4 +193,5 @@
             std::list<CameraPosition*> cameraPositions_;
             std::string cameraPositionTemplate_;
+            Controller* xmlcontroller_;
     };
 }
