MCPcopy Create free account
hub / github.com/NetHack/NetHack / meatmetal

Function meatmetal

src/mon.c:1462–1529  ·  view source on GitHub ↗

* Maybe eat a metallic object (not just gold). * Return value: 0 => nothing happened, 1 => monster ate something, * 2 => monster died (it must have grown into a genocided form, but * that can't happen at present because nothing which eats objects * has young and old forms). */

Source from the content-addressed store, hash-verified

1460 * has young and old forms).
1461 */
1462int
1463meatmetal(struct monst *mtmp)
1464{
1465 struct obj *otmp;
1466 char *otmpname;
1467 int vis = canseemon(mtmp);
1468
1469 /* If a pet, eating is handled separately, in dog.c */
1470 if (mtmp->mtame)
1471 return 0;
1472
1473 /* Eats topmost metal object if it is there */
1474 for (otmp = svl.level.objects[mtmp->mx][mtmp->my]; otmp;
1475 otmp = otmp->nexthere) {
1476 /* Don't eat indigestible/choking/inappropriate objects */
1477 if ((mtmp->data == &mons[PM_RUST_MONSTER] && !is_rustprone(otmp))
1478 || (otmp->otyp == AMULET_OF_STRANGULATION
1479 || otmp->otyp == RIN_SLOW_DIGESTION)
1480 || (otmp->opoisoned && !resists_poison(mtmp)))
1481 continue;
1482 if (is_metallic(otmp) && !obj_resists(otmp, 5, 95)
1483 && touch_artifact(otmp, mtmp)) {
1484 if (mtmp->data == &mons[PM_RUST_MONSTER] && otmp->oerodeproof) {
1485 if (vis) {
1486 /* call distant_name() for its side-effects even when
1487 !verbose so won't be printed */
1488 otmpname = distant_name(otmp, doname);
1489 if (flags.verbose)
1490 pline_mon(mtmp, "%s eats %s!",
1491 Monnam(mtmp), otmpname);
1492 }
1493 /* The object's rustproofing is gone now */
1494 otmp->oerodeproof = 0;
1495 mtmp->mstun = 1;
1496 if (vis) {
1497 /* (see above; format even if it won't be printed) */
1498 otmpname = distant_name(otmp, doname);
1499 if (flags.verbose)
1500 pline_mon(mtmp, "%s spits %s out in disgust!",
1501 Monnam(mtmp), otmpname);
1502 }
1503 } else {
1504 if (cansee(mtmp->mx, mtmp->my)) {
1505 /* (see above; format even if it won't be printed) */
1506 otmpname = distant_name(otmp, doname);
1507 if (flags.verbose)
1508 pline_mon(mtmp, "%s eats %s!",
1509 Monnam(mtmp), otmpname);
1510 } else {
1511 if (flags.verbose) {
1512 Soundeffect(se_crunching_sound, 50);
1513 You_hear("a crunching sound.");
1514 }
1515 }
1516 mtmp->meating = otmp->owt / 2 + 1;
1517 m_consume_obj(mtmp, otmp);
1518 if (DEADMONSTER(mtmp))
1519 return 2;

Callers 1

monmove.cFile · 0.85

Calls 11

canseemonFunction · 0.85
obj_resistsFunction · 0.85
touch_artifactFunction · 0.85
distant_nameFunction · 0.85
pline_monFunction · 0.85
MonnamFunction · 0.85
You_hearFunction · 0.85
m_consume_objFunction · 0.85
rndFunction · 0.85
mksobj_atFunction · 0.85
newsymFunction · 0.85

Tested by

no test coverage detected