From 86030946647fc40dc3ca7157aafa1476d7550045 Mon Sep 17 00:00:00 2001 From: toaster Date: Fri, 3 Mar 2023 16:37:35 +0000 Subject: [PATCH] M_PopulateChallengeGrid: Attempt to recover from one major tile too many for the amount of space left, which is relatively trivial only in the height == 4 case. --- src/m_cond.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/m_cond.c b/src/m_cond.c index ce67bfe99..0b6be081b 100644 --- a/src/m_cond.c +++ b/src/m_cond.c @@ -212,7 +212,53 @@ quickcheckagain: } } - if (nummajorunlocks > 0) +#if (CHALLENGEGRIDHEIGHT == 4) + if (nummajorunlocks == 1) + { + UINT8 unlocktomoveup = MAXUNLOCKABLES; + + j = gamedata->challengegridwidth-1; + + // Attempt to fix our whoopsie. + for (i = 0; i < j; i++) + { + if (gamedata->challengegrid[1 + (i*CHALLENGEGRIDHEIGHT)] != MAXUNLOCKABLES + && gamedata->challengegrid[(i*CHALLENGEGRIDHEIGHT)] == MAXUNLOCKABLES) + break; + } + + if (i == j) + { + UINT16 widthtoprint = gamedata->challengegridwidth; + Z_Free(gamedata->challengegrid); + gamedata->challengegrid = NULL; + + I_Error("M_PopulateChallengeGrid: was not able to populate one large tile even after trying again (width %d)", widthtoprint); + } + + unlocktomoveup = gamedata->challengegrid[1 + (i*CHALLENGEGRIDHEIGHT)]; + + if (i == 0 + && challengegridloops + && (gamedata->challengegrid [1 + (j*CHALLENGEGRIDHEIGHT)] + == gamedata->challengegrid[1])) + ; + else + { + j = i + 1; + } + + // Push one pair up. + gamedata->challengegrid[(i*CHALLENGEGRIDHEIGHT)] = gamedata->challengegrid[(j*CHALLENGEGRIDHEIGHT)] = unlocktomoveup; + // Wedge the remaining four underneath. + gamedata->challengegrid[2 + (i*CHALLENGEGRIDHEIGHT)] = gamedata->challengegrid[2 + (j*CHALLENGEGRIDHEIGHT)] = selection[1][0]; + gamedata->challengegrid[3 + (i*CHALLENGEGRIDHEIGHT)] = gamedata->challengegrid[3 + (j*CHALLENGEGRIDHEIGHT)] = selection[1][0]; + + nummajorunlocks = 0; + } + else +#endif + if (nummajorunlocks > 0) { UINT16 widthtoprint = gamedata->challengegridwidth; Z_Free(gamedata->challengegrid);