From fd40561c7d584fa55c245bb96c4509b9839e140a Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Fri, 26 Apr 2024 15:26:10 -0400 Subject: [PATCH] Make chao keys easier --- src/g_gamedata.cpp | 44 +++++++++++++++++++++++++++++++++++++++++--- src/m_cond.h | 4 ++-- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/g_gamedata.cpp b/src/g_gamedata.cpp index e080d5c5e..adb41ff88 100644 --- a/src/g_gamedata.cpp +++ b/src/g_gamedata.cpp @@ -28,6 +28,9 @@ namespace fs = std::filesystem; using json = nlohmann::json; +#define GD_VERSION_MAJOR (0xBA5ED321) +#define GD_VERSION_MINOR (1) + void srb2::save_ng_gamedata() { if (gamedata == NULL || !gamedata->loaded) @@ -293,8 +296,8 @@ void srb2::save_ng_gamedata() srb2::io::BufferedOutputStream bos {std::move(file)}; // The header is necessary to validate during loading. - srb2::io::write(static_cast(0xBA5ED321), bos); // major - srb2::io::write(static_cast(0), bos); // minor/flags + srb2::io::write(static_cast(GD_VERSION_MAJOR), bos); // major + srb2::io::write(static_cast(GD_VERSION_MINOR), bos); // minor/flags srb2::io::write(static_cast(gamedata->evercrashed), bos); // dirty (crash recovery) std::vector ubjson = json::to_ubjson(ng); @@ -413,7 +416,7 @@ void srb2::load_ng_gamedata() return; } - if (majorversion != 0xBA5ED321) + if (majorversion != GD_VERSION_MAJOR) { const char* gdfolder = G_GameDataFolder(); I_Error("Game data is not for Ring Racers v2.0.\nDelete %s (maybe in %s) and try again.", gamedatafilename, gdfolder); @@ -827,7 +830,42 @@ void srb2::load_ng_gamedata() } } + bool converted = false; + UINT32 chao_key_rounds = GDCONVERT_ROUNDSTOKEY; + UINT32 start_keys = GDINIT_CHAOKEYS; + + if (minorversion == 0) + { + chao_key_rounds = 14; + start_keys = 3; + } + + if (chao_key_rounds != GDCONVERT_ROUNDSTOKEY) + { + // Chao key rounds changed. + // Just reset all round progress, because there is a dumbass + // bug that can cause infinite chao keys from loading. + gamedata->pendingkeyrounds = 0; + gamedata->pendingkeyroundoffset = 0; + gamedata->keyspending = 0; + converted = true; + } + + if (GDINIT_CHAOKEYS > start_keys) + { + // Chao key starting amount changed. + // Give some free keys! + gamedata->chaokeys += GDINIT_CHAOKEYS - start_keys; + converted = true; + } + M_FinaliseGameData(); + + if (converted) + { + CONS_Printf("Gamedata was converted from version %d to version %d\n", + minorversion, GD_VERSION_MINOR); + } } // G_LoadGameData diff --git a/src/m_cond.h b/src/m_cond.h index 5c2142561..421b7a95b 100644 --- a/src/m_cond.h +++ b/src/m_cond.h @@ -298,9 +298,9 @@ typedef enum { #define GDMAX_CHAOKEYS 9999 #define GDMAX_SEALEDSWAPS 7 -#define GDCONVERT_ROUNDSTOKEY 14 +#define GDCONVERT_ROUNDSTOKEY 5 -#define GDINIT_CHAOKEYS 3 // Start with 3 Chao Keys !! +#define GDINIT_CHAOKEYS 10 // Start with 10 Chao Keys !! #define GDINIT_PRISONSTOPRIZE 30 // 30 Prison Eggs to your [Wild Prize] !! typedef enum {