From 3d1d01ce861e7364c4ef337e651471b9b8888fbd Mon Sep 17 00:00:00 2001 From: Adam Newgas Date: Sat, 13 Jul 2019 23:27:29 +0100 Subject: [PATCH] More use of DMAXX/DMAXY --- Source/drlg_l1.cpp | 16 +++---- Source/drlg_l2.cpp | 12 ++--- Source/drlg_l3.cpp | 112 ++++++++++++++++++++++----------------------- Source/drlg_l4.cpp | 46 +++++++++---------- 4 files changed, 93 insertions(+), 93 deletions(-) diff --git a/Source/drlg_l1.cpp b/Source/drlg_l1.cpp index 2f85c5e10..c964905e5 100644 --- a/Source/drlg_l1.cpp +++ b/Source/drlg_l1.cpp @@ -691,8 +691,8 @@ int DRLG_PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, B numt = random(0, tmax - tmin) + tmin; for (i = 0; i < numt; i++) { - sx = random(0, 40 - sw); - sy = random(0, 40 - sh); + sx = random(0, DMAXX - sw); + sy = random(0, DMAXY - sh); abort = FALSE; found = 0; @@ -739,9 +739,9 @@ int DRLG_PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, B } if (abort == FALSE) { - if (++sx == 40 - sw) { + if (++sx == DMAXX - sw) { sx = 0; - if (++sy == 40 - sh) + if (++sy == DMAXY - sh) sy = 0; } if (++found > 4000) @@ -820,7 +820,7 @@ void L5firstRoom() if (random(0, 2) == 0) { ys = 1; - ye = 39; + ye = DMAXY - 1; VR1 = random(0, 2); VR2 = random(0, 2); @@ -861,7 +861,7 @@ void L5firstRoom() HR1 = 0; } else { xs = 1; - xe = 39; + xe = DMAXX - 1; HR1 = random(0, 2); HR2 = random(0, 2); @@ -1009,8 +1009,8 @@ void L5makeDungeon() int i, j; int i_2, j_2; - for (j = 0; j < 40; j++) { - for (i = 0; i < 40; i++) { + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { j_2 = j << 1; i_2 = i << 1; L5dungeon[i_2][j_2] = dungeon[i][j]; diff --git a/Source/drlg_l2.cpp b/Source/drlg_l2.cpp index cd4bb6385..1c134261f 100644 --- a/Source/drlg_l2.cpp +++ b/Source/drlg_l2.cpp @@ -1089,7 +1089,7 @@ BOOL CreateDungeon() break; } - CreateRoom(2, 2, 39, 39, 0, 0, ForceHW, ForceH, ForceW); + CreateRoom(2, 2, DMAXX - 1, DMAXY - 1, 0, 0, ForceHW, ForceH, ForceW); while (pHallList != NULL) { GetHall(&nHx1, &nHy1, &nHx2, &nHy2, &nHd); @@ -1685,7 +1685,7 @@ BOOL DL2_FillVoids() if (y1 == 0) { yf1 = FALSE; } - if (y2 == 39) { + if (y2 == DMAXY - 1) { yf2 = FALSE; } if (y2 - y1 >= 14) { @@ -1735,7 +1735,7 @@ BOOL DL2_FillVoids() if (y1 == 0) { yf1 = FALSE; } - if (y2 == 39) { + if (y2 == DMAXY - 1) { yf2 = FALSE; } if (y2 - y1 >= 14) { @@ -1785,7 +1785,7 @@ BOOL DL2_FillVoids() if (x1 == 0) { xf1 = FALSE; } - if (x2 == 39) { + if (x2 == DMAXX - 1) { xf2 = FALSE; } if (x2 - x1 >= 14) { @@ -1809,7 +1809,7 @@ BOOL DL2_FillVoids() x2 -= 2; if (x2 - x1 > 5) { while (yf2) { - if (y2 == 39) { + if (y2 == DMAXY - 1) { yf2 = FALSE; } if (y2 - y1 >= 12) { @@ -1835,7 +1835,7 @@ BOOL DL2_FillVoids() if (x1 == 0) { xf1 = FALSE; } - if (x2 == 39) { + if (x2 == DMAXX - 1) { xf2 = FALSE; } if (x2 - x1 >= 14) { diff --git a/Source/drlg_l3.cpp b/Source/drlg_l3.cpp index a81a75aaa..0803d2fbc 100644 --- a/Source/drlg_l3.cpp +++ b/Source/drlg_l3.cpp @@ -206,8 +206,8 @@ void FixL3Warp() { int i, j; - for (j = 0; j < 40; j++) { - for (i = 0; i < 40; i++) { + 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; @@ -226,15 +226,15 @@ void FixL3HallofHeroes() { int i, j; - for (j = 0; j < 40; j++) { - for (i = 0; i < 40; i++) { + 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 < 40; j++) { - for (i = 0; i < 40; i++) { + 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; @@ -457,8 +457,8 @@ void InitL3Dungeon() memset(dungeon, 0, sizeof(dungeon)); - for (j = 0; j < 40; j++) { - for (i = 0; i < 40; i++) { + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { dungeon[i][j] = 0; dflags[i][j] = 0; } @@ -606,8 +606,8 @@ void DRLG_L3FillDiags() { int i, j, v; - for (j = 0; j < 39; j++) { - for (i = 0; i < 39; i++) { + for (j = 0; j < DMAXY - 1; j++) { + for (i = 0; i < DMAXX - 1; i++) { v = dungeon[i + 1][j + 1] + 2 * dungeon[i][j + 1] + 4 * dungeon[i + 1][j] + 8 * dungeon[i][j]; if (v == 6) { if (random(0, 2) == 0) { @@ -631,8 +631,8 @@ void DRLG_L3FillSingles() { int i, j; - for (j = 1; j < 39; j++) { - for (i = 1; i < 39; i++) { + for (j = 1; j < DMAXY - 1; j++) { + for (i = 1; i < DMAXX - 1; i++) { if (dungeon[i][j] == 0 && dungeon[i][j - 1] + dungeon[i - 1][j - 1] + dungeon[i + 1][j - 1] == 3 && dungeon[i + 1][j] + dungeon[i - 1][j] == 2 @@ -647,7 +647,7 @@ void DRLG_L3FillStraights() { int i, j, xc, xs, yc, ys, k; - for (j = 0; j < 39; j++) { + for (j = 0; j < DMAXY - 1; j++) { xs = 0; for (i = 0; i < 37; i++) { if (dungeon[i][j] == 0 && dungeon[i][j + 1] == 1) { @@ -665,7 +665,7 @@ void DRLG_L3FillStraights() } } } - for (j = 0; j < 39; j++) { + for (j = 0; j < DMAXY - 1; j++) { xs = 0; for (i = 0; i < 37; i++) { if (dungeon[i][j] == 1 && dungeon[i][j + 1] == 0) { @@ -683,7 +683,7 @@ void DRLG_L3FillStraights() } } } - for (i = 0; i < 39; i++) { + for (i = 0; i < DMAXX - 1; i++) { ys = 0; for (j = 0; j < 37; j++) { if (dungeon[i][j] == 0 && dungeon[i + 1][j] == 1) { @@ -701,7 +701,7 @@ void DRLG_L3FillStraights() } } } - for (i = 0; i < 39; i++) { + for (i = 0; i < DMAXX - 1; i++) { ys = 0; for (j = 0; j < 37; j++) { if (dungeon[i][j] == 1 && dungeon[i + 1][j] == 0) { @@ -725,11 +725,11 @@ void DRLG_L3Edges() { int i, j; - for (j = 0; j < 40; j++) { - dungeon[39][j] = 0; + for (j = 0; j < DMAXY; j++) { + dungeon[DMAXX - 1][j] = 0; } - for (i = 0; i < 40; i++) { - dungeon[i][39] = 0; + for (i = 0; i < DMAXX; i++) { + dungeon[i][DMAXY - 1] = 0; } } @@ -739,8 +739,8 @@ int DRLG_L3GetFloorArea() gfa = 0; - for (j = 0; j < 40; j++) { - for (i = 0; i < 40; i++) { + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { gfa += dungeon[i][j]; } } @@ -752,8 +752,8 @@ void DRLG_L3MakeMegas() { int i, j, v; - for (j = 0; j < 39; j++) { - for (i = 0; i < 39; i++) { + for (j = 0; j < DMAXY-1; j++) { + for (i = 0; i < DMAXX-1; i++) { v = dungeon[i + 1][j + 1] + 2 * dungeon[i][j + 1] + 4 * dungeon[i + 1][j] + 8 * dungeon[i][j]; if (v == 6) { if (random(0, 2) == 0) { @@ -771,10 +771,10 @@ void DRLG_L3MakeMegas() } dungeon[i][j] = L3ConvTbl[v]; } - dungeon[39][j] = 8; + dungeon[DMAXX-1][j] = 8; } - for (i = 0; i < 40; i++) { - dungeon[i][39] = 8; + for (i = 0; i < DMAXX; i++) { + dungeon[i][DMAXY-1] = 8; } } @@ -799,12 +799,12 @@ void DRLG_L3River() ry = 0; i = 0; while ((dungeon[rx][ry] < 25 || dungeon[rx][ry] > 28) && i < 100) { - rx = random(0, 40); - ry = random(0, 40); + rx = random(0, DMAXX); + ry = random(0, DMAXY); i++; - while ((dungeon[rx][ry] < 25 || dungeon[rx][ry] > 28) && ry < 40) { + while ((dungeon[rx][ry] < 25 || dungeon[rx][ry] > 28) && ry < DMAXY) { rx++; - if (rx >= 40) { + if (rx >= DMAXX) { rx = 0; ry++; } @@ -856,10 +856,10 @@ void DRLG_L3River() if (dir == 0 && ry > 0) { ry--; } - if (dir == 1 && ry < 40) { + if (dir == 1 && ry < DMAXY) { ry++; } - if (dir == 2 && rx < 40) { + if (dir == 2 && rx < DMAXX) { rx++; } if (dir == 3 && rx > 0) { @@ -1027,14 +1027,14 @@ void DRLG_L3Pool() BYTE k; static BYTE poolsub[15] = { 0, 35, 26, 36, 25, 29, 34, 7, 33, 28, 27, 37, 32, 31, 30 }; - for (duny = 0; duny < 40; duny++) { - for (dunx = 0; dunx < 40; dunx++) { + for (duny = 0; duny < DMAXY; duny++) { + for (dunx = 0; dunx < DMAXY; dunx++) { if (dungeon[dunx][duny] != 8) { continue; } dungeon[dunx][duny] |= 0x80; totarea = 1; - if (dunx + 1 < 40) { + if (dunx + 1 < DMAXX) { found = DRLG_L3SpawnEdge(dunx + 1, duny, &totarea); } else { found = TRUE; @@ -1044,7 +1044,7 @@ void DRLG_L3Pool() } else { found = TRUE; } - if (duny + 1 < 40 && !found) { + if (duny + 1 < DMAXY && !found) { found = DRLG_L3SpawnEdge(dunx, duny + 1, &totarea); } else { found = TRUE; @@ -1059,7 +1059,7 @@ void DRLG_L3Pool() for (i = dunx - totarea; i < dunx + totarea; i++) { // BUGFIX: In the following swap the order to first do the // index checks and only then access dungeon[i][j] - if (dungeon[i][j] & 0x80 && j >= 0 && j < 40 && i >= 0 && i < 40) { + if (dungeon[i][j] & 0x80 && j >= 0 && j < DMAXY && i >= 0 && i < DMAXX) { dungeon[i][j] &= ~0x80; if (totarea > 4 && poolchance < 25 && !found) { k = poolsub[dungeon[i][j]]; @@ -1078,12 +1078,12 @@ void DRLG_L3Pool() BOOL DRLG_L3SpawnEdge(int x, int y, int *totarea) { BYTE i; - static BYTE spawntable[15] = { 0, 10, 3, 5, 12, 6, 9, 0, 0, 12, 3, 6, 9, 10, 5 }; + 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 >= 40 || y >= 40) { + if (x < 0 || y < 0 || x >= DMAXX || y >= DMAXY) { return TRUE; } if (dungeon[x][y] & 0x80) { @@ -1131,12 +1131,12 @@ BOOL DRLG_L3SpawnEdge(int x, int y, int *totarea) BOOL DRLG_L3Spawn(int x, int y, int *totarea) { BYTE i; - static BYTE spawntable[15] = { 0, 10, 67, 5, 44, 6, 9, 0, 0, 28, 131, 6, 9, 10, 5 }; + 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 >= 40 || y >= 40) { + if (x < 0 || y < 0 || x >= DMAXX || y >= DMAXY) { return TRUE; } if (dungeon[x][y] & 0x80) { @@ -1215,21 +1215,21 @@ BOOL DRLG_L3PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy } for (i = 0; i < numt; i++) { - sx = random(0, 40 - sw); - sy = random(0, 40 - sh); + sx = random(0, DMAXX - sw); + sy = random(0, DMAXY - sh); found = FALSE; trys = 0; while (!found && trys < 200) { trys++; found = TRUE; if (cx != -1 && sx >= cx - sw && sx <= cx + 12) { - sx = random(0, 40 - sw); - sy = random(0, 40 - sh); + sx = random(0, DMAXX - sw); + sy = random(0, DMAXY - sh); found = FALSE; } if (cy != -1 && sy >= cy - sh && sy <= cy + 12) { - sx = random(0, 40 - sw); - sy = random(0, 40 - sh); + sx = random(0, DMAXX - sw); + sy = random(0, DMAXY - sh); found = FALSE; } ii = 2; @@ -1246,10 +1246,10 @@ BOOL DRLG_L3PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy } if (!found) { sx++; - if (sx == 40 - sw) { + if (sx == DMAXX - sw) { sx = 0; sy++; - if (sy == 40 - sh) { + if (sy == DMAXY - sh) { sy = 0; } } @@ -1289,8 +1289,8 @@ void DRLG_L3PlaceRndSet(const BYTE *miniset, int rndper) sw = miniset[0]; sh = miniset[1]; - for (sy = 0; sy < 40 - sh; sy++) { - for (sx = 0; sx < 40 - sw; sx++) { + 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++) { @@ -1750,8 +1750,8 @@ void LoadL3Dungeon(char *sFileName, int vx, int vy) lm += 2; } } - for (j = 0; j < 40; j++) { - for (i = 0; i < 40; i++) { + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { if (dungeon[i][j] == 0) { dungeon[i][j] = 8; } @@ -1808,8 +1808,8 @@ void LoadPreL3Dungeon(char *sFileName, int vx, int vy) lm += 2; } } - for (j = 0; j < 40; j++) { - for (i = 0; i < 40; i++) { + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { if (dungeon[i][j] == 0) { dungeon[i][j] = 8; } diff --git a/Source/drlg_l4.cpp b/Source/drlg_l4.cpp index 724394091..5d8932fe0 100644 --- a/Source/drlg_l4.cpp +++ b/Source/drlg_l4.cpp @@ -342,9 +342,9 @@ void L4SaveQuads() x = 0; for (i = 0; i < 14; i++) { dflags[i + l4holdx][j + l4holdy] = 1; - dflags[39 - x - l4holdx][j + l4holdy] = 1; - dflags[i + l4holdx][39 - y - l4holdy] = 1; - dflags[39 - x - l4holdx][39 - y - 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++; @@ -460,8 +460,8 @@ void DRLG_L4GeneralFix() { int i, j; - for (j = 0; j < 39; j++) { - for (i = 0; i < 39; i++) { + 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; } @@ -647,8 +647,8 @@ void DRLG_L4Shadows() int x, y; BOOL okflag; - for (y = 1; y < 40; y++) { - for (x = 1; x < 40; x++) { + for (y = 1; y < DMAXY; y++) { + for (x = 1; x < DMAXY; x++) { okflag = FALSE; if (dungeon[x][y] == 3) { okflag = TRUE; @@ -682,8 +682,8 @@ void InitL4Dungeon() memset(dung, 0, sizeof(dung)); memset(L4dungeon, 0, sizeof(L4dungeon)); - for (j = 0; j < 40; j++) { - for (i = 0; i < 40; i++) { + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { dungeon[i][j] = 30; dflags[i][j] = 0; } @@ -709,8 +709,8 @@ void L4AddWall() { int i, j, x, y; - for (j = 0; j < 40; j++) { - for (i = 0; i < 40; i++) { + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) { if (dflags[i][j] != 0) { continue; } @@ -1355,8 +1355,8 @@ void DRLG_L4Subs() int x, y, i, rv; BYTE c; - for (y = 0; y < 40; y++) { - for (x = 0; x < 40; x++) { + for (y = 0; y < DMAXY; y++) { + for (x = 0; x < DMAXX; x++) { if (random(0, 3) == 0) { c = L4BTYPES[dungeon[x][y]]; if (c != 0 && dflags[x][y] == 0) { @@ -1376,8 +1376,8 @@ void DRLG_L4Subs() } } } - for (y = 0; y < 40; y++) { - for (x = 0; x < 40; x++) { + for (y = 0; y < DMAXY; y++) { + for (x = 0; x < DMAXX; x++) { if (random(0, 10) == 0) { if (L4BTYPES[dungeon[x][y]] == 6 && dflags[x][y] == 0) { dungeon[x][y] = random(0, 3) + 95; @@ -1693,8 +1693,8 @@ BOOL DRLG_L4PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy } for (i = 0; i < numt; i++) { - sx = random(0, 40 - sw); - sy = random(0, 40 - sh); + sx = random(0, DMAXX - sw); + sy = random(0, DMAXY - sh); found = FALSE; for (bailcnt = 0; !found && bailcnt < 200; bailcnt++) { found = TRUE; @@ -1702,13 +1702,13 @@ BOOL DRLG_L4PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy found = FALSE; } if (cx != -1 && sx >= cx - sw && sx <= cx + 12) { - sx = random(0, 40 - sw); - sy = random(0, 40 - sh); + sx = random(0, DMAXX - sw); + sy = random(0, DMAXY - sh); found = FALSE; } if (cy != -1 && sy >= cy - sh && sy <= cy + 12) { - sx = random(0, 40 - sw); - sy = random(0, 40 - sh); + sx = random(0, DMAXX - sw); + sy = random(0, DMAXY - sh); found = FALSE; } ii = 2; @@ -1725,10 +1725,10 @@ BOOL DRLG_L4PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy } if (!found) { sx++; - if (sx == 40 - sw) { + if (sx == DMAXX - sw) { sx = 0; sy++; - if (sy == 40 - sh) { + if (sy == DMAXY - sh) { sy = 0; } }