From: Christoph Sommer Date: Sat, 17 Jun 2006 16:16:26 +0000 (+0000) Subject: Statistics are now invalid (i.e. no displaying, no merging) after restarting a level... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=f17ff6d7a4ebb176f264e037b12ab8adfbeb3846;p=supertux.git Statistics are now invalid (i.e. no displaying, no merging) after restarting a level from a firefly SVN-Revision: 3671 --- diff --git a/src/game_session.cpp b/src/game_session.cpp index 5cfa5adaa..b089677bc 100644 --- a/src/game_session.cpp +++ b/src/game_session.cpp @@ -122,6 +122,7 @@ GameSession::restart_level(bool fromBeginning) level->stats.total_badguys = level->get_total_badguys(); level->stats.total_secrets = level->get_total_count(); level->stats.reset(); + if (!fromBeginning) level->stats.declare_invalid(); if (fromBeginning) reset_sector=""; if(reset_sector != "") { diff --git a/src/statistics.cpp b/src/statistics.cpp index 5a9cc64b0..37322ec57 100644 --- a/src/statistics.cpp +++ b/src/statistics.cpp @@ -37,7 +37,7 @@ namespace { 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), secrets(nv_secrets), total_secrets(nv_secrets), 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), valid(true), display_stat(0) { } @@ -95,6 +95,9 @@ Statistics::draw_worldmap_info(DrawingContext& context) // skip draw if level was never played if (coins == nv_coins) return; + // skip draw if stats were declared invalid + if (!valid) return; + context.draw_text(white_small_text, ::chain("- ", _("Best Level Statistics"), " -"), Vector((WMAP_INFO_LEFT_X + WMAP_INFO_RIGHT_X) / 2, WMAP_INFO_TOP_Y1), CENTER_ALLIGN, LAYER_GUI); float alpha; @@ -157,6 +160,9 @@ Statistics::draw_message_info(DrawingContext& context, std::string title) // TODO: do we need this? if (coins == nv_coins) return; + // skip draw if stats were declared invalid + if (!valid) return; + context.draw_text(gold_text, title, Vector(SCREEN_WIDTH/2, 410), CENTER_ALLIGN, LAYER_GUI); char str[128]; @@ -189,6 +195,9 @@ Statistics::draw_endseq_panel(DrawingContext& context, Statistics* best_stats, S // TODO: do we need this? if (coins == nv_coins) return; + // skip draw if stats were declared invalid + if (!valid) return; + // abort if we have no backdrop if (!backdrop) return; @@ -260,6 +269,7 @@ Statistics::reset() void Statistics::merge(Statistics& s2) { + if (!s2.valid) return; coins = std::max(coins, s2.coins); total_coins = s2.total_coins; badguys = std::max(badguys, s2.badguys); @@ -272,6 +282,7 @@ Statistics::merge(Statistics& s2) void Statistics::operator+=(const Statistics& s2) { + if (!s2.valid) return; if (s2.coins != nv_coins) coins += s2.coins; if (s2.total_coins != nv_coins) total_coins += s2.total_coins; if (s2.badguys != nv_badguys) badguys += s2.badguys; @@ -280,3 +291,10 @@ Statistics::operator+=(const Statistics& s2) if (s2.secrets != nv_secrets) secrets += s2.secrets; if (s2.total_secrets != nv_secrets) total_secrets += s2.total_secrets; } + +void +Statistics::declare_invalid() +{ + valid = false; +} + diff --git a/src/statistics.hpp b/src/statistics.hpp index 0883e36aa..5419f5bca 100644 --- a/src/statistics.hpp +++ b/src/statistics.hpp @@ -59,7 +59,10 @@ public: void merge(Statistics& stats); /**< Given another Statistics object finds the best of each one */ void operator+=(const Statistics& o); /**< Add two Statistics objects */ + void declare_invalid(); /**< marks statistics as invalid for their entire lifetime (e.g. after cheating). Invalid statistics will not be merged or drawn. */ + private: + bool valid; /**< stores whether this statistics can be trusted */ Timer timer; /**< for draw_worldmap_info: time until switching to next stat */ int display_stat; /**< for draw_worldmap_info: which stat is currently displayed */ };