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:
+14
-7
@@ -469,17 +469,24 @@ 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)
|
||||||
/* never select non-cockatrice corpses */
|
continue;
|
||||||
&& !((x == CORPSE || x == EGG)
|
|
||||||
&& !touch_petrifies(&mons[otmp->corpsenm]))
|
/* never select non-cockatrice corpses */
|
||||||
&& (!otmp->oartifact || touch_artifact(otmp, mtmp)))
|
if ((type == CORPSE || type == EGG)
|
||||||
return otmp;
|
&& (otmp->corpsenm == NON_PM
|
||||||
|
|| !touch_petrifies(&mons[otmp->corpsenm])))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!can_touch_safely(mtmp, otmp))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
return otmp;
|
||||||
}
|
}
|
||||||
return (struct obj *) 0;
|
return (struct obj *) 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user