[Orxonox-commit 5930] r10589 - code/branches/towerdefenseFabien/src/modules/towerdefense

landauf at orxonox.net landauf at orxonox.net
Tue Sep 15 16:48:24 CEST 2015


Author: landauf
Date: 2015-09-15 16:48:24 +0200 (Tue, 15 Sep 2015)
New Revision: 10589

Modified:
   code/branches/towerdefenseFabien/src/modules/towerdefense/TowerDefense.cc
Log:
enemies can be killed by towers -> the WeakPtr returns NULL -> remove enemy from list

Modified: code/branches/towerdefenseFabien/src/modules/towerdefense/TowerDefense.cc
===================================================================
--- code/branches/towerdefenseFabien/src/modules/towerdefense/TowerDefense.cc	2015-09-15 14:44:28 UTC (rev 10588)
+++ code/branches/towerdefenseFabien/src/modules/towerdefense/TowerDefense.cc	2015-09-15 14:48:24 UTC (rev 10589)
@@ -321,23 +321,31 @@
 
         for (std::list<WeakPtr<TowerDefenseEnemy> >::iterator it = enemies_.begin(); it != enemies_.end(); )
         {
-            //destroys enemys at the end of the path and reduces the life by 1. No credits gifted
-            Vector3 ship = (*it)->getRVWorldPosition();
-            float distance = ship.distance(endpoint_);
-            if(distance < 50)
+            if (*it == NULL)
             {
-                orxout() << "enemy deleted" << endl;                
-                (*it)->destroy();
+                // the enemy was destroyed by a tower - remove it from the list
                 enemies_.erase(it++);
-                this->reduceLifes(1);
-                if (this->getLifes() == 0)
-                {
-                    this->end();
-                }
             }
             else
             {
-                ++ it;
+                //destroys enemys at the end of the path and reduces the life by 1. No credits gifted
+                Vector3 ship = (*it)->getRVWorldPosition();
+                float distance = ship.distance(endpoint_);
+                if(distance < 50)
+                {
+                    orxout() << "enemy deleted" << endl;
+                    (*it)->destroy();
+                    enemies_.erase(it++);
+                    this->reduceLifes(1);
+                    if (this->getLifes() == 0)
+                    {
+                        this->end();
+                    }
+                }
+                else
+                {
+                    ++ it;
+                }
             }
         }        
 




More information about the Orxonox-commit mailing list