From 1ae5df651deb3cacc6ad7e1d5cc5889a06e6b86c Mon Sep 17 00:00:00 2001 From: toaster Date: Sat, 4 Mar 2023 21:36:58 +0000 Subject: [PATCH] UC_ADDON - If you add a file (and you've unlocked Addons on non-DEVELOP builds) this gets achieved - Also, Custom # of Rounds Played conditions will show "Custom" only if Addons are loaded --- src/deh_soc.c | 5 +++-- src/g_game.c | 6 +++++- src/m_cond.c | 19 ++++++++++++++++--- src/m_cond.h | 4 +++- src/w_wad.c | 9 +++++++++ 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/deh_soc.c b/src/deh_soc.c index 86bf76c80..9f796ec7a 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -2525,10 +2525,11 @@ static void readcondition(UINT8 set, UINT32 id, char *word2) return; } } - else if (fastcmp(params[0], "CRASH")) + else if ((offset=0) || fastcmp(params[0], "ADDON") + || (++offset && fastcmp(params[0], "CRASH"))) { //PARAMCHECK(1); - ty = UC_CRASH; + ty = UC_ADDON + offset; } else if ((offset=0) || fastcmp(params[0], "AND") || (++offset && fastcmp(params[0], "COMMA"))) diff --git a/src/g_game.c b/src/g_game.c index 499d8b78e..4f24a8caa 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4425,6 +4425,8 @@ void G_LoadGameData(void) gamedata->crashflags = READUINT8(save.p); if (gamedata->crashflags & GDCRASH_LAST) gamedata->crashflags |= GDCRASH_ANY; + + gamedata->everloadedaddon = (boolean)READUINT8(save.p); } else { @@ -4598,7 +4600,7 @@ void G_SaveGameData(boolean dirty) return; } - length = (4+1+4+4+(4*GDGT_MAX)+1+4+(MAXEMBLEMS+(MAXUNLOCKABLES*2)+MAXCONDITIONSETS)+4+4+2); + length = (4+1+4+4+(4*GDGT_MAX)+1+1+4+(MAXEMBLEMS+(MAXUNLOCKABLES*2)+MAXCONDITIONSETS)+4+4+2); if (gamedata->challengegrid) { length += gamedata->challengegridwidth * CHALLENGEGRIDHEIGHT; @@ -4630,6 +4632,8 @@ void G_SaveGameData(boolean dirty) WRITEUINT8(save.p, crashflags); // 1 } + WRITEUINT8(save.p, gamedata->everloadedaddon); // 1 + WRITEUINT32(save.p, quickncasehash(timeattackfolder, 64)); // To save space, use one bit per collected/achieved/unlocked flag diff --git a/src/m_cond.c b/src/m_cond.c index 27a88b10f..5b69ba1d3 100644 --- a/src/m_cond.c +++ b/src/m_cond.c @@ -532,6 +532,8 @@ void M_ClearStats(void) for (i = 0; i < GDGT_MAX; ++i) gamedata->roundsplayed[i] = 0; gamedata->timesBeaten = 0; + + gamedata->everloadedaddon = false; gamedata->crashflags = 0; } @@ -695,6 +697,13 @@ boolean M_CheckCondition(condition_t *cn, player_t *player) return gamedata->unlocked[cn->requirement-1]; case UC_CONDITIONSET: // requires condition set x to already be achieved return M_Achieved(cn->requirement-1); + + case UC_ADDON: + return ( +#ifndef DEVELOP + M_SecretUnlocked(SECRET_ADDONS, true) && +#endif + (gamedata->everloadedaddon == true)); case UC_CRASH: if (gamedata->crashflags & (GDCRASH_LAST|GDCRASH_ANY)) { @@ -863,9 +872,8 @@ static const char *M_GetConditionString(condition_t *cn) if (cn->extrainfo1 == GDGT_MAX) work = ""; - else if (cn->extrainfo1 != GDGT_RACE - && cn->extrainfo1 != GDGT_BATTLE - && cn->extrainfo1 != GDGT_CUSTOM + else if (cn->extrainfo1 != GDGT_RACE && cn->extrainfo1 != GDGT_BATTLE // Base gametypes + && (cn->extrainfo1 != GDGT_CUSTOM || M_SecretUnlocked(SECRET_ADDONS, true) == false) // Custom is visible at 0 if addons are unlocked && gamedata->roundsplayed[cn->extrainfo1] == 0) work = " ???"; else switch (cn->extrainfo1) @@ -1025,6 +1033,11 @@ static const char *M_GetConditionString(condition_t *cn) gamedata->unlocked[cn->requirement-1] ? unlockables[cn->requirement-1].name : "???"); + + case UC_ADDON: + if (!M_SecretUnlocked(SECRET_ADDONS, true) && !gamedata->everloadedaddon) + return NULL; + return "Load a custom addon into \"Dr. Robotnik's Ring Racers\""; case UC_CRASH: if (gamedata->crashflags & (GDCRASH_LAST|GDCRASH_ANY)) return "Launch \"Dr. Robotnik's Ring Racers\" again after a game crash"; diff --git a/src/m_cond.h b/src/m_cond.h index 65fee4632..1c1009932 100644 --- a/src/m_cond.h +++ b/src/m_cond.h @@ -44,6 +44,7 @@ typedef enum UC_UNLOCKABLE, // UNLOCKABLE [unlockable number] UC_CONDITIONSET, // CONDITIONSET [condition set number] + UC_ADDON, // Ever loaded a custom file? UC_CRASH, // Hee ho ! // Just for string building @@ -230,7 +231,8 @@ struct gamedata_t UINT32 roundsplayed[GDGT_MAX]; UINT32 totalrings; - // Funny + // SPECIFIC SPECIAL EVENTS + boolean everloadedaddon; UINT8 crashflags; }; diff --git a/src/w_wad.c b/src/w_wad.c index ad630a6fb..e0c19e7e5 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -49,6 +49,7 @@ #include "fastcmp.h" #include "g_game.h" // G_LoadGameData +#include "m_cond.h" // gamedata itself #include "filesrch.h" #include "i_video.h" // rendermode @@ -813,6 +814,14 @@ UINT16 W_InitFile(const char *filename, boolean mainfile, boolean startup) } #endif + // Do this immediately before anything of consequence that invalidates gamedata can happen. + if ((mainfile == false) && (gamedata != NULL) && (gamedata->everloadedaddon == false)) + { + gamedata->everloadedaddon = true; + M_UpdateUnlockablesAndExtraEmblems(true); + G_SaveGameData(true); + } + switch(type = ResourceFileDetect(filename)) { case RET_SOC: