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.
This commit is contained in:
Michael Meyer
2022-06-29 17:19:59 -04:00
committed by PatR
parent 9bab9d4fce
commit 59cf69085a

View File

@@ -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