Browse Source

apply bounds check function

pull/2855/merge
qndel 5 years ago committed by Anders Jenbo
parent
commit
f8cda02456
  1. 18
      Source/lighting.cpp
  2. 14
      Source/monster.cpp
  3. 2
      Source/player.cpp
  4. 5
      Source/scrollrt.cpp
  5. 2
      Source/track.cpp

18
Source/lighting.cpp

@ -514,7 +514,7 @@ void DoUnLight(int nXPos, int nYPos, int nRadius)
for (int y = minY; y < maxY; y++) { for (int y = minY; y < maxY; y++) {
for (int x = minX; x < maxX; x++) { for (int x = minX; x < maxX; x++) {
if (x >= 0 && x < MAXDUNX && y >= 0 && y < MAXDUNY) if (InDungeonBounds({ x, y }))
dLight[x][y] = dPreLight[x][y]; dLight[x][y] = dPreLight[x][y];
} }
} }
@ -564,7 +564,7 @@ void DoLighting(Point position, int nRadius, int lnum)
maxY = MAXDUNY - position.y; maxY = MAXDUNY - position.y;
} }
if (position.x >= 0 && position.x < MAXDUNX && position.y >= 0 && position.y < MAXDUNY) { if (InDungeonBounds(position)) {
if (currlevel < 17) { if (currlevel < 17) {
SetLight(position, 0); SetLight(position, 0);
} else if (GetLight(position) > lightradius[nRadius][0]) { } else if (GetLight(position) > lightradius[nRadius][0]) {
@ -579,7 +579,7 @@ void DoLighting(Point position, int nRadius, int lnum)
if (radiusBlock < 128) { if (radiusBlock < 128) {
Point temp = position + Displacement { x, y }; Point temp = position + Displacement { x, y };
int8_t v = lightradius[nRadius][radiusBlock]; int8_t v = lightradius[nRadius][radiusBlock];
if (temp.x >= 0 && temp.x < MAXDUNX && temp.y >= 0 && temp.y < MAXDUNY) if (InDungeonBounds(temp))
if (v < GetLight(temp)) if (v < GetLight(temp))
SetLight(temp, v); SetLight(temp, v);
} }
@ -593,7 +593,7 @@ void DoLighting(Point position, int nRadius, int lnum)
if (radiusBlock < 128) { if (radiusBlock < 128) {
Point temp = position + Displacement { y, -x }; Point temp = position + Displacement { y, -x };
int8_t v = lightradius[nRadius][radiusBlock]; int8_t v = lightradius[nRadius][radiusBlock];
if (temp.x >= 0 && temp.x < MAXDUNX && temp.y >= 0 && temp.y < MAXDUNY) if (InDungeonBounds(temp))
if (v < GetLight(temp)) if (v < GetLight(temp))
SetLight(temp, v); SetLight(temp, v);
} }
@ -607,7 +607,7 @@ void DoLighting(Point position, int nRadius, int lnum)
if (radiusBlock < 128) { if (radiusBlock < 128) {
Point temp = position - Displacement { x, y }; Point temp = position - Displacement { x, y };
int8_t v = lightradius[nRadius][radiusBlock]; int8_t v = lightradius[nRadius][radiusBlock];
if (temp.x >= 0 && temp.x < MAXDUNX && temp.y >= 0 && temp.y < MAXDUNY) if (InDungeonBounds(temp))
if (v < GetLight(temp)) if (v < GetLight(temp))
SetLight(temp, v); SetLight(temp, v);
} }
@ -621,7 +621,7 @@ void DoLighting(Point position, int nRadius, int lnum)
if (radiusBlock < 128) { if (radiusBlock < 128) {
Point temp = position + Displacement { -y, x }; Point temp = position + Displacement { -y, x };
int8_t v = lightradius[nRadius][radiusBlock]; int8_t v = lightradius[nRadius][radiusBlock];
if (temp.x >= 0 && temp.x < MAXDUNX && temp.y >= 0 && temp.y < MAXDUNY) if (InDungeonBounds(temp))
if (v < GetLight(temp)) if (v < GetLight(temp))
SetLight(temp, v); SetLight(temp, v);
} }
@ -706,11 +706,11 @@ void DoVision(Point position, int nRadius, bool doautomap, bool visible)
} }
break; break;
} }
if (nCrawlX >= 0 && nCrawlX < MAXDUNX && nCrawlY >= 0 && nCrawlY < MAXDUNY) { if (InDungeonBounds({ nCrawlX, nCrawlY })) {
nBlockerFlag = nBlockTable[dPiece[nCrawlX][nCrawlY]]; nBlockerFlag = nBlockTable[dPiece[nCrawlX][nCrawlY]];
if ((x1adj + nCrawlX >= 0 && x1adj + nCrawlX < MAXDUNX && y1adj + nCrawlY >= 0 && y1adj + nCrawlY < MAXDUNY if ((InDungeonBounds({ x1adj + nCrawlX, y1adj + nCrawlY })
&& !nBlockTable[dPiece[x1adj + nCrawlX][y1adj + nCrawlY]]) && !nBlockTable[dPiece[x1adj + nCrawlX][y1adj + nCrawlY]])
|| (x2adj + nCrawlX >= 0 && x2adj + nCrawlX < MAXDUNX && y2adj + nCrawlY >= 0 && y2adj + nCrawlY < MAXDUNY || (InDungeonBounds({ x2adj + nCrawlX, y2adj + nCrawlY })
&& !nBlockTable[dPiece[x2adj + nCrawlX][y2adj + nCrawlY]])) { && !nBlockTable[dPiece[x2adj + nCrawlX][y2adj + nCrawlY]])) {
if (doautomap) { if (doautomap) {
if (dFlags[nCrawlX][nCrawlY] != 0) { if (dFlags[nCrawlX][nCrawlY] != 0) {

14
Source/monster.cpp

@ -394,7 +394,7 @@ void PlaceUniqueMonst(int uniqindex, int miniontype, int bosspacksize)
int count2 = 0; int count2 = 0;
for (int x = xp - 3; x < xp + 3; x++) { for (int x = xp - 3; x < xp + 3; x++) {
for (int y = yp - 3; y < yp + 3; y++) { for (int y = yp - 3; y < yp + 3; y++) {
if (y >= 0 && y < MAXDUNY && x >= 0 && x < MAXDUNX && CanPlaceMonster(x, y)) { if (InDungeonBounds({ x, y }) && CanPlaceMonster(x, y)) {
count2++; count2++;
} }
} }
@ -1134,7 +1134,7 @@ void Teleport(int i)
if (j != 0 || k != 0) { if (j != 0 || k != 0) {
x = mx + rx * j; x = mx + rx * j;
y = my + ry * k; y = my + ry * k;
if (y >= 0 && y < MAXDUNY && x >= 0 && x < MAXDUNX && x != monster.position.tile.x && y != monster.position.tile.y) { if (InDungeonBounds({ x, y }) && x != monster.position.tile.x && y != monster.position.tile.y) {
if (IsTileAvailable(monster, { x, y })) if (IsTileAvailable(monster, { x, y }))
done = true; done = true;
} }
@ -2614,7 +2614,7 @@ void FallenAi(int i)
for (int x = -rad; x <= rad; x++) { for (int x = -rad; x <= rad; x++) {
int xpos = monster.position.tile.x + x; int xpos = monster.position.tile.x + x;
int ypos = monster.position.tile.y + y; int ypos = monster.position.tile.y + y;
if (y >= 0 && y < MAXDUNY && x >= 0 && x < MAXDUNX) { if (InDungeonBounds({ x, y })) {
int m = dMonster[xpos][ypos]; int m = dMonster[xpos][ypos];
if (m <= 0) if (m <= 0)
continue; continue;
@ -3941,11 +3941,9 @@ void M_ClearSquares(int i)
int m2 = i + 1; int m2 = i + 1;
for (int y = my - 1; y <= my + 1; y++) { for (int y = my - 1; y <= my + 1; y++) {
if (y >= 0 && y < MAXDUNY) { for (int x = mx - 1; x <= mx + 1; x++) {
for (int x = mx - 1; x <= mx + 1; x++) { if (InDungeonBounds({ x, y }) && (dMonster[x][y] == m1 || dMonster[x][y] == m2))
if (x >= 0 && x < MAXDUNX && (dMonster[x][y] == m1 || dMonster[x][y] == m2)) dMonster[x][y] = 0;
dMonster[x][y] = 0;
}
} }
} }
} }

2
Source/player.cpp

@ -2892,7 +2892,7 @@ void FixPlrWalkTags(int pnum)
int dy = player.position.old.y; int dy = player.position.old.y;
for (int y = dy - 1; y <= dy + 1; y++) { for (int y = dy - 1; y <= dy + 1; y++) {
for (int x = dx - 1; x <= dx + 1; x++) { for (int x = dx - 1; x <= dx + 1; x++) {
if (x >= 0 && x < MAXDUNX && y >= 0 && y < MAXDUNY && (dPlayer[x][y] == pp || dPlayer[x][y] == pn)) { if (InDungeonBounds({ x, y }) && (dPlayer[x][y] == pp || dPlayer[x][y] == pn)) {
dPlayer[x][y] = 0; dPlayer[x][y] = 0;
} }
} }

5
Source/scrollrt.cpp

@ -818,8 +818,7 @@ void DrawPlayerHelper(const Surface &out, Point tilePosition, Point targetBuffer
*/ */
void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosition) void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosition)
{ {
assert(tilePosition.x >= 0 && tilePosition.x < MAXDUNX); assert(InDungeonBounds(tilePosition));
assert(tilePosition.y >= 0 && tilePosition.y < MAXDUNY);
if (dRendered[tilePosition.x][tilePosition.y]) if (dRendered[tilePosition.x][tilePosition.y])
return; return;
@ -972,7 +971,7 @@ void DrawTileContent(const Surface &out, Point tilePosition, Point targetBufferP
for (int i = 0; i < rows; i++) { for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) { for (int j = 0; j < columns; j++) {
if (tilePosition.x >= 0 && tilePosition.x < MAXDUNX && tilePosition.y >= 0 && tilePosition.y < MAXDUNY) { if (InDungeonBounds(tilePosition)) {
if (tilePosition.x + 1 < MAXDUNX && tilePosition.y - 1 >= 0 && targetBufferPosition.x + TILE_WIDTH <= gnScreenWidth) { if (tilePosition.x + 1 < MAXDUNX && tilePosition.y - 1 >= 0 && targetBufferPosition.x + TILE_WIDTH <= gnScreenWidth) {
// Render objects behind walls first to prevent sprites, that are moving // Render objects behind walls first to prevent sprites, that are moving
// between tiles, from poking through the walls as they exceed the tile bounds. // between tiles, from poking through the walls as they exceed the tile bounds.

2
Source/track.cpp

@ -56,7 +56,7 @@ void RepeatMouseAction()
bool rangedAttack = myPlayer.UsesRangedWeapon(); bool rangedAttack = myPlayer.UsesRangedWeapon();
switch (LastMouseButtonAction) { switch (LastMouseButtonAction) {
case MouseActionType::Attack: case MouseActionType::Attack:
if (cursPosition.x >= 0 && cursPosition.x < MAXDUNX && cursPosition.y >= 0 && cursPosition.y < MAXDUNY) if (InDungeonBounds(cursPosition))
NetSendCmdLoc(MyPlayerId, true, rangedAttack ? CMD_RATTACKXY : CMD_SATTACKXY, cursPosition); NetSendCmdLoc(MyPlayerId, true, rangedAttack ? CMD_RATTACKXY : CMD_SATTACKXY, cursPosition);
break; break;
case MouseActionType::AttackMonsterTarget: case MouseActionType::AttackMonsterTarget:

Loading…
Cancel
Save