[Orxonox-commit 5065] r9729 - code/trunk/src/orxonox/gametypes

jo at orxonox.net jo at orxonox.net
Thu Oct 31 22:18:39 CET 2013


Author: jo
Date: 2013-10-31 22:18:39 +0100 (Thu, 31 Oct 2013)
New Revision: 9729

Modified:
   code/trunk/src/orxonox/gametypes/Mission.cc
   code/trunk/src/orxonox/gametypes/Mission.h
Log:
Creating new console command to set the lives in a mission.

Modified: code/trunk/src/orxonox/gametypes/Mission.cc
===================================================================
--- code/trunk/src/orxonox/gametypes/Mission.cc	2013-10-29 19:56:38 UTC (rev 9728)
+++ code/trunk/src/orxonox/gametypes/Mission.cc	2013-10-31 21:18:39 UTC (rev 9729)
@@ -32,12 +32,15 @@
 
 #include "core/CoreIncludes.h"
 #include "core/command/ConsoleCommand.h"
+#include "infos/PlayerInfo.h"
 #include "network/Host.h"
 #include "worldentities/pawns/Pawn.h"
 
+
 namespace orxonox
 {
     SetConsoleCommand("Mission", "endMission", &Mission::endMission);
+    SetConsoleCommand("Mission", "setLives", &Mission::setLivesWrapper);
     RegisterUnloadableClass(Mission);
 
     Mission::Mission(Context* context) : TeamGametype(context)
@@ -61,10 +64,14 @@
 
     void Mission::pawnKilled(Pawn* victim, Pawn* killer)
     {
-        if (victim && victim->getPlayer() && this->lives_ == 1)
+        if (victim && victim->getPlayer() && victim->getPlayer()->isHumanPlayer() )
         {
-            this->missionAccomplished_ = false;
-            this->end();
+            this->lives_--;
+            if (this->lives_ == 0)
+            {
+                this->missionAccomplished_ = false;
+                this->end();
+            }
         }
     }
 
@@ -102,6 +109,14 @@
             it->end();
         }
     }
+    
+    void Mission::setLivesWrapper(unsigned int amount)
+    {
+        for (ObjectList<Mission>::iterator it = ObjectList<Mission>::begin(); it != ObjectList<Mission>::end(); ++it)
+        {//TODO: make sure that only the desired mission is ended !! This is a dirty HACK, that would affect ALL missions!
+            it->setLives(amount);
+        }
+    }
 
 
 }

Modified: code/trunk/src/orxonox/gametypes/Mission.h
===================================================================
--- code/trunk/src/orxonox/gametypes/Mission.h	2013-10-29 19:56:38 UTC (rev 9728)
+++ code/trunk/src/orxonox/gametypes/Mission.h	2013-10-31 21:18:39 UTC (rev 9729)
@@ -54,14 +54,13 @@
             inline void setMissionAccomplished(bool acc)
                 {this->missionAccomplished_ = acc;}
             static void endMission(bool accomplished);
+            static void setLivesWrapper(unsigned int amount);
 
         protected:
             virtual void pawnKilled(Pawn* victim, Pawn* killer = 0);
             bool missionAccomplished_; //<! indicates if player successfully finsihed the mission;
             int lives_; //<! amount of player's lives <-> nr. of retries
-            //Make end() a callback function to the event "END"
-            //or create a console command.
-
+            //<! If the lives_ are set negative -> unlimited lives.
     };
 }
 




More information about the Orxonox-commit mailing list