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

Function mintrap

src/trap.c:3732–3840  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3730}
3731
3732int
3733mintrap(struct monst *mtmp, unsigned mintrapflags)
3734{
3735 struct trap *trap = t_at(mtmp->mx, mtmp->my);
3736 struct permonst *mptr = mtmp->data;
3737 int trap_result = Trap_Effect_Finished;
3738
3739 if (!trap) {
3740 mtmp->mtrapped = 0; /* perhaps teleported? */
3741 } else if (mtmp->mtrapped) { /* is currently in the trap */
3742 if (!trap->tseen && cansee(mtmp->mx, mtmp->my) && canseemon(mtmp)
3743 && (is_pit(trap->ttyp) || trap->ttyp == BEAR_TRAP
3744 || trap->ttyp == HOLE
3745 || trap->ttyp == WEB)) {
3746 /* If you come upon an obviously trapped monster, then
3747 you must be able to see the trap it's in too. */
3748 seetrap(trap);
3749 }
3750
3751 if (!rn2(40) || (is_pit(trap->ttyp) && m_easy_escape_pit(mtmp))) {
3752 if (sobj_at(BOULDER, mtmp->mx, mtmp->my)
3753 && is_pit(trap->ttyp)) {
3754 if (!rn2(2)) {
3755 mtmp->mtrapped = 0;
3756 if (canseemon(mtmp))
3757 pline_mon(mtmp, "%s pulls free...",
3758 Monnam(mtmp));
3759 fill_pit(mtmp->mx, mtmp->my);
3760 }
3761 } else {
3762 if (canseemon(mtmp)) {
3763 set_msg_xy(mtmp->mx, mtmp->my);
3764 if (is_pit(trap->ttyp))
3765 pline("%s climbs %sout of the pit.", Monnam(mtmp),
3766 m_easy_escape_pit(mtmp) ? "easily " : "");
3767 else if (trap->ttyp == BEAR_TRAP || trap->ttyp == WEB)
3768 pline("%s pulls free of the %s.", Monnam(mtmp),
3769 trapname(trap->ttyp, FALSE));
3770 }
3771 mtmp->mtrapped = 0;
3772 }
3773 } else if (metallivorous(mptr)) {
3774 if (trap->ttyp == BEAR_TRAP) {
3775 if (canseemon(mtmp))
3776 pline_mon(mtmp, "%s eats a bear trap!",
3777 Monnam(mtmp));
3778 deltrap(trap);
3779 mtmp->meating = 5;
3780 mtmp->mtrapped = 0;
3781 } else if (trap->ttyp == SPIKED_PIT) {
3782 if (canseemon(mtmp))
3783 pline_mon(mtmp, "%s munches on some spikes!",
3784 Monnam(mtmp));
3785 trap->ttyp = PIT;
3786 mtmp->meating = 5;
3787 }
3788 }
3789 trap_result = mtmp->mtrapped ? Trap_Caught_Mon : Trap_Effect_Finished;

Callers 15

hmon_hitmon_splitmonFunction · 0.85
dismount_steedFunction · 0.85
rloc_to_coreFunction · 0.85
domove_swap_with_petFunction · 0.85
domove_coreFunction · 0.85
mattackmFunction · 0.85
gulpmmFunction · 0.85
digactualholeFunction · 0.85
mhurtle_stepFunction · 0.85
mhurtleFunction · 0.85
keepdogsFunction · 0.85
trapeffect_webFunction · 0.85

Calls 15

t_atFunction · 0.85
canseemonFunction · 0.85
seetrapFunction · 0.85
rn2Function · 0.85
m_easy_escape_pitFunction · 0.85
sobj_atFunction · 0.85
pline_monFunction · 0.85
MonnamFunction · 0.85
fill_pitFunction · 0.85
set_msg_xyFunction · 0.85
trapnameFunction · 0.85
deltrapFunction · 0.85

Tested by

no test coverage detected