Index: code/trunk/src/modules/towerdefense/CMakeLists.txt
===================================================================
--- code/trunk/src/modules/towerdefense/CMakeLists.txt	(revision 12189)
+++ code/trunk/src/modules/towerdefense/CMakeLists.txt	(revision 12190)
@@ -10,4 +10,6 @@
   TowerDefenseField.cc
   TDCoordinate.cc
+  TowerDefenseController.cc
+  TowerDefenseRangeViewer.cc
 )
 
Index: code/trunk/src/modules/towerdefense/TowerDefense.cc
===================================================================
--- code/trunk/src/modules/towerdefense/TowerDefense.cc	(revision 12189)
+++ code/trunk/src/modules/towerdefense/TowerDefense.cc	(revision 12190)
@@ -76,5 +76,6 @@
 #include "TowerDefenseCenterpoint.h"
 #include "worldentities/SpawnPoint.h"
-#include "controllers/WaypointController.h"
+#include "worldentities/StaticEntity.h"
+#include "TowerDefenseController.h" //muss ich noch in den richtigen Ordner verschieben
 #include "graphics/Model.h"
 #include "infos/PlayerInfo.h"
@@ -82,4 +83,7 @@
 #include "core/CoreIncludes.h"
 #include "Highscore.h"
+#include "util/Output.h"
+#include "TowerDefenseRangeViewer.h"
+
 
 namespace orxonox
@@ -92,4 +96,5 @@
 
         selecter = nullptr;
+        rangeViewer = nullptr;
         this->player_ = nullptr;
         this->setHUDTemplate("TowerDefenseHUD");
@@ -124,6 +129,12 @@
                 selecter = new TowerDefenseSelecter(this->center_->getContext());                
             }
+            if(rangeViewer == nullptr){
+                rangeViewer = new TowerDefenseRangeViewer(this->center_->getContext());
+            }
             selecter->addTemplate(center_->getSelecterTemplate());
+            rangeViewer->addTemplate("therangeviewer");
+            rangeViewer->setPosition(-10000,0,-500);
             center_->attach(selecter);
+            center_->attach(rangeViewer);
         }
         else // If no centerpoint was specified, an error is thrown and the level is exited.
@@ -136,4 +147,5 @@
 
         createFields();
+
         TeamDeathmatch::start();
 
@@ -157,5 +169,6 @@
             en1->addTemplate("enemytowerdefense1");
             en1->setScale(3);
-            en1->setHealth(en1->getHealth() + this->getWaveNumber()*4);
+            en1->setHealth(en1->getHealth() + this->getWaveNumber()*1/3*0.5*(en1->getHealth()));
+            en1->setShieldHealth(en1->getShieldHealth() + this->getWaveNumber()*1/3*0.5*(en1->getShieldHealth()));
             break;
 
@@ -163,5 +176,5 @@
             en1->addTemplate("enemytowerdefense2");
             en1->setScale(2);
-            en1->setHealth(en1->getHealth() + this->getWaveNumber()*4);
+            en1->setHealth(en1->getHealth() + this->getWaveNumber()*1/3*0.3*(en1->getHealth()));
             break;
 
@@ -169,5 +182,6 @@
             en1->addTemplate("enemytowerdefense3");
             en1->setScale(1);
-            en1->setHealth(en1->getHealth() + this->getWaveNumber()*4);
+            en1->setHealth(en1->getHealth() + this->getWaveNumber()*1/3*0.2*(en1->getHealth()));
+            en1->setShieldHealth(en1->getShieldHealth() + this->getWaveNumber()*1/3*0.5*(en1->getShieldHealth()));
             break;
         }        
@@ -175,7 +189,10 @@
         en1->setTeam(2);
 
-        WaypointController* controller = (WaypointController*)(en1->getXMLController());
-
-        if (controller != nullptr && waypoints_.size() > 1)
+        //Jedem Enemy wird ein eigener Controller uebergeben
+        TowerDefenseController* controller = new TowerDefenseController(this->center_->getContext()); 
+        controller->setControllableEntity(en1);
+        en1->setController(controller);
+
+        if (waypoints_.size() > 1)
         {
             en1->setPosition(waypoints_.at(0)->getPosition() + offset_);
@@ -192,5 +209,6 @@
         }
 
-        enemies_.push_back(en1);
+        auto pair = std::make_pair(orxonox::WeakPtr<TowerDefenseEnemy>(en1), controller);
+        enemies_.push_back(pair);
     }
 
@@ -277,4 +295,10 @@
         timeSinceLastSpawn_ += dt;
 
+        if(selecter != nullptr && getField(selecter->selectedPos_)->canUpgrade() == true ){
+            rangeViewer->setPosition(((selecter->selectedPos_->GetX())-8)*100, ((selecter->selectedPos_->GetY())-8)*100, 200);
+        } else {
+            rangeViewer->setPosition(-10000,0,-500);
+        }
+
         //build/upgrade tower at selecter position
         if (selecter != nullptr && selecter->buildTower_ == true)
@@ -291,22 +315,48 @@
             }            
         }
+                
         
-        for (std::list<WeakPtr<TowerDefenseEnemy>>::iterator it = enemies_.begin(); it != enemies_.end(); )
-        {
-            if (*it == nullptr)
-            {
-                // the enemy was destroyed by a tower - remove it from the list
-                enemies_.erase(it++);
-                addCredit(1);
+        for (EnemyList::iterator it = enemies_.begin(); it != enemies_.end(); )
+        {
+            WeakPtr<TowerDefenseEnemy> enemy = it->first;
+            TowerDefenseController* ctrl = it->second;
+
+            if (enemy == nullptr)
+            {
+
+                // the enemy was destroyed by a tower - remove it from the list AND destroy the corresponding controler
+                ctrl->destroy();
+                it = enemies_.erase(it);
+                
+                int currentType = this->getWaveNumber() % 3 + 1;
+                switch (currentType){ //Entscheidet, wie viele Credits vergeben werden sollen
+                    case 1: //currently boss wave
+                        addCredit(100);
+                        if (this->getLifes() <= 90)
+                        {
+                            this->setLifes(this->getLifes() + 10);
+                        }
+                        break;
+
+                    case 2: //currently mass wave
+                        addCredit(5);
+                        break;
+
+                    case 3: //currently moderate wave
+                        addCredit(10);
+                        break;
+                }
             }
             else
             {
                 //if ships are at the end they get destroyed
-                Vector3 ship = (*it)->getRVWorldPosition();
+                Vector3 ship = enemy->getRVWorldPosition();
                 float distance = ship.distance(endpoint_);
                 if(distance < 40)
                 {
-                    (*it)->destroy();
-                    enemies_.erase(it++);
+                    enemy->getController()->destroy();
+                    enemy->destroy();
+
+                    it = enemies_.erase(it);
                     this->reduceLifes(1);
                     if (this->getLifes() == 0)
@@ -328,8 +378,9 @@
             timeSinceLastSpawn_ -= 1.0;
             -- waveSize_;
-            addTowerDefenseEnemy(this->getWaveNumber() % 3 + 1);
+            addTowerDefenseEnemy(this->getWaveNumber() % 3 + 1); //Gegnertyp rotiert durch die 3 moeglichen, er beginnt bei Typ 2!!!
         }
         else if (timeUntilNextWave_ <= 0.0 && waveSize_ <= 0)
         {
+            int currentType = this->getWaveNumber() % 3 + 1;
             //New wave
             ++ waveNumber_;
@@ -337,5 +388,18 @@
 
             timeUntilNextWave_ = waveNumber_+20.0f;
-            waveSize_ = waveNumber_+5;
+            // Entscheidung, wie gross die einzelnen waves sein sollen.
+            switch (currentType){
+                case 1: //currently boss wave
+                    waveSize_ = waveNumber_+10;
+                    break;
+
+                case 2: //currently mass wave
+                    waveSize_ = (waveNumber_+10)/2;
+                    break;
+
+                case 3: //currently moderate wave
+                    waveSize_ = 1;
+                    break;
+            }
         }
 
@@ -349,7 +413,7 @@
         std::string fields = center_->getFields();
         int pos = 0;
-        for (int j = 15; j >= 0; --j)
-        {
-            for (int i = 0; i < 16; ++i)
+        for (int j = 15; j >= 0; --j) //Vertical number of rows
+        {
+            for (int i = 0; i <= 15; ++i) //Horizontal number of rows
             {
                 coord.Set(i,j);
@@ -412,4 +476,5 @@
         }
 
+        //Falls kein anliegender Weg gefunden wurde.
         delete nextCoord;
         return nullptr;
Index: code/trunk/src/modules/towerdefense/TowerDefense.h
===================================================================
--- code/trunk/src/modules/towerdefense/TowerDefense.h	(revision 12189)
+++ code/trunk/src/modules/towerdefense/TowerDefense.h	(revision 12190)
@@ -32,4 +32,5 @@
 #include "TDCoordinate.h"
 #include "TowerDefenseSelecter.h"
+#include "TowerDefenseController.h"
 #include "towerdefense/TowerDefensePrereqs.h"
 #include "gametypes/TeamDeathmatch.h"
@@ -37,7 +38,10 @@
 #include "util/Output.h"
 #include "TowerDefenseField.h"
+#include "TowerDefenseRangeViewer.h"
 
 namespace orxonox
 {
+    using EnemyList = std::list<std::pair<orxonox::WeakPtr<TowerDefenseEnemy>, TowerDefenseController*>>;
+
     /**
     @brief
@@ -73,5 +77,6 @@
         virtual TDCoordinate* getNextStreetCoord(TDCoordinate*);
         
-        TowerDefenseSelecter* selecter;        
+        TowerDefenseSelecter* selecter;   
+        TowerDefenseRangeViewer* rangeViewer;     
 
     private:
@@ -86,5 +91,5 @@
         int waveNumber_;
         int lifes_;
-        std::list<orxonox::WeakPtr<TowerDefenseEnemy>> enemies_;
+        EnemyList enemies_;
         TowerDefenseField* fields_[16][16];
         std::vector<orxonox::WeakPtr<TowerDefenseField>> waypoints_;
Index: code/trunk/src/modules/towerdefense/TowerDefenseController.cc
===================================================================
--- code/trunk/src/modules/towerdefense/TowerDefenseController.cc	(revision 12190)
+++ code/trunk/src/modules/towerdefense/TowerDefenseController.cc	(revision 12190)
@@ -0,0 +1,131 @@
+/*
+ *   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:
+ *      Michael Baumgartner
+ *   Co-authors:
+ *      Fabian 'x3n' Landau
+ *
+ */
+
+#include "TowerDefenseController.h"
+
+#include "core/CoreIncludes.h"
+#include "items/Engine.h"
+#include "worldentities/ControllableEntity.h"
+#include "worldentities/pawns/SpaceShip.h"
+#include "TowerDefense.h"
+#include "TowerDefenseTower.h"
+#include "TowerDefenseCenterpoint.h"
+#include "worldentities/SpawnPoint.h"
+#include "graphics/Model.h"
+#include "infos/PlayerInfo.h"
+#include "chat/ChatManager.h"
+#include "Highscore.h"
+#include <math.h>
+
+namespace orxonox
+{
+    RegisterClass(TowerDefenseController);
+
+    
+    //Offset fuer die Position der Entities auf der Map
+    Vector3 offset_ = Vector3(0,0,10);
+
+    TowerDefenseController::TowerDefenseController(Context* context) : ArtificialController(context)
+    {
+        RegisterObject(TowerDefenseController);
+    }
+
+    TowerDefenseController::~TowerDefenseController() //Destructor, ehrlich gesagt keine Ahnung was er genau loescht (nehme an den Controller, falls man am letzten Waypoint angekommen ist.)
+    {
+    }
+
+    void TowerDefenseController::tick(float dt)
+    {
+        if (!this->isActive())
+            return;
+
+        SpaceShip* ship = dynamic_cast<SpaceShip*>(this->getControllableEntity());
+       
+        if (this->waypoints_.size() == 0 || !ship)
+            return;
+
+        //Bewegung entlang der Verbindungslinie zweier Waypoints, bis die Distanz zwischen Ihnen zurueckgelegt 
+        //wurde, dann eine Drehung in Richtung des Verbindungsvektors zum naechsten Vektor, und Bewegung in diese Richtung. Iterationsfehler werden behoben, indem man zuweit zurueck-
+        //gelegte Wege direkt in die neue Richtung uebernimmt. Dafuer wird in der while-Schleife zuerst berechnet, in welchem Abschnitt man sich befindet, und anschliessend, welche Distanz
+        //man in diesem Abschnitt zurueckgelegt hat. Dann wird die Position des Schiffes einfach auf den entsprechenden Ort gelegt, und geschaut, dass es in die richtige Richtung zeigt.
+
+        //Die Position  kann iterativ bestimmt werden. this->waypoints ist der Array bestehend aus den Wegpunkten, sprich allen Ecken wobei an der Position 0 der SpawnPoint steht.
+
+        // Geschwindigkeit auslesen
+        float speed;
+        Engine* engine = ship->getEngine(0);
+        if(engine != nullptr) {
+            speed = engine->getMaxSpeedFront(); //Geschwindigkeit sollte ausgelesen werden, wird momentan aber noch NICHT -> ein Fehler mit den Engines
+
+        } else {
+            speed = 200; //Momentan wird hiermit die Geschwindigkeit ALLER Schiffe gesetzt!
+        }
+
+        //Zurueckgelegte Gesamtdistanz aktualisieren.
+        totalDistance += speed * dt;
+
+        float currentDistance = 0;
+        int waypointIdx = 0;
+        bool atEnd = true;
+        while (waypointIdx + 1 < this->waypoints_.size()) {
+            Vector3 prevWaypoint = this->waypoints_[waypointIdx]->getWorldPosition();
+            Vector3 nextWaypoint = this->waypoints_[waypointIdx + 1]->getWorldPosition();
+
+            float waypointDistance = prevWaypoint.distance(nextWaypoint);
+            if (currentDistance + waypointDistance < totalDistance) {
+                currentDistance += waypointDistance;
+                waypointIdx++;
+            } else {
+                atEnd = false;
+                break;
+            }
+        }
+
+        //Nun sollten wir wissen, zwischen welchen Waypoints sich unser Raumschiff befindet, uns welche Restdistanz wir haben. Wir koennen die Position unseres Raumschiffes nun setzten.
+        //Der Offset ist glaube ich fuer alle Tiles und Objekte noetig, damits am richtigen Ort ist.
+
+        //Berechnung des Richtungsvektors
+        Vector3 newPosition;
+        Vector3 newDirection;
+        if (atEnd) {
+            newPosition = this->waypoints_.back()->getWorldPosition();
+        } else {
+            Vector3 prevWaypoint = this->waypoints_[waypointIdx]->getWorldPosition();
+            Vector3 nextWaypoint = this->waypoints_[waypointIdx + 1]->getWorldPosition();
+
+            Vector3 direction = (nextWaypoint -  prevWaypoint).normalisedCopy();
+            newPosition = prevWaypoint + (totalDistance - currentDistance) * direction;
+            newDirection = direction;
+        }
+
+        this->getControllableEntity()->setPosition(offset_ + newPosition);
+        this->getControllableEntity()->lookAt(this->getControllableEntity()->getPosition() + newDirection);
+        this->getControllableEntity()->setVelocity(speed * newDirection);
+    }
+
+}
Index: code/trunk/src/modules/towerdefense/TowerDefenseController.h
===================================================================
--- code/trunk/src/modules/towerdefense/TowerDefenseController.h	(revision 12190)
+++ code/trunk/src/modules/towerdefense/TowerDefenseController.h	(revision 12190)
@@ -0,0 +1,56 @@
+/*
+ *   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:
+ *      Michael Baumgartner
+ *   Co-authors:
+ *      Fabian 'x3n' Landau
+ *
+ */
+
+#ifndef _TowerDefenseController_H__
+#define _TowerDefenseController_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include <vector>
+#include "tools/interfaces/Tickable.h"
+#include "controllers/ArtificialController.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport TowerDefenseController : public ArtificialController, public Tickable
+    {
+        public:
+            TowerDefenseController(Context* context);
+            virtual ~TowerDefenseController();
+
+            virtual void tick(float dt) override;
+
+        private:
+
+        	//Muessen festhalten, welche Distanz das Spaceship bereits zurueckgelegt hat.
+    		double totalDistance = 0;
+
+    };
+}
+
+#endif /* _TowerDefenseController_H__ */
Index: code/trunk/src/modules/towerdefense/TowerDefenseEnemy.cc
===================================================================
--- code/trunk/src/modules/towerdefense/TowerDefenseEnemy.cc	(revision 12189)
+++ code/trunk/src/modules/towerdefense/TowerDefenseEnemy.cc	(revision 12190)
@@ -29,5 +29,4 @@
     TowerDefenseEnemy::~TowerDefenseEnemy()
     {
-
     }
 
Index: code/trunk/src/modules/towerdefense/TowerDefenseField.cc
===================================================================
--- code/trunk/src/modules/towerdefense/TowerDefenseField.cc	(revision 12189)
+++ code/trunk/src/modules/towerdefense/TowerDefenseField.cc	(revision 12190)
@@ -1,2 +1,3 @@
+
 /*
  *   ORXONOX - the hottest 3D action shooter ever to exist
@@ -282,4 +283,5 @@
                 }
             }
+            
         }                           
     }
Index: code/trunk/src/modules/towerdefense/TowerDefensePrereqs.h
===================================================================
--- code/trunk/src/modules/towerdefense/TowerDefensePrereqs.h	(revision 12189)
+++ code/trunk/src/modules/towerdefense/TowerDefensePrereqs.h	(revision 12190)
@@ -68,5 +68,5 @@
 
     class TowerDefenseTower;
-
+    class TowerDefenseRangeViewer;
     class TowerDefenseCenterpoint;
     class TowerDefenseHUDController;
Index: code/trunk/src/modules/towerdefense/TowerDefenseRangeViewer.cc
===================================================================
--- code/trunk/src/modules/towerdefense/TowerDefenseRangeViewer.cc	(revision 12190)
+++ code/trunk/src/modules/towerdefense/TowerDefenseRangeViewer.cc	(revision 12190)
@@ -0,0 +1,23 @@
+#include "core/CoreIncludes.h"
+#include "worldentities/StaticEntity.h"
+#include "TowerDefenseRangeViewer.h"
+
+
+#include "util/Output.h"
+
+namespace orxonox {
+	RegisterClass(TowerDefenseRangeViewer);
+	TowerDefenseRangeViewer::TowerDefenseRangeViewer(Context* context) : StaticEntity(context)
+	{
+		RegisterObject(TowerDefenseRangeViewer);
+	}
+
+	TowerDefenseRangeViewer::~TowerDefenseRangeViewer()
+    {
+
+    }
+
+	void TowerDefenseRangeViewer::XMLPort(Element& xmlelement, XMLPort::Mode mode){
+		SUPER(TowerDefenseRangeViewer, XMLPort, xmlelement, mode);
+	}
+}
Index: code/trunk/src/modules/towerdefense/TowerDefenseRangeViewer.h
===================================================================
--- code/trunk/src/modules/towerdefense/TowerDefenseRangeViewer.h	(revision 12190)
+++ code/trunk/src/modules/towerdefense/TowerDefenseRangeViewer.h	(revision 12190)
@@ -0,0 +1,18 @@
+#ifndef _TowerDefenseRangeViewer_H__
+#define _TowerDefenseRangeViewer_H__
+#include "towerdefense/TowerDefensePrereqs.h"
+#include "util/Output.h"
+#include "worldentities/StaticEntity.h"
+
+namespace orxonox
+{
+    class _TowerDefenseExport TowerDefenseRangeViewer : public StaticEntity
+    {
+    public:
+        TowerDefenseRangeViewer(Context* context);
+        virtual ~TowerDefenseRangeViewer();
+        virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+    };
+}
+
+#endif /* _TowerDefenseRangeViewer_H__ */
Index: code/trunk/src/modules/towerdefense/towerdefensereadme.txt
===================================================================
--- code/trunk/src/modules/towerdefense/towerdefensereadme.txt	(revision 12189)
+++ code/trunk/src/modules/towerdefense/towerdefensereadme.txt	(revision 12190)
@@ -12,5 +12,5 @@
 Represents a Tower
 I'm not actually sure if you have to code C++ in order to have your result. I would suggest to simply create a new spaceship template or maybe better a
-new template for a pawn. (The tower don't need to be spaceships; pawn is just fine.)
+new template for a pawn. (The towers don't need to be spaceships; pawn is just fine.)
 Example for a template: /data/levels/templates/assff.oxt && /data/levels/include/weaponSettingsAssff.oxi
 @ assff.oxt: you don't need an engine (or your towers could fly away :-) and probably no Cameras. (just try what happens if you leave them out.) 
