Index: code/trunk/src/modules/overlays/hud/CMakeLists.txt
===================================================================
--- code/trunk/src/modules/overlays/hud/CMakeLists.txt	(revision 8891)
+++ code/trunk/src/modules/overlays/hud/CMakeLists.txt	(revision 9016)
@@ -7,4 +7,5 @@
   HUDHealthBar.cc
   HUDTimer.cc
+  HUDEnemyHealthBar.cc
   ChatOverlay.cc
   AnnounceMessage.cc
Index: code/trunk/src/modules/overlays/hud/HUDEnemyHealthBar.cc
===================================================================
--- code/trunk/src/modules/overlays/hud/HUDEnemyHealthBar.cc	(revision 9016)
+++ code/trunk/src/modules/overlays/hud/HUDEnemyHealthBar.cc	(revision 9016)
@@ -0,0 +1,210 @@
+/*
+ *   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:
+ *      Matthias Spalinger
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "HUDEnemyHealthBar.h"
+
+#include <OgreCamera.h>
+
+#include "util/Convert.h"
+#include "core/ConfigValueIncludes.h"
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+#include "infos/PlayerInfo.h"
+#include "overlays/OverlayGroup.h"
+#include "CameraManager.h"
+#include "graphics/Camera.h"
+#include "util/Math.h"
+#include "HUDNavigation.h"
+#include "core/input/InputManager.h"
+#include "controllers/HumanController.h"
+#include "core/GraphicsManager.h"
+#include "Scene.h"
+#include "Radar.h"
+#include "controllers/NewHumanController.h"
+
+namespace orxonox
+{
+    CreateFactory(HUDEnemyHealthBar);
+
+    HUDEnemyHealthBar::HUDEnemyHealthBar(BaseObject* creator) : HUDHealthBar(creator)
+    {
+        RegisterObject(HUDEnemyHealthBar);
+
+        this->setConfigValues();
+        setSensibility(0.1f);
+        this->owner_ = 0;
+        markerLimit_ = 3; //TODO connect with markerLimit_ from the settings / from HUDNavigation.cc
+        currentYaw = 0;
+        currentPitch = 0;
+
+        this->getOverlayText()->setCaption("");
+    }
+
+    HUDEnemyHealthBar::~HUDEnemyHealthBar()
+    {
+        sortedObjectList_.clear();
+    }
+
+    void HUDEnemyHealthBar::setConfigValues()
+    {
+        SetConfigValue(useEnemyBar_, true);
+    }
+
+    void HUDEnemyHealthBar::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(HUDEnemyHealthBar, XMLPort, xmlelement, mode);
+
+        XMLPortParam ( HUDEnemyHealthBar, "sensibility", setSensibility, getSensibility, xmlelement, mode );
+    }
+
+    bool compareDist ( std::pair<RadarViewable*, unsigned int > a, std::pair<RadarViewable*, unsigned int > b )
+    {
+        return a.second<b.second;
+    }
+
+    void HUDEnemyHealthBar::tick(float dt)
+    {
+        if (!useEnemyBar_){
+            this->setValue(0); //TODO hide it instead of setting it to 0
+            this->getOverlayText()->setCaption("");
+            return;
+        }
+
+        Camera* cam = CameraManager::getInstance().getActiveCamera();
+        if ( cam == NULL )
+            return;
+        const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix();
+
+        unsigned int markerCount_ = 0;
+
+        for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++listIt )
+        {
+            listIt->second = ( int ) ( ( listIt->first->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition() ).length() + 0.5f );
+        }
+    
+        sortedObjectList_.sort ( compareDist );
+
+        for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++markerCount_, ++listIt )
+        {
+            if ( markerCount_ < markerLimit_ )
+            {        
+                // Transform to screen coordinates and reverse x-axis
+                Vector3 pos = (camTransform * listIt->first->getRVWorldPosition());
+                pos.x = -pos.x;                
+
+                // get mouse position
+                if(this->getOwner() && dynamic_cast<ControllableEntity*>(this->getOwner())->getController() && dynamic_cast<NewHumanController*>(dynamic_cast<ControllableEntity*>(this->getOwner())->getController()))
+                {
+                    currentYaw = dynamic_cast<NewHumanController*>(dynamic_cast<ControllableEntity*>(this->getOwner())->getController())->getCurrentYaw();
+                    currentPitch = dynamic_cast<NewHumanController*>(dynamic_cast<ControllableEntity*>(this->getOwner())->getController())->getCurrentPitch();
+                }
+                // Compare cursor position to object position
+                if ( fabs(pos.x - currentYaw) < sens_ && fabs(pos.y - currentPitch) < sens_ )
+                {
+                    this->owner_ = orxonox_cast<Pawn*>(listIt->first);
+                    break;
+                }
+            }
+            this->owner_ = 0;
+        }
+
+
+
+        if (this->owner_)
+        {
+            this->setValue(this->owner_->getHealth() / this->owner_->getInitialHealth());
+            this->getOverlayText()->setCaption(multi_cast<std::string>(static_cast<int>(this->owner_->getHealth())));
+        }
+        else
+        {
+            this->setValue(0);      //TODO hide it instead of setting it to zero
+            this->getOverlayText()->setCaption("");
+        }
+
+        if (this->getTextUseBarColour())
+            this->getOverlayText()->setColour(this->getCurrentBarColour());
+    }
+
+    void HUDEnemyHealthBar::addObject ( RadarViewable* object )
+    {
+        if( showObject(object)==false )
+            return;
+    
+        if ( sortedObjectList_.size() >= markerLimit_ )
+            if ( object == NULL )
+                return;
+    
+        sortedObjectList_.push_front ( std::make_pair ( object, ( unsigned int ) 0 ) );
+
+        //remove duplicates
+        sortedObjectList_.unique();
+    }
+
+    bool HUDEnemyHealthBar::showObject(RadarViewable* rv)
+    {
+        if ( rv == dynamic_cast<RadarViewable*> ( this->getOwner() ) )
+            return false;
+        assert( rv->getWorldEntity() );
+        if ( rv->getWorldEntity()->isVisible()==false || rv->getRadarVisibility()==false )
+            return false;
+        return true;
+    }
+
+    void HUDEnemyHealthBar::removeObject ( RadarViewable* viewable )
+    {
+        for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++listIt )
+        {
+            if ( (listIt->first) == viewable )
+            {
+                sortedObjectList_.erase ( listIt );
+                break;
+            }
+    
+        }
+
+    }
+
+    void HUDEnemyHealthBar::objectChanged(RadarViewable* viewable)
+    {
+        // TODO: niceification neccessary - and while you're at it: the same function exists in HUDNavigation.cc ;)
+        removeObject(viewable);
+        addObject(viewable);
+    }
+
+    void HUDEnemyHealthBar::changedOwner()
+    {
+    
+        const std::set<RadarViewable*>& respawnObjects = this->getOwner()->getScene()->getRadar()->getRadarObjects();
+        for ( std::set<RadarViewable*>::const_iterator it = respawnObjects.begin(); it != respawnObjects.end(); ++it )
+        {
+            if ( ! ( *it )->isHumanShip_ )
+                this->addObject ( *it );
+        }
+    }
+
+}
Index: code/trunk/src/modules/overlays/hud/HUDEnemyHealthBar.h
===================================================================
--- code/trunk/src/modules/overlays/hud/HUDEnemyHealthBar.h	(revision 9016)
+++ code/trunk/src/modules/overlays/hud/HUDEnemyHealthBar.h	(revision 9016)
@@ -0,0 +1,83 @@
+/*
+ *   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:
+ *      Matthias Spalinger
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _HUDEnemyHealthBar_H__
+#define _HUDEnemyHealthBar_H__
+
+#include "interfaces/RadarViewable.h"
+#include "worldentities/pawns/Pawn.h"
+
+#include "HUDHealthBar.h"
+#include "interfaces/RadarListener.h"
+
+namespace orxonox
+{
+    class _OverlaysExport HUDEnemyHealthBar : public HUDHealthBar, public RadarListener
+    {
+        public:
+            HUDEnemyHealthBar(BaseObject* creator);
+            virtual ~HUDEnemyHealthBar();
+            void setConfigValues();
+
+            bool compareDistance ( std::pair<RadarViewable*, unsigned int > a, std::pair<RadarViewable*, unsigned int > b );
+
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+            virtual void tick(float dt);
+
+            //RadarListener interface
+            void addObject ( RadarViewable* object );
+            void removeObject ( RadarViewable* viewable );
+            void objectChanged(RadarViewable* viewable);
+            virtual void radarTick ( float dt ) {}
+            inline float getRadarSensitivity() const
+                { return 1.0f; }
+
+            void changedOwner();
+
+        private:
+
+            void setSensibility (float sense){
+                this->sens_ = sense;}
+            float getSensibility(){
+                return this->sens_;}
+
+            bool showObject(RadarViewable* rv);
+        
+            typedef std::list < std::pair<RadarViewable*, unsigned int > > sortedList;
+            sortedList sortedObjectList_;
+
+            Pawn* owner_;
+            float sens_;
+            bool useEnemyBar_;
+            unsigned int markerLimit_;
+
+            float currentYaw;
+            float currentPitch;
+    };
+}
+#endif /* _HUDEnemyHealthBar_H__ */
Index: code/trunk/src/modules/overlays/hud/HUDHealthBar.h
===================================================================
--- code/trunk/src/modules/overlays/hud/HUDHealthBar.h	(revision 8891)
+++ code/trunk/src/modules/overlays/hud/HUDHealthBar.h	(revision 9016)
@@ -110,4 +110,9 @@
                 { return this->textoverlay_->getSpaceWidth(); }
 
+            inline void setOverlayText(SmartPtr<OverlayText> textoverlay)
+                { this->textoverlay_ = textoverlay; }
+            inline SmartPtr<OverlayText> getOverlayText() const
+                {return this->textoverlay_; }
+
         private:
             WeakPtr<Pawn> owner_;
Index: code/trunk/src/modules/overlays/hud/HUDNavigation.cc
===================================================================
--- code/trunk/src/modules/overlays/hud/HUDNavigation.cc	(revision 8891)
+++ code/trunk/src/modules/overlays/hud/HUDNavigation.cc	(revision 9016)
@@ -25,4 +25,5 @@
  *      Reto Grieder
  *      Oliver Scheuss
+ *      Matthias Spalinger
  *
  */
@@ -63,5 +64,5 @@
 {
   SetConfigValue(markerLimit_, 3);
-
+  SetConfigValue(showDistance, false);
 }
 
@@ -75,8 +76,8 @@
 
     // Set default values
-    setFont ( "Monofur" );
-    setTextSize ( 0.05f );
-    setNavMarkerSize ( 0.05f );
-    setDetectionLimit( 10000.0f );
+    this->setFont ( "Monofur" );
+    this->setTextSize ( 0.05f );
+    this->setNavMarkerSize ( 0.05f );
+    this->setDetectionLimit( 10000.0f ); 
 }
 
@@ -97,8 +98,8 @@
     SUPER ( HUDNavigation, XMLPort, xmlelement, mode );
 
-    XMLPortParam ( HUDNavigation, "font",           setFont,           getFont,           xmlelement, mode );
-    XMLPortParam ( HUDNavigation, "textSize",       setTextSize,       getTextSize,       xmlelement, mode );
-    XMLPortParam ( HUDNavigation, "navMarkerSize",  setNavMarkerSize,  getNavMarkerSize,  xmlelement, mode );
-    XMLPortParam ( HUDNavigation, "detectionLimit", setDetectionLimit, getDetectionLimit, xmlelement, mode );
+    XMLPortParam ( HUDNavigation, "font",          setFont,          getFont,          xmlelement, mode );
+    XMLPortParam ( HUDNavigation, "textSize",      setTextSize,      getTextSize,      xmlelement, mode );
+    XMLPortParam ( HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize, xmlelement, mode );
+    XMLPortParam ( HUDNavigation, "detectionLimit", setDetectionLimit, getDetectionLimit, xmlelement, mode ); 
 }
 
@@ -144,5 +145,17 @@
 }
 
-
+float HUDNavigation::getArrowSizeX(int dist)
+{    
+    if (dist < 600) 
+        dist = 600;
+    return this->getActualSize().x * 900 * navMarkerSize_ / dist;
+}
+
+float HUDNavigation::getArrowSizeY(int dist)
+{    
+    if (dist < 600)
+        dist = 600;   
+    return this->getActualSize().y * 900 * navMarkerSize_ / dist;
+}
 
 void HUDNavigation::tick ( float dt )
@@ -165,4 +178,5 @@
     unsigned int markerCount_ = 0;
     bool closeEnough_ = false; //only display objects that are close enough to be relevant for the player
+
 //         for (ObjectMap::iterator it = activeObjectList_.begin(); it != activeObjectList_.end(); ++it)
     for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++markerCount_, ++listIt )
@@ -170,5 +184,6 @@
         ObjectMap::iterator it = activeObjectList_.find ( listIt->first );
         closeEnough_ = listIt->second < detectionLimit_ ;
-        if ( markerCount_ < markerLimit_ && (closeEnough_ ||  detectionLimit_ < 0) ) // display on HUD if the statement is true
+        // display radarviewables on HUD if the marker limit and max-distance is not exceeded 
+        if ( markerCount_ < markerLimit_ && (closeEnough_ ||  detectionLimit_ < 0) ) 
         {
 
@@ -176,6 +191,17 @@
             // Get Distance to HumanController and save it in the TextAreaOverlayElement.
             int dist = listIt->second;
+            float textLength = 0.0f;
+
+            //display distance next to cursor
+            if (showDistance){
             it->second.text_->setCaption ( multi_cast<std::string> ( dist ) );
-            float textLength = multi_cast<std::string> ( dist ).size() * it->second.text_->getCharHeight() * 0.3f;
+            textLength = multi_cast<std::string> ( dist ).size() * it->second.text_->getCharHeight() * 0.3f;
+            }
+
+            //display name next to cursor
+            else{
+            it->second.text_->setCaption(it->first->getRVName()); 
+            textLength = it->first->getRVName().size() * it->second.text_->getCharHeight() * 0.3f;
+            }
 
             // Transform to screen coordinates
@@ -194,6 +220,4 @@
             else
                 outOfView = pos.x < -1.0 || pos.x > 1.0 || pos.y < -1.0 || pos.y > 1.0;
-            // Get Distance to HumanController and save it in the TextAreaOverlayElement.
-            it->second.text_->setCaption ( multi_cast<std::string> ( dist ) );
 
             if ( outOfView )
@@ -207,4 +231,10 @@
                     it->second.wasOutOfView_ = true;
                 }
+
+                //float xDistScale = this->getActualSize().x * 1000.0f * navMarkerSize_ / dist;
+                //float yDistScale = this->getActualSize().y * 1000.0f * navMarkerSize_ / dist;
+
+                // Adjust Arrowsize according to distance
+                it->second.panel_->setDimensions(getArrowSizeX(dist),getArrowSizeY(dist));
 
                 // Switch between top, bottom, left and right position of the arrow at the screen border
@@ -263,4 +293,5 @@
                   //it->second.panel_->setMaterialName ( "Orxonox/NavTDC" );
                     it->second.panel_->setMaterialName( TextureGenerator::getMaterialName( "tdc.png", it->first->getRadarObjectColour()) );
+                    it->second.panel_->setDimensions ( navMarkerSize_ * this->getActualSize().x, navMarkerSize_ * this->getActualSize().y );
                     it->second.wasOutOfView_ = false;
                 }
@@ -280,5 +311,5 @@
             it->second.text_->show();
         }
-        else // do not display on HUD
+        else // do not display on HUD 
         {
             it->second.panel_->hide();
@@ -312,5 +343,5 @@
 void HUDNavigation::addObject ( RadarViewable* object )
 {
-    if( showObject(object) == false )
+    if( showObject(object)==false )
         return;
 
@@ -399,5 +430,5 @@
         return false;
     assert( rv->getWorldEntity() );
-    if ( rv->getWorldEntity()->isVisible() == false || rv->getRadarVisibility() == false )
+    if ( rv->getWorldEntity()->isVisible()==false || rv->getRadarVisibility()==false )
         return false;
     return true;
Index: code/trunk/src/modules/overlays/hud/HUDNavigation.h
===================================================================
--- code/trunk/src/modules/overlays/hud/HUDNavigation.h	(revision 8891)
+++ code/trunk/src/modules/overlays/hud/HUDNavigation.h	(revision 9016)
@@ -24,4 +24,5 @@
  *   Co-authors:
  *      Reto Grieder
+ *      Matthias Spalinger
  *
  */
@@ -54,4 +55,5 @@
     virtual void tick ( float dt );
 
+    // RadarListener interface
     virtual void addObject ( RadarViewable* object );
     virtual void removeObject ( RadarViewable* viewable );
@@ -66,4 +68,6 @@
     inline float getRadarSensitivity() const
     { return 1.0f; }
+
+    unsigned int getMarkerLimit() { return this->markerLimit_; }
 
 private:
@@ -81,12 +85,11 @@
     // XMLPort accessors
     void setNavMarkerSize ( float size )
-    { navMarkerSize_ = size; this->sizeChanged(); }
+        { navMarkerSize_ = size; this->sizeChanged(); }
     float getNavMarkerSize() const
-    { return navMarkerSize_; }
-
-    void setDetectionLimit( float limit )
-    { this->detectionLimit_ = limit; }
-    float getDetectionLimit() const
-    { return this->detectionLimit_; }
+        { return navMarkerSize_; }
+    void setDetectionLimit( float limit ) 
+        { this->detectionLimit_ = limit; } 
+    float getDetectionLimit() const 
+        { return this->detectionLimit_; }
 
     void setTextSize ( float size );
@@ -102,12 +105,15 @@
     sortedList sortedObjectList_;
 
+    float getArrowSizeX(int dist);    
+    float getArrowSizeY(int dist);
 
     float navMarkerSize_;
     std::string fontName_;
     float textSize_;
+    bool showDistance;
 
-    unsigned int markerLimit_; //TODO: is it possible to set this over the console and/or the IG-Setting
-    float detectionLimit_; //!< Objects that are more far away than detectionLimit_ are not displayed on the HUD. 10000.0f is the default value.
-                           //!< In order to bypass this behaviour, set a negative detectionLimit_. Then the detection range is "infinite".
+    unsigned int markerLimit_;
+    float detectionLimit_; //!< Objects that are more far away than detectionLimit_ are not displayed on the HUD. 10000.0f is the default value. 
+
 };
 }
