From 0dc84d8f3422d478998175ab30d785777db010aa Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 7 Aug 2022 02:16:40 +0200 Subject: [PATCH] racing fixed (hopefully) --- racing.cpp | 2 ++ system.cpp | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/racing.cpp b/racing.cpp index f7bb397f..22a23812 100644 --- a/racing.cpp +++ b/racing.cpp @@ -80,6 +80,7 @@ vector ghostset; array, MAXPLAYER> current_history; EX map best_scores; +EX map best_scores_to_save; string ghost_prefix = "default"; @@ -1287,6 +1288,7 @@ EX void race_won() { if(!best_scores.count(specialland)) best_scores[specialland] = result; best_scores[specialland] = min(best_scores[specialland], result); + best_scores_to_save[specialland] = result; saveStats(); if(official_race) uploadScore(); } diff --git a/system.cpp b/system.cpp index 9dea6748..0e0cadaa 100644 --- a/system.cpp +++ b/system.cpp @@ -1081,11 +1081,13 @@ EX void saveStats(bool emergency IS(false)) { #if CAP_RACING if(racing::on) { - if(racing::official_race && !cheater) { + auto& bs = racing::best_scores_to_save; + if(racing::official_race && !cheater && bs.count(specialland)) { fprintf(f, "RACING %s %d %d date: %s\n", VER, - int(specialland), racing::best_scores[specialland], + int(specialland), bs[specialland], buf); fclose(f); + bs.erase(specialland); } return; } @@ -1262,7 +1264,8 @@ EX void loadsave() { char buf1[80], ver[10]; int land, score; sscanf(buf, "%70s%9s%d%d", buf1, ver, &land, &score); - racing::best_scores[eLand(land)] = score; + /* score may equal 0 because of earlier bugs */ + if(score) racing::best_scores[eLand(land)] = score; println(hlog, "loaded the score for ", dnameof(eLand(land)), " of ", score); } #endif