From 9264ad4b894b618cb0448ac53bd2d724b2078fca Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 16 Jul 2021 21:49:03 +0200 Subject: [PATCH] Use IsTileNotSolid() in place of !nSolidTable[dPiece[][]] --- Source/controls/plrctrls.cpp | 4 ++-- Source/items.cpp | 2 +- Source/missiles.cpp | 2 +- Source/objects.cpp | 4 ++-- Source/path.cpp | 8 ++++---- Source/player.cpp | 2 +- Source/scrollrt.cpp | 2 +- Source/themes.cpp | 39 ++++++++++++++++++------------------ 8 files changed, 32 insertions(+), 31 deletions(-) diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index 1fe569c3f..c7d16a76e 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -91,7 +91,7 @@ int GetDistance(Point destination, int maxDistance) } int8_t walkpath[MAX_PATH_LENGTH]; - int steps = FindPath([](Point position){ return PosOkPlayer(MyPlayerId, position); }, Players[MyPlayerId].position.future.x, Players[MyPlayerId].position.future.y, destination.x, destination.y, walkpath); + int steps = FindPath([](Point position) { return PosOkPlayer(MyPlayerId, position); }, Players[MyPlayerId].position.future.x, Players[MyPlayerId].position.future.y, destination.x, destination.y, walkpath); if (steps > maxDistance) return 0; @@ -1051,7 +1051,7 @@ bool IsPathBlocked(Point position, Direction dir) auto leftStep { position + d1 }; auto rightStep { position + d2 }; - if (!nSolidTable[dPiece[leftStep.x][leftStep.y]] && !nSolidTable[dPiece[rightStep.x][rightStep.y]]) + if (IsTileNotSolid(leftStep) && IsTileNotSolid(rightStep)) return false; return !PosOkPlayer(MyPlayerId, leftStep) && !PosOkPlayer(MyPlayerId, rightStep); diff --git a/Source/items.cpp b/Source/items.cpp index 5e7f99935..3a72ce16c 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -3247,7 +3247,7 @@ bool ItemSpaceOk(Point position) return false; } - return !nSolidTable[dPiece[position.x][position.y]]; + return IsTileNotSolid(position); } int AllocateItem() diff --git a/Source/missiles.cpp b/Source/missiles.cpp index c161bd649..31daca3f3 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -2125,7 +2125,7 @@ void AddTeleport(int mi, Point /*src*/, Point dst, int /*midir*/, int8_t /*miene int tx = dst.x + CrawlTable[ck - 1]; int ty = dst.y + CrawlTable[ck]; if (0 < tx && tx < MAXDUNX && 0 < ty && ty < MAXDUNY) { - if (!nSolidTable[dPiece[tx][ty]] && dMonster[tx][ty] == 0 && dObject[tx][ty] == 0 && dPlayer[tx][ty] == 0) { + if (IsTileNotSolid({ tx, ty }) && dMonster[tx][ty] == 0 && dObject[tx][ty] == 0 && dPlayer[tx][ty] == 0) { Missiles[mi].position.tile = { tx, ty }; Missiles[mi].position.start = { tx, ty }; Missiles[mi]._miDelFlag = false; diff --git a/Source/objects.cpp b/Source/objects.cpp index 32add173c..21d021ef7 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -670,7 +670,7 @@ void AddObjTraps() if (GenerateRnd(2) == 0) { int xp = i - 1; - while (!nSolidTable[dPiece[xp][j]]) // BUGFIX: check if xp >= 0 + while (IsTileNotSolid({ xp, j })) // BUGFIX: check if xp >= 0 xp--; if (!WallTrapLocOkK(xp, j) || i - xp <= 1) @@ -683,7 +683,7 @@ void AddObjTraps() Objects[oi]._oTrapFlag = true; } else { int yp = j - 1; - while (!nSolidTable[dPiece[i][yp]]) // BUGFIX: check if yp >= 0 + while (IsTileNotSolid({ i, yp })) // BUGFIX: check if yp >= 0 yp--; if (!WallTrapLocOkK(i, yp) || j - yp <= 1) diff --git a/Source/path.cpp b/Source/path.cpp index 541cab03a..08ab2b0ac 100644 --- a/Source/path.cpp +++ b/Source/path.cpp @@ -198,16 +198,16 @@ bool path_solid_pieces(PATHNODE *pPath, int dx, int dy) bool rv = true; switch (path_directions[3 * (dy - pPath->position.y) + 3 - pPath->position.x + 1 + dx]) { case 5: - rv = !nSolidTable[dPiece[dx][dy + 1]] && !nSolidTable[dPiece[dx + 1][dy]]; + rv = IsTileNotSolid({ dx, dy + 1 }) && IsTileNotSolid({ dx + 1, dy }); break; case 6: - rv = !nSolidTable[dPiece[dx][dy + 1]] && !nSolidTable[dPiece[dx - 1][dy]]; + rv = IsTileNotSolid({ dx, dy + 1 }) && IsTileNotSolid({ dx - 1, dy }); break; case 7: - rv = !nSolidTable[dPiece[dx][dy - 1]] && !nSolidTable[dPiece[dx - 1][dy]]; + rv = IsTileNotSolid({ dx, dy - 1 }) && IsTileNotSolid({ dx - 1, dy }); break; case 8: - rv = !nSolidTable[dPiece[dx + 1][dy]] && !nSolidTable[dPiece[dx][dy - 1]]; + rv = IsTileNotSolid({ dx + 1, dy }) && IsTileNotSolid({ dx, dy - 1 }); break; } return rv; diff --git a/Source/player.cpp b/Source/player.cpp index 9f3f27692..4c3043232 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -1310,7 +1310,7 @@ void PlrDoTrans(Point position) for (int i = position.y - 1; i <= position.y + 1; i++) { for (int j = position.x - 1; j <= position.x + 1; j++) { - if (!nSolidTable[dPiece[j][i]] && dTransVal[j][i] != 0) { + if (IsTileNotSolid({ j, i }) && dTransVal[j][i] != 0) { TransList[dTransVal[j][i]] = true; } } diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index c09bcb885..98f5463df 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -988,7 +988,7 @@ static void DrawFloor(const Surface &out, int x, int y, int sx, int sy, int rows } #define IsWall(x, y) (dPiece[x][y] == 0 || nSolidTable[dPiece[x][y]] || dSpecial[x][y] != 0) -#define IsWalkable(x, y) (dPiece[x][y] != 0 && !nSolidTable[dPiece[x][y]]) +#define IsWalkable(x, y) (dPiece[x][y] != 0 && IsTileNotSolid({ x, y })) /** * @brief Render a row of tile diff --git a/Source/themes.cpp b/Source/themes.cpp index 117f52aef..b7aea4d59 100644 --- a/Source/themes.cpp +++ b/Source/themes.cpp @@ -9,6 +9,7 @@ #include "items.h" #include "monster.h" #include "objects.h" +#include "path.h" #include "quests.h" #include "trigs.h" @@ -69,8 +70,8 @@ bool TFit_Shrine(int i) while (found == 0) { if (dTransVal[xp][yp] == themes[i].ttval) { if (nTrapTable[dPiece[xp][yp - 1]] - && !nSolidTable[dPiece[xp - 1][yp]] - && !nSolidTable[dPiece[xp + 1][yp]] + && IsTileNotSolid({ xp - 1, yp }) + && IsTileNotSolid({ xp + 1, yp }) && dTransVal[xp - 1][yp] == themes[i].ttval && dTransVal[xp + 1][yp] == themes[i].ttval && dObject[xp - 1][yp - 1] == 0 @@ -79,8 +80,8 @@ bool TFit_Shrine(int i) } if (found == 0 && nTrapTable[dPiece[xp - 1][yp]] - && !nSolidTable[dPiece[xp][yp - 1]] - && !nSolidTable[dPiece[xp][yp + 1]] + && IsTileNotSolid({ xp, yp - 1 }) + && IsTileNotSolid({ xp, yp + 1 }) && dTransVal[xp][yp - 1] == themes[i].ttval && dTransVal[xp][yp + 1] == themes[i].ttval && dObject[xp - 1][yp - 1] == 0 @@ -113,7 +114,7 @@ bool TFit_Obj5(int t) while (r > 0) { bool found = false; - if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) { + if (dTransVal[xp][yp] == themes[t].ttval && IsTileNotSolid({ xp, yp })) { found = true; for (int i = 0; found && i < 25; i++) { if (nSolidTable[dPiece[xp + trm5x[i]][yp + trm5y[i]]]) { @@ -374,13 +375,13 @@ bool CheckThemeRoom(int tv) for (int i = 0; i < MAXDUNX; i++) { if (dTransVal[i][j] != tv || nSolidTable[dPiece[i][j]]) continue; - if (dTransVal[i - 1][j] != tv && !nSolidTable[dPiece[i - 1][j]]) + if (dTransVal[i - 1][j] != tv && IsTileNotSolid({ i - 1, j })) return false; - if (dTransVal[i + 1][j] != tv && !nSolidTable[dPiece[i + 1][j]]) + if (dTransVal[i + 1][j] != tv && IsTileNotSolid({ i + 1, j })) return false; - if (dTransVal[i][j - 1] != tv && !nSolidTable[dPiece[i][j - 1]]) + if (dTransVal[i][j - 1] != tv && IsTileNotSolid({ i, j - 1 })) return false; - if (dTransVal[i][j + 1] != tv && !nSolidTable[dPiece[i][j + 1]]) + if (dTransVal[i][j + 1] != tv && IsTileNotSolid({ i, j + 1 })) return false; } } @@ -489,7 +490,7 @@ void PlaceThemeMonsts(int t, int f) int mtype = scattertypes[GenerateRnd(numscattypes)]; for (int yp = 0; yp < MAXDUNY; yp++) { for (int xp = 0; xp < MAXDUNX; xp++) { - if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]] && dItem[xp][yp] == 0 && dObject[xp][yp] == 0) { + if (dTransVal[xp][yp] == themes[t].ttval && IsTileNotSolid({ xp, yp }) && dItem[xp][yp] == 0 && dObject[xp][yp] == 0) { if (GenerateRnd(f) == 0) { AddMonster({ xp, yp }, static_cast(GenerateRnd(8)), mtype, true); } @@ -510,7 +511,7 @@ void Theme_Barrel(int t) for (int yp = 0; yp < MAXDUNY; yp++) { for (int xp = 0; xp < MAXDUNX; xp++) { - if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) { + if (dTransVal[xp][yp] == themes[t].ttval && IsTileNotSolid({ xp, yp })) { if (GenerateRnd(barrnd[leveltype - 1]) == 0) { _object_id r = OBJ_BARREL; if (GenerateRnd(barrnd[leveltype - 1]) != 0) { @@ -559,7 +560,7 @@ void Theme_MonstPit(int t) int ixp = 0; int iyp = 0; while (r > 0) { - if (dTransVal[ixp][iyp] == themes[t].ttval && !nSolidTable[dPiece[ixp][iyp]]) { + if (dTransVal[ixp][iyp] == themes[t].ttval && IsTileNotSolid({ ixp, iyp })) { --r; } if (r <= 0) @@ -664,7 +665,7 @@ void Theme_Treasure(int t) AdvanceRndSeed(); for (int yp = 0; yp < MAXDUNY; yp++) { for (int xp = 0; xp < MAXDUNX; xp++) { - if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) { + if (dTransVal[xp][yp] == themes[t].ttval && IsTileNotSolid({ xp, yp })) { int rv = GenerateRnd(treasrnd[leveltype - 1]); // BUGFIX: the `2*` in `2*GenerateRnd(treasrnd...) == 0` has no effect, should probably be `GenerateRnd(2*treasrnd...) == 0` if ((2 * GenerateRnd(treasrnd[leveltype - 1])) == 0) { @@ -744,7 +745,7 @@ void Theme_Torture(int t) for (int yp = 1; yp < MAXDUNY - 1; yp++) { for (int xp = 1; xp < MAXDUNX - 1; xp++) { - if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) { + if (dTransVal[xp][yp] == themes[t].ttval && IsTileNotSolid({ xp, yp })) { if (CheckThemeObj3(xp, yp, t, -1)) { if (GenerateRnd(tortrnd[leveltype - 1]) == 0) { AddObject(OBJ_TNUDEM2, { xp, yp }); @@ -781,7 +782,7 @@ void Theme_Decap(int t) for (int yp = 1; yp < MAXDUNY - 1; yp++) { for (int xp = 1; xp < MAXDUNX - 1; xp++) { - if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) { + if (dTransVal[xp][yp] == themes[t].ttval && IsTileNotSolid({ xp, yp })) { if (CheckThemeObj3(xp, yp, t, -1)) { if (GenerateRnd(decaprnd[leveltype - 1]) == 0) { AddObject(OBJ_DECAP, { xp, yp }); @@ -823,7 +824,7 @@ void Theme_ArmorStand(int t) } for (int yp = 0; yp < MAXDUNY; yp++) { for (int xp = 0; xp < MAXDUNX; xp++) { - if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) { + if (dTransVal[xp][yp] == themes[t].ttval && IsTileNotSolid({ xp, yp })) { if (CheckThemeObj3(xp, yp, t, -1)) { if (GenerateRnd(armorrnd[leveltype - 1]) == 0) { AddObject(OBJ_ARMORSTANDN, { xp, yp }); @@ -847,7 +848,7 @@ void Theme_GoatShrine(int t) AddObject(OBJ_GOATSHRINE, { themex, themey }); for (int yy = themey - 1; yy <= themey + 1; yy++) { for (int xx = themex - 1; xx <= themex + 1; xx++) { - if (dTransVal[xx][yy] == themes[t].ttval && !nSolidTable[dPiece[xx][yy]] && (xx != themex || yy != themey)) { + if (dTransVal[xx][yy] == themes[t].ttval && IsTileNotSolid({ xx, yy }) && (xx != themex || yy != themey)) { AddMonster({ xx, yy }, DIR_SW, themeVar1, true); } } @@ -908,7 +909,7 @@ void Theme_BrnCross(int t) for (int yp = 0; yp < MAXDUNY; yp++) { for (int xp = 0; xp < MAXDUNX; xp++) { - if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) { + if (dTransVal[xp][yp] == themes[t].ttval && IsTileNotSolid({ xp, yp })) { if (CheckThemeObj3(xp, yp, t, -1)) { if (GenerateRnd(bcrossrnd[leveltype - 1]) == 0) { AddObject(OBJ_TBCROSS, { xp, yp }); @@ -936,7 +937,7 @@ void Theme_WeaponRack(int t) } for (int yp = 0; yp < MAXDUNY; yp++) { for (int xp = 0; xp < MAXDUNX; xp++) { - if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) { + if (dTransVal[xp][yp] == themes[t].ttval && IsTileNotSolid({ xp, yp })) { if (CheckThemeObj3(xp, yp, t, -1)) { if (GenerateRnd(weaponrnd[leveltype - 1]) == 0) { AddObject(OBJ_WEAPONRACKN, { xp, yp });