Skip to content

Commit

Permalink
merge InitThemes and HoldThemeRooms
Browse files Browse the repository at this point in the history
  • Loading branch information
pionere committed Aug 19, 2024
1 parent 1a5dc6e commit 8efc400
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 43 deletions.
3 changes: 1 addition & 2 deletions Source/interfac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
71 changes: 34 additions & 37 deletions Source/themes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)) {
Expand All @@ -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.
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 6 additions & 4 deletions Source/themes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 8efc400

Please sign in to comment.