src/weapon: Avoid touch_petrifies with invalid corpsenm

Filter out unset (-1) corpsenm before calling touch_petrifies.
While here, cleanup the oselect by doing excluding loop
and use can_touch_safely for filtering (suggested by entrez).
This commit is contained in:
Mika Kuoppala
2024-01-06 12:06:56 -08:00
committed by PatR
parent 83fba62152
commit 4669676fc0
+12 -5
View File
@@ -469,16 +469,23 @@ static struct obj *oselect(struct monst *, int);
} while (0) } while (0)
static struct obj * static struct obj *
oselect(struct monst *mtmp, int x) oselect(struct monst *mtmp, int type)
{ {
struct obj *otmp; struct obj *otmp;
for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) { for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) {
if (otmp->otyp == x if (otmp->otyp != type)
continue;
/* never select non-cockatrice corpses */ /* never select non-cockatrice corpses */
&& !((x == CORPSE || x == EGG) if ((type == CORPSE || type == EGG)
&& !touch_petrifies(&mons[otmp->corpsenm])) && (otmp->corpsenm == NON_PM
&& (!otmp->oartifact || touch_artifact(otmp, mtmp))) || !touch_petrifies(&mons[otmp->corpsenm])))
continue;
if (!can_touch_safely(mtmp, otmp))
continue;
return otmp; return otmp;
} }
return (struct obj *) 0; return (struct obj *) 0;