Index: code/trunk/src/modules/towerdefense/TowerDefense.cc
===================================================================
--- code/trunk/src/modules/towerdefense/TowerDefense.cc	(revision 12047)
+++ 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;
