From 85921ce4169bc3f8eadfe3b21a749068d7e3f2f1 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 21 Apr 2019 01:50:40 +0200 Subject: [PATCH 1/2] Clean up CheckThemeRoom --- Source/themes.cpp | 103 ++++++++++++++++------------------------------ Source/themes.h | 2 +- 2 files changed, 37 insertions(+), 68 deletions(-) diff --git a/Source/themes.cpp b/Source/themes.cpp index 1adaa2f79..4828e4a48 100644 --- a/Source/themes.cpp +++ b/Source/themes.cpp @@ -371,77 +371,46 @@ BOOL SpecialThemeFit(int i, int t) return rv; } -BOOLEAN CheckThemeRoom(int tv) +BOOL CheckThemeRoom(int tv) { - int v1; // esi - int *v2; // edx - signed int v3; // edi - signed int v4; // esi - signed int v5; // edx - signed int v6; // eax - int v7; // edi - int *v8; // esi - char *v9; // eax - int *v10; // edx - signed int v12; // [esp+Ch] [ebp-8h] - - v1 = 0; - if (trigflag_4 <= 0) { - LABEL_5: - v3 = 0; - v4 = 0; - do { - v5 = 0; - v6 = v4; - do { - if (dTransVal[0][v6] == tv) { - if (dFlags[0][v6] & DFLAG_POPULATED) { - return 0; - } - ++v3; - } - ++v5; - v6 += 112; - } while (v5 < 112); - ++v4; - } while (v4 < 112); - if (leveltype != 1 || v3 >= 9 && v3 <= 100) { - v7 = 0; - v8 = &dPiece[-1][111]; - LABEL_16: - v12 = 0; - v9 = &dTransVal[-1][v7 + 111]; - v10 = v8; - while (v9[1] != tv - || nSolidTable[v10[1]] - || (*(v9 - 111) == tv || nSolidTable[*(v10 - 111)]) /* check */ - && (v9[113] == tv || nSolidTable[v10[113]]) - && (*v9 == tv || nSolidTable[*v10]) - && (v9[2] == tv || nSolidTable[v10[2]])) { - ++v12; - v10 += 112; - v9 += 112; - if (v12 >= 112) { - ++v8; - ++v7; - if ((signed int)v8 < (signed int)&dPiece[0][111]) { - goto LABEL_16; - } - return 1; - } - } + int i, j, tarea; + + for (i = 0; i < trigflag_4; i++) { + if (dTransVal[trigs[i]._tx][trigs[i]._ty] == tv) + return FALSE; + } + + tarea = 0; + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) { + if (dTransVal[i][j] == tv) + continue; + if (dFlags[i][j] & DFLAG_POPULATED) + return FALSE; + + tarea++; } - } else { - v2 = &trigs[0]._ty; - while (dTransVal[*(v2 - 1)][*v2] != tv) { - ++v1; - v2 += 4; - if (v1 >= trigflag_4) { - goto LABEL_5; - } + } + + if (leveltype == DTYPE_CATHEDRAL && (tarea < 9 || tarea > 100)) + return FALSE; + + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) { + if (dTransVal[i][j] != tv || nSolidTable[dPiece[i][j]]) + continue; + if (dTransVal[i - 1][j] != tv && !nSolidTable[dPiece[i - 1][j]]) + return FALSE; + if (dTransVal[i + 1][j] != tv && !nSolidTable[dPiece[i + 1][j]]) + return FALSE; + if (dTransVal[i][j - 1] != tv && !nSolidTable[dPiece[i][j - 1]]) + return FALSE; + if (dTransVal[i][j + 1] != tv && !nSolidTable[dPiece[i][j + 1]]) + return FALSE; } } - return 0; + + return TRUE; } void InitThemes() diff --git a/Source/themes.h b/Source/themes.h index e86812eb4..8a4141b2d 100644 --- a/Source/themes.h +++ b/Source/themes.h @@ -27,7 +27,7 @@ BOOL CheckThemeObj3(int xp, int yp, int t, int f); BOOL TFit_Obj3(int t); BOOL CheckThemeReqs(int t); BOOL SpecialThemeFit(int i, int t); -BOOLEAN CheckThemeRoom(int tv); +BOOL CheckThemeRoom(int tv); void InitThemes(); void HoldThemeRooms(); void PlaceThemeMonsts(int t, int f); From dade490e9fc0f32b0c95e39f7e166ba7a5c6a059 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 21 Apr 2019 03:03:22 +0200 Subject: [PATCH 2/2] Clean up InitThemes --- Source/objects.cpp | 2 +- Source/themes.cpp | 140 +++++++++++++++------------------------------ Source/themes.h | 2 +- structs.h | 2 +- 4 files changed, 50 insertions(+), 96 deletions(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index 6552d8551..5f9d12e8b 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -370,7 +370,7 @@ void InitObjectGFX() } if (AllObjects[i].otheme != -1) { for (j = 0; j < numthemes; j++) { - if ((char)themes[j].ttype == AllObjects[i].otheme) + if (themes[j].ttype == AllObjects[i].otheme) fileload[AllObjects[i].ofindex] = TRUE; } } diff --git a/Source/themes.cpp b/Source/themes.cpp index 4828e4a48..e0ac7098a 100644 --- a/Source/themes.cpp +++ b/Source/themes.cpp @@ -4,7 +4,7 @@ int numthemes; // idb BOOL armorFlag; -int ThemeGoodIn[4]; +WORD ThemeGoodIn[4]; BOOL weaponFlag; BOOL treasureFlag; BOOL mFountainFlag; @@ -415,111 +415,65 @@ BOOL CheckThemeRoom(int tv) void InitThemes() { - int v0; // esi - char v1; // bl - int v2; // edi - //int v3; // eax - int i; // ebx - //int v6; // eax - int v8; // esi - int v9; // ecx - int j; // eax - //int v11; // eax - int *v13; // edi - int v14; // esi - int *v15; // ebx - //int v16; // eax - int v17; // eax - int k; // esi - int l; // ebx - //int v20; // eax + int i, j; zharlib = -1; - v0 = 0; - bCrossFlag = FALSE; numthemes = 0; + bCrossFlag = FALSE; armorFlag = TRUE; - bFountainFlag = 1; - cauldronFlag = 1; - mFountainFlag = 1; - pFountainFlag = 1; - tFountainFlag = 1; - treasureFlag = 1; + bFountainFlag = TRUE; + cauldronFlag = TRUE; + mFountainFlag = TRUE; + pFountainFlag = TRUE; + tFountainFlag = TRUE; + treasureFlag = TRUE; weaponFlag = TRUE; - if (currlevel != 16) { - v1 = leveltype; - if (leveltype == DTYPE_CATHEDRAL) { - ThemeGoodIn[0] = 0; - ThemeGoodIn[1] = 0; - ThemeGoodIn[2] = 0; - ThemeGoodIn[3] = 0; - v2 = 0; - do { - if (v0 >= MAXTHEMES) { - break; - } - //_LOBYTE(v3) = CheckThemeRoom(v2); - if (CheckThemeRoom(v2)) { - themes[v0].ttval = v2; - for (i = ThemeGood[random(0, 4)];; i = random(0, 17)) { - //_LOBYTE(v6) = SpecialThemeFit(numthemes, i); - if (SpecialThemeFit(numthemes, i)) { - break; - } + + if (currlevel == 16) + return; + + if (leveltype == DTYPE_CATHEDRAL) { + for (i = 0; i < sizeof(ThemeGoodIn); i++) + ThemeGoodIn[i] = 0; + + for (i = 0; i < 256 && numthemes < MAXTHEMES; i++) { + if (CheckThemeRoom(i)) { + themes[numthemes].ttval = i; + for (j = ThemeGood[random(0, 4)];; j = random(0, 17)) { + if (SpecialThemeFit(numthemes, j)) { + break; } - v8 = numthemes; - themes[numthemes].ttype = i; - v1 = leveltype; - v0 = v8 + 1; - numthemes = v0; } - ++v2; - } while (v2 < 256); + themes[numthemes].ttype = j; + numthemes++; + } } - if (v1 == 2 || v1 == 3 || v1 == 4) { - v9 = themeCount; - for (j = 0; j < v9; ++j) - themes[j].ttype = -1; - //_LOBYTE(v11) = QuestStatus(QTYPE_ZHAR); - v13 = &themeLoc[0].ttval; - if (QuestStatus(QTYPE_ZHAR)) { - v14 = 0; - if (themeCount > 0) { - v15 = &themeLoc[0].ttval; - while (1) { - themes[v14].ttval = *v15; - //_LOBYTE(v16) = SpecialThemeFit(v14, 5); - if (SpecialThemeFit(v14, 5)) { - break; - } - ++v14; - v15 += 5; - if (v14 >= themeCount) { - goto LABEL_23; - } - } - themes[v14].ttype = 5; - zharlib = v14; + } + if (leveltype == 2 || leveltype == 3 || leveltype == 4) { + for (i = 0; i < themeCount; i++) + themes[i].ttype = -1; + if (QuestStatus(QTYPE_ZHAR)) { + for (j = 0; j < themeCount; j++) { + themes[j].ttval = themeLoc[j].ttval; + if (SpecialThemeFit(j, 5)) { + themes[j].ttype = 5; + zharlib = j; + break; } } - LABEL_23: - v17 = themeCount; - for (k = 0; k < themeCount; v13 += 5) { - if (themes[k].ttype == -1) { - themes[k].ttval = *v13; - for (l = ThemeGood[random(0, 4)];; l = random(0, 17)) { - //_LOBYTE(v20) = SpecialThemeFit(k, l); - if (SpecialThemeFit(k, l)) { - break; - } + } + for (i = 0; i < themeCount; i++) { + if (themes[i].ttype == -1) { + themes[i].ttval = themeLoc[i].ttval; + for (j = ThemeGood[random(0, 4)];; j = random(0, 17)) { + if (SpecialThemeFit(i, j)) { + break; } - themes[k].ttype = l; } - v17 = themeCount; - ++k; + themes[i].ttype = j; } - numthemes += v17; } + numthemes += themeCount; } } // 6AAA54: using guessed type int treasureFlag; @@ -1037,7 +991,7 @@ void CreateThemeRooms() for (i = 0; i < numthemes; i++) { themex = 0; themey = 0; - switch ((char)themes[i].ttype) { + switch (themes[i].ttype) { case THEME_BARREL: Theme_Barrel(i); break; diff --git a/Source/themes.h b/Source/themes.h index 8a4141b2d..6a578527b 100644 --- a/Source/themes.h +++ b/Source/themes.h @@ -4,7 +4,7 @@ extern int numthemes; // idb extern BOOL armorFlag; -extern int ThemeGoodIn[4]; +extern WORD ThemeGoodIn[4]; extern BOOL weaponFlag; extern BOOL treasureFlag; extern BOOL mFountainFlag; diff --git a/structs.h b/structs.h index bc6517fc6..9071368d1 100644 --- a/structs.h +++ b/structs.h @@ -1153,7 +1153,7 @@ typedef struct ROOMNODE { ////////////////////////////////////////////////// typedef struct ThemeStruct { - int ttype; /* aligned 4 */ + char ttype; /* aligned 4 */ int ttval; } ThemeStruct;