From 59cf69085a3423367e0ac5223b42946470bae22e Mon Sep 17 00:00:00 2001 From: Michael Meyer Date: Wed, 29 Jun 2022 17:19:59 -0400 Subject: [PATCH] Fix: non-swimming pets eating underwater food Commit 32234b1d in 2003 mentioned in its commit message that pet dragons shouldn't be able to eat underwater food items. This was mostly true: non-swimming pets wouldn't select underwater food as a goal, and wouldn't spend an action eating something unreachable on their current position. But the "combined eat and move" case in dog_move didn't check could_reach_item, so if a non-swimming pet happened to move to a spot with underwater food for some reason, they could eat it on that turn anyway. This commit should close this loophole and prevent non-swimming monsters from eating underwater food (or other unreachable food) even if they happen to fly over its position. --- src/dogmove.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/dogmove.c b/src/dogmove.c index 39de229f0..b774490d5 100644 --- a/src/dogmove.c +++ b/src/dogmove.c @@ -1115,13 +1115,15 @@ dog_move(register struct monst *mtmp, /* dog eschews cursed objects, but likes dog food */ /* (minion isn't interested; `cursemsg' stays FALSE) */ - if (has_edog) + if (has_edog) { + boolean can_reach_food = could_reach_item(mtmp, nx, ny); for (obj = g.level.objects[nx][ny]; obj; obj = obj->nexthere) { if (obj->cursed) { cursemsg[i] = TRUE; - } else if ((otyp = dogfood(mtmp, obj)) < MANFOOD - && (otyp < ACCFOOD - || edog->hungrytime <= g.moves)) { + } else if (can_reach_food + && (otyp = dogfood(mtmp, obj)) < MANFOOD + && (otyp < ACCFOOD + || edog->hungrytime <= g.moves)) { /* Note: our dog likes the food so much that he * might eat it even when it conceals a cursed object */ nix = nx; @@ -1132,6 +1134,7 @@ dog_move(register struct monst *mtmp, goto newdogpos; } } + } /* didn't find something to eat; if we saw a cursed item and aren't being forced to walk on it, usually keep looking */ if (cursemsg[i] && !mtmp->mleashed && uncursedcnt > 0