Browse Source

♻️ Leverage 'Point' struct on 'ItemSpaceOk'

pull/2099/head
Juliano Leal Goncalves 5 years ago committed by Anders Jenbo
parent
commit
9c85e61025
  1. 36
      Source/items.cpp
  2. 2
      Source/items.h
  3. 4
      Source/player.cpp

36
Source/items.cpp

@ -1270,43 +1270,43 @@ void CreatePlrItems(int playerId)
CalcPlrItemVals(playerId, false); CalcPlrItemVals(playerId, false);
} }
bool ItemSpaceOk(int i, int j) bool ItemSpaceOk(Point position)
{ {
int oi; int oi;
// BUGFIX: Check `i + 1 >= MAXDUNX` and `j + 1 >= MAXDUNY` (applied) // BUGFIX: Check `i + 1 >= MAXDUNX` and `j + 1 >= MAXDUNY` (applied)
if (i < 0 || i + 1 >= MAXDUNX || j < 0 || j + 1 >= MAXDUNY) if (position.x < 0 || position.x + 1 >= MAXDUNX || position.y < 0 || position.y + 1 >= MAXDUNY)
return false; return false;
if (dMonster[i][j] != 0) if (dMonster[position.x][position.y] != 0)
return false; return false;
if (dPlayer[i][j] != 0) if (dPlayer[position.x][position.y] != 0)
return false; return false;
if (dItem[i][j] != 0) if (dItem[position.x][position.y] != 0)
return false; return false;
if (dObject[i][j] != 0) { if (dObject[position.x][position.y] != 0) {
oi = dObject[i][j] > 0 ? dObject[i][j] - 1 : -(dObject[i][j] + 1); oi = dObject[position.x][position.y] > 0 ? dObject[position.x][position.y] - 1 : -(dObject[position.x][position.y] + 1);
if (object[oi]._oSolidFlag) if (object[oi]._oSolidFlag)
return false; return false;
} }
if (dObject[i + 1][j + 1] > 0 && object[dObject[i + 1][j + 1] - 1]._oSelFlag != 0) if (dObject[position.x + 1][position.y + 1] > 0 && object[dObject[position.x + 1][position.y + 1] - 1]._oSelFlag != 0)
return false; return false;
if (dObject[i + 1][j + 1] < 0 && object[-(dObject[i + 1][j + 1] + 1)]._oSelFlag != 0) if (dObject[position.x + 1][position.y + 1] < 0 && object[-(dObject[position.x + 1][position.y + 1] + 1)]._oSelFlag != 0)
return false; return false;
if (dObject[i + 1][j] > 0 if (dObject[position.x + 1][position.y] > 0
&& dObject[i][j + 1] > 0 && dObject[position.x][position.y + 1] > 0
&& object[dObject[i + 1][j] - 1]._oSelFlag != 0 && object[dObject[position.x + 1][position.y] - 1]._oSelFlag != 0
&& object[dObject[i][j + 1] - 1]._oSelFlag != 0) { && object[dObject[position.x][position.y + 1] - 1]._oSelFlag != 0) {
return false; return false;
} }
return !nSolidTable[dPiece[i][j]]; return !nSolidTable[dPiece[position.x][position.y]];
} }
static bool GetItemSpace(Point position, int8_t inum) static bool GetItemSpace(Point position, int8_t inum)
@ -1319,7 +1319,7 @@ static bool GetItemSpace(Point position, int8_t inum)
for (int j = position.y - 1; j <= position.y + 1; j++) { for (int j = position.y - 1; j <= position.y + 1; j++) {
xx = 0; xx = 0;
for (int i = position.x - 1; i <= position.x + 1; i++) { for (int i = position.x - 1; i <= position.x + 1; i++) {
itemhold[xx][yy] = ItemSpaceOk(i, j); itemhold[xx][yy] = ItemSpaceOk({ i, j });
xx++; xx++;
} }
yy++; yy++;
@ -1383,7 +1383,7 @@ static void GetSuperItemSpace(Point position, int8_t inum)
int yy = position.y + j; int yy = position.y + j;
for (int i = -k; i <= k; i++) { for (int i = -k; i <= k; i++) {
int xx = i + position.x; int xx = i + position.x;
if (!ItemSpaceOk(xx, yy)) if (!ItemSpaceOk({ xx, yy }))
continue; continue;
items[inum].position = { xx, yy }; items[inum].position = { xx, yy };
dItem[xx][yy] = inum + 1; dItem[xx][yy] = inum + 1;
@ -1402,7 +1402,7 @@ Point GetSuperItemLoc(Point position)
ret.y = position.y + j; ret.y = position.y + j;
for (int i = -k; i <= k; i++) { for (int i = -k; i <= k; i++) {
ret.x = i + position.x; ret.x = i + position.x;
if (ItemSpaceOk(ret.x, ret.y)) { if (ItemSpaceOk(ret)) {
return ret; return ret;
} }
} }
@ -2832,7 +2832,7 @@ void SpawnQuestItem(int itemid, Point position, int randarea, int selflag)
bool failed = false; bool failed = false;
for (int i = 0; i < randarea && !failed; i++) { for (int i = 0; i < randarea && !failed; i++) {
for (int j = 0; j < randarea && !failed; j++) { for (int j = 0; j < randarea && !failed; j++) {
failed = !ItemSpaceOk(i + position.x, j + position.y); failed = !ItemSpaceOk(position + Point { i, j });
} }
} }
if (!failed) if (!failed)

2
Source/items.h

@ -406,7 +406,7 @@ void GetGoldSeed(int pnum, ItemStruct *h);
int GetGoldCursor(int value); int GetGoldCursor(int value);
void SetPlrHandGoldCurs(ItemStruct *h); void SetPlrHandGoldCurs(ItemStruct *h);
void CreatePlrItems(int playerId); void CreatePlrItems(int playerId);
bool ItemSpaceOk(int i, int j); bool ItemSpaceOk(Point position);
int AllocateItem(); int AllocateItem();
Point GetSuperItemLoc(Point position); Point GetSuperItemLoc(Point position);
void GetItemAttrs(int i, int idata, int lvl); void GetItemAttrs(int i, int idata, int lvl);

4
Source/player.cpp

@ -1649,7 +1649,7 @@ static void PlrDeadItem(PlayerStruct &player, ItemStruct *itm, int xx, int yy)
int x = xx + player.position.tile.x; int x = xx + player.position.tile.x;
int y = yy + player.position.tile.y; int y = yy + player.position.tile.y;
if ((xx || yy) && ItemSpaceOk(x, y)) { if ((xx || yy) && ItemSpaceOk({ x, y })) {
RespawnDeadItem(itm, x, y); RespawnDeadItem(itm, x, y);
player.HoldItem = *itm; player.HoldItem = *itm;
NetSendCmdPItem(false, CMD_RESPAWNITEM, { x, y }); NetSendCmdPItem(false, CMD_RESPAWNITEM, { x, y });
@ -1661,7 +1661,7 @@ static void PlrDeadItem(PlayerStruct &player, ItemStruct *itm, int xx, int yy)
y = j + player.position.tile.y; y = j + player.position.tile.y;
for (i = -k; i <= k; i++) { for (i = -k; i <= k; i++) {
x = i + player.position.tile.x; x = i + player.position.tile.x;
if (ItemSpaceOk(x, y)) { if (ItemSpaceOk({ x, y })) {
RespawnDeadItem(itm, x, y); RespawnDeadItem(itm, x, y);
player.HoldItem = *itm; player.HoldItem = *itm;
NetSendCmdPItem(false, CMD_RESPAWNITEM, { x, y }); NetSendCmdPItem(false, CMD_RESPAWNITEM, { x, y });

Loading…
Cancel
Save