From 244488950ba1c0daf20795213619c27e6963937c Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Tue, 18 Apr 2006 22:14:59 +0000 Subject: [PATCH] Statisticts now also count secret areas found SVN-Revision: 3362 --- src/badguy/badguy.cpp | 1 + src/game_session.cpp | 2 ++ src/level.cpp | 17 ++++++++--------- src/level.hpp | 15 ++++++++++++--- src/object/coin.cpp | 1 + src/sector.hpp | 12 +++++++++++- src/statistics.cpp | 30 ++++++++++++++++++++++++------ src/statistics.hpp | 2 ++ src/trigger/secretarea_trigger.cpp | 5 ++++- 9 files changed, 65 insertions(+), 20 deletions(-) diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index 1f1d597e8..88827a509 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -26,6 +26,7 @@ #include "statistics.hpp" #include "game_session.hpp" #include "log.hpp" +#include "level.hpp" static const float SQUISH_TIME = 2; static const float X_OFFSCREEN_DISTANCE = 1600; diff --git a/src/game_session.cpp b/src/game_session.cpp index b65025332..0e817deb6 100644 --- a/src/game_session.cpp +++ b/src/game_session.cpp @@ -66,6 +66,7 @@ #include "gettext.hpp" #include "console.hpp" #include "flip_level_transformer.hpp" +#include "trigger/secretarea_trigger.hpp" // the engine will be run with a logical framerate of 64fps. // We chose 64fps here because it is a power of 2, so 1/64 gives an "even" @@ -118,6 +119,7 @@ GameSession::restart_level(bool fromBeginning) level->load(levelfile); level->stats.total_coins = level->get_total_coins(); level->stats.total_badguys = level->get_total_badguys(); + level->stats.total_secrets = level->get_total_count(); level->stats.reset(); if (fromBeginning) reset_sector=""; diff --git a/src/level.cpp b/src/level.cpp index 0517c6a6b..1ba57a4f4 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -182,15 +182,6 @@ Level::get_sector(size_t num) } int -Level::get_total_badguys() -{ - int total_badguys = 0; - for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) - total_badguys += (*i)->get_total_badguys(); - return total_badguys; -} - -int Level::get_total_coins() { // FIXME not really correct as coins can also be inside blocks... @@ -207,3 +198,11 @@ Level::get_total_coins() return total_coins; } +int +Level::get_total_badguys() +{ + int total_badguys = 0; + for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) + total_badguys += (*i)->get_total_badguys(); + return total_badguys; +} diff --git a/src/level.hpp b/src/level.hpp index f91ab3c23..7e0aba783 100644 --- a/src/level.hpp +++ b/src/level.hpp @@ -24,8 +24,7 @@ #include #include #include "statistics.hpp" - -class Sector; +#include "sector.hpp" namespace lisp { class Lisp; @@ -61,8 +60,18 @@ public: size_t get_sector_count(); Sector* get_sector(size_t num); - int get_total_badguys(); int get_total_coins(); + int get_total_badguys(); + + /** Get total number of GameObjects of given type */ + template int get_total_count() + { + int total = 0; + for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) { + total += (*i)->get_total_count(); + } + return total; + } private: void load_old_format(const lisp::Lisp& reader); diff --git a/src/object/coin.cpp b/src/object/coin.cpp index c7cf94014..b89f2006d 100644 --- a/src/object/coin.cpp +++ b/src/object/coin.cpp @@ -29,6 +29,7 @@ #include "gameobjs.hpp" #include "statistics.hpp" #include "object_factory.hpp" +#include "level.hpp" Coin::Coin(const Vector& pos) { diff --git a/src/sector.hpp b/src/sector.hpp index 12a168293..d291c0a69 100644 --- a/src/sector.hpp +++ b/src/sector.hpp @@ -28,7 +28,6 @@ #include "script_manager.hpp" #include "math/vector.hpp" #include "video/drawing_context.hpp" -#include "level.hpp" namespace lisp { class Lisp; @@ -47,6 +46,7 @@ class ScriptInterpreter; class SpawnPoint; class MovingObject; class CollisionHit; +class Level; enum MusicType { LEVEL_MUSIC, @@ -117,6 +117,16 @@ public: /** Get total number of badguys */ int get_total_badguys(); + /** Get total number of GameObjects of given type */ + template int get_total_count() + { + int total = 0; + for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end(); ++i) { + if (dynamic_cast(*i)) total++; + } + return total; + } + void collision_tilemap(const Rect& dest, const Vector& movement, CollisionHit& hit) const; /** Checks if at the specified rectangle are gameobjects with STATIC flag set diff --git a/src/statistics.cpp b/src/statistics.cpp index 1642312b7..d08f7b0d8 100644 --- a/src/statistics.cpp +++ b/src/statistics.cpp @@ -34,9 +34,10 @@ namespace { const int nv_coins = std::numeric_limits::min(); const int nv_badguys = std::numeric_limits::min(); const float nv_time = std::numeric_limits::max(); + const int nv_secrets = std::numeric_limits::min(); } -Statistics::Statistics() : coins(nv_coins), total_coins(nv_coins), badguys(nv_badguys), total_badguys(nv_badguys), time(nv_time), display_stat(0) +Statistics::Statistics() : coins(nv_coins), total_coins(nv_coins), badguys(nv_badguys), total_badguys(nv_badguys), time(nv_time), secrets(nv_secrets), total_secrets(nv_secrets), display_stat(0) { } @@ -52,6 +53,8 @@ Statistics::parse(const lisp::Lisp& reader) reader.get("badguys-killed", badguys); reader.get("badguys-killed-total", total_badguys); reader.get("time-needed", time); + reader.get("secrets-found", secrets); + reader.get("secrets-found-total", total_secrets); } void @@ -62,6 +65,8 @@ Statistics::write(lisp::Writer& writer) writer.write_int("badguys-killed", badguys); writer.write_int("badguys-killed-total", total_badguys); writer.write_float("time-needed", time); + writer.write_int("secrets-found", secrets); + writer.write_int("secrets-found-total", total_secrets); } //define TOTAL_DISPLAY_TIME 3400 @@ -113,6 +118,9 @@ Statistics::draw_worldmap_info(DrawingContext& context) sprintf(stat_buf, "%02d:%02d", mins,secs); } break; + case 3: + sprintf(caption_buf, _("Max secrets found:")); + sprintf(stat_buf, "%d/%d", secrets, total_secrets); default: log_debug << "Invalid stat requested to be drawn" << std::endl; break; @@ -122,7 +130,7 @@ Statistics::draw_worldmap_info(DrawingContext& context) { timer.start(TOTAL_DISPLAY_TIME); display_stat++; - if (display_stat > 2) display_stat = 0; + if (display_stat > 3) display_stat = 0; } context.draw_text(white_small_text, caption_buf, Vector(WMAP_INFO_LEFT_X, 490), LEFT_ALLIGN, LAYER_GUI); @@ -155,6 +163,11 @@ Statistics::draw_message_info(DrawingContext& context, std::string title) int secs = (csecs % 6000) / 100; sprintf(str, _("Min time needed: %02d:%02d"), mins,secs); context.draw_text(white_small_text, str, Vector(SCREEN_WIDTH/2, py), CENTER_ALLIGN, LAYER_GUI); + py+=18; + + sprintf(str, _("Max secrets found: %d / %d"), secrets, total_secrets); + context.draw_text(white_small_text, str, Vector(SCREEN_WIDTH/2, py), CENTER_ALLIGN, LAYER_GUI); + py+=18; } void @@ -200,11 +213,11 @@ Statistics::draw_endseq_panel(DrawingContext& context, Statistics* best_stats, S } context.draw_text(gold_text, buf, Vector(col3_x, row2_y), LEFT_ALLIGN, LAYER_GUI); - context.draw_text(white_text, "Badguys", Vector(col1_x, row4_y), LEFT_ALLIGN, LAYER_GUI); - snprintf(buf, 128, "%d/%d", badguys, total_badguys); + context.draw_text(white_text, "Secrets", Vector(col1_x, row4_y), LEFT_ALLIGN, LAYER_GUI); + snprintf(buf, 128, "%d/%d", secrets, total_secrets); context.draw_text(gold_text, buf, Vector(col2_x, row4_y), LEFT_ALLIGN, LAYER_GUI); - if (best_stats && (best_stats->badguys > badguys)) { - snprintf(buf, 128, "%d/%d", best_stats->badguys, best_stats->total_badguys); + if (best_stats && (best_stats->secrets > secrets)) { + snprintf(buf, 128, "%d/%d", best_stats->secrets, best_stats->total_secrets); } context.draw_text(gold_text, buf, Vector(col3_x, row4_y), LEFT_ALLIGN, LAYER_GUI); @@ -229,6 +242,7 @@ Statistics::reset() coins = 0; badguys = 0; time = 0; + secrets = 0; } void @@ -239,6 +253,8 @@ Statistics::merge(Statistics& s2) badguys = std::max(badguys, s2.badguys); total_badguys = s2.total_badguys; time = std::min(time, s2.time); + secrets = std::max(secrets, s2.secrets); + total_secrets = s2.total_secrets; } void @@ -249,4 +265,6 @@ Statistics::operator+=(const Statistics& s2) if (s2.badguys != nv_badguys) badguys += s2.badguys; if (s2.total_badguys != nv_badguys) total_badguys += s2.total_badguys; if (s2.time != nv_time) time += s2.time; + if (s2.secrets != nv_secrets) secrets += s2.secrets; + if (s2.total_secrets != nv_secrets) total_secrets += s2.total_secrets; } diff --git a/src/statistics.hpp b/src/statistics.hpp index d2655eb82..0883e36aa 100644 --- a/src/statistics.hpp +++ b/src/statistics.hpp @@ -39,6 +39,8 @@ public: int badguys; /**< badguys actively killed */ int total_badguys; /**< (vincible) badguys in level */ float time; /**< seconds needed */ + int secrets; /**< secret areas found */ + int total_secrets; /**< secret areas in level */ public: Statistics(); /**< Creates new statistics, call reset() before counting */ diff --git a/src/trigger/secretarea_trigger.cpp b/src/trigger/secretarea_trigger.cpp index e7a077024..9beca7b7c 100644 --- a/src/trigger/secretarea_trigger.cpp +++ b/src/trigger/secretarea_trigger.cpp @@ -25,6 +25,8 @@ #include "lisp/writer.hpp" #include "object_factory.hpp" #include "main.hpp" +#include "sector.hpp" +#include "level.hpp" static const float MESSAGE_TIME=3.5; @@ -45,7 +47,7 @@ SecretAreaTrigger::SecretAreaTrigger(const lisp::Lisp& reader) SecretAreaTrigger::SecretAreaTrigger(const Rect& area) { bbox = area; - message = "You found a secret area!"; + message = "You found a secret area!"; //FIXME: translation missing message_displayed = false; } @@ -89,6 +91,7 @@ SecretAreaTrigger::event(Player& , EventType type) if (!message_displayed) { message_timer.start(MESSAGE_TIME); message_displayed = true; + Sector::current()->get_level()->stats.secrets++; } } } -- 2.11.0