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

Function precheck

src/muse.c:58–160  ·  view source on GitHub ↗

Any preliminary checks which may result in the monster being unable to use * the item. Returns 0 if nothing happened, 2 if the monster can't do * anything (i.e. it teleported) and 1 if it's dead. */

Source from the content-addressed store, hash-verified

56 * anything (i.e. it teleported) and 1 if it's dead.
57 */
58staticfn int
59precheck(struct monst *mon, struct obj *obj)
60{
61 boolean vis;
62
63 if (!obj)
64 return 0;
65 vis = cansee(mon->mx, mon->my);
66
67 if (obj->oclass == POTION_CLASS) {
68 coord cc;
69 static const char *const empty = "The potion turns out to be empty.";
70 struct monst *mtmp;
71
72 if (objdescr_is(obj, "milky")) {
73 if (!(svm.mvitals[PM_GHOST].mvflags & G_GONE)
74 && !rn2(POTION_OCCUPANT_CHANCE(svm.mvitals[PM_GHOST].born))) {
75 if (!enexto(&cc, mon->mx, mon->my, &mons[PM_GHOST]))
76 return 0;
77 mquaffmsg(mon, obj);
78 m_useup(mon, obj);
79 mtmp = makemon(&mons[PM_GHOST], cc.x, cc.y, MM_NOMSG);
80 if (!mtmp) {
81 if (vis)
82 pline1(empty);
83 } else {
84 if (vis) {
85 pline(
86 "As %s opens the bottle, an enormous %s emerges!",
87 mon_nam(mon),
88 Hallucination ? rndmonnam(NULL)
89 : (const char *) "ghost");
90 pline("%s is frightened to death,"
91 " and unable to move.",
92 Monnam(mon));
93 }
94 paralyze_monst(mon, 3);
95 }
96 return 2;
97 }
98 }
99 if (objdescr_is(obj, "smoky")
100 && !(svm.mvitals[PM_DJINNI].mvflags & G_GONE)
101 && !rn2(POTION_OCCUPANT_CHANCE(svm.mvitals[PM_DJINNI].born))) {
102 if (!enexto(&cc, mon->mx, mon->my, &mons[PM_DJINNI]))
103 return 0;
104 mquaffmsg(mon, obj);
105 m_useup(mon, obj);
106 mtmp = makemon(&mons[PM_DJINNI], cc.x, cc.y, MM_NOMSG);
107 if (!mtmp) {
108 if (vis)
109 pline1(empty);
110 } else {
111 if (vis)
112 pline_mon(mtmp, "In a cloud of smoke, %s emerges!", a_monnam(mtmp));
113 pline("%s speaks.", vis ? Monnam(mtmp) : Something);
114 /* I suspect few players will be upset that monsters */
115 /* can't wish for wands of death here.... */

Callers 3

use_defensiveFunction · 0.70
use_offensiveFunction · 0.70
use_miscFunction · 0.70

Calls 15

objdescr_isFunction · 0.85
rn2Function · 0.85
enextoFunction · 0.85
mquaffmsgFunction · 0.85
m_useupFunction · 0.85
makemonFunction · 0.85
mon_namFunction · 0.85
rndmonnamFunction · 0.85
MonnamFunction · 0.85
paralyze_monstFunction · 0.85
pline_monFunction · 0.85
a_monnamFunction · 0.85

Tested by

no test coverage detected