From e162fffecfb0a8824df0377e6af09479e336550b Mon Sep 17 00:00:00 2001 From: toaster Date: Wed, 7 Jun 2023 08:14:30 +0100 Subject: [PATCH] UC_PASSWORD Unlockable type that supports entering (case-insensitive) string --- src/deh_soc.c | 7 +++++++ src/m_cond.c | 43 ++++++++++++++++++++++++++++++++++++++++++- src/m_cond.h | 3 +++ src/menus/extras-1.c | 11 ++++++++++- 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/deh_soc.c b/src/deh_soc.c index b466f1158..f6ae6a285 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -2585,6 +2585,13 @@ static void readcondition(UINT8 set, UINT32 id, char *word2) //PARAMCHECK(1); ty = UC_ADDON + offset; } + else if (fastcmp(params[0], "PASSWORD")) + { + PARAMCHECK(1); + ty = UC_PASSWORD; + stringvar = Z_StrDup(params[1]); + re = -1; + } else if ((offset=0) || fastcmp(params[0], "AND") || (++offset && fastcmp(params[0], "COMMA"))) { diff --git a/src/m_cond.c b/src/m_cond.c index fc24c3986..eca1b5433 100644 --- a/src/m_cond.c +++ b/src/m_cond.c @@ -844,6 +844,8 @@ boolean M_CheckCondition(condition_t *cn, player_t *player) return true; } return false; + case UC_PASSWORD: + return (cn->stringvar == NULL); // Just for string building case UC_AND: @@ -1292,6 +1294,8 @@ static const char *M_GetConditionString(condition_t *cn) if (gamedata->evercrashed) return "launch \"Dr. Robotnik's Ring Racers\" again after a game crash"; return NULL; + case UC_PASSWORD: + return "enter a secret password"; case UC_AND: return "&"; @@ -1610,7 +1614,7 @@ char *M_BuildConditionSetString(UINT16 unlockid) static boolean M_CheckUnlockConditions(player_t *player) { - INT32 i; + UINT32 i; conditionset_t *c; boolean ret; @@ -1629,6 +1633,43 @@ static boolean M_CheckUnlockConditions(player_t *player) return ret; } +boolean M_ConditionInterpret(const char *password) +{ + UINT32 i, j; + conditionset_t *c; + condition_t *cn; + + for (i = 0; i < MAXCONDITIONSETS; ++i) + { + c = &conditionSets[i]; + + if (!c->numconditions || gamedata->achieved[i]) + continue; + + for (j = 0; j < c->numconditions; ++j) + { + cn = &c->condition[j]; + + if (cn->type != UC_PASSWORD) + continue; + + if (cn->stringvar == NULL) + continue; + + if (stricmp(cn->stringvar, password)) + continue; + + // Remove the password for this session. + Z_Free(cn->stringvar); + cn->stringvar = NULL; + + return true; + } + } + + return false; +} + boolean M_UpdateUnlockablesAndExtraEmblems(boolean loud, boolean doall) { UINT16 i = 0, response = 0, newkeys = 0; diff --git a/src/m_cond.h b/src/m_cond.h index 2dfb1a221..c178b2f5d 100644 --- a/src/m_cond.h +++ b/src/m_cond.h @@ -55,6 +55,8 @@ typedef enum UC_REPLAY, // Save a replay UC_CRASH, // Hee ho ! + UC_PASSWORD, // Type in something funny + // Just for string building UC_AND, UC_COMMA, @@ -333,6 +335,7 @@ void M_ClearStats(void); boolean M_NotFreePlay(player_t *player); // Updating conditions and unlockables +boolean M_ConditionInterpret(const char *password); boolean M_CheckCondition(condition_t *cn, player_t *player); boolean M_UpdateUnlockablesAndExtraEmblems(boolean loud, boolean doall); diff --git a/src/menus/extras-1.c b/src/menus/extras-1.c index 9cc211287..4331743b6 100644 --- a/src/menus/extras-1.c +++ b/src/menus/extras-1.c @@ -173,8 +173,17 @@ void M_ExtrasTick(void) if (menutyping.active == false && cv_dummyextraspassword.string[0] != '\0') { - if (cht_Interpret(cv_dummyextraspassword.string) == true) + if (M_ConditionInterpret(cv_dummyextraspassword.string) == true) + { + if (M_UpdateUnlockablesAndExtraEmblems(true, true)) + { + M_Challenges(0); + } + } + else if (cht_Interpret(cv_dummyextraspassword.string) == true) + { M_InitExtras(-1); + } CV_StealthSet(&cv_dummyextraspassword, ""); }