Index: code/branches/turretFS14/src/modules/objects/Turret.cc
===================================================================
--- code/branches/turretFS14/src/modules/objects/Turret.cc	(revision 10044)
+++ code/branches/turretFS14/src/modules/objects/Turret.cc	(revision 10049)
@@ -38,5 +38,9 @@
 
     /**
-     * @brief Constructor
+        @brief 
+        Sets default values for all variables. Also hides the turret from the radar.
+
+        @param context
+        The context
      */
     Turret::Turret(Context* context) : Pawn(context)
@@ -48,5 +52,6 @@
         this->localY_ = Vector3::UNIT_Y;
         this->localX_ = Vector3::UNIT_X;
-        this->attackRadius_ = 200;
+        this->maxAttackRadius_ = 200;
+        this->minAttackRadius_ = 0;
         this->maxPitch_ = 90;
         this->maxYaw_ = 90;
@@ -58,5 +63,6 @@
 
     /**
-     * @brief Destructor
+        @brief 
+        Destructor. Nothing to see here.
      */
     Turret::~Turret()
@@ -65,10 +71,20 @@
     }
 
-
+    /**
+        @brief
+        Checks, if a (world)position 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 position
+        The position to check
+    */
     bool Turret::isInRange(const Vector3 &position)
     {
         //Check distance
         Vector3 distance = position - this->getWorldPosition();
-        if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_))
+        float distanceVal = distance.squaredLength();
+        if(distanceVal > (this->maxAttackRadius_ * this->maxAttackRadius_) || distanceVal < (this->minAttackRadius_ * this->minAttackRadius_))
         {
             return false;
@@ -100,4 +116,15 @@
     }
 
+    /**
+        @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)
     {
@@ -106,7 +133,12 @@
 
         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)
     {    
@@ -127,4 +159,10 @@
     }
 
+    /**
+        @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)
     {
@@ -145,8 +183,20 @@
     }
 
+    /**
+        @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)
     {
@@ -154,9 +204,16 @@
         
         XMLPortParamVariable(Turret, "rotationThrust", rotationThrust_, xmlelement, mode);
-        XMLPortParam(Turret, "attackRadius", setAttackRadius, getAttackRadius, 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.
+    */
     void Turret::tick(float dt)
     {
@@ -166,5 +223,5 @@
         if(!this->once_)
         {
-
+            //Account for rotations done in xml
             Quaternion startOrient = this->getOrientation();
             this->localXStart_ = startOrient * this->localX_;
@@ -198,6 +255,6 @@
         if(this->rotation_ != Quaternion::IDENTITY)
         {
-            //Don't make the rotation instantaneous
-            Quaternion drot = Quaternion::Slerp(dt*this->rotationThrust_/20.f, Quaternion::IDENTITY, this->rotation_);
+            //Don't make the rotation instantaneous. Use an arbitrary interpolation, not that great...
+            Quaternion drot = Quaternion::nlerp(dt*this->rotationThrust_/20.f, Quaternion::IDENTITY, this->rotation_);
             this->rotate(drot, WorldEntity::World);
             this->rotation_ = Quaternion::IDENTITY;
