* 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). */
| 1460 | * has young and old forms). |
| 1461 | */ |
| 1462 | int |
| 1463 | meatmetal(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; |
no test coverage detected