Index: code/branches/towerdefenseHS14/data/levels/includes/weaponSettingsTurret.oxi
===================================================================
--- code/branches/towerdefenseHS14/data/levels/includes/weaponSettingsTurret.oxi	(revision 10142)
+++ code/branches/towerdefenseHS14/data/levels/includes/weaponSettingsTurret.oxi	(revision 10144)
@@ -11,11 +11,11 @@
         </links>
         <Weapon>
-          <attached>
-            <Model mesh="sphere.mesh" position="3,3,-2.2" scale=0.6 />
-          </attached>
-          <HsW01 mode=0 munitionpershot=0 delay=0 damage=3.14159 material="Flares/point_lensflare" muzzleoffset=" 3, 3,-2.2" />
-          <HsW01 mode=0 munitionpershot=0 delay=0 damage=3.14159 material="Flares/point_lensflare" muzzleoffset=" 3,-3,-2.2" />
-          <HsW01 mode=0 munitionpershot=0 delay=0 damage=3.14159 material="Flares/point_lensflare" muzzleoffset="-3, 3,-2.2" />
-          <HsW01 mode=0 munitionpershot=0 delay=0 damage=3.14159 material="Flares/point_lensflare" muzzleoffset="-3,-3,-2.2" />
+          <!-- <attached>
+            <Model mesh="sphere.mesh" position="1.7,1.7,-24.5" scale=0.6 />
+          </attached> -->
+          <HsW01 mode=0 munitionpershot=0 delay=0 damage=1 material="Flares/point_lensflare" muzzleoffset="1.7, 1.7,-30" />
+          <HsW01 mode=0 munitionpershot=0 delay=0 damage=1 material="Flares/point_lensflare" muzzleoffset="1.7, -1.7,-30" />
+          <HsW01 mode=0 munitionpershot=0 delay=0 damage=1 material="Flares/point_lensflare" muzzleoffset="-1.7, 1.7,-30" />
+          <HsW01 mode=0 munitionpershot=0 delay=0 damage=1 material="Flares/point_lensflare" muzzleoffset="-1.7, -1.7,-30" />
         </Weapon>
       </WeaponPack>
Index: code/branches/towerdefenseHS14/data/levels/templates/enemytowerdefense.oxt
===================================================================
--- code/branches/towerdefenseHS14/data/levels/templates/enemytowerdefense.oxt	(revision 10142)
+++ code/branches/towerdefenseHS14/data/levels/templates/enemytowerdefense.oxt	(revision 10144)
@@ -7,7 +7,7 @@
    explosionchunks        = 6
 
-   health            = 100
-   maxhealth         = 200
-   initialhealth     = 100
+   health            = 1
+   maxhealth         = 2
+   initialhealth     = 1
 
    shieldhealth        = 30
Index: code/branches/towerdefenseHS14/data/levels/templates/standardTurret.oxt
===================================================================
--- code/branches/towerdefenseHS14/data/levels/templates/standardTurret.oxt	(revision 10144)
+++ code/branches/towerdefenseHS14/data/levels/templates/standardTurret.oxt	(revision 10144)
@@ -0,0 +1,40 @@
+<Template name=standardturret>
+  <Turret collisionType="dynamic">
+    <attached>
+      <Model position="0,0,0" mesh="turretSocketFront.mesh" scale3D="10,10,10" pitch=-90/>
+      <Model position="0,0,0" mesh="turretSocketIn.mesh" scale3D="10,10,10" pitch=-90/>
+      <Model position="0,0,0" mesh="turretSocketTop.mesh" scale3D="10,10,10" pitch=-90/>
+      <Model position="0,0,0" mesh="turretSocketLeft.mesh" scale3D="10,10,10" pitch=-90/>
+      <Model position="0,0,0" mesh="turretSocketRight.mesh" scale3D="10,10,10" pitch=-90/>
+
+      <Turret position="0,0,-10" collisionType="dynamic" angularDamping=0.999999 mass=100 maxPitch=90 maxYaw=90 maxAttackRadius=2000 minAttackRadius=30>
+        <attached>
+          <Model position="0,0,0" pitch="-90" roll="0" mesh="turretHead.mesh" scale3D="10,10,10"/>
+        </attached>
+        <collisionShapes>
+          <SphereCollisionShape radius="10"   position = "0,0,0"/>
+        </collisionShapes>
+        <controller>
+          <TurretController/>
+        </controller>
+        <?lua
+          include("../includes/weaponSettingsTurret.oxi")
+        ?>
+      </Turret>
+    </attached>
+    
+    <controller>
+      <TeamTargetProxy/>
+    </controller>
+  </Turret>
+</Template>
+
+<Template name=spaceshipturretcameras defaults=0>
+  <SpaceShip>
+    <camerapositions>
+      <CameraPosition position="0,10, 40" drag=true mouselook=true />
+      <CameraPosition position="0,20, 80" drag=true mouselook=true />
+      <CameraPosition position="0,30,120" drag=true mouselook=true />
+    </camerapositions>
+  </SpaceShip>
+</Template>
Index: code/branches/towerdefenseHS14/data/levels/templates/tower.oxt
===================================================================
--- code/branches/towerdefenseHS14/data/levels/templates/tower.oxt	(revision 10142)
+++ code/branches/towerdefenseHS14/data/levels/templates/tower.oxt	(revision 10144)
@@ -26,16 +26,5 @@
         <Model position="0,0,0" scale=45 mesh="Tower.mesh" />
         
-        <Turret position="0,0,-100" collisionType="dynamic" angularDamping=0.999999 mass=100 maxPitch=90 maxYaw=90 maxAttackRadius=2000 minAttackRadius=30>
         
-	        <collisionShapes>
-	          	<SphereCollisionShape radius="10"   position = "0,0,0"/>
-	        </collisionShapes>
-	       	<controller>
-          		<TurretController/>
-        	</controller>
-	        <?lua
-	          	include("../includes/weaponSettingsTurret.oxi")
-	        ?>
-      	</Turret>
     </attached>
 
@@ -50,2 +39,44 @@
 </Template>
 
+
+
+<Template name=towerturret>
+  <TowerDefenseTower
+
+
+   explosionchunks        = 6
+
+   reloadrate          = 3
+   reloadwaittime      = 1
+
+   collisionType     = "dynamic"
+   team = 1
+
+
+  >
+  <attached>
+
+    <Model position="0,0,0" scale=45 mesh="Tower.mesh" />
+    <Turret collisionType="dynamic" position="0,0,10" direction="0,0,1" pitch="0" yaw="0" roll="0" angularDamping=0.999999 mass=100 maxPitch=90 maxYaw=90 maxAttackRadius=1000 minAttackRadius=30>
+
+      <controller>
+        <TurretController/>
+      </controller>
+      <?lua
+        include("../includes/weaponSettingsTurret.oxi")
+      ?>
+    </Turret>
+  </attached>
+    
+
+
+
+    <!--collisionShapes>
+
+    </collisionShapes-->
+
+<?lua
+  include("../includes/towerWeaponSettings.oxi")
+?>
+  </TowerDefenseTower>
+</Template>
Index: code/branches/towerdefenseHS14/data/levels/towerDefense.oxw
===================================================================
--- code/branches/towerdefenseHS14/data/levels/towerDefense.oxw	(revision 10142)
+++ code/branches/towerdefenseHS14/data/levels/towerDefense.oxw	(revision 10144)
@@ -22,9 +22,10 @@
   include("templates/tower.oxt")
   include("templates/enemytowerdefense.oxt")
+  include("templates/standardTurret.oxt")
 ?>
 
 <!-- Specify the position of the camera -->
 <Template name=centerpointmarkcamera defaults=0>
-  <Pawn>
+  <Pawn team=1>
     <camerapositions>
       <CameraPosition position="0,0,1500"/>
@@ -35,5 +36,5 @@
 <!-- Loads a mesh to mark the center-->
 <Template name=centerpointmark>
-  <Pawn camerapositiontemplate=centerpointmarkcamera>
+  <Pawn team=1 camerapositiontemplate=centerpointmarkcamera>
     <attached>
       <Model position="0,0,0" mesh="cylinder.mesh" scale3D="1,1,1" /> <!-- the camera is attached to this -->
@@ -71,5 +72,5 @@
 
     <!-- Spawns the camera, attached to a crate -->
-    <SpawnPoint team=0 position="0,0,0" spawnclass=Pawn pawndesign=centerpointmark />
+    <SpawnPoint team=1 position="0,0,0" spawnclass=Pawn pawndesign=centerpointmark />
     <!--TeamSpawnPoint team=1 position="-7,7,4" direction="-1,0,0" roll=90 yaw=0 spawnclass=SpaceShip pawndesign=spaceshipassff /-->
 
@@ -81,5 +82,5 @@
 
     <!--invisible entity to attach towers to, since playfield is static and towers are dynamic-->
-    <StaticEntity position=0,0,0>
+    <StaticEntity team =1 position=0,0,0>
 
         <attached>
@@ -118,4 +119,5 @@
     collisionType=dynamic
     mass=100000
+    team=1
     />
 
Index: code/branches/towerdefenseHS14/data/levels/turretTest.oxw
===================================================================
--- code/branches/towerdefenseHS14/data/levels/turretTest.oxw	(revision 10142)
+++ code/branches/towerdefenseHS14/data/levels/turretTest.oxw	(revision 10144)
@@ -3,5 +3,5 @@
 <LevelInfo
  name = "turret Test"
- description = "A level with a turret in it."
+ description = "A level to test turrets with."
  tags = "test"
  screenshot = "emptylevel.png"
@@ -16,6 +16,5 @@
 <?lua
   include("templates/spaceshipAssff.oxt")
-  include("templates/spaceshipPirate.oxt")
-  include("templates/spaceshipTurret.oxt")
+  include("templates/standardTurret.oxt")
 ?>
 
@@ -33,29 +32,24 @@
     <SpawnPoint team=0 position="-200,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
 
+<SpaceShip position = "0,0,800" collisionType="dynamic" team=10>
+  <controller>
+    <TeamTargetProxy team=10/>
+  </controller>
+  <attached>
+    <Model position="0,0,0" mesh="plane.mesh" scale3D="20,20,20" pitch=-90/>
 
-<StaticEntity position="0,0,0" yaw=0 pitch=0>
-    <attached>
-        <Model position="0,0,0" mesh="turretSocketFront.mesh" scale3D="10,10,10" />
-        <Model position="0,0,0" mesh="turretSocketIn.mesh" scale3D="10,10,10" />
-        <Model position="0,0,0" mesh="turretSocketTop.mesh" scale3D="10,10,10" />
-        <Model position="0,0,0" mesh="turretSocketLeft.mesh" scale3D="10,10,10" />
-        <Model position="0,0,0" mesh="turretSocketRight.mesh" scale3D="10,10,10" />
-    </attached>
-</StaticEntity>
+    <?lua for i = 1, 10, 1 do ?>
+      <Turret position="<?lua print(150-i*30) ?>,<?lua print(150-i*30) ?>,0" pitch="0" yaw="0" roll="0">
+        <templates>
+          <Template link=standardturret />
+        </templates>
+      </Turret>
+    <?lua end ?>
 
-
-
-<Turret position="0,10,0" pitch="90" yaw="0" roll="0">
-    <templates>
-        <Template link=spaceshipturret />
-    </templates>
-    <controller>
-        <WaypointPatrolController alertnessradius=100 team=10>
-        </WaypointPatrolController>
-     </controller>
-</Turret>
-
-
-
+  </attached>
+  <collisionShapes>
+    <BoxCollisionShape radius="10"   position="0,0,0" halfExtents="200, 200, 0"/>
+  </collisionShapes>
+</SpaceShip>
     
   </Scene>
Index: code/branches/towerdefenseHS14/src/libraries/core/input/InputManager.cc
===================================================================
--- code/branches/towerdefenseHS14/src/libraries/core/input/InputManager.cc	(revision 10142)
+++ code/branches/towerdefenseHS14/src/libraries/core/input/InputManager.cc	(revision 10144)
@@ -175,11 +175,11 @@
 
         if (exclusiveMouse_ || GraphicsManager::getInstance().isFullScreen())
-        {
+        {   // HACK MARTIN for debugging, changed values here to true
             if (CommandLineParser::getValue("keyboard_no_grab").get<bool>())
                 paramList.insert(StringPair("x11_keyboard_grab", "false"));
             else
-                paramList.insert(StringPair("x11_keyboard_grab", "true"));
-            paramList.insert(StringPair("x11_mouse_grab",  "true"));
-            paramList.insert(StringPair("x11_mouse_hide", "true"));
+                paramList.insert(StringPair("x11_keyboard_grab", "false"));
+            paramList.insert(StringPair("x11_mouse_grab",  "false"));
+            paramList.insert(StringPair("x11_mouse_hide", "false"));
         }
         else
Index: code/branches/towerdefenseHS14/src/modules/objects/CMakeLists.txt
===================================================================
--- code/branches/towerdefenseHS14/src/modules/objects/CMakeLists.txt	(revision 10142)
+++ code/branches/towerdefenseHS14/src/modules/objects/CMakeLists.txt	(revision 10144)
@@ -11,4 +11,5 @@
 ADD_SUBDIRECTORY(eventsystem)
 ADD_SUBDIRECTORY(triggers)
+ADD_SUBDIRECTORY(controllers)
 
 ORXONOX_ADD_LIBRARY(objects
Index: code/branches/towerdefenseHS14/src/modules/objects/Turret.cc
===================================================================
--- code/branches/towerdefenseHS14/src/modules/objects/Turret.cc	(revision 10142)
+++ code/branches/towerdefenseHS14/src/modules/objects/Turret.cc	(revision 10144)
@@ -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/towerdefenseHS14/src/modules/objects/Turret.h
===================================================================
--- code/branches/towerdefenseHS14/src/modules/objects/Turret.h	(revision 10142)
+++ code/branches/towerdefenseHS14/src/modules/objects/Turret.h	(revision 10144)
@@ -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/towerdefenseHS14/src/modules/towerdefense/TowerDefense.cc
===================================================================
--- code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefense.cc	(revision 10142)
+++ code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefense.cc	(revision 10144)
@@ -158,5 +158,5 @@
         for (int i = 0; i < kInitialTowerCount; i++)
         {
-            addTower(i+4,(i+5));
+            addTower(i+4,i+5);
         }
 
@@ -277,5 +277,5 @@
   //    Create tower
         TowerDefenseTower* towernew = new TowerDefenseTower(this->center_->getContext());
-        towernew->addTemplate("tower");
+        towernew->addTemplate("towerturret");
         towernew->setPosition(static_cast<float>((x-8) * tileScale), static_cast<float>((y-8) * tileScale), 75);
         towernew->setGame(this);
Index: code/branches/towerdefenseHS14/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/towerdefenseHS14/src/orxonox/controllers/ArtificialController.cc	(revision 10142)
+++ code/branches/towerdefenseHS14/src/orxonox/controllers/ArtificialController.cc	(revision 10144)
@@ -94,5 +94,5 @@
         static const float hardcoded_projectile_speed = 1250;
 
-        this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getPosition(), hardcoded_projectile_speed, this->target_->getPosition(), this->target_->getVelocity());
+        this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), hardcoded_projectile_speed, this->target_->getWorldPosition(), this->target_->getVelocity());
         this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO);
 
Index: code/branches/towerdefenseHS14/src/orxonox/worldentities/WorldEntity.cc
===================================================================
--- code/branches/towerdefenseHS14/src/orxonox/worldentities/WorldEntity.cc	(revision 10142)
+++ code/branches/towerdefenseHS14/src/orxonox/worldentities/WorldEntity.cc	(revision 10144)
@@ -414,6 +414,7 @@
             else if (this->isDynamic())
             {
-                orxout(internal_warning) << "Cannot attach a dynamic object to a WorldEntity." << endl;
-                return false;
+                //***HACKY HACK (to allow turrets to be attached)***
+                //orxout(internal_warning) << "Cannot attach a dynamic object to a WorldEntity." << endl;
+                //return false;
             }
             else if (this->isKinematic() && newParent->isDynamic())
