diff --git a/Source/drlg_l1.cpp b/Source/drlg_l1.cpp index b1484447b..5e5c6f9ec 100644 --- a/Source/drlg_l1.cpp +++ b/Source/drlg_l1.cpp @@ -24,7 +24,7 @@ namespace { /** Represents a tile ID map of twice the size, repeating each tile of the original map in blocks of 4. */ BYTE L5dungeon[80][80]; -BYTE L5dflags[DMAXX][DMAXY]; +uint8_t L5dflags[DMAXX][DMAXY]; /** Specifies whether a single player quest DUN has been loaded. */ bool L5setloadflag; /** Specifies whether to generate a horizontal room at position 1 in the Cathedral. */ @@ -502,6 +502,37 @@ BYTE CornerstoneRoomPattern[27] = { */ BYTE L5ConvTbl[16] = { 22, 13, 1, 13, 2, 13, 13, 13, 4, 13, 1, 13, 2, 13, 16, 13 }; +enum CathedralTile : uint8_t { + // clang-format off + VWall = 1, + HWall = 2, + Corner = 3, + DWall = 4, + DArch = 5, + VWallEnd = 6, + HWallEnd = 7, + HArchEnd = 8, + VArchEnd = 9, + HArchVWall = 10, + VArch = 11, + HArch = 12, + Floor = 13, + HWallVArch = 14, + Pilar = 15, + DirtCorner = 21, + VDoor = 25, + HDoor = 26, + HFenceVWall = 27, + HDoorVDoor = 28, + VDoorEnd = 30, + HDoorEnd = 31, + VFence = 35, + HFence = 36, + HWallVFence = 37, + EntranceStairs = 64, + // clang-format on +}; + void InitCryptPieces() { for (int j = 0; j < MAXDUNY; j++) { @@ -515,65 +546,6 @@ void InitCryptPieces() } } -void PlaceDoor(int x, int y) -{ - if ((L5dflags[x][y] & DLRG_PROTECTED) == 0) { - BYTE df = L5dflags[x][y] & 0x7F; - BYTE c = dungeon[x][y]; - - if (df == 1) { - if (y != 1 && c == 2) - dungeon[x][y] = 26; - if (y != 1 && c == 7) - dungeon[x][y] = 31; - if (y != 1 && c == 14) - dungeon[x][y] = 42; - if (y != 1 && c == 4) - dungeon[x][y] = 43; - if (x != 1 && c == 1) - dungeon[x][y] = 25; - if (x != 1 && c == 10) - dungeon[x][y] = 40; - if (x != 1 && c == 6) - dungeon[x][y] = 30; - } - if (df == 2) { - if (x != 1 && c == 1) - dungeon[x][y] = 25; - if (x != 1 && c == 6) - dungeon[x][y] = 30; - if (x != 1 && c == 10) - dungeon[x][y] = 40; - if (x != 1 && c == 4) - dungeon[x][y] = 41; - if (y != 1 && c == 2) - dungeon[x][y] = 26; - if (y != 1 && c == 14) - dungeon[x][y] = 42; - if (y != 1 && c == 7) - dungeon[x][y] = 31; - } - if (df == 3) { - if (x != 1 && y != 1 && c == 4) - dungeon[x][y] = 28; - if (x != 1 && c == 10) - dungeon[x][y] = 40; - if (y != 1 && c == 14) - dungeon[x][y] = 42; - if (y != 1 && c == 2) - dungeon[x][y] = 26; - if (x != 1 && c == 1) - dungeon[x][y] = 25; - if (y != 1 && c == 7) - dungeon[x][y] = 31; - if (x != 1 && c == 6) - dungeon[x][y] = 30; - } - } - - L5dflags[x][y] = DLRG_PROTECTED; -} - void CryptLavafloor() { for (int j = 1; j < 40; j++) { @@ -921,7 +893,7 @@ void FillFloor() { for (int j = 0; j < DMAXY; j++) { for (int i = 0; i < DMAXX; i++) { - if (L5dflags[i][j] == 0 && dungeon[i][j] == 13) { + if (L5dflags[i][j] == 0 && dungeon[i][j] == CathedralTile::Floor) { int rv = GenerateRnd(3); if (rv == 1) @@ -1002,7 +974,7 @@ void MapRoom(int x, int y, int width, int height) { for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - dungeon[x + i][y + j] = 1; + dungeon[x + i][y + j] = CathedralTile::VWall; } } } @@ -1106,12 +1078,12 @@ void FirstRoom() ye = 22; for (int 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; + dungeon[17][y] = CathedralTile::VWall; + dungeon[18][y] = CathedralTile::VWall; + dungeon[19][y] = CathedralTile::VWall; + dungeon[20][y] = CathedralTile::VWall; + dungeon[21][y] = CathedralTile::VWall; + dungeon[22][y] = CathedralTile::VWall; } if (VR1) @@ -1147,12 +1119,12 @@ void FirstRoom() xe = 22; for (int 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; + dungeon[x][17] = CathedralTile::VWall; + dungeon[x][18] = CathedralTile::VWall; + dungeon[x][19] = CathedralTile::VWall; + dungeon[x][20] = CathedralTile::VWall; + dungeon[x][21] = CathedralTile::VWall; + dungeon[x][22] = CathedralTile::VWall; } if (HR1) @@ -1174,7 +1146,7 @@ int FindArea() for (int j = 0; j < DMAXY; j++) { for (int i = 0; i < DMAXX; i++) { // NOLINT(modernize-loop-convert) - if (dungeon[i][j] == 1) + if (dungeon[i][j] == CathedralTile::VWall) rv++; } } @@ -1265,37 +1237,33 @@ int VerticalWallOk(int i, int j) return -1; } -void HorizontalWall(int i, int j, char p, int dx) +void HorizontalWall(int i, int j, CathedralTile p, int dx) { - int8_t dt; + CathedralTile dt = CathedralTile::HWall; + CathedralTile wt = CathedralTile::HDoor; switch (GenerateRnd(4)) { - case 0: - case 1: - dt = 2; + case 2: // Add arch + dt = CathedralTile::HArch; + wt = CathedralTile::HArch; + if (p == CathedralTile::HWall) + p = CathedralTile::HArch; + else if (p == CathedralTile::DWall) + p = CathedralTile::HArchVWall; break; - case 2: - dt = 12; - if (p == 2) - p = 12; - if (p == 4) - p = 10; + case 3: // Add Fence + dt = CathedralTile::HFence; + if (p == CathedralTile::HWall) + p = CathedralTile::HFence; + else if (p == CathedralTile::DWall) + p = CathedralTile::HFenceVWall; break; - case 3: - dt = 36; - if (p == 2) - p = 36; - if (p == 4) - p = 27; + default: break; } - int8_t wt = 26; if (GenerateRnd(6) == 5) - wt = 12; - - if (dt == 12) - wt = 12; + wt = CathedralTile::HArch; dungeon[i][j] = p; @@ -1305,45 +1273,39 @@ void HorizontalWall(int i, int j, char p, int dx) int xx = GenerateRnd(dx - 1) + 1; - if (wt == 12) { - dungeon[i + xx][j] = wt; - } else { - dungeon[i + xx][j] = 2; - L5dflags[i + xx][j] |= DLRG_HDOOR; + dungeon[i + xx][j] = wt; + if (wt == CathedralTile::HDoor) { + L5dflags[i + xx][j] |= DLRG_PROTECTED; } } -void VerticalWall(int i, int j, char p, int dy) +void VerticalWall(int i, int j, CathedralTile p, int dy) { - int8_t dt; + CathedralTile dt = CathedralTile::VWall; + CathedralTile wt = CathedralTile::VDoor; switch (GenerateRnd(4)) { - case 0: - case 1: - dt = 1; + case 2: // Add arch + dt = CathedralTile::VArch; + wt = CathedralTile::VArch; + if (p == CathedralTile::VWall) + p = CathedralTile::VArch; + else if (p == CathedralTile::DWall) + p = CathedralTile::HWallVArch; break; - case 2: - dt = 11; - if (p == 1) - p = 11; - if (p == 4) - p = 14; + case 3: // Add Fence + dt = CathedralTile::VFence; + if (p == CathedralTile::VWall) + p = CathedralTile::VFence; + else if (p == CathedralTile::DWall) + p = CathedralTile::HWallVFence; break; - case 3: - dt = 35; - if (p == 1) - p = 35; - if (p == 4) - p = 37; + default: break; } - int8_t wt = 25; if (GenerateRnd(6) == 5) - wt = 11; - - if (dt == 11) - wt = 11; + wt = CathedralTile::VArch; dungeon[i][j] = p; @@ -1353,11 +1315,9 @@ void VerticalWall(int i, int j, char p, int dy) int yy = GenerateRnd(dy - 1) + 1; - if (wt == 11) { - dungeon[i][j + yy] = wt; - } else { - dungeon[i][j + yy] = 1; - L5dflags[i][j + yy] |= DLRG_VDOOR; + dungeon[i][j + yy] = wt; + if (wt == CathedralTile::VDoor) { + L5dflags[i][j + yy] |= DLRG_PROTECTED; } } @@ -1366,46 +1326,46 @@ void AddWall() for (int j = 0; j < DMAXY; j++) { for (int i = 0; i < DMAXX; i++) { if (L5dflags[i][j] == 0) { - if (dungeon[i][j] == 3) { + if (dungeon[i][j] == CathedralTile::Corner) { AdvanceRndSeed(); int x = HorizontalWallOk(i, j); if (x != -1) { - HorizontalWall(i, j, 2, x); + HorizontalWall(i, j, CathedralTile::HWall, x); } } - if (dungeon[i][j] == 3) { + if (dungeon[i][j] == CathedralTile::Corner) { AdvanceRndSeed(); int y = VerticalWallOk(i, j); if (y != -1) { - VerticalWall(i, j, 1, y); + VerticalWall(i, j, CathedralTile::VWall, y); } } - if (dungeon[i][j] == 6) { + if (dungeon[i][j] == CathedralTile::VWallEnd) { AdvanceRndSeed(); int x = HorizontalWallOk(i, j); if (x != -1) { - HorizontalWall(i, j, 4, x); + HorizontalWall(i, j, CathedralTile::DWall, x); } } - if (dungeon[i][j] == 7) { + if (dungeon[i][j] == CathedralTile::HWallEnd) { AdvanceRndSeed(); int y = VerticalWallOk(i, j); if (y != -1) { - VerticalWall(i, j, 4, y); + VerticalWall(i, j, CathedralTile::DWall, y); } } - if (dungeon[i][j] == 2) { + if (dungeon[i][j] == CathedralTile::HWall) { AdvanceRndSeed(); int x = HorizontalWallOk(i, j); if (x != -1) { - HorizontalWall(i, j, 2, x); + HorizontalWall(i, j, CathedralTile::HWall, x); } } - if (dungeon[i][j] == 1) { + if (dungeon[i][j] == CathedralTile::VWall) { AdvanceRndSeed(); int y = VerticalWallOk(i, j); if (y != -1) { - VerticalWall(i, j, 1, y); + VerticalWall(i, j, CathedralTile::VWall, y); } } } @@ -1416,72 +1376,72 @@ void AddWall() void GenerateChamber(int sx, int sy, bool topflag, bool bottomflag, bool leftflag, bool rightflag) { if (topflag) { - 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; + dungeon[sx + 2][sy] = CathedralTile::HArch; + dungeon[sx + 3][sy] = CathedralTile::HArch; + dungeon[sx + 4][sy] = CathedralTile::Corner; + dungeon[sx + 7][sy] = CathedralTile::VArchEnd; + dungeon[sx + 8][sy] = CathedralTile::HArch; + dungeon[sx + 9][sy] = CathedralTile::HWall; } if (bottomflag) { 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; + dungeon[sx + 2][sy] = CathedralTile::HArchVWall; + dungeon[sx + 3][sy] = CathedralTile::HArch; + dungeon[sx + 4][sy] = CathedralTile::HArchEnd; + dungeon[sx + 7][sy] = CathedralTile::DArch; + dungeon[sx + 8][sy] = CathedralTile::HArch; + if (dungeon[sx + 9][sy] != CathedralTile::DWall) { + dungeon[sx + 9][sy] = CathedralTile::DirtCorner; } sy -= 11; } if (leftflag) { - 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; + dungeon[sx][sy + 2] = CathedralTile::VArch; + dungeon[sx][sy + 3] = CathedralTile::VArch; + dungeon[sx][sy + 4] = CathedralTile::Corner; + dungeon[sx][sy + 7] = CathedralTile::HArchEnd; + dungeon[sx][sy + 8] = CathedralTile::VArch; + dungeon[sx][sy + 9] = CathedralTile::VWall; } if (rightflag) { 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; + dungeon[sx][sy + 2] = CathedralTile::HWallVArch; + dungeon[sx][sy + 3] = CathedralTile::VArch; + dungeon[sx][sy + 4] = CathedralTile::VArchEnd; + dungeon[sx][sy + 7] = CathedralTile::DArch; + dungeon[sx][sy + 8] = CathedralTile::VArch; + if (dungeon[sx][sy + 9] != CathedralTile::DWall) { + dungeon[sx][sy + 9] = CathedralTile::DirtCorner; } sx -= 11; } for (int j = 1; j < 11; j++) { for (int i = 1; i < 11; i++) { - dungeon[i + sx][j + sy] = 13; + dungeon[i + sx][j + sy] = CathedralTile::Floor; 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; + dungeon[sx + 4][sy + 4] = CathedralTile::Pilar; + dungeon[sx + 7][sy + 4] = CathedralTile::Pilar; + dungeon[sx + 4][sy + 7] = CathedralTile::Pilar; + dungeon[sx + 7][sy + 7] = CathedralTile::Pilar; } void GenerateHall(int x1, int y1, int x2, int y2) { if (y1 == y2) { for (int i = x1; i < x2; i++) { - dungeon[i][y1] = 12; - dungeon[i][y1 + 3] = 12; + dungeon[i][y1] = CathedralTile::HArch; + dungeon[i][y1 + 3] = CathedralTile::HArch; } return; } for (int i = y1; i < y2; i++) { - dungeon[x1][i] = 11; - dungeon[x1 + 3][i] = 11; + dungeon[x1][i] = CathedralTile::VArch; + dungeon[x1 + 3][i] = CathedralTile::VArch; } } @@ -1624,12 +1584,13 @@ void SetCornerRoom(int rx1, int ry1) dungeon[rx1 + i][ry1 + j] = CornerstoneRoomPattern[sp]; L5dflags[rx1 + i][ry1 + j] |= DLRG_PROTECTED; } else { - dungeon[rx1 + i][ry1 + j] = 13; + dungeon[rx1 + i][ry1 + j] = CathedralTile::Floor; } sp++; } } } + void Substitution() { for (int y = 0; y < DMAXY; y++) { @@ -1689,7 +1650,7 @@ void SetRoom(int rx1, int ry1) dungeon[rx1 + i][ry1 + j] = tileId; L5dflags[rx1 + i][ry1 + j] |= DLRG_PROTECTED; } else { - dungeon[rx1 + i][ry1 + j] = 13; + dungeon[rx1 + i][ry1 + j] = CathedralTile::Floor; } } } @@ -1717,7 +1678,7 @@ void SetCryptRoom(int rx1, int ry1) dungeon[rx1 + i][ry1 + j] = UberRoomPattern[sp]; L5dflags[rx1 + i][ry1 + j] |= DLRG_PROTECTED; } else { - dungeon[rx1 + i][ry1 + j] = 13; + dungeon[rx1 + i][ry1 + j] = CathedralTile::Floor; } sp++; } @@ -2027,11 +1988,11 @@ void FixCornerTiles() { for (int j = 1; j < DMAXY - 1; j++) { for (int i = 1; i < DMAXX - 1; i++) { - if ((L5dflags[i][j] & DLRG_PROTECTED) == 0 && dungeon[i][j] == 17 && dungeon[i - 1][j] == 13 && dungeon[i][j - 1] == 1) { + if ((L5dflags[i][j] & DLRG_PROTECTED) == 0 && dungeon[i][j] == 17 && dungeon[i - 1][j] == CathedralTile::Floor && dungeon[i][j - 1] == CathedralTile::VWall) { dungeon[i][j] = 16; L5dflags[i][j - 1] &= DLRG_PROTECTED; } - if (dungeon[i][j] == 202 && dungeon[i + 1][j] == 13 && dungeon[i][j + 1] == 1) { + if (dungeon[i][j] == 202 && dungeon[i + 1][j] == CathedralTile::Floor && dungeon[i][j + 1] == CathedralTile::VWall) { dungeon[i][j] = 8; } } @@ -2259,7 +2220,7 @@ void GenerateLevel(lvl_entry entry) for (int j = 0; j < DMAXY; j++) { for (int i = 0; i < DMAXX; i++) { - if (dungeon[i][j] == 64) { + if (dungeon[i][j] == CathedralTile::EntranceStairs) { int xx = 2 * i + 16; /* todo: fix loop */ int yy = 2 * j + 16; DRLG_CopyTrans(xx, yy + 1, xx, yy); @@ -2276,13 +2237,6 @@ void GenerateLevel(lvl_entry entry) } FixCornerTiles(); - for (int j = 0; j < DMAXY; j++) { - for (int i = 0; i < DMAXX; i++) { - if ((L5dflags[i][j] & ~DLRG_PROTECTED) != 0) - PlaceDoor(i, j); - } - } - if (leveltype == DTYPE_CRYPT) { CryptPatternGroup1(10); PlaceMiniSetRandom(CryptPattern1, 95); @@ -2382,7 +2336,7 @@ void LoadL1Dungeon(const char *path, int vx, int vy) dungeon[i][j] = tileId; L5dflags[i][j] |= DLRG_PROTECTED; } else { - dungeon[i][j] = 13; + dungeon[i][j] = CathedralTile::Floor; } } } @@ -2428,7 +2382,7 @@ void LoadPreL1Dungeon(const char *path) dungeon[i][j] = tileId; L5dflags[i][j] |= DLRG_PROTECTED; } else { - dungeon[i][j] = 13; + dungeon[i][j] = CathedralTile::Floor; } } }