MCPcopy Index your code
hub / github.com/NetHack/NetHack / meatcorpse

Function meatcorpse

src/mon.c:1655–1722  ·  view source on GitHub ↗

Monster eats a corpse off the ground. Return value is 0 = nothing eaten, 1 = ate a corpse, 2 = died. */

Source from the content-addressed store, hash-verified

1653/* Monster eats a corpse off the ground.
1654 Return value is 0 = nothing eaten, 1 = ate a corpse, 2 = died. */
1655int
1656meatcorpse(
1657 struct monst *mtmp) /* for purple worms and other voracious monsters */
1658{
1659 struct obj *otmp;
1660 struct permonst *ptr, *original_ptr = mtmp->data, *corpsepm;
1661 coordxy x = mtmp->mx, y = mtmp->my;
1662
1663 /* if a pet, eating is handled separately, in dog.c */
1664 if (mtmp->mtame)
1665 return 0;
1666
1667 /* skips past any globs */
1668 for (otmp = sobj_at(CORPSE, x, y); otmp;
1669 /* won't get back here if otmp is split or gets used up */
1670 otmp = nxtobj(otmp, CORPSE, TRUE)) {
1671
1672 corpsepm = &mons[otmp->corpsenm];
1673 /* skip some corpses */
1674 if (vegan(corpsepm) /* ignore veggy corpse even if omnivorous */
1675 /* don't eat harmful corpses */
1676 || (flesh_petrifies(corpsepm) && !resists_ston(mtmp)))
1677 continue;
1678 if (is_rider(corpsepm)) {
1679 boolean revived_it = revive_corpse(otmp);
1680
1681 newsym(x, y); /* corpse is gone; mtmp might be too so do this now
1682 since we're bypassing the bottom of the loop */
1683 if (!revived_it)
1684 continue; /* revival failed? if so, corpse is gone */
1685 /* Successful Rider revival; unlike skipped corpses, don't
1686 just move on to next corpse as if nothing has happened.
1687 [Can Rider revival bump 'mtmp' off level when it's full?
1688 We ought to return 3 if that happens.] */
1689 break;
1690 }
1691
1692 if (otmp->quan > 1)
1693 otmp = splitobj(otmp, 1L);
1694
1695 if (cansee(x, y) && canseemon(mtmp)) {
1696 /* call distant_name() for its possible side-effects even if
1697 the result won't be printed */
1698 char *otmpname = distant_name(otmp, doname);
1699
1700 if (flags.verbose)
1701 pline_mon(mtmp, "%s eats %s!",
1702 Monnam(mtmp), otmpname);
1703 } else {
1704 Soundeffect(se_masticating_sound, 50);
1705 if (flags.verbose)
1706 You_hear("a masticating sound.");
1707 }
1708
1709 m_consume_obj(mtmp, otmp);
1710 /* in case it polymorphed or died */
1711 ptr = mtmp->data;
1712 if (ptr != original_ptr)

Callers 1

monmove.cFile · 0.85

Calls 11

sobj_atFunction · 0.85
nxtobjFunction · 0.85
revive_corpseFunction · 0.85
newsymFunction · 0.85
splitobjFunction · 0.85
canseemonFunction · 0.85
distant_nameFunction · 0.85
pline_monFunction · 0.85
MonnamFunction · 0.85
You_hearFunction · 0.85
m_consume_objFunction · 0.85

Tested by

no test coverage detected