From 8efc40011bae77dc30b0d87f410b2478f760eb2e Mon Sep 17 00:00:00 2001 From: pionere Date: Mon, 19 Aug 2024 08:25:55 +0200 Subject: [PATCH] merge InitThemes and HoldThemeRooms --- Source/interfac.cpp | 3 +- Source/themes.cpp | 71 ++++++++++++++++++++++----------------------- Source/themes.h | 10 ++++--- 3 files changed, 41 insertions(+), 43 deletions(-) diff --git a/Source/interfac.cpp b/Source/interfac.cpp index 5a40fd652fe..b69f6775569 100644 --- a/Source/interfac.cpp +++ b/Source/interfac.cpp @@ -229,9 +229,8 @@ void LoadGameLevel(int lvldir) IncProgress(); // "MonsterFX" (7) if (currLvl._dType != DTYPE_TOWN) { GetLevelMTypes(); // select monster types and load their fx - InitThemes(); // select theme types + InitThemes(); // protect themes with dFlags and select theme types IncProgress(); // "Monsters" (8) - HoldThemeRooms(); // protect themes with dFlags InitMonsters(); // place monsters } else { InitLvlStores(); diff --git a/Source/themes.cpp b/Source/themes.cpp index 8618ad555d3..d01e6fba56a 100644 --- a/Source/themes.cpp +++ b/Source/themes.cpp @@ -310,12 +310,41 @@ void InitLvlThemes() void InitThemes() { - int i, j; + int i, j, x, y, x1, y1, x2, y2; // assert(currLvl._dType != DTYPE_TOWN); if (currLvl._dLevelNum >= DLV_HELL4) // there are no themes in hellfire (and on diablo-level) return; + for (i = 0; i < numthemes; i++) { + x1 = themes[i]._tsx1; + y1 = themes[i]._tsy1; + x2 = themes[i]._tsx2; + y2 = themes[i]._tsy2; + // convert to subtile-coordinates + x1 = DBORDERX + 2 * x1; + y1 = DBORDERY + 2 * y1; + x2 = DBORDERX + 2 * x2 + 1; + y2 = DBORDERY + 2 * y2 + 1; + themes[i]._tsx1 = x1; + themes[i]._tsy1 = y1; + themes[i]._tsx2 = x2; + themes[i]._tsy2 = y2; + // select transval + themes[i]._tsTransVal = dTransVal[x1 + 2][y1 + 2]; + assert(themes[i]._tsTransVal != 0); + // protect themes with dFlags + // v = themes[i]._tsTransVal; + for (x = x1 + 1; x < x2; x++) { + for (y = y1 + 1; y < y2; y++) { + // if (dTransVal[x][y] == v) { -- wall? + dFlags[x][y] |= BFLAG_MON_PROTECT | BFLAG_OBJ_PROTECT; + // } + } + } + } + + // select theme types // TODO: use dType instead _gbShrineFlag = currLvl._dDunType != DGT_CAVES && currLvl._dDunType != DGT_HELL; _gbSkelRoomFlag = _gbShrineFlag && numSkelTypes != 0; @@ -329,16 +358,6 @@ void InitThemes() _gbTFountainFlag = true; _gbTreasureFlag = true; - for (i = 0; i < numthemes; i++) { - // convert to subtile-coordinates - themes[i]._tsx1 = DBORDERX + 2 * themes[i]._tsx1; - themes[i]._tsy1 = DBORDERY + 2 * themes[i]._tsy1; - themes[i]._tsx2 = DBORDERX + 2 * themes[i]._tsx2 + 1; - themes[i]._tsy2 = DBORDERY + 2 * themes[i]._tsy2 + 1; - // select transval - themes[i]._tsTransVal = dTransVal[themes[i]._tsx1 + 2][themes[i]._tsy1 + 2]; - assert(themes[i]._tsTransVal != 0); - } if (QuestStatus(Q_ZHAR)) { for (i = 0; i < numthemes; i++) { if (SpecialThemeFit(i, THEME_LIBRARY)) { @@ -356,28 +375,6 @@ void InitThemes() } } -void HoldThemeRooms() -{ - int i, x, y, x1, y1, x2, y2; - // assert(currLvl._dType != DTYPE_TOWN); - // assert(currLvl._dLevelNum < DLV_HELL4 || numthemes == 0); // there are no themes in hellfire (and on diablo-level) - - for (i = numthemes - 1; i >= 0; i--) { - x1 = themes[i]._tsx1; - y1 = themes[i]._tsy1; - x2 = themes[i]._tsx2; - y2 = themes[i]._tsy2; - // v = themes[i]._tsTransVal; - for (x = x1 + 1; x < x2; x++) { - for (y = y1 + 1; y < y2; y++) { - // if (dTransVal[x][y] == v) { -- wall? - dFlags[x][y] |= BFLAG_MON_PROTECT | BFLAG_OBJ_PROTECT; - // } - } - } - } -} - /* * Place a theme object with the specified frequency. * @param tv: theme id in the dungeon matrix. @@ -566,13 +563,13 @@ static void Theme_SkelRoom(int themeId, BYTE tv) AddObject(OBJ_BANNERL, xx + 1, yy + 1); } - if ((dObject[xx][yy - 3] == 0 || !objects[dObject[xx][yy - 3] - 1]._oDoorFlag) // not a door - && (nSolidTable[dPiece[xx][yy - 3]] || !nSolidTable[dPiece[xx + 1][yy - 3]])) { // or a single path to NE TODO: allow if !nSolidTable[dPiece[xx - 1][yy - 3]]? + if ((dObject[xx][yy - 3] == 0 || !objects[dObject[xx][yy - 3] - 1]._oDoorFlag) // not a door + && (nSolidTable[dPiece[xx][yy - 3]] || !nSolidTable[dPiece[xx + 1][yy - 3]])) { // or a single path to NE TODO: allow if !nSolidTable[dPiece[xx - 1][yy - 3]]? // assert(dObject[xx][yy - 2] == 0); AddObject(OBJ_BOOK2R, xx, yy - 2); } - if ((dObject[xx][yy + 3] == 0 || !objects[dObject[xx][yy + 3] - 1]._oDoorFlag) // not a door - && (nSolidTable[dPiece[xx][yy + 3]] || !nSolidTable[dPiece[xx + 1][yy + 3]])) { // or a single path to SW TODO: allow if !nSolidTable[dPiece[xx - 1][yy + 3]]? + if ((dObject[xx][yy + 3] == 0 || !objects[dObject[xx][yy + 3] - 1]._oDoorFlag) // not a door + && (nSolidTable[dPiece[xx][yy + 3]] || !nSolidTable[dPiece[xx + 1][yy + 3]])) { // or a single path to SW TODO: allow if !nSolidTable[dPiece[xx - 1][yy + 3]]? // assert(dObject[xx][yy + 2] == 0); AddObject(OBJ_BOOK2R, xx, yy + 2); } diff --git a/Source/themes.h b/Source/themes.h index 0136a2a37c1..1a26db12629 100644 --- a/Source/themes.h +++ b/Source/themes.h @@ -16,16 +16,18 @@ extern int numthemes; extern int zharlib; extern ThemeStruct themes[MAXTHEMES]; +/** + * @brief InitLvlThemes resets the global variables of the theme rooms. + */ void InitLvlThemes(); -void InitThemes(); /** - * @brief HoldThemeRooms marks theme rooms as populated. + * @brief InitThemes marks theme rooms as populated and selects their type. */ -void HoldThemeRooms(); +void InitThemes(); /** - * CreateThemeRooms adds thematic elements to rooms. + * @brief CreateThemeRooms adds thematic elements to rooms. */ void CreateThemeRooms();