Browse Source

Clean up variable init in drlg files

pull/2272/head
Anders Jenbo 5 years ago
parent
commit
51b71b01c9
  1. 275
      Source/drlg_l1.cpp
  2. 384
      Source/drlg_l2.cpp
  3. 425
      Source/drlg_l3.cpp
  4. 353
      Source/drlg_l4.cpp

275
Source/drlg_l1.cpp

@ -488,18 +488,13 @@ BYTE L5ConvTbl[16] = { 22, 13, 1, 13, 2, 13, 13, 13, 4, 13, 1, 13, 2, 13, 16, 13
void DRLG_InitL5Vals()
{
int i, j, pc;
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) {
if (dPiece[i][j] == 77) {
pc = 1;
dSpecial[i][j] = 1;
} else if (dPiece[i][j] == 80) {
pc = 2;
} else {
continue;
dSpecial[i][j] = 2;
}
dSpecial[i][j] = pc;
}
}
}
@ -565,10 +560,8 @@ static void DRLG_PlaceDoor(int x, int y)
void drlg_l1_crypt_lavafloor()
{
int i, j;
for (j = 1; j < 40; j++) {
for (i = 1; i < 40; i++) {
for (int j = 1; j < 40; j++) {
for (int i = 1; i < 40; i++) {
switch (dungeon[i][j]) {
case 5:
if (dungeon[i - 1][j] == 13)
@ -855,44 +848,39 @@ void drlg_l1_crypt_lavafloor()
static void DRLG_L1Shadows()
{
int x, y, i;
BYTE sd[2][2];
BYTE tnv3;
bool patflag;
uint8_t sd[2][2];
for (y = 1; y < DMAXY; y++) {
for (x = 1; x < DMAXX; x++) {
for (int y = 1; y < DMAXY; y++) {
for (int x = 1; x < DMAXX; x++) {
sd[0][0] = BSTYPES[dungeon[x][y]];
sd[1][0] = BSTYPES[dungeon[x - 1][y]];
sd[0][1] = BSTYPES[dungeon[x][y - 1]];
sd[1][1] = BSTYPES[dungeon[x - 1][y - 1]];
for (i = 0; i < 37; i++) {
if (SPATS[i].strig == sd[0][0]) {
patflag = true;
if (SPATS[i].s1 != 0 && SPATS[i].s1 != sd[1][1])
patflag = false;
if (SPATS[i].s2 != 0 && SPATS[i].s2 != sd[0][1])
patflag = false;
if (SPATS[i].s3 != 0 && SPATS[i].s3 != sd[1][0])
patflag = false;
if (patflag) {
if (SPATS[i].nv1 != 0 && L5dflags[x - 1][y - 1] == 0)
dungeon[x - 1][y - 1] = SPATS[i].nv1;
if (SPATS[i].nv2 != 0 && L5dflags[x][y - 1] == 0)
dungeon[x][y - 1] = SPATS[i].nv2;
if (SPATS[i].nv3 != 0 && L5dflags[x - 1][y] == 0)
dungeon[x - 1][y] = SPATS[i].nv3;
}
}
for (const auto &shadow : SPATS) {
if (shadow.strig != sd[0][0])
continue;
if (shadow.s1 != 0 && shadow.s1 != sd[1][1])
continue;
if (shadow.s2 != 0 && shadow.s2 != sd[0][1])
continue;
if (shadow.s3 != 0 && shadow.s3 != sd[1][0])
continue;
if (shadow.nv1 != 0 && L5dflags[x - 1][y - 1] == 0)
dungeon[x - 1][y - 1] = shadow.nv1;
if (shadow.nv2 != 0 && L5dflags[x][y - 1] == 0)
dungeon[x][y - 1] = shadow.nv2;
if (shadow.nv3 != 0 && L5dflags[x - 1][y] == 0)
dungeon[x - 1][y] = shadow.nv3;
}
}
}
for (y = 1; y < DMAXY; y++) {
for (x = 1; x < DMAXX; x++) {
for (int y = 1; y < DMAXY; y++) {
for (int x = 1; x < DMAXX; x++) {
if (dungeon[x - 1][y] == 139 && L5dflags[x - 1][y] == 0) {
tnv3 = 139;
uint8_t tnv3 = 139;
if (dungeon[x][y] == 29)
tnv3 = 141;
if (dungeon[x][y] == 32)
@ -908,7 +896,7 @@ static void DRLG_L1Shadows()
dungeon[x - 1][y] = tnv3;
}
if (dungeon[x - 1][y] == 149 && L5dflags[x - 1][y] == 0) {
tnv3 = 149;
uint8_t tnv3 = 149;
if (dungeon[x][y] == 29)
tnv3 = 153;
if (dungeon[x][y] == 32)
@ -924,7 +912,7 @@ static void DRLG_L1Shadows()
dungeon[x - 1][y] = tnv3;
}
if (dungeon[x - 1][y] == 148 && L5dflags[x - 1][y] == 0) {
tnv3 = 148;
uint8_t tnv3 = 148;
if (dungeon[x][y] == 29)
tnv3 = 154;
if (dungeon[x][y] == 32)
@ -945,22 +933,21 @@ static void DRLG_L1Shadows()
static int DRLG_PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview, int noquad, int ldir)
{
int sx, sy, sw, sh, xx, yy, i, ii, numt, found, t;
bool abort;
int sx;
int sy;
sw = miniset[0];
sh = miniset[1];
int sw = miniset[0];
int sh = miniset[1];
if (tmax - tmin == 0)
numt = 1;
else
int numt = 1;
if (tmax - tmin != 0)
numt = GenerateRnd(tmax - tmin) + tmin;
for (i = 0; i < numt; i++) {
for (int i = 0; i < numt; i++) {
sx = GenerateRnd(DMAXX - sw);
sy = GenerateRnd(DMAXY - sh);
abort = false;
found = 0;
bool abort = false;
int found = 0;
while (!abort) {
abort = true;
@ -992,10 +979,10 @@ static int DRLG_PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, in
break;
}
ii = 2;
int ii = 2;
for (yy = 0; yy < sh && abort; yy++) {
for (xx = 0; xx < sw && abort; xx++) {
for (int yy = 0; yy < sh && abort; yy++) {
for (int xx = 0; xx < sw && abort; xx++) {
if (miniset[ii] != 0 && dungeon[xx + sx][sy + yy] != miniset[ii])
abort = false;
if (L5dflags[xx + sx][sy + yy] != 0)
@ -1015,10 +1002,10 @@ static int DRLG_PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, in
}
}
ii = sw * sh + 2;
int ii = sw * sh + 2;
for (yy = 0; yy < sh; yy++) {
for (xx = 0; xx < sw; xx++) {
for (int yy = 0; yy < sh; yy++) {
for (int xx = 0; xx < sw; xx++) {
if (miniset[ii] != 0)
dungeon[xx + sx][sy + yy] = miniset[ii];
ii++;
@ -1027,7 +1014,7 @@ static int DRLG_PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, in
}
if (miniset == PWATERIN) {
t = TransVal;
int t = TransVal;
TransVal = 0;
DRLG_MRectTrans(sx, sy + 2, sx + 5, sy + 4);
TransVal = t;
@ -1158,10 +1145,10 @@ void DRLG_Init_Globals()
static void DRLG_InitL1Vals()
{
int i, j, pc;
int pc;
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) {
if (dPiece[i][j] == 12) {
pc = 1;
} else if (dPiece[i][j] == 11) {
@ -1298,10 +1285,8 @@ void LoadPreL1Dungeon(const char *path)
static void InitL5Dungeon()
{
int i, j;
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
dungeon[i][j] = 0;
L5dflags[i][j] = 0;
}
@ -1319,10 +1304,8 @@ static void L5ClearFlags()
static void L5drawRoom(int x, int y, int w, int h)
{
int i, j;
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
for (int i = 0; i < w; i++) {
dungeon[x + i][y + j] = 1;
}
}
@ -1330,10 +1313,8 @@ static 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 < height; j++) {
for (i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
for (int 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] != 0)
@ -1346,26 +1327,28 @@ static bool L5checkRoom(int x, int y, int width, int height)
static void L5roomGen(int x, int y, int w, int h, int dir)
{
bool ran, ran2;
int width, height, rx, ry, ry2;
int cw, ch, cx1, cy1, cx2;
int dirProb = GenerateRnd(4);
int num = 0;
bool ran;
bool ran2;
if ((dir == 1 && dirProb == 0) || (dir != 1 && dirProb != 0)) {
int cw;
int ch;
int cx1;
int cy1;
do {
cw = (GenerateRnd(5) + 2) & ~1;
ch = (GenerateRnd(5) + 2) & ~1;
cy1 = h / 2 + y - ch / 2;
cx1 = x - cw;
cy1 = h / 2 + y - ch / 2;
ran = L5checkRoom(cx1 - 1, cy1 - 1, ch + 2, cw + 1); /// BUGFIX: swap args 3 and 4 ("ch+2" and "cw+1")
num++;
} while (!ran && num < 20);
if (ran)
L5drawRoom(cx1, cy1, cw, ch);
cx2 = x + w;
int cx2 = x + w;
ran2 = L5checkRoom(cx2, cy1 - 1, cw + 1, ch + 2);
if (ran2)
L5drawRoom(cx2, cy1, cw, ch);
@ -1376,6 +1359,10 @@ static void L5roomGen(int x, int y, int w, int h, int dir)
return;
}
int width;
int height;
int rx;
int ry;
do {
width = (GenerateRnd(5) + 2) & ~1;
height = (GenerateRnd(5) + 2) & ~1;
@ -1387,7 +1374,7 @@ static void L5roomGen(int x, int y, int w, int h, int dir)
if (ran)
L5drawRoom(rx, ry, width, height);
ry2 = y + h;
int ry2 = y + h;
ran2 = L5checkRoom(rx - 1, ry2, width + 2, height + 1);
if (ran2)
L5drawRoom(rx, ry2, width, height);
@ -1399,12 +1386,9 @@ static void L5roomGen(int x, int y, int w, int h, int dir)
static void L5firstRoom()
{
int ys, ye, y;
int xs, xe, x;
if (GenerateRnd(2) == 0) {
ys = 1;
ye = DMAXY - 1;
int ys = 1;
int ye = DMAXY - 1;
VR1 = (GenerateRnd(2) != 0);
VR2 = (GenerateRnd(2) != 0);
@ -1424,7 +1408,7 @@ static void L5firstRoom()
else
ye = 22;
for (y = ys; y < ye; y++) {
for (int y = ys; y < ye; y++) {
dungeon[17][y] = 1;
dungeon[18][y] = 1;
dungeon[19][y] = 1;
@ -1444,8 +1428,8 @@ static void L5firstRoom()
HR2 = false;
HR1 = false;
} else {
xs = 1;
xe = DMAXX - 1;
int xs = 1;
int xe = DMAXX - 1;
HR1 = GenerateRnd(2) != 0;
HR2 = GenerateRnd(2) != 0;
@ -1465,7 +1449,7 @@ static void L5firstRoom()
else
xe = 22;
for (x = xs; x < xe; x++) {
for (int x = xs; x < xe; x++) {
dungeon[x][17] = 1;
dungeon[x][18] = 1;
dungeon[x][19] = 1;
@ -1489,13 +1473,10 @@ static void L5firstRoom()
static int L5GetArea()
{
int i, j;
int rv;
rv = 0;
int rv = 0;
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) { // NOLINT(modernize-loop-convert)
if (dungeon[i][j] == 1)
rv++;
}
@ -1506,13 +1487,10 @@ static int L5GetArea()
static void L5makeDungeon()
{
int i, j;
int i_2, j_2;
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
j_2 = j * 2;
i_2 = i * 2;
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
int i_2 = i * 2;
int j_2 = j * 2;
L5dungeon[i_2][j_2] = dungeon[i][j];
L5dungeon[i_2][j_2 + 1] = dungeon[i][j];
L5dungeon[i_2 + 1][j_2] = dungeon[i][j];
@ -1523,22 +1501,21 @@ static void L5makeDungeon()
static void L5makeDmt()
{
int i, j, idx, val, dmtx, dmty;
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) { // NOLINT(modernize-loop-convert)
dungeon[i][j] = 22;
}
}
for (j = 0, dmty = 1; dmty <= 77; j++, dmty += 2) {
for (i = 0, dmtx = 1; dmtx <= 77; i++, dmtx += 2) {
val = 8 * L5dungeon[dmtx + 1][dmty + 1]
int dmty = 1;
for (int j = 0; dmty <= 77; j++, dmty += 2) {
int dmtx = 1;
for (int i = 0; dmtx <= 77; i++, dmtx += 2) {
int val = 8 * L5dungeon[dmtx + 1][dmty + 1]
+ 4 * L5dungeon[dmtx][dmty + 1]
+ 2 * L5dungeon[dmtx + 1][dmty]
+ L5dungeon[dmtx][dmty];
idx = L5ConvTbl[val];
dungeon[i][j] = idx;
dungeon[i][j] = L5ConvTbl[val];
}
}
}
@ -1597,8 +1574,7 @@ static int L5VWallOk(int i, int j)
static void L5HorizWall(int i, int j, char p, int dx)
{
int xx;
char wt, dt;
int8_t dt;
switch (GenerateRnd(4)) {
case 0:
@ -1621,20 +1597,20 @@ static void L5HorizWall(int i, int j, char p, int dx)
break;
}
int8_t wt = 26;
if (GenerateRnd(6) == 5)
wt = 12;
else
wt = 26;
if (dt == 12)
wt = 12;
dungeon[i][j] = p;
for (xx = 1; xx < dx; xx++) {
for (int xx = 1; xx < dx; xx++) {
dungeon[i + xx][j] = dt;
}
xx = GenerateRnd(dx - 1) + 1;
int xx = GenerateRnd(dx - 1) + 1;
if (wt == 12) {
dungeon[i + xx][j] = wt;
@ -1646,8 +1622,7 @@ static void L5HorizWall(int i, int j, char p, int dx)
static void L5VertWall(int i, int j, char p, int dy)
{
int yy;
char wt, dt;
int8_t dt;
switch (GenerateRnd(4)) {
case 0:
@ -1670,20 +1645,20 @@ static void L5VertWall(int i, int j, char p, int dy)
break;
}
int8_t wt = 25;
if (GenerateRnd(6) == 5)
wt = 11;
else
wt = 25;
if (dt == 11)
wt = 11;
dungeon[i][j] = p;
for (yy = 1; yy < dy; yy++) {
for (int yy = 1; yy < dy; yy++) {
dungeon[i][j + yy] = dt;
}
yy = GenerateRnd(dy - 1) + 1;
int yy = GenerateRnd(dy - 1) + 1;
if (wt == 11) {
dungeon[i][j + yy] = wt;
@ -1695,38 +1670,36 @@ static void L5VertWall(int i, int j, char p, int dy)
static void L5AddWall()
{
int i, j, x, y;
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
if (L5dflags[i][j] == 0) {
if (dungeon[i][j] == 3 && GenerateRnd(100) < WALL_CHANCE) {
x = L5HWallOk(i, j);
int x = L5HWallOk(i, j);
if (x != -1)
L5HorizWall(i, j, 2, x);
}
if (dungeon[i][j] == 3 && GenerateRnd(100) < WALL_CHANCE) {
y = L5VWallOk(i, j);
int y = L5VWallOk(i, j);
if (y != -1)
L5VertWall(i, j, 1, y);
}
if (dungeon[i][j] == 6 && GenerateRnd(100) < WALL_CHANCE) {
x = L5HWallOk(i, j);
int x = L5HWallOk(i, j);
if (x != -1)
L5HorizWall(i, j, 4, x);
}
if (dungeon[i][j] == 7 && GenerateRnd(100) < WALL_CHANCE) {
y = L5VWallOk(i, j);
int y = L5VWallOk(i, j);
if (y != -1)
L5VertWall(i, j, 4, y);
}
if (dungeon[i][j] == 2 && GenerateRnd(100) < WALL_CHANCE) {
x = L5HWallOk(i, j);
int x = L5HWallOk(i, j);
if (x != -1)
L5HorizWall(i, j, 2, x);
}
if (dungeon[i][j] == 1 && GenerateRnd(100) < WALL_CHANCE) {
y = L5VWallOk(i, j);
int y = L5VWallOk(i, j);
if (y != -1)
L5VertWall(i, j, 1, y);
}
@ -1737,8 +1710,6 @@ static void L5AddWall()
static void DRLG_L5GChamber(int sx, int sy, bool topflag, bool bottomflag, bool leftflag, bool rightflag)
{
int i, j;
if (topflag) {
dungeon[sx + 2][sy] = 12;
dungeon[sx + 3][sy] = 12;
@ -1780,8 +1751,8 @@ static void DRLG_L5GChamber(int sx, int sy, bool topflag, bool bottomflag, bool
sx -= 11;
}
for (j = 1; j < 11; j++) {
for (i = 1; i < 11; i++) {
for (int j = 1; j < 11; j++) {
for (int i = 1; i < 11; i++) {
dungeon[i + sx][j + sy] = 13;
L5dflags[i + sx][j + sy] |= DLRG_CHAMBER;
}
@ -1987,16 +1958,14 @@ void drlg_l1_crypt_rndset(const BYTE *miniset, int rndper)
static void DRLG_L5Subs()
{
int x, y, rv, i;
for (y = 0; y < DMAXY; y++) {
for (x = 0; x < DMAXX; x++) {
for (int y = 0; y < DMAXY; y++) {
for (int x = 0; x < DMAXX; x++) {
if (GenerateRnd(4) == 0) {
BYTE c = L5BTYPES[dungeon[x][y]];
if (c != 0 && L5dflags[x][y] == 0) {
rv = GenerateRnd(16);
i = -1;
int rv = GenerateRnd(16);
int i = -1;
while (rv >= 0) {
if (++i == sizeof(L5BTYPES))
@ -2479,9 +2448,7 @@ static void DRLG_L5CornerFix()
static void DRLG_L5(lvl_entry entry)
{
int i, j, minarea;
bool doneflag;
int minarea = 761;
switch (currlevel) {
case 1:
minarea = 533;
@ -2490,10 +2457,10 @@ static void DRLG_L5(lvl_entry entry)
minarea = 693;
break;
default:
minarea = 761;
break;
}
bool doneflag;
do {
DRLG_InitTrans();
@ -2616,8 +2583,8 @@ static void DRLG_L5(lvl_entry entry)
}
} while (!doneflag);
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
if (dungeon[i][j] == 64) {
int xx = 2 * i + 16; /* todo: fix loop */
int yy = 2 * j + 16;
@ -2631,8 +2598,8 @@ static void DRLG_L5(lvl_entry entry)
DRLG_L5DirtFix();
DRLG_L5CornerFix();
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
if ((L5dflags[i][j] & ~DLRG_PROTECTED) != 0)
DRLG_PlaceDoor(i, j);
}
@ -2694,8 +2661,8 @@ static void DRLG_L5(lvl_entry entry)
DRLG_L1Floor();
}
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
pdungeon[i][j] = dungeon[i][j];
}
}

384
Source/drlg_l2.cpp

@ -1614,22 +1614,21 @@ int Patterns[100][10] = {
static bool DRLG_L2PlaceMiniSet(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;
int sw = miniset[0];
int sh = miniset[1];
sw = miniset[0];
sh = miniset[1];
if (tmax - tmin == 0) {
numt = 1;
} else {
int numt = 1;
if (tmax - tmin != 0) {
numt = GenerateRnd(tmax - tmin) + tmin;
}
for (i = 0; i < numt; i++) {
int sx = 0;
int sy = 0;
for (int i = 0; i < numt; i++) {
sx = GenerateRnd(DMAXX - sw);
sy = GenerateRnd(DMAXY - sh);
found = false;
bool found = false;
int bailcnt;
for (bailcnt = 0; !found && bailcnt < 200; bailcnt++) {
found = true;
if (sx >= nSx1 && sx <= nSx2 && sy >= nSy1 && sy <= nSy2) {
@ -1645,9 +1644,9 @@ static bool DRLG_L2PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx,
sy = GenerateRnd(DMAXY - sh);
found = false;
}
ii = 2;
for (yy = 0; yy < sh && found; yy++) {
for (xx = 0; xx < sw && found; xx++) {
int ii = 2;
for (int yy = 0; yy < sh && found; yy++) {
for (int xx = 0; xx < sw && found; xx++) {
if (miniset[ii] != 0 && dungeon[xx + sx][yy + sy] != miniset[ii]) {
found = false;
}
@ -1671,9 +1670,9 @@ static bool DRLG_L2PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx,
if (bailcnt >= 200) {
return false;
}
ii = sw * sh + 2;
for (yy = 0; yy < sh; yy++) {
for (xx = 0; xx < sw; xx++) {
int ii = sw * sh + 2;
for (int yy = 0; yy < sh; yy++) {
for (int xx = 0; xx < sw; xx++) {
if (miniset[ii] != 0) {
dungeon[xx + sx][yy + sy] = miniset[ii];
}
@ -1700,21 +1699,18 @@ static bool DRLG_L2PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx,
static void DRLG_L2PlaceRndSet(const BYTE *miniset, int rndper)
{
int sx, sy, sw, sh, xx, yy, ii, kk;
bool found;
int sw = miniset[0];
int sh = miniset[1];
sw = miniset[0];
sh = miniset[1];
for (sy = 0; sy < DMAXY - sh; sy++) {
for (sx = 0; sx < DMAXX - sw; sx++) {
found = true;
ii = 2;
for (int sy = 0; sy < DMAXY - sh; sy++) {
for (int sx = 0; sx < DMAXX - sw; sx++) {
bool found = true;
int ii = 2;
if (sx >= nSx1 && sx <= nSx2 && sy >= nSy1 && sy <= nSy2) {
found = false;
}
for (yy = 0; yy < sh && found; yy++) {
for (xx = 0; xx < sw && found; xx++) {
for (int yy = 0; yy < sh && found; yy++) {
for (int xx = 0; xx < sw && found; xx++) {
if (miniset[ii] != 0 && dungeon[xx + sx][yy + sy] != miniset[ii]) {
found = false;
}
@ -1724,10 +1720,10 @@ static void DRLG_L2PlaceRndSet(const BYTE *miniset, int rndper)
ii++;
}
}
kk = sw * sh + 2;
int kk = sw * sh + 2;
if (found) {
for (yy = std::max(sy - sh, 0); yy < std::min(sy + 2 * sh, DMAXY) && found; yy++) {
for (xx = std::max(sx - sw, 0); xx < std::min(sx + 2 * sw, DMAXX); xx++) {
for (int yy = std::max(sy - sh, 0); yy < std::min(sy + 2 * sh, DMAXY) && found; yy++) {
for (int xx = std::max(sx - sw, 0); xx < std::min(sx + 2 * sw, DMAXX); xx++) {
// BUGFIX: yy and xx can go out of bounds (fixed)
if (dungeon[xx][yy] == miniset[kk]) {
found = false;
@ -1736,8 +1732,8 @@ static void DRLG_L2PlaceRndSet(const BYTE *miniset, int rndper)
}
}
if (found && GenerateRnd(100) < rndper) {
for (yy = 0; yy < sh; yy++) {
for (xx = 0; xx < sw; xx++) {
for (int yy = 0; yy < sh; yy++) {
for (int xx = 0; xx < sw; xx++) {
if (miniset[kk] != 0) {
dungeon[xx + sx][yy + sy] = miniset[kk];
}
@ -1751,16 +1747,13 @@ static void DRLG_L2PlaceRndSet(const BYTE *miniset, int rndper)
static void DRLG_L2Subs()
{
int x, y, i, j, k, rv;
BYTE c;
for (y = 0; y < DMAXY; y++) {
for (x = 0; x < DMAXX; x++) {
for (int y = 0; y < DMAXY; y++) {
for (int x = 0; x < DMAXX; x++) {
if ((x < nSx1 || x > nSx2) && (y < nSy1 || y > nSy2) && GenerateRnd(4) == 0) {
c = BTYPESL2[dungeon[x][y]];
uint8_t c = BTYPESL2[dungeon[x][y]];
if (c != 0) {
rv = GenerateRnd(16);
k = -1;
int rv = GenerateRnd(16);
int k = -1;
while (rv >= 0) {
k++;
if (k == sizeof(BTYPESL2)) {
@ -1770,8 +1763,9 @@ static void DRLG_L2Subs()
rv--;
}
}
int j;
for (j = y - 2; j < y + 2; j++) {
for (i = x - 2; i < x + 2; i++) {
for (int i = x - 2; i < x + 2; i++) {
if (dungeon[i][j] == k) {
j = y + 3;
i = x + 2;
@ -1789,39 +1783,32 @@ static void DRLG_L2Subs()
static void DRLG_L2Shadows()
{
int x, y, i;
bool patflag;
BYTE sd[2][2];
int8_t sd[2][2];
for (y = 1; y < DMAXY; y++) {
for (x = 1; x < DMAXX; x++) {
for (int y = 1; y < DMAXY; y++) {
for (int x = 1; x < DMAXX; x++) {
sd[0][0] = BSTYPESL2[dungeon[x][y]];
sd[1][0] = BSTYPESL2[dungeon[x - 1][y]];
sd[0][1] = BSTYPESL2[dungeon[x][y - 1]];
sd[1][1] = BSTYPESL2[dungeon[x - 1][y - 1]];
for (i = 0; i < 2; i++) {
if (SPATSL2[i].strig == sd[0][0]) {
patflag = true;
if (SPATSL2[i].s1 != 0 && SPATSL2[i].s1 != sd[1][1]) {
patflag = false;
}
if (SPATSL2[i].s2 != 0 && SPATSL2[i].s2 != sd[0][1]) {
patflag = false;
}
if (SPATSL2[i].s3 != 0 && SPATSL2[i].s3 != sd[1][0]) {
patflag = false;
}
if (patflag) {
if (SPATSL2[i].nv1 != 0) {
dungeon[x - 1][y - 1] = SPATSL2[i].nv1;
}
if (SPATSL2[i].nv2 != 0) {
dungeon[x][y - 1] = SPATSL2[i].nv2;
}
if (SPATSL2[i].nv3 != 0) {
dungeon[x - 1][y] = SPATSL2[i].nv3;
}
}
for (const auto &shadow : SPATSL2) {
if (shadow.strig != sd[0][0])
continue;
if (shadow.s1 != 0 && shadow.s1 != sd[1][1])
continue;
if (shadow.s2 != 0 && shadow.s2 != sd[0][1])
continue;
if (shadow.s3 != 0 && shadow.s3 != sd[1][0])
continue;
if (shadow.nv1 != 0) {
dungeon[x - 1][y - 1] = shadow.nv1;
}
if (shadow.nv2 != 0) {
dungeon[x][y - 1] = shadow.nv2;
}
if (shadow.nv3 != 0) {
dungeon[x - 1][y] = shadow.nv3;
}
}
}
@ -1830,10 +1817,8 @@ static void DRLG_L2Shadows()
void InitDungeon()
{
int i, j;
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
predungeon[i][j] = 32;
dflags[i][j] = 0;
}
@ -1890,8 +1875,6 @@ static void DRLG_L2SetRoom(int rx1, int ry1)
static void DefineRoom(int nX1, int nY1, int nX2, int nY2, bool ForceHW)
{
int i, j;
predungeon[nX1][nY1] = 67;
predungeon[nX1][nY2] = 69;
predungeon[nX2][nY1] = 66;
@ -1904,7 +1887,7 @@ static void DefineRoom(int nX1, int nY1, int nX2, int nY2, bool ForceHW)
RoomList[nRoomCnt].nRoomy2 = nY2;
if (ForceHW) {
for (i = nX1; i < nX2; i++) {
for (int i = nX1; i < nX2; i++) {
/// BUGFIX: Should loop j between nY1 and nY2 instead of always using nY1.
while (i < nY2) {
dflags[i][nY1] |= DLRG_PROTECTED;
@ -1912,15 +1895,15 @@ static void DefineRoom(int nX1, int nY1, int nX2, int nY2, bool ForceHW)
}
}
}
for (i = nX1 + 1; i <= nX2 - 1; i++) {
for (int i = nX1 + 1; i <= nX2 - 1; i++) {
predungeon[i][nY1] = 35;
predungeon[i][nY2] = 35;
}
nY2--;
for (j = nY1 + 1; j <= nY2; j++) {
for (int j = nY1 + 1; j <= nY2; j++) {
predungeon[nX1][j] = 35;
predungeon[nX2][j] = 35;
for (i = nX1 + 1; i < nX2; i++) {
for (int i = nX1 + 1; i < nX2; i++) {
predungeon[i][j] = 46;
}
}
@ -1968,31 +1951,27 @@ static void PlaceHallExt(int nX, int nY)
*/
static void CreateRoom(int nX1, int nY1, int nX2, int nY2, int nRDest, int nHDir, bool ForceHW, int nH, int nW)
{
int nAw, nAh, nRw, nRh, nRx1, nRy1, nRx2, nRy2, nHw, nHh, nHx1, nHy1, nHx2, nHy2, nRid;
if (nRoomCnt >= 80) {
return;
}
nAw = nX2 - nX1;
nAh = nY2 - nY1;
int nAw = nX2 - nX1;
int nAh = nY2 - nY1;
if (nAw < Area_Min || nAh < Area_Min) {
return;
}
int nRw = nAw;
if (nAw > Room_Max) {
nRw = GenerateRnd(Room_Max - Room_Min) + Room_Min;
} else if (nAw > Room_Min) {
nRw = GenerateRnd(nAw - Room_Min) + Room_Min;
} else {
nRw = nAw;
}
int nRh = nAh;
if (nAh > Room_Max) {
nRh = GenerateRnd(Room_Max - Room_Min) + Room_Min;
} else if (nAh > Room_Min) {
nRh = GenerateRnd(nAh - Room_Min) + Room_Min;
} else {
nRh = nAh;
}
if (ForceHW) {
@ -2000,10 +1979,10 @@ static void CreateRoom(int nX1, int nY1, int nX2, int nY2, int nRDest, int nHDir
nRh = nH;
}
nRx1 = GenerateRnd(nX2 - nX1) + nX1;
nRy1 = GenerateRnd(nY2 - nY1) + nY1;
nRx2 = nRw + nRx1;
nRy2 = nRh + nRy1;
int nRx1 = GenerateRnd(nX2 - nX1) + nX1;
int nRy1 = GenerateRnd(nY2 - nY1) + nY1;
int nRx2 = nRw + nRx1;
int nRy2 = nRh + nRy1;
if (nRx2 > nX2) {
nRx2 = nX2;
nRx1 = nX2 - nRw;
@ -2046,21 +2025,25 @@ static void CreateRoom(int nX1, int nY1, int nX2, int nY2, int nRDest, int nHDir
nSy2 = nRy2;
}
nRid = nRoomCnt;
int nRid = nRoomCnt;
RoomList[nRid].nRoomDest = nRDest;
if (nRDest != 0) {
int nHx1 = 0;
int nHy1 = 0;
int nHx2 = 0;
int nHy2 = 0;
if (nHDir == 1) {
nHx1 = GenerateRnd(nRx2 - nRx1 - 2) + nRx1 + 1;
nHy1 = nRy1;
nHw = RoomList[nRDest].nRoomx2 - RoomList[nRDest].nRoomx1 - 2;
int nHw = RoomList[nRDest].nRoomx2 - RoomList[nRDest].nRoomx1 - 2;
nHx2 = GenerateRnd(nHw) + RoomList[nRDest].nRoomx1 + 1;
nHy2 = RoomList[nRDest].nRoomy2;
}
if (nHDir == 3) {
nHx1 = GenerateRnd(nRx2 - nRx1 - 2) + nRx1 + 1;
nHy1 = nRy2;
nHw = RoomList[nRDest].nRoomx2 - RoomList[nRDest].nRoomx1 - 2;
int nHw = RoomList[nRDest].nRoomx2 - RoomList[nRDest].nRoomx1 - 2;
nHx2 = GenerateRnd(nHw) + RoomList[nRDest].nRoomx1 + 1;
nHy2 = RoomList[nRDest].nRoomy1;
}
@ -2068,14 +2051,14 @@ static void CreateRoom(int nX1, int nY1, int nX2, int nY2, int nRDest, int nHDir
nHx1 = nRx2;
nHy1 = GenerateRnd(nRy2 - nRy1 - 2) + nRy1 + 1;
nHx2 = RoomList[nRDest].nRoomx1;
nHh = RoomList[nRDest].nRoomy2 - RoomList[nRDest].nRoomy1 - 2;
int nHh = RoomList[nRDest].nRoomy2 - RoomList[nRDest].nRoomy1 - 2;
nHy2 = GenerateRnd(nHh) + RoomList[nRDest].nRoomy1 + 1;
}
if (nHDir == 4) {
nHx1 = nRx1;
nHy1 = GenerateRnd(nRy2 - nRy1 - 2) + nRy1 + 1;
nHx2 = RoomList[nRDest].nRoomx2;
nHh = RoomList[nRDest].nRoomy2 - RoomList[nRDest].nRoomy1 - 2;
int nHh = RoomList[nRDest].nRoomy2 - RoomList[nRDest].nRoomy1 - 2;
nHy2 = GenerateRnd(nHh) + RoomList[nRDest].nRoomy1 + 1;
}
HallList.push_back({ nHx1, nHy1, nHx2, nHy2, nHDir });
@ -2096,8 +2079,7 @@ static void CreateRoom(int nX1, int nY1, int nX2, int nY2, int nRDest, int nHDir
static void ConnectHall(const HALLNODE &node)
{
int nCurrd, nDx, nDy, nRp, nOrigX1, nOrigY1, fMinusFlag, fPlusFlag;
bool fDoneflag, fInroom;
int nRp;
int nX1 = node.nHallx1;
int nY1 = node.nHally1;
@ -2105,18 +2087,18 @@ static void ConnectHall(const HALLNODE &node)
int nY2 = node.nHally2;
int nHd = node.nHalldir;
fDoneflag = false;
fMinusFlag = GenerateRnd(100);
fPlusFlag = GenerateRnd(100);
nOrigX1 = nX1;
nOrigY1 = nY1;
bool fDoneflag = false;
int fMinusFlag = GenerateRnd(100);
int fPlusFlag = GenerateRnd(100);
int nOrigX1 = nX1;
int nOrigY1 = nY1;
CreateDoorType(nX1, nY1);
CreateDoorType(nX2, nY2);
nCurrd = nHd;
int nCurrd = nHd;
nX2 -= Dir_Xadd[nCurrd];
nY2 -= Dir_Yadd[nCurrd];
predungeon[nX2][nY2] = 44;
fInroom = false;
bool fInroom = false;
while (!fDoneflag) {
if (nX1 >= 38 && nCurrd == 2) {
@ -2174,8 +2156,8 @@ static void ConnectHall(const HALLNODE &node)
fInroom = true;
}
}
nDx = abs(nX2 - nX1);
nDy = abs(nY2 - nY1);
int nDx = abs(nX2 - nX1);
int nDy = abs(nY2 - nY1);
if (nDx > nDy) {
nRp = 2 * nDx;
if (nRp > 30) {
@ -2251,13 +2233,11 @@ static void ConnectHall(const HALLNODE &node)
static void DoPatternCheck(int i, int j)
{
int k, l, x, y, nOk;
for (k = 0; Patterns[k][4] != 255; k++) {
x = i - 1;
y = j - 1;
nOk = 254;
for (l = 0; l < 9 && nOk == 254; l++) {
for (int k = 0; Patterns[k][4] != 255; k++) {
int x = i - 1;
int y = j - 1;
int nOk = 254;
for (int l = 0; l < 9 && nOk == 254; l++) {
nOk = 255;
if (l == 3 || l == 6) {
y++;
@ -2322,10 +2302,8 @@ static void DoPatternCheck(int i, int j)
static void L2TileFix()
{
int i, j;
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
if (dungeon[i][j] == 1 && dungeon[i][j + 1] == 3) {
dungeon[i][j + 1] = 1;
}
@ -2362,11 +2340,9 @@ static bool DL2_Cont(bool x1f, bool y1f, bool x2f, bool y2f)
static int DL2_NumNoChar()
{
int t, ii, jj;
t = 0;
for (jj = 0; jj < DMAXY; jj++) {
for (ii = 0; ii < DMAXX; ii++) {
int t = 0;
for (int jj = 0; jj < DMAXY; jj++) {
for (int ii = 0; ii < DMAXX; ii++) { // NOLINT(modernize-loop-convert)
if (predungeon[ii][jj] == 32) {
t++;
}
@ -2378,18 +2354,16 @@ static int DL2_NumNoChar()
static void DL2_DrawRoom(int x1, int y1, int x2, int y2)
{
int ii, jj;
for (jj = y1; jj <= y2; jj++) {
for (ii = x1; ii <= x2; ii++) {
for (int jj = y1; jj <= y2; jj++) {
for (int ii = x1; ii <= x2; ii++) {
predungeon[ii][jj] = 46;
}
}
for (jj = y1; jj <= y2; jj++) {
for (int jj = y1; jj <= y2; jj++) {
predungeon[x1][jj] = 35;
predungeon[x2][jj] = 35;
}
for (ii = x1; ii <= x2; ii++) {
for (int ii = x1; ii <= x2; ii++) {
predungeon[ii][y1] = 35;
predungeon[ii][y2] = 35;
}
@ -2397,9 +2371,7 @@ static void DL2_DrawRoom(int x1, int y1, int x2, int y2)
static void DL2_KnockWalls(int x1, int y1, int x2, int y2)
{
int ii, jj;
for (ii = x1 + 1; ii < x2; ii++) {
for (int ii = x1 + 1; ii < x2; ii++) {
if (predungeon[ii][y1 - 1] == 46 && predungeon[ii][y1 + 1] == 46) {
predungeon[ii][y1] = 46;
}
@ -2413,7 +2385,7 @@ static void DL2_KnockWalls(int x1, int y1, int x2, int y2)
predungeon[ii][y2 + 1] = 46;
}
}
for (jj = y1 + 1; jj < y2; jj++) {
for (int jj = y1 + 1; jj < y2; jj++) {
if (predungeon[x1 - 1][jj] == 46 && predungeon[x1 + 1][jj] == 46) {
predungeon[x1][jj] = 46;
}
@ -2431,67 +2403,70 @@ static void DL2_KnockWalls(int x1, int y1, int x2, int y2)
static bool DL2_FillVoids()
{
int ii, jj, xx, yy, x1, x2, y1, y2;
bool xf1, xf2, yf1, yf2;
int to;
to = 0;
int to = 0;
while (DL2_NumNoChar() > 700 && to < 100) {
xx = GenerateRnd(38) + 1;
yy = GenerateRnd(38) + 1;
int xx = GenerateRnd(38) + 1;
int yy = GenerateRnd(38) + 1;
if (predungeon[xx][yy] != 35) {
continue;
}
xf1 = xf2 = yf1 = yf2 = false;
bool xf1 = false;
bool xf2 = false;
bool yf1 = false;
bool yf2 = false;
if (predungeon[xx - 1][yy] == 32 && predungeon[xx + 1][yy] == 46) {
if (predungeon[xx + 1][yy - 1] == 46
&& predungeon[xx + 1][yy + 1] == 46
&& predungeon[xx - 1][yy - 1] == 32
&& predungeon[xx - 1][yy + 1] == 32) {
xf1 = yf1 = yf2 = true;
xf1 = true;
yf1 = true;
yf2 = true;
}
} else if (predungeon[xx + 1][yy] == 32 && predungeon[xx - 1][yy] == 46) {
if (predungeon[xx - 1][yy - 1] == 46
&& predungeon[xx - 1][yy + 1] == 46
&& predungeon[xx + 1][yy - 1] == 32
&& predungeon[xx + 1][yy + 1] == 32) {
xf2 = yf1 = yf2 = true;
xf2 = true;
yf1 = true;
yf2 = true;
}
} else if (predungeon[xx][yy - 1] == 32 && predungeon[xx][yy + 1] == 46) {
if (predungeon[xx - 1][yy + 1] == 46
&& predungeon[xx + 1][yy + 1] == 46
&& predungeon[xx - 1][yy - 1] == 32
&& predungeon[xx + 1][yy - 1] == 32) {
yf1 = xf1 = xf2 = true;
yf1 = true;
xf1 = true;
xf2 = true;
}
} else if (predungeon[xx][yy + 1] == 32 && predungeon[xx][yy - 1] == 46) {
if (predungeon[xx - 1][yy - 1] == 46
&& predungeon[xx + 1][yy - 1] == 46
&& predungeon[xx - 1][yy + 1] == 32
&& predungeon[xx + 1][yy + 1] == 32) {
yf2 = xf1 = xf2 = true;
yf2 = true;
xf1 = true;
xf2 = true;
}
}
if (DL2_Cont(xf1, yf1, xf2, yf2)) {
int x1 = xx;
if (xf1) {
x1 = xx - 1;
} else {
x1 = xx;
x1--;
}
int x2 = xx;
if (xf2) {
x2 = xx + 1;
} else {
x2 = xx;
x2++;
}
int y1 = yy;
if (yf1) {
y1 = yy - 1;
} else {
y1 = yy;
y1--;
}
int y2 = yy;
if (yf2) {
y2 = yy + 1;
} else {
y2 = yy;
y2++;
}
if (!xf1) {
while (yf1 || yf2) {
@ -2528,7 +2503,7 @@ static bool DL2_FillVoids()
if (x2 - x1 >= 12) {
xf2 = false;
}
for (jj = y1; jj <= y2; jj++) {
for (int jj = y1; jj <= y2; jj++) {
if (predungeon[x2][jj] != 32) {
xf2 = false;
}
@ -2578,7 +2553,7 @@ static bool DL2_FillVoids()
if (x2 - x1 >= 12) {
xf1 = false;
}
for (jj = y1; jj <= y2; jj++) {
for (int jj = y1; jj <= y2; jj++) {
if (predungeon[x1][jj] != 32) {
xf1 = false;
}
@ -2628,7 +2603,7 @@ static bool DL2_FillVoids()
if (y2 - y1 >= 12) {
yf2 = false;
}
for (ii = x1; ii <= x2; ii++) {
for (int ii = x1; ii <= x2; ii++) {
if (predungeon[ii][y2] != 32) {
yf2 = false;
}
@ -2678,7 +2653,7 @@ static bool DL2_FillVoids()
if (y2 - y1 >= 12) {
yf1 = false;
}
for (ii = x1; ii <= x2; ii++) {
for (int ii = x1; ii <= x2; ii++) {
if (predungeon[ii][y1] != 32) {
yf1 = false;
}
@ -2703,12 +2678,9 @@ static bool DL2_FillVoids()
static bool CreateDungeon()
{
int i, j, ForceH, ForceW;
bool ForceHW;
ForceW = 0;
ForceH = 0;
ForceHW = false;
int ForceW = 0;
int ForceH = 0;
bool ForceHW = false;
switch (currlevel) {
case 5:
@ -2743,8 +2715,8 @@ static bool CreateDungeon()
HallList.pop_front();
}
for (j = 0; j < DMAXY; j++) { /// BUGFIX: change '<=' to '<' (fixed)
for (i = 0; i < DMAXX; i++) { /// BUGFIX: change '<=' to '<' (fixed)
for (int j = 0; j < DMAXY; j++) { /// BUGFIX: change '<=' to '<' (fixed)
for (int i = 0; i < DMAXX; i++) { /// BUGFIX: change '<=' to '<' (fixed)
if (predungeon[i][j] == 67) {
predungeon[i][j] = 35;
}
@ -2791,8 +2763,8 @@ static bool CreateDungeon()
return false;
}
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
DoPatternCheck(i, j);
}
}
@ -2854,12 +2826,10 @@ static void DRLG_L2FTVR(int i, int j, int x, int y, int d)
static void DRLG_L2FloodTVal()
{
int i, j, xx, yy;
yy = 16;
for (j = 0; j < DMAXY; j++) {
xx = 16;
for (i = 0; i < DMAXX; i++) {
int yy = 16;
for (int j = 0; j < DMAXY; j++) {
int xx = 16;
for (int i = 0; i < DMAXX; i++) {
if (dungeon[i][j] == 3 && dTransVal[xx][yy] == 0) {
DRLG_L2FTVR(i, j, xx, yy, 0);
TransVal++;
@ -2872,12 +2842,10 @@ static void DRLG_L2FloodTVal()
static void DRLG_L2TransFix()
{
int i, j, xx, yy;
yy = 16;
for (j = 0; j < DMAXY; j++) {
xx = 16;
for (i = 0; i < DMAXX; i++) {
int yy = 16;
for (int j = 0; j < DMAXY; j++) {
int xx = 16;
for (int i = 0; i < DMAXX; i++) {
if (dungeon[i][j] == 14 && dungeon[i][j - 1] == 10) {
dTransVal[xx + 1][yy] = dTransVal[xx][yy];
dTransVal[xx + 1][yy + 1] = dTransVal[xx][yy];
@ -2907,10 +2875,8 @@ static void DRLG_L2TransFix()
static void L2DirtFix()
{
int i, j;
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
if (dungeon[i][j] == 13 && dungeon[i + 1][j] != 11) {
dungeon[i][j] = 146;
}
@ -2935,11 +2901,8 @@ static void L2DirtFix()
void L2LockoutFix()
{
int i, j;
bool doorok;
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
if (dungeon[i][j] == 4 && dungeon[i - 1][j] != 3) {
dungeon[i][j] = 1;
}
@ -2948,13 +2911,13 @@ void L2LockoutFix()
}
}
}
for (j = 1; j < DMAXY - 1; j++) {
for (i = 1; i < DMAXX - 1; i++) {
for (int j = 1; j < DMAXY - 1; j++) {
for (int i = 1; i < DMAXX - 1; i++) {
if ((dflags[i][j] & DLRG_PROTECTED) != 0) {
continue;
}
if ((dungeon[i][j] == 2 || dungeon[i][j] == 5) && dungeon[i][j - 1] == 3 && dungeon[i][j + 1] == 3) {
doorok = false;
bool doorok = false;
while (true) {
if (dungeon[i][j] != 2 && dungeon[i][j] != 5) {
break;
@ -2973,13 +2936,13 @@ void L2LockoutFix()
}
}
}
for (j = 1; j < DMAXX - 1; j++) { /* check: might be flipped */
for (i = 1; i < DMAXY - 1; i++) {
for (int j = 1; j < DMAXX - 1; j++) { /* check: might be flipped */
for (int i = 1; i < DMAXY - 1; i++) {
if ((dflags[j][i] & DLRG_PROTECTED) != 0) {
continue;
}
if ((dungeon[j][i] == 1 || dungeon[j][i] == 4) && dungeon[j - 1][i] == 3 && dungeon[j + 1][i] == 3) {
doorok = false;
bool doorok = false;
while (true) {
if (dungeon[j][i] != 1 && dungeon[j][i] != 4) {
break;
@ -3002,10 +2965,8 @@ void L2LockoutFix()
void L2DoorFix()
{
int i, j;
for (j = 1; j < DMAXY; j++) {
for (i = 1; i < DMAXX; i++) {
for (int j = 1; j < DMAXY; j++) {
for (int i = 1; i < DMAXX; i++) {
if (dungeon[i][j] == 4 && dungeon[i][j - 1] == 3) {
dungeon[i][j] = 7;
}
@ -3018,10 +2979,7 @@ void L2DoorFix()
static void DRLG_L2(lvl_entry entry)
{
int i, j;
bool doneflag;
doneflag = false;
bool doneflag = false;
while (!doneflag) {
nRoomCnt = 0;
InitDungeon();
@ -3181,8 +3139,8 @@ static void DRLG_L2(lvl_entry entry)
DRLG_L2Subs();
DRLG_L2Shadows();
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
pdungeon[i][j] = dungeon[i][j];
}
}
@ -3193,10 +3151,10 @@ static void DRLG_L2(lvl_entry entry)
static void DRLG_InitL2Vals()
{
int i, j, pc;
int pc;
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) {
if (dPiece[i][j] == 541) {
pc = 5;
} else if (dPiece[i][j] == 178) {
@ -3213,8 +3171,8 @@ static void DRLG_InitL2Vals()
dSpecial[i][j] = pc;
}
}
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) {
if (dPiece[i][j] == 132) {
dSpecial[i][j + 1] = 2;
dSpecial[i][j + 2] = 1;

425
Source/drlg_l3.cpp

@ -846,12 +846,10 @@ const BYTE byte_48A9C8[] = {
static void InitL3Dungeon()
{
int i, j;
memset(dungeon, 0, sizeof(dungeon));
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
dungeon[i][j] = 0;
dflags[i][j] = 0;
}
@ -860,15 +858,13 @@ static void InitL3Dungeon()
static bool DRLG_L3FillRoom(int x1, int y1, int x2, int y2)
{
int i, j, v;
if (x1 <= 1 || x2 >= 34 || y1 <= 1 || y2 >= 38) {
return false;
}
v = 0;
for (j = y1; j <= y2; j++) {
for (i = x1; i <= x2; i++) {
int v = 0;
for (int j = y1; j <= y2; j++) {
for (int i = x1; i <= x2; i++) {
v += dungeon[i][j];
}
}
@ -877,12 +873,12 @@ static bool DRLG_L3FillRoom(int x1, int y1, int x2, int y2)
return false;
}
for (j = y1 + 1; j < y2; j++) {
for (i = x1 + 1; i < x2; i++) {
for (int j = y1 + 1; j < y2; j++) {
for (int i = x1 + 1; i < x2; i++) {
dungeon[i][j] = 1;
}
}
for (j = y1; j <= y2; j++) {
for (int j = y1; j <= y2; j++) {
if (GenerateRnd(2) != 0) {
dungeon[x1][j] = 1;
}
@ -890,7 +886,7 @@ static bool DRLG_L3FillRoom(int x1, int y1, int x2, int y2)
dungeon[x2][j] = 1;
}
}
for (i = x1; i <= x2; i++) {
for (int i = x1; i <= x2; i++) {
if (GenerateRnd(2) != 0) {
dungeon[i][y1] = 1;
}
@ -904,11 +900,13 @@ static bool DRLG_L3FillRoom(int x1, int y1, int x2, int y2)
static void DRLG_L3CreateBlock(int x, int y, int obs, int dir)
{
int blksizex, blksizey, x1, y1, x2, y2;
int contflag;
int x1;
int y1;
int x2;
int y2;
blksizex = GenerateRnd(2) + 3;
blksizey = GenerateRnd(2) + 3;
int blksizex = GenerateRnd(2) + 3;
int blksizey = GenerateRnd(2) + 3;
if (dir == 0) {
y2 = y - 1;
@ -924,9 +922,9 @@ static void DRLG_L3CreateBlock(int x, int y, int obs, int dir)
}
x2 = blksizex + x1;
}
if (dir == 3) {
x2 = x - 1;
x1 = x2 - blksizex;
if (dir == 1) {
x1 = x + 1;
x2 = x1 + blksizex;
if (blksizey < obs) {
y1 = GenerateRnd(blksizey) + y;
}
@ -952,9 +950,9 @@ static void DRLG_L3CreateBlock(int x, int y, int obs, int dir)
}
x2 = blksizex + x1;
}
if (dir == 1) {
x1 = x + 1;
x2 = x1 + blksizex;
if (dir == 3) {
x2 = x - 1;
x1 = x2 - blksizex;
if (blksizey < obs) {
y1 = GenerateRnd(blksizey) + y;
}
@ -968,7 +966,7 @@ static void DRLG_L3CreateBlock(int x, int y, int obs, int dir)
}
if (DRLG_L3FillRoom(x1, y1, x2, y2)) {
contflag = GenerateRnd(4);
int contflag = GenerateRnd(4);
if (contflag != 0 && dir != 2) {
DRLG_L3CreateBlock(x1, y1, blksizey, 0);
}
@ -986,10 +984,8 @@ static void DRLG_L3CreateBlock(int x, int y, int obs, int dir)
static void DRLG_L3FloorArea(int x1, int y1, int x2, int y2)
{
int i, j;
for (j = y1; j <= y2; j++) {
for (i = x1; i <= x2; i++) {
for (int j = y1; j <= y2; j++) {
for (int i = x1; i <= x2; i++) {
dungeon[i][j] = 1;
}
}
@ -997,11 +993,9 @@ static void DRLG_L3FloorArea(int x1, int y1, int x2, int y2)
static void DRLG_L3FillDiags()
{
int i, j, v;
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];
for (int j = 0; j < DMAXY - 1; j++) {
for (int i = 0; i < DMAXX - 1; i++) {
int v = dungeon[i + 1][j + 1] + 2 * dungeon[i][j + 1] + 4 * dungeon[i + 1][j] + 8 * dungeon[i][j];
if (v == 6) {
if (GenerateRnd(2) == 0) {
dungeon[i][j] = 1;
@ -1022,10 +1016,8 @@ static void DRLG_L3FillDiags()
static void DRLG_L3FillSingles()
{
int i, j;
for (j = 1; j < DMAXY - 1; j++) {
for (i = 1; i < DMAXX - 1; i++) {
for (int j = 1; j < DMAXY - 1; j++) {
for (int 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
@ -1038,11 +1030,12 @@ static void DRLG_L3FillSingles()
static void DRLG_L3FillStraights()
{
int i, j, xc, xs, yc, ys, k, rv;
int xc;
int yc;
for (j = 0; j < DMAXY - 1; j++) {
xs = 0;
for (i = 0; i < 37; i++) {
for (int j = 0; j < DMAXY - 1; j++) {
int xs = 0;
for (int i = 0; i < 37; i++) {
if (dungeon[i][j] == 0 && dungeon[i][j + 1] == 1) {
if (xs == 0) {
xc = i;
@ -1050,8 +1043,8 @@ static void DRLG_L3FillStraights()
xs++;
} else {
if (xs > 3 && GenerateRnd(2) != 0) {
for (k = xc; k < i; k++) {
rv = GenerateRnd(2);
for (int k = xc; k < i; k++) {
int rv = GenerateRnd(2);
dungeon[k][j] = rv;
}
}
@ -1059,9 +1052,9 @@ static void DRLG_L3FillStraights()
}
}
}
for (j = 0; j < DMAXY - 1; j++) {
xs = 0;
for (i = 0; i < 37; i++) {
for (int j = 0; j < DMAXY - 1; j++) {
int xs = 0;
for (int i = 0; i < 37; i++) {
if (dungeon[i][j] == 1 && dungeon[i][j + 1] == 0) {
if (xs == 0) {
xc = i;
@ -1069,8 +1062,8 @@ static void DRLG_L3FillStraights()
xs++;
} else {
if (xs > 3 && GenerateRnd(2) != 0) {
for (k = xc; k < i; k++) {
rv = GenerateRnd(2);
for (int k = xc; k < i; k++) {
int rv = GenerateRnd(2);
dungeon[k][j + 1] = rv;
}
}
@ -1078,9 +1071,9 @@ static void DRLG_L3FillStraights()
}
}
}
for (i = 0; i < DMAXX - 1; i++) {
ys = 0;
for (j = 0; j < 37; j++) {
for (int i = 0; i < DMAXX - 1; i++) {
int ys = 0;
for (int j = 0; j < 37; j++) {
if (dungeon[i][j] == 0 && dungeon[i + 1][j] == 1) {
if (ys == 0) {
yc = j;
@ -1088,8 +1081,8 @@ static void DRLG_L3FillStraights()
ys++;
} else {
if (ys > 3 && GenerateRnd(2) != 0) {
for (k = yc; k < j; k++) {
rv = GenerateRnd(2);
for (int k = yc; k < j; k++) {
int rv = GenerateRnd(2);
dungeon[i][k] = rv;
}
}
@ -1097,9 +1090,9 @@ static void DRLG_L3FillStraights()
}
}
}
for (i = 0; i < DMAXX - 1; i++) {
ys = 0;
for (j = 0; j < 37; j++) {
for (int i = 0; i < DMAXX - 1; i++) {
int ys = 0;
for (int j = 0; j < 37; j++) {
if (dungeon[i][j] == 1 && dungeon[i + 1][j] == 0) {
if (ys == 0) {
yc = j;
@ -1107,8 +1100,8 @@ static void DRLG_L3FillStraights()
ys++;
} else {
if (ys > 3 && GenerateRnd(2) != 0) {
for (k = yc; k < j; k++) {
rv = GenerateRnd(2);
for (int k = yc; k < j; k++) {
int rv = GenerateRnd(2);
dungeon[i + 1][k] = rv;
}
}
@ -1120,24 +1113,20 @@ static void DRLG_L3FillStraights()
static void DRLG_L3Edges()
{
int i, j;
for (j = 0; j < DMAXY; j++) {
for (int j = 0; j < DMAXY; j++) {
dungeon[DMAXX - 1][j] = 0;
}
for (i = 0; i < DMAXX; i++) {
for (int i = 0; i < DMAXX; i++) { // NOLINT(modernize-loop-convert)
dungeon[i][DMAXY - 1] = 0;
}
}
static int DRLG_L3GetFloorArea()
{
int i, j, gfa;
gfa = 0;
int gfa = 0;
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) { // NOLINT(modernize-loop-convert)
gfa += dungeon[i][j];
}
}
@ -1147,13 +1136,11 @@ static int DRLG_L3GetFloorArea()
static void DRLG_L3MakeMegas()
{
int i, j, v, rv;
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];
for (int j = 0; j < DMAXY - 1; j++) {
for (int i = 0; i < DMAXX - 1; i++) {
int v = dungeon[i + 1][j + 1] + 2 * dungeon[i][j + 1] + 4 * dungeon[i + 1][j] + 8 * dungeon[i][j];
if (v == 6) {
rv = GenerateRnd(2);
int rv = GenerateRnd(2);
if (rv == 0) {
v = 12;
} else {
@ -1161,7 +1148,7 @@ static void DRLG_L3MakeMegas()
}
}
if (v == 9) {
rv = GenerateRnd(2);
int rv = GenerateRnd(2);
if (rv == 0) {
v = 13;
} else {
@ -1172,31 +1159,30 @@ static void DRLG_L3MakeMegas()
}
dungeon[DMAXX - 1][j] = 8;
}
for (i = 0; i < DMAXX; i++) {
for (int i = 0; i < DMAXX; i++) { // NOLINT(modernize-loop-convert)
dungeon[i][DMAXY - 1] = 8;
}
}
static void DRLG_L3River()
{
int rx, ry, px, py, dir, nodir, nodir2, dircheck;
int dir;
int nodir;
int river[3][100];
int riveramt;
int i, found, bridge, lpcnt;
int rivercnt = 0;
bool bail = false;
int trys = 0;
/// BUGFIX: pdir is uninitialized, add code `pdir = -1;`(fixed)
int pdir = -1;
while (trys < 200 && rivercnt < 4) {
bail = false;
bool bail = false;
while (!bail && trys < 200) {
trys++;
rx = 0;
ry = 0;
i = 0;
int rx = 0;
int ry = 0;
int i = 0;
// BUGFIX: Replace with `(ry >= DMAXY || dungeon[rx][ry] < 25 || dungeon[rx][ry] > 28) && i < 100` (fixed)
while ((ry >= DMAXY || dungeon[rx][ry] < 25 || dungeon[rx][ry] > 28) && i < 100) {
rx = GenerateRnd(DMAXX);
@ -1242,11 +1228,11 @@ static void DRLG_L3River()
river[0][0] = rx;
river[1][0] = ry;
riveramt = 1;
nodir2 = 4;
dircheck = 0;
int nodir2 = 4;
int dircheck = 0;
while (dircheck < 4 && riveramt < 100) {
px = rx;
py = ry;
int px = rx;
int py = ry;
if (dircheck == 0) {
dir = GenerateRnd(4);
} else {
@ -1383,8 +1369,9 @@ static void DRLG_L3River()
bail = false;
}
if (bail) {
found = 0;
lpcnt = 0;
int found = 0;
int lpcnt = 0;
int bridge;
while (found == 0 && lpcnt < 30) {
lpcnt++;
bridge = GenerateRnd(riveramt);
@ -1398,7 +1385,7 @@ static void DRLG_L3River()
&& dungeon[river[0][bridge] + 1][river[1][bridge]] == 7) {
found = 2;
}
for (i = 0; i < riveramt && found != 0; i++) {
for (int 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]) {
@ -1540,22 +1527,18 @@ static bool DRLG_L3Spawn(int x, int y, int *totarea)
*/
static void DRLG_L3Pool()
{
int i, j, dunx, duny, totarea, poolchance;
bool found;
BYTE k;
static BYTE poolsub[15] = { 0, 35, 26, 36, 25, 29, 34, 7, 33, 28, 27, 37, 32, 31, 30 };
constexpr uint8_t poolsub[15] = { 0, 35, 26, 36, 25, 29, 34, 7, 33, 28, 27, 37, 32, 31, 30 };
for (duny = 0; duny < DMAXY; duny++) {
for (dunx = 0; dunx < DMAXY; dunx++) {
for (int duny = 0; duny < DMAXY; duny++) {
for (int dunx = 0; dunx < DMAXY; dunx++) {
if (dungeon[dunx][duny] != 8) {
continue;
}
dungeon[dunx][duny] |= 0x80;
totarea = 1;
int totarea = 1;
bool found = true;
if (dunx + 1 < DMAXX) {
found = DRLG_L3Spawn(dunx + 1, duny, &totarea);
} else {
found = true;
}
if (dunx - 1 > 0 && !found) {
found = DRLG_L3Spawn(dunx - 1, duny, &totarea);
@ -1572,15 +1555,15 @@ static void DRLG_L3Pool()
} else {
found = true;
}
poolchance = GenerateRnd(100);
for (j = std::max(duny - totarea, 0); j < std::min(duny + totarea, DMAXY); j++) {
for (i = std::max(dunx - totarea, 0); i < std::min(dunx + totarea, DMAXX); i++) {
int poolchance = GenerateRnd(100);
for (int j = std::max(duny - totarea, 0); j < std::min(duny + totarea, DMAXY); j++) {
for (int i = std::max(dunx - totarea, 0); i < std::min(dunx + totarea, DMAXX); i++) {
// BUGFIX: In the following swap the order to first do the
// index checks and only then access dungeon[i][j] (fixed)
if ((dungeon[i][j] & 0x80) != 0) {
dungeon[i][j] &= ~0x80;
if (totarea > 4 && poolchance < 25 && !found) {
k = poolsub[dungeon[i][j]];
uint8_t k = poolsub[dungeon[i][j]];
if (k != 0 && k <= 37) {
dungeon[i][j] = k;
}
@ -1595,10 +1578,8 @@ static void DRLG_L3Pool()
static void DRLG_L3PoolFix()
{
int dunx, duny;
for (duny = 1; duny < DMAXY - 1; duny++) { // BUGFIX: Change '0' to '1' and 'DMAXY' to 'DMAXY - 1' (fixed)
for (dunx = 1; dunx < DMAXX - 1; dunx++) { // BUGFIX: Change '0' to '1' and 'DMAXX' to 'DMAXX - 1' (fixed)
for (int duny = 1; duny < DMAXY - 1; duny++) { // BUGFIX: Change '0' to '1' and 'DMAXY' to 'DMAXY - 1' (fixed)
for (int dunx = 1; dunx < DMAXX - 1; dunx++) { // BUGFIX: Change '0' to '1' and 'DMAXX' to 'DMAXX - 1' (fixed)
if (dungeon[dunx][duny] == 8) {
if (dungeon[dunx - 1][duny - 1] >= 25 && dungeon[dunx - 1][duny - 1] <= 41
&& dungeon[dunx - 1][duny] >= 25 && dungeon[dunx - 1][duny] <= 41
@ -1619,23 +1600,22 @@ static void DRLG_L3PoolFix()
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;
int sx;
int sy;
sw = miniset[0];
sh = miniset[1];
int sw = miniset[0];
int sh = miniset[1];
if (tmax - tmin == 0) {
numt = 1;
} else {
int numt = 1;
if (tmax - tmin != 0) {
numt = GenerateRnd(tmax - tmin) + tmin;
}
for (i = 0; i < numt; i++) {
for (int i = 0; i < numt; i++) {
sx = GenerateRnd(DMAXX - sw);
sy = GenerateRnd(DMAXY - sh);
found = false;
trys = 0;
bool found = false;
int trys = 0;
while (!found && trys < 200) {
trys++;
found = true;
@ -1649,9 +1629,9 @@ static bool DRLG_L3PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx,
sy = GenerateRnd(DMAXY - sh);
found = false;
}
ii = 2;
for (yy = 0; yy < sh && found; yy++) {
for (xx = 0; xx < sw && found; xx++) {
int ii = 2;
for (int yy = 0; yy < sh && found; yy++) {
for (int xx = 0; xx < sw && found; xx++) {
if (miniset[ii] != 0 && dungeon[xx + sx][yy + sy] != miniset[ii]) {
found = false;
}
@ -1675,9 +1655,9 @@ static bool DRLG_L3PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx,
if (trys >= 200) {
return true;
}
ii = sw * sh + 2;
for (yy = 0; yy < sh; yy++) {
for (xx = 0; xx < sw; xx++) {
int ii = sw * sh + 2;
for (int yy = 0; yy < sh; yy++) {
for (int xx = 0; xx < sw; xx++) {
if (miniset[ii] != 0) {
dungeon[xx + sx][yy + sy] = miniset[ii];
}
@ -1700,18 +1680,15 @@ static bool DRLG_L3PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx,
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; yy++) {
for (xx = 0; xx < sw && found; xx++) {
int sw = miniset[0];
int sh = miniset[1];
for (int sy = 0; sy < DMAXX - sh; sy++) {
for (int sx = 0; sx < DMAXY - sw; sx++) {
bool found = true;
int ii = 2;
for (int yy = 0; yy < sh && found; yy++) {
for (int xx = 0; xx < sw && found; xx++) {
if (miniset[ii] != 0 && dungeon[xx + sx][yy + sy] != miniset[ii]) {
found = false;
}
@ -1721,7 +1698,7 @@ static void DRLG_L3PlaceRndSet(const BYTE *miniset, int rndper)
ii++;
}
}
kk = sw * sh + 2;
int kk = sw * sh + 2;
if (miniset[kk] >= 84 && miniset[kk] <= 100 && found) {
// BUGFIX: accesses to dungeon can go out of bounds (fixed)
// BUGFIX: Comparisons vs 100 should use same tile as comparisons vs 84.
@ -1739,8 +1716,8 @@ static void DRLG_L3PlaceRndSet(const BYTE *miniset, int rndper)
}
}
if (found && GenerateRnd(100) < rndper) {
for (yy = 0; yy < sh; yy++) {
for (xx = 0; xx < sw; xx++) {
for (int yy = 0; yy < sh; yy++) {
for (int xx = 0; xx < sw; xx++) {
if (miniset[kk] != 0) {
dungeon[xx + sx][yy + sy] = miniset[kk];
}
@ -1754,20 +1731,16 @@ static void DRLG_L3PlaceRndSet(const BYTE *miniset, int rndper)
bool drlg_l3_hive_rnd_piece(const BYTE *miniset, int rndper)
{
int sx, sy, sw, sh, xx, yy, ii, kk;
bool found;
bool placed;
placed = false;
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; yy++) {
for (xx = 0; xx < sw && found; xx++) {
bool placed = false;
int sw = miniset[0];
int sh = miniset[1];
for (int sy = 0; sy < DMAXX - sh; sy++) {
for (int sx = 0; sx < DMAXY - sw; sx++) {
bool found = true;
int ii = 2;
for (int yy = 0; yy < sh && found; yy++) {
for (int xx = 0; xx < sw && found; xx++) {
if (miniset[ii] != 0 && dungeon[xx + sx][yy + sy] != miniset[ii]) {
found = false;
}
@ -1777,7 +1750,7 @@ bool drlg_l3_hive_rnd_piece(const BYTE *miniset, int rndper)
ii++;
}
}
kk = sw * sh + 2;
int kk = sw * sh + 2;
if (miniset[kk] >= 84 && miniset[kk] <= 100 && found) {
// BUGFIX: accesses to dungeon can go out of bounds
// BUGFIX: Comparisons vs 100 should use same tile as comparisons vs 84.
@ -1796,8 +1769,8 @@ bool drlg_l3_hive_rnd_piece(const BYTE *miniset, int rndper)
}
if (found && GenerateRnd(100) < rndper) {
placed = true;
for (yy = 0; yy < sh; yy++) {
for (xx = 0; xx < sw; xx++) {
for (int yy = 0; yy < sh; yy++) {
for (int xx = 0; xx < sw; xx++) {
if (miniset[kk] != 0) {
dungeon[xx + sx][yy + sy] = miniset[kk];
}
@ -1909,10 +1882,8 @@ static bool WoodHorizR(int x, int j)
void AddFenceDoors()
{
int i, j;
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int 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) {
@ -1933,10 +1904,8 @@ void AddFenceDoors()
void FenceDoorFix()
{
int i, j;
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int 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) {
@ -1981,25 +1950,17 @@ void FenceDoorFix()
static void DRLG_L3Wood()
{
#if (_MSC_VER >= 1920)
volatile // visual studio 2019 throws internal compiler error without it, see #708
#endif
int i,
j, x, y, xx, yy, rt, rp, x1, y1, x2, y2;
bool skip;
for (j = 1; j < DMAXY - 1; j++) { // BUGFIX: Change '0' to '1' (fixed)
for (i = 1; i < DMAXX - 1; i++) { // BUGFIX: Change '0' to '1' (fixed)
for (int j = 1; j < DMAXY - 1; j++) { // BUGFIX: Change '0' to '1' (fixed)
for (int i = 1; i < DMAXX - 1; i++) { // BUGFIX: Change '0' to '1' (fixed)
if (dungeon[i][j] == 10 && GenerateRnd(2) != 0) {
x = i;
int x = i;
while (dungeon[x][j] == 10) {
x++;
}
x--;
if (x - i > 0) {
dungeon[i][j] = 127;
for (xx = i + 1; xx < x; xx++) {
for (int xx = i + 1; xx < x; xx++) {
if (GenerateRnd(2) != 0) {
dungeon[xx][j] = 126;
} else {
@ -2010,14 +1971,14 @@ static void DRLG_L3Wood()
}
}
if (dungeon[i][j] == 9 && GenerateRnd(2) != 0) {
y = j;
int y = j;
while (dungeon[i][y] == 9) {
y++;
}
y--;
if (y - j > 0) {
dungeon[i][j] = 123;
for (yy = j + 1; yy < y; yy++) {
for (int yy = j + 1; yy < y; yy++) {
if (GenerateRnd(2) != 0) {
dungeon[i][yy] = 121;
} else {
@ -2029,12 +1990,12 @@ static void DRLG_L3Wood()
}
if (dungeon[i][j] == 11 && dungeon[i + 1][j] == 10 && dungeon[i][j + 1] == 9 && GenerateRnd(2) != 0) {
dungeon[i][j] = 125;
x = i + 1;
int x = i + 1;
while (dungeon[x][j] == 10) {
x++;
}
x--;
for (xx = i + 1; xx < x; xx++) {
for (int xx = i + 1; xx < x; xx++) {
if (GenerateRnd(2) != 0) {
dungeon[xx][j] = 126;
} else {
@ -2042,12 +2003,12 @@ static void DRLG_L3Wood()
}
}
dungeon[x][j] = 128;
y = j + 1;
int y = j + 1;
while (dungeon[i][y] == 9) {
y++;
}
y--;
for (yy = j + 1; yy < y; yy++) {
for (int yy = j + 1; yy < y; yy++) {
if (GenerateRnd(2) != 0) {
dungeon[i][yy] = 121;
} else {
@ -2059,24 +2020,24 @@ static void DRLG_L3Wood()
}
}
for (j = 1; j < DMAXY; j++) { // BUGFIX: Change '0' to '1' (fixed)
for (i = 1; i < DMAXX; i++) { // BUGFIX: Change '0' to '1' (fixed)
for (int j = 1; j < DMAXY; j++) { // BUGFIX: Change '0' to '1' (fixed)
for (int i = 1; i < DMAXX; i++) { // BUGFIX: Change '0' to '1' (fixed)
if (dungeon[i][j] == 7 && GenerateRnd(1) == 0 && SkipThemeRoom(i, j)) {
rt = GenerateRnd(2);
int rt = GenerateRnd(2);
if (rt == 0) {
y1 = j;
int y1 = j;
// BUGFIX: Check `y1 >= 0` first (fixed)
while (y1 >= 0 && WoodVertU(i, y1)) {
y1--;
}
y1++;
y2 = j;
int y2 = j;
// BUGFIX: Check `y2 < DMAXY` first (fixed)
while (y2 < DMAXY && WoodVertD(i, y2)) {
y2++;
}
y2--;
skip = true;
bool skip = true;
if (dungeon[i][y1] == 7) {
skip = false;
}
@ -2084,8 +2045,8 @@ static void DRLG_L3Wood()
skip = false;
}
if (y2 - y1 > 1 && skip) {
rp = GenerateRnd(y2 - y1 - 1) + y1 + 1;
for (y = y1; y <= y2; y++) {
int rp = GenerateRnd(y2 - y1 - 1) + y1 + 1;
for (int y = y1; y <= y2; y++) {
if (y == rp) {
continue;
}
@ -2118,19 +2079,19 @@ static void DRLG_L3Wood()
}
}
if (rt == 1) {
x1 = i;
int x1 = i;
// BUGFIX: Check `x1 >= 0` first (fixed)
while (x1 >= 0 && WoodHorizL(x1, j)) {
x1--;
}
x1++;
x2 = i;
int x2 = i;
// BUGFIX: Check `x2 < DMAXX` first (fixed)
while (x2 < DMAXX && WoodHorizR(x2, j)) {
x2++;
}
x2--;
skip = true;
bool skip = true;
if (dungeon[x1][j] == 7) {
skip = false;
}
@ -2138,8 +2099,8 @@ static void DRLG_L3Wood()
skip = false;
}
if (x2 - x1 > 1 && skip) {
rp = GenerateRnd(x2 - x1 - 1) + x1 + 1;
for (x = x1; x <= x2; x++) {
int rp = GenerateRnd(x2 - x1 - 1) + x1 + 1;
for (int x = x1; x <= x2; x++) {
if (x == rp) {
continue;
}
@ -2181,22 +2142,19 @@ static void DRLG_L3Wood()
static bool DRLG_L3Anvil()
{
int sx, sy, sw, sh, xx, yy, ii, trys;
bool found;
sw = L3ANVIL[0];
sh = L3ANVIL[1];
sx = GenerateRnd(DMAXX - sw);
sy = GenerateRnd(DMAXY - sh);
int sw = L3ANVIL[0];
int sh = L3ANVIL[1];
int sx = GenerateRnd(DMAXX - sw);
int sy = GenerateRnd(DMAXY - sh);
found = false;
trys = 0;
bool found = false;
int trys = 0;
while (!found && trys < 200) {
trys++;
found = true;
ii = 2;
for (yy = 0; yy < sh && found; yy++) {
for (xx = 0; xx < sw && found; xx++) {
int ii = 2;
for (int yy = 0; yy < sh && found; yy++) {
for (int xx = 0; xx < sw && found; xx++) {
if (L3ANVIL[ii] != 0 && dungeon[xx + sx][yy + sy] != L3ANVIL[ii]) {
found = false;
}
@ -2221,9 +2179,9 @@ static bool DRLG_L3Anvil()
return true;
}
ii = sw * sh + 2;
for (yy = 0; yy < sh; yy++) {
for (xx = 0; xx < sw; xx++) {
int ii = sw * sh + 2;
for (int yy = 0; yy < sh; yy++) {
for (int xx = 0; xx < sw; xx++) {
if (L3ANVIL[ii] != 0) {
dungeon[xx + sx][yy + sy] = L3ANVIL[ii];
}
@ -2242,10 +2200,8 @@ static bool DRLG_L3Anvil()
static void FixL3Warp()
{
int i, j;
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int 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;
@ -2262,17 +2218,15 @@ static void FixL3Warp()
static void FixL3HallofHeroes()
{
int i, j;
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int 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++) {
for (int j = 0; j < DMAXY; j++) {
for (int 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;
@ -2303,11 +2257,12 @@ static void DRLG_L3LockRec(int x, int y)
bool DRLG_L3Lockout()
{
int i, j, t, fx, fy;
int fx;
int fy;
t = 0;
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
int t = 0;
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
if (dungeon[i][j] != 0) {
lockout[i][j] = true;
fx = i;
@ -2327,8 +2282,8 @@ bool DRLG_L3Lockout()
static void DRLG_L3(lvl_entry entry)
{
int x1, y1, x2, y2, i, j;
bool found, genok;
bool found;
bool genok;
lavapool = 0;
@ -2336,10 +2291,10 @@ static void DRLG_L3(lvl_entry entry)
do {
do {
InitL3Dungeon();
x1 = GenerateRnd(20) + 10;
y1 = GenerateRnd(20) + 10;
x2 = x1 + 2;
y2 = y1 + 2;
int x1 = GenerateRnd(20) + 10;
int y1 = GenerateRnd(20) + 10;
int x2 = x1 + 2;
int y2 = y1 + 2;
DRLG_L3FillRoom(x1, y1, x2, y2);
DRLG_L3CreateBlock(x1, y1, 2, 0);
DRLG_L3CreateBlock(x2, y1, 2, 1);
@ -2570,8 +2525,8 @@ static void DRLG_L3(lvl_entry entry)
DRLG_L3PlaceRndSet(byte_48A800, 25);
}
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
pdungeon[i][j] = dungeon[i][j];
}
}
@ -2586,8 +2541,6 @@ static void DRLG_L3Pass3()
void CreateL3Dungeon(uint32_t rseed, lvl_entry entry)
{
int i, j;
SetRndSeed(rseed);
dminx = 16;
dminy = 16;
@ -2599,8 +2552,8 @@ void CreateL3Dungeon(uint32_t rseed, lvl_entry entry)
DRLG_L3Pass3();
if (currlevel < 17) {
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
for (int j = 0; j < MAXDUNY; j++) {
for (int 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) {
@ -2613,8 +2566,8 @@ void CreateL3Dungeon(uint32_t rseed, lvl_entry entry)
}
}
} else {
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) {
if (dPiece[i][j] >= 382 && dPiece[i][j] <= 457) {
DoLighting({ i, j }, 9, -1);
}

353
Source/drlg_l4.cpp

@ -155,12 +155,9 @@ const BYTE L4BTYPES[140] = {
static void DRLG_L4Shadows()
{
int x, y;
bool okflag;
for (y = 1; y < DMAXY; y++) {
for (x = 1; x < DMAXY; x++) {
okflag = false;
for (int y = 1; y < DMAXY; y++) {
for (int x = 1; x < DMAXY; x++) {
bool okflag = false;
if (dungeon[x][y] == 3) {
okflag = true;
}
@ -188,13 +185,11 @@ static void DRLG_L4Shadows()
static void InitL4Dungeon()
{
int i, j;
memset(dung, 0, sizeof(dung));
memset(L4dungeon, 0, sizeof(L4dungeon));
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
dungeon[i][j] = 30;
dflags[i][j] = 0;
}
@ -251,16 +246,15 @@ void DRLG_L4SetSPRoom(int rx1, int ry1)
static void L4makeDmt()
{
int i, j, idx, val, dmtx, dmty;
for (j = 0, dmty = 1; dmty <= 77; j++, dmty += 2) {
for (i = 0, dmtx = 1; dmtx <= 77; i++, dmtx += 2) {
val = 8 * L4dungeon[dmtx + 1][dmty + 1]
int dmty = 1;
for (int j = 0; dmty <= 77; j++, dmty += 2) {
int dmtx = 1;
for (int i = 0; dmtx <= 77; i++, dmtx += 2) {
int val = 8 * L4dungeon[dmtx + 1][dmty + 1]
+ 4 * L4dungeon[dmtx][dmty + 1]
+ 2 * L4dungeon[dmtx + 1][dmty]
+ L4dungeon[dmtx][dmty];
idx = L4ConvTbl[val];
dungeon[i][j] = idx;
dungeon[i][j] = L4ConvTbl[val];
}
}
}
@ -268,8 +262,6 @@ static void L4makeDmt()
static int L4HWallOk(int i, int j)
{
int x;
bool wallok;
for (x = 1; dungeon[i + x][j] == 6; x++) {
if (dflags[i + x][j] != 0) {
break;
@ -282,7 +274,7 @@ static int L4HWallOk(int i, int j)
}
}
wallok = false;
bool wallok = false;
if (dungeon[i + x][j] == 10) {
wallok = true;
@ -318,8 +310,6 @@ static int L4HWallOk(int i, int j)
static int L4VWallOk(int i, int j)
{
int y;
bool wallok;
for (y = 1; dungeon[i][j + y] == 6; y++) {
if (dflags[i][j + y] != 0) {
break;
@ -332,7 +322,7 @@ static int L4VWallOk(int i, int j)
}
}
wallok = false;
bool wallok = false;
if (dungeon[i][j + y] == 8) {
wallok = true;
@ -370,8 +360,6 @@ static int L4VWallOk(int i, int j)
static void L4HorizWall(int i, int j, int dx)
{
int xx;
if (dungeon[i][j] == 13) {
dungeon[i][j] = 17;
}
@ -382,7 +370,7 @@ static void L4HorizWall(int i, int j, int dx)
dungeon[i][j] = 14;
}
for (xx = 1; xx < dx; xx++) {
for (int xx = 1; xx < dx; xx++) {
dungeon[i + xx][j] = 2;
}
@ -399,7 +387,7 @@ static void L4HorizWall(int i, int j, int dx)
dungeon[i + dx][j] = 29;
}
xx = GenerateRnd(dx - 3) + 1;
int xx = GenerateRnd(dx - 3) + 1;
dungeon[i + xx][j] = 57;
dungeon[i + xx + 2][j] = 56;
dungeon[i + xx + 1][j] = 60;
@ -414,8 +402,6 @@ static void L4HorizWall(int i, int j, int dx)
static void L4VertWall(int i, int j, int dy)
{
int yy;
if (dungeon[i][j] == 14) {
dungeon[i][j] = 17;
}
@ -426,7 +412,7 @@ static void L4VertWall(int i, int j, int dy)
dungeon[i][j] = 10;
}
for (yy = 1; yy < dy; yy++) {
for (int yy = 1; yy < dy; yy++) {
dungeon[i][j + yy] = 1;
}
@ -446,7 +432,7 @@ static void L4VertWall(int i, int j, int dy)
dungeon[i][j + dy] = 29;
}
yy = GenerateRnd(dy - 3) + 1;
int yy = GenerateRnd(dy - 3) + 1;
dungeon[i][j + yy] = 53;
dungeon[i][j + yy + 2] = 52;
dungeon[i][j + yy + 1] = 6;
@ -461,99 +447,97 @@ static void L4VertWall(int i, int j, int dy)
static void L4AddWall()
{
int i, j, x, y;
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
if (dflags[i][j] != 0) {
continue;
}
if (dungeon[i][j] == 10 && GenerateRnd(100) < WALL_CHANCE) {
x = L4HWallOk(i, j);
int x = L4HWallOk(i, j);
if (x != -1) {
L4HorizWall(i, j, x);
}
}
if (dungeon[i][j] == 12 && GenerateRnd(100) < WALL_CHANCE) {
x = L4HWallOk(i, j);
int x = L4HWallOk(i, j);
if (x != -1) {
L4HorizWall(i, j, x);
}
}
if (dungeon[i][j] == 13 && GenerateRnd(100) < WALL_CHANCE) {
x = L4HWallOk(i, j);
int x = L4HWallOk(i, j);
if (x != -1) {
L4HorizWall(i, j, x);
}
}
if (dungeon[i][j] == 15 && GenerateRnd(100) < WALL_CHANCE) {
x = L4HWallOk(i, j);
int x = L4HWallOk(i, j);
if (x != -1) {
L4HorizWall(i, j, x);
}
}
if (dungeon[i][j] == 16 && GenerateRnd(100) < WALL_CHANCE) {
x = L4HWallOk(i, j);
int x = L4HWallOk(i, j);
if (x != -1) {
L4HorizWall(i, j, x);
}
}
if (dungeon[i][j] == 21 && GenerateRnd(100) < WALL_CHANCE) {
x = L4HWallOk(i, j);
int x = L4HWallOk(i, j);
if (x != -1) {
L4HorizWall(i, j, x);
}
}
if (dungeon[i][j] == 22 && GenerateRnd(100) < WALL_CHANCE) {
x = L4HWallOk(i, j);
int x = L4HWallOk(i, j);
if (x != -1) {
L4HorizWall(i, j, x);
}
}
if (dungeon[i][j] == 8 && GenerateRnd(100) < WALL_CHANCE) {
y = L4VWallOk(i, j);
int y = L4VWallOk(i, j);
if (y != -1) {
L4VertWall(i, j, y);
}
}
if (dungeon[i][j] == 9 && GenerateRnd(100) < WALL_CHANCE) {
y = L4VWallOk(i, j);
int y = L4VWallOk(i, j);
if (y != -1) {
L4VertWall(i, j, y);
}
}
if (dungeon[i][j] == 11 && GenerateRnd(100) < WALL_CHANCE) {
y = L4VWallOk(i, j);
int y = L4VWallOk(i, j);
if (y != -1) {
L4VertWall(i, j, y);
}
}
if (dungeon[i][j] == 14 && GenerateRnd(100) < WALL_CHANCE) {
y = L4VWallOk(i, j);
int y = L4VWallOk(i, j);
if (y != -1) {
L4VertWall(i, j, y);
}
}
if (dungeon[i][j] == 15 && GenerateRnd(100) < WALL_CHANCE) {
y = L4VWallOk(i, j);
int y = L4VWallOk(i, j);
if (y != -1) {
L4VertWall(i, j, y);
}
}
if (dungeon[i][j] == 16 && GenerateRnd(100) < WALL_CHANCE) {
y = L4VWallOk(i, j);
int y = L4VWallOk(i, j);
if (y != -1) {
L4VertWall(i, j, y);
}
}
if (dungeon[i][j] == 21 && GenerateRnd(100) < WALL_CHANCE) {
y = L4VWallOk(i, j);
int y = L4VWallOk(i, j);
if (y != -1) {
L4VertWall(i, j, y);
}
}
if (dungeon[i][j] == 23 && GenerateRnd(100) < WALL_CHANCE) {
y = L4VWallOk(i, j);
int y = L4VWallOk(i, j);
if (y != -1) {
L4VertWall(i, j, y);
}
@ -564,10 +548,8 @@ static void L4AddWall()
static void L4tileFix()
{
int i, j;
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
if (dungeon[i][j] == 2 && dungeon[i + 1][j] == 6)
dungeon[i + 1][j] = 5;
if (dungeon[i][j] == 2 && dungeon[i + 1][j] == 1)
@ -576,8 +558,8 @@ static void L4tileFix()
dungeon[i][j + 1] = 14;
}
}
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
if (dungeon[i][j] == 2 && dungeon[i + 1][j] == 6)
dungeon[i + 1][j] = 2;
if (dungeon[i][j] == 2 && dungeon[i + 1][j] == 9)
@ -596,8 +578,8 @@ static void L4tileFix()
dungeon[i][j - 1] = 1;
}
}
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
if (dungeon[i][j] == 13 && dungeon[i][j + 1] == 30)
dungeon[i][j + 1] = 27;
if (dungeon[i][j] == 27 && dungeon[i + 1][j] == 30)
@ -784,8 +766,8 @@ static void L4tileFix()
dungeon[i + 1][j] = 16;
}
}
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
if (dungeon[i][j] == 21 && dungeon[i][j + 1] == 24 && dungeon[i][j + 2] == 1)
dungeon[i][j + 1] = 17;
if (dungeon[i][j] == 15 && dungeon[i + 1][j + 1] == 9 && dungeon[i + 1][j - 1] == 1 && dungeon[i + 2][j] == 16)
@ -856,8 +838,8 @@ static void L4tileFix()
dungeon[i + 1][j] = 16;
}
}
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
if (dungeon[i][j] == 21 && dungeon[i + 1][j] == 10)
dungeon[i + 1][j] = 17;
if (dungeon[i][j] == 17 && dungeon[i + 1][j] == 4)
@ -896,8 +878,8 @@ static void L4tileFix()
dungeon[i + 1][j] = 16;
}
}
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
if (dungeon[i][j] == 15 && dungeon[i + 1][j] == 28 && dungeon[i + 2][j] == 16)
dungeon[i + 1][j] = 23;
if (dungeon[i][j] == 21 && dungeon[i + 1][j - 1] == 21 && dungeon[i + 1][j + 1] == 13 && dungeon[i + 2][j] == 2)
@ -910,18 +892,15 @@ static void L4tileFix()
static void DRLG_L4Subs()
{
int x, y, i, rv;
BYTE c;
for (y = 0; y < DMAXY; y++) {
for (x = 0; x < DMAXX; x++) {
rv = GenerateRnd(3);
for (int y = 0; y < DMAXY; y++) {
for (int x = 0; x < DMAXX; x++) {
int rv = GenerateRnd(3);
if (rv == 0) {
c = dungeon[x][y];
uint8_t c = dungeon[x][y];
c = L4BTYPES[c];
if (c != 0 && dflags[x][y] == 0) {
rv = GenerateRnd(16);
i = -1;
int i = -1;
while (rv >= 0) {
i++;
if (i == sizeof(L4BTYPES)) {
@ -936,11 +915,11 @@ static void DRLG_L4Subs()
}
}
}
for (y = 0; y < DMAXY; y++) {
for (x = 0; x < DMAXX; x++) {
rv = GenerateRnd(10);
for (int y = 0; y < DMAXY; y++) {
for (int x = 0; x < DMAXX; x++) {
int rv = GenerateRnd(10);
if (rv == 0) {
c = dungeon[x][y];
uint8_t c = dungeon[x][y];
if (L4BTYPES[c] == 6 && dflags[x][y] == 0) {
dungeon[x][y] = GenerateRnd(3) + 95;
}
@ -951,42 +930,40 @@ static void DRLG_L4Subs()
static void L4makeDungeon()
{
int i, j, k, l;
for (j = 0; j < 20; j++) {
for (i = 0; i < 20; i++) {
k = i * 2;
l = j * 2;
for (int j = 0; j < 20; j++) {
for (int i = 0; i < 20; i++) {
int k = i * 2;
int l = j * 2;
L4dungeon[k][l] = dung[i][j];
L4dungeon[k][l + 1] = dung[i][j];
L4dungeon[k + 1][l] = dung[i][j];
L4dungeon[k + 1][l + 1] = dung[i][j];
}
}
for (j = 0; j < 20; j++) {
for (i = 0; i < 20; i++) {
k = i * 2;
l = j * 2;
for (int j = 0; j < 20; j++) {
for (int i = 0; i < 20; i++) {
int k = i * 2;
int l = j * 2;
L4dungeon[k][l + 40] = dung[i][19 - j];
L4dungeon[k][l + 41] = dung[i][19 - j];
L4dungeon[k + 1][l + 40] = dung[i][19 - j];
L4dungeon[k + 1][l + 41] = dung[i][19 - j];
}
}
for (j = 0; j < 20; j++) {
for (i = 0; i < 20; i++) {
k = i * 2;
l = j * 2;
for (int j = 0; j < 20; j++) {
for (int i = 0; i < 20; i++) {
int k = i * 2;
int l = j * 2;
L4dungeon[k + 40][l] = dung[19 - i][j];
L4dungeon[k + 40][l + 1] = dung[19 - i][j];
L4dungeon[k + 41][l] = dung[19 - i][j];
L4dungeon[k + 41][l + 1] = dung[19 - i][j];
}
}
for (j = 0; j < 20; j++) {
for (i = 0; i < 20; i++) {
k = i * 2;
l = j * 2;
for (int j = 0; j < 20; j++) {
for (int i = 0; i < 20; i++) {
int k = i * 2;
int l = j * 2;
L4dungeon[k + 40][l + 40] = dung[19 - i][19 - j];
L4dungeon[k + 40][l + 41] = dung[19 - i][19 - j];
L4dungeon[k + 41][l + 40] = dung[19 - i][19 - j];
@ -997,10 +974,8 @@ static void L4makeDungeon()
static void uShape()
{
int j, i, rv;
for (j = 19; j >= 0; j--) {
for (i = 19; i >= 0; i--) {
for (int j = 19; j >= 0; j--) {
for (int i = 19; i >= 0; i--) {
if (dung[i][j] != 1) {
hallok[j] = false;
}
@ -1017,10 +992,10 @@ static void uShape()
}
}
rv = GenerateRnd(19) + 1;
int rv = GenerateRnd(19) + 1;
do {
if (hallok[rv]) {
for (i = 19; i >= 0; i--) {
for (int i = 19; i >= 0; i--) {
if (dung[i][rv] == 1) {
i = -1;
rv = 0;
@ -1037,8 +1012,8 @@ static void uShape()
}
} while (rv != 0);
for (i = 19; i >= 0; i--) {
for (j = 19; j >= 0; j--) {
for (int i = 19; i >= 0; i--) {
for (int j = 19; j >= 0; j--) {
if (dung[i][j] != 1) {
hallok[i] = false;
}
@ -1058,7 +1033,7 @@ static void uShape()
rv = GenerateRnd(19) + 1;
do {
if (hallok[rv]) {
for (j = 19; j >= 0; j--) {
for (int j = 19; j >= 0; j--) {
if (dung[rv][j] == 1) {
j = -1;
rv = 0;
@ -1076,15 +1051,12 @@ static void uShape()
} while (rv != 0);
}
static long GetArea()
static int GetArea()
{
int i, j;
long rv;
rv = 0;
int rv = 0;
for (j = 0; j < 20; j++) {
for (i = 0; i < 20; i++) {
for (int j = 0; j < 20; j++) {
for (int i = 0; i < 20; i++) { // NOLINT(modernize-loop-convert)
if (dung[i][j] == 1) {
rv++;
}
@ -1096,10 +1068,8 @@ static long GetArea()
static void L4drawRoom(int x, int y, int width, int height)
{
int i, j;
for (j = 0; j < height && j + y < 20; j++) {
for (i = 0; i < width && i + x < 20; i++) {
for (int j = 0; j < height && j + y < 20; j++) {
for (int i = 0; i < width && i + x < 20; i++) {
dung[i + x][j + y] = 1;
}
}
@ -1107,14 +1077,12 @@ static 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++) {
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
if (i + x < 0 || i + x >= 20 || j + y < 0 || j + y >= 20) {
return false;
}
@ -1129,14 +1097,15 @@ static bool L4checkRoom(int x, int y, int width, int height)
static void L4roomGen(int x, int y, int w, int h, int dir)
{
bool ran, ran2;
int width, height, rx, ry, ry2;
int cw, ch, cx1, cy1, cx2;
bool ran;
int dirProb = GenerateRnd(4);
int num = 0;
if ((dir == 1 && dirProb == 0) || (dir != 1 && dirProb != 0)) {
int cw;
int ch;
int cx1;
int cy1;
do {
cw = (GenerateRnd(5) + 2) & ~1;
ch = (GenerateRnd(5) + 2) & ~1;
@ -1148,8 +1117,8 @@ static void L4roomGen(int x, int y, int w, int h, int dir)
if (ran)
L4drawRoom(cx1, cy1, cw, ch);
cx2 = x + w;
ran2 = L4checkRoom(cx2, cy1 - 1, cw + 1, ch + 2);
int cx2 = x + w;
bool ran2 = L4checkRoom(cx2, cy1 - 1, cw + 1, ch + 2);
if (ran2)
L4drawRoom(cx2, cy1, cw, ch);
if (ran)
@ -1159,6 +1128,10 @@ static void L4roomGen(int x, int y, int w, int h, int dir)
return;
}
int width;
int height;
int rx;
int ry;
do {
width = (GenerateRnd(5) + 2) & ~1;
height = (GenerateRnd(5) + 2) & ~1;
@ -1170,8 +1143,8 @@ static void L4roomGen(int x, int y, int w, int h, int dir)
if (ran)
L4drawRoom(rx, ry, width, height);
ry2 = y + h;
ran2 = L4checkRoom(rx - 1, ry2, width + 2, height + 1);
int ry2 = y + h;
bool ran2 = L4checkRoom(rx - 1, ry2, width + 2, height + 1);
if (ran2)
L4drawRoom(rx, ry2, width, height);
if (ran)
@ -1182,8 +1155,8 @@ static void L4roomGen(int x, int y, int w, int h, int dir)
static void L4firstRoom()
{
int x, y, w, h, rndx, rndy, xmin, xmax, ymin, ymax, tx, ty;
int w = 14;
int h = 14;
if (currlevel != 16) {
if (currlevel == quests[Q_WARLORD]._qlevel && quests[Q_WARLORD]._qactive != QUEST_NOTAVAIL) {
assert(!gbIsMultiplayer);
@ -1196,29 +1169,15 @@ static void L4firstRoom()
w = GenerateRnd(5) + 2;
h = GenerateRnd(5) + 2;
}
} else {
w = 14;
h = 14;
}
xmin = (20 - w) / 2;
xmax = 19 - w;
rndx = GenerateRnd(xmax - xmin + 1) + xmin;
if (rndx + w > 19) {
tx = w + rndx - 19;
x = rndx - tx + 1;
} else {
x = rndx;
}
ymin = (20 - h) / 2;
ymax = 19 - h;
rndy = GenerateRnd(ymax - ymin + 1) + ymin;
if (rndy + h > 19) {
ty = h + rndy - 19;
y = rndy - ty + 1;
} else {
y = rndy;
}
int xmin = (20 - w) / 2;
int xmax = 19 - w;
int x = GenerateRnd(xmax - xmin + 1) + xmin;
int ymin = (20 - h) / 2;
int ymax = 19 - h;
int y = GenerateRnd(ymax - ymin + 1) + ymin;
if (currlevel == 16) {
l4holdx = x;
@ -1242,13 +1201,11 @@ static void L4firstRoom()
void L4SaveQuads()
{
int i, j, x, y;
x = l4holdx;
y = l4holdy;
int x = l4holdx;
int y = l4holdy;
for (j = 0; j < 14; j++) {
for (i = 0; i < 14; i++) {
for (int j = 0; j < 14; j++) {
for (int i = 0; i < 14; i++) {
dflags[i + x][j + y] = 1;
dflags[DMAXX - 1 - i - x][j + y] = 1;
dflags[i + x][DMAXY - 1 - j - y] = 1;
@ -1287,22 +1244,22 @@ void DRLG_LoadDiabQuads(bool preflag)
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;
int sx;
int sy;
sw = miniset[0];
sh = miniset[1];
int sw = miniset[0];
int sh = miniset[1];
if (tmax - tmin == 0) {
numt = 1;
} else {
int numt = 1;
if (tmax - tmin != 0) {
numt = GenerateRnd(tmax - tmin) + tmin;
}
for (i = 0; i < numt; i++) {
for (int i = 0; i < numt; i++) {
sx = GenerateRnd(DMAXX - sw);
sy = GenerateRnd(DMAXY - sh);
found = false;
bool found = false;
int bailcnt;
for (bailcnt = 0; !found && bailcnt < 200; bailcnt++) {
found = true;
if (sx >= SP4x1 && sx <= SP4x2 && sy >= SP4y1 && sy <= SP4y2) {
@ -1318,9 +1275,9 @@ static bool DRLG_L4PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx,
sy = GenerateRnd(DMAXY - sh);
found = false;
}
ii = 2;
for (yy = 0; yy < sh && found; yy++) {
for (xx = 0; xx < sw && found; xx++) {
int ii = 2;
for (int yy = 0; yy < sh && found; yy++) {
for (int xx = 0; xx < sw && found; xx++) {
if (miniset[ii] != 0 && dungeon[xx + sx][yy + sy] != miniset[ii]) {
found = false;
}
@ -1344,9 +1301,9 @@ static bool DRLG_L4PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx,
if (bailcnt >= 200) {
return false;
}
ii = sw * sh + 2;
for (yy = 0; yy < sh; yy++) {
for (xx = 0; xx < sw; xx++) {
int ii = sw * sh + 2;
for (int yy = 0; yy < sh; yy++) {
for (int xx = 0; xx < sw; xx++) {
if (miniset[ii] != 0) {
dungeon[xx + sx][yy + sy] = miniset[ii];
dflags[xx + sx][yy + sy] |= 8;
@ -1425,12 +1382,10 @@ static void DRLG_L4FTVR(int i, int j, int x, int y, int d)
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++) {
int yy = 16;
for (int j = 0; j < DMAXY; j++) {
int xx = 16;
for (int i = 0; i < DMAXX; i++) {
if (dungeon[i][j] == 6 && dTransVal[xx][yy] == 0) {
DRLG_L4FTVR(i, j, xx, yy, 0);
TransVal++;
@ -1477,12 +1432,10 @@ bool IsDLLWall(char dd)
static void DRLG_L4TransFix()
{
int i, j, xx, yy;
yy = 16;
for (j = 0; j < DMAXY; j++) {
xx = 16;
for (i = 0; i < DMAXX; i++) {
int yy = 16;
for (int j = 0; j < DMAXY; j++) {
int xx = 16;
for (int i = 0; i < DMAXX; i++) {
if (IsDURWall(dungeon[i][j]) && dungeon[i][j - 1] == 18) {
dTransVal[xx + 1][yy] = dTransVal[xx][yy];
dTransVal[xx + 1][yy + 1] = dTransVal[xx][yy];
@ -1520,10 +1473,8 @@ static void DRLG_L4TransFix()
static void DRLG_L4Corners()
{
int i, j;
for (j = 1; j < DMAXY - 1; j++) {
for (i = 1; i < DMAXX - 1; i++) {
for (int j = 1; j < DMAXY - 1; j++) {
for (int i = 1; i < DMAXX - 1; i++) {
if (dungeon[i][j] >= 18 && dungeon[i][j] <= 30) {
if (dungeon[i + 1][j] < 18) {
dungeon[i][j] += 98;
@ -1537,22 +1488,18 @@ static void DRLG_L4Corners()
void L4FixRim()
{
int i, j;
for (i = 0; i < 20; i++) {
for (int i = 0; i < 20; i++) { // NOLINT(modernize-loop-convert)
dung[i][0] = 0;
}
for (j = 0; j < 20; j++) {
for (int 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++) {
for (int j = 0; j < DMAXY - 1; j++) {
for (int 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;
}
@ -1562,7 +1509,7 @@ void DRLG_L4GeneralFix()
static void DRLG_L4(lvl_entry entry)
{
int i, j, spi, spj, ar;
int ar;
bool doneflag;
do {
@ -1583,8 +1530,8 @@ static void DRLG_L4(lvl_entry entry)
L4SaveQuads();
}
if (QuestStatus(Q_WARLORD) || (currlevel == quests[Q_BETRAYER]._qlevel && gbIsMultiplayer)) {
for (spi = SP4x1; spi < SP4x2; spi++) {
for (spj = SP4y1; spj < SP4y2; spj++) {
for (int spi = SP4x1; spi < SP4x2; spi++) {
for (int spj = SP4y1; spj < SP4y2; spj++) {
dflags[spi][spj] = 1;
}
}
@ -1685,8 +1632,8 @@ static void DRLG_L4(lvl_entry entry)
DRLG_Init_Globals();
if (QuestStatus(Q_WARLORD)) {
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
pdungeon[i][j] = dungeon[i][j];
}
}
@ -1695,8 +1642,8 @@ static void DRLG_L4(lvl_entry entry)
DRLG_CheckQuests(SP4x1, SP4y1);
if (currlevel == 15) {
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
if (dungeon[i][j] == 98) {
Make_SetPC(i - 1, j - 1, 5, 5);
}
@ -1707,8 +1654,8 @@ static void DRLG_L4(lvl_entry entry)
}
}
if (currlevel == 16) {
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
pdungeon[i][j] = dungeon[i][j];
}
}

Loading…
Cancel
Save