From 04214c05ec7e72bd65a56284ed4f8161c27ee19b Mon Sep 17 00:00:00 2001 From: toaster Date: Tue, 30 Apr 2024 22:19:12 +0100 Subject: [PATCH] Reduce code duplication in M_UpdateChallengeGridExtraData for adjacency rules --- src/m_cond.c | 50 ++++++++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/src/m_cond.c b/src/m_cond.c index 8d7c1f3b4..e63da18cf 100644 --- a/src/m_cond.c +++ b/src/m_cond.c @@ -398,6 +398,20 @@ badgrid: gamedata->challengegridwidth = 0; } +static void M_ChallengeGridExtraDataAdjacencyRules(challengegridextradata_t *extradata, UINT16 adjacent) +{ + // Adjacent unlocked tile, permit hint/general key skip. + if (gamedata->unlocked[adjacent] == true) + { + extradata->flags |= CHE_HINT; + } + // Adjacent locked tile, prevent 10x key skip. + else + { + extradata->flags &= ~CHE_ALLCLEAR; + } +} + void M_UpdateChallengeGridExtraData(challengegridextradata_t *extradata) { UINT16 i, j, num, id, tempid, work; @@ -489,14 +503,7 @@ void M_UpdateChallengeGridExtraData(challengegridextradata_t *extradata) } else if (work < MAXUNLOCKABLES) { - if (gamedata->unlocked[work] == true) - { - extradata[id].flags |= CHE_HINT; - } - else - { - extradata[id].flags &= ~CHE_ALLCLEAR; - } + M_ChallengeGridExtraDataAdjacencyRules(extradata+id, work); } } @@ -534,14 +541,7 @@ void M_UpdateChallengeGridExtraData(challengegridextradata_t *extradata) } else if (work < MAXUNLOCKABLES) { - if (gamedata->unlocked[work] == true) - { - extradata[id].flags |= CHE_HINT; - } - else - { - extradata[id].flags &= ~CHE_ALLCLEAR; - } + M_ChallengeGridExtraDataAdjacencyRules(extradata+id, work); } } @@ -566,14 +566,7 @@ void M_UpdateChallengeGridExtraData(challengegridextradata_t *extradata) } else if (work < MAXUNLOCKABLES) { - if (gamedata->unlocked[work] == true) - { - extradata[id].flags |= CHE_HINT; - } - else - { - extradata[id].flags &= ~CHE_ALLCLEAR; - } + M_ChallengeGridExtraDataAdjacencyRules(extradata+id, work); } } @@ -595,14 +588,7 @@ void M_UpdateChallengeGridExtraData(challengegridextradata_t *extradata) } else if (work < MAXUNLOCKABLES) { - if (gamedata->unlocked[work] == true) - { - extradata[id].flags |= CHE_HINT; - } - else - { - extradata[id].flags &= ~CHE_ALLCLEAR; - } + M_ChallengeGridExtraDataAdjacencyRules(extradata+id, work); } } }