Index: code/branches/presentationHS14/src/modules/objects/CMakeLists.txt
===================================================================
--- code/branches/presentationHS14/src/modules/objects/CMakeLists.txt	(revision 10160)
+++ code/branches/presentationHS14/src/modules/objects/CMakeLists.txt	(revision 10181)
@@ -11,4 +11,5 @@
 ADD_SUBDIRECTORY(eventsystem)
 ADD_SUBDIRECTORY(triggers)
+ADD_SUBDIRECTORY(controllers)
 
 ORXONOX_ADD_LIBRARY(objects
Index: code/branches/presentationHS14/src/modules/objects/Turret.cc
===================================================================
--- code/branches/presentationHS14/src/modules/objects/Turret.cc	(revision 10160)
+++ code/branches/presentationHS14/src/modules/objects/Turret.cc	(revision 10181)
@@ -21,5 +21,5 @@
  *
  *   Author:
- *      Marian Runo
+ *      Marian Runo, Martin Mueller
  *   Co-authors:
  *      ...
@@ -29,7 +29,8 @@
 #include "Turret.h"
 #include "core/CoreIncludes.h"
-#include "OgreQuaternion.h"
 #include "core/XMLPort.h"
-#include "controllers/WaypointPatrolController.h"
+#include "Scene.h"
+#include <OgreSceneManager.h>
+
 
 namespace orxonox
@@ -37,49 +38,247 @@
     RegisterClass(Turret);
 
-    /**
-     * @brief Constructor
+
+
+    /**
+        @brief 
+        Sets default values for all variables. Also hides the turret from the radar.
+
+        @param context
+        The context
      */
-    Turret::Turret(Context* context) : SpaceShip(context)
+    Turret::Turret(Context* context) : Pawn(context)
     {
         RegisterObject(Turret);
-        this->controller_ = new WaypointPatrolController(this->getContext());
-    }
-
-    /**
-     * @brief Destructor
+        this->rotationThrust_ = 50;
+        this->startDir_ = Vector3::ZERO;
+        this->localZ_ = Vector3::UNIT_Z;
+        this->localY_ = Vector3::UNIT_Y;
+        this->localX_ = Vector3::UNIT_X;
+        this->maxAttackRadius_ = 200;
+        this->minAttackRadius_ = 0;
+        this->maxPitch_ = 90;
+        this->maxYaw_ = 90;
+        this->once_ = false;
+        this->rotation_ = Quaternion::IDENTITY;
+
+        this->setRadarVisibility(false);
+
+        //this->rayTest_ = this->getScene()->getSceneManager()->createRayQuery(Ogre::Ray());
+    }
+
+    /**
+        @brief 
+        Destructor. Destroys the rayTest_ element (if it was used)  .
      */
     Turret::~Turret()
     {
-
-    }
-
-
+        //this->getScene()->getSceneManager()->destroyQuery(this->rayTest_);
+    }
+
+    /**
+        @brief
+        Checks, if a WorldEntity is inside the turret's range.
+
+        This function is safe to use on turrets that are attached, rotated, etc.
+        The turret's range is determined with the maxPitch, maxYaw, and the two attackRadius.
+
+        @param target
+        The WorldEntity to check
+
+        @return
+        The squared distance to the position. -1, if it's ouside of range
+    */
+    float Turret::isInRange(const WorldEntity* target )
+    {
+        //Check distance
+        Vector3 distance = target->getWorldPosition() - this->getWorldPosition();
+        float distanceVal = distance.squaredLength();
+        if(distanceVal > (this->maxAttackRadius_ * this->maxAttackRadius_) || distanceVal < (this->minAttackRadius_ * this->minAttackRadius_))
+        {
+            return -1.f;
+        }
+
+        //Check pitch
+        Vector3 dir = getTransformedVector(distance, this->localX_, this->localY_, this->localZ_);
+        Vector3 dirProjected = dir;
+        dirProjected.x = 0;
+        Vector3 startDirProjected = this->startDir_;
+        startDirProjected.x = 0;
+        Ogre::Real angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
+        if(angle > this->maxPitch_)
+        {
+            return -1.f;
+        }
+
+        //Check yaw
+        dirProjected = dir;
+        dirProjected.y = 0;
+        startDirProjected = this->startDir_;
+        startDirProjected.y = 0;
+        angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
+        if(angle > this->maxYaw_)
+        {
+            return -1.f;
+        }
+
+        //TODO: Finish this. Find a way to convert objects from Ogre to Orxonox
+        /*Ogre::Ray ray = Ogre::Ray(this->getWorldPosition(), distance);
+        this->rayTest_->setRay(ray);
+        Ogre::RaySceneQueryResult result = this->rayTest_->execute();*/
+
+
+        return distanceVal;
+    }
+
+    /**
+        @brief
+        Rotates the turret to make it aim at a certain position.
+
+        @note
+        There are no checks, if the position is valid (i.e. if the turret is allowed to aim there).
+        This function must be called again for every tick, or the turret will stop rotating.
+
+        @param position
+        The position to aim at
+    */
+    void Turret::aimAtPosition(const Vector3& position)
+    {
+        Vector3 currDir = this->getWorldOrientation() * WorldEntity::FRONT;
+        Vector3 targetDir = position - this->getWorldPosition();
+
+        this->rotation_ = currDir.getRotationTo(targetDir);
+    }
+
+    /**
+        @brief
+        Does currently nothing.
+
+        Should rotate the turret with the specified pitch. Contains a failed attempt at limiting said rotation.
+    */
     void Turret::rotatePitch(const Vector2& value)
-    {
-        orxout()<< "Turret rotate Pitch"<< endl;
-
-        const Quaternion& orient = this->getOrientation();
-        Radian pitch = orient.getPitch();
-
-        if((value.x > 0 && pitch < Radian(180)) || (value.x < 0 && pitch > Radian(0)))
-            SpaceShip::rotatePitch(value);
-    }
-
-
-    void Turret::setAlertnessRadius(float value)
-    {
-        this->controller_->setAlertnessRadius(value);
-    }
-    float Turret::getAlertnessRadius()
-    {
-        return this->controller_->getAlertnessRadius();
-    }
-
+    {    
+        //This is a failed attempt at limiting the turret's rotation. It's handled in the controller (for now?)
+        /*
+        Vector3 currentDir = getTransformedVector(this->getOrientation() * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
+        Vector3 currentDirProjected = currentDir;
+        currentDirProjected.x = 0;
+        Vector3 startDirProjected = this->startDir_;
+        startDirProjected.x = 0;     
+        Ogre::Real angle = startDirProjected.angleBetween(currentDirProjected).valueDegrees();
+        //orxout() << "Pitch: " << angle << endl;   
+        //if(angle < this->maxPitch_ || (currentDirProjected.y <= 0 && value.x > 0) || (currentDirProjected.y > 0 && value.x < 0) )
+        {
+            this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x*0.8f);
+        }
+        */
+    }
+
+    /**
+        @brief
+        Does currently nothing.
+
+        Should rotate the turret with the specified yaw. Contains a failed attempt at limiting said rotation.
+    */
+    void Turret::rotateYaw(const Vector2& value)
+    {
+        //This is a failed attempt at limiting the turret's rotation. It's handled in the controller (for now?)
+        /*
+        Vector3 currentDir = getTransformedVector(this->getOrientation() * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
+        Vector3 currentDirProjected = currentDir;
+        currentDirProjected.y = 0;
+        Vector3 startDirProjected = this->startDir_;
+        startDirProjected.y = 0;
+        Ogre::Real angle = startDirProjected.angleBetween(currentDirProjected).valueDegrees();
+        orxout() << "Yaw: " << angle << endl;
+        if(angle < this->maxYaw_ || (currentDirProjected.x <= 0 && value.x < 0) || (currentDirProjected.x > 0 && value.x > 0))
+        {
+            this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x*0.8f);
+        }
+        */
+    }
+
+    /**
+        @brief
+        Does currently nothing.
+
+        May be used to limit turret's rotation in the future.
+    */
+    void Turret::rotateRoll(const Vector2& value)
+    {
+    }
+
+    /**
+        @brief
+        Loads parameters from xml
+
+        Parameters loaded are: rotationThrust, maxAttackRadius, minAttackRadius, maxYaw, maxPitch
+    */
     void Turret::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
         SUPER(Turret, XMLPort, xmlelement, mode);
-        XMLPortParam(Turret, "alertnessRadius", setAlertnessRadius, getAlertnessRadius, xmlelement, mode).defaultValues("400");
-    }
-
-
+        
+        XMLPortParamVariable(Turret, "rotationThrust", rotationThrust_, xmlelement, mode);
+        XMLPortParam(Turret, "maxAttackRadius", setMaxAttackRadius, getMaxAttackRadius, xmlelement, mode);
+        XMLPortParam(Turret, "minAttackRadius", setMinAttackRadius, getMinAttackRadius, xmlelement, mode);
+        XMLPortParam(Turret, "maxYaw", setMaxYaw, getMaxYaw, xmlelement, mode);
+        XMLPortParam(Turret, "maxPitch", setMaxPitch, getMaxPitch, xmlelement, mode);
+    }
+
+    /**
+        @brief
+        The turret's actions are done here.
+
+        Every tick, the turret gets rotated if it should, and the local axes get updated with the parent's rotation.
+    
+        @param dt
+        Duration of the tick
+    */
+    void Turret::tick(float dt)
+    {
+        SUPER(Turret, tick, dt);
+
+        //Stuff isn't properly initialized in the c'tor, so we have to do it like this
+        if(!this->once_)
+        {
+            //Account for rotations done in xml
+            Quaternion startOrient = this->getOrientation();
+            this->localXStart_ = startOrient * this->localX_;
+            this->localXStart_.normalise();
+            this->localX_ = this->localXStart_;
+            this->localYStart_ = startOrient * this->localY_;
+            this->localYStart_.normalise();
+            this->localY_ = this->localYStart_;
+            this->localZStart_ = startOrient * this->localZ_;
+            this->localZStart_.normalise();
+            this->localZ_ = this->localZStart_;
+
+            //startDir should always be (0,0,-1)
+            this->startDir_ = getTransformedVector(startOrient * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
+
+            this->once_ = true;
+
+        }
+
+        //Adjust local axes to parent's rotation
+        WorldEntity* parent = this->getParent();
+        if(parent)
+        {
+            Quaternion parentrot = parent->getWorldOrientation();
+            this->localX_ = parentrot * this->localXStart_;
+            this->localY_ = parentrot * this->localYStart_;
+            this->localZ_ = parentrot * this->localZStart_;
+        }
+
+        //rotate
+        if(this->rotation_ != Quaternion::IDENTITY)
+        {
+            //Don't make the rotation instantaneous. Use an arbitrary interpolation, not that great...
+            //TODO: make the rotation better (constant velocity etc.). At the moment, the turret rotates
+            //slower the closer it is to the destination
+            Quaternion drot = Quaternion::nlerp(dt*this->rotationThrust_/20.f, Quaternion::IDENTITY, this->rotation_);
+            this->rotate(drot, WorldEntity::World);
+            this->rotation_ = Quaternion::IDENTITY;
+        }
+
+    }
 }
Index: code/branches/presentationHS14/src/modules/objects/Turret.h
===================================================================
--- code/branches/presentationHS14/src/modules/objects/Turret.h	(revision 10160)
+++ code/branches/presentationHS14/src/modules/objects/Turret.h	(revision 10181)
@@ -21,5 +21,5 @@
  *
  *   Author:
- *      Marian Runo
+ *      Marian Runo, Martin Mueller
  *   Co-authors:
  *      ...
@@ -28,5 +28,4 @@
 
 /**
-    @file Turret.h
     @brief Definition of the Turret class.
     @ingroup Objects
@@ -37,10 +36,24 @@
 
 #include "objects/ObjectsPrereqs.h"
-
-#include "worldentities/pawns/SpaceShip.h"
+#include "worldentities/pawns/Pawn.h"
+#include <OgreSceneQuery.h>
 
 namespace orxonox
 {
-    class _ObjectsExport Turret : public SpaceShip
+    /**
+    @brief
+        Creates a turret with limited rotation. The point of this class is to be able to attach
+        a turret to a spaceship or a spacestation which is more or less completely autonomous in
+        it's behaviour.
+
+        This class also contains a custom local coordinate system, which gets initially rotated through xml, and
+        afterwards is updated with the parent's rotation (if there is one). This allows for almost trivialal calculation
+        of pitch, yaw and roll through coordinate transformation. (TODO: Ogre should do something like this already, investigate...)
+        
+
+    @note
+        The rotation isn't limited "physically". You have to call isInRange to find out if the turret is allowed to shoot at a target.
+    */
+    class _ObjectsExport Turret : public Pawn
     {
         public:
@@ -48,17 +61,64 @@
             virtual ~Turret();
 
-            //virtual void tick(float dt);
-
             virtual void rotatePitch(const Vector2& value);
-
-            void setAlertnessRadius(float value);
-            float getAlertnessRadius();
+            virtual void rotateYaw(const Vector2& value);
+            virtual void rotateRoll(const Vector2& value);
+            virtual float isInRange(const WorldEntity* target);
+            virtual void aimAtPosition(const Vector3 &position);
 
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+            virtual void tick(float dt);
 
+            /** @brief Sets the maximum distance the turret is allowed to shoot. @param radius The distance*/
+            inline void setMaxAttackRadius(float radius)
+                { this->maxAttackRadius_ = radius; }
+
+            /** @brief Sets the minimum distance the turret is allowed to shoot. @param radius The distance*/
+            inline void setMinAttackRadius(float radius)
+                { this->minAttackRadius_ = radius; }
+
+            /** @brief Sets the maximum pitch the turret can have (in both directions). @param pitch The pitch (in one direction)*/
+            inline void setMaxPitch(float pitch)
+                { this->maxPitch_ = pitch; }
+
+            /** @brief Sets the maximum yaw the turret can have (in both directions). @param yaw The yaw (in one direction)*/
+            inline void setMaxYaw(float yaw)
+                { this->maxYaw_ = yaw; }
+
+            /** @brief Returns the maximum distance the turret is allowed to shoot. @return The distance */
+            inline float getMaxAttackRadius() const
+                { return this->maxAttackRadius_; }                
+
+            /** @brief Returns the minimum distance the turret is allowed to shoot. @return The distance */
+            inline float getMinAttackRadius() const
+                { return this->minAttackRadius_; }   
+
+            /** @brief Returns the maximum pitch the turret can have. @return The pitch */
+            inline float getMaxPitch() const
+                { return this->maxPitch_; }
+
+            /** @brief Returns the maximum yaw the turret can have. @return The yaw */
+            inline float getMaxYaw() const
+                { return this->maxYaw_; }
 
         protected:
-            WaypointPatrolController* controller_;
+            Vector3 startDir_; //!< The initial facing direction, in local coordinates.
+            Vector3 localZ_; //!< The local z-axis, includes for the parent's rotation and rotations done in xml.
+            Vector3 localY_; //!< The local y-axis, includes for the parent's rotation and rotations done in xml.
+            Vector3 localX_; //!< The local x-axis, includes for the parent's rotation and rotations done in xml.      
+            Quaternion rotation_; //!< The rotation to be done by the turret.
+
         private:
+            bool once_; //!< Flag for executing code in the tick function only once.
+
+            Vector3 localZStart_; //!< The local z-axis, without the parent's rotation.
+            Vector3 localYStart_; //!< The local y-axis, without the parent's rotation.
+            Vector3 localXStart_; //!< The local x-axis, without the parent's rotation.
+            float maxAttackRadius_; //!< The maximum distance the turret is allowed to shoot.
+            float minAttackRadius_; //!< The minimum distance the turret is allowed to shoot.
+            Ogre::Real maxPitch_; //!< The maxmium pitch the turret can have (on one side).
+            Ogre::Real maxYaw_; //!< The maxmium yaw the turret can have (on one side).
+            float rotationThrust_;  //!< The velocity the turret rotates with.
+            Ogre::RaySceneQuery* rayTest_; //!< Used to perform a raytest, currently unused @see isInRange
 
     };
@@ -66,3 +126,2 @@
 
 #endif
-
Index: code/branches/presentationHS14/src/modules/objects/controllers/CMakeLists.txt
===================================================================
--- code/branches/presentationHS14/src/modules/objects/controllers/CMakeLists.txt	(revision 10181)
+++ code/branches/presentationHS14/src/modules/objects/controllers/CMakeLists.txt	(revision 10181)
@@ -0,0 +1,4 @@
+ADD_SOURCE_FILES(OBJECTS_SRC_FILES
+  TurretController.cc
+  TeamTargetProxy.cc
+)
Index: code/branches/presentationHS14/src/modules/objects/controllers/TeamTargetProxy.cc
===================================================================
--- code/branches/presentationHS14/src/modules/objects/controllers/TeamTargetProxy.cc	(revision 10181)
+++ code/branches/presentationHS14/src/modules/objects/controllers/TeamTargetProxy.cc	(revision 10181)
@@ -0,0 +1,105 @@
+/*
+ *   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:
+ *      Martin Mueller
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "TeamTargetProxy.h"
+#include "worldentities/ControllableEntity.h"
+#include "worldentities/pawns/Pawn.h"
+
+namespace orxonox
+{
+	RegisterClass(TeamTargetProxy);
+
+   /**
+       @brief 
+       Sets default values for all variables.
+
+       @param context
+       The context
+    */
+	TeamTargetProxy::TeamTargetProxy(Context* context) : FormationController(context)
+ 	{
+ 		RegisterObject(TeamTargetProxy);
+
+ 		this->once_ = false;
+ 	}
+
+    /**
+        @brief 
+        Destructor. Nothing to see here.
+     */
+ 	TeamTargetProxy::~TeamTargetProxy()
+ 	{
+ 	}
+
+    /**
+        @brief
+        Copies the team and the target from the parent.
+
+        That's all there is.
+    */
+ 	void TeamTargetProxy::tick(float dt)
+ 	{
+	    if (!this->isActive() || !this->getControllableEntity())
+	        return;
+
+        ControllableEntity* parent = orxonox_cast<ControllableEntity*> (this->getControllableEntity()->getParent());
+
+        if(this->getTeam() != -1 && !this->once_ && parent)
+        {
+            orxout(internal_warning) << "TeamTargetProxy: Team already set, may result in undesired behaviour. Will get overridden by the parent's team." << endl;
+        }
+
+        if(!this->once_)
+            this->once_ = true;
+
+        //Teams aren't set immediately, after creation, so we have to check every tick...
+        if(parent)
+        {
+            Controller* parentcontroller = parent->getController();
+            if(parentcontroller)
+            {
+                this->setTeam(parentcontroller->getTeam());
+            }
+            else
+            {
+                this->setTeam(parent->getTeam());
+            }
+            this->getControllableEntity()->setTeam(parent->getTeam());
+        }
+
+        if(parent)
+        {
+            Pawn* parenttarget = orxonox_cast<Pawn*>(parent->getTarget());
+            if(parenttarget)
+            {
+                this->setTarget(parenttarget);
+                this->getControllableEntity()->setTarget(parenttarget);
+            }
+        }
+ 	}
+}
Index: code/branches/presentationHS14/src/modules/objects/controllers/TeamTargetProxy.h
===================================================================
--- code/branches/presentationHS14/src/modules/objects/controllers/TeamTargetProxy.h	(revision 10181)
+++ code/branches/presentationHS14/src/modules/objects/controllers/TeamTargetProxy.h	(revision 10181)
@@ -0,0 +1,60 @@
+/*
+ *   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:
+ *      Martin Mueller
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _TeamTargetProxy_H__
+#define _TeamTargetProxy_H__
+
+#include "OrxonoxPrereqs.h"
+#include "controllers/FormationController.h"
+
+ namespace orxonox
+ {
+ 	/**
+ 		@brief
+ 		A controller, that just copies the team and the target of a parent for itself and it's controllable entity.
+
+ 		Useful for following (and similar) situations: (-> means attached to)
+			turret (rotates) -> some kind of turret base (looks nice) -> spaceship (flies around)
+			The turret has a controller that wants to copy the spaceship's target and team. In this case it doesn't work though,
+			because the turret isn't directly attached to the spaceship. Here's where this controller comes in. Drawback: the base
+			has to be controllable and ticks every second (performance?)
+ 	*/
+ 	class _OrxonoxExport TeamTargetProxy : public FormationController, public Tickable
+ 	{
+ 		public:
+ 			TeamTargetProxy(Context* context);
+ 			virtual ~TeamTargetProxy();
+
+ 			virtual void tick(float dt);
+
+ 		private:
+ 			bool once_; //!< Flag for executing code in the tick function only once.
+ 	};
+ }
+
+ #endif
Index: code/branches/presentationHS14/src/modules/objects/controllers/TurretController.cc
===================================================================
--- code/branches/presentationHS14/src/modules/objects/controllers/TurretController.cc	(revision 10181)
+++ code/branches/presentationHS14/src/modules/objects/controllers/TurretController.cc	(revision 10181)
@@ -0,0 +1,202 @@
+/*
+ *   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:
+ *      Martin Mueller
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "TurretController.h"
+#include "worldentities/pawns/Pawn.h"
+#include "Turret.h"
+
+ namespace orxonox
+ {
+ 	RegisterClass(TurretController);
+
+    /**
+        @brief 
+        Sets default values for all variables.
+
+        @param context
+        The context
+    */
+ 	TurretController::TurretController(Context* context) : ArtificialController(context)
+ 	{
+ 		RegisterObject(TurretController);
+
+ 		this->once_ = false;
+
+ 	}
+
+    /**
+        @brief 
+        Destructor. Nothing to see here.
+    */
+ 	TurretController::~TurretController()
+ 	{
+
+ 	}
+
+    /**
+        @brief 
+        Searches a valid target for the turret to aim at.
+
+        Loops through all pawns and tests, if it is in range. Scores every pawn and chooses the best one (the one with the lowest score).
+        If the turret has a parent, try to aim at the same target the parent has, if there is one.
+
+        @see targetScore
+        The function that scores the pawns.
+    */
+ 	void TurretController::searchTarget()
+ 	{
+        Turret* turret = orxonox_cast<Turret*>(this->getControllableEntity());
+
+        //The controller might find a target before teams are set, so we need to check again here.
+        if(this->target_ && turret->isInRange(target_) != -1.f && !FormationController::sameTeam(turret, this->target_, this->getGametype()))
+        {
+        	return;
+        }
+        else
+        {
+        	this->forgetTarget();
+        	turret->setTarget(0);
+        }
+
+
+        ControllableEntity* parent = orxonox_cast<ControllableEntity*>(turret->getParent());
+        if(parent)
+        {
+        	Pawn* parenttarget = orxonox_cast<Pawn*>(parent->getTarget());
+        	if(parenttarget && turret->isInRange(parenttarget))
+        	{
+        		this->setTarget(parenttarget);
+        		turret->setTarget(parenttarget);
+        		return;
+        	}
+        }
+
+        float minScore = FLT_MAX;
+        float tempScore;
+        Pawn* minScorePawn = 0;
+
+  		for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)     
+        {
+        	Pawn* entity = orxonox_cast<Pawn*>(*it);
+            if (!entity || FormationController::sameTeam(this->getControllableEntity(), entity, this->getGametype()))
+            	continue;
+            tempScore = turret->isInRange(entity);
+            if(tempScore != -1.f)
+            {
+            	if(tempScore < minScore)
+            	{
+            		minScore = tempScore;
+            		minScorePawn = entity;
+            	}
+            }
+    	}
+        this->setTarget(minScorePawn);
+        turret->setTarget(minScorePawn);
+ 	}
+
+    /**
+        @brief 
+        Tests, if the turret is looking at the target, with a specified tolerance
+
+		This uses the world position as opposed to the local position in the old version.
+
+		@param angle
+		The tolerance, in radians
+    */
+    bool TurretController::isLookingAtTargetNew(float angle) const
+    {
+        return (getAngle(this->getControllableEntity()->getWorldPosition(), this->getControllableEntity()->getWorldOrientation() * WorldEntity::FRONT, this->target_->getWorldPosition()) < angle);
+    }
+
+    /**
+        @brief 
+        Scores a pawn as a target, based on distance and health.
+
+        The more health and distance a pawn has, the higher the score. This means lower equals better.
+
+		@param pawn
+		The pawn to score
+
+		@param distance
+		The distance. Can be squared or normed, doesn't matter as long as all are treated the same.
+    */   
+ 	float TurretController::targetScore(Pawn* pawn, float distance) const
+ 	{
+ 		return pawn->getHealth()/pawn->getMaxHealth() + distance;
+ 	}
+
+    /**
+    	@brief
+    	Does all the controlling of the turret.
+
+    	If the turret has a parent, copies the team from there, if it's not already set.
+    	Other actions are: Search a target. If a target has been found, aim and shoot at it.
+    */
+ 	void TurretController::tick(float dt)
+ 	{
+	    if (!this->isActive() || !this->getControllableEntity())
+	        return;
+
+
+        ControllableEntity* parent = orxonox_cast<ControllableEntity*> (this->getControllableEntity()->getParent());
+        if(this->getTeam() != -1 && !this->once_ && parent)
+        {
+            orxout(internal_warning) << "TurretController: Team already set, may result in undesired behaviour. Will get overridden by the parent's team." << endl;
+        }
+
+        if(!this->once_)
+        	this->once_ = true;
+     
+        //Teams aren't set immediately, after creation, so we have to check every tick...
+        if(parent)
+        {
+            Controller* parentcontroller = parent->getController();
+            if(parentcontroller)
+            {
+                this->setTeam(parentcontroller->getTeam());
+            }
+            else
+            {
+                this->setTeam(parent->getTeam());
+            }
+            this->getControllableEntity()->setTeam(parent->getTeam());
+        }
+
+ 		this->searchTarget();
+		if(this->target_)
+ 		{
+ 			Turret* turret = orxonox_cast<Turret*> (this->getControllableEntity());
+ 			this->aimAtTarget();
+ 			turret->aimAtPosition(target_->getWorldPosition());
+ 			if(this->isLookingAtTargetNew(Degree(5).valueRadians()))
+ 			{
+ 				this->getControllableEntity()->fire(0);
+ 			}
+ 		}
+ 	}
+ }
Index: code/branches/presentationHS14/src/modules/objects/controllers/TurretController.h
===================================================================
--- code/branches/presentationHS14/src/modules/objects/controllers/TurretController.h	(revision 10181)
+++ code/branches/presentationHS14/src/modules/objects/controllers/TurretController.h	(revision 10181)
@@ -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:
+ *      Martin Mueller
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @brief Definition for the controller for turrets.
+*/
+
+#ifndef _TurretController_H__
+#define _TurretController_H__
+
+#include "OrxonoxPrereqs.h"
+#include "controllers/ArtificialController.h"
+
+ namespace orxonox
+ {
+ 	/**
+ 		@brief
+ 		Controller for turrets. Chooses a target, and makes the turret aim/shoot at it.
+
+ 		The controllableEntity gets casted to Turret, so this controller won't work for anything else.
+ 	*/
+ 	class _OrxonoxExport TurretController : public ArtificialController, public Tickable
+ 	{
+ 		public:
+ 			TurretController(Context* context);
+ 			virtual ~TurretController();
+
+ 			virtual void tick(float dt);
+
+ 		private:
+
+ 			void searchTarget();
+ 			bool isLookingAtTargetNew(float angle) const;
+ 			float targetScore(Pawn* pawn, float distance) const;
+
+ 			bool once_; //!< Flag for executing code in the tick function only once.
+ 	};
+ }
+
+ #endif
