X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsupertux%2Fstatistics.cpp;h=94d6325b055528bf00b5e81dec412619e0c975fe;hb=16821f2758e779138ebfe71b17cbb77f1b1aaf38;hp=0dd695d4c497784632e62d7e90c37cf92820c25b;hpb=b355dd0f7b2f2c741ae25d46363c9fd570c496f7;p=supertux.git diff --git a/src/supertux/statistics.cpp b/src/supertux/statistics.cpp index 0dd695d4c..94d6325b0 100644 --- a/src/supertux/statistics.cpp +++ b/src/supertux/statistics.cpp @@ -39,15 +39,15 @@ float WMAP_INFO_RIGHT_X; float WMAP_INFO_TOP_Y1; float WMAP_INFO_TOP_Y2; -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) +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) { WMAP_INFO_LEFT_X = SCREEN_WIDTH - 32 - 256; WMAP_INFO_RIGHT_X = WMAP_INFO_LEFT_X + 256; @@ -74,7 +74,8 @@ Statistics::serialize_to_squirrel(HSQUIRRELVM vm) if (time != nv_time) scripting::store_float(vm, "time-needed", time); if (secrets != nv_secrets) scripting::store_int(vm, "secrets-found", secrets); if (total_secrets != nv_secrets) scripting::store_int(vm, "secrets-found-total", total_secrets); - sq_createslot(vm, -3); + if(SQ_FAILED(sq_createslot(vm, -3))) + throw scripting::SquirrelError(vm, "Couldn't create statistics table"); } void @@ -95,7 +96,7 @@ Statistics::unserialize_from_squirrel(HSQUIRRELVM vm) } void -Statistics::draw_worldmap_info(DrawingContext& context) +Statistics::draw_worldmap_info(DrawingContext& context, float target_time) { // skip draw if level was never played if (coins == nv_coins) return; @@ -113,15 +114,15 @@ Statistics::draw_worldmap_info(DrawingContext& context) WMAP_INFO_TOP_Y1 = SCREEN_HEIGHT - 100; WMAP_INFO_TOP_Y2 = WMAP_INFO_TOP_Y1 + 16; } - - context.draw_text(Resources::small_font, std::string("- ") + _("Best Level Statistics") + " -", - Vector((WMAP_INFO_LEFT_X + WMAP_INFO_RIGHT_X) / 2, WMAP_INFO_TOP_Y1), + + context.draw_text(Resources::small_font, std::string("- ") + _("Best Level Statistics") + " -", + Vector((WMAP_INFO_LEFT_X + WMAP_INFO_RIGHT_X) / 2, WMAP_INFO_TOP_Y1), ALIGN_CENTER, LAYER_HUD,Statistics::header_color); std::string caption_buf; std::string stat_buf; float posy = WMAP_INFO_TOP_Y2; - for (int stat_no = 0; stat_no < 4; stat_no++) { + for (int stat_no = 0; stat_no < 5; stat_no++) { switch (stat_no) { case 0: @@ -133,13 +134,22 @@ Statistics::draw_worldmap_info(DrawingContext& context) stat_buf = frags_to_string(badguys, total_badguys); break; case 2: - caption_buf = _("Min time needed:"); - stat_buf = time_to_string(time); - break; - case 3: caption_buf = _("Max secrets found:"); stat_buf = secrets_to_string(secrets, total_secrets); break; + case 3: + caption_buf = _("Best time completed:"); + stat_buf = time_to_string(time); + break; + case 4: + if(target_time){ // display target time only if defined for level + caption_buf = _("Level target time:"); + stat_buf = time_to_string(target_time); + } else { + caption_buf = ""; + stat_buf = ""; + } + break; default: log_debug << "Invalid stat requested to be drawn" << std::endl; break; @@ -273,11 +283,12 @@ Statistics::operator+=(const Statistics& s2) } bool -Statistics::completed(const Statistics& stats) +Statistics::completed(const Statistics& stats, const float target_time) { - return (stats.coins == stats.total_coins && - stats.badguys == stats.total_badguys && - stats.secrets == stats.total_secrets); + return (stats.coins == stats.total_coins && + stats.badguys == stats.total_badguys && + stats.secrets == stats.total_secrets && + ((!target_time) || (stats.time <= target_time))); } void @@ -300,7 +311,7 @@ Statistics::frags_to_string(int badguys, int total_badguys) { return os.str(); } -std::string +std::string Statistics::time_to_string(float time) { int time_csecs = std::min(static_cast(time * 100), 99 * 6000 + 9999); int mins = (time_csecs / 6000);