Skip to content

Commit

Permalink
Fix items drifting through walls (tmewett#663)
Browse files Browse the repository at this point in the history
  • Loading branch information
zenzombie authored Mar 13, 2024
1 parent 2276993 commit f26d647
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions changes/prevent-items-drifting-through-walls.md
Original file line number Diff line number Diff line change
@@ -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.
21 changes: 12 additions & 9 deletions src/brogue/Items.c
Original file line number Diff line number Diff line change
Expand Up @@ -1216,16 +1216,19 @@ void updateFloorItems() {
if (cellHasTerrainFlag((pos){ 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((pos){ x, y });
refreshDungeonCell(loc);
continue;
}
theItem->loc = loc;
refreshDungeonCell((pos){ x, y });
refreshDungeonCell(loc);
continue;
}
if (cellHasTMFlag((pos){ x, y }, TM_PROMOTES_ON_ITEM)) {
for (layer = 0; layer < NUMBER_TERRAIN_LAYERS; layer++) {
Expand Down

0 comments on commit f26d647

Please sign in to comment.