From 69d6238a7c20e1f65299413fe1372143ecc4bcd3 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Thu, 10 Oct 2019 09:31:27 +0100 Subject: [PATCH 1/5] Add BUGFIX comment for gmenu_call_proc --- Source/gmenu.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index d37a2943c..2f65d83ab 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -107,6 +107,7 @@ void gmenu_call_proc(TMenuItem *pItem, void (*gmFunc)(TMenuItem *)) sgCurrentMenuIdx++; } } + // BUGFIX: OOB access when sgCurrentMenuIdx is 0; should be set to NULL instead. sgpCurrItem = &sgpCurrentMenu[sgCurrentMenuIdx - 1]; gmenu_up_down(TRUE); } From 74216dc1b4515c103bff3d40273cc76cc4005af5 Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Sun, 13 Oct 2019 04:48:32 -0500 Subject: [PATCH 2/5] Fix function order [drlg_l1.cpp] --- Source/drlg_l1.cpp | 1756 ++++++++++++++++++++++---------------------- Source/drlg_l1.h | 34 - 2 files changed, 877 insertions(+), 913 deletions(-) diff --git a/Source/drlg_l1.cpp b/Source/drlg_l1.cpp index bb3ad1813..07c8655a7 100644 --- a/Source/drlg_l1.cpp +++ b/Source/drlg_l1.cpp @@ -108,431 +108,7 @@ const BYTE PWATERIN[] = { 6, 6, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, /* data */ BYTE L5ConvTbl[16] = { 22, 13, 1, 13, 2, 13, 13, 13, 4, 13, 1, 13, 2, 13, 16, 13 }; -void DRLG_Init_Globals() -{ - char c; - - memset(dFlags, 0, sizeof(dFlags)); - memset(dPlayer, 0, sizeof(dPlayer)); - memset(dMonster, 0, sizeof(dMonster)); - memset(dDead, 0, sizeof(dDead)); - memset(dObject, 0, sizeof(dObject)); - memset(dItem, 0, sizeof(dItem)); - memset(dMissile, 0, sizeof(dMissile)); - memset(dArch, 0, sizeof(dArch)); - if (!lightflag) { - if (light4flag) - c = 3; - else - c = 15; - } else { - c = 0; - } - memset(dLight, c, sizeof(dLight)); -} - -#ifndef SPAWN -void LoadL1Dungeon(char *sFileName, int vx, int vy) -{ - int i, j, rw, rh; - BYTE *pLevelMap, *lm; - - dminx = 16; - dminy = 16; - dmaxx = 96; - dmaxy = 96; - - DRLG_InitTrans(); - pLevelMap = LoadFileInMem(sFileName, NULL); - - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - dungeon[i][j] = 22; - L5dflags[i][j] = 0; - } - } - - lm = pLevelMap; - rw = *lm; - lm += 2; - rh = *lm; - lm += 2; - - for (j = 0; j < rh; j++) { - for (i = 0; i < rw; i++) { - if (*lm != 0) { - dungeon[i][j] = *lm; - L5dflags[i][j] |= DLRG_PROTECTED; - } else { - dungeon[i][j] = 13; - } - lm += 2; - } - } - - DRLG_L1Floor(); - ViewX = vx; - ViewY = vy; - DRLG_L1Pass3(); - DRLG_Init_Globals(); - DRLG_InitL1Vals(); - SetMapMonsters(pLevelMap, 0, 0); - SetMapObjects(pLevelMap, 0, 0); - mem_free_dbg(pLevelMap); -} -#endif - -void DRLG_L1Floor() -{ - int i, j; - LONG rv; - - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - if (L5dflags[i][j] == 0 && dungeon[i][j] == 13) { - rv = random(0, 3); - - if (rv == 1) - dungeon[i][j] = 162; - if (rv == 2) - dungeon[i][j] = 163; - } - } - } -} - -void DRLG_L1Pass3() -{ - int i, j, xx, yy; - long v1, v2, v3, v4, lv; - - lv = 22 - 1; - -#ifdef USE_ASM - __asm { - mov esi, pMegaTiles - mov eax, lv - shl eax, 3 - add esi, eax - xor eax, eax - lodsw - inc eax - mov v1, eax - lodsw - inc eax - mov v2, eax - lodsw - inc eax - mov v3, eax - lodsw - inc eax - mov v4, eax - } -#else - v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1; - v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; - v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; - v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; -#endif - - for (j = 0; j < MAXDUNY; j += 2) - { - for (i = 0; i < MAXDUNX; i += 2) { - dPiece[i][j] = v1; - dPiece[i + 1][j] = v2; - dPiece[i][j + 1] = v3; - dPiece[i + 1][j + 1] = v4; - } - } - - yy = 16; - for (j = 0; j < DMAXY; j++) { - xx = 16; - for (i = 0; i < DMAXX; i++) { - lv = dungeon[i][j] - 1; - /// ASSERT: assert(lv >= 0); -#ifdef USE_ASM - __asm { - mov esi, pMegaTiles - mov eax, lv - shl eax, 3 - add esi, eax - xor eax, eax - lodsw - inc eax - mov v1, eax - lodsw - inc eax - mov v2, eax - lodsw - inc eax - mov v3, eax - lodsw - inc eax - mov v4, eax - } -#else - v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1; - v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; - v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; - v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; -#endif - dPiece[xx][yy] = v1; - dPiece[xx + 1][yy] = v2; - dPiece[xx][yy + 1] = v3; - dPiece[xx + 1][yy + 1] = v4; - xx += 2; - } - yy += 2; - } -} - -void DRLG_InitL1Vals() -{ - int i, j, pc; - - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) { - if (dPiece[i][j] == 12) { - pc = 1; - } else if (dPiece[i][j] == 11) { - pc = 2; - } else if (dPiece[i][j] == 71) { - pc = 1; - } else if (dPiece[i][j] == 259) { - pc = 5; - } else if (dPiece[i][j] == 249) { - pc = 2; - } else if (dPiece[i][j] == 325) { - pc = 2; - } else if (dPiece[i][j] == 321) { - pc = 1; - } else if (dPiece[i][j] == 255) { - pc = 4; - } else if (dPiece[i][j] == 211) { - pc = 1; - } else if (dPiece[i][j] == 344) { - pc = 2; - } else if (dPiece[i][j] == 341) { - pc = 1; - } else if (dPiece[i][j] == 331) { - pc = 2; - } else if (dPiece[i][j] == 418) { - pc = 1; - } else if (dPiece[i][j] == 421) { - pc = 2; - } else { - continue; - } - dArch[i][j] = pc; - } - } -} - -#ifndef SPAWN -void LoadPreL1Dungeon(char *sFileName, int vx, int vy) -{ - int i, j, rw, rh; - BYTE *pLevelMap, *lm; - - dminx = 16; - dminy = 16; - dmaxx = 96; - dmaxy = 96; - - pLevelMap = LoadFileInMem(sFileName, NULL); - - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - dungeon[i][j] = 22; - L5dflags[i][j] = 0; - } - } - - lm = pLevelMap; - rw = *lm; - lm += 2; - rh = *lm; - lm += 2; - - for (j = 0; j < rh; j++) { - for (i = 0; i < rw; i++) { - if (*lm != 0) { - dungeon[i][j] = *lm; - L5dflags[i][j] |= DLRG_PROTECTED; - } else { - dungeon[i][j] = 13; - } - lm += 2; - } - } - - DRLG_L1Floor(); - - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - pdungeon[i][j] = dungeon[i][j]; - } - } - - mem_free_dbg(pLevelMap); -} -#endif - -void CreateL5Dungeon(DWORD rseed, int entry) -{ - SetRndSeed(rseed); - - dminx = 16; - dminy = 16; - dmaxx = 96; - dmaxy = 96; - - DRLG_InitTrans(); - DRLG_InitSetPC(); - DRLG_LoadL1SP(); - DRLG_L5(entry); - DRLG_L1Pass3(); - DRLG_FreeL1SP(); - DRLG_InitL1Vals(); - DRLG_SetPC(); -} - -void DRLG_LoadL1SP() -{ - setloadflag = FALSE; - if (QuestStatus(QTYPE_BUTCH)) { - pSetPiece = LoadFileInMem("Levels\\L1Data\\rnd6.DUN", NULL); - setloadflag = TRUE; - } - if (QuestStatus(QTYPE_KING) && gbMaxPlayers == 1) { - pSetPiece = LoadFileInMem("Levels\\L1Data\\SKngDO.DUN", NULL); - setloadflag = TRUE; - } - if (QuestStatus(QTYPE_BOL)) { - pSetPiece = LoadFileInMem("Levels\\L1Data\\Banner2.DUN", NULL); - setloadflag = TRUE; - } -} - -void DRLG_FreeL1SP() -{ - MemFreeDbg(pSetPiece); -} - -void DRLG_L5(int entry) -{ - int i, j; - LONG minarea; - BOOL doneflag; - - switch (currlevel) { - case 1: - minarea = 533; - break; - case 2: - minarea = 693; - break; - case 3: - case 4: - minarea = 761; - break; - } - - do { - DRLG_InitTrans(); - - do { - InitL5Dungeon(); - L5firstRoom(); - } while (L5GetArea() < minarea); - - L5makeDungeon(); - L5makeDmt(); - L5FillChambers(); - L5tileFix(); - L5AddWall(); - L5ClearFlags(); - DRLG_L5FloodTVal(); - - doneflag = TRUE; - - if (QuestStatus(QTYPE_PW)) { - if (entry == 0) { - if (DRLG_PlaceMiniSet(PWATERIN, 1, 1, 0, 0, 1, -1, 0) < 0) - doneflag = FALSE; - } else { - if (DRLG_PlaceMiniSet(PWATERIN, 1, 1, 0, 0, 0, -1, 0) < 0) - doneflag = FALSE; - ViewY--; - } - } - if (QuestStatus(QTYPE_BOL)) { - if (entry == 0) { - if (DRLG_PlaceMiniSet(STAIRSUP, 1, 1, 0, 0, 1, -1, 0) < 0) - doneflag = FALSE; - } else { - if (DRLG_PlaceMiniSet(STAIRSUP, 1, 1, 0, 0, 0, -1, 0) < 0) - doneflag = FALSE; - if (entry == 1) { - ViewX = 2 * setpc_x + 20; - ViewY = 2 * setpc_y + 28; - } else { - ViewY--; - } - } - } else if (entry == 0) { - if (DRLG_PlaceMiniSet(L5STAIRSUP, 1, 1, 0, 0, 1, -1, 0) < 0) - doneflag = FALSE; - else if (DRLG_PlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, 0, -1, 1) < 0) - doneflag = FALSE; - } else { - if (DRLG_PlaceMiniSet(L5STAIRSUP, 1, 1, 0, 0, 0, -1, 0) < 0) - doneflag = FALSE; - else if (DRLG_PlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, 1, -1, 1) < 0) - doneflag = FALSE; - ViewY--; - } - } while (doneflag == FALSE); - - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - if (dungeon[i][j] == 64) { - int xx = 2 * i + 16; /* todo: fix loop */ - int yy = 2 * j + 16; - DRLG_CopyTrans(xx, yy + 1, xx, yy); - DRLG_CopyTrans(xx + 1, yy + 1, xx + 1, yy); - } - } - } - - DRLG_L5TransFix(); - DRLG_L5DirtFix(); - DRLG_L5CornerFix(); - - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - if (L5dflags[i][j] & 0x7F) - DRLG_PlaceDoor(i, j); - } - } - - DRLG_L5Subs(); - DRLG_L1Shadows(); - DRLG_PlaceMiniSet(LAMPS, 5, 10, 0, 0, 0, -1, 4); - DRLG_L1Floor(); - - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - pdungeon[i][j] = dungeon[i][j]; - } - } - - DRLG_Init_Globals(); - DRLG_CheckQuests(setpc_x, setpc_y); -} - -void DRLG_PlaceDoor(int x, int y) +static void DRLG_PlaceDoor(int x, int y) { if ((L5dflags[x][y] & DLRG_PROTECTED) == 0) { BYTE df = L5dflags[x][y] & 0x7F; @@ -591,7 +167,7 @@ void DRLG_PlaceDoor(int x, int y) L5dflags[x][y] = DLRG_PROTECTED; } -void DRLG_L1Shadows() +static void DRLG_L1Shadows() { int x, y, i; BYTE sd[2][2]; @@ -681,7 +257,7 @@ void DRLG_L1Shadows() } } -int DRLG_PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, BOOL setview, int noquad, int ldir) +static int DRLG_PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, BOOL setview, int noquad, int ldir) { int xx, yy, sx, sy; int ii, i, t, found; @@ -744,59 +320,350 @@ int DRLG_PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, B } } - if (abort == FALSE) { - if (++sx == DMAXX - sw) { - sx = 0; - if (++sy == DMAXY - sh) - sy = 0; - } - if (++found > 4000) - return -1; - } + if (abort == FALSE) { + if (++sx == DMAXX - sw) { + sx = 0; + if (++sy == DMAXY - sh) + sy = 0; + } + if (++found > 4000) + return -1; + } + } + + ii = sw * sh + 2; + + for (yy = 0; yy < sh; yy++) { + for (xx = 0; xx < sw; xx++) { + if (miniset[ii]) + dungeon[xx + sx][sy + yy] = miniset[ii]; + ii++; + } + } + } + + if (miniset == PWATERIN) { + t = TransVal; + TransVal = 0; + DRLG_MRectTrans(sx, sy + 2, sx + 5, sy + 4); + TransVal = t; + + quests[QTYPE_PW]._qtx = 2 * sx + 21; + quests[QTYPE_PW]._qty = 2 * sy + 22; + } + + if (setview == TRUE) { + ViewX = 2 * sx + 19; + ViewY = 2 * sy + 20; + } + + if (ldir == 0) { + LvlViewX = 2 * sx + 19; + LvlViewY = 2 * sy + 20; + } + + if (sx < cx && sy < cy) + return 0; + if (sx > cx && sy < cy) + return 1; + if (sx < cx && sy > cy) + return 2; + else + return 3; +} + +static void DRLG_L1Floor() +{ + int i, j; + LONG rv; + + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + if (L5dflags[i][j] == 0 && dungeon[i][j] == 13) { + rv = random(0, 3); + + if (rv == 1) + dungeon[i][j] = 162; + if (rv == 2) + dungeon[i][j] = 163; + } + } + } +} + +static void DRLG_L1Pass3() +{ + int i, j, xx, yy; + long v1, v2, v3, v4, lv; + + lv = 22 - 1; + +#ifdef USE_ASM + __asm { + mov esi, pMegaTiles + mov eax, lv + shl eax, 3 + add esi, eax + xor eax, eax + lodsw + inc eax + mov v1, eax + lodsw + inc eax + mov v2, eax + lodsw + inc eax + mov v3, eax + lodsw + inc eax + mov v4, eax + } +#else + v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1; + v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; + v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; + v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; +#endif + + for (j = 0; j < MAXDUNY; j += 2) + { + for (i = 0; i < MAXDUNX; i += 2) { + dPiece[i][j] = v1; + dPiece[i + 1][j] = v2; + dPiece[i][j + 1] = v3; + dPiece[i + 1][j + 1] = v4; + } + } + + yy = 16; + for (j = 0; j < DMAXY; j++) { + xx = 16; + for (i = 0; i < DMAXX; i++) { + lv = dungeon[i][j] - 1; + /// ASSERT: assert(lv >= 0); +#ifdef USE_ASM + __asm { + mov esi, pMegaTiles + mov eax, lv + shl eax, 3 + add esi, eax + xor eax, eax + lodsw + inc eax + mov v1, eax + lodsw + inc eax + mov v2, eax + lodsw + inc eax + mov v3, eax + lodsw + inc eax + mov v4, eax + } +#else + v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1; + v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1; + v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1; + v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1; +#endif + dPiece[xx][yy] = v1; + dPiece[xx + 1][yy] = v2; + dPiece[xx][yy + 1] = v3; + dPiece[xx + 1][yy + 1] = v4; + xx += 2; + } + yy += 2; + } +} + +static void DRLG_LoadL1SP() +{ + setloadflag = FALSE; + if (QuestStatus(QTYPE_BUTCH)) { + pSetPiece = LoadFileInMem("Levels\\L1Data\\rnd6.DUN", NULL); + setloadflag = TRUE; + } + if (QuestStatus(QTYPE_KING) && gbMaxPlayers == 1) { + pSetPiece = LoadFileInMem("Levels\\L1Data\\SKngDO.DUN", NULL); + setloadflag = TRUE; + } + if (QuestStatus(QTYPE_BOL)) { + pSetPiece = LoadFileInMem("Levels\\L1Data\\Banner2.DUN", NULL); + setloadflag = TRUE; + } +} + +static void DRLG_FreeL1SP() +{ + MemFreeDbg(pSetPiece); +} + +void DRLG_Init_Globals() +{ + char c; + + memset(dFlags, 0, sizeof(dFlags)); + memset(dPlayer, 0, sizeof(dPlayer)); + memset(dMonster, 0, sizeof(dMonster)); + memset(dDead, 0, sizeof(dDead)); + memset(dObject, 0, sizeof(dObject)); + memset(dItem, 0, sizeof(dItem)); + memset(dMissile, 0, sizeof(dMissile)); + memset(dArch, 0, sizeof(dArch)); + if (!lightflag) { + if (light4flag) + c = 3; + else + c = 15; + } else { + c = 0; + } + memset(dLight, c, sizeof(dLight)); +} + +static void DRLG_InitL1Vals() +{ + int i, j, pc; + + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) { + if (dPiece[i][j] == 12) { + pc = 1; + } else if (dPiece[i][j] == 11) { + pc = 2; + } else if (dPiece[i][j] == 71) { + pc = 1; + } else if (dPiece[i][j] == 259) { + pc = 5; + } else if (dPiece[i][j] == 249) { + pc = 2; + } else if (dPiece[i][j] == 325) { + pc = 2; + } else if (dPiece[i][j] == 321) { + pc = 1; + } else if (dPiece[i][j] == 255) { + pc = 4; + } else if (dPiece[i][j] == 211) { + pc = 1; + } else if (dPiece[i][j] == 344) { + pc = 2; + } else if (dPiece[i][j] == 341) { + pc = 1; + } else if (dPiece[i][j] == 331) { + pc = 2; + } else if (dPiece[i][j] == 418) { + pc = 1; + } else if (dPiece[i][j] == 421) { + pc = 2; + } else { + continue; + } + dArch[i][j] = pc; + } + } +} + +#ifndef SPAWN +void LoadL1Dungeon(char *sFileName, int vx, int vy) +{ + int i, j, rw, rh; + BYTE *pLevelMap, *lm; + + dminx = 16; + dminy = 16; + dmaxx = 96; + dmaxy = 96; + + DRLG_InitTrans(); + pLevelMap = LoadFileInMem(sFileName, NULL); + + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + dungeon[i][j] = 22; + L5dflags[i][j] = 0; } + } - ii = sw * sh + 2; + lm = pLevelMap; + rw = *lm; + lm += 2; + rh = *lm; + lm += 2; - for (yy = 0; yy < sh; yy++) { - for (xx = 0; xx < sw; xx++) { - if (miniset[ii]) - dungeon[xx + sx][sy + yy] = miniset[ii]; - ii++; + for (j = 0; j < rh; j++) { + for (i = 0; i < rw; i++) { + if (*lm != 0) { + dungeon[i][j] = *lm; + L5dflags[i][j] |= DLRG_PROTECTED; + } else { + dungeon[i][j] = 13; } + lm += 2; } } - if (miniset == PWATERIN) { - t = TransVal; - TransVal = 0; - DRLG_MRectTrans(sx, sy + 2, sx + 5, sy + 4); - TransVal = t; + DRLG_L1Floor(); + ViewX = vx; + ViewY = vy; + DRLG_L1Pass3(); + DRLG_Init_Globals(); + DRLG_InitL1Vals(); + SetMapMonsters(pLevelMap, 0, 0); + SetMapObjects(pLevelMap, 0, 0); + mem_free_dbg(pLevelMap); +} - quests[QTYPE_PW]._qtx = 2 * sx + 21; - quests[QTYPE_PW]._qty = 2 * sy + 22; +void LoadPreL1Dungeon(char *sFileName, int vx, int vy) +{ + int i, j, rw, rh; + BYTE *pLevelMap, *lm; + + dminx = 16; + dminy = 16; + dmaxx = 96; + dmaxy = 96; + + pLevelMap = LoadFileInMem(sFileName, NULL); + + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + dungeon[i][j] = 22; + L5dflags[i][j] = 0; + } } - if (setview == TRUE) { - ViewX = 2 * sx + 19; - ViewY = 2 * sy + 20; + lm = pLevelMap; + rw = *lm; + lm += 2; + rh = *lm; + lm += 2; + + for (j = 0; j < rh; j++) { + for (i = 0; i < rw; i++) { + if (*lm != 0) { + dungeon[i][j] = *lm; + L5dflags[i][j] |= DLRG_PROTECTED; + } else { + dungeon[i][j] = 13; + } + lm += 2; + } } - if (ldir == 0) { - LvlViewX = 2 * sx + 19; - LvlViewY = 2 * sy + 20; + DRLG_L1Floor(); + + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + pdungeon[i][j] = dungeon[i][j]; + } } - if (sx < cx && sy < cy) - return 0; - if (sx > cx && sy < cy) - return 1; - if (sx < cx && sy > cy) - return 2; - else - return 3; + mem_free_dbg(pLevelMap); } +#endif -void InitL5Dungeon() +static void InitL5Dungeon() { int i, j; @@ -808,7 +675,7 @@ void InitL5Dungeon() } } -void L5ClearFlags() +static void L5ClearFlags() { int i, j; @@ -819,108 +686,34 @@ void L5ClearFlags() } } -void L5firstRoom() +static void L5drawRoom(int x, int y, int w, int h) { - int ys, ye, y; - int xs, xe, x; - - if (random(0, 2) == 0) { - ys = 1; - ye = DMAXY - 1; - - VR1 = random(0, 2); - VR2 = random(0, 2); - VR3 = random(0, 2); - - if (VR1 + VR3 <= 1) - VR2 = 1; - if (VR1) - L5drawRoom(15, 1, 10, 10); - else - ys = 18; - - if (VR2) - L5drawRoom(15, 15, 10, 10); - if (VR3) - L5drawRoom(15, 29, 10, 10); - else - ye = 22; - - for (y = ys; y < ye; y++) { - dungeon[17][y] = 1; - dungeon[18][y] = 1; - dungeon[19][y] = 1; - dungeon[20][y] = 1; - dungeon[21][y] = 1; - dungeon[22][y] = 1; - } - - if (VR1) - L5roomGen(15, 1, 10, 10, 0); - if (VR2) - L5roomGen(15, 15, 10, 10, 0); - if (VR3) - L5roomGen(15, 29, 10, 10, 0); - - HR3 = 0; - HR2 = 0; - HR1 = 0; - } else { - xs = 1; - xe = DMAXX - 1; - - HR1 = random(0, 2); - HR2 = random(0, 2); - HR3 = random(0, 2); - - if (HR1 + HR3 <= 1) - HR2 = 1; - if (HR1) - L5drawRoom(1, 15, 10, 10); - else - xs = 18; - - if (HR2) - L5drawRoom(15, 15, 10, 10); - if (HR3) - L5drawRoom(29, 15, 10, 10); - else - xe = 22; + int i, j; - for (x = xs; x < xe; x++) { - dungeon[x][17] = 1; - dungeon[x][18] = 1; - dungeon[x][19] = 1; - dungeon[x][20] = 1; - dungeon[x][21] = 1; - dungeon[x][22] = 1; + for (j = 0; j < h; j++) { + for (i = 0; i < w; i++) { + dungeon[x + i][y + j] = 1; } - - if (HR1) - L5roomGen(1, 15, 10, 10, 1); - if (HR2) - L5roomGen(15, 15, 10, 10, 1); - if (HR3) - L5roomGen(29, 15, 10, 10, 1); - - VR3 = 0; - VR2 = 0; - VR1 = 0; } } -void L5drawRoom(int x, int y, int w, int h) +static BOOL L5checkRoom(int x, int y, int width, int height) { int i, j; - for (j = 0; j < h; j++) { - for (i = 0; i < w; i++) { - dungeon[x + i][y + j] = 1; + for (j = 0; j < height; j++) { + for (i = 0; i < width; i++) { + if (i + x < 0 || i + x >= DMAXX || j + y < 0 || j + y >= DMAXY) + return FALSE; + if (dungeon[i + x][j + y]) + return FALSE; } } + + return TRUE; } -void L5roomGen(int x, int y, int w, int h, int dir) +static void L5roomGen(int x, int y, int w, int h, int dir) { int num, dirProb; BOOL ran, ran2; @@ -963,37 +756,111 @@ void L5roomGen(int x, int y, int w, int h, int dir) num++; } while (ran == FALSE && num < 20); - if (ran == TRUE) - L5drawRoom(rx, ry, width, height); - ry2 = y + h; - ran2 = L5checkRoom(rx - 1, ry2, width + 2, height + 1); - if (ran2 == TRUE) - L5drawRoom(rx, ry2, width, height); - if (ran == TRUE) - L5roomGen(rx, ry, width, height, 0); - if (ran2 == TRUE) - L5roomGen(rx, ry2, width, height, 0); - break; - } -} + if (ran == TRUE) + L5drawRoom(rx, ry, width, height); + ry2 = y + h; + ran2 = L5checkRoom(rx - 1, ry2, width + 2, height + 1); + if (ran2 == TRUE) + L5drawRoom(rx, ry2, width, height); + if (ran == TRUE) + L5roomGen(rx, ry, width, height, 0); + if (ran2 == TRUE) + L5roomGen(rx, ry2, width, height, 0); + break; + } +} + +static void L5firstRoom() +{ + int ys, ye, y; + int xs, xe, x; + + if (random(0, 2) == 0) { + ys = 1; + ye = DMAXY - 1; + + VR1 = random(0, 2); + VR2 = random(0, 2); + VR3 = random(0, 2); + + if (VR1 + VR3 <= 1) + VR2 = 1; + if (VR1) + L5drawRoom(15, 1, 10, 10); + else + ys = 18; + + if (VR2) + L5drawRoom(15, 15, 10, 10); + if (VR3) + L5drawRoom(15, 29, 10, 10); + else + ye = 22; + + for (y = ys; y < ye; y++) { + dungeon[17][y] = 1; + dungeon[18][y] = 1; + dungeon[19][y] = 1; + dungeon[20][y] = 1; + dungeon[21][y] = 1; + dungeon[22][y] = 1; + } + + if (VR1) + L5roomGen(15, 1, 10, 10, 0); + if (VR2) + L5roomGen(15, 15, 10, 10, 0); + if (VR3) + L5roomGen(15, 29, 10, 10, 0); -BOOL L5checkRoom(int x, int y, int width, int height) -{ - int i, j; + HR3 = 0; + HR2 = 0; + HR1 = 0; + } else { + xs = 1; + xe = DMAXX - 1; - for (j = 0; j < height; j++) { - for (i = 0; i < width; i++) { - if (i + x < 0 || i + x >= DMAXX || j + y < 0 || j + y >= DMAXY) - return FALSE; - if (dungeon[i + x][j + y]) - return FALSE; + HR1 = random(0, 2); + HR2 = random(0, 2); + HR3 = random(0, 2); + + if (HR1 + HR3 <= 1) + HR2 = 1; + if (HR1) + L5drawRoom(1, 15, 10, 10); + else + xs = 18; + + if (HR2) + L5drawRoom(15, 15, 10, 10); + if (HR3) + L5drawRoom(29, 15, 10, 10); + else + xe = 22; + + for (x = xs; x < xe; x++) { + dungeon[x][17] = 1; + dungeon[x][18] = 1; + dungeon[x][19] = 1; + dungeon[x][20] = 1; + dungeon[x][21] = 1; + dungeon[x][22] = 1; } - } - return TRUE; + if (HR1) + L5roomGen(1, 15, 10, 10, 1); + if (HR2) + L5roomGen(15, 15, 10, 10, 1); + if (HR3) + L5roomGen(29, 15, 10, 10, 1); + + VR3 = 0; + VR2 = 0; + VR1 = 0; + } } -int L5GetArea() +static int L5GetArea() { int i, j; int rv; @@ -1010,7 +877,7 @@ int L5GetArea() return rv; } -void L5makeDungeon() +static void L5makeDungeon() { int i, j; int i_2, j_2; @@ -1027,7 +894,7 @@ void L5makeDungeon() } } -void L5makeDmt() +static void L5makeDmt() { int i, j, dmtx, dmty; @@ -1048,49 +915,7 @@ void L5makeDmt() } } -void L5AddWall() -{ - int i, j, x, y; - - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - if (!L5dflags[i][j]) { - if (dungeon[i][j] == 3 && random(0, 100) < 100) { - x = L5HWallOk(i, j); - if (x != -1) - L5HorizWall(i, j, 2, x); - } - if (dungeon[i][j] == 3 && random(0, 100) < 100) { - y = L5VWallOk(i, j); - if (y != -1) - L5VertWall(i, j, 1, y); - } - if (dungeon[i][j] == 6 && random(0, 100) < 100) { - x = L5HWallOk(i, j); - if (x != -1) - L5HorizWall(i, j, 4, x); - } - if (dungeon[i][j] == 7 && random(0, 100) < 100) { - y = L5VWallOk(i, j); - if (y != -1) - L5VertWall(i, j, 4, y); - } - if (dungeon[i][j] == 2 && random(0, 100) < 100) { - x = L5HWallOk(i, j); - if (x != -1) - L5HorizWall(i, j, 2, x); - } - if (dungeon[i][j] == 1 && random(0, 100) < 100) { - y = L5VWallOk(i, j); - if (y != -1) - L5VertWall(i, j, 1, y); - } - } - } - } -} - -int L5HWallOk(int i, int j) +static int L5HWallOk(int i, int j) { int x; BOOL wallok; @@ -1116,7 +941,7 @@ int L5HWallOk(int i, int j) return -1; } -int L5VWallOk(int i, int j) +static int L5VWallOk(int i, int j) { int y; BOOL wallok; @@ -1142,7 +967,7 @@ int L5VWallOk(int i, int j) return -1; } -void L5HorizWall(int i, int j, char p, int dx) +static void L5HorizWall(int i, int j, char p, int dx) { int xx; char wt, dt; @@ -1181,66 +1006,183 @@ void L5HorizWall(int i, int j, char p, int dx) dungeon[i + xx][j] = dt; } - xx = random(0, dx - 1) + 1; - - if (wt == 12) { - dungeon[i + xx][j] = wt; - } else { - dungeon[i + xx][j] = 2; - L5dflags[i + xx][j] |= DLRG_HDOOR; + xx = random(0, dx - 1) + 1; + + if (wt == 12) { + dungeon[i + xx][j] = wt; + } else { + dungeon[i + xx][j] = 2; + L5dflags[i + xx][j] |= DLRG_HDOOR; + } +} + +static void L5VertWall(int i, int j, char p, int dy) +{ + int yy; + char wt, dt; + + switch (random(0, 4)) { + case 0: + case 1: + dt = 1; + break; + case 2: + dt = 11; + if (p == 1) + p = 11; + if (p == 4) + p = 14; + break; + case 3: + dt = 35; + if (p == 1) + p = 35; + if (p == 4) + p = 37; + break; + } + + if (random(0, 6) == 5) + wt = 11; + else + wt = 25; + if (dt == 11) + wt = 11; + + dungeon[i][j] = p; + + for (yy = 1; yy < dy; yy++) { + dungeon[i][j + yy] = dt; + } + + yy = random(0, dy - 1) + 1; + + if (wt == 11) { + dungeon[i][j + yy] = wt; + } else { + dungeon[i][j + yy] = 1; + L5dflags[i][j + yy] |= DLRG_VDOOR; + } +} + +static void L5AddWall() +{ + int i, j, x, y; + + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + if (!L5dflags[i][j]) { + if (dungeon[i][j] == 3 && random(0, 100) < 100) { + x = L5HWallOk(i, j); + if (x != -1) + L5HorizWall(i, j, 2, x); + } + if (dungeon[i][j] == 3 && random(0, 100) < 100) { + y = L5VWallOk(i, j); + if (y != -1) + L5VertWall(i, j, 1, y); + } + if (dungeon[i][j] == 6 && random(0, 100) < 100) { + x = L5HWallOk(i, j); + if (x != -1) + L5HorizWall(i, j, 4, x); + } + if (dungeon[i][j] == 7 && random(0, 100) < 100) { + y = L5VWallOk(i, j); + if (y != -1) + L5VertWall(i, j, 4, y); + } + if (dungeon[i][j] == 2 && random(0, 100) < 100) { + x = L5HWallOk(i, j); + if (x != -1) + L5HorizWall(i, j, 2, x); + } + if (dungeon[i][j] == 1 && random(0, 100) < 100) { + y = L5VWallOk(i, j); + if (y != -1) + L5VertWall(i, j, 1, y); + } + } + } + } +} + +static void DRLG_L5GChamber(int sx, int sy, BOOL topflag, BOOL bottomflag, BOOL leftflag, BOOL rightflag) +{ + int i, j; + + if (topflag == TRUE) { + dungeon[sx + 2][sy] = 12; + dungeon[sx + 3][sy] = 12; + dungeon[sx + 4][sy] = 3; + dungeon[sx + 7][sy] = 9; + dungeon[sx + 8][sy] = 12; + dungeon[sx + 9][sy] = 2; + } + if (bottomflag == TRUE) { + sy += 11; + dungeon[sx + 2][sy] = 10; + dungeon[sx + 3][sy] = 12; + dungeon[sx + 4][sy] = 8; + dungeon[sx + 7][sy] = 5; + dungeon[sx + 8][sy] = 12; + if (dungeon[sx + 9][sy] != 4) { + dungeon[sx + 9][sy] = 21; + } + sy -= 11; + } + if (leftflag == TRUE) { + dungeon[sx][sy + 2] = 11; + dungeon[sx][sy + 3] = 11; + dungeon[sx][sy + 4] = 3; + dungeon[sx][sy + 7] = 8; + dungeon[sx][sy + 8] = 11; + dungeon[sx][sy + 9] = 1; + } + if (rightflag == TRUE) { + sx += 11; + dungeon[sx][sy + 2] = 14; + dungeon[sx][sy + 3] = 11; + dungeon[sx][sy + 4] = 9; + dungeon[sx][sy + 7] = 5; + dungeon[sx][sy + 8] = 11; + if (dungeon[sx][sy + 9] != 4) { + dungeon[sx][sy + 9] = 21; + } + sx -= 11; + } + + for (j = 1; j < 11; j++) { + for (i = 1; i < 11; i++) { + dungeon[i + sx][j + sy] = 13; + L5dflags[i + sx][j + sy] |= DLRG_CHAMBER; + } } + + dungeon[sx + 4][sy + 4] = 15; + dungeon[sx + 7][sy + 4] = 15; + dungeon[sx + 4][sy + 7] = 15; + dungeon[sx + 7][sy + 7] = 15; } -void L5VertWall(int i, int j, char p, int dy) +static void DRLG_L5GHall(int x1, int y1, int x2, int y2) { - int yy; - char wt, dt; - - switch (random(0, 4)) { - case 0: - case 1: - dt = 1; - break; - case 2: - dt = 11; - if (p == 1) - p = 11; - if (p == 4) - p = 14; - break; - case 3: - dt = 35; - if (p == 1) - p = 35; - if (p == 4) - p = 37; - break; - } - - if (random(0, 6) == 5) - wt = 11; - else - wt = 25; - if (dt == 11) - wt = 11; - - dungeon[i][j] = p; - - for (yy = 1; yy < dy; yy++) { - dungeon[i][j + yy] = dt; - } - - yy = random(0, dy - 1) + 1; + int i; - if (wt == 11) { - dungeon[i][j + yy] = wt; + if (y1 == y2) { + for (i = x1; i < x2; i++) { + dungeon[i][y1] = 12; + dungeon[i][y1 + 3] = 12; + } } else { - dungeon[i][j + yy] = 1; - L5dflags[i][j + yy] |= DLRG_VDOOR; + for (i = y1; i < y2; i++) { + dungeon[x1][i] = 11; + dungeon[x1 + 3][i] = 11; + } } } -void L5tileFix() +static void L5tileFix() { int i, j; @@ -1348,7 +1290,7 @@ void L5tileFix() } } -void DRLG_L5Subs() +static void DRLG_L5Subs() { int x, y, rv, i; @@ -1387,7 +1329,35 @@ void DRLG_L5Subs() } } -void L5FillChambers() +static void DRLG_L5SetRoom(int rx1, int ry1) +{ + int rw, rh, i, j; + BYTE *sp; + + rw = *pSetPiece; + rh = *(pSetPiece + 2); + + setpc_x = rx1; + setpc_y = ry1; + setpc_w = rw; + setpc_h = rh; + + sp = pSetPiece + 4; + + for (j = 0; j < rh; j++) { + for (i = 0; i < rw; i++) { + if (*sp) { + dungeon[rx1 + i][ry1 + j] = *sp; + L5dflags[rx1 + i][ry1 + j] |= DLRG_PROTECTED; + } else { + dungeon[rx1 + i][ry1 + j] = 13; + } + sp += 2; + } + } +} + +static void L5FillChambers() { int c; @@ -1409,218 +1379,95 @@ void L5FillChambers() DRLG_L5GChamber(28, 14, 0, 0, 1, 0); if (HR1 && HR2) DRLG_L5GHall(12, 18, 14, 18); - if (HR2 && HR3) - DRLG_L5GHall(26, 18, 28, 18); - if (HR1 && !HR2 && HR3) - DRLG_L5GHall(12, 18, 28, 18); - if (VR1) - DRLG_L5GChamber(14, 0, 0, 1, 0, 0); - - if (VR2) { - if (VR1 && !VR3) - DRLG_L5GChamber(14, 14, 1, 0, 0, 0); - if (!VR1 && VR3) - DRLG_L5GChamber(14, 14, 0, 1, 0, 0); - if (VR1 && VR3) - DRLG_L5GChamber(14, 14, 1, 1, 0, 0); - if (!VR1 && !VR3) - DRLG_L5GChamber(14, 14, 0, 0, 0, 0); - } - - if (VR3) - DRLG_L5GChamber(14, 28, 1, 0, 0, 0); - if (VR1 && VR2) - DRLG_L5GHall(18, 12, 18, 14); - if (VR2 && VR3) - DRLG_L5GHall(18, 26, 18, 28); - if (VR1 && !VR2 && VR3) - DRLG_L5GHall(18, 12, 18, 28); - - if (setloadflag) { - if (VR1 || VR2 || VR3) { - c = 1; - if (!VR1 && VR2 && VR3 && random(0, 2)) - c = 2; - if (VR1 && VR2 && !VR3 && random(0, 2)) - c = 0; - - if (VR1 && !VR2 && VR3) { - if (random(0, 2)) - c = 0; - else - c = 2; - } - - if (VR1 && VR2 && VR3) - c = random(0, 3); - - switch (c) { - case 0: - DRLG_L5SetRoom(16, 2); - break; - case 1: - DRLG_L5SetRoom(16, 16); - break; - case 2: - DRLG_L5SetRoom(16, 30); - break; - } - } else { - c = 1; - if (!HR1 && HR2 && HR3 && random(0, 2)) - c = 2; - if (HR1 && HR2 && !HR3 && random(0, 2)) - c = 0; - - if (HR1 && !HR2 && HR3) { - if (random(0, 2)) - c = 0; - else - c = 2; - } - - if (HR1 && HR2 && HR3) - c = random(0, 3); - - switch (c) { - case 0: - DRLG_L5SetRoom(2, 16); - break; - case 1: - DRLG_L5SetRoom(16, 16); - break; - case 2: - DRLG_L5SetRoom(30, 16); - break; - } - } - } -} - -void DRLG_L5GChamber(int sx, int sy, BOOL topflag, BOOL bottomflag, BOOL leftflag, BOOL rightflag) -{ - int i, j; - - if (topflag == TRUE) { - dungeon[sx + 2][sy] = 12; - dungeon[sx + 3][sy] = 12; - dungeon[sx + 4][sy] = 3; - dungeon[sx + 7][sy] = 9; - dungeon[sx + 8][sy] = 12; - dungeon[sx + 9][sy] = 2; - } - if (bottomflag == TRUE) { - sy += 11; - dungeon[sx + 2][sy] = 10; - dungeon[sx + 3][sy] = 12; - dungeon[sx + 4][sy] = 8; - dungeon[sx + 7][sy] = 5; - dungeon[sx + 8][sy] = 12; - if (dungeon[sx + 9][sy] != 4) { - dungeon[sx + 9][sy] = 21; - } - sy -= 11; - } - if (leftflag == TRUE) { - dungeon[sx][sy + 2] = 11; - dungeon[sx][sy + 3] = 11; - dungeon[sx][sy + 4] = 3; - dungeon[sx][sy + 7] = 8; - dungeon[sx][sy + 8] = 11; - dungeon[sx][sy + 9] = 1; - } - if (rightflag == TRUE) { - sx += 11; - dungeon[sx][sy + 2] = 14; - dungeon[sx][sy + 3] = 11; - dungeon[sx][sy + 4] = 9; - dungeon[sx][sy + 7] = 5; - dungeon[sx][sy + 8] = 11; - if (dungeon[sx][sy + 9] != 4) { - dungeon[sx][sy + 9] = 21; - } - sx -= 11; - } - - for (j = 1; j < 11; j++) { - for (i = 1; i < 11; i++) { - dungeon[i + sx][j + sy] = 13; - L5dflags[i + sx][j + sy] |= DLRG_CHAMBER; - } - } - - dungeon[sx + 4][sy + 4] = 15; - dungeon[sx + 7][sy + 4] = 15; - dungeon[sx + 4][sy + 7] = 15; - dungeon[sx + 7][sy + 7] = 15; -} - -void DRLG_L5GHall(int x1, int y1, int x2, int y2) -{ - int i; - - if (y1 == y2) { - for (i = x1; i < x2; i++) { - dungeon[i][y1] = 12; - dungeon[i][y1 + 3] = 12; - } - } else { - for (i = y1; i < y2; i++) { - dungeon[x1][i] = 11; - dungeon[x1 + 3][i] = 11; - } + if (HR2 && HR3) + DRLG_L5GHall(26, 18, 28, 18); + if (HR1 && !HR2 && HR3) + DRLG_L5GHall(12, 18, 28, 18); + if (VR1) + DRLG_L5GChamber(14, 0, 0, 1, 0, 0); + + if (VR2) { + if (VR1 && !VR3) + DRLG_L5GChamber(14, 14, 1, 0, 0, 0); + if (!VR1 && VR3) + DRLG_L5GChamber(14, 14, 0, 1, 0, 0); + if (VR1 && VR3) + DRLG_L5GChamber(14, 14, 1, 1, 0, 0); + if (!VR1 && !VR3) + DRLG_L5GChamber(14, 14, 0, 0, 0, 0); } -} -void DRLG_L5SetRoom(int rx1, int ry1) -{ - int rw, rh, i, j; - BYTE *sp; + if (VR3) + DRLG_L5GChamber(14, 28, 1, 0, 0, 0); + if (VR1 && VR2) + DRLG_L5GHall(18, 12, 18, 14); + if (VR2 && VR3) + DRLG_L5GHall(18, 26, 18, 28); + if (VR1 && !VR2 && VR3) + DRLG_L5GHall(18, 12, 18, 28); - rw = *pSetPiece; - rh = *(pSetPiece + 2); + if (setloadflag) { + if (VR1 || VR2 || VR3) { + c = 1; + if (!VR1 && VR2 && VR3 && random(0, 2)) + c = 2; + if (VR1 && VR2 && !VR3 && random(0, 2)) + c = 0; - setpc_x = rx1; - setpc_y = ry1; - setpc_w = rw; - setpc_h = rh; + if (VR1 && !VR2 && VR3) { + if (random(0, 2)) + c = 0; + else + c = 2; + } - sp = pSetPiece + 4; + if (VR1 && VR2 && VR3) + c = random(0, 3); - for (j = 0; j < rh; j++) { - for (i = 0; i < rw; i++) { - if (*sp) { - dungeon[rx1 + i][ry1 + j] = *sp; - L5dflags[rx1 + i][ry1 + j] |= DLRG_PROTECTED; - } else { - dungeon[rx1 + i][ry1 + j] = 13; + switch (c) { + case 0: + DRLG_L5SetRoom(16, 2); + break; + case 1: + DRLG_L5SetRoom(16, 16); + break; + case 2: + DRLG_L5SetRoom(16, 30); + break; } - sp += 2; - } - } -} - -void DRLG_L5FloodTVal() -{ - int xx, yy, i, j; + } else { + c = 1; + if (!HR1 && HR2 && HR3 && random(0, 2)) + c = 2; + if (HR1 && HR2 && !HR3 && random(0, 2)) + c = 0; - yy = 16; + if (HR1 && !HR2 && HR3) { + if (random(0, 2)) + c = 0; + else + c = 2; + } - for (j = 0; j < DMAXY; j++) { - xx = 16; + if (HR1 && HR2 && HR3) + c = random(0, 3); - for (i = 0; i < DMAXX; i++) { - if (dungeon[i][j] == 13 && !dTransVal[xx][yy]) { - DRLG_L5FTVR(i, j, xx, yy, 0); - TransVal++; + switch (c) { + case 0: + DRLG_L5SetRoom(2, 16); + break; + case 1: + DRLG_L5SetRoom(16, 16); + break; + case 2: + DRLG_L5SetRoom(30, 16); + break; } - xx += 2; } - yy += 2; } } -void DRLG_L5FTVR(int i, int j, int x, int y, int d) +static void DRLG_L5FTVR(int i, int j, int x, int y, int d) { if (dTransVal[x][y] || dungeon[i][j] != 13) { if (d == 1) { @@ -1663,7 +1510,27 @@ void DRLG_L5FTVR(int i, int j, int x, int y, int d) } } -void DRLG_L5TransFix() +static void DRLG_L5FloodTVal() +{ + int xx, yy, i, j; + + yy = 16; + + for (j = 0; j < DMAXY; j++) { + xx = 16; + + for (i = 0; i < DMAXX; i++) { + if (dungeon[i][j] == 13 && !dTransVal[xx][yy]) { + DRLG_L5FTVR(i, j, xx, yy, 0); + TransVal++; + } + xx += 2; + } + yy += 2; + } +} + +static void DRLG_L5TransFix() { int xx, yy, i, j; @@ -1700,7 +1567,7 @@ void DRLG_L5TransFix() } } -void DRLG_L5DirtFix() +static void DRLG_L5DirtFix() { int i, j; @@ -1722,7 +1589,7 @@ void DRLG_L5DirtFix() } } -void DRLG_L5CornerFix() +static void DRLG_L5CornerFix() { int i, j; @@ -1738,3 +1605,134 @@ void DRLG_L5CornerFix() } } } + +static void DRLG_L5(int entry) +{ + int i, j; + LONG minarea; + BOOL doneflag; + + switch (currlevel) { + case 1: + minarea = 533; + break; + case 2: + minarea = 693; + break; + case 3: + case 4: + minarea = 761; + break; + } + + do { + DRLG_InitTrans(); + + do { + InitL5Dungeon(); + L5firstRoom(); + } while (L5GetArea() < minarea); + + L5makeDungeon(); + L5makeDmt(); + L5FillChambers(); + L5tileFix(); + L5AddWall(); + L5ClearFlags(); + DRLG_L5FloodTVal(); + + doneflag = TRUE; + + if (QuestStatus(QTYPE_PW)) { + if (entry == 0) { + if (DRLG_PlaceMiniSet(PWATERIN, 1, 1, 0, 0, 1, -1, 0) < 0) + doneflag = FALSE; + } else { + if (DRLG_PlaceMiniSet(PWATERIN, 1, 1, 0, 0, 0, -1, 0) < 0) + doneflag = FALSE; + ViewY--; + } + } + if (QuestStatus(QTYPE_BOL)) { + if (entry == 0) { + if (DRLG_PlaceMiniSet(STAIRSUP, 1, 1, 0, 0, 1, -1, 0) < 0) + doneflag = FALSE; + } else { + if (DRLG_PlaceMiniSet(STAIRSUP, 1, 1, 0, 0, 0, -1, 0) < 0) + doneflag = FALSE; + if (entry == 1) { + ViewX = 2 * setpc_x + 20; + ViewY = 2 * setpc_y + 28; + } else { + ViewY--; + } + } + } else if (entry == 0) { + if (DRLG_PlaceMiniSet(L5STAIRSUP, 1, 1, 0, 0, 1, -1, 0) < 0) + doneflag = FALSE; + else if (DRLG_PlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, 0, -1, 1) < 0) + doneflag = FALSE; + } else { + if (DRLG_PlaceMiniSet(L5STAIRSUP, 1, 1, 0, 0, 0, -1, 0) < 0) + doneflag = FALSE; + else if (DRLG_PlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, 1, -1, 1) < 0) + doneflag = FALSE; + ViewY--; + } + } while (doneflag == FALSE); + + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + if (dungeon[i][j] == 64) { + int xx = 2 * i + 16; /* todo: fix loop */ + int yy = 2 * j + 16; + DRLG_CopyTrans(xx, yy + 1, xx, yy); + DRLG_CopyTrans(xx + 1, yy + 1, xx + 1, yy); + } + } + } + + DRLG_L5TransFix(); + DRLG_L5DirtFix(); + DRLG_L5CornerFix(); + + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + if (L5dflags[i][j] & 0x7F) + DRLG_PlaceDoor(i, j); + } + } + + DRLG_L5Subs(); + DRLG_L1Shadows(); + DRLG_PlaceMiniSet(LAMPS, 5, 10, 0, 0, 0, -1, 4); + DRLG_L1Floor(); + + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + pdungeon[i][j] = dungeon[i][j]; + } + } + + DRLG_Init_Globals(); + DRLG_CheckQuests(setpc_x, setpc_y); +} + +void CreateL5Dungeon(DWORD rseed, int entry) +{ + SetRndSeed(rseed); + + dminx = 16; + dminy = 16; + dmaxx = 96; + dmaxy = 96; + + DRLG_InitTrans(); + DRLG_InitSetPC(); + DRLG_LoadL1SP(); + DRLG_L5(entry); + DRLG_L1Pass3(); + DRLG_FreeL1SP(); + DRLG_InitL1Vals(); + DRLG_SetPC(); +} diff --git a/Source/drlg_l1.h b/Source/drlg_l1.h index b392eaa85..728439e7b 100644 --- a/Source/drlg_l1.h +++ b/Source/drlg_l1.h @@ -15,42 +15,8 @@ extern BYTE *pSetPiece; void DRLG_Init_Globals(); void LoadL1Dungeon(char *sFileName, int vx, int vy); -void DRLG_L1Floor(); -void DRLG_L1Pass3(); -void DRLG_InitL1Vals(); void LoadPreL1Dungeon(char *sFileName, int vx, int vy); void CreateL5Dungeon(DWORD rseed, int entry); -void DRLG_LoadL1SP(); -void DRLG_FreeL1SP(); -void DRLG_L5(int entry); -void DRLG_PlaceDoor(int x, int y); -void DRLG_L1Shadows(); -int DRLG_PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, BOOL setview, int noquad, int ldir); -void InitL5Dungeon(); -void L5ClearFlags(); -void L5firstRoom(); -void L5drawRoom(int x, int y, int w, int h); -void L5roomGen(int x, int y, int w, int h, int dir); -BOOL L5checkRoom(int x, int y, int width, int height); -int L5GetArea(); -void L5makeDungeon(); -void L5makeDmt(); -void L5AddWall(); -int L5HWallOk(int i, int j); -int L5VWallOk(int i, int j); -void L5HorizWall(int i, int j, char p, int dx); -void L5VertWall(int i, int j, char p, int dy); -void L5tileFix(); -void DRLG_L5Subs(); -void L5FillChambers(); -void DRLG_L5GChamber(int sx, int sy, BOOL topflag, BOOL bottomflag, BOOL leftflag, BOOL rightflag); -void DRLG_L5GHall(int x1, int y1, int x2, int y2); -void DRLG_L5SetRoom(int rx1, int ry1); -void DRLG_L5FloodTVal(); -void DRLG_L5FTVR(int i, int j, int x, int y, int d); -void DRLG_L5TransFix(); -void DRLG_L5DirtFix(); -void DRLG_L5CornerFix(); /* rdata */ extern const ShadowStruct SPATS[37]; From 6597688eacacd65ec5414667db71569bcd427dca Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 13 Oct 2019 02:11:00 +0200 Subject: [PATCH 3/5] Rename cell functions --- Source/control.cpp | 44 +++++------ Source/doom.cpp | 2 +- Source/engine.cpp | 150 ++++++++++++++++++++---------------- Source/engine.h | 72 ++++++++--------- Source/error.cpp | 16 ++-- Source/gmenu.cpp | 12 +-- Source/interfac.cpp | 2 +- Source/inv.cpp | 58 +++++++------- Source/items.cpp | 2 +- Source/minitext.cpp | 2 +- Source/quests.cpp | 6 +- Source/scrollrt.cpp | 144 +++++++++++++++++----------------- Source/stores.cpp | 18 ++--- Source/town.cpp | 60 +++++++-------- comparer-config/diablo.toml | 72 ++++++++--------- comparer-config/spawn.toml | 72 ++++++++--------- 16 files changed, 375 insertions(+), 357 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index 8d6d46aa8..42ae61cf0 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -1123,16 +1123,16 @@ void InitControlPan() pSpellCels = LoadFileInMem("CtrlPan\\SpelIcon.CEL", NULL); SetSpellTrans(RSPLTYPE_SKILL); pStatusPanel = LoadFileInMem("CtrlPan\\Panel8.CEL", NULL); - CelDecodeRect(pBtmBuff, 0, (PANEL_HEIGHT + 16) - 1, PANEL_WIDTH, pStatusPanel, 1, PANEL_WIDTH); + CelBlitWidth(pBtmBuff, 0, (PANEL_HEIGHT + 16) - 1, PANEL_WIDTH, pStatusPanel, 1, PANEL_WIDTH); MemFreeDbg(pStatusPanel); pStatusPanel = LoadFileInMem("CtrlPan\\P8Bulbs.CEL", NULL); - CelDecodeRect(pLifeBuff, 0, 87, 88, pStatusPanel, 1, 88); - CelDecodeRect(pManaBuff, 0, 87, 88, pStatusPanel, 2, 88); + CelBlitWidth(pLifeBuff, 0, 87, 88, pStatusPanel, 1, 88); + CelBlitWidth(pManaBuff, 0, 87, 88, pStatusPanel, 2, 88); MemFreeDbg(pStatusPanel); talkflag = FALSE; if (gbMaxPlayers != 1) { pTalkPanel = LoadFileInMem("CtrlPan\\TalkPanl.CEL", NULL); - CelDecodeRect(pBtmBuff, 0, (PANEL_HEIGHT + 16) * 2 - 1, PANEL_WIDTH, pTalkPanel, 1, PANEL_WIDTH); + CelBlitWidth(pBtmBuff, 0, (PANEL_HEIGHT + 16) * 2 - 1, PANEL_WIDTH, pTalkPanel, 1, PANEL_WIDTH); MemFreeDbg(pTalkPanel); pMultiBtns = LoadFileInMem("CtrlPan\\P8But2.CEL", NULL); pTalkBtns = LoadFileInMem("CtrlPan\\TalkButt.CEL", NULL); @@ -1201,14 +1201,14 @@ void DrawCtrlPan() if (!panbtn[i]) DrawPanelBox(PanBtnPos[i][0], PanBtnPos[i][1] - 336, 71, 20, PanBtnPos[i][0] + SCREEN_X, PanBtnPos[i][1] + SCREEN_Y); else - CelDecodeOnly(PanBtnPos[i][0] + SCREEN_X, PanBtnPos[i][1] + SCREEN_Y + 18, pPanelButtons, i + 1, 71); + CelDraw(PanBtnPos[i][0] + SCREEN_X, PanBtnPos[i][1] + SCREEN_Y + 18, pPanelButtons, i + 1, 71); } if (numpanbtns == 8) { - CelDecodeOnly(87 + SCREEN_X, 474 + SCREEN_Y, pMultiBtns, panbtn[6] + 1, 33); + CelDraw(87 + SCREEN_X, 474 + SCREEN_Y, pMultiBtns, panbtn[6] + 1, 33); if (FriendlyMode) - CelDecodeOnly(527 + SCREEN_X, 474 + SCREEN_Y, pMultiBtns, panbtn[7] + 3, 33); + CelDraw(527 + SCREEN_X, 474 + SCREEN_Y, pMultiBtns, panbtn[7] + 3, 33); else - CelDecodeOnly(527 + SCREEN_X, 474 + SCREEN_Y, pMultiBtns, panbtn[7] + 5, 33); + CelDraw(527 + SCREEN_X, 474 + SCREEN_Y, pMultiBtns, panbtn[7] + 5, 33); } } @@ -1660,7 +1660,7 @@ void DrawChr() char chrstr[64]; int pc, mindam, maxdam; - CelDecodeOnly(SCREEN_X, 351 + SCREEN_Y, pChrPanel, 1, 320); + CelDraw(SCREEN_X, 351 + SCREEN_Y, pChrPanel, 1, 320); ADD_PlrStringXY(20, 32, 151, plr[myplr]._pName, COL_WHITE); if (plr[myplr]._pClass == PC_WARRIOR) { @@ -1833,13 +1833,13 @@ void DrawChr() ADD_PlrStringXY(95, 266, 126, chrstr, COL_RED); pc = plr[myplr]._pClass; if (plr[myplr]._pBaseStr < MaxStats[pc][ATTRIB_STR]) - CelDecodeOnly(137 + SCREEN_X, 159 + SCREEN_Y, pChrButtons, chrbtn[ATTRIB_STR] + 2, 41); + CelDraw(137 + SCREEN_X, 159 + SCREEN_Y, pChrButtons, chrbtn[ATTRIB_STR] + 2, 41); if (plr[myplr]._pBaseMag < MaxStats[pc][ATTRIB_MAG]) - CelDecodeOnly(137 + SCREEN_X, 187 + SCREEN_Y, pChrButtons, chrbtn[ATTRIB_MAG] + 4, 41); + CelDraw(137 + SCREEN_X, 187 + SCREEN_Y, pChrButtons, chrbtn[ATTRIB_MAG] + 4, 41); if (plr[myplr]._pBaseDex < MaxStats[pc][ATTRIB_DEX]) - CelDecodeOnly(137 + SCREEN_X, 216 + SCREEN_Y, pChrButtons, chrbtn[ATTRIB_DEX] + 6, 41); + CelDraw(137 + SCREEN_X, 216 + SCREEN_Y, pChrButtons, chrbtn[ATTRIB_DEX] + 6, 41); if (plr[myplr]._pBaseVit < MaxStats[pc][ATTRIB_VIT]) - CelDecodeOnly(137 + SCREEN_X, 244 + SCREEN_Y, pChrButtons, chrbtn[ATTRIB_VIT] + 8, 41); + CelDraw(137 + SCREEN_X, 244 + SCREEN_Y, pChrButtons, chrbtn[ATTRIB_VIT] + 8, 41); } col = plr[myplr]._pMaxHP <= plr[myplr]._pMaxHPBase ? COL_WHITE : COL_BLUE; @@ -1942,7 +1942,7 @@ void DrawLevelUpIcon() if (!stextflag) { nCel = lvlbtndown ? 3 : 2; ADD_PlrStringXY(0, 303, 120, "Level Up", COL_WHITE); - CelDecodeOnly(40 + SCREEN_X, 335 + SCREEN_Y, pChrButtons, nCel, 41); + CelDraw(40 + SCREEN_X, 335 + SCREEN_Y, pChrButtons, nCel, 41); } } @@ -2067,7 +2067,7 @@ int DrawDurIcon4Item(ItemStruct *pItem, int x, int c) } if (pItem->_iDurability > 2) c += 8; - CelDecodeOnly(x, 335 + SCREEN_Y, pDurIcons, c, 32); + CelDraw(x, 335 + SCREEN_Y, pDurIcons, c, 32); return x - 40; } @@ -2179,8 +2179,8 @@ void DrawSpellBook() char st; unsigned __int64 spl; - CelDecodeOnly(PANEL_RIGHT, 351 + SCREEN_Y, pSpellBkCel, 1, 320); - CelDecodeOnly(PANEL_RIGHT + 76 * sbooktab + 7, 348 + SCREEN_Y, pSBkBtnCel, sbooktab + 1, 76); + CelDraw(PANEL_RIGHT, 351 + SCREEN_Y, pSpellBkCel, 1, 320); + CelDraw(PANEL_RIGHT + 76 * sbooktab + 7, 348 + SCREEN_Y, pSBkBtnCel, sbooktab + 1, 76); spl = plr[myplr]._pMemSpells | plr[myplr]._pISpells | plr[myplr]._pAblSpells; @@ -2305,7 +2305,7 @@ void DrawGoldSplit(int amount) int screen_x, i; screen_x = 0; - CelDecodeOnly(351 + SCREEN_X, 178 + SCREEN_Y, pGBoxBuff, 1, 261); + CelDraw(351 + SCREEN_X, 178 + SCREEN_Y, pGBoxBuff, 1, 261); sprintf(tempstr, "You have %u gold", initialDropGoldValue); ADD_PlrStringXY(366, 87, 600, tempstr, COL_GOLD); sprintf(tempstr, "%s. How many do", get_pieces_str(initialDropGoldValue)); @@ -2321,7 +2321,7 @@ void DrawGoldSplit(int amount) } else { screen_x = 450; } - CelDecodeOnly(screen_x, 140 + SCREEN_Y, pSPentSpn2Cels, nGoldFrame, 12); + CelDraw(screen_x, 140 + SCREEN_Y, pSPentSpn2Cels, nGoldFrame, 12); nGoldFrame = (nGoldFrame & 7) + 1; } @@ -2428,7 +2428,7 @@ void DrawTalkPan() } if (msg) *msg = '\0'; - CelDecDatOnly(gpBuffer + x, pSPentSpn2Cels, frame, 12); + CelBlitFrame(gpBuffer + x, pSPentSpn2Cels, frame, 12); frame = (frame & 7) + 1; talk_btn = 0; for (i = 0; i < 4; i++) { @@ -2441,7 +2441,7 @@ void DrawTalkPan() nCel = 4; else nCel = 3; - CelDecodeOnly(172 + SCREEN_X, 436 + 18 * talk_btn + SCREEN_Y, pTalkBtns, nCel, 61); + CelDraw(172 + SCREEN_X, 436 + 18 * talk_btn + SCREEN_Y, pTalkBtns, nCel, 61); } } else { color = COL_RED; @@ -2451,7 +2451,7 @@ void DrawTalkPan() nCel = 1; if (talkbtndown[talk_btn]) nCel += 4; - CelDecodeOnly(172 + SCREEN_X, 436 + 18 * talk_btn + SCREEN_Y, pTalkBtns, nCel, 61); + CelDraw(172 + SCREEN_X, 436 + 18 * talk_btn + SCREEN_Y, pTalkBtns, nCel, 61); } if (plr[i].plractive) { control_print_talk_msg(plr[i]._pName, 46, 60 + talk_btn * 18, &x, color); diff --git a/Source/doom.cpp b/Source/doom.cpp index c4052eff2..8bb9d080a 100644 --- a/Source/doom.cpp +++ b/Source/doom.cpp @@ -91,5 +91,5 @@ void doom_draw() } } - CelDecodeOnly(SCREEN_X, PANEL_Y - 1, pDoomCel, 1, SCREEN_WIDTH); + CelDraw(SCREEN_X, PANEL_Y - 1, pDoomCel, 1, SCREEN_WIDTH); } diff --git a/Source/engine.cpp b/Source/engine.cpp index eb883845a..f7699c2d6 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -40,7 +40,7 @@ __FINLINE int CelGetFrameSize(BYTE *pCelBuff, int nCel) return SwapLE32(pFrameTable[nCel + 1]) - SwapLE32(pFrameTable[nCel]); } -void CelDrawDatOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) +void CelBlit(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) { int w; @@ -139,7 +139,7 @@ void CelDrawDatOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) #endif } -void CelDecodeOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth) +void CelDraw(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth) { int nDataSize; BYTE *pRLEBytes; @@ -152,10 +152,10 @@ void CelDecodeOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth) return; pRLEBytes = CelGetFrame(pCelBuff, nCel, &nDataSize); - CelDrawDatOnly(&gpBuffer[sx + PitchTbl[sy]], pRLEBytes, nDataSize, nWidth); + CelBlit(&gpBuffer[sx + PitchTbl[sy]], pRLEBytes, nDataSize, nWidth); } -void CelDecDatOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth) +void CelBlitFrame(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth) { int nDataSize; BYTE *pRLEBytes; @@ -168,14 +168,14 @@ void CelDecDatOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth) return; pRLEBytes = CelGetFrame(pCelBuff, nCel, &nDataSize); - CelDrawDatOnly(pBuff, pRLEBytes, nDataSize, nWidth); + CelBlit(pBuff, pRLEBytes, nDataSize, nWidth); } /** * @param CelSkip Skip lower parts of sprite, must be multiple of 2, max 8 * @param CelCap Amount of sprite to render from lower to upper, must be multiple of 2, max 8 */ -void CelDrawHdrOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) +void CelClippedDraw(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { BYTE *pRLEBytes; DWORD *pFrameTable; @@ -205,7 +205,7 @@ void CelDrawHdrOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int Ce else nDataSize -= nDataStart; - CelDrawDatOnly( + CelBlit( &gpBuffer[sx + PitchTbl[sy - 16 * CelSkip]], pRLEBytes + nDataStart, nDataSize, @@ -216,7 +216,7 @@ void CelDrawHdrOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int Ce * @param CelSkip Skip lower parts of sprite, must be multiple of 2, max 8 * @param CelCap Amount of sprite to render from lower to upper, must be multiple of 2, max 8 */ -void CelDecodeHdrOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) +void CelClippedBlit(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { BYTE *pRLEBytes; DWORD *pFrameTable; @@ -246,10 +246,10 @@ void CelDecodeHdrOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int Cel else nDataSize -= nDataStart; - CelDrawDatOnly(pBuff, pRLEBytes + nDataStart, nDataSize, nWidth); + CelBlit(pBuff, pRLEBytes + nDataStart, nDataSize, nWidth); } -void CelDecDatLightOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) +void CelBlitLight(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) { int w; BYTE *tbl; @@ -286,7 +286,7 @@ void CelDecDatLightOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWi sub edx, eax mov ecx, eax push edx - call CelDecDatLightEntry + call CelBlitLightEntry pop edx pop ebx or edx, edx @@ -307,7 +307,7 @@ void CelDecDatLightOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWi /* Assembly Macro */ // clang-format off __asm { - CelDecDatLightEntry: + CelBlitLightEntry: shr cl, 1 jnb label5 mov dl, [esi] @@ -402,7 +402,7 @@ void CelDecDatLightOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWi #endif } -void CelDecDatLightTrans(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) +void CelBlitLightTrans(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) { int w; BOOL shift; @@ -589,7 +589,7 @@ void CelDecDatLightTrans(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nW #endif } -void CelDecodeLightOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth) +void CelDrawLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth) { int nDataSize; BYTE *pDecodeTo, *pRLEBytes; @@ -605,16 +605,16 @@ void CelDecodeLightOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth) pDecodeTo = &gpBuffer[sx + PitchTbl[sy]]; if (light_table_index) - CelDecDatLightOnly(pDecodeTo, pRLEBytes, nDataSize, nWidth); + CelBlitLight(pDecodeTo, pRLEBytes, nDataSize, nWidth); else - CelDrawDatOnly(pDecodeTo, pRLEBytes, nDataSize, nWidth); + CelBlit(pDecodeTo, pRLEBytes, nDataSize, nWidth); } /** * @param CelSkip Skip lower parts of sprite, must be multiple of 2, max 8 * @param CelCap Amount of sprite to render from lower to upper, must be multiple of 2, max 8 */ -void CelDecodeHdrLightOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) +void CelClippedDrawLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { int nDataStart, nDataSize, nDataCap; BYTE *pRLEBytes, *pDecodeTo; @@ -648,16 +648,16 @@ void CelDecodeHdrLightOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, pDecodeTo = &gpBuffer[sx + PitchTbl[sy - 16 * CelSkip]]; if (light_table_index) - CelDecDatLightOnly(pDecodeTo, pRLEBytes, nDataSize, nWidth); + CelBlitLight(pDecodeTo, pRLEBytes, nDataSize, nWidth); else - CelDrawDatOnly(pDecodeTo, pRLEBytes, nDataSize, nWidth); + CelBlit(pDecodeTo, pRLEBytes, nDataSize, nWidth); } /** * @param CelSkip Skip lower parts of sprite, must be multiple of 2, max 8 * @param CelCap Amount of sprite to render from lower to upper, must be multiple of 2, max 8 */ -void CelDecodeHdrLightTrans(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) +void CelClippedBlitLightTrans(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { int nDataStart, nDataSize, nDataCap; BYTE *pRLEBytes; @@ -690,18 +690,18 @@ void CelDecodeHdrLightTrans(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, i pRLEBytes += nDataStart; if (cel_transparency_active) - CelDecDatLightTrans(pBuff, pRLEBytes, nDataSize, nWidth); + CelBlitLightTrans(pBuff, pRLEBytes, nDataSize, nWidth); else if (light_table_index) - CelDecDatLightOnly(pBuff, pRLEBytes, nDataSize, nWidth); + CelBlitLight(pBuff, pRLEBytes, nDataSize, nWidth); else - CelDrawDatOnly(pBuff, pRLEBytes, nDataSize, nWidth); + CelBlit(pBuff, pRLEBytes, nDataSize, nWidth); } /** * @param CelSkip Skip lower parts of sprite, must be multiple of 2, max 8 * @param CelCap Amount of sprite to render from lower to upper, must be multiple of 2, max 8 */ -void CelDrawHdrLightRed(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap, char light) +void CelDrawLightRed(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap, char light) { int nDataStart, nDataSize, nDataCap, w, idx; BYTE *pRLEBytes, *dst, *tbl; @@ -814,7 +814,10 @@ void CelDrawHdrLightRed(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, in #endif } -void Cel2DecDatOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) +/** + * @brief Same as CelBlit but checks for drawing outside the buffer + */ +void CelBlitSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) { int w; @@ -931,7 +934,7 @@ void Cel2DecDatOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) * @param CelSkip Skip lower parts of sprite, must be multiple of 2, max 8 * @param CelCap Amount of sprite to render from lower to upper, must be multiple of 2, max 8 */ -void Cel2DrawHdrOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) +void CelClippedDrawSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { BYTE *pRLEBytes; DWORD *pFrameTable; @@ -961,7 +964,7 @@ void Cel2DrawHdrOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int C else nDataSize -= nDataStart; - Cel2DecDatOnly( + CelBlitSafe( &gpBuffer[sx + PitchTbl[sy - 16 * CelSkip]], pRLEBytes + nDataStart, nDataSize, @@ -972,7 +975,7 @@ void Cel2DrawHdrOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int C * @param CelSkip Skip lower parts of sprite, must be multiple of 2, max 8 * @param CelCap Amount of sprite to render from lower to upper, must be multiple of 2, max 8 */ -void Cel2DecodeHdrOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) +void CelClippedBlitSafe(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { BYTE *pRLEBytes; DWORD *pFrameTable; @@ -1002,10 +1005,13 @@ void Cel2DecodeHdrOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int Ce else nDataSize -= nDataStart; - Cel2DecDatOnly(pBuff, pRLEBytes + nDataStart, nDataSize, nWidth); + CelBlitSafe(pBuff, pRLEBytes + nDataStart, nDataSize, nWidth); } -void Cel2DecDatLightOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) +/** + * @brief Same as CelBlitLight but checks for drawing outside the buffer + */ +void CelBlitLightSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) { int w; BYTE *tbl; @@ -1173,7 +1179,10 @@ void Cel2DecDatLightOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nW #endif } -void Cel2DecDatLightTrans(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) +/** + * @brief Same as CelBlitLightTrans but checks for drawing outside the buffer + */ +void CelBlitLightTransSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) { int w; BOOL shift; @@ -1378,7 +1387,7 @@ void Cel2DecDatLightTrans(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int n * @param CelSkip Skip lower parts of sprite, must be multiple of 2, max 8 * @param CelCap Amount of sprite to render from lower to upper, must be multiple of 2, max 8 */ -void Cel2DecodeHdrLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) +void CelDrawLightSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { int nDataStart, nDataSize, nDataCap; BYTE *pRLEBytes, *pDecodeTo; @@ -1412,16 +1421,16 @@ void Cel2DecodeHdrLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, in pDecodeTo = &gpBuffer[sx + PitchTbl[sy - 16 * CelSkip]]; if (light_table_index) - Cel2DecDatLightOnly(pDecodeTo, pRLEBytes, nDataSize, nWidth); + CelBlitLightSafe(pDecodeTo, pRLEBytes, nDataSize, nWidth); else - Cel2DecDatOnly(pDecodeTo, pRLEBytes, nDataSize, nWidth); + CelBlitSafe(pDecodeTo, pRLEBytes, nDataSize, nWidth); } /** * @param CelSkip Skip lower parts of sprite, must be multiple of 2, max 8 * @param CelCap Amount of sprite to render from lower to upper, must be multiple of 2, max 8 */ -void Cel2DecodeLightTrans(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) +void CelClippedBlitLightTransSafe(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { int nDataStart, nDataSize, nDataCap; BYTE *pRLEBytes; @@ -1451,18 +1460,19 @@ void Cel2DecodeLightTrans(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int pRLEBytes += nDataStart; if (cel_transparency_active) - Cel2DecDatLightTrans(pBuff, pRLEBytes, nDataSize, nWidth); + CelBlitLightTransSafe(pBuff, pRLEBytes, nDataSize, nWidth); else if (light_table_index) - Cel2DecDatLightOnly(pBuff, pRLEBytes, nDataSize, nWidth); + CelBlitLightSafe(pBuff, pRLEBytes, nDataSize, nWidth); else - Cel2DecDatOnly(pBuff, pRLEBytes, nDataSize, nWidth); + CelBlitSafe(pBuff, pRLEBytes, nDataSize, nWidth); } /** + * @brief Same as CelDrawLightRed but checks for drawing outside the buffer * @param CelSkip Skip lower parts of sprite, must be multiple of 2, max 8 * @param CelCap Amount of sprite to render from lower to upper, must be multiple of 2, max 8 */ -void Cel2DrawHdrLightRed(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap, char light) +void CelDrawLightRedSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap, char light) { int nDataStart, nDataSize, nDataCap, w, idx; BYTE *pRLEBytes, *dst, *tbl; @@ -1476,6 +1486,7 @@ void Cel2DrawHdrLightRed(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, i return; pFrameTable = (DWORD *)pCelBuff; + pRLEBytes = &pCelBuff[pFrameTable[nCel]]; nDataStart = *(WORD *)&pRLEBytes[CelSkip]; if (!nDataStart) @@ -1582,7 +1593,10 @@ void Cel2DrawHdrLightRed(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, i #endif } -void CelDecodeRect(BYTE *pBuff, int CelSkip, int hgt, int wdt, BYTE *pCelBuff, int nCel, int nWidth) +/** + * @brief Same as CelBlit but cropped to given width + */ +void CelBlitWidth(BYTE *pBuff, int CelSkip, int hgt, int wdt, BYTE *pCelBuff, int nCel, int nWidth) { BYTE *pRLEBytes, *dst, *end; @@ -1700,7 +1714,7 @@ void CelDecodeRect(BYTE *pBuff, int CelSkip, int hgt, int wdt, BYTE *pCelBuff, i * @param CelSkip Skip lower parts of sprite, must be multiple of 2, max 8 * @param CelCap Amount of sprite to render from lower to upper, must be multiple of 2, max 8 */ -void CelDecodeClr(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) +void CelBlitOutline(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { int nDataStart, nDataSize, nDataCap, w; BYTE *pRLEBytes, *dst; @@ -1838,10 +1852,11 @@ void CelDecodeClr(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth } /** + * @brief Same as CelBlitOutline but checks for drawing outside the buffer * @param CelSkip Skip lower parts of sprite, must be multiple of 2, max 8 * @param CelCap Amount of sprite to render from lower to upper, must be multiple of 2, max 8 */ -void CelDrawHdrClrHL(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) +void CelBlitOutlineSafe(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { int nDataStart, nDataSize, nDataCap, w; BYTE *pRLEBytes, *dst; @@ -2443,6 +2458,9 @@ DWORD LoadFileWithMem(const char *pszName, void *p) return dwFileLen; } +/** + * @brief Apply the color swaps to a CL2 sprite + */ void Cl2ApplyTrans(BYTE *p, BYTE *ttbl, int nCel) { int i, nDataSize; @@ -2486,7 +2504,7 @@ void Cl2ApplyTrans(BYTE *p, BYTE *ttbl, int nCel) * @param CelSkip Skip lower parts of sprite, must be multiple of 2, max 8 * @param CelCap Amount of sprite to render from lower to upper, must be multiple of 2, max 8 */ -void Cl2DecodeFrm1(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) +void Cl2Draw(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { BYTE *pRLEBytes; DWORD *pFrameTable; @@ -2516,14 +2534,14 @@ void Cl2DecodeFrm1(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int Cel if (!nDataSize) nDataSize = pFrameTable[nCel + 1] - pFrameTable[nCel]; - Cl2DecDatFrm1( + Cl2Blit( &gpBuffer[sx + PitchTbl[sy - 16 * CelSkip]], pRLEBytes + nDataStart, nDataSize - nDataStart, nWidth); } -void Cl2DecDatFrm1(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) +void Cl2Blit(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) { #ifdef USE_ASM __asm { @@ -2668,7 +2686,7 @@ void Cl2DecDatFrm1(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) * @param CelSkip Skip lower parts of sprite, must be multiple of 2, max 8 * @param CelCap Amount of sprite to render from lower to upper, must be multiple of 2, max 8 */ -void Cl2DecodeFrm2(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) +void Cl2DrawOutline(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { int nDataStart, nDataSize; BYTE *pRLEBytes; @@ -2698,7 +2716,7 @@ void Cl2DecodeFrm2(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidt if (!nDataSize) nDataSize = pFrameTable[nCel + 1] - pFrameTable[nCel]; - Cl2DecDatFrm2( + Cl2BlitOutline( &gpBuffer[sx + PitchTbl[sy - 16 * CelSkip]], pRLEBytes + nDataStart, nDataSize - nDataStart, @@ -2706,7 +2724,7 @@ void Cl2DecodeFrm2(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidt col); } -void Cl2DecDatFrm2(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, char col) +void Cl2BlitOutline(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, char col) { #ifdef USE_ASM __asm { @@ -2872,7 +2890,7 @@ void Cl2DecDatFrm2(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, * @param CelSkip Skip lower parts of sprite, must be multiple of 2, max 8 * @param CelCap Amount of sprite to render from lower to upper, must be multiple of 2, max 8 */ -void Cl2DecodeFrm3(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap, char light) +void Cl2DrawLightTbl(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap, char light) { int nDataStart, nDataSize, idx, nSize; BYTE *pRLEBytes, *pDecodeTo; @@ -2912,7 +2930,7 @@ void Cl2DecodeFrm3(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int Cel if (light >= 4) idx += (light - 1) << 8; - Cl2DecDatLightTbl1( + Cl2BlitLight( pDecodeTo, pRLEBytes, nSize, @@ -2920,7 +2938,7 @@ void Cl2DecodeFrm3(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int Cel &pLightTbl[idx]); } -void Cl2DecDatLightTbl1(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, BYTE *pTable) +void Cl2BlitLight(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, BYTE *pTable) { #ifdef USE_ASM __asm { @@ -3074,7 +3092,7 @@ void Cl2DecDatLightTbl1(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWi * @param CelSkip Skip lower parts of sprite, must be multiple of 2, max 8 * @param CelCap Amount of sprite to render from lower to upper, must be multiple of 2, max 8 */ -void Cl2DecodeLightTbl(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) +void Cl2DrawLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { int nDataStart, nDataSize, nSize; BYTE *pRLEBytes, *pDecodeTo; @@ -3109,16 +3127,16 @@ void Cl2DecodeLightTbl(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int pDecodeTo = &gpBuffer[sx + PitchTbl[sy - 16 * CelSkip]]; if (light_table_index) - Cl2DecDatLightTbl1(pDecodeTo, pRLEBytes, nSize, nWidth, &pLightTbl[light_table_index * 256]); + Cl2BlitLight(pDecodeTo, pRLEBytes, nSize, nWidth, &pLightTbl[light_table_index * 256]); else - Cl2DecDatFrm1(pDecodeTo, pRLEBytes, nSize, nWidth); + Cl2Blit(pDecodeTo, pRLEBytes, nSize, nWidth); } /** * @param CelSkip Skip lower parts of sprite, must be multiple of 2, max 8 * @param CelCap Amount of sprite to render from lower to upper, must be multiple of 2, max 8 */ -void Cl2DecodeFrm4(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) +void Cl2DrawSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { BYTE *pRLEBytes; DWORD *pFrameTable; @@ -3148,14 +3166,14 @@ void Cl2DecodeFrm4(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int Cel if (!nDataSize) nDataSize = pFrameTable[nCel + 1] - pFrameTable[nCel]; - Cl2DecDatFrm4( + Cl2BlitSafe( &gpBuffer[sx + PitchTbl[sy - 16 * CelSkip]], pRLEBytes + nDataStart, nDataSize - nDataStart, nWidth); } -void Cl2DecDatFrm4(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) +void Cl2BlitSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) { #ifdef USE_ASM __asm { @@ -3313,7 +3331,7 @@ void Cl2DecDatFrm4(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) * @param CelSkip Skip lower parts of sprite, must be multiple of 2, max 8 * @param CelCap Amount of sprite to render from lower to upper, must be multiple of 2, max 8 */ -void Cl2DecodeClrHL(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) +void Cl2DrawOutlineSafe(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { int nDataStart, nDataSize; BYTE *pRLEBytes; @@ -3344,7 +3362,7 @@ void Cl2DecodeClrHL(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWid nDataSize = pFrameTable[nCel + 1] - pFrameTable[nCel]; gpBufEnd -= BUFFER_WIDTH; - Cl2DecDatClrHL( + Cl2BlitOutlineSafe( &gpBuffer[sx + PitchTbl[sy - 16 * CelSkip]], pRLEBytes + nDataStart, nDataSize - nDataStart, @@ -3353,7 +3371,7 @@ void Cl2DecodeClrHL(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWid gpBufEnd += BUFFER_WIDTH; } -void Cl2DecDatClrHL(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, char col) +void Cl2BlitOutlineSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, char col) { #ifdef USE_ASM __asm { @@ -3530,7 +3548,7 @@ void Cl2DecDatClrHL(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, * @param CelSkip Skip lower parts of sprite, must be multiple of 2, max 8 * @param CelCap Amount of sprite to render from lower to upper, must be multiple of 2, max 8 */ -void Cl2DecodeFrm5(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap, char light) +void Cl2DrawLightTblSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap, char light) { int nDataStart, nDataSize, idx, nSize; BYTE *pRLEBytes, *pDecodeTo; @@ -3570,7 +3588,7 @@ void Cl2DecodeFrm5(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int Cel if (light >= 4) idx += (light - 1) << 8; - Cl2DecDatLightTbl2( + Cl2BlitLightSafe( pDecodeTo, pRLEBytes, nSize, @@ -3578,7 +3596,7 @@ void Cl2DecodeFrm5(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int Cel &pLightTbl[idx]); } -void Cl2DecDatLightTbl2(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, BYTE *pTable) +void Cl2BlitLightSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, BYTE *pTable) { #ifdef USE_ASM __asm { @@ -3745,7 +3763,7 @@ void Cl2DecDatLightTbl2(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWi * @param CelSkip Skip lower parts of sprite, must be multiple of 2, max 8 * @param CelCap Amount of sprite to render from lower to upper, must be multiple of 2, max 8 */ -void Cl2DecodeFrm6(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) +void Cl2DrawLightSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { int nDataStart, nDataSize, nSize; BYTE *pRLEBytes, *pDecodeTo; @@ -3780,9 +3798,9 @@ void Cl2DecodeFrm6(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int Cel pDecodeTo = &gpBuffer[sx + PitchTbl[sy - 16 * CelSkip]]; if (light_table_index) - Cl2DecDatLightTbl2(pDecodeTo, pRLEBytes, nSize, nWidth, &pLightTbl[light_table_index * 256]); + Cl2BlitLightSafe(pDecodeTo, pRLEBytes, nSize, nWidth, &pLightTbl[light_table_index * 256]); else - Cl2DecDatFrm4(pDecodeTo, pRLEBytes, nSize, nWidth); + Cl2BlitSafe(pDecodeTo, pRLEBytes, nSize, nWidth); } void PlayInGameMovie(char *pszMovie) diff --git a/Source/engine.h b/Source/engine.h index 234ccb317..c7bd94e85 100644 --- a/Source/engine.h +++ b/Source/engine.h @@ -13,28 +13,28 @@ extern BOOL gbNotInView; // valid - if x/y are in bounds __FINLINE BYTE *CelGetFrame(BYTE *pCelBuff, int nCel, int *nDataSize); -void CelDrawDatOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth); -void CelDecodeOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth); -void CelDecDatOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth); -void CelDrawHdrOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); -void CelDecodeHdrOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); -void CelDecDatLightOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth); -void CelDecDatLightTrans(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth); -void CelDecodeLightOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth); -void CelDecodeHdrLightOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); -void CelDecodeHdrLightTrans(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); -void CelDrawHdrLightRed(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap, char light); -void Cel2DecDatOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth); -void Cel2DrawHdrOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); -void Cel2DecodeHdrOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); -void Cel2DecDatLightOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth); -void Cel2DecDatLightTrans(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth); -void Cel2DecodeHdrLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); -void Cel2DecodeLightTrans(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); -void Cel2DrawHdrLightRed(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap, char light); -void CelDecodeRect(BYTE *pBuff, int always_0, int hgt, int wdt, BYTE *pCelBuff, int nCel, int nWidth); -void CelDecodeClr(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); -void CelDrawHdrClrHL(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); +void CelBlit(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth); +void CelDraw(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth); +void CelBlitFrame(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth); +void CelClippedDraw(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); +void CelClippedBlit(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); +void CelBlitLight(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth); +void CelBlitLightTrans(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth); +void CelDrawLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth); +void CelClippedDrawLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); +void CelClippedBlitLightTrans(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); +void CelDrawLightRed(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap, char light); +void CelBlitSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth); +void CelClippedDrawSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); +void CelClippedBlitSafe(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); +void CelBlitLightSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth); +void CelBlitLightTransSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth); +void CelDrawLightSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); +void CelClippedBlitLightTransSafe(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); +void CelDrawLightRedSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap, char light); +void CelBlitWidth(BYTE *pBuff, int always_0, int hgt, int wdt, BYTE *pCelBuff, int nCel, int nWidth); +void CelBlitOutline(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); +void CelBlitOutlineSafe(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); void ENG_set_pixel(int sx, int sy, BYTE col); void engine_draw_pixel(int sx, int sy); void DrawLine(int x0, int y0, int x1, int y1, BYTE col); @@ -48,20 +48,20 @@ void mem_free_dbg(void *p); BYTE *LoadFileInMem(char *pszName, DWORD *pdwFileLen); DWORD LoadFileWithMem(const char *pszName, void *p); void Cl2ApplyTrans(BYTE *p, BYTE *ttbl, int nCel); -void Cl2DecodeFrm1(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); -void Cl2DecDatFrm1(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth); -void Cl2DecodeFrm2(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); -void Cl2DecDatFrm2(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, char col); -void Cl2DecodeFrm3(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap, char light); -void Cl2DecDatLightTbl1(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, BYTE *pTable); -void Cl2DecodeLightTbl(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); -void Cl2DecodeFrm4(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); -void Cl2DecDatFrm4(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth); -void Cl2DecodeClrHL(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); -void Cl2DecDatClrHL(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, char col); -void Cl2DecodeFrm5(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap, char light); -void Cl2DecDatLightTbl2(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, BYTE *pTable); -void Cl2DecodeFrm6(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); +void Cl2Draw(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); +void Cl2Blit(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth); +void Cl2DrawOutline(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); +void Cl2BlitOutline(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, char col); +void Cl2DrawLightTbl(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap, char light); +void Cl2BlitLight(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, BYTE *pTable); +void Cl2DrawLight(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); +void Cl2DrawSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); +void Cl2BlitSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth); +void Cl2DrawOutlineSafe(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); +void Cl2BlitOutlineSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, char col); +void Cl2DrawLightTblSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap, char light); +void Cl2BlitLightSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, BYTE *pTable); +void Cl2DrawLightSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap); void PlayInGameMovie(char *pszMovie); /* rdata */ diff --git a/Source/error.cpp b/Source/error.cpp index 919041a8f..fd2df0a8c 100644 --- a/Source/error.cpp +++ b/Source/error.cpp @@ -85,21 +85,21 @@ void DrawDiabloMsg() int i, len, off, width, sx, sy; BYTE c; - CelDecodeOnly(165, 318, pSTextSlidCels, 1, 12); - CelDecodeOnly(591, 318, pSTextSlidCels, 4, 12); - CelDecodeOnly(165, 366, pSTextSlidCels, 2, 12); - CelDecodeOnly(591, 366, pSTextSlidCels, 3, 12); + CelDraw(165, 318, pSTextSlidCels, 1, 12); + CelDraw(591, 318, pSTextSlidCels, 4, 12); + CelDraw(165, 366, pSTextSlidCels, 2, 12); + CelDraw(591, 366, pSTextSlidCels, 3, 12); sx = 173; for (i = 0; i < 35; i++) { - CelDecodeOnly(sx, 318, pSTextSlidCels, 5, 12); - CelDecodeOnly(sx, 366, pSTextSlidCels, 7, 12); + CelDraw(sx, 318, pSTextSlidCels, 5, 12); + CelDraw(sx, 366, pSTextSlidCels, 7, 12); sx += 12; } sy = 330; for (i = 0; i < 3; i++) { - CelDecodeOnly(165, sy, pSTextSlidCels, 6, 12); - CelDecodeOnly(591, sy, pSTextSlidCels, 8, 12); + CelDraw(165, sy, pSTextSlidCels, 6, 12); + CelDraw(591, sy, pSTextSlidCels, 8, 12); sy += 12; } diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index 2f65d83ab..39e28b331 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -55,7 +55,7 @@ void gmenu_print_text(int x, int y, char *pszStr) c = gbFontTransTbl[(BYTE)*pszStr++]; c = lfontframe[c]; if (c) - CelDecodeLightOnly(x, y, BigTGold_cel, c, 46); + CelDrawLight(x, y, BigTGold_cel, c, 46); x += lfontkern[c] + 2; } } @@ -151,7 +151,7 @@ void gmenu_draw() if (sgpCurrentMenu) { if (dword_63447C) dword_63447C(sgpCurrentMenu); - CelDecodeOnly((SCREEN_WIDTH - 296) / 2 + SCREEN_X, 102 + SCREEN_Y, sgpLogo, 1, 296); + CelDraw((SCREEN_WIDTH - 296) / 2 + SCREEN_X, 102 + SCREEN_Y, sgpLogo, 1, 296); y = 160 + SCREEN_Y; i = sgpCurrentMenu; if (sgpCurrentMenu->fnMenu) { @@ -179,21 +179,21 @@ void gmenu_draw_menu_item(TMenuItem *pItem, int y) w = gmenu_get_lfont(pItem); if (pItem->dwFlags & GMENU_SLIDER) { x = 16 + w / 2 + SCREEN_X; - CelDecodeOnly(x, t - 8, optbar_cel, 1, 287); + CelDraw(x, t - 8, optbar_cel, 1, 287); step = pItem->dwFlags & 0xFFF; nSteps = (pItem->dwFlags & 0xFFF000) >> 12; if (nSteps < 2) nSteps = 2; pos = step * 256 / nSteps; gmenu_clear_buffer(x + 2, t - 10, pos + 13, 28); - CelDecodeOnly(x + 2 + pos, y - 12, option_cel, 1, 27); + CelDraw(x + 2 + pos, y - 12, option_cel, 1, 27); } x = SCREEN_WIDTH / 2 - w / 2 + SCREEN_X; light_table_index = (pItem->dwFlags & GMENU_ENABLED) ? 0 : 15; gmenu_print_text(x, y, pItem->pszStr); if (pItem == sgpCurrItem) { - CelDecodeOnly(x - 54, y + 1, PentSpin_cel, PentSpin_frame, 48); - CelDecodeOnly(x + 4 + w, y + 1, PentSpin_cel, PentSpin_frame, 48); + CelDraw(x - 54, y + 1, PentSpin_cel, PentSpin_frame, 48); + CelDraw(x + 4 + w, y + 1, PentSpin_cel, PentSpin_frame, 48); } } diff --git a/Source/interfac.cpp b/Source/interfac.cpp index 28fd47211..01f0ede33 100644 --- a/Source/interfac.cpp +++ b/Source/interfac.cpp @@ -36,7 +36,7 @@ void DrawCutscene() DWORD i; lock_buf(1); - CelDecodeOnly(SCREEN_X, 480 + SCREEN_Y - 1, (BYTE *)sgpBackCel, 1, 640); + CelDraw(SCREEN_X, 480 + SCREEN_Y - 1, (BYTE *)sgpBackCel, 1, 640); for (i = 0; i < sgdwProgress; i++) { DrawProgress( diff --git a/Source/inv.cpp b/Source/inv.cpp index 220d1c741..036f203e9 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -172,7 +172,7 @@ void DrawInv() BOOL invtest[NUM_INV_GRID_ELEM]; int frame, frame_width, colour, screen_x, screen_y, i, j, ii; - CelDecodeOnly(PANEL_RIGHT, 351 + SCREEN_Y, pInvCels, 1, 320); + CelDraw(PANEL_RIGHT, 351 + SCREEN_Y, pInvCels, 1, 320); if (plr[myplr].InvBody[INVLOC_HEAD]._itype != ITYPE_NONE) { InvDrawSlotBack(PANEL_RIGHT + 133, 59 + SCREEN_Y, 2 * INV_SLOT_SIZE_PX, 2 * INV_SLOT_SIZE_PX); @@ -188,13 +188,13 @@ void DrawInv() if (!plr[myplr].InvBody[INVLOC_HEAD]._iStatFlag) { colour = ICOL_RED; } - CelDecodeClr(colour, PANEL_RIGHT + 133, 59 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); + CelBlitOutline(colour, PANEL_RIGHT + 133, 59 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); } if (plr[myplr].InvBody[INVLOC_HEAD]._iStatFlag) { - CelDrawHdrOnly(PANEL_RIGHT + 133, 59 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); + CelClippedDraw(PANEL_RIGHT + 133, 59 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); } else { - CelDrawHdrLightRed(PANEL_RIGHT + 133, 59 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8, 1); + CelDrawLightRed(PANEL_RIGHT + 133, 59 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8, 1); } } @@ -212,13 +212,13 @@ void DrawInv() if (!plr[myplr].InvBody[INVLOC_RING_LEFT]._iStatFlag) { colour = ICOL_RED; } - CelDecodeClr(colour, PANEL_RIGHT + 48, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); + CelBlitOutline(colour, PANEL_RIGHT + 48, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); } if (plr[myplr].InvBody[INVLOC_RING_LEFT]._iStatFlag) { - CelDrawHdrOnly(PANEL_RIGHT + 48, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); + CelClippedDraw(PANEL_RIGHT + 48, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); } else { - CelDrawHdrLightRed(PANEL_RIGHT + 48, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8, 1); + CelDrawLightRed(PANEL_RIGHT + 48, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8, 1); } } @@ -236,13 +236,13 @@ void DrawInv() if (!plr[myplr].InvBody[INVLOC_RING_RIGHT]._iStatFlag) { colour = ICOL_RED; } - CelDecodeClr(colour, PANEL_RIGHT + 249, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); + CelBlitOutline(colour, PANEL_RIGHT + 249, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); } if (plr[myplr].InvBody[INVLOC_RING_RIGHT]._iStatFlag) { - CelDrawHdrOnly(PANEL_RIGHT + 249, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); + CelClippedDraw(PANEL_RIGHT + 249, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); } else { - CelDrawHdrLightRed(PANEL_RIGHT + 249, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8, 1); + CelDrawLightRed(PANEL_RIGHT + 249, 205 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8, 1); } } @@ -260,13 +260,13 @@ void DrawInv() if (!plr[myplr].InvBody[INVLOC_AMULET]._iStatFlag) { colour = ICOL_RED; } - CelDecodeClr(colour, PANEL_RIGHT + 205, 60 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); + CelBlitOutline(colour, PANEL_RIGHT + 205, 60 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); } if (plr[myplr].InvBody[INVLOC_AMULET]._iStatFlag) { - CelDrawHdrOnly(PANEL_RIGHT + 205, 60 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); + CelClippedDraw(PANEL_RIGHT + 205, 60 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); } else { - CelDrawHdrLightRed(PANEL_RIGHT + 205, 60 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8, 1); + CelDrawLightRed(PANEL_RIGHT + 205, 60 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8, 1); } } @@ -287,13 +287,13 @@ void DrawInv() if (!plr[myplr].InvBody[INVLOC_HAND_LEFT]._iStatFlag) { colour = ICOL_RED; } - CelDecodeClr(colour, screen_x, screen_y, pCursCels, frame, frame_width, 0, 8); + CelBlitOutline(colour, screen_x, screen_y, pCursCels, frame, frame_width, 0, 8); } if (plr[myplr].InvBody[INVLOC_HAND_LEFT]._iStatFlag) { - CelDrawHdrOnly(screen_x, screen_y, pCursCels, frame, frame_width, 0, 8); + CelClippedDraw(screen_x, screen_y, pCursCels, frame, frame_width, 0, 8); } else { - CelDrawHdrLightRed(screen_x, screen_y, pCursCels, frame, frame_width, 0, 8, 1); + CelDrawLightRed(screen_x, screen_y, pCursCels, frame, frame_width, 0, 8, 1); } if (plr[myplr].InvBody[INVLOC_HAND_LEFT]._iLoc == ILOC_TWOHAND) { @@ -301,7 +301,7 @@ void DrawInv() light_table_index = 0; cel_transparency_active = 1; - CelDecodeHdrLightTrans( + CelClippedBlitLightTrans( frame_width == INV_SLOT_SIZE_PX ? &gpBuffer[SCREENXY(PANEL_RIGHT + 197, SCREEN_Y)] : &gpBuffer[SCREENXY(PANEL_RIGHT + 183, SCREEN_Y)], @@ -327,13 +327,13 @@ void DrawInv() if (!plr[myplr].InvBody[INVLOC_HAND_RIGHT]._iStatFlag) { colour = ICOL_RED; } - CelDecodeClr(colour, screen_x, screen_y, pCursCels, frame, frame_width, 0, 8); + CelBlitOutline(colour, screen_x, screen_y, pCursCels, frame, frame_width, 0, 8); } if (plr[myplr].InvBody[INVLOC_HAND_RIGHT]._iStatFlag) { - CelDrawHdrOnly(screen_x, screen_y, pCursCels, frame, frame_width, 0, 8); + CelClippedDraw(screen_x, screen_y, pCursCels, frame, frame_width, 0, 8); } else { - CelDrawHdrLightRed(screen_x, screen_y, pCursCels, frame, frame_width, 0, 8, 1); + CelDrawLightRed(screen_x, screen_y, pCursCels, frame, frame_width, 0, 8, 1); } } @@ -351,13 +351,13 @@ void DrawInv() if (!plr[myplr].InvBody[INVLOC_CHEST]._iStatFlag) { colour = ICOL_RED; } - CelDecodeClr(colour, PANEL_RIGHT + 133, 160 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); + CelBlitOutline(colour, PANEL_RIGHT + 133, 160 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); } if (plr[myplr].InvBody[INVLOC_CHEST]._iStatFlag) { - CelDrawHdrOnly(PANEL_RIGHT + 133, 160 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); + CelClippedDraw(PANEL_RIGHT + 133, 160 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8); } else { - CelDrawHdrLightRed(PANEL_RIGHT + 133, 160 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8, 1); + CelDrawLightRed(PANEL_RIGHT + 133, 160 + SCREEN_Y, pCursCels, frame, frame_width, 0, 8, 1); } } @@ -388,7 +388,7 @@ void DrawInv() if (!plr[myplr].InvList[ii]._iStatFlag) { colour = ICOL_RED; } - CelDecodeClr( + CelBlitOutline( colour, InvRect[j + SLOTXY_INV_FIRST].X + SCREEN_X, InvRect[j + SLOTXY_INV_FIRST].Y + SCREEN_Y - 1, @@ -396,12 +396,12 @@ void DrawInv() } if (plr[myplr].InvList[ii]._iStatFlag) { - CelDrawHdrOnly( + CelClippedDraw( InvRect[j + SLOTXY_INV_FIRST].X + SCREEN_X, InvRect[j + SLOTXY_INV_FIRST].Y + SCREEN_Y - 1, pCursCels, frame, frame_width, 0, 8); } else { - CelDrawHdrLightRed( + CelDrawLightRed( InvRect[j + SLOTXY_INV_FIRST].X + SCREEN_X, InvRect[j + SLOTXY_INV_FIRST].Y + SCREEN_Y - 1, pCursCels, frame, frame_width, 0, 8, 1); @@ -436,13 +436,13 @@ void DrawInvBelt() colour = ICOL_BLUE; if (!plr[myplr].SpdList[i]._iStatFlag) colour = ICOL_RED; - CelDecodeClr(colour, InvRect[i + 65].X + 64, InvRect[i + 65].Y + 159, pCursCels, frame, frame_width, 0, 8); + CelBlitOutline(colour, InvRect[i + 65].X + 64, InvRect[i + 65].Y + 159, pCursCels, frame, frame_width, 0, 8); } if (plr[myplr].SpdList[i]._iStatFlag) - CelDrawHdrOnly(InvRect[i + 65].X + 64, InvRect[i + 65].Y + 159, pCursCels, frame, frame_width, 0, 8); + CelClippedDraw(InvRect[i + 65].X + 64, InvRect[i + 65].Y + 159, pCursCels, frame, frame_width, 0, 8); else - CelDrawHdrLightRed(InvRect[i + 65].X + 64, InvRect[i + 65].Y + 159, pCursCels, frame, frame_width, 0, 8, 1); + CelDrawLightRed(InvRect[i + 65].X + 64, InvRect[i + 65].Y + 159, pCursCels, frame, frame_width, 0, 8, 1); if (AllItemsList[plr[myplr].SpdList[i].IDidx].iUsable && plr[myplr].SpdList[i]._iStatFlag diff --git a/Source/items.cpp b/Source/items.cpp index 0153903e3..9c9cd3b51 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -2908,7 +2908,7 @@ void PrintItemPower(char plidx, ItemStruct *x) void DrawUTextBack() { - CelDecodeOnly(88, 487, pSTextBoxCels, 1, 271); + CelDraw(88, 487, pSTextBoxCels, 1, 271); #define TRANS_RECT_X 27 #define TRANS_RECT_Y 28 diff --git a/Source/minitext.cpp b/Source/minitext.cpp index 9d0eb0a3c..194db7ec1 100644 --- a/Source/minitext.cpp +++ b/Source/minitext.cpp @@ -66,7 +66,7 @@ void InitQTextMsg(int m) void DrawQTextBack() { - CelDecodeOnly(88, 487, pTextBoxCels, 1, 591); + CelDraw(88, 487, pTextBoxCels, 1, 591); #define TRANS_RECT_X 27 #define TRANS_RECT_Y 28 diff --git a/Source/quests.cpp b/Source/quests.cpp index 8e5ceab5f..e0a60344d 100644 --- a/Source/quests.cpp +++ b/Source/quests.cpp @@ -714,7 +714,7 @@ void PrintQLString(int x, int y, BOOL cjustflag, char *str, int col) off += k; } if (qline == y) { - CelDecodeOnly(cjustflag ? x + k + 76 : x + 76, s + 205, pSPentSpn2Cels, ALLQUESTS, 12); + CelDraw(cjustflag ? x + k + 76 : x + 76, s + 205, pSPentSpn2Cels, ALLQUESTS, 12); } for (i = 0; i < len; i++) { c = fontframe[gbFontTransTbl[(BYTE)str[i]]]; @@ -725,7 +725,7 @@ void PrintQLString(int x, int y, BOOL cjustflag, char *str, int col) off += fontkern[c] + 1; } if (qline == y) { - CelDecodeOnly(cjustflag ? x + k + 100 : 340 - x, s + 205, pSPentSpn2Cels, ALLQUESTS, 12); + CelDraw(cjustflag ? x + k + 100 : 340 - x, s + 205, pSPentSpn2Cels, ALLQUESTS, 12); } } @@ -734,7 +734,7 @@ void DrawQuestLog() int y, i; PrintQLString(0, 2, TRUE, "Quest Log", 3); - CelDecodeOnly(64, 511, pQLogCel, 1, 320); + CelDraw(64, 511, pQLogCel, 1, 320); y = qtopline; for (i = 0; i < numqlines; i++) { PrintQLString(0, y, TRUE, questlist[qlist[i]]._qlstr, 0); diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index c722cb429..1b331dfe5 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -153,14 +153,14 @@ static void scrollrt_draw_cursor_item() if (!plr[myplr].HoldItem._iStatFlag) { col = PAL16_RED + 5; } - CelDrawHdrClrHL(col, mx + SCREEN_X, my + cursH + SCREEN_Y - 1, pCursCels, pcurs, cursW, 0, 8); + CelBlitOutlineSafe(col, mx + SCREEN_X, my + cursH + SCREEN_Y - 1, pCursCels, pcurs, cursW, 0, 8); if (col != PAL16_RED + 5) { - Cel2DrawHdrOnly(mx + SCREEN_X, my + cursH + SCREEN_Y - 1, pCursCels, pcurs, cursW, 0, 8); + CelClippedDrawSafe(mx + SCREEN_X, my + cursH + SCREEN_Y - 1, pCursCels, pcurs, cursW, 0, 8); } else { - Cel2DrawHdrLightRed(mx + SCREEN_X, my + cursH + SCREEN_Y - 1, pCursCels, pcurs, cursW, 0, 8, 1); + CelDrawLightRedSafe(mx + SCREEN_X, my + cursH + SCREEN_Y - 1, pCursCels, pcurs, cursW, 0, 8, 1); } } else { - Cel2DrawHdrOnly(mx + SCREEN_X, my + cursH + SCREEN_Y - 1, pCursCels, pcurs, cursW, 0, 8); + CelClippedDrawSafe(mx + SCREEN_X, my + cursH + SCREEN_Y - 1, pCursCels, pcurs, cursW, 0, 8); } } @@ -192,11 +192,11 @@ void DrawMissile(int x, int y, int sx, int sy, int CelSkip, int CelCap, BOOL pre mx = sx + m->_mixoff - m->_miAnimWidth2; my = sy + m->_miyoff; if (m->_miUniqTrans) - Cl2DecodeFrm3(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap, m->_miUniqTrans + 3); + Cl2DrawLightTbl(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap, m->_miUniqTrans + 3); else if (m->_miLightFlag) - Cl2DecodeLightTbl(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap); + Cl2DrawLight(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap); else - Cl2DecodeFrm1(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap); + Cl2Draw(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap); } } } else { @@ -216,11 +216,11 @@ void DrawMissile(int x, int y, int sx, int sy, int CelSkip, int CelCap, BOOL pre mx = sx + m->_mixoff - m->_miAnimWidth2; my = sy + m->_miyoff; if (m->_miUniqTrans) - Cl2DecodeFrm3(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap, m->_miUniqTrans + 3); + Cl2DrawLightTbl(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap, m->_miUniqTrans + 3); else if (m->_miLightFlag) - Cl2DecodeLightTbl(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap); + Cl2DrawLight(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap); else - Cl2DecodeFrm1(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap); + Cl2Draw(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap); } } } @@ -253,11 +253,11 @@ void DrawClippedMissile(int x, int y, int sx, int sy, int CelSkip, int CelCap, B mx = sx + m->_mixoff - m->_miAnimWidth2; my = sy + m->_miyoff; if (m->_miUniqTrans) - Cl2DecodeFrm5(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap, m->_miUniqTrans + 3); + Cl2DrawLightTblSafe(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap, m->_miUniqTrans + 3); else if (m->_miLightFlag) - Cl2DecodeFrm6(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap); + Cl2DrawLightSafe(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap); else - Cl2DecodeFrm4(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap); + Cl2DrawSafe(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap); } } } else { @@ -277,11 +277,11 @@ void DrawClippedMissile(int x, int y, int sx, int sy, int CelSkip, int CelCap, B mx = sx + m->_mixoff - m->_miAnimWidth2; my = sy + m->_miyoff; if (m->_miUniqTrans) - Cl2DecodeFrm5(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap, m->_miUniqTrans + 3); + Cl2DrawLightTblSafe(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap, m->_miUniqTrans + 3); else if (m->_miLightFlag) - Cl2DecodeFrm6(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap); + Cl2DrawLightSafe(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap); else - Cl2DecodeFrm4(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap); + Cl2DrawSafe(mx, my, m->_miAnimData, m->_miAnimFrame, m->_miAnimWidth, CelSkip, CelCap); } } } @@ -323,7 +323,7 @@ static void DrawMonster(int x, int y, int mx, int my, int m, int CelSkip, int Ce } if (!(dFlags[x][y] & BFLAG_LIT)) { - Cl2DecodeFrm3(mx, my, monster[m]._mAnimData, monster[m]._mAnimFrame, monster[m].MType->width, CelSkip, CelCap, 1); + Cl2DrawLightTbl(mx, my, monster[m]._mAnimData, monster[m]._mAnimFrame, monster[m].MType->width, CelSkip, CelCap, 1); } else { trans = 0; if (monster[m]._uniqtype) @@ -333,9 +333,9 @@ static void DrawMonster(int x, int y, int mx, int my, int m, int CelSkip, int Ce if (plr[myplr]._pInfraFlag && light_table_index > 8) trans = 1; if (trans) - Cl2DecodeFrm3(mx, my, monster[m]._mAnimData, monster[m]._mAnimFrame, monster[m].MType->width, CelSkip, CelCap, trans); + Cl2DrawLightTbl(mx, my, monster[m]._mAnimData, monster[m]._mAnimFrame, monster[m].MType->width, CelSkip, CelCap, trans); else - Cl2DecodeLightTbl(mx, my, monster[m]._mAnimData, monster[m]._mAnimFrame, monster[m].MType->width, CelSkip, CelCap); + Cl2DrawLight(mx, my, monster[m]._mAnimData, monster[m]._mAnimFrame, monster[m].MType->width, CelSkip, CelCap); } } @@ -376,7 +376,7 @@ static void DrawClippedMonster(int x, int y, int mx, int my, int m, int CelSkip, } if (!(dFlags[x][y] & BFLAG_LIT)) { - Cl2DecodeFrm5(mx, my, monster[m]._mAnimData, monster[m]._mAnimFrame, monster[m].MType->width, CelSkip, CelCap, 1); + Cl2DrawLightTblSafe(mx, my, monster[m]._mAnimData, monster[m]._mAnimFrame, monster[m].MType->width, CelSkip, CelCap, 1); } else { trans = 0; if (monster[m]._uniqtype) @@ -386,9 +386,9 @@ static void DrawClippedMonster(int x, int y, int mx, int my, int m, int CelSkip, if (plr[myplr]._pInfraFlag && light_table_index > 8) trans = 1; if (trans) - Cl2DecodeFrm5(mx, my, monster[m]._mAnimData, monster[m]._mAnimFrame, monster[m].MType->width, CelSkip, CelCap, trans); + Cl2DrawLightTblSafe(mx, my, monster[m]._mAnimData, monster[m]._mAnimFrame, monster[m].MType->width, CelSkip, CelCap, trans); else - Cl2DecodeFrm6(mx, my, monster[m]._mAnimData, monster[m]._mAnimFrame, monster[m].MType->width, CelSkip, CelCap); + Cl2DrawLightSafe(mx, my, monster[m]._mAnimData, monster[m]._mAnimFrame, monster[m].MType->width, CelSkip, CelCap); } } @@ -420,11 +420,11 @@ static void DrawPlayer(int pnum, int x, int y, int px, int py, BYTE *pCelBuff, i return; } if (pnum == pcursplr) - Cl2DecodeFrm2(165, px, py, pCelBuff, nCel, nWidth, CelSkip, CelCap); + Cl2DrawOutline(165, px, py, pCelBuff, nCel, nWidth, CelSkip, CelCap); if (pnum == myplr) { - Cl2DecodeFrm1(px, py, pCelBuff, nCel, nWidth, CelSkip, CelCap); + Cl2Draw(px, py, pCelBuff, nCel, nWidth, CelSkip, CelCap); if (plr[pnum].pManaShield) - Cl2DecodeFrm1( + Cl2Draw( px + plr[pnum]._pAnimWidth2 - misfiledata[MFILE_MANASHLD].mAnimWidth2[0], py, misfiledata[MFILE_MANASHLD].mAnimData[0], @@ -433,9 +433,9 @@ static void DrawPlayer(int pnum, int x, int y, int px, int py, BYTE *pCelBuff, i CelSkip, CelCap); } else if (!(dFlags[x][y] & BFLAG_LIT) || plr[myplr]._pInfraFlag && light_table_index > 8) { - Cl2DecodeFrm3(px, py, pCelBuff, nCel, nWidth, CelSkip, CelCap, 1); + Cl2DrawLightTbl(px, py, pCelBuff, nCel, nWidth, CelSkip, CelCap, 1); if (plr[pnum].pManaShield) - Cl2DecodeFrm3( + Cl2DrawLightTbl( px + plr[pnum]._pAnimWidth2 - misfiledata[MFILE_MANASHLD].mAnimWidth2[0], py, misfiledata[MFILE_MANASHLD].mAnimData[0], @@ -450,9 +450,9 @@ static void DrawPlayer(int pnum, int x, int y, int px, int py, BYTE *pCelBuff, i light_table_index = 0; else light_table_index -= 5; - Cl2DecodeLightTbl(px, py, pCelBuff, nCel, nWidth, CelSkip, CelCap); + Cl2DrawLight(px, py, pCelBuff, nCel, nWidth, CelSkip, CelCap); if (plr[pnum].pManaShield) - Cl2DecodeLightTbl( + Cl2DrawLight( px + plr[pnum]._pAnimWidth2 - misfiledata[MFILE_MANASHLD].mAnimWidth2[0], py, misfiledata[MFILE_MANASHLD].mAnimData[0], @@ -493,11 +493,11 @@ static void DrawClippedPlayer(int pnum, int x, int y, int px, int py, BYTE *pCel return; } if (pnum == pcursplr) - Cl2DecodeClrHL(165, px, py, pCelBuff, nCel, nWidth, CelSkip, CelCap); + Cl2DrawOutlineSafe(165, px, py, pCelBuff, nCel, nWidth, CelSkip, CelCap); if (pnum == myplr) { - Cl2DecodeFrm4(px, py, pCelBuff, nCel, nWidth, CelSkip, CelCap); + Cl2DrawSafe(px, py, pCelBuff, nCel, nWidth, CelSkip, CelCap); if (plr[pnum].pManaShield) - Cl2DecodeFrm4( + Cl2DrawSafe( px + plr[pnum]._pAnimWidth2 - misfiledata[MFILE_MANASHLD].mAnimWidth2[0], py, misfiledata[MFILE_MANASHLD].mAnimData[0], @@ -506,9 +506,9 @@ static void DrawClippedPlayer(int pnum, int x, int y, int px, int py, BYTE *pCel CelSkip, CelCap); } else if (!(dFlags[x][y] & BFLAG_LIT) || plr[myplr]._pInfraFlag && light_table_index > 8) { - Cl2DecodeFrm5(px, py, pCelBuff, nCel, nWidth, CelSkip, CelCap, 1); + Cl2DrawLightTblSafe(px, py, pCelBuff, nCel, nWidth, CelSkip, CelCap, 1); if (plr[pnum].pManaShield) - Cl2DecodeFrm5( + Cl2DrawLightTblSafe( px + plr[pnum]._pAnimWidth2 - misfiledata[MFILE_MANASHLD].mAnimWidth2[0], py, misfiledata[MFILE_MANASHLD].mAnimData[0], @@ -523,9 +523,9 @@ static void DrawClippedPlayer(int pnum, int x, int y, int px, int py, BYTE *pCel light_table_index = 0; else light_table_index -= 5; - Cl2DecodeFrm6(px, py, pCelBuff, nCel, nWidth, CelSkip, CelCap); + Cl2DrawLightSafe(px, py, pCelBuff, nCel, nWidth, CelSkip, CelCap); if (plr[pnum].pManaShield) - Cl2DecodeFrm6( + Cl2DrawLightSafe( px + plr[pnum]._pAnimWidth2 - misfiledata[MFILE_MANASHLD].mAnimWidth2[0], py, misfiledata[MFILE_MANASHLD].mAnimData[0], @@ -617,13 +617,13 @@ static void DrawObject(int x, int y, int ox, int oy, BOOL pre, int CelSkip, int } if (bv == pcursobj) - CelDecodeClr(194, sx, sy, object[bv]._oAnimData, object[bv]._oAnimFrame, object[bv]._oAnimWidth, CelSkip, CelCap); + CelBlitOutline(194, sx, sy, object[bv]._oAnimData, object[bv]._oAnimFrame, object[bv]._oAnimWidth, CelSkip, CelCap); if (object[bv]._oLight) { - CelDecodeHdrLightOnly(sx, sy, object[bv]._oAnimData, object[bv]._oAnimFrame, object[bv]._oAnimWidth, CelSkip, CelCap); + CelClippedDrawLight(sx, sy, object[bv]._oAnimData, object[bv]._oAnimFrame, object[bv]._oAnimWidth, CelSkip, CelCap); } else { /// ASSERT: assert(object[bv]._oAnimData); if (object[bv]._oAnimData) // BUGFIX: _oAnimData was already checked, this is redundant - CelDrawHdrOnly(sx, sy, object[bv]._oAnimData, object[bv]._oAnimFrame, object[bv]._oAnimWidth, CelSkip, CelCap); + CelClippedDraw(sx, sy, object[bv]._oAnimData, object[bv]._oAnimFrame, object[bv]._oAnimWidth, CelSkip, CelCap); } } @@ -670,11 +670,11 @@ static void DrawClippedObject(int x, int y, int ox, int oy, BOOL pre, int CelSki } if (bv == pcursobj) - CelDrawHdrClrHL(194, sx, sy, object[bv]._oAnimData, object[bv]._oAnimFrame, object[bv]._oAnimWidth, CelSkip, CelCap); + CelBlitOutlineSafe(194, sx, sy, object[bv]._oAnimData, object[bv]._oAnimFrame, object[bv]._oAnimWidth, CelSkip, CelCap); if (object[bv]._oLight) - Cel2DecodeHdrLight(sx, sy, object[bv]._oAnimData, object[bv]._oAnimFrame, object[bv]._oAnimWidth, CelSkip, CelCap); + CelDrawLightSafe(sx, sy, object[bv]._oAnimData, object[bv]._oAnimFrame, object[bv]._oAnimWidth, CelSkip, CelCap); else - Cel2DrawHdrOnly(sx, sy, object[bv]._oAnimData, object[bv]._oAnimFrame, object[bv]._oAnimWidth, CelSkip, CelCap); + CelClippedDrawSafe(sx, sy, object[bv]._oAnimData, object[bv]._oAnimFrame, object[bv]._oAnimWidth, CelSkip, CelCap); } static void scrollrt_draw_clipped_dungeon(BYTE *pBuff, int sx, int sy, int dx, int dy, int eflag); @@ -754,7 +754,7 @@ static void scrollrt_draw_clipped_dungeon(BYTE *pBuff, int sx, int sy, int dx, i negMon = dMonster[sx][sy - 1]; if (visiondebug && bFlag & BFLAG_LIT) { - Cel2DecodeHdrOnly(pBuff, pSquareCel, 1, 64, 0, 8); + CelClippedBlitSafe(pBuff, pSquareCel, 1, 64, 0, 8); } if (MissilePreFlag && bFlag & BFLAG_MISSILE) { DrawClippedMissile(sx, sy, dx, dy, 0, 8, 1); @@ -771,9 +771,9 @@ static void scrollrt_draw_clipped_dungeon(BYTE *pBuff, int sx, int sy, int dx, i nCel = pDeadGuy->_deadFrame; if (nCel >= 1 && pFrameTable[0] <= 50 && nCel <= (int)pFrameTable[0]) { if (pDeadGuy->_deadtrans != 0) { - Cl2DecodeFrm5(px, dy, pCelBuff, nCel, pDeadGuy->_deadWidth, 0, 8, pDeadGuy->_deadtrans); + Cl2DrawLightTblSafe(px, dy, pCelBuff, nCel, pDeadGuy->_deadWidth, 0, 8, pDeadGuy->_deadtrans); } else { - Cl2DecodeFrm6(px, dy, pCelBuff, pDeadGuy->_deadFrame, pDeadGuy->_deadWidth, 0, 8); + Cl2DrawLightSafe(px, dy, pCelBuff, pDeadGuy->_deadFrame, pDeadGuy->_deadWidth, 0, 8); } } else { // app_fatal("Clipped dead sub: frame %d of %d, deadnum==%d", nCel, pFrameTable[0], (bDead & 0x1F) - 1); @@ -796,9 +796,9 @@ static void scrollrt_draw_clipped_dungeon(BYTE *pBuff, int sx, int sy, int dx, i if (nCel >= 1 && pFrameTable[0] <= 50 && nCel <= (int)pFrameTable[0]) { px = dx - pItem->_iAnimWidth2; if (bItem - 1 == pcursitem) { - CelDrawHdrClrHL(181, px, dy, pCelBuff, nCel, pItem->_iAnimWidth, 0, 8); + CelBlitOutlineSafe(181, px, dy, pCelBuff, nCel, pItem->_iAnimWidth, 0, 8); } - Cel2DecodeHdrLight(px, dy, pItem->_iAnimData, pItem->_iAnimFrame, pItem->_iAnimWidth, 0, 8); + CelDrawLightSafe(px, dy, pItem->_iAnimData, pItem->_iAnimFrame, pItem->_iAnimWidth, 0, 8); } else { /* app_fatal( @@ -841,7 +841,7 @@ static void scrollrt_draw_clipped_dungeon(BYTE *pBuff, int sx, int sy, int dx, i px = dx + pMonster->_mxoff - pMonster->MType->width2; py = dy + pMonster->_myoff; if (draw_monster_num == pcursmonst) { - Cl2DecodeClrHL(233, px, py, pMonster->_mAnimData, pMonster->_mAnimFrame, pMonster->MType->width, 0, 8); + Cl2DrawOutlineSafe(233, px, py, pMonster->_mAnimData, pMonster->_mAnimFrame, pMonster->MType->width, 0, 8); } DrawClippedMonster(sx, sy, px, py, draw_monster_num, 0, 8); if (eflag && pMonster->_meflag) { @@ -884,7 +884,7 @@ static void scrollrt_draw_clipped_dungeon(BYTE *pBuff, int sx, int sy, int dx, i px = dx + pMonster->_mxoff - pMonster->MType->width2; py = dy + pMonster->_myoff; if (draw_monster_num == pcursmonst) { - Cl2DecodeClrHL(233, px, py, pMonster->_mAnimData, pMonster->_mAnimFrame, pMonster->MType->width, 0, 8); + Cl2DrawOutlineSafe(233, px, py, pMonster->_mAnimData, pMonster->_mAnimFrame, pMonster->MType->width, 0, 8); } DrawClippedMonster(sx, sy, px, py, draw_monster_num, 0, 8); if (eflag && pMonster->_meflag) { @@ -916,9 +916,9 @@ static void scrollrt_draw_clipped_dungeon(BYTE *pBuff, int sx, int sy, int dx, i if (nCel >= 1 && pFrameTable[0] <= 50 && nCel <= (int)pFrameTable[0]) { px = dx - pItem->_iAnimWidth2; if (bItem - 1 == pcursitem) { - CelDrawHdrClrHL(181, px, dy, pCelBuff, nCel, pItem->_iAnimWidth, 0, 8); + CelBlitOutlineSafe(181, px, dy, pCelBuff, nCel, pItem->_iAnimWidth, 0, 8); } - Cel2DecodeHdrLight(px, dy, pItem->_iAnimData, pItem->_iAnimFrame, pItem->_iAnimWidth, 0, 8); + CelDrawLightSafe(px, dy, pItem->_iAnimData, pItem->_iAnimFrame, pItem->_iAnimWidth, 0, 8); } else { /* app_fatal( @@ -937,7 +937,7 @@ static void scrollrt_draw_clipped_dungeon(BYTE *pBuff, int sx, int sy, int dx, i } if (bArch != 0) { cel_transparency_active = TransList[bMap]; - Cel2DecodeLightTrans(pBuff, pSpecialCels, bArch, 64, 0, 8); + CelClippedBlitLightTransSafe(pBuff, pSpecialCels, bArch, 64, 0, 8); } } @@ -1186,7 +1186,7 @@ static void scrollrt_draw_clipped_dungeon_2(BYTE *pBuff, int sx, int sy, int ski negMon = dMonster[sx][sy - 1]; if (visiondebug && bFlag & BFLAG_LIT) { - Cel2DecodeHdrOnly(pBuff, pSquareCel, 1, 64, CelSkip, 8); + CelClippedBlitSafe(pBuff, pSquareCel, 1, 64, CelSkip, 8); } if (MissilePreFlag && bFlag & BFLAG_MISSILE) { DrawClippedMissile(sx, sy, dx, dy, CelSkip, 8, 1); @@ -1203,9 +1203,9 @@ static void scrollrt_draw_clipped_dungeon_2(BYTE *pBuff, int sx, int sy, int ski nCel = pDeadGuy->_deadFrame; if (nCel >= 1 && pFrameTable[0] <= 50 && nCel <= (int)pFrameTable[0]) { if (pDeadGuy->_deadtrans != 0) { - Cl2DecodeFrm5(px, dy, pCelBuff, nCel, pDeadGuy->_deadWidth, CelSkip, 8, pDeadGuy->_deadtrans); + Cl2DrawLightTblSafe(px, dy, pCelBuff, nCel, pDeadGuy->_deadWidth, CelSkip, 8, pDeadGuy->_deadtrans); } else { - Cl2DecodeFrm6(px, dy, pCelBuff, pDeadGuy->_deadFrame, pDeadGuy->_deadWidth, CelSkip, 8); + Cl2DrawLightSafe(px, dy, pCelBuff, pDeadGuy->_deadFrame, pDeadGuy->_deadWidth, CelSkip, 8); } } else { // app_fatal("Clipped dead sub2: frame %d of %d, deadnum==%d", nCel, pFrameTable[0], (bDead & 0x1F) - 1); @@ -1228,9 +1228,9 @@ static void scrollrt_draw_clipped_dungeon_2(BYTE *pBuff, int sx, int sy, int ski if (nCel >= 1 && pFrameTable[0] <= 50 && nCel <= (int)pFrameTable[0]) { px = dx - pItem->_iAnimWidth2; if (bItem - 1 == pcursitem) { - CelDrawHdrClrHL(181, px, dy, pCelBuff, nCel, pItem->_iAnimWidth, CelSkip, 8); + CelBlitOutlineSafe(181, px, dy, pCelBuff, nCel, pItem->_iAnimWidth, CelSkip, 8); } - Cel2DecodeHdrLight(px, dy, pItem->_iAnimData, pItem->_iAnimFrame, pItem->_iAnimWidth, CelSkip, 8); + CelDrawLightSafe(px, dy, pItem->_iAnimData, pItem->_iAnimFrame, pItem->_iAnimWidth, CelSkip, 8); } else { /* app_fatal( @@ -1273,7 +1273,7 @@ static void scrollrt_draw_clipped_dungeon_2(BYTE *pBuff, int sx, int sy, int ski px = dx + pMonster->_mxoff - pMonster->MType->width2; py = dy + pMonster->_myoff; if (draw_monster_num == pcursmonst) { - Cl2DecodeClrHL(233, px, py, pMonster->_mAnimData, pMonster->_mAnimFrame, pMonster->MType->width, CelSkip, 8); + Cl2DrawOutlineSafe(233, px, py, pMonster->_mAnimData, pMonster->_mAnimFrame, pMonster->MType->width, CelSkip, 8); } DrawClippedMonster(sx, sy, px, py, draw_monster_num, CelSkip, 8); if (eflag && !pMonster->_meflag) { @@ -1316,7 +1316,7 @@ static void scrollrt_draw_clipped_dungeon_2(BYTE *pBuff, int sx, int sy, int ski px = dx + pMonster->_mxoff - pMonster->MType->width2; py = dy + pMonster->_myoff; if (draw_monster_num == pcursmonst) { - Cl2DecodeClrHL(233, px, py, pMonster->_mAnimData, pMonster->_mAnimFrame, pMonster->MType->width, CelSkip, 8); + Cl2DrawOutlineSafe(233, px, py, pMonster->_mAnimData, pMonster->_mAnimFrame, pMonster->MType->width, CelSkip, 8); } DrawClippedMonster(sx, sy, px, py, draw_monster_num, CelSkip, 8); if (eflag && !pMonster->_meflag) { @@ -1348,9 +1348,9 @@ static void scrollrt_draw_clipped_dungeon_2(BYTE *pBuff, int sx, int sy, int ski if (nCel >= 1 && pFrameTable[0] <= 50 && nCel <= (int)pFrameTable[0]) { px = dx - pItem->_iAnimWidth2; if (bItem - 1 == pcursitem) { - CelDrawHdrClrHL(181, px, dy, pCelBuff, nCel, pItem->_iAnimWidth, CelSkip, 8); + CelBlitOutlineSafe(181, px, dy, pCelBuff, nCel, pItem->_iAnimWidth, CelSkip, 8); } - Cel2DecodeHdrLight(px, dy, pItem->_iAnimData, pItem->_iAnimFrame, pItem->_iAnimWidth, CelSkip, 8); + CelDrawLightSafe(px, dy, pItem->_iAnimData, pItem->_iAnimFrame, pItem->_iAnimWidth, CelSkip, 8); } else { /* app_fatal( @@ -1369,7 +1369,7 @@ static void scrollrt_draw_clipped_dungeon_2(BYTE *pBuff, int sx, int sy, int ski } if (bArch != 0) { cel_transparency_active = TransList[bMap]; - Cel2DecodeLightTrans(pBuff, pSpecialCels, bArch, 64, CelSkip, 8); + CelClippedBlitLightTransSafe(pBuff, pSpecialCels, bArch, 64, CelSkip, 8); } } @@ -1551,7 +1551,7 @@ static void scrollrt_draw_dungeon(BYTE *pBuff, int sx, int sy, int capChunks, in negMon = dMonster[sx][sy - 1]; if (visiondebug && bFlag & BFLAG_LIT) { - CelDecodeHdrOnly(pBuff, pSquareCel, 1, 64, 0, CelCap); + CelClippedBlit(pBuff, pSquareCel, 1, 64, 0, CelCap); } tx = dx - 96; ty = dy - 16; @@ -1572,9 +1572,9 @@ static void scrollrt_draw_dungeon(BYTE *pBuff, int sx, int sy, int capChunks, in nCel = pDeadGuy->_deadFrame; if (nCel >= 1 && pFrameTable[0] <= 50 && nCel <= (int)pFrameTable[0]) { if (pDeadGuy->_deadtrans != 0) { - Cl2DecodeFrm3(px, dy, pCelBuff, nCel, pDeadGuy->_deadWidth, 0, CelCap, pDeadGuy->_deadtrans); + Cl2DrawLightTbl(px, dy, pCelBuff, nCel, pDeadGuy->_deadWidth, 0, CelCap, pDeadGuy->_deadtrans); } else { - Cl2DecodeLightTbl(px, dy, pCelBuff, pDeadGuy->_deadFrame, pDeadGuy->_deadWidth, 0, CelCap); + Cl2DrawLight(px, dy, pCelBuff, pDeadGuy->_deadFrame, pDeadGuy->_deadWidth, 0, CelCap); } } else { // app_fatal("Unclipped dead: frame %d of %d, deadnum==%d", nCel, pFrameTable[0], (bDead & 0x1F) - 1); @@ -1597,9 +1597,9 @@ static void scrollrt_draw_dungeon(BYTE *pBuff, int sx, int sy, int capChunks, in if (nCel >= 1 && pFrameTable[0] <= 50 && nCel <= (int)pFrameTable[0]) { px = dx - pItem->_iAnimWidth2; if (bItem - 1 == pcursitem) { - CelDecodeClr(181, px, dy, pCelBuff, nCel, pItem->_iAnimWidth, 0, CelCap); + CelBlitOutline(181, px, dy, pCelBuff, nCel, pItem->_iAnimWidth, 0, CelCap); } - CelDecodeHdrLightOnly(px, dy, pItem->_iAnimData, pItem->_iAnimFrame, pItem->_iAnimWidth, 0, CelCap); + CelClippedDrawLight(px, dy, pItem->_iAnimData, pItem->_iAnimFrame, pItem->_iAnimWidth, 0, CelCap); } else { // app_fatal("Draw \"%s\" Item 1: frame %d of %d, item type==%d", pItem->_iIName, nCel, pFrameTable[0], pItem->_itype); } @@ -1635,7 +1635,7 @@ static void scrollrt_draw_dungeon(BYTE *pBuff, int sx, int sy, int capChunks, in px = dx + pMonster->_mxoff - pMonster->MType->width2; py = dy + pMonster->_myoff; if (draw_monster_num == pcursmonst) { - Cl2DecodeFrm2(233, px, py, pMonster->_mAnimData, pMonster->_mAnimFrame, pMonster->MType->width, 0, CelCap); + Cl2DrawOutline(233, px, py, pMonster->_mAnimData, pMonster->_mAnimFrame, pMonster->MType->width, 0, CelCap); } DrawMonster(sx, sy, px, py, draw_monster_num, 0, CelCap); if (eflag && !pMonster->_meflag) { @@ -1678,7 +1678,7 @@ static void scrollrt_draw_dungeon(BYTE *pBuff, int sx, int sy, int capChunks, in px = dx + pMonster->_mxoff - pMonster->MType->width2; py = dy + pMonster->_myoff; if (draw_monster_num == pcursmonst) { - Cl2DecodeFrm2(233, px, py, pMonster->_mAnimData, pMonster->_mAnimFrame, pMonster->MType->width, 0, CelCap); + Cl2DrawOutline(233, px, py, pMonster->_mAnimData, pMonster->_mAnimFrame, pMonster->MType->width, 0, CelCap); } DrawMonster(sx, sy, px, py, draw_monster_num, 0, CelCap); if (eflag && !pMonster->_meflag) { @@ -1710,9 +1710,9 @@ static void scrollrt_draw_dungeon(BYTE *pBuff, int sx, int sy, int capChunks, in if (nCel >= 1 && pFrameTable[0] <= 50 && nCel <= (int)pFrameTable[0]) { px = dx - pItem->_iAnimWidth2; if (bItem - 1 == pcursitem) { - CelDecodeClr(181, px, dy, pCelBuff, nCel, pItem->_iAnimWidth, 0, CelCap); + CelBlitOutline(181, px, dy, pCelBuff, nCel, pItem->_iAnimWidth, 0, CelCap); } - CelDecodeHdrLightOnly(px, dy, pItem->_iAnimData, pItem->_iAnimFrame, pItem->_iAnimWidth, 0, CelCap); + CelClippedDrawLight(px, dy, pItem->_iAnimData, pItem->_iAnimFrame, pItem->_iAnimWidth, 0, CelCap); } else { // app_fatal("Draw \"%s\" Item 2: frame %d of %d, item type==%d", pItem->_iIName, nCel, pFrameTable[0], pItem->_itype); } @@ -1724,7 +1724,7 @@ static void scrollrt_draw_dungeon(BYTE *pBuff, int sx, int sy, int capChunks, in } if (bArch != 0) { cel_transparency_active = TransList[bMap]; - CelDecodeHdrLightTrans(pBuff, pSpecialCels, bArch, 64, 0, CelCap); + CelClippedBlitLightTrans(pBuff, pSpecialCels, bArch, 64, 0, CelCap); } } diff --git a/Source/stores.cpp b/Source/stores.cpp index e1743db34..2e25fe735 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -130,7 +130,7 @@ void FreeStoreMem() void DrawSTextBack() { - CelDecodeOnly(408, 487, pSTextBoxCels, 1, 271); + CelDraw(408, 487, pSTextBoxCels, 1, 271); #define TRANS_RECT_X 347 #define TRANS_RECT_Y 28 @@ -167,7 +167,7 @@ void PrintSString(int x, int y, BOOL cjustflag, char *str, char col, int val) off += k; } if (stextsel == y) { - CelDecodeOnly(cjustflag ? xx + x + k - 20 : xx + x - 20, s + 205, pSPentSpn2Cels, InStoreFlag, 12); + CelDraw(cjustflag ? xx + x + k - 20 : xx + x - 20, s + 205, pSPentSpn2Cels, InStoreFlag, 12); } for (i = 0; i < len; i++) { c = fontframe[gbFontTransTbl[(BYTE)str[i]]]; @@ -189,7 +189,7 @@ void PrintSString(int x, int y, BOOL cjustflag, char *str, char col, int val) } } if (stextsel == y) { - CelDecodeOnly(cjustflag ? xx + x + k + 4 : 660 - x, s + 205, pSPentSpn2Cels, InStoreFlag, 12); + CelDraw(cjustflag ? xx + x + k + 4 : 660 - x, s + 205, pSPentSpn2Cels, InStoreFlag, 12); } } @@ -248,16 +248,16 @@ void DrawSArrows(int y1, int y2) yd1 = SStringY[y1] + 204; yd2 = SStringY[y2] + 204; if (stextscrlubtn != -1) - CelDecodeOnly(665, yd1, pSTextSlidCels, 12, 12); + CelDraw(665, yd1, pSTextSlidCels, 12, 12); else - CelDecodeOnly(665, yd1, pSTextSlidCels, 10, 12); + CelDraw(665, yd1, pSTextSlidCels, 10, 12); if (stextscrldbtn != -1) - CelDecodeOnly(665, yd2, pSTextSlidCels, 11, 12); + CelDraw(665, yd2, pSTextSlidCels, 11, 12); else - CelDecodeOnly(665, yd2, pSTextSlidCels, 9, 12); + CelDraw(665, yd2, pSTextSlidCels, 9, 12); yd1 += 12; for (yd3 = yd1; yd3 < yd2; yd3 += 12) { - CelDecodeOnly(665, yd3, pSTextSlidCels, 14, 12); + CelDraw(665, yd3, pSTextSlidCels, 14, 12); } if (stextsel == 22) yd3 = stextlhold; @@ -267,7 +267,7 @@ void DrawSArrows(int y1, int y2) yd3 = 1000 * (stextsval + ((yd3 - stextup) >> 2)) / (storenumh - 1) * (SStringY[y2] - SStringY[y1] - 24) / 1000; else yd3 = 0; - CelDecodeOnly(665, SStringY[y1 + 1] + 204 + yd3, pSTextSlidCels, 13, 12); + CelDraw(665, SStringY[y1 + 1] + 204 + yd3, pSTextSlidCels, 13, 12); } void DrawSTextHelp() diff --git a/Source/town.cpp b/Source/town.cpp index 41cf40097..eb5cb9693 100644 --- a/Source/town.cpp +++ b/Source/town.cpp @@ -399,34 +399,34 @@ void town_draw_clipped_town(BYTE *pBuff, int sx, int sy, int dx, int dy, int efl bv = dItem[sx][sy] - 1; px = dx - item[bv]._iAnimWidth2; if (bv == pcursitem) { - CelDrawHdrClrHL(181, px, dy, item[bv]._iAnimData, item[bv]._iAnimFrame, item[bv]._iAnimWidth, 0, 8); + CelBlitOutlineSafe(181, px, dy, item[bv]._iAnimData, item[bv]._iAnimFrame, item[bv]._iAnimWidth, 0, 8); } - Cel2DrawHdrOnly(px, dy, item[bv]._iAnimData, item[bv]._iAnimFrame, item[bv]._iAnimWidth, 0, 8); + CelClippedDrawSafe(px, dy, item[bv]._iAnimData, item[bv]._iAnimFrame, item[bv]._iAnimWidth, 0, 8); } if (dFlags[sx][sy] & BFLAG_MONSTLR) { mi = -(dMonster[sx][sy - 1] + 1); px = dx - towner[mi]._tAnimWidth2; if (mi == pcursmonst) { - CelDrawHdrClrHL(166, px, dy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, 0, 8); + CelBlitOutlineSafe(166, px, dy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, 0, 8); } - Cel2DrawHdrOnly(px, dy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, 0, 8); + CelClippedDrawSafe(px, dy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, 0, 8); } if (dMonster[sx][sy] > 0) { mi = dMonster[sx][sy] - 1; px = dx - towner[mi]._tAnimWidth2; if (mi == pcursmonst) { - CelDrawHdrClrHL(166, px, dy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, 0, 8); + CelBlitOutlineSafe(166, px, dy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, 0, 8); } - Cel2DrawHdrOnly(px, dy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, 0, 8); + CelClippedDrawSafe(px, dy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, 0, 8); } if (dFlags[sx][sy] & BFLAG_PLAYERLR) { bv = -(dPlayer[sx][sy - 1] + 1); px = dx + plr[bv]._pxoff - plr[bv]._pAnimWidth2; py = dy + plr[bv]._pyoff; if (bv == pcursplr) { - Cl2DecodeClrHL(165, px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, 0, 8); + Cl2DrawOutlineSafe(165, px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, 0, 8); } - Cl2DecodeFrm4(px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, 0, 8); + Cl2DrawSafe(px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, 0, 8); if (eflag && plr[bv]._peflag) { town_draw_clipped_e_flag(pBuff - 64, sx - 1, sy + 1, dx - 64, dy); } @@ -439,9 +439,9 @@ void town_draw_clipped_town(BYTE *pBuff, int sx, int sy, int dx, int dy, int efl px = dx + plr[bv]._pxoff - plr[bv]._pAnimWidth2; py = dy + plr[bv]._pyoff; if (bv == pcursplr) { - Cl2DecodeClrHL(165, px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, 0, 8); + Cl2DrawOutlineSafe(165, px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, 0, 8); } - Cl2DecodeFrm4(px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, 0, 8); + Cl2DrawSafe(px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, 0, 8); if (eflag && plr[bv]._peflag) { town_draw_clipped_e_flag(pBuff - 64, sx - 1, sy + 1, dx - 64, dy); } @@ -581,34 +581,34 @@ void town_draw_clipped_town_2(BYTE *pBuff, int sx, int sy, int skipChunks, int C bv = dItem[sx][sy] - 1; px = dx - item[bv]._iAnimWidth2; if (bv == pcursitem) { - CelDrawHdrClrHL(181, px, dy, item[bv]._iAnimData, item[bv]._iAnimFrame, item[bv]._iAnimWidth, CelSkip, 8); + CelBlitOutlineSafe(181, px, dy, item[bv]._iAnimData, item[bv]._iAnimFrame, item[bv]._iAnimWidth, CelSkip, 8); } - Cel2DrawHdrOnly(px, dy, item[bv]._iAnimData, item[bv]._iAnimFrame, item[bv]._iAnimWidth, CelSkip, 8); + CelClippedDrawSafe(px, dy, item[bv]._iAnimData, item[bv]._iAnimFrame, item[bv]._iAnimWidth, CelSkip, 8); } if (dFlags[sx][sy] & BFLAG_MONSTLR) { mi = -(dMonster[sx][sy - 1] + 1); px = dx - towner[mi]._tAnimWidth2; if (mi == pcursmonst) { - CelDrawHdrClrHL(166, px, dy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, CelSkip, 8); + CelBlitOutlineSafe(166, px, dy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, CelSkip, 8); } - Cel2DrawHdrOnly(px, dy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, CelSkip, 8); + CelClippedDrawSafe(px, dy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, CelSkip, 8); } if (dMonster[sx][sy] > 0) { mi = dMonster[sx][sy] - 1; px = dx - towner[mi]._tAnimWidth2; if (mi == pcursmonst) { - CelDrawHdrClrHL(166, px, dy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, CelSkip, 8); + CelBlitOutlineSafe(166, px, dy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, CelSkip, 8); } - Cel2DrawHdrOnly(px, dy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, CelSkip, 8); + CelClippedDrawSafe(px, dy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, CelSkip, 8); } if (dFlags[sx][sy] & BFLAG_PLAYERLR) { bv = -(dPlayer[sx][sy - 1] + 1); px = dx + plr[bv]._pxoff - plr[bv]._pAnimWidth2; py = dy + plr[bv]._pyoff; if (bv == pcursplr) { - Cl2DecodeClrHL(165, px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, CelSkip, 8); + Cl2DrawOutlineSafe(165, px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, CelSkip, 8); } - Cl2DecodeFrm4(px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, CelSkip, 8); + Cl2DrawSafe(px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, CelSkip, 8); if (eflag && plr[bv]._peflag) { town_draw_clipped_e_flag_2(pBuff - 64, sx - 1, sy + 1, skipChunks, CelSkip, dx - 64, dy); } @@ -621,9 +621,9 @@ void town_draw_clipped_town_2(BYTE *pBuff, int sx, int sy, int skipChunks, int C px = dx + plr[bv]._pxoff - plr[bv]._pAnimWidth2; py = dy + plr[bv]._pyoff; if (bv == pcursplr) { - Cl2DecodeClrHL(165, px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, CelSkip, 8); + Cl2DrawOutlineSafe(165, px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, CelSkip, 8); } - Cl2DecodeFrm4(px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, CelSkip, 8); + Cl2DrawSafe(px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, CelSkip, 8); if (eflag && plr[bv]._peflag) { town_draw_clipped_e_flag_2(pBuff - 64, sx - 1, sy + 1, skipChunks, CelSkip, dx - 64, dy); } @@ -770,38 +770,38 @@ void town_draw_town_all(BYTE *pBuff, int x, int y, int capChunks, int CelCap, in bv = dItem[x][y] - 1; px = sx - item[bv]._iAnimWidth2; if (bv == pcursitem) { - CelDecodeClr(181, px, sy, item[bv]._iAnimData, item[bv]._iAnimFrame, item[bv]._iAnimWidth, 0, CelCap); + CelBlitOutline(181, px, sy, item[bv]._iAnimData, item[bv]._iAnimFrame, item[bv]._iAnimWidth, 0, CelCap); } /// ASSERT: assert(item[bv]._iAnimData); - CelDrawHdrOnly(px, sy, item[bv]._iAnimData, item[bv]._iAnimFrame, item[bv]._iAnimWidth, 0, CelCap); + CelClippedDraw(px, sy, item[bv]._iAnimData, item[bv]._iAnimFrame, item[bv]._iAnimWidth, 0, CelCap); } if (dFlags[x][y] & BFLAG_MONSTLR) { mi = -(dMonster[x][y - 1] + 1); px = sx - towner[mi]._tAnimWidth2; if (mi == pcursmonst) { - CelDecodeClr(166, px, sy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, 0, CelCap); + CelBlitOutline(166, px, sy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, 0, CelCap); } /// ASSERT: assert(towner[mi]._tAnimData); - CelDrawHdrOnly(px, sy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, 0, CelCap); + CelClippedDraw(px, sy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, 0, CelCap); } if (dMonster[x][y] > 0) { mi = dMonster[x][y] - 1; px = sx - towner[mi]._tAnimWidth2; if (mi == pcursmonst) { - CelDecodeClr(166, px, sy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, 0, CelCap); + CelBlitOutline(166, px, sy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, 0, CelCap); } /// ASSERT: assert(towner[mi]._tAnimData); - CelDrawHdrOnly(px, sy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, 0, CelCap); + CelClippedDraw(px, sy, towner[mi]._tAnimData, towner[mi]._tAnimFrame, towner[mi]._tAnimWidth, 0, CelCap); } if (dFlags[x][y] & BFLAG_PLAYERLR) { bv = -(dPlayer[x][y - 1] + 1); px = sx + plr[bv]._pxoff - plr[bv]._pAnimWidth2; py = sy + plr[bv]._pyoff; if (bv == pcursplr) { - Cl2DecodeFrm2(165, px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, 0, CelCap); + Cl2DrawOutline(165, px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, 0, CelCap); } /// ASSERT: assert(plr[bv]._pAnimData); - Cl2DecodeFrm1(px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, 0, CelCap); + Cl2Draw(px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, 0, CelCap); if (eflag && plr[bv]._peflag) { town_draw_e_flag(pBuff - 64, x - 1, y + 1, capChunks, CelCap, sx - 64, sy); } @@ -814,10 +814,10 @@ void town_draw_town_all(BYTE *pBuff, int x, int y, int capChunks, int CelCap, in px = sx + plr[bv]._pxoff - plr[bv]._pAnimWidth2; py = sy + plr[bv]._pyoff; if (bv == pcursplr) { - Cl2DecodeFrm2(165, px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, 0, CelCap); + Cl2DrawOutline(165, px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, 0, CelCap); } /// ASSERT: assert(plr[bv]._pAnimData); - Cl2DecodeFrm1(px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, 0, CelCap); + Cl2Draw(px, py, plr[bv]._pAnimData, plr[bv]._pAnimFrame, plr[bv]._pAnimWidth, 0, CelCap); if (eflag && plr[bv]._peflag) { town_draw_e_flag(pBuff - 64, x - 1, y + 1, capChunks, CelCap, sx - 64, sy); } diff --git a/comparer-config/diablo.toml b/comparer-config/diablo.toml index 248f921a5..03e64c4b9 100644 --- a/comparer-config/diablo.toml +++ b/comparer-config/diablo.toml @@ -1763,112 +1763,112 @@ addr = 0x41618E size = 0x6E [[func]] -name = "CelDrawDatOnly" +name = "CelBlit" addr = 0x41620C size = 0x68 [[func]] -name = "CelDecodeOnly" +name = "CelDraw" addr = 0x416274 size = 0x44 [[func]] -name = "CelDecDatOnly" +name = "CelBlitFrame" addr = 0x4162B8 size = 0x26 [[func]] -name = "CelDrawHdrOnly" +name = "CelClippedDraw" addr = 0x4162DE size = 0x7B [[func]] -name = "CelDecodeHdrOnly" +name = "CelClippedBlit" addr = 0x416359 size = 0x53 [[func]] -name = "CelDecDatLightOnly" +name = "CelBlitLight" addr = 0x4163AC size = 0xDC [[func]] -name = "CelDecDatLightTrans" +name = "CelBlitLightTrans" addr = 0x416488 size = 0xDD [[func]] -name = "CelDecodeLightOnly" +name = "CelDrawLight" addr = 0x416565 size = 0x58 [[func]] -name = "CelDecodeHdrLightOnly" +name = "CelClippedDrawLight" addr = 0x4165BD size = 0x8E [[func]] -name = "CelDecodeHdrLightTrans" +name = "CelClippedBlitLightTrans" addr = 0x41664B size = 0x74 [[func]] -name = "CelDrawHdrLightRed" +name = "CelDrawLightRed" addr = 0x4166BF size = 0x11C [[func]] -name = "Cel2DecDatOnly" +name = "CelBlitSafe" addr = 0x4167DB size = 0x7F [[func]] -name = "Cel2DrawHdrOnly" +name = "CelClippedDrawSafe" addr = 0x41685A size = 0x7B [[func]] -name = "Cel2DecodeHdrOnly" +name = "CelClippedBlitSafe" addr = 0x4168D5 size = 0x55 [[func]] -name = "Cel2DecDatLightOnly" +name = "CelBlitLightSafe" addr = 0x41692A size = 0xF7 [[func]] -name = "Cel2DecDatLightTrans" +name = "CelBlitLightTransSafe" addr = 0x416A21 size = 0xF8 [[func]] -name = "Cel2DecodeHdrLight" +name = "CelDrawLightSafe" addr = 0x416B19 size = 0x90 [[func]] -name = "Cel2DecodeLightTrans" +name = "CelClippedBlitLightTransSafe" addr = 0x416BA9 size = 0x72 [[func]] -name = "Cel2DrawHdrLightRed" +name = "CelDrawLightRedSafe" addr = 0x416C1B size = 0x121 [[func]] -name = "CelDecodeRect" +name = "CelBlitWidth" addr = 0x416D3C size = 0x8A [[func]] -name = "CelDecodeClr" +name = "CelBlitOutline" addr = 0x416DC6 size = 0xFA [[func]] -name = "CelDrawHdrClrHL" +name = "CelBlitOutlineSafe" addr = 0x416EC0 size = 0x12F @@ -1933,72 +1933,72 @@ addr = 0x4176D2 size = 0x73 [[func]] -name = "Cl2DecodeFrm1" +name = "Cl2Draw" addr = 0x417745 size = 0x7A [[func]] -name = "Cl2DecDatFrm1" +name = "Cl2Blit" addr = 0x4177BF size = 0x88 [[func]] -name = "Cl2DecodeFrm2" +name = "Cl2DrawOutline" addr = 0x417847 size = 0x7E [[func]] -name = "Cl2DecDatFrm2" +name = "Cl2BlitOutline" addr = 0x4178C5 size = 0xBC [[func]] -name = "Cl2DecodeFrm3" +name = "Cl2DrawLightTbl" addr = 0x417981 size = 0xC3 [[func]] -name = "Cl2DecDatLightTbl1" +name = "Cl2BlitLight" addr = 0x417A44 size = 0xA5 [[func]] -name = "Cl2DecodeLightTbl" +name = "Cl2DrawLight" addr = 0x417AE9 size = 0x9A [[func]] -name = "Cl2DecodeFrm4" +name = "Cl2DrawSafe" addr = 0x417B83 size = 0x7A [[func]] -name = "Cl2DecDatFrm4" +name = "Cl2BlitSafe" addr = 0x417BFD size = 0x9C [[func]] -name = "Cl2DecodeClrHL" +name = "Cl2DrawOutlineSafe" addr = 0x417C99 size = 0x8F [[func]] -name = "Cl2DecDatClrHL" +name = "Cl2BlitOutlineSafe" addr = 0x417D28 size = 0xD0 [[func]] -name = "Cl2DecodeFrm5" +name = "Cl2DrawLightTblSafe" addr = 0x417DF8 size = 0xC3 [[func]] -name = "Cl2DecDatLightTbl2" +name = "Cl2BlitLightSafe" addr = 0x417EBB size = 0xBD [[func]] -name = "Cl2DecodeFrm6" +name = "Cl2DrawLightSafe" addr = 0x417F78 size = 0x9A diff --git a/comparer-config/spawn.toml b/comparer-config/spawn.toml index c2c7242a0..08d16891b 100644 --- a/comparer-config/spawn.toml +++ b/comparer-config/spawn.toml @@ -1233,112 +1233,112 @@ addr = 0x40DFFE size = 0x6E [[func]] -name = "CelDrawDatOnly" +name = "CelBlit" addr = 0x40E07C size = 0x68 [[func]] -name = "CelDecodeOnly" +name = "CelDraw" addr = 0x40E0E4 size = 0x44 [[func]] -name = "CelDecDatOnly" +name = "CelBlitFrame" addr = 0x40E128 size = 0x26 [[func]] -name = "CelDrawHdrOnly" +name = "CelClippedDraw" addr = 0x40E14E size = 0x7B [[func]] -name = "CelDecodeHdrOnly" +name = "CelClippedBlit" addr = 0x40E1C9 size = 0x53 [[func]] -name = "CelDecDatLightOnly" +name = "CelBlitLight" addr = 0x40E21C size = 0xDC [[func]] -name = "CelDecDatLightTrans" +name = "CelBlitLightTrans" addr = 0x40E2F8 size = 0xDD [[func]] -name = "CelDecodeLightOnly" +name = "CelDrawLight" addr = 0x40E3D5 size = 0x58 [[func]] -name = "CelDecodeHdrLightOnly" +name = "CelClippedDrawLight" addr = 0x40E42D size = 0x8E [[func]] -name = "CelDecodeHdrLightTrans" +name = "CelClippedBlitLightTrans" addr = 0x40E4BB size = 0x74 [[func]] -name = "CelDrawHdrLightRed" +name = "CelDrawLightRed" addr = 0x40E52F size = 0x11C [[func]] -name = "Cel2DecDatOnly" +name = "CelBlitSafe" addr = 0x40E64B size = 0x7F [[func]] -name = "Cel2DrawHdrOnly" +name = "CelClippedDrawSafe" addr = 0x40E6CA size = 0x7B [[func]] -name = "Cel2DecodeHdrOnly" +name = "CelClippedBlitSafe" addr = 0x40E745 size = 0x55 [[func]] -name = "Cel2DecDatLightOnly" +name = "CelBlitLightSafe" addr = 0x40E79A size = 0xF7 [[func]] -name = "Cel2DecDatLightTrans" +name = "CelBlitLightTransSafe" addr = 0x40E891 size = 0xF8 [[func]] -name = "Cel2DecodeHdrLight" +name = "CelDrawLightSafe" addr = 0x40E989 size = 0x90 [[func]] -name = "Cel2DecodeLightTrans" +name = "CelClippedBlitLightTransSafe" addr = 0x40EA19 size = 0x72 [[func]] -name = "Cel2DrawHdrLightRed" +name = "CelDrawLightRedSafe" addr = 0x40EA8B size = 0x121 [[func]] -name = "CelDecodeRect" +name = "CelBlitWidth" addr = 0x40EBAC size = 0x8A [[func]] -name = "CelDecodeClr" +name = "CelBlitOutline" addr = 0x40EC36 size = 0xFA [[func]] -name = "CelDrawHdrClrHL" +name = "CelBlitOutlineSafe" addr = 0x40ED30 size = 0x12F @@ -1403,72 +1403,72 @@ addr = 0x40F542 size = 0x73 [[func]] -name = "Cl2DecodeFrm1" +name = "Cl2Draw" addr = 0x40F5B5 size = 0x7A [[func]] -name = "Cl2DecDatFrm1" +name = "Cl2Blit" addr = 0x40F62F size = 0x88 [[func]] -name = "Cl2DecodeFrm2" +name = "Cl2DrawOutline" addr = 0x40F6B7 size = 0x7E [[func]] -name = "Cl2DecDatFrm2" +name = "Cl2BlitOutline" addr = 0x40F735 size = 0xBC [[func]] -name = "Cl2DecodeFrm3" +name = "Cl2DrawLightTbl" addr = 0x40F7F1 size = 0xC3 [[func]] -name = "Cl2DecDatLightTbl1" +name = "Cl2BlitLight" addr = 0x40F8B4 size = 0xA5 [[func]] -name = "Cl2DecodeLightTbl" +name = "Cl2DrawLight" addr = 0x40F959 size = 0x9A [[func]] -name = "Cl2DecodeFrm4" +name = "Cl2DrawSafe" addr = 0x40F9F3 size = 0x7A [[func]] -name = "Cl2DecDatFrm4" +name = "Cl2BlitSafe" addr = 0x40FA6D size = 0x9C [[func]] -name = "Cl2DecodeClrHL" +name = "Cl2DrawOutlineSafe" addr = 0x40FB09 size = 0x8F [[func]] -name = "Cl2DecDatClrHL" +name = "Cl2BlitOutlineSafe" addr = 0x40FB98 size = 0xD0 [[func]] -name = "Cl2DecodeFrm5" +name = "Cl2DrawLightTblSafe" addr = 0x40FC68 size = 0xC3 [[func]] -name = "Cl2DecDatLightTbl2" +name = "Cl2BlitLightSafe" addr = 0x40FD2B size = 0xBD [[func]] -name = "Cl2DecodeFrm6" +name = "Cl2DrawLightSafe" addr = 0x40FDE8 size = 0x9A From 2b055004865d57b9ac84ae370265da09577a1ba0 Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Sun, 13 Oct 2019 09:23:22 -0500 Subject: [PATCH 4/5] Fix function order [drlg_l3.cpp] --- Source/drlg_l3.cpp | 1362 ++++++++++++++++++----------------- Source/drlg_l3.h | 24 - comparer-config/diablo.toml | 4 +- 3 files changed, 684 insertions(+), 706 deletions(-) diff --git a/Source/drlg_l3.cpp b/Source/drlg_l3.cpp index 2b4e1d6e9..76656dbbc 100644 --- a/Source/drlg_l3.cpp +++ b/Source/drlg_l3.cpp @@ -70,389 +70,7 @@ const BYTE L3ANVIL[244] = { 0, 0, 0, 0 }; -void AddFenceDoors() -{ - int i, j; - - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - if (dungeon[i][j] == 7) { - if (dungeon[i - 1][j] <= 152 && dungeon[i - 1][j] >= 130 - && dungeon[i + 1][j] <= 152 && dungeon[i + 1][j] >= 130) { - dungeon[i][j] = 146; - continue; - } - } - if (dungeon[i][j] == 7) { - if (dungeon[i][j - 1] <= 152 && dungeon[i][j - 1] >= 130 - && dungeon[i][j + 1] <= 152 && dungeon[i][j + 1] >= 130) { - dungeon[i][j] = 147; - continue; - } - } - } - } -} - -void FenceDoorFix() -{ - int i, j; - - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - if (dungeon[i][j] == 146) { - if (dungeon[i + 1][j] > 152 || dungeon[i + 1][j] < 130 - || dungeon[i - 1][j] > 152 || dungeon[i - 1][j] < 130) { - dungeon[i][j] = 7; - continue; - } - } - if (dungeon[i][j] == 146) { - if (dungeon[i + 1][j] != 130 && dungeon[i - 1][j] != 130 - && dungeon[i + 1][j] != 132 && dungeon[i - 1][j] != 132 - && dungeon[i + 1][j] != 133 && dungeon[i - 1][j] != 133 - && dungeon[i + 1][j] != 134 && dungeon[i - 1][j] != 134 - && dungeon[i + 1][j] != 136 && dungeon[i - 1][j] != 136 - && dungeon[i + 1][j] != 138 && dungeon[i - 1][j] != 138 - && dungeon[i + 1][j] != 140 && dungeon[i - 1][j] != 140) { - dungeon[i][j] = 7; - continue; - } - } - if (dungeon[i][j] == 147) { - if (dungeon[i][j + 1] > 152 || dungeon[i][j + 1] < 130 - || dungeon[i][j - 1] > 152 || dungeon[i][j - 1] < 130) { - dungeon[i][j] = 7; - continue; - } - } - if (dungeon[i][j] == 147) { - if (dungeon[i][j + 1] != 131 && dungeon[i][j - 1] != 131 - && dungeon[i][j + 1] != 132 && dungeon[i][j - 1] != 132 - && dungeon[i][j + 1] != 133 && dungeon[i][j - 1] != 133 - && dungeon[i][j + 1] != 135 && dungeon[i][j - 1] != 135 - && dungeon[i][j + 1] != 137 && dungeon[i][j - 1] != 137 - && dungeon[i][j + 1] != 138 && dungeon[i][j - 1] != 138 - && dungeon[i][j + 1] != 139 && dungeon[i][j - 1] != 139) { - dungeon[i][j] = 7; - continue; - } - } - } - } -} - -BOOL DRLG_L3Anvil() -{ - int sx, sy, sw, sh, xx, yy, ii, trys; - BOOL found; - - sw = L3ANVIL[0]; - sh = L3ANVIL[1]; - sx = random(0, DMAXX - sw); - sy = random(0, DMAXY - sh); - - found = FALSE; - trys = 0; - while (!found && trys < 200) { - trys++; - found = TRUE; - ii = 2; - for (yy = 0; yy < sh && found == TRUE; yy++) { - for (xx = 0; xx < sw && found == TRUE; xx++) { - if (L3ANVIL[ii] != 0 && dungeon[xx + sx][yy + sy] != L3ANVIL[ii]) { - found = FALSE; - } - if (dflags[xx + sx][yy + sy] != 0) { - found = FALSE; - } - ii++; - } - } - if (!found) { - sx++; - if (sx == DMAXX - sw) { - sx = 0; - sy++; - if (sy == DMAXY - sh) { - sy = 0; - } - } - } - } - if (trys >= 200) { - return TRUE; - } - - ii = sw * sh + 2; - for (yy = 0; yy < sh; yy++) { - for (xx = 0; xx < sw; xx++) { - if (L3ANVIL[ii] != 0) { - dungeon[xx + sx][yy + sy] = L3ANVIL[ii]; - } - dflags[xx + sx][yy + sy] |= DLRG_PROTECTED; - ii++; - } - } - - setpc_x = sx; - setpc_y = sy; - setpc_w = sw; - setpc_h = sh; - - return FALSE; -} - -void FixL3Warp() -{ - int i, j; - - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - if (dungeon[i][j] == 125 && dungeon[i + 1][j] == 125 && dungeon[i][j + 1] == 125 && dungeon[i + 1][j + 1] == 125) { - dungeon[i][j] = 156; - dungeon[i + 1][j] = 155; - dungeon[i][j + 1] = 153; - dungeon[i + 1][j + 1] = 154; - return; - } - if (dungeon[i][j] == 5 && dungeon[i + 1][j + 1] == 7) { - dungeon[i][j] = 7; - } - } - } -} - -void FixL3HallofHeroes() -{ - int i, j; - - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - if (dungeon[i][j] == 5 && dungeon[i + 1][j + 1] == 7) { - dungeon[i][j] = 7; - } - } - } - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - if (dungeon[i][j] == 5 && dungeon[i + 1][j + 1] == 12 && dungeon[i + 1][j] == 7) { - dungeon[i][j] = 7; - dungeon[i][j + 1] = 7; - dungeon[i + 1][j + 1] = 7; - } - if (dungeon[i][j] == 5 && dungeon[i + 1][j + 1] == 12 && dungeon[i][j + 1] == 7) { - dungeon[i][j] = 7; - dungeon[i + 1][j] = 7; - dungeon[i + 1][j + 1] = 7; - } - } - } -} - -void DRLG_L3LockRec(int x, int y) -{ - if (!lockout[x][y]) { - return; - } - - lockout[x][y] = FALSE; - lockoutcnt++; - DRLG_L3LockRec(x, y - 1); - DRLG_L3LockRec(x, y + 1); - DRLG_L3LockRec(x - 1, y); - DRLG_L3LockRec(x + 1, y); -} - -BOOL DRLG_L3Lockout() -{ - int i, j, t, fx, fy; - - t = 0; - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - if (dungeon[i][j] != 0) { - lockout[i][j] = TRUE; - fx = i; - fy = j; - t++; - } else { - lockout[i][j] = FALSE; - } - } - } - - lockoutcnt = 0; - DRLG_L3LockRec(fx, fy); - - return t == lockoutcnt; -} - -void CreateL3Dungeon(DWORD rseed, int entry) -{ - int i, j; - - SetRndSeed(rseed); - dminx = 16; - dminy = 16; - dmaxx = 96; - dmaxy = 96; - DRLG_InitTrans(); - DRLG_InitSetPC(); - DRLG_L3(entry); - DRLG_L3Pass3(); - - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) { - if (dPiece[i][j] >= 56 && dPiece[i][j] <= 147) { - DoLighting(i, j, 7, -1); - } else if (dPiece[i][j] >= 154 && dPiece[i][j] <= 161) { - DoLighting(i, j, 7, -1); - } else if (dPiece[i][j] == 150) { - DoLighting(i, j, 7, -1); - } else if (dPiece[i][j] == 152) { - DoLighting(i, j, 7, -1); - } - } - } - - DRLG_SetPC(); -} - -void DRLG_L3(int entry) -{ - int x1, y1, x2, y2, i, j; - BOOL found, genok; - - lavapool = FALSE; - - do { - do { - do { - InitL3Dungeon(); - x1 = random(0, 20) + 10; - y1 = random(0, 20) + 10; - x2 = x1 + 2; - y2 = y1 + 2; - DRLG_L3FillRoom(x1, y1, x2, y2); - DRLG_L3CreateBlock(x1, y1, 2, 0); - DRLG_L3CreateBlock(x2, y1, 2, 1); - DRLG_L3CreateBlock(x1, y2, 2, 2); - DRLG_L3CreateBlock(x1, y1, 2, 3); - if (QuestStatus(QTYPE_ANVIL)) { - x1 = random(0, 10) + 10; - y1 = random(0, 10) + 10; - x2 = x1 + 12; - y2 = y1 + 12; - DRLG_L3FloorArea(x1, y1, x2, y2); - } - DRLG_L3FillDiags(); - DRLG_L3FillSingles(); - DRLG_L3FillStraights(); - DRLG_L3FillDiags(); - DRLG_L3Edges(); - if (DRLG_L3GetFloorArea() >= 600) { - found = DRLG_L3Lockout(); - } else { - found = FALSE; - } - } while (!found); - DRLG_L3MakeMegas(); - if (entry == 0) { - genok = DRLG_L3PlaceMiniSet(L3UP, 1, 1, -1, -1, 1, 0); - if (!genok) { - genok = DRLG_L3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, 0, 1); - if (!genok && currlevel == 9) { - genok = DRLG_L3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, 0, 6); - } - } - } else if (entry == 1) { - genok = DRLG_L3PlaceMiniSet(L3UP, 1, 1, -1, -1, 0, 0); - if (!genok) { - genok = DRLG_L3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, 1, 1); - ViewX += 2; - ViewY -= 2; - if (!genok && currlevel == 9) { - genok = DRLG_L3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, 0, 6); - } - } - } else { - genok = DRLG_L3PlaceMiniSet(L3UP, 1, 1, -1, -1, 0, 0); - if (!genok) { - genok = DRLG_L3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, 0, 1); - if (!genok && currlevel == 9) { - genok = DRLG_L3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, 1, 6); - } - } - } - if (!genok && QuestStatus(QTYPE_ANVIL)) { - genok = DRLG_L3Anvil(); - } - } while (genok == TRUE); - DRLG_L3Pool(); - } while (!lavapool); - - DRLG_L3PoolFix(); - FixL3Warp(); - DRLG_L3PlaceRndSet(L3ISLE1, 70); - DRLG_L3PlaceRndSet(L3ISLE2, 70); - DRLG_L3PlaceRndSet(L3ISLE3, 30); - DRLG_L3PlaceRndSet(L3ISLE4, 30); - DRLG_L3PlaceRndSet(L3ISLE1, 100); - DRLG_L3PlaceRndSet(L3ISLE2, 100); - DRLG_L3PlaceRndSet(L3ISLE5, 90); - FixL3HallofHeroes(); - DRLG_L3River(); - - if (QuestStatus(QTYPE_ANVIL)) { - dungeon[setpc_x + 7][setpc_y + 5] = 7; - dungeon[setpc_x + 8][setpc_y + 5] = 7; - dungeon[setpc_x + 9][setpc_y + 5] = 7; - if (dungeon[setpc_x + 10][setpc_y + 5] == 17 || dungeon[setpc_x + 10][setpc_y + 5] == 18) { - dungeon[setpc_x + 10][setpc_y + 5] = 45; - } - } - - DRLG_PlaceThemeRooms(5, 10, 7, 0, 0); - DRLG_L3Wood(); - DRLG_L3PlaceRndSet(L3TITE1, 10); - DRLG_L3PlaceRndSet(L3TITE2, 10); - DRLG_L3PlaceRndSet(L3TITE3, 10); - DRLG_L3PlaceRndSet(L3TITE6, 20); - DRLG_L3PlaceRndSet(L3TITE7, 20); - DRLG_L3PlaceRndSet(L3TITE8, 20); - DRLG_L3PlaceRndSet(L3TITE9, 20); - DRLG_L3PlaceRndSet(L3TITE10, 20); - DRLG_L3PlaceRndSet(L3TITE11, 30); - DRLG_L3PlaceRndSet(L3TITE12, 20); - DRLG_L3PlaceRndSet(L3TITE13, 20); - DRLG_L3PlaceRndSet(L3CREV1, 30); - DRLG_L3PlaceRndSet(L3CREV2, 30); - DRLG_L3PlaceRndSet(L3CREV3, 30); - DRLG_L3PlaceRndSet(L3CREV4, 30); - DRLG_L3PlaceRndSet(L3CREV5, 30); - DRLG_L3PlaceRndSet(L3CREV6, 30); - DRLG_L3PlaceRndSet(L3CREV7, 30); - DRLG_L3PlaceRndSet(L3CREV8, 30); - DRLG_L3PlaceRndSet(L3CREV9, 30); - DRLG_L3PlaceRndSet(L3CREV10, 30); - DRLG_L3PlaceRndSet(L3CREV11, 30); - DRLG_L3PlaceRndSet(L3XTRA1, 25); - DRLG_L3PlaceRndSet(L3XTRA2, 25); - DRLG_L3PlaceRndSet(L3XTRA3, 25); - DRLG_L3PlaceRndSet(L3XTRA4, 25); - DRLG_L3PlaceRndSet(L3XTRA5, 25); - - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - pdungeon[i][j] = dungeon[i][j]; - } - } - - DRLG_Init_Globals(); -} - -void InitL3Dungeon() +static void InitL3Dungeon() { int i, j; @@ -466,7 +84,7 @@ void InitL3Dungeon() } } -BOOL DRLG_L3FillRoom(int x1, int y1, int x2, int y2) +static BOOL DRLG_L3FillRoom(int x1, int y1, int x2, int y2) { int i, j, v; @@ -510,7 +128,7 @@ BOOL DRLG_L3FillRoom(int x1, int y1, int x2, int y2) return TRUE; } -void DRLG_L3CreateBlock(int x, int y, int obs, int dir) +static void DRLG_L3CreateBlock(int x, int y, int obs, int dir) { int blksizex, blksizey, x1, y1, x2, y2; BOOL contflag; @@ -592,7 +210,7 @@ void DRLG_L3CreateBlock(int x, int y, int obs, int dir) } } -void DRLG_L3FloorArea(int x1, int y1, int x2, int y2) +static void DRLG_L3FloorArea(int x1, int y1, int x2, int y2) { int i, j; @@ -603,7 +221,7 @@ void DRLG_L3FloorArea(int x1, int y1, int x2, int y2) } } -void DRLG_L3FillDiags() +static void DRLG_L3FillDiags() { int i, j, v; @@ -628,7 +246,7 @@ void DRLG_L3FillDiags() } } -void DRLG_L3FillSingles() +static void DRLG_L3FillSingles() { int i, j; @@ -644,7 +262,7 @@ void DRLG_L3FillSingles() } } -void DRLG_L3FillStraights() +static void DRLG_L3FillStraights() { int i, j, xc, xs, yc, ys, k, rv; @@ -726,7 +344,7 @@ void DRLG_L3FillStraights() } } -void DRLG_L3Edges() +static void DRLG_L3Edges() { int i, j; @@ -738,7 +356,7 @@ void DRLG_L3Edges() } } -int DRLG_L3GetFloorArea() +static int DRLG_L3GetFloorArea() { int i, j, gfa; @@ -753,7 +371,7 @@ int DRLG_L3GetFloorArea() return gfa; } -void DRLG_L3MakeMegas() +static void DRLG_L3MakeMegas() { int i, j, v, rv; @@ -785,7 +403,7 @@ void DRLG_L3MakeMegas() } } -void DRLG_L3River() +static void DRLG_L3River() { int rx, ry, px, py, dir, pdir, nodir, nodir2, dircheck; int river[3][100]; @@ -981,50 +599,155 @@ void DRLG_L3River() if (bail == TRUE && riveramt < 7) { bail = FALSE; } - if (bail == TRUE) { - found = 0; - lpcnt = 0; - while (found == 0 && lpcnt < 30) { - lpcnt++; - bridge = random(0, riveramt); - if ((river[2][bridge] == 15 || river[2][bridge] == 16) - && dungeon[river[0][bridge]][river[1][bridge] - 1] == 7 - && dungeon[river[0][bridge]][river[1][bridge] + 1] == 7) { - found = 1; - } - if ((river[2][bridge] == 17 || river[2][bridge] == 18) - && dungeon[river[0][bridge] - 1][river[1][bridge]] == 7 - && dungeon[river[0][bridge] + 1][river[1][bridge]] == 7) { - found = 2; - } - for (i = 0; i < riveramt && found != 0; i++) { - if (found == 1 - && (river[1][bridge] - 1 == river[1][i] || river[1][bridge] + 1 == river[1][i]) - && river[0][bridge] == river[0][i]) { - found = 0; - } - if (found == 2 - && (river[0][bridge] - 1 == river[0][i] || river[0][bridge] + 1 == river[0][i]) - && river[1][bridge] == river[1][i]) { - found = 0; - } - } - } - if (found != 0) { - if (found == 1) { - river[2][bridge] = 44; - } else { - river[2][bridge] = 45; - } - rivercnt++; - for (bridge = 0; bridge <= riveramt; bridge++) { - dungeon[river[0][bridge]][river[1][bridge]] = river[2][bridge]; - } - } else { - bail = FALSE; - } + if (bail == TRUE) { + found = 0; + lpcnt = 0; + while (found == 0 && lpcnt < 30) { + lpcnt++; + bridge = random(0, riveramt); + if ((river[2][bridge] == 15 || river[2][bridge] == 16) + && dungeon[river[0][bridge]][river[1][bridge] - 1] == 7 + && dungeon[river[0][bridge]][river[1][bridge] + 1] == 7) { + found = 1; + } + if ((river[2][bridge] == 17 || river[2][bridge] == 18) + && dungeon[river[0][bridge] - 1][river[1][bridge]] == 7 + && dungeon[river[0][bridge] + 1][river[1][bridge]] == 7) { + found = 2; + } + for (i = 0; i < riveramt && found != 0; i++) { + if (found == 1 + && (river[1][bridge] - 1 == river[1][i] || river[1][bridge] + 1 == river[1][i]) + && river[0][bridge] == river[0][i]) { + found = 0; + } + if (found == 2 + && (river[0][bridge] - 1 == river[0][i] || river[0][bridge] + 1 == river[0][i]) + && river[1][bridge] == river[1][i]) { + found = 0; + } + } + } + if (found != 0) { + if (found == 1) { + river[2][bridge] = 44; + } else { + river[2][bridge] = 45; + } + rivercnt++; + for (bridge = 0; bridge <= riveramt; bridge++) { + dungeon[river[0][bridge]][river[1][bridge]] = river[2][bridge]; + } + } else { + bail = FALSE; + } + } + } +} + +static BOOL DRLG_L3Spawn(int x, int y, int *totarea); + +static BOOL DRLG_L3SpawnEdge(int x, int y, int *totarea) +{ + BYTE i; + static BYTE spawntable[15] = { 0, 0x0A, 0x43, 0x05, 0x2C, 0x06, 0x09, 0, 0, 0x1C, 0x83, 0x06, 0x09, 0x0A, 0x05 }; + + if (*totarea > 40) { + return TRUE; + } + if (x < 0 || y < 0 || x >= DMAXX || y >= DMAXY) { + return TRUE; + } + if (dungeon[x][y] & 0x80) { + return FALSE; + } + if (dungeon[x][y] > 15) { + return TRUE; + } + + i = dungeon[x][y]; + dungeon[x][y] |= 0x80; + *totarea += 1; + + if (spawntable[i] & 8 && DRLG_L3SpawnEdge(x, y - 1, totarea) == TRUE) { + return TRUE; + } + if (spawntable[i] & 4 && DRLG_L3SpawnEdge(x, y + 1, totarea) == TRUE) { + return TRUE; + } + if (spawntable[i] & 2 && DRLG_L3SpawnEdge(x + 1, y, totarea) == TRUE) { + return TRUE; + } + if (spawntable[i] & 1 && DRLG_L3SpawnEdge(x - 1, y, totarea) == TRUE) { + return TRUE; + } + if (spawntable[i] & 0x80 && DRLG_L3Spawn(x, y - 1, totarea) == TRUE) { + return TRUE; + } + if (spawntable[i] & 0x40 && DRLG_L3Spawn(x, y + 1, totarea) == TRUE) { + return TRUE; + } + if (spawntable[i] & 0x20 && DRLG_L3Spawn(x + 1, y, totarea) == TRUE) { + return TRUE; + } + if (spawntable[i] & 0x10 && DRLG_L3Spawn(x - 1, y, totarea) == TRUE) { + return TRUE; + } + + return FALSE; +} + +static BOOL DRLG_L3Spawn(int x, int y, int *totarea) +{ + BYTE i; + static BYTE spawntable[15] = { 0, 0x0A, 0x03, 0x05, 0x0C, 0x06, 0x09, 0, 0, 0x012, 0x03, 0x06, 0x09, 0x0A, 0x05 }; + + if (*totarea > 40) { + return TRUE; + } + if (x < 0 || y < 0 || x >= DMAXX || y >= DMAXY) { + return TRUE; + } + if (dungeon[x][y] & 0x80) { + return FALSE; + } + if (dungeon[x][y] > 15) { + return TRUE; + } + + i = dungeon[x][y]; + dungeon[x][y] |= 0x80; + *totarea += 1; + + if (i != 8) { + if (spawntable[i] & 8 && DRLG_L3SpawnEdge(x, y - 1, totarea) == TRUE) { + return TRUE; + } + if (spawntable[i] & 4 && DRLG_L3SpawnEdge(x, y + 1, totarea) == TRUE) { + return TRUE; + } + if (spawntable[i] & 2 && DRLG_L3SpawnEdge(x + 1, y, totarea) == TRUE) { + return TRUE; + } + if (spawntable[i] & 1 && DRLG_L3SpawnEdge(x - 1, y, totarea) == TRUE) { + return TRUE; + } + } else { + if (DRLG_L3Spawn(x + 1, y, totarea) == TRUE) { + return TRUE; + } + if (DRLG_L3Spawn(x - 1, y, totarea) == TRUE) { + return TRUE; + } + if (DRLG_L3Spawn(x, y + 1, totarea) == TRUE) { + return TRUE; + } + if (DRLG_L3Spawn(x, y - 1, totarea) == TRUE) { + return TRUE; } } + + return FALSE; } /** @@ -1032,7 +755,7 @@ void DRLG_L3River() * an area of at most 40 tiles and disconnected from the map edge. * If it finds one, converts it to lava tiles and sets lavapool to TRUE. */ -void DRLG_L3Pool() +static void DRLG_L3Pool() { int i, j, dunx, duny, totarea, poolchance; BOOL found; @@ -1047,22 +770,22 @@ void DRLG_L3Pool() dungeon[dunx][duny] |= 0x80; totarea = 1; if (dunx + 1 < DMAXX) { - found = DRLG_L3SpawnEdge(dunx + 1, duny, &totarea); + found = DRLG_L3Spawn(dunx + 1, duny, &totarea); } else { found = TRUE; } if (dunx - 1 > 0 && !found) { - found = DRLG_L3SpawnEdge(dunx - 1, duny, &totarea); + found = DRLG_L3Spawn(dunx - 1, duny, &totarea); } else { found = TRUE; } if (duny + 1 < DMAXY && !found) { - found = DRLG_L3SpawnEdge(dunx, duny + 1, &totarea); + found = DRLG_L3Spawn(dunx, duny + 1, &totarea); } else { found = TRUE; } if (duny - 1 > 0 && !found) { - found = DRLG_L3SpawnEdge(dunx, duny - 1, &totarea); + found = DRLG_L3Spawn(dunx, duny - 1, &totarea); } else { found = TRUE; } @@ -1087,110 +810,7 @@ void DRLG_L3Pool() } } -BOOL DRLG_L3SpawnEdge(int x, int y, int *totarea) -{ - BYTE i; - static BYTE spawntable[15] = { 0, 0x0A, 0x03, 0x05, 0x0C, 0x06, 0x09, 0, 0, 0x012, 0x03, 0x06, 0x09, 0x0A, 0x05 }; - - if (*totarea > 40) { - return TRUE; - } - if (x < 0 || y < 0 || x >= DMAXX || y >= DMAXY) { - return TRUE; - } - if (dungeon[x][y] & 0x80) { - return FALSE; - } - if (dungeon[x][y] > 15) { - return TRUE; - } - - i = dungeon[x][y]; - dungeon[x][y] |= 0x80; - *totarea += 1; - - if (i != 8) { - if (spawntable[i] & 8 && DRLG_L3Spawn(x, y - 1, totarea) == TRUE) { - return TRUE; - } - if (spawntable[i] & 4 && DRLG_L3Spawn(x, y + 1, totarea) == TRUE) { - return TRUE; - } - if (spawntable[i] & 2 && DRLG_L3Spawn(x + 1, y, totarea) == TRUE) { - return TRUE; - } - if (spawntable[i] & 1 && DRLG_L3Spawn(x - 1, y, totarea) == TRUE) { - return TRUE; - } - } else { - if (DRLG_L3SpawnEdge(x + 1, y, totarea) == TRUE) { - return TRUE; - } - if (DRLG_L3SpawnEdge(x - 1, y, totarea) == TRUE) { - return TRUE; - } - if (DRLG_L3SpawnEdge(x, y + 1, totarea) == TRUE) { - return TRUE; - } - if (DRLG_L3SpawnEdge(x, y - 1, totarea) == TRUE) { - return TRUE; - } - } - - return FALSE; -} - -BOOL DRLG_L3Spawn(int x, int y, int *totarea) -{ - BYTE i; - static BYTE spawntable[15] = { 0, 0x0A, 0x43, 0x05, 0x2C, 0x06, 0x09, 0, 0, 0x1C, 0x83, 0x06, 0x09, 0x0A, 0x05 }; - - if (*totarea > 40) { - return TRUE; - } - if (x < 0 || y < 0 || x >= DMAXX || y >= DMAXY) { - return TRUE; - } - if (dungeon[x][y] & 0x80) { - return FALSE; - } - if (dungeon[x][y] > 15) { - return TRUE; - } - - i = dungeon[x][y]; - dungeon[x][y] |= 0x80; - *totarea += 1; - - if (spawntable[i] & 8 && DRLG_L3Spawn(x, y - 1, totarea) == TRUE) { - return TRUE; - } - if (spawntable[i] & 4 && DRLG_L3Spawn(x, y + 1, totarea) == TRUE) { - return TRUE; - } - if (spawntable[i] & 2 && DRLG_L3Spawn(x + 1, y, totarea) == TRUE) { - return TRUE; - } - if (spawntable[i] & 1 && DRLG_L3Spawn(x - 1, y, totarea) == TRUE) { - return TRUE; - } - if (spawntable[i] & 0x80 && DRLG_L3SpawnEdge(x, y - 1, totarea) == TRUE) { - return TRUE; - } - if (spawntable[i] & 0x40 && DRLG_L3SpawnEdge(x, y + 1, totarea) == TRUE) { - return TRUE; - } - if (spawntable[i] & 0x20 && DRLG_L3SpawnEdge(x + 1, y, totarea) == TRUE) { - return TRUE; - } - if (spawntable[i] & 0x10 && DRLG_L3SpawnEdge(x - 1, y, totarea) == TRUE) { - return TRUE; - } - - return FALSE; -} - -void DRLG_L3PoolFix() +static void DRLG_L3PoolFix() { int dunx, duny; @@ -1212,7 +832,7 @@ void DRLG_L3PoolFix() } } -BOOL DRLG_L3PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, BOOL setview, int ldir) +static BOOL DRLG_L3PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, BOOL setview, int ldir) { int sx, sy, sw, sh, xx, yy, i, ii, numt, trys; BOOL found; @@ -1267,87 +887,255 @@ BOOL DRLG_L3PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy } } } - if (trys >= 200) { + if (trys >= 200) { + return TRUE; + } + ii = sw * sh + 2; + for (yy = 0; yy < sh; yy++) { + for (xx = 0; xx < sw; xx++) { + if (miniset[ii] != 0) { + dungeon[xx + sx][yy + sy] = miniset[ii]; + } + ii++; + } + } + } + + if (setview == TRUE) { + ViewX = 2 * sx + 17; + ViewY = 2 * sy + 19; + } + if (ldir == 0) { + LvlViewX = 2 * sx + 17; + LvlViewY = 2 * sy + 19; + } + + return FALSE; +} + +static void DRLG_L3PlaceRndSet(const BYTE *miniset, int rndper) +{ + int sx, sy, sw, sh, xx, yy, ii, kk; + BOOL found; + + sw = miniset[0]; + sh = miniset[1]; + + for (sy = 0; sy < DMAXX - sh; sy++) { + for (sx = 0; sx < DMAXY - sw; sx++) { + found = TRUE; + ii = 2; + for (yy = 0; yy < sh && found == TRUE; yy++) { + for (xx = 0; xx < sw && found == TRUE; xx++) { + if (miniset[ii] != 0 && dungeon[xx + sx][yy + sy] != miniset[ii]) { + found = FALSE; + } + if (dflags[xx + sx][yy + sy] != 0) { + found = FALSE; + } + ii++; + } + } + kk = sw * sh + 2; + if (miniset[kk] >= 84 && miniset[kk] <= 100 && found == TRUE) { + // BUGFIX: accesses to dungeon can go out of bounds + // BUGFIX: Comparisons vs 100 should use same tile as comparisons vs 84. + if (dungeon[sx - 1][sy] >= 84 && dungeon[sx - 1][sy] <= 100) { + found = FALSE; + } + if (dungeon[sx + 1][sy] >= 84 && dungeon[sx - 1][sy] <= 100) { + found = FALSE; + } + if (dungeon[sx][sy + 1] >= 84 && dungeon[sx - 1][sy] <= 100) { + found = FALSE; + } + if (dungeon[sx][sy - 1] >= 84 && dungeon[sx - 1][sy] <= 100) { + found = FALSE; + } + } + if (found == TRUE && random(0, 100) < rndper) { + for (yy = 0; yy < sh; yy++) { + for (xx = 0; xx < sw; xx++) { + if (miniset[kk] != 0) { + dungeon[xx + sx][yy + sy] = miniset[kk]; + } + kk++; + } + } + } + } + } +} + +static BOOL WoodVertU(int i, int y) +{ + if ((dungeon[i + 1][y] > 152 || dungeon[i + 1][y] < 130) + && (dungeon[i - 1][y] > 152 || dungeon[i - 1][y] < 130)) { + if (dungeon[i][y] == 7) { + return TRUE; + } + if (dungeon[i][y] == 10) { + return TRUE; + } + if (dungeon[i][y] == 126) { + return TRUE; + } + if (dungeon[i][y] == 129) { + return TRUE; + } + if (dungeon[i][y] == 134) { + return TRUE; + } + if (dungeon[i][y] == 136) { + return TRUE; + } + } + + return FALSE; +} + +static BOOL WoodVertD(int i, int y) +{ + if ((dungeon[i + 1][y] > 152 || dungeon[i + 1][y] < 130) + && (dungeon[i - 1][y] > 152 || dungeon[i - 1][y] < 130)) { + if (dungeon[i][y] == 7) { + return TRUE; + } + if (dungeon[i][y] == 2) { + return TRUE; + } + if (dungeon[i][y] == 134) { + return TRUE; + } + if (dungeon[i][y] == 136) { + return TRUE; + } + } + + return FALSE; +} + +static BOOL WoodHorizL(int x, int j) +{ + if ((dungeon[x][j + 1] > 152 || dungeon[x][j + 1] < 130) + && (dungeon[x][j - 1] > 152 || dungeon[x][j - 1] < 130)) { + if (dungeon[x][j] == 7) { + return TRUE; + } + if (dungeon[x][j] == 9) { return TRUE; } - ii = sw * sh + 2; - for (yy = 0; yy < sh; yy++) { - for (xx = 0; xx < sw; xx++) { - if (miniset[ii] != 0) { - dungeon[xx + sx][yy + sy] = miniset[ii]; - } - ii++; - } + if (dungeon[x][j] == 121) { + return TRUE; + } + if (dungeon[x][j] == 124) { + return TRUE; + } + if (dungeon[x][j] == 135) { + return TRUE; + } + if (dungeon[x][j] == 137) { + return TRUE; } } - if (setview == TRUE) { - ViewX = 2 * sx + 17; - ViewY = 2 * sy + 19; - } - if (ldir == 0) { - LvlViewX = 2 * sx + 17; - LvlViewY = 2 * sy + 19; + return FALSE; +} + +static BOOL WoodHorizR(int x, int j) +{ + if ((dungeon[x][j + 1] > 152 || dungeon[x][j + 1] < 130) + && (dungeon[x][j - 1] > 152 || dungeon[x][j - 1] < 130)) { + if (dungeon[x][j] == 7) { + return TRUE; + } + if (dungeon[x][j] == 4) { + return TRUE; + } + if (dungeon[x][j] == 135) { + return TRUE; + } + if (dungeon[x][j] == 137) { + return TRUE; + } } return FALSE; } -void DRLG_L3PlaceRndSet(const BYTE *miniset, int rndper) +void AddFenceDoors() { - int sx, sy, sw, sh, xx, yy, ii, kk; - BOOL found; - - sw = miniset[0]; - sh = miniset[1]; + int i, j; - for (sy = 0; sy < DMAXX - sh; sy++) { - for (sx = 0; sx < DMAXY - sw; sx++) { - found = TRUE; - ii = 2; - for (yy = 0; yy < sh && found == TRUE; yy++) { - for (xx = 0; xx < sw && found == TRUE; xx++) { - if (miniset[ii] != 0 && dungeon[xx + sx][yy + sy] != miniset[ii]) { - found = FALSE; - } - if (dflags[xx + sx][yy + sy] != 0) { - found = FALSE; - } - ii++; + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + if (dungeon[i][j] == 7) { + if (dungeon[i - 1][j] <= 152 && dungeon[i - 1][j] >= 130 + && dungeon[i + 1][j] <= 152 && dungeon[i + 1][j] >= 130) { + dungeon[i][j] = 146; + continue; } } - kk = sw * sh + 2; - if (miniset[kk] >= 84 && miniset[kk] <= 100 && found == TRUE) { - // BUGFIX: accesses to dungeon can go out of bounds - // BUGFIX: Comparisons vs 100 should use same tile as comparisons vs 84. - if (dungeon[sx - 1][sy] >= 84 && dungeon[sx - 1][sy] <= 100) { - found = FALSE; + if (dungeon[i][j] == 7) { + if (dungeon[i][j - 1] <= 152 && dungeon[i][j - 1] >= 130 + && dungeon[i][j + 1] <= 152 && dungeon[i][j + 1] >= 130) { + dungeon[i][j] = 147; + continue; } - if (dungeon[sx + 1][sy] >= 84 && dungeon[sx - 1][sy] <= 100) { - found = FALSE; + } + } + } +} + +void FenceDoorFix() +{ + int i, j; + + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + if (dungeon[i][j] == 146) { + if (dungeon[i + 1][j] > 152 || dungeon[i + 1][j] < 130 + || dungeon[i - 1][j] > 152 || dungeon[i - 1][j] < 130) { + dungeon[i][j] = 7; + continue; } - if (dungeon[sx][sy + 1] >= 84 && dungeon[sx - 1][sy] <= 100) { - found = FALSE; + } + if (dungeon[i][j] == 146) { + if (dungeon[i + 1][j] != 130 && dungeon[i - 1][j] != 130 + && dungeon[i + 1][j] != 132 && dungeon[i - 1][j] != 132 + && dungeon[i + 1][j] != 133 && dungeon[i - 1][j] != 133 + && dungeon[i + 1][j] != 134 && dungeon[i - 1][j] != 134 + && dungeon[i + 1][j] != 136 && dungeon[i - 1][j] != 136 + && dungeon[i + 1][j] != 138 && dungeon[i - 1][j] != 138 + && dungeon[i + 1][j] != 140 && dungeon[i - 1][j] != 140) { + dungeon[i][j] = 7; + continue; } - if (dungeon[sx][sy - 1] >= 84 && dungeon[sx - 1][sy] <= 100) { - found = FALSE; + } + if (dungeon[i][j] == 147) { + if (dungeon[i][j + 1] > 152 || dungeon[i][j + 1] < 130 + || dungeon[i][j - 1] > 152 || dungeon[i][j - 1] < 130) { + dungeon[i][j] = 7; + continue; } } - if (found == TRUE && random(0, 100) < rndper) { - for (yy = 0; yy < sh; yy++) { - for (xx = 0; xx < sw; xx++) { - if (miniset[kk] != 0) { - dungeon[xx + sx][yy + sy] = miniset[kk]; - } - kk++; - } + if (dungeon[i][j] == 147) { + if (dungeon[i][j + 1] != 131 && dungeon[i][j - 1] != 131 + && dungeon[i][j + 1] != 132 && dungeon[i][j - 1] != 132 + && dungeon[i][j + 1] != 133 && dungeon[i][j - 1] != 133 + && dungeon[i][j + 1] != 135 && dungeon[i][j - 1] != 135 + && dungeon[i][j + 1] != 137 && dungeon[i][j - 1] != 137 + && dungeon[i][j + 1] != 138 && dungeon[i][j - 1] != 138 + && dungeon[i][j + 1] != 139 && dungeon[i][j - 1] != 139) { + dungeon[i][j] = 7; + continue; } } } } } -void DRLG_L3Wood() +static void DRLG_L3Wood() { int i, j, x, y, xx, yy, rt, rp, x1, y1, x2, y2; BOOL skip; @@ -1533,108 +1321,291 @@ void DRLG_L3Wood() } } } - - AddFenceDoors(); - FenceDoorFix(); + + AddFenceDoors(); + FenceDoorFix(); +} + +BOOL DRLG_L3Anvil() +{ + int sx, sy, sw, sh, xx, yy, ii, trys; + BOOL found; + + sw = L3ANVIL[0]; + sh = L3ANVIL[1]; + sx = random(0, DMAXX - sw); + sy = random(0, DMAXY - sh); + + found = FALSE; + trys = 0; + while (!found && trys < 200) { + trys++; + found = TRUE; + ii = 2; + for (yy = 0; yy < sh && found == TRUE; yy++) { + for (xx = 0; xx < sw && found == TRUE; xx++) { + if (L3ANVIL[ii] != 0 && dungeon[xx + sx][yy + sy] != L3ANVIL[ii]) { + found = FALSE; + } + if (dflags[xx + sx][yy + sy] != 0) { + found = FALSE; + } + ii++; + } + } + if (!found) { + sx++; + if (sx == DMAXX - sw) { + sx = 0; + sy++; + if (sy == DMAXY - sh) { + sy = 0; + } + } + } + } + if (trys >= 200) { + return TRUE; + } + + ii = sw * sh + 2; + for (yy = 0; yy < sh; yy++) { + for (xx = 0; xx < sw; xx++) { + if (L3ANVIL[ii] != 0) { + dungeon[xx + sx][yy + sy] = L3ANVIL[ii]; + } + dflags[xx + sx][yy + sy] |= DLRG_PROTECTED; + ii++; + } + } + + setpc_x = sx; + setpc_y = sy; + setpc_w = sw; + setpc_h = sh; + + return FALSE; +} + +void FixL3Warp() +{ + int i, j; + + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + if (dungeon[i][j] == 125 && dungeon[i + 1][j] == 125 && dungeon[i][j + 1] == 125 && dungeon[i + 1][j + 1] == 125) { + dungeon[i][j] = 156; + dungeon[i + 1][j] = 155; + dungeon[i][j + 1] = 153; + dungeon[i + 1][j + 1] = 154; + return; + } + if (dungeon[i][j] == 5 && dungeon[i + 1][j + 1] == 7) { + dungeon[i][j] = 7; + } + } + } +} + +void FixL3HallofHeroes() +{ + int i, j; + + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + if (dungeon[i][j] == 5 && dungeon[i + 1][j + 1] == 7) { + dungeon[i][j] = 7; + } + } + } + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + if (dungeon[i][j] == 5 && dungeon[i + 1][j + 1] == 12 && dungeon[i + 1][j] == 7) { + dungeon[i][j] = 7; + dungeon[i][j + 1] = 7; + dungeon[i + 1][j + 1] = 7; + } + if (dungeon[i][j] == 5 && dungeon[i + 1][j + 1] == 12 && dungeon[i][j + 1] == 7) { + dungeon[i][j] = 7; + dungeon[i + 1][j] = 7; + dungeon[i + 1][j + 1] = 7; + } + } + } } -BOOL WoodVertU(int i, int y) +void DRLG_L3LockRec(int x, int y) { - if ((dungeon[i + 1][y] > 152 || dungeon[i + 1][y] < 130) - && (dungeon[i - 1][y] > 152 || dungeon[i - 1][y] < 130)) { - if (dungeon[i][y] == 7) { - return TRUE; - } - if (dungeon[i][y] == 10) { - return TRUE; - } - if (dungeon[i][y] == 126) { - return TRUE; - } - if (dungeon[i][y] == 129) { - return TRUE; - } - if (dungeon[i][y] == 134) { - return TRUE; - } - if (dungeon[i][y] == 136) { - return TRUE; - } + if (!lockout[x][y]) { + return; } - return FALSE; + lockout[x][y] = FALSE; + lockoutcnt++; + DRLG_L3LockRec(x, y - 1); + DRLG_L3LockRec(x, y + 1); + DRLG_L3LockRec(x - 1, y); + DRLG_L3LockRec(x + 1, y); } -BOOL WoodVertD(int i, int y) +BOOL DRLG_L3Lockout() { - if ((dungeon[i + 1][y] > 152 || dungeon[i + 1][y] < 130) - && (dungeon[i - 1][y] > 152 || dungeon[i - 1][y] < 130)) { - if (dungeon[i][y] == 7) { - return TRUE; - } - if (dungeon[i][y] == 2) { - return TRUE; - } - if (dungeon[i][y] == 134) { - return TRUE; - } - if (dungeon[i][y] == 136) { - return TRUE; + int i, j, t, fx, fy; + + t = 0; + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + if (dungeon[i][j] != 0) { + lockout[i][j] = TRUE; + fx = i; + fy = j; + t++; + } else { + lockout[i][j] = FALSE; + } } } - return FALSE; + lockoutcnt = 0; + DRLG_L3LockRec(fx, fy); + + return t == lockoutcnt; } -BOOL WoodHorizL(int x, int j) +static void DRLG_L3(int entry) { - if ((dungeon[x][j + 1] > 152 || dungeon[x][j + 1] < 130) - && (dungeon[x][j - 1] > 152 || dungeon[x][j - 1] < 130)) { - if (dungeon[x][j] == 7) { - return TRUE; - } - if (dungeon[x][j] == 9) { - return TRUE; - } - if (dungeon[x][j] == 121) { - return TRUE; - } - if (dungeon[x][j] == 124) { - return TRUE; - } - if (dungeon[x][j] == 135) { - return TRUE; - } - if (dungeon[x][j] == 137) { - return TRUE; + int x1, y1, x2, y2, i, j; + BOOL found, genok; + + lavapool = FALSE; + + do { + do { + do { + InitL3Dungeon(); + x1 = random(0, 20) + 10; + y1 = random(0, 20) + 10; + x2 = x1 + 2; + y2 = y1 + 2; + DRLG_L3FillRoom(x1, y1, x2, y2); + DRLG_L3CreateBlock(x1, y1, 2, 0); + DRLG_L3CreateBlock(x2, y1, 2, 1); + DRLG_L3CreateBlock(x1, y2, 2, 2); + DRLG_L3CreateBlock(x1, y1, 2, 3); + if (QuestStatus(QTYPE_ANVIL)) { + x1 = random(0, 10) + 10; + y1 = random(0, 10) + 10; + x2 = x1 + 12; + y2 = y1 + 12; + DRLG_L3FloorArea(x1, y1, x2, y2); + } + DRLG_L3FillDiags(); + DRLG_L3FillSingles(); + DRLG_L3FillStraights(); + DRLG_L3FillDiags(); + DRLG_L3Edges(); + if (DRLG_L3GetFloorArea() >= 600) { + found = DRLG_L3Lockout(); + } else { + found = FALSE; + } + } while (!found); + DRLG_L3MakeMegas(); + if (entry == 0) { + genok = DRLG_L3PlaceMiniSet(L3UP, 1, 1, -1, -1, 1, 0); + if (!genok) { + genok = DRLG_L3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, 0, 1); + if (!genok && currlevel == 9) { + genok = DRLG_L3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, 0, 6); + } + } + } else if (entry == 1) { + genok = DRLG_L3PlaceMiniSet(L3UP, 1, 1, -1, -1, 0, 0); + if (!genok) { + genok = DRLG_L3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, 1, 1); + ViewX += 2; + ViewY -= 2; + if (!genok && currlevel == 9) { + genok = DRLG_L3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, 0, 6); + } + } + } else { + genok = DRLG_L3PlaceMiniSet(L3UP, 1, 1, -1, -1, 0, 0); + if (!genok) { + genok = DRLG_L3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, 0, 1); + if (!genok && currlevel == 9) { + genok = DRLG_L3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, 1, 6); + } + } + } + if (!genok && QuestStatus(QTYPE_ANVIL)) { + genok = DRLG_L3Anvil(); + } + } while (genok == TRUE); + DRLG_L3Pool(); + } while (!lavapool); + + DRLG_L3PoolFix(); + FixL3Warp(); + DRLG_L3PlaceRndSet(L3ISLE1, 70); + DRLG_L3PlaceRndSet(L3ISLE2, 70); + DRLG_L3PlaceRndSet(L3ISLE3, 30); + DRLG_L3PlaceRndSet(L3ISLE4, 30); + DRLG_L3PlaceRndSet(L3ISLE1, 100); + DRLG_L3PlaceRndSet(L3ISLE2, 100); + DRLG_L3PlaceRndSet(L3ISLE5, 90); + FixL3HallofHeroes(); + DRLG_L3River(); + + if (QuestStatus(QTYPE_ANVIL)) { + dungeon[setpc_x + 7][setpc_y + 5] = 7; + dungeon[setpc_x + 8][setpc_y + 5] = 7; + dungeon[setpc_x + 9][setpc_y + 5] = 7; + if (dungeon[setpc_x + 10][setpc_y + 5] == 17 || dungeon[setpc_x + 10][setpc_y + 5] == 18) { + dungeon[setpc_x + 10][setpc_y + 5] = 45; } } - return FALSE; -} + DRLG_PlaceThemeRooms(5, 10, 7, 0, 0); + DRLG_L3Wood(); + DRLG_L3PlaceRndSet(L3TITE1, 10); + DRLG_L3PlaceRndSet(L3TITE2, 10); + DRLG_L3PlaceRndSet(L3TITE3, 10); + DRLG_L3PlaceRndSet(L3TITE6, 20); + DRLG_L3PlaceRndSet(L3TITE7, 20); + DRLG_L3PlaceRndSet(L3TITE8, 20); + DRLG_L3PlaceRndSet(L3TITE9, 20); + DRLG_L3PlaceRndSet(L3TITE10, 20); + DRLG_L3PlaceRndSet(L3TITE11, 30); + DRLG_L3PlaceRndSet(L3TITE12, 20); + DRLG_L3PlaceRndSet(L3TITE13, 20); + DRLG_L3PlaceRndSet(L3CREV1, 30); + DRLG_L3PlaceRndSet(L3CREV2, 30); + DRLG_L3PlaceRndSet(L3CREV3, 30); + DRLG_L3PlaceRndSet(L3CREV4, 30); + DRLG_L3PlaceRndSet(L3CREV5, 30); + DRLG_L3PlaceRndSet(L3CREV6, 30); + DRLG_L3PlaceRndSet(L3CREV7, 30); + DRLG_L3PlaceRndSet(L3CREV8, 30); + DRLG_L3PlaceRndSet(L3CREV9, 30); + DRLG_L3PlaceRndSet(L3CREV10, 30); + DRLG_L3PlaceRndSet(L3CREV11, 30); + DRLG_L3PlaceRndSet(L3XTRA1, 25); + DRLG_L3PlaceRndSet(L3XTRA2, 25); + DRLG_L3PlaceRndSet(L3XTRA3, 25); + DRLG_L3PlaceRndSet(L3XTRA4, 25); + DRLG_L3PlaceRndSet(L3XTRA5, 25); -BOOL WoodHorizR(int x, int j) -{ - if ((dungeon[x][j + 1] > 152 || dungeon[x][j + 1] < 130) - && (dungeon[x][j - 1] > 152 || dungeon[x][j - 1] < 130)) { - if (dungeon[x][j] == 7) { - return TRUE; - } - if (dungeon[x][j] == 4) { - return TRUE; - } - if (dungeon[x][j] == 135) { - return TRUE; - } - if (dungeon[x][j] == 137) { - return TRUE; + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + pdungeon[i][j] = dungeon[i][j]; } } - return FALSE; + DRLG_Init_Globals(); } -void DRLG_L3Pass3() +static void DRLG_L3Pass3() { int i, j, xx, yy; long v1, v2, v3, v4, lv; @@ -1733,6 +1704,37 @@ void DRLG_L3Pass3() } } +void CreateL3Dungeon(DWORD rseed, int entry) +{ + int i, j; + + SetRndSeed(rseed); + dminx = 16; + dminy = 16; + dmaxx = 96; + dmaxy = 96; + DRLG_InitTrans(); + DRLG_InitSetPC(); + DRLG_L3(entry); + DRLG_L3Pass3(); + + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) { + if (dPiece[i][j] >= 56 && dPiece[i][j] <= 147) { + DoLighting(i, j, 7, -1); + } else if (dPiece[i][j] >= 154 && dPiece[i][j] <= 161) { + DoLighting(i, j, 7, -1); + } else if (dPiece[i][j] == 150) { + DoLighting(i, j, 7, -1); + } else if (dPiece[i][j] == 152) { + DoLighting(i, j, 7, -1); + } + } + } + + DRLG_SetPC(); +} + void LoadL3Dungeon(char *sFileName, int vx, int vy) { int i, j, rw, rh; diff --git a/Source/drlg_l3.h b/Source/drlg_l3.h index 01deec677..9170d7f9f 100644 --- a/Source/drlg_l3.h +++ b/Source/drlg_l3.h @@ -15,30 +15,6 @@ void FixL3HallofHeroes(); void DRLG_L3LockRec(int x, int y); BOOL DRLG_L3Lockout(); void CreateL3Dungeon(DWORD rseed, int entry); -void DRLG_L3(int entry); -void InitL3Dungeon(); -BOOL DRLG_L3FillRoom(int x1, int y1, int x2, int y2); -void DRLG_L3CreateBlock(int x, int y, int obs, int dir); -void DRLG_L3FloorArea(int x1, int y1, int x2, int y2); -void DRLG_L3FillDiags(); -void DRLG_L3FillSingles(); -void DRLG_L3FillStraights(); -void DRLG_L3Edges(); -int DRLG_L3GetFloorArea(); -void DRLG_L3MakeMegas(); -void DRLG_L3River(); -void DRLG_L3Pool(); -BOOL DRLG_L3SpawnEdge(int x, int y, int *totarea); -BOOL DRLG_L3Spawn(int x, int y, int *totarea); -void DRLG_L3PoolFix(); -BOOL DRLG_L3PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, BOOL setview, int ldir); -void DRLG_L3PlaceRndSet(const BYTE *miniset, int rndper); -void DRLG_L3Wood(); -BOOL WoodVertU(int i, int y); -BOOL WoodVertD(int i, int y); -BOOL WoodHorizL(int x, int j); -BOOL WoodHorizR(int x, int j); -void DRLG_L3Pass3(); void LoadL3Dungeon(char *sFileName, int vx, int vy); void LoadPreL3Dungeon(char *sFileName, int vx, int vy); diff --git a/comparer-config/diablo.toml b/comparer-config/diablo.toml index 03e64c4b9..7973f29c4 100644 --- a/comparer-config/diablo.toml +++ b/comparer-config/diablo.toml @@ -1308,12 +1308,12 @@ addr = 0x411614 size = 0x15E [[func]] -name = "DRLG_L3SpawnEdge" +name = "DRLG_L3Spawn" addr = 0x411772 size = 0x12A [[func]] -name = "DRLG_L3Spawn" +name = "DRLG_L3SpawnEdge" addr = 0x41189C size = 0x144 From 7f0eb791f8ed96aa8291babab0ef891c390160fe Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Sun, 13 Oct 2019 09:48:15 -0500 Subject: [PATCH 5/5] Fix function order [drlg_l4.cpp] --- Source/drlg_l4.cpp | 1144 ++++++++++++++++++++++---------------------- Source/drlg_l4.h | 24 - 2 files changed, 572 insertions(+), 596 deletions(-) diff --git a/Source/drlg_l4.cpp b/Source/drlg_l4.cpp index 566d3d82b..e78bb7efa 100644 --- a/Source/drlg_l4.cpp +++ b/Source/drlg_l4.cpp @@ -288,365 +288,7 @@ const BYTE L4BTYPES[140] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -void DRLG_LoadL4SP() -{ - setloadflag_2 = 0; - if (QuestStatus(QTYPE_WARLRD)) { - pSetPiece_2 = (char *)LoadFileInMem("Levels\\L4Data\\Warlord.DUN", NULL); - setloadflag_2 = 1; - } - if (currlevel == 15 && gbMaxPlayers != 1) { - pSetPiece_2 = (char *)LoadFileInMem("Levels\\L4Data\\Vile1.DUN", NULL); - setloadflag_2 = 1; - } -} - -void DRLG_FreeL4SP() -{ - MemFreeDbg(pSetPiece_2); -} - -void DRLG_L4SetSPRoom(int rx1, int ry1) -{ - int rw, rh, i, j; - BYTE *sp; - - rw = (BYTE)pSetPiece_2[0]; - rh = (BYTE)pSetPiece_2[2]; - - setpc_x = rx1; - setpc_y = ry1; - setpc_w = rw; - setpc_h = rh; - - sp = (BYTE *)&pSetPiece_2[4]; - - for (j = 0; j < rh; j++) { - for (i = 0; i < rw; i++) { - if (*sp != 0) { - dungeon[i + rx1][j + ry1] = *sp; - dflags[i + rx1][j + ry1] |= DLRG_PROTECTED; - } else { - dungeon[i + rx1][j + ry1] = 6; - } - sp += 2; - } - } -} - -void L4SaveQuads() -{ - int i, j, x, y; - - y = 0; - for (j = 0; j < 14; j++) { - x = 0; - for (i = 0; i < 14; i++) { - dflags[i + l4holdx][j + l4holdy] = 1; - dflags[DMAXX - 1 - x - l4holdx][j + l4holdy] = 1; - dflags[i + l4holdx][DMAXY - 1 - y - l4holdy] = 1; - dflags[DMAXX - 1 - x - l4holdx][DMAXY - 1 - y - l4holdy] = 1; - x++; - } - y++; - } -} - -void DRLG_L4SetRoom(BYTE *pSetPiece, int rx1, int ry1) -{ - int rw, rh, i, j; - BYTE *sp; - - rw = pSetPiece[0]; - rh = pSetPiece[2]; - sp = &pSetPiece[4]; - - for (j = 0; j < rh; j++) { - for (i = 0; i < rw; i++) { - if (*sp != 0) { - dungeon[i + rx1][j + ry1] = *sp; - dflags[i + rx1][j + ry1] |= DLRG_PROTECTED; - } else { - dungeon[i + rx1][j + ry1] = 6; - } - sp += 2; - } - } -} - -void DRLG_LoadDiabQuads(BOOL preflag) -{ - BYTE *lpSetPiece; - - lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab1.DUN", NULL); - diabquad1x = 4 + l4holdx; - diabquad1y = 4 + l4holdy; - DRLG_L4SetRoom(lpSetPiece, diabquad1x, diabquad1y); - mem_free_dbg(lpSetPiece); - - if (preflag) { - lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab2b.DUN", NULL); - } else { - lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab2a.DUN", NULL); - } - diabquad2x = 27 - l4holdx; - diabquad2y = 1 + l4holdy; - DRLG_L4SetRoom(lpSetPiece, diabquad2x, diabquad2y); - mem_free_dbg(lpSetPiece); - - if (preflag) { - lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab3b.DUN", NULL); - } else { - lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab3a.DUN", NULL); - } - diabquad3x = 1 + l4holdx; - diabquad3y = 27 - l4holdy; - DRLG_L4SetRoom(lpSetPiece, diabquad3x, diabquad3y); - mem_free_dbg(lpSetPiece); - - if (preflag) { - lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab4b.DUN", NULL); - } else { - lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab4a.DUN", NULL); - } - diabquad4x = 28 - l4holdx; - diabquad4y = 28 - l4holdy; - DRLG_L4SetRoom(lpSetPiece, diabquad4x, diabquad4y); - mem_free_dbg(lpSetPiece); -} - -BOOL IsDURWall(char d) -{ - if (d == 25) { - return TRUE; - } - if (d == 28) { - return TRUE; - } - if (d == 23) { - return TRUE; - } - - return FALSE; -} - -BOOL IsDLLWall(char dd) -{ - if (dd == 27) { - return TRUE; - } - if (dd == 26) { - return TRUE; - } - if (dd == 22) { - return TRUE; - } - - return FALSE; -} - -void L4FixRim() -{ - int i, j; - - for (i = 0; i < 20; i++) { - dung[i][0] = 0; - } - for (j = 0; j < 20; j++) { - dung[0][j] = 0; - } -} - -void DRLG_L4GeneralFix() -{ - int i, j; - - for (j = 0; j < DMAXY - 1; j++) { - for (i = 0; i < DMAXX - 1; i++) { - if ((dungeon[i][j] == 24 || dungeon[i][j] == 122) && dungeon[i + 1][j] == 2 && dungeon[i][j + 1] == 5) { - dungeon[i][j] = 17; - } - } - } -} - -void CreateL4Dungeon(DWORD rseed, int entry) -{ - SetRndSeed(rseed); - - dminx = 16; - dminy = 16; - dmaxx = 96; - dmaxy = 96; - - ViewX = 40; - ViewY = 40; - - DRLG_InitSetPC(); - DRLG_LoadL4SP(); - DRLG_L4(entry); - DRLG_L4Pass3(); - DRLG_FreeL4SP(); - DRLG_SetPC(); -} - -void DRLG_L4(int entry) -{ - int i, j, spi, spj, ar; - BOOL doneflag; - - do { - DRLG_InitTrans(); - do { - InitL4Dungeon(); - L4firstRoom(); - L4FixRim(); - ar = GetArea(); - if (ar >= 173) { - uShape(); - } - } while (ar < 173); - L4makeDungeon(); - L4makeDmt(); - L4tileFix(); - if (currlevel == 16) { - L4SaveQuads(); - } - if (QuestStatus(QTYPE_WARLRD) || currlevel == quests[QTYPE_VB]._qlevel && gbMaxPlayers != 1) { - for (spi = SP4x1; spi < SP4x2; spi++) { - for (spj = SP4y1; spj < SP4y2; spj++) { - dflags[spi][spj] = 1; - } - } - } - L4AddWall(); - DRLG_L4FloodTVal(); - DRLG_L4TransFix(); - if (setloadflag_2) { - DRLG_L4SetSPRoom(SP4x1, SP4y1); - } - if (currlevel == 16) { - DRLG_LoadDiabQuads(TRUE); - } - if (QuestStatus(QTYPE_WARLRD)) { - if (entry == 0) { - doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, 1, 0); - if (doneflag && currlevel == 13) { - doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, 0, 6); - } - ViewX++; - } else if (entry == 1) { - doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, 0, 0); - if (doneflag && currlevel == 13) { - doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, 0, 6); - } - ViewX = 2 * setpc_x + 22; - ViewY = 2 * setpc_y + 22; - } else { - doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, 0, 0); - if (doneflag && currlevel == 13) { - doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, 1, 6); - } - ViewX++; - } - } else if (currlevel != 15) { - if (entry == 0) { - doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, 1, 0); - if (doneflag && currlevel != 16) { - doneflag = DRLG_L4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, 0, 1); - } - if (doneflag && currlevel == 13) { - doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, 0, 6); - } - ViewX++; - } else if (entry == 1) { - doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, 0, 0); - if (doneflag && currlevel != 16) { - doneflag = DRLG_L4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, 1, 1); - } - if (doneflag && currlevel == 13) { - doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, 0, 6); - } - ViewY++; - } else { - doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, 0, 0); - if (doneflag && currlevel != 16) { - doneflag = DRLG_L4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, 0, 1); - } - if (doneflag && currlevel == 13) { - doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, 1, 6); - } - ViewX++; - } - } else { - if (entry == 0) { - doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, 1, 0); - if (doneflag) { - if (gbMaxPlayers == 1 && quests[QTYPE_MOD]._qactive != 2) { - doneflag = DRLG_L4PlaceMiniSet(L4PENTA, 1, 1, -1, -1, 0, 1); - } else { - doneflag = DRLG_L4PlaceMiniSet(L4PENTA2, 1, 1, -1, -1, 0, 1); - } - } - ViewX++; - } else { - doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, 0, 0); - if (doneflag) { - if (gbMaxPlayers == 1 && quests[QTYPE_MOD]._qactive != 2) { - doneflag = DRLG_L4PlaceMiniSet(L4PENTA, 1, 1, -1, -1, 1, 1); - } else { - doneflag = DRLG_L4PlaceMiniSet(L4PENTA2, 1, 1, -1, -1, 1, 1); - } - } - ViewY++; - } - } - } while (!doneflag); - - DRLG_L4GeneralFix(); - - if (currlevel != 16) { - DRLG_PlaceThemeRooms(7, 10, 6, 8, 1); - } - - DRLG_L4Shadows(); - DRLG_L4Corners(); - DRLG_L4Subs(); - DRLG_Init_Globals(); - - if (QuestStatus(QTYPE_WARLRD)) { - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - pdungeon[i][j] = dungeon[i][j]; - } - } - } - - DRLG_CheckQuests(SP4x1, SP4y1); - - if (currlevel == 15) { - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - if (dungeon[i][j] == 98) { - Make_SetPC(i - 1, j - 1, 5, 5); - } - if (dungeon[i][j] == 107) { - Make_SetPC(i - 1, j - 1, 5, 5); - } - } - } - } - if (currlevel == 16) { - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - pdungeon[i][j] = dungeon[i][j]; - } - } - DRLG_LoadDiabQuads(FALSE); - } -} - -void DRLG_L4Shadows() +static void DRLG_L4Shadows() { int x, y; BOOL okflag; @@ -679,7 +321,7 @@ void DRLG_L4Shadows() } } -void InitL4Dungeon() +static void InitL4Dungeon() { int i, j; @@ -694,7 +336,53 @@ void InitL4Dungeon() } } -void L4makeDmt() +void DRLG_LoadL4SP() +{ + setloadflag_2 = 0; + if (QuestStatus(QTYPE_WARLRD)) { + pSetPiece_2 = (char *)LoadFileInMem("Levels\\L4Data\\Warlord.DUN", NULL); + setloadflag_2 = 1; + } + if (currlevel == 15 && gbMaxPlayers != 1) { + pSetPiece_2 = (char *)LoadFileInMem("Levels\\L4Data\\Vile1.DUN", NULL); + setloadflag_2 = 1; + } +} + +void DRLG_FreeL4SP() +{ + MemFreeDbg(pSetPiece_2); +} + +void DRLG_L4SetSPRoom(int rx1, int ry1) +{ + int rw, rh, i, j; + BYTE *sp; + + rw = (BYTE)pSetPiece_2[0]; + rh = (BYTE)pSetPiece_2[2]; + + setpc_x = rx1; + setpc_y = ry1; + setpc_w = rw; + setpc_h = rh; + + sp = (BYTE *)&pSetPiece_2[4]; + + for (j = 0; j < rh; j++) { + for (i = 0; i < rw; i++) { + if (*sp != 0) { + dungeon[i + rx1][j + ry1] = *sp; + dflags[i + rx1][j + ry1] |= DLRG_PROTECTED; + } else { + dungeon[i + rx1][j + ry1] = 6; + } + sp += 2; + } + } +} + +static void L4makeDmt() { int i, j, val, dmtx, dmty; @@ -709,110 +397,7 @@ void L4makeDmt() } } -void L4AddWall() -{ - int i, j, x, y; - - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) { - if (dflags[i][j] != 0) { - continue; - } - if (dungeon[i][j] == 10 && random(0, 100) < 100) { - x = L4HWallOk(i, j); - if (x != -1) { - L4HorizWall(i, j, x); - } - } - if (dungeon[i][j] == 12 && random(0, 100) < 100) { - x = L4HWallOk(i, j); - if (x != -1) { - L4HorizWall(i, j, x); - } - } - if (dungeon[i][j] == 13 && random(0, 100) < 100) { - x = L4HWallOk(i, j); - if (x != -1) { - L4HorizWall(i, j, x); - } - } - if (dungeon[i][j] == 15 && random(0, 100) < 100) { - x = L4HWallOk(i, j); - if (x != -1) { - L4HorizWall(i, j, x); - } - } - if (dungeon[i][j] == 16 && random(0, 100) < 100) { - x = L4HWallOk(i, j); - if (x != -1) { - L4HorizWall(i, j, x); - } - } - if (dungeon[i][j] == 21 && random(0, 100) < 100) { - x = L4HWallOk(i, j); - if (x != -1) { - L4HorizWall(i, j, x); - } - } - if (dungeon[i][j] == 22 && random(0, 100) < 100) { - x = L4HWallOk(i, j); - if (x != -1) { - L4HorizWall(i, j, x); - } - } - if (dungeon[i][j] == 8 && random(0, 100) < 100) { - y = L4VWallOk(i, j); - if (y != -1) { - L4VertWall(i, j, y); - } - } - if (dungeon[i][j] == 9 && random(0, 100) < 100) { - y = L4VWallOk(i, j); - if (y != -1) { - L4VertWall(i, j, y); - } - } - if (dungeon[i][j] == 11 && random(0, 100) < 100) { - y = L4VWallOk(i, j); - if (y != -1) { - L4VertWall(i, j, y); - } - } - if (dungeon[i][j] == 14 && random(0, 100) < 100) { - y = L4VWallOk(i, j); - if (y != -1) { - L4VertWall(i, j, y); - } - } - if (dungeon[i][j] == 15 && random(0, 100) < 100) { - y = L4VWallOk(i, j); - if (y != -1) { - L4VertWall(i, j, y); - } - } - if (dungeon[i][j] == 16 && random(0, 100) < 100) { - y = L4VWallOk(i, j); - if (y != -1) { - L4VertWall(i, j, y); - } - } - if (dungeon[i][j] == 21 && random(0, 100) < 100) { - y = L4VWallOk(i, j); - if (y != -1) { - L4VertWall(i, j, y); - } - } - if (dungeon[i][j] == 23 && random(0, 100) < 100) { - y = L4VWallOk(i, j); - if (y != -1) { - L4VertWall(i, j, y); - } - } - } - } -} - -int L4HWallOk(int i, int j) +static int L4HWallOk(int i, int j) { int x; BOOL wallok; @@ -863,7 +448,7 @@ int L4HWallOk(int i, int j) } } -int L4VWallOk(int i, int j) +static int L4VWallOk(int i, int j) { int y; BOOL wallok; @@ -917,7 +502,7 @@ int L4VWallOk(int i, int j) } } -void L4HorizWall(int i, int j, int dx) +static void L4HorizWall(int i, int j, int dx) { int xx; @@ -961,7 +546,7 @@ void L4HorizWall(int i, int j, int dx) } } -void L4VertWall(int i, int j, int dy) +static void L4VertWall(int i, int j, int dy) { int yy; @@ -1008,7 +593,110 @@ void L4VertWall(int i, int j, int dy) } } -void L4tileFix() +static void L4AddWall() +{ + int i, j, x, y; + + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + if (dflags[i][j] != 0) { + continue; + } + if (dungeon[i][j] == 10 && random(0, 100) < 100) { + x = L4HWallOk(i, j); + if (x != -1) { + L4HorizWall(i, j, x); + } + } + if (dungeon[i][j] == 12 && random(0, 100) < 100) { + x = L4HWallOk(i, j); + if (x != -1) { + L4HorizWall(i, j, x); + } + } + if (dungeon[i][j] == 13 && random(0, 100) < 100) { + x = L4HWallOk(i, j); + if (x != -1) { + L4HorizWall(i, j, x); + } + } + if (dungeon[i][j] == 15 && random(0, 100) < 100) { + x = L4HWallOk(i, j); + if (x != -1) { + L4HorizWall(i, j, x); + } + } + if (dungeon[i][j] == 16 && random(0, 100) < 100) { + x = L4HWallOk(i, j); + if (x != -1) { + L4HorizWall(i, j, x); + } + } + if (dungeon[i][j] == 21 && random(0, 100) < 100) { + x = L4HWallOk(i, j); + if (x != -1) { + L4HorizWall(i, j, x); + } + } + if (dungeon[i][j] == 22 && random(0, 100) < 100) { + x = L4HWallOk(i, j); + if (x != -1) { + L4HorizWall(i, j, x); + } + } + if (dungeon[i][j] == 8 && random(0, 100) < 100) { + y = L4VWallOk(i, j); + if (y != -1) { + L4VertWall(i, j, y); + } + } + if (dungeon[i][j] == 9 && random(0, 100) < 100) { + y = L4VWallOk(i, j); + if (y != -1) { + L4VertWall(i, j, y); + } + } + if (dungeon[i][j] == 11 && random(0, 100) < 100) { + y = L4VWallOk(i, j); + if (y != -1) { + L4VertWall(i, j, y); + } + } + if (dungeon[i][j] == 14 && random(0, 100) < 100) { + y = L4VWallOk(i, j); + if (y != -1) { + L4VertWall(i, j, y); + } + } + if (dungeon[i][j] == 15 && random(0, 100) < 100) { + y = L4VWallOk(i, j); + if (y != -1) { + L4VertWall(i, j, y); + } + } + if (dungeon[i][j] == 16 && random(0, 100) < 100) { + y = L4VWallOk(i, j); + if (y != -1) { + L4VertWall(i, j, y); + } + } + if (dungeon[i][j] == 21 && random(0, 100) < 100) { + y = L4VWallOk(i, j); + if (y != -1) { + L4VertWall(i, j, y); + } + } + if (dungeon[i][j] == 23 && random(0, 100) < 100) { + y = L4VWallOk(i, j); + if (y != -1) { + L4VertWall(i, j, y); + } + } + } + } +} + +static void L4tileFix() { int i, j; @@ -1354,7 +1042,7 @@ void L4tileFix() } } -void DRLG_L4Subs() +static void DRLG_L4Subs() { int x, y, i, rv; BYTE c; @@ -1391,7 +1079,7 @@ void DRLG_L4Subs() } } -void L4makeDungeon() +static void L4makeDungeon() { int i, j, k, l; @@ -1437,7 +1125,7 @@ void L4makeDungeon() } } -void uShape() +static void uShape() { int j, i, rv; @@ -1516,7 +1204,7 @@ void uShape() } while (rv != 0); } -long GetArea() +static long GetArea() { int i, j; long rv; @@ -1534,76 +1222,40 @@ long GetArea() return rv; } -void L4firstRoom() +static void L4drawRoom(int x, int y, int width, int height) { - int x, y, w, h, rndx, rndy, xmin, xmax, ymin, ymax; + int i, j; - if (currlevel != 16) { - if (currlevel == quests[QTYPE_WARLRD]._qlevel && quests[QTYPE_WARLRD]._qactive) { - /// ASSERT: assert(gbMaxPlayers == 1); - w = 11; - h = 11; - } else if (currlevel == quests[QTYPE_VB]._qlevel && gbMaxPlayers != 1) { - w = 11; - h = 11; - } else { - w = random(0, 5) + 2; - h = random(0, 5) + 2; + for (j = 0; j < height; j++) { + for (i = 0; i < width; i++) { + dung[i + x][j + y] = 1; } - } else { - w = 14; - h = 14; - } - - xmin = (20 - w) >> 1; - xmax = 19 - w; - rndx = random(0, xmax - xmin + 1) + xmin; - if (rndx + w > 19) { - x = 19 - w + 1; - } else { - x = rndx; - } - ymin = (20 - h) >> 1; - ymax = 19 - h; - rndy = random(0, ymax - ymin + 1) + ymin; - if (rndy + h > 19) { - y = 19 - h + 1; - } else { - y = rndy; - } - - if (currlevel == 16) { - l4holdx = x; - l4holdy = y; } - if (QuestStatus(QTYPE_WARLRD) || currlevel == quests[QTYPE_VB]._qlevel && gbMaxPlayers != 1) { - SP4x1 = x + 1; - SP4y1 = y + 1; - SP4x2 = SP4x1 + w; - SP4y2 = SP4y1 + h; - } else { - SP4x1 = 0; - SP4y1 = 0; - SP4x2 = 0; - SP4y2 = 0; - } - - L4drawRoom(x, y, w, h); - L4roomGen(x, y, w, h, random(0, 2)); } -void L4drawRoom(int x, int y, int width, int height) +static BOOL L4checkRoom(int x, int y, int width, int height) { int i, j; + if (x <= 0 || y <= 0) { + return FALSE; + } + for (j = 0; j < height; j++) { for (i = 0; i < width; i++) { - dung[i + x][j + y] = 1; + if (i + x < 0 || i + x >= 20 || j + y < 0 || j + y >= 20) { + return FALSE; + } + if (dung[i + x][j + y] != 0) { + return FALSE; + } } } + + return TRUE; } -void L4roomGen(int x, int y, int w, int h, int dir) +static void L4roomGen(int x, int y, int w, int h, int dir) { int num; BOOL ran, ran2; @@ -1660,29 +1312,146 @@ void L4roomGen(int x, int y, int w, int h, int dir) } } -BOOL L4checkRoom(int x, int y, int width, int height) +static void L4firstRoom() { - int i, j; + int x, y, w, h, rndx, rndy, xmin, xmax, ymin, ymax; - if (x <= 0 || y <= 0) { - return FALSE; + if (currlevel != 16) { + if (currlevel == quests[QTYPE_WARLRD]._qlevel && quests[QTYPE_WARLRD]._qactive) { + /// ASSERT: assert(gbMaxPlayers == 1); + w = 11; + h = 11; + } else if (currlevel == quests[QTYPE_VB]._qlevel && gbMaxPlayers != 1) { + w = 11; + h = 11; + } else { + w = random(0, 5) + 2; + h = random(0, 5) + 2; + } + } else { + w = 14; + h = 14; } - for (j = 0; j < height; j++) { - for (i = 0; i < width; i++) { - if (i + x < 0 || i + x >= 20 || j + y < 0 || j + y >= 20) { - return FALSE; - } - if (dung[i + x][j + y] != 0) { - return FALSE; + xmin = (20 - w) >> 1; + xmax = 19 - w; + rndx = random(0, xmax - xmin + 1) + xmin; + if (rndx + w > 19) { + x = 19 - w + 1; + } else { + x = rndx; + } + ymin = (20 - h) >> 1; + ymax = 19 - h; + rndy = random(0, ymax - ymin + 1) + ymin; + if (rndy + h > 19) { + y = 19 - h + 1; + } else { + y = rndy; + } + + if (currlevel == 16) { + l4holdx = x; + l4holdy = y; + } + if (QuestStatus(QTYPE_WARLRD) || currlevel == quests[QTYPE_VB]._qlevel && gbMaxPlayers != 1) { + SP4x1 = x + 1; + SP4y1 = y + 1; + SP4x2 = SP4x1 + w; + SP4y2 = SP4y1 + h; + } else { + SP4x1 = 0; + SP4y1 = 0; + SP4x2 = 0; + SP4y2 = 0; + } + + L4drawRoom(x, y, w, h); + L4roomGen(x, y, w, h, random(0, 2)); +} + +void L4SaveQuads() +{ + int i, j, x, y; + + y = 0; + for (j = 0; j < 14; j++) { + x = 0; + for (i = 0; i < 14; i++) { + dflags[i + l4holdx][j + l4holdy] = 1; + dflags[DMAXX - 1 - x - l4holdx][j + l4holdy] = 1; + dflags[i + l4holdx][DMAXY - 1 - y - l4holdy] = 1; + dflags[DMAXX - 1 - x - l4holdx][DMAXY - 1 - y - l4holdy] = 1; + x++; + } + y++; + } +} + +void DRLG_L4SetRoom(BYTE *pSetPiece, int rx1, int ry1) +{ + int rw, rh, i, j; + BYTE *sp; + + rw = pSetPiece[0]; + rh = pSetPiece[2]; + sp = &pSetPiece[4]; + + for (j = 0; j < rh; j++) { + for (i = 0; i < rw; i++) { + if (*sp != 0) { + dungeon[i + rx1][j + ry1] = *sp; + dflags[i + rx1][j + ry1] |= DLRG_PROTECTED; + } else { + dungeon[i + rx1][j + ry1] = 6; } + sp += 2; } } +} - return TRUE; +void DRLG_LoadDiabQuads(BOOL preflag) +{ + BYTE *lpSetPiece; + + lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab1.DUN", NULL); + diabquad1x = 4 + l4holdx; + diabquad1y = 4 + l4holdy; + DRLG_L4SetRoom(lpSetPiece, diabquad1x, diabquad1y); + mem_free_dbg(lpSetPiece); + + if (preflag) { + lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab2b.DUN", NULL); + } else { + lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab2a.DUN", NULL); + } + diabquad2x = 27 - l4holdx; + diabquad2y = 1 + l4holdy; + DRLG_L4SetRoom(lpSetPiece, diabquad2x, diabquad2y); + mem_free_dbg(lpSetPiece); + + if (preflag) { + lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab3b.DUN", NULL); + } else { + lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab3a.DUN", NULL); + } + diabquad3x = 1 + l4holdx; + diabquad3y = 27 - l4holdy; + DRLG_L4SetRoom(lpSetPiece, diabquad3x, diabquad3y); + mem_free_dbg(lpSetPiece); + + if (preflag) { + lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab4b.DUN", NULL); + } else { + lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab4a.DUN", NULL); + } + diabquad4x = 28 - l4holdx; + diabquad4y = 28 - l4holdy; + DRLG_L4SetRoom(lpSetPiece, diabquad4x, diabquad4y); + mem_free_dbg(lpSetPiece); } -BOOL DRLG_L4PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, BOOL setview, int ldir) +static BOOL DRLG_L4PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, BOOL setview, int ldir) { int sx, sy, sw, sh, xx, yy, i, ii, numt, bailcnt; BOOL found; @@ -1757,37 +1526,19 @@ BOOL DRLG_L4PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy quests[QTYPE_VB]._qtx = sx + 1; quests[QTYPE_VB]._qty = sy + 1; } - if (setview == TRUE) { - ViewX = 2 * sx + 21; - ViewY = 2 * sy + 22; - } - if (ldir == 0) { - LvlViewX = 2 * sx + 21; - LvlViewY = 2 * sy + 22; - } - - return TRUE; -} - -void DRLG_L4FloodTVal() -{ - int i, j, xx, yy; - - yy = 16; - for (j = 0; j < DMAXY; j++) { - xx = 16; - for (i = 0; i < DMAXX; i++) { - if (dungeon[i][j] == 6 && dTransVal[xx][yy] == 0) { - DRLG_L4FTVR(i, j, xx, yy, 0); - TransVal++; - } - xx += 2; - } - yy += 2; + if (setview == TRUE) { + ViewX = 2 * sx + 21; + ViewY = 2 * sy + 22; + } + if (ldir == 0) { + LvlViewX = 2 * sx + 21; + LvlViewY = 2 * sy + 22; } + + return TRUE; } -void DRLG_L4FTVR(int i, int j, int x, int y, int d) +static void DRLG_L4FTVR(int i, int j, int x, int y, int d) { if (dTransVal[x][y] != 0 || dungeon[i][j] != 6) { if (d == 1) { @@ -1834,7 +1585,55 @@ void DRLG_L4FTVR(int i, int j, int x, int y, int d) } } -void DRLG_L4TransFix() +static void DRLG_L4FloodTVal() +{ + int i, j, xx, yy; + + yy = 16; + for (j = 0; j < DMAXY; j++) { + xx = 16; + for (i = 0; i < DMAXX; i++) { + if (dungeon[i][j] == 6 && dTransVal[xx][yy] == 0) { + DRLG_L4FTVR(i, j, xx, yy, 0); + TransVal++; + } + xx += 2; + } + yy += 2; + } +} + +BOOL IsDURWall(char d) +{ + if (d == 25) { + return TRUE; + } + if (d == 28) { + return TRUE; + } + if (d == 23) { + return TRUE; + } + + return FALSE; +} + +BOOL IsDLLWall(char dd) +{ + if (dd == 27) { + return TRUE; + } + if (dd == 26) { + return TRUE; + } + if (dd == 22) { + return TRUE; + } + + return FALSE; +} + +static void DRLG_L4TransFix() { int i, j, xx, yy; @@ -1877,7 +1676,7 @@ void DRLG_L4TransFix() } } -void DRLG_L4Corners() +static void DRLG_L4Corners() { int i, j; @@ -1894,7 +1693,188 @@ void DRLG_L4Corners() } } -void DRLG_L4Pass3() +void L4FixRim() +{ + int i, j; + + for (i = 0; i < 20; i++) { + dung[i][0] = 0; + } + for (j = 0; j < 20; j++) { + dung[0][j] = 0; + } +} + +void DRLG_L4GeneralFix() +{ + int i, j; + + for (j = 0; j < DMAXY - 1; j++) { + for (i = 0; i < DMAXX - 1; i++) { + if ((dungeon[i][j] == 24 || dungeon[i][j] == 122) && dungeon[i + 1][j] == 2 && dungeon[i][j + 1] == 5) { + dungeon[i][j] = 17; + } + } + } +} + +static void DRLG_L4(int entry) +{ + int i, j, spi, spj, ar; + BOOL doneflag; + + do { + DRLG_InitTrans(); + do { + InitL4Dungeon(); + L4firstRoom(); + L4FixRim(); + ar = GetArea(); + if (ar >= 173) { + uShape(); + } + } while (ar < 173); + L4makeDungeon(); + L4makeDmt(); + L4tileFix(); + if (currlevel == 16) { + L4SaveQuads(); + } + if (QuestStatus(QTYPE_WARLRD) || currlevel == quests[QTYPE_VB]._qlevel && gbMaxPlayers != 1) { + for (spi = SP4x1; spi < SP4x2; spi++) { + for (spj = SP4y1; spj < SP4y2; spj++) { + dflags[spi][spj] = 1; + } + } + } + L4AddWall(); + DRLG_L4FloodTVal(); + DRLG_L4TransFix(); + if (setloadflag_2) { + DRLG_L4SetSPRoom(SP4x1, SP4y1); + } + if (currlevel == 16) { + DRLG_LoadDiabQuads(TRUE); + } + if (QuestStatus(QTYPE_WARLRD)) { + if (entry == 0) { + doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, 1, 0); + if (doneflag && currlevel == 13) { + doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, 0, 6); + } + ViewX++; + } else if (entry == 1) { + doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, 0, 0); + if (doneflag && currlevel == 13) { + doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, 0, 6); + } + ViewX = 2 * setpc_x + 22; + ViewY = 2 * setpc_y + 22; + } else { + doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, 0, 0); + if (doneflag && currlevel == 13) { + doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, 1, 6); + } + ViewX++; + } + } else if (currlevel != 15) { + if (entry == 0) { + doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, 1, 0); + if (doneflag && currlevel != 16) { + doneflag = DRLG_L4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, 0, 1); + } + if (doneflag && currlevel == 13) { + doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, 0, 6); + } + ViewX++; + } else if (entry == 1) { + doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, 0, 0); + if (doneflag && currlevel != 16) { + doneflag = DRLG_L4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, 1, 1); + } + if (doneflag && currlevel == 13) { + doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, 0, 6); + } + ViewY++; + } else { + doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, 0, 0); + if (doneflag && currlevel != 16) { + doneflag = DRLG_L4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, 0, 1); + } + if (doneflag && currlevel == 13) { + doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, 1, 6); + } + ViewX++; + } + } else { + if (entry == 0) { + doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, 1, 0); + if (doneflag) { + if (gbMaxPlayers == 1 && quests[QTYPE_MOD]._qactive != 2) { + doneflag = DRLG_L4PlaceMiniSet(L4PENTA, 1, 1, -1, -1, 0, 1); + } else { + doneflag = DRLG_L4PlaceMiniSet(L4PENTA2, 1, 1, -1, -1, 0, 1); + } + } + ViewX++; + } else { + doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, 0, 0); + if (doneflag) { + if (gbMaxPlayers == 1 && quests[QTYPE_MOD]._qactive != 2) { + doneflag = DRLG_L4PlaceMiniSet(L4PENTA, 1, 1, -1, -1, 1, 1); + } else { + doneflag = DRLG_L4PlaceMiniSet(L4PENTA2, 1, 1, -1, -1, 1, 1); + } + } + ViewY++; + } + } + } while (!doneflag); + + DRLG_L4GeneralFix(); + + if (currlevel != 16) { + DRLG_PlaceThemeRooms(7, 10, 6, 8, 1); + } + + DRLG_L4Shadows(); + DRLG_L4Corners(); + DRLG_L4Subs(); + DRLG_Init_Globals(); + + if (QuestStatus(QTYPE_WARLRD)) { + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + pdungeon[i][j] = dungeon[i][j]; + } + } + } + + DRLG_CheckQuests(SP4x1, SP4y1); + + if (currlevel == 15) { + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + if (dungeon[i][j] == 98) { + Make_SetPC(i - 1, j - 1, 5, 5); + } + if (dungeon[i][j] == 107) { + Make_SetPC(i - 1, j - 1, 5, 5); + } + } + } + } + if (currlevel == 16) { + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { + pdungeon[i][j] = dungeon[i][j]; + } + } + DRLG_LoadDiabQuads(FALSE); + } +} + +static void DRLG_L4Pass3() { int i, j, xx, yy; long v1, v2, v3, v4, lv; @@ -1992,4 +1972,24 @@ void DRLG_L4Pass3() yy += 2; } } + +void CreateL4Dungeon(DWORD rseed, int entry) +{ + SetRndSeed(rseed); + + dminx = 16; + dminy = 16; + dmaxx = 96; + dmaxy = 96; + + ViewX = 40; + ViewY = 40; + + DRLG_InitSetPC(); + DRLG_LoadL4SP(); + DRLG_L4(entry); + DRLG_L4Pass3(); + DRLG_FreeL4SP(); + DRLG_SetPC(); +} #endif diff --git a/Source/drlg_l4.h b/Source/drlg_l4.h index d4ec873d5..6559545b1 100644 --- a/Source/drlg_l4.h +++ b/Source/drlg_l4.h @@ -32,30 +32,6 @@ BOOL IsDLLWall(char dd); void L4FixRim(); void DRLG_L4GeneralFix(); void CreateL4Dungeon(DWORD rseed, int entry); -void DRLG_L4(int entry); -void DRLG_L4Shadows(); -void InitL4Dungeon(); -void L4makeDmt(); -void L4AddWall(); -int L4HWallOk(int i, int j); -int L4VWallOk(int i, int j); -void L4HorizWall(int i, int j, int dx); -void L4VertWall(int i, int j, int dy); -void L4tileFix(); -void DRLG_L4Subs(); -void L4makeDungeon(); -void uShape(); -long GetArea(); -void L4firstRoom(); -void L4drawRoom(int x, int y, int width, int height); -void L4roomGen(int x, int y, int w, int h, int dir); -BOOL L4checkRoom(int x, int y, int width, int height); -BOOL DRLG_L4PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, BOOL setview, int ldir); -void DRLG_L4FloodTVal(); -void DRLG_L4FTVR(int i, int j, int x, int y, int d); -void DRLG_L4TransFix(); -void DRLG_L4Corners(); -void DRLG_L4Pass3(); /* rdata */ extern const BYTE L4ConvTbl[16];