From 84b2c7183da5b9a4d3edcb47ca60a1d5392b905f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ond=C5=99ej=20Ho=C5=A1ek?= Date: Wed, 11 Jan 2006 19:59:34 +0000 Subject: [PATCH] * The "time needed" statistic now works again. You might need to delete your savegames first to make it work, though. * Included stdint.h in moving_object.hpp to fix problems with a few systems. SVN-Revision: 2983 --- src/game_session.cpp | 42 +++++++++++++++++++++++++++++++++++++++++- src/moving_object.hpp | 2 ++ src/object/level_time.cpp | 12 ++++++++++++ src/object/level_time.hpp | 2 ++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/game_session.cpp b/src/game_session.cpp index 12c0bd1c0..c64b9ba07 100644 --- a/src/game_session.cpp +++ b/src/game_session.cpp @@ -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::iterator i = level->sectors.begin(); i != level->sectors.end(); ++i) + { + Sector* sec = *i; + + for(std::vector::iterator j = sec->gameobjects.begin(); + j != sec->gameobjects.end(); ++j) + { + GameObject* obj = *j; + + LevelTime* lt = dynamic_cast (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::iterator i = level->sectors.begin(); i != level->sectors.end(); ++i) + { + Sector* sec = *i; + + for(std::vector::iterator j = sec->gameobjects.begin(); + j != sec->gameobjects.end(); ++j) + { + GameObject* obj = *j; + + LevelTime* lt = dynamic_cast (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!? diff --git a/src/moving_object.hpp b/src/moving_object.hpp index 0969cb0e9..79e415bb2 100644 --- a/src/moving_object.hpp +++ b/src/moving_object.hpp @@ -19,6 +19,8 @@ #ifndef SUPERTUX_MOVING_OBJECT_H #define SUPERTUX_MOVING_OBJECT_H +#include + #include "game_object.hpp" #include "collision_hit.hpp" #include "math/vector.hpp" diff --git a/src/object/level_time.cpp b/src/object/level_time.cpp index db8f3faaa..7b5a1eced 100644 --- a/src/object/level_time.cpp +++ b/src/object/level_time.cpp @@ -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"); diff --git a/src/object/level_time.hpp b/src/object/level_time.hpp index 0a6e1b3af..43dcd6d8b 100644 --- a/src/object/level_time.hpp +++ b/src/object/level_time.hpp @@ -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; -- 2.11.0