const int nv_secrets = std::numeric_limits<int>::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)
{
}
// 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;
// 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];
// 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;
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);
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;
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;
+}
+
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 */
};