* The "time needed" statistic now works again. You might need to delete your savegame...
authorOndřej Hošek <ondra.hosek@gmail.com>
Wed, 11 Jan 2006 19:59:34 +0000 (19:59 +0000)
committerOndřej Hošek <ondra.hosek@gmail.com>
Wed, 11 Jan 2006 19:59:34 +0000 (19:59 +0000)
* Included stdint.h in moving_object.hpp to fix problems with a few systems.

SVN-Revision: 2983

src/game_session.cpp
src/moving_object.hpp
src/object/level_time.cpp
src/object/level_time.hpp

index 12c0bd1..c64b9ba 100644 (file)
@@ -48,6 +48,7 @@
 #include "object/tilemap.hpp"
 #include "object/camera.hpp"
 #include "object/player.hpp"
+#include "object/level_time.hpp"
 #include "lisp/lisp.hpp"
 #include "lisp/parser.hpp"
 #include "resources.hpp"
@@ -110,7 +111,24 @@ GameSession::restart_level()
   global_stats.reset();
   global_stats.set_total_points(COINS_COLLECTED_STAT, level->get_total_coins());
   global_stats.set_total_points(BADGUYS_KILLED_STAT, level->get_total_badguys());
-  //global_stats.set_total_points(TIME_NEEDED_STAT, level->timelimit);
+  
+  // get time
+  int time = 0;
+  for(std::vector<Sector*>::iterator i = level->sectors.begin(); i != level->sectors.end(); ++i)
+  {
+    Sector* sec = *i;
+
+    for(std::vector<GameObject*>::iterator j = sec->gameobjects.begin();
+        j != sec->gameobjects.end(); ++j)
+    {
+      GameObject* obj = *j;
+      
+      LevelTime* lt = dynamic_cast<LevelTime*> (obj);
+      if(lt)
+        time += int(lt->get_level_time());
+    }
+  }
+  global_stats.set_total_points(TIME_NEEDED_STAT, (time == 0) ? -1 : time);
 
   if(reset_sector != "") {
     currentsector = level->get_sector(reset_sector);
@@ -388,6 +406,28 @@ GameSession::check_end_conditions()
   /* End of level? */
   if(end_sequence && endsequence_timer.check()) {
     exit_status = ES_LEVEL_FINISHED;
+    
+    // add time spent to statistics
+    int tottime = 0, remtime = 0;
+    for(std::vector<Sector*>::iterator i = level->sectors.begin(); i != level->sectors.end(); ++i)
+    {
+      Sector* sec = *i;
+
+      for(std::vector<GameObject*>::iterator j = sec->gameobjects.begin();
+          j != sec->gameobjects.end(); ++j)
+      {
+        GameObject* obj = *j;
+
+        LevelTime* lt = dynamic_cast<LevelTime*> (obj);
+        if(lt)
+        {
+          tottime += int(lt->get_level_time());
+          remtime += int(lt->get_remaining_time());
+        }
+      }
+    }
+    global_stats.set_points(TIME_NEEDED_STAT, (tottime == 0 ? -1 : (tottime-remtime)));
+
     return;
   } else if (!end_sequence && tux->is_dead()) {
     if (player_status->lives < 0) { // No more lives!?
index 0969cb0..79e415b 100644 (file)
@@ -19,6 +19,8 @@
 #ifndef SUPERTUX_MOVING_OBJECT_H
 #define SUPERTUX_MOVING_OBJECT_H
 
+#include <stdint.h>
+
 #include "game_object.hpp"
 #include "collision_hit.hpp"
 #include "math/vector.hpp"
index db8f3fa..7b5a1ec 100644 (file)
@@ -68,4 +68,16 @@ LevelTime::draw(DrawingContext& context)
   context.pop_transform();
 }
 
+float
+LevelTime::get_level_time()
+{
+  return time_left.get_period();
+}
+
+float
+LevelTime::get_remaining_time()
+{
+  return time_left.get_timeleft();
+}
+
 IMPLEMENT_FACTORY(LevelTime, "leveltime");
index 0a6e1b3..43dcd6d 100644 (file)
@@ -13,6 +13,8 @@ public:
 
     void update(float elapsed_time);
     void draw(DrawingContext& context);
+    float get_level_time();
+    float get_remaining_time();
 
 private:
     Timer time_left;