From d75c6450d97d0aa9a136b9b0dc28af0c9c358c18 Mon Sep 17 00:00:00 2001 From: Brandon <71573970+zenzombie@users.noreply.github.com> Date: Sun, 11 Feb 2024 14:53:14 -0800 Subject: [PATCH] Fix items drifting through walls --- .../prevent-items-drifting-through-walls.md | 1 + src/brogue/Items.c | 21 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 changes/prevent-items-drifting-through-walls.md diff --git a/changes/prevent-items-drifting-through-walls.md b/changes/prevent-items-drifting-through-walls.md new file mode 100644 index 00000000..669f450f --- /dev/null +++ b/changes/prevent-items-drifting-through-walls.md @@ -0,0 +1 @@ +Fixed a bug where items in deep water could drift through walls. Items can now only drift to an available adjacent cell. \ No newline at end of file diff --git a/src/brogue/Items.c b/src/brogue/Items.c index 0582704f..236daedf 100644 --- a/src/brogue/Items.c +++ b/src/brogue/Items.c @@ -1183,16 +1183,19 @@ void updateFloorItems() { if (cellHasTerrainFlag(x, y, T_MOVES_ITEMS)) { pos loc; getQualifyingLocNear(&loc, (pos){ x, y }, true, 0, (T_OBSTRUCTS_ITEMS | T_OBSTRUCTS_PASSABILITY), (HAS_ITEM), false, false); - removeItemAt((pos){ x, y }); - pmapAt(loc)->flags |= HAS_ITEM; - if (pmap[x][y].flags & ITEM_DETECTED) { - pmap[x][y].flags &= ~ITEM_DETECTED; - pmapAt(loc)->flags |= ITEM_DETECTED; + // To prevent items drifting through walls, they can only drift to an adjacent cell + if (distanceBetween((pos){ x, y }, loc) == 1) { + removeItemAt((pos){ x, y }); + pmapAt(loc)->flags |= HAS_ITEM; + if (pmap[x][y].flags & ITEM_DETECTED) { + pmap[x][y].flags &= ~ITEM_DETECTED; + pmapAt(loc)->flags |= ITEM_DETECTED; + } + theItem->loc = loc; + refreshDungeonCell(x, y); + refreshDungeonCell(loc.x, loc.y); + continue; } - theItem->loc = loc; - refreshDungeonCell(x, y); - refreshDungeonCell(loc.x, loc.y); - continue; } if (cellHasTMFlag(x, y, TM_PROMOTES_ON_ITEM)) { for (layer = 0; layer < NUMBER_TERRAIN_LAYERS; layer++) {