Source:NetHack 5.0.0/src/potion.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to potion.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/potion.c#line12]], for example.

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

1. /* NetHack 5.0	potion.c	$NHDT-Date: 1770949988 2026/02/12 18:33:08 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.279 $ */
2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3. /*-Copyright (c) Robert Patrick Rankin, 2013. */
4. /* NetHack may be freely redistributed.  See license for details. */
5. 
6. #include "hack.h"
7. 
8. staticfn long itimeout(long);
9. staticfn long itimeout_incr(long, int);
10. staticfn void ghost_from_bottle(void);
11. staticfn int drink_ok(struct obj *);
12. staticfn void peffect_restore_ability(struct obj *);
13. staticfn void peffect_hallucination(struct obj *);
14. staticfn void peffect_water(struct obj *);
15. staticfn void peffect_booze(struct obj *);
16. staticfn void peffect_enlightenment(struct obj *);
17. staticfn void peffect_invisibility(struct obj *);
18. staticfn void peffect_see_invisible(struct obj *);
19. staticfn void peffect_paralysis(struct obj *);
20. staticfn void peffect_sleeping(struct obj *);
21. staticfn int peffect_monster_detection(struct obj *);
22. staticfn int peffect_object_detection(struct obj *);
23. staticfn void peffect_sickness(struct obj *);
24. staticfn void peffect_confusion(struct obj *);
25. staticfn void peffect_gain_ability(struct obj *);
26. staticfn void peffect_speed(struct obj *);
27. staticfn void peffect_blindness(struct obj *);
28. staticfn void peffect_gain_level(struct obj *);
29. staticfn void peffect_healing(struct obj *);
30. staticfn void peffect_extra_healing(struct obj *);
31. staticfn void peffect_full_healing(struct obj *);
32. staticfn void peffect_levitation(struct obj *);
33. staticfn void peffect_gain_energy(struct obj *);
34. staticfn void peffect_oil(struct obj *);
35. staticfn void peffect_acid(struct obj *);
36. staticfn void peffect_polymorph(struct obj *);
37. staticfn boolean H2Opotion_dip(struct obj *, struct obj *, boolean,
38.                              const char *);
39. staticfn short mixtype(struct obj *, struct obj *);
40. staticfn int dip_ok(struct obj *);
41. staticfn int dip_hands_ok(struct obj *);
42. staticfn void hold_potion(struct obj *, const char *, const char *,
43.                         const char *);
44. staticfn void poof(struct obj *);
45. staticfn boolean dip_potion_explosion(struct obj *, int);
46. staticfn int potion_dip(struct obj *obj, struct obj *potion);
47. 
48. /* used to indicate whether quaff or dip has skipped an opportunity to
49.    use a fountain or such, in order to vary the feedback if hero lacks
50.    any potions [reinitialized every time it's used so does not need to
51.    be placed in struct instance_globals gd] */
52. static int drink_ok_extra = 0;
53. 
54. /* force `val' to be within valid range for intrinsic timeout value */
55. staticfn long
56. itimeout(long val)
57. {
58.     if (val >= TIMEOUT)
59.         val = TIMEOUT;
60.     else if (val < 1L)
61.         val = 0L;
62. 
63.     return val;
64. }
65. 
66. /* increment `old' by `incr' and force result to be valid intrinsic timeout */
67. staticfn long
68. itimeout_incr(long old, int incr)
69. {
70.     return itimeout((old & TIMEOUT) + (long) incr);
71. }
72. 
73. /* set the timeout field of intrinsic `which' */
74. void
75. set_itimeout(long *which, long val)
76. {
77.     *which &= ~TIMEOUT;
78.     *which |= itimeout(val);
79. }
80. 
81. /* increment the timeout field of intrinsic `which' */
82. void
83. incr_itimeout(long *which, int incr)
84. {
85.     set_itimeout(which, itimeout_incr(*which, incr));
86. }
87. 
88. void
89. make_confused(long xtime, boolean talk)
90. {
91.     long old = HConfusion;
92. 
93.     if (Unaware)
94.         talk = FALSE;
95. 
96.     if (!xtime && old) {
97.         if (talk)
98.             You_feel("less %s now.", Hallucination ? "trippy" : "confused");
99.     }
100.     if ((xtime && !old) || (!xtime && old))
101.         disp.botl = TRUE;
102. 
103.     set_itimeout(&HConfusion, xtime);
104. }
105. 
106. void
107. make_stunned(long xtime, boolean talk)
108. {
109.     long old = HStun;
110. 
111.     if (Unaware)
112.         talk = FALSE;
113. 
114.     if (!xtime && old) {
115.         if (talk)
116.             You_feel("%s now.",
117.                      Hallucination ? "less wobbly" : "a bit steadier");
118.     }
119.     if (xtime && !old) {
120.         if (talk) {
121.             if (u.usteed)
122.                 You("wobble in the saddle.");
123.             else
124.                 You("%s...", stagger(gy.youmonst.data, "stagger"));
125.         }
126.     }
127.     if ((!xtime && old) || (xtime && !old))
128.         disp.botl = TRUE;
129. 
130.     set_itimeout(&HStun, xtime);
131. }
132. 
133. /* Sick is overloaded with both fatal illness and food poisoning (via
134.    u.usick_type bit mask), but delayed killer can only support one or
135.    the other at a time.  They should become separate intrinsics.... */
136. void
137. make_sick(long xtime,
138.           const char *cause, /* sickness cause */
139.           boolean talk,
140.           int type)
141. {
142.     struct kinfo *kptr;
143.     long old = Sick;
144. 
145. #if 0   /* tell player even if hero is unconscious */
146.     if (Unaware)
147.         talk = FALSE;
148. #endif
149.     if (xtime > 0L) {
150.         if (Sick_resistance)
151.             return;
152.         if (!old) {
153.             /* newly sick */
154.             You_feel("deathly sick.");
155.         } else {
156.             /* already sick */
157.             if (talk)
158.                 You_feel("%s worse.", xtime <= Sick / 2L ? "much" : "even");
159.         }
160.         set_itimeout(&Sick, xtime);
161.         u.usick_type |= type;
162.         disp.botl = TRUE;
163.     } else if (old && (type & u.usick_type)) {
164.         /* was sick, now not */
165.         u.usick_type &= ~type;
166.         if (u.usick_type) { /* only partly cured */
167.             if (talk)
168.                 You_feel("somewhat better.");
169.             set_itimeout(&Sick, Sick * 2); /* approximation */
170.         } else {
171.             if (talk)
172.                 You_feel("cured.  What a relief!");
173.             Sick = 0L; /* set_itimeout(&Sick, 0L) */
174.         }
175.         disp.botl = TRUE;
176.     }
177. 
178.     kptr = find_delayed_killer(SICK);
179.     if (Sick) {
180.         exercise(A_CON, FALSE);
181.         /* setting delayed_killer used to be unconditional, but that's
182.            not right when make_sick(0) is called to cure food poisoning
183.            if hero was also fatally ill; this is only approximate */
184.         if (xtime || !old || !kptr) {
185.             int kpfx = ((cause && !strcmp(cause, "#wizintrinsic"))
186.                         ? KILLED_BY : KILLED_BY_AN);
187. 
188.             delayed_killer(SICK, kpfx, cause);
189.         }
190.     } else
191.         dealloc_killer(kptr);
192. }
193. 
194. void
195. make_slimed(long xtime, const char *msg)
196. {
197.     long old = Slimed;
198. 
199. #if 0   /* tell player even if hero is unconscious */
200.     if (Unaware)
201.         msg = 0;
202. #endif
203.     set_itimeout(&Slimed, xtime);
204.     if ((xtime != 0L) ^ (old != 0L)) {
205.         disp.botl = TRUE;
206.         if (msg)
207.             pline("%s", msg);
208.     }
209.     if (!Slimed) {
210.         dealloc_killer(find_delayed_killer(SLIMED));
211.         /* fake appearance is set late in turn-to-slime countdown */
212.         if (U_AP_TYPE == M_AP_MONSTER
213.             && gy.youmonst.mappearance == PM_GREEN_SLIME) {
214.             gy.youmonst.m_ap_type = M_AP_NOTHING;
215.             gy.youmonst.mappearance = 0;
216.         }
217.     }
218. }
219. 
220. /* start or stop petrification */
221. void
222. make_stoned(long xtime, const char *msg, int killedby, const char *killername)
223. {
224.     long old = Stoned;
225. 
226. #if 0   /* tell player even if hero is unconscious */
227.     if (Unaware)
228.         msg = 0;
229. #endif
230.     set_itimeout(&Stoned, xtime);
231.     if ((xtime != 0L) ^ (old != 0L)) {
232.         disp.botl = TRUE;
233.         if (msg)
234.             pline("%s", msg);
235.     }
236.     if (!Stoned)
237.         dealloc_killer(find_delayed_killer(STONED));
238.     else if (!old)
239.         delayed_killer(STONED, killedby, killername);
240. }
241. 
242. void
243. make_vomiting(long xtime, boolean talk)
244. {
245.     long old = Vomiting;
246. 
247.     if (Unaware)
248.         talk = FALSE;
249. 
250.     set_itimeout(&Vomiting, xtime);
251.     disp.botl = TRUE;
252.     if (!xtime && old)
253.         if (talk)
254.             You_feel("much less nauseated now.");
255. }
256. 
257. static const char vismsg[] = "vision seems to %s for a moment but is %s now.";
258. static const char eyemsg[] = "%s momentarily %s.";
259. 
260. void
261. make_blinded(long xtime, boolean talk)
262. {
263.     long old = BlindedTimeout;
264.     boolean u_could_see, can_see_now;
265.     const char *eyes;
266. 
267.     /* we probe ahead in case the Eyes of the Overworld
268.        are or will be overriding blindness */
269.     u_could_see = !Blind;
270.     set_itimeout(&HBlinded, xtime ? 1L : 0L);
271.     can_see_now = !Blind;
272.     set_itimeout(&HBlinded, old);
273. 
274.     if (Unaware)
275.         talk = FALSE;
276. 
277.     if (can_see_now && !u_could_see) { /* regaining sight */
278.         if (talk) {
279.             if (Hallucination)
280.                 pline("Far out!  Everything is all cosmic again!");
281.             else
282.                 You("can see again.");
283.         }
284.     } else if (old && !xtime) {
285.         /* clearing temporary blindness without toggling blindness */
286.         if (talk) {
287.             if (!haseyes(gy.youmonst.data) || PermaBlind) {
288.                 strange_feeling((struct obj *) 0, (char *) 0);
289.             } else if (Blindfolded) {
290.                 eyes = body_part(EYE);
291.                 if (eyecount(gy.youmonst.data) != 1)
292.                     eyes = makeplural(eyes);
293.                 Your(eyemsg, eyes, vtense(eyes, "itch"));
294.             } else { /* Eyes of the Overworld */
295.                 Your(vismsg, "brighten", Hallucination ? "sadder" : "normal");
296.             }
297.         }
298.     }
299. 
300.     if (u_could_see && !can_see_now) { /* losing sight */
301.         if (talk) {
302.             if (Hallucination)
303.                 pline("Oh, bummer!  Everything is dark!  Help!");
304.             else
305.                 pline("A cloud of darkness falls upon you.");
306.         }
307.         /* Before the hero goes blind, set the ball&chain variables. */
308.         if (Punished)
309.             set_bc(0);
310.     } else if (!old && xtime) {
311.         /* setting temporary blindness without toggling blindness */
312.         if (talk) {
313.             if (!haseyes(gy.youmonst.data) || PermaBlind) {
314.                 strange_feeling((struct obj *) 0, (char *) 0);
315.             } else if (Blindfolded) {
316.                 eyes = body_part(EYE);
317.                 if (eyecount(gy.youmonst.data) != 1)
318.                     eyes = makeplural(eyes);
319.                 Your(eyemsg, eyes, vtense(eyes, "twitch"));
320.             } else { /* Eyes of the Overworld */
321.                 Your(vismsg, "dim", Hallucination ? "happier" : "normal");
322.             }
323.         }
324.     }
325. 
326.     set_itimeout(&HBlinded, xtime);
327. 
328.     if (u_could_see ^ can_see_now) { /* one or the other but not both */
329.         toggle_blindness();
330.     }
331. }
332. 
333. /* blindness has just started or just ended--caller enforces that;
334.    called by Blindf_on(), Blindf_off(), and make_blinded() */
335. void
336. toggle_blindness(void)
337. {
338.     boolean Stinging = (uwep && (EWarn_of_mon & W_WEP) != 0L);
339. 
340.     /* blindness has just been toggled */
341.     disp.botl = TRUE; /* status conditions need update */
342.     gv.vision_full_recalc = 1; /* vision has changed */
343.     /* this vision recalculation used to be deferred until moveloop(),
344.        but that made it possible for vision irregularities to occur
345.        (cited case was force bolt hitting an adjacent potion of blindness
346.        and then a secret door; hero was blinded by vapors but then got the
347.        message "a door appears in the wall" because wall spot was IN_SIGHT) */
348.     vision_recalc(0);
349.     if (Blind_telepat || Infravision || Stinging)
350.         see_monsters(); /* also counts EWarn_of_mon monsters */
351.     /*
352.      * Avoid either of the sequences
353.      * "Sting starts glowing", [become blind], "Sting stops quivering" or
354.      * "Sting starts quivering", [regain sight], "Sting stops glowing"
355.      * by giving "Sting is quivering" when becoming blind or
356.      * "Sting is glowing" when regaining sight so that the eventual
357.      * "stops" message matches the most recent "Sting is ..." one.
358.      */
359.     if (Stinging)
360.         Sting_effects(-1);
361.     /* update dknown flag for inventory picked up while blind */
362.     if (!Blind)
363.         learn_unseen_invent();
364. }
365. 
366. DISABLE_WARNING_FORMAT_NONLITERAL
367. 
368. boolean
369. make_hallucinated(
370.     long xtime,   /* nonzero if this is an attempt to turn on hallucination */
371.     boolean talk,
372.     long mask)    /* nonzero if resistance status should change by mask */
373. {
374.     long old = HHallucination;
375.     boolean changed = 0;
376.     const char *message, *verb;
377. 
378.     if (Unaware)
379.         talk = FALSE;
380. 
381.     message = (!xtime) ? "Everything %s SO boring now."
382.                        : "Oh wow!  Everything %s so cosmic!";
383.     verb = (!Blind) ? "looks" : "feels";
384. 
385.     if (mask) {
386.         if (HHallucination)
387.             changed = TRUE;
388. 
389.         if (!xtime)
390.             EHalluc_resistance |= mask;
391.         else
392.             EHalluc_resistance &= ~mask;
393.     } else {
394.         if (!EHalluc_resistance && (!!HHallucination != !!xtime))
395.             changed = TRUE;
396.         set_itimeout(&HHallucination, xtime);
397. 
398.         /* clearing temporary hallucination without toggling vision */
399.         if (!changed && !HHallucination && old && talk) {
400.             if (!haseyes(gy.youmonst.data)) {
401.                 strange_feeling((struct obj *) 0, (char *) 0);
402.             } else if (Blind) {
403.                 const char *eyes = body_part(EYE);
404. 
405.                 if (eyecount(gy.youmonst.data) != 1)
406.                     eyes = makeplural(eyes);
407.                 Your(eyemsg, eyes, vtense(eyes, "itch"));
408.             } else { /* Grayswandir */
409.                 Your(vismsg, "flatten", "normal");
410.             }
411.         }
412.     }
413. 
414.     if (changed) {
415.         /* in case we're mimicking an orange (hallucinatory form
416.            of mimicking gold) update the mimicking's-over message */
417.         if (!Hallucination)
418.             eatmupdate();
419. 
420.         if (u.uswallow) {
421.             swallowed(0); /* redraw swallow display */
422.         } else {
423.             /* The see_* routines should be called *before* the pline. */
424.             see_monsters();
425.             see_objects();
426.             see_traps();
427.         }
428. 
429.         /* for perm_inv and anything similar
430.         (eg. Qt windowport's equipped items display) */
431.         update_inventory();
432. 
433.         disp.botl = TRUE;
434.         if (talk)
435.             pline(message, verb);
436.     }
437.     return changed;
438. }
439. 
440. RESTORE_WARNING_FORMAT_NONLITERAL
441. 
442. void
443. make_deaf(long xtime, boolean talk)
444. {
445.     long old = HDeaf;
446. 
447.     if (Unaware)
448.         talk = FALSE;
449. 
450.     set_itimeout(&HDeaf, xtime);
451.     if ((xtime != 0L) ^ (old != 0L)) {
452.         disp.botl = TRUE;
453.         if (talk)
454.             You(old && !Deaf ? "can hear again."
455.                              : "are unable to hear anything.");
456.     }
457. }
458. 
459. /* set or clear "slippery fingers" */
460. void
461. make_glib(int xtime)
462. {
463.     disp.botl |= (!Glib ^ !!xtime);
464.     set_itimeout(&Glib, xtime);
465.     /* may change "(being worn)" to "(being worn; slippery)" or vice versa */
466.     if (uarmg)
467.         update_inventory();
468. }
469. 
470. void
471. self_invis_message(void)
472. {
473.     pline("%s %s.",
474.           Hallucination ? "Far out, man!  You"
475.                         : "Gee!  All of a sudden, you",
476.           See_invisible ? "can see right through yourself"
477.                         : "can't see yourself");
478. }
479. 
480. staticfn void
481. ghost_from_bottle(void)
482. {
483.     struct monst *mtmp = makemon(&mons[PM_GHOST], u.ux, u.uy, MM_NOMSG);
484. 
485.     if (!mtmp) {
486.         pline("This bottle turns out to be empty.");
487.         return;
488.     }
489.     if (Blind) {
490.         pline("As you open the bottle, %s emerges.", something);
491.         return;
492.     }
493.     pline("As you open the bottle, an enormous %s emerges!",
494.           Hallucination ? rndmonnam(NULL) : (const char *) "ghost");
495.     if (flags.verbose)
496.         You("are frightened to death, and unable to move.");
497.     nomul(-3);
498.     gm.multi_reason = "being frightened to death";
499.     gn.nomovemsg = "You regain your composure.";
500. }
501. 
502. /* getobj callback for object to drink from, which also does double duty as
503.    the callback for dipping into (both just allow potions). */
504. staticfn int
505. drink_ok(struct obj *obj)
506. {
507.     /* getobj()'s callback to test whether hands/self is a valid "item" to
508.        pick is used here to communicate the fact that player has already
509.        passed up an opportunity to perform the action (drink or dip) on a
510.        non-inventory dungeon feature, so if there are no potions in invent
511.        the message will be "you have nothing /else/ to {drink | dip into}";
512.        if player used 'm' prefix to bypass dungeon features, drink_ok_extra
513.        will be 0 and the potential "else" will be omitted */
514.     if (!obj)
515.         return drink_ok_extra ? GETOBJ_EXCLUDE_NONINVENT : GETOBJ_EXCLUDE;
516. 
517.     if (obj->oclass == POTION_CLASS)
518.         return GETOBJ_SUGGEST;
519. 
520.     return GETOBJ_EXCLUDE;
521. }
522. 
523. /* "Quaffing is like drinking, except you spill more." - Terry Pratchett */
524. /* the #quaff command */
525. int
526. dodrink(void)
527. {
528.     struct obj *otmp;
529. 
530.     if (Strangled) {
531.         pline("If you can't breathe air, how can you drink liquid?");
532.         return ECMD_OK;
533.     }
534. 
535.     drink_ok_extra = 0;
536.     /* preceding 'q'/#quaff with 'm' skips the possibility of drinking
537.        from fountains, sinks, and surrounding water plus the prompting
538.        which those entail; optional for interactive use, essential for
539.        context-sensitive inventory item action 'quaff' */
540.     if (!iflags.menu_requested) {
541.         /* Is there a fountain to drink from here? */
542.         if (IS_FOUNTAIN(levl[u.ux][u.uy].typ)
543.             /* not as low as floor level but similar restrictions apply */
544.             && can_reach_floor(FALSE)) {
545.             if (y_n("Drink from the fountain?") == 'y') {
546.                 drinkfountain();
547.                 return ECMD_TIME;
548.             }
549.             ++drink_ok_extra;
550.         }
551.         /* Or a kitchen sink? */
552.         if (IS_SINK(levl[u.ux][u.uy].typ)
553.             /* not as low as floor level but similar restrictions apply */
554.             && can_reach_floor(FALSE)) {
555.             if (y_n("Drink from the sink?") == 'y') {
556.                 drinksink();
557.                 return ECMD_TIME;
558.             }
559.             ++drink_ok_extra;
560.         }
561.         /* Or are you surrounded by water? */
562.         if (Underwater && !u.uswallow) {
563.             if (y_n("Drink the water around you?") == 'y') {
564.                 pline("Do you know what lives in this water?");
565.                 return ECMD_TIME;
566.             }
567.             ++drink_ok_extra;
568.         }
569.     }
570. 
571.     otmp = getobj("drink", drink_ok, GETOBJ_NOFLAGS);
572.     if (!otmp)
573.         return ECMD_CANCEL;
574. 
575.     /*
576.      * 3.6:  quan > 1 used to be left to useup(), but we need to
577.      * force the current potion to be unworn, and don't want to do
578.      * that for the entire stack when starting with more than 1.
579.      * [Drinking a wielded potion of polymorph can trigger a shape
580.      * change which causes hero's weapon to be dropped.  In 3.4.x,
581.      * that led to an "object lost" panic since subsequent useup()
582.      * was no longer dealing with an inventory item.  Unwearing
583.      * the current potion is intended to keep it in inventory.]
584.      *
585.      * 5.0: switch back to relying on useup() unless the object is
586.      * actually worn.  Otherwise drinking a stack of unpaid potions
587.      * one by one in a shop makes each one a separate used-up item
588.      * for 'Ix' invent display and for itemized shop billing instead
589.      * of having a single stack with quantity greater than 1.
590.      */
591.     if (otmp->owornmask) {
592.         if (otmp->quan > 1L) {
593.             otmp = splitobj(otmp, 1L);
594.             otmp->owornmask = 0L; /* rest of original stack is unaffected */
595.         } else {
596.             remove_worn_item(otmp, FALSE);
597.         }
598.     }
599.     otmp->in_use = TRUE; /* you've opened the stopper */
600. 
601.     if (objdescr_is(otmp, "milky")
602.         && !(svm.mvitals[PM_GHOST].mvflags & G_GONE)
603.         && !rn2(POTION_OCCUPANT_CHANCE(svm.mvitals[PM_GHOST].born))) {
604.         ghost_from_bottle();
605.         useup(otmp);
606.         return ECMD_TIME;
607.     } else if (objdescr_is(otmp, "smoky")
608.                && !(svm.mvitals[PM_DJINNI].mvflags & G_GONE)
609.                && !rn2(POTION_OCCUPANT_CHANCE(svm.mvitals[PM_DJINNI].born))) {
610.         djinni_from_bottle(otmp);
611.         useup(otmp);
612.         return ECMD_TIME;
613.     }
614.     return dopotion(otmp);
615. }
616. 
617. int
618. dopotion(struct obj *otmp)
619. {
620.     int retval;
621. 
622.     otmp->in_use = TRUE;
623.     gp.potion_nothing = gp.potion_unkn = 0;
624.     if ((retval = peffects(otmp)) >= 0)
625.         return retval ? ECMD_TIME : ECMD_OK;
626. 
627.     if (gp.potion_nothing) {
628.         gp.potion_unkn++;
629.         You("have a %s feeling for a moment, then it passes.",
630.             Hallucination ? "normal" : "peculiar");
631.     }
632.     if (otmp->dknown && !objects[otmp->otyp].oc_name_known) {
633.         if (!gp.potion_unkn) {
634.             makeknown(otmp->otyp);
635.             more_experienced(0, 10);
636.         } else
637.             trycall(otmp);
638.     }
639.     useup(otmp);
640.     return ECMD_TIME;
641. }
642. 
643. /* potion or spell of restore ability; for spell, otmp is a temporary
644.    spellbook object that will be blessed if hero is skilled in healing */
645. staticfn void
646. peffect_restore_ability(struct obj *otmp)
647. {
648.     gp.potion_unkn++;
649.     if (otmp->cursed) {
650.         pline("Ulch!  This makes you feel mediocre!");
651.         return;
652.     } else {
653.         int i, ii;
654. 
655.         /* unlike unicorn horn, overrides Fixed_abil;
656.            does not recover temporary strength loss due to hunger
657.            or temporary dexterity loss due to wounded legs */
658.         pline("Wow!  This makes you feel %s!",
659.               (!otmp->blessed) ? "good"
660.               : unfixable_trouble_count(FALSE) ? "better"
661.                 : "great");
662.         i = rn2(A_MAX); /* start at a random point */
663.         for (ii = 0; ii < A_MAX; ii++) {
664.             int lim = AMAX(i);
665. 
666.             /* this used to adjust 'lim' for A_STR when u.uhs was
667.                WEAK or worse, but that's handled via ATEMP(A_STR) now */
668.             if (ABASE(i) < lim) {
669.                 ABASE(i) = lim;
670.                 /* reset stat abuse (but not exercise) to 0 as well */
671.                 AEXE(i) = max(AEXE(i), 0);
672. 
673.                 disp.botl = TRUE;
674.                 /* only first found if not blessed */
675.                 if (!otmp->blessed)
676.                     break;
677.             }
678.             if (++i >= A_MAX)
679.                 i = 0;
680.         }
681. 
682.         /* when using the potion (not the spell) also restore lost levels,
683.            to make the potion more worth keeping around for players with
684.            the spell or with a unihorn; this is better than full healing
685.            in that it can restore all of them, not just half, and a
686.            blessed potion restores them all at once */
687.         if (otmp->otyp == POT_RESTORE_ABILITY && u.ulevel < u.ulevelmax) {
688.             do {
689.                 pluslvl(FALSE);
690.             } while (u.ulevel < u.ulevelmax && otmp->blessed);
691.         }
692.     }
693. }
694. 
695. staticfn void
696. peffect_hallucination(struct obj *otmp)
697. {
698.     if (Halluc_resistance) {
699.         gp.potion_nothing++;
700.         return;
701.     } else if (Hallucination) {
702.         gp.potion_nothing++;
703.     }
704.     (void) make_hallucinated(itimeout_incr(HHallucination,
705.                                            rn1(200, 600 - 300 * bcsign(otmp))),
706.                              TRUE, 0L);
707.     if ((otmp->blessed && !rn2(3)) || (!otmp->cursed && !rn2(6))) {
708.         You("perceive yourself...");
709.         display_nhwindow(WIN_MESSAGE, FALSE);
710.         enlightenment(MAGICENLIGHTENMENT, ENL_GAMEINPROGRESS);
711.         Your("awareness re-normalizes.");
712.         exercise(A_WIS, TRUE);
713.     }
714. }
715. 
716. staticfn void
717. peffect_water(struct obj *otmp)
718. {
719.     if (!otmp->blessed && !otmp->cursed) {
720.         pline("This tastes like %s.", hliquid("water"));
721.         u.uhunger += rnd(10);
722.         newuhs(FALSE);
723.         return;
724.     }
725.     gp.potion_unkn++;
726.     if (mon_hates_blessings(&gy.youmonst) /* undead or demon */
727.         || u.ualign.type == A_CHAOTIC) {
728.         if (otmp->blessed) {
729.             pline("This burns like %s!", hliquid("acid"));
730.             exercise(A_CON, FALSE);
731.             if (ismnum(u.ulycn)) {
732.                 Your("affinity to %s disappears!",
733.                      makeplural(mons[u.ulycn].pmnames[NEUTRAL]));
734.                 if (gy.youmonst.data == &mons[u.ulycn])
735.                     you_unwere(FALSE);
736.                 set_ulycn(NON_PM); /* cure lycanthropy */
737.             }
738.             losehp(Maybe_Half_Phys(d(2, 6)), "potion of holy water",
739.                    KILLED_BY_AN);
740.         } else if (otmp->cursed) {
741.             You_feel("quite proud of yourself.");
742.             healup(d(2, 6), 0, 0, 0);
743.             if (ismnum(u.ulycn) && !Upolyd)
744.                 you_were();
745.             exercise(A_CON, TRUE);
746.         }
747.     } else {
748.         if (otmp->blessed) {
749.             You_feel("full of awe.");
750.             make_sick(0L, (char *) 0, TRUE, SICK_ALL);
751.             exercise(A_WIS, TRUE);
752.             exercise(A_CON, TRUE);
753.             if (ismnum(u.ulycn))
754.                 you_unwere(TRUE); /* "Purified" */
755.             /* make_confused(0L, TRUE); */
756.         } else {
757.             if (u.ualign.type == A_LAWFUL) {
758.                 pline("This burns like %s!", hliquid("acid"));
759.                 losehp(Maybe_Half_Phys(d(2, 6)), "potion of unholy water",
760.                        KILLED_BY_AN);
761.             } else
762.                 You_feel("full of dread.");
763.             if (ismnum(u.ulycn) && !Upolyd)
764.                 you_were();
765.             exercise(A_CON, FALSE);
766.         }
767.     }
768. }
769. 
770. staticfn void
771. peffect_booze(struct obj *otmp)
772. {
773.     gp.potion_unkn++;
774.     pline("Ooph!  This tastes like %s%s!",
775.           otmp->odiluted ? "watered down " : "",
776.           Hallucination ? "dandelion wine" : "liquid fire");
777.     if (!otmp->blessed) {
778.         /* booze hits harder if drinking on an empty stomach */
779.         make_confused(itimeout_incr(HConfusion, d(2 + u.uhs, 8)), FALSE);
780.     }
781.     /* the whiskey makes us feel better */
782.     if (!otmp->odiluted)
783.         healup(1, 0, FALSE, FALSE);
784.     u.uhunger += 10 * (2 + bcsign(otmp));
785.     newuhs(FALSE);
786.     exercise(A_WIS, FALSE);
787.     if (otmp->cursed) {
788.         You("pass out.");
789.         gm.multi = -rnd(15);
790.         gn.nomovemsg = "You awake with a headache.";
791.     }
792. }
793. 
794. staticfn void
795. peffect_enlightenment(struct obj *otmp)
796. {
797.     if (otmp->cursed) {
798.         gp.potion_unkn++;
799.         You("have an uneasy feeling...");
800.         exercise(A_WIS, FALSE);
801.     } else {
802.         if (otmp->blessed) {
803.             (void) adjattrib(A_INT, 1, FALSE);
804.             (void) adjattrib(A_WIS, 1, FALSE);
805.         }
806.         do_enlightenment_effect();
807.     }
808. }
809. 
810. staticfn void
811. peffect_invisibility(struct obj *otmp)
812. {
813.     boolean is_spell = (otmp->oclass == SPBOOK_CLASS);
814. 
815.     /* spell cannot penetrate mummy wrapping */
816.     if (is_spell && BInvis && uarmc->otyp == MUMMY_WRAPPING) {
817.         You_feel("rather itchy under %s.", yname(uarmc));
818.         return;
819.     }
820.     if (Invis || Blind || BInvis) {
821.         gp.potion_nothing++;
822.     } else {
823.         self_invis_message();
824.     }
825.     if (otmp->blessed && !rn2(HInvis ? 15 : 30))
826.         HInvis |= FROMOUTSIDE;
827.     else
828.         incr_itimeout(&HInvis, d(6 - 3 * bcsign(otmp), 100) + 100);
829.     newsym(u.ux, u.uy); /* update position */
830.     if (otmp->cursed) {
831.         pline("For some reason, you feel your presence is known.");
832.         aggravate();
833. 
834.         /* doing this gives temporary invisibility, but removes permanent
835.            invisibility */
836.         HInvis &= ~FROMOUTSIDE;
837.     }
838. }
839. 
840. staticfn void
841. peffect_see_invisible(struct obj *otmp)
842. {
843.     int msg = Invisible && !Blind;
844.     int permchance = 10 - (HInvis ? 3 : 0) - (HSee_invisible ? 6 : 0);
845. 
846.     gp.potion_unkn++;
847.     if (otmp->cursed)
848.         pline("Yecch!  This tastes %s.",
849.               Hallucination ? "overripe" : "rotten");
850.     else
851.         pline(
852.               Hallucination
853.               ? "This tastes like 10%% real %s%s all-natural beverage."
854.               : "This tastes like %s%s.",
855.               otmp->odiluted ? "reconstituted " : "", fruitname(TRUE));
856.     if (otmp->otyp == POT_FRUIT_JUICE) {
857.         u.uhunger += (otmp->odiluted ? 5 : 10) * (2 + bcsign(otmp));
858.         newuhs(FALSE);
859.         return;
860.     }
861.     if (!otmp->cursed) {
862.         /* Tell them they can see again immediately, which
863.          * will help them identify the potion...
864.          */
865.         make_blinded(0L, TRUE);
866.     }
867.     if (otmp->blessed && !rn2(permchance))
868.         HSee_invisible |= FROMOUTSIDE;
869.     else
870.         incr_itimeout(&HSee_invisible, rn1(100, 750));
871.     set_mimic_blocking(); /* do special mimic handling */
872.     see_monsters();       /* see invisible monsters */
873.     newsym(u.ux, u.uy);   /* see yourself! */
874.     if (msg && !Blind) {  /* Blind possible if polymorphed */
875.         You("can see through yourself, but you are visible!");
876.         gp.potion_unkn--;
877.     }
878. }
879. 
880. staticfn void
881. peffect_paralysis(struct obj *otmp)
882. {
883.     if (Free_action) {
884.         You("stiffen momentarily.");
885.     } else {
886.         if (Levitation || Is_airlevel(&u.uz) || Is_waterlevel(&u.uz))
887.             You("are motionlessly suspended.");
888.         else if (u.usteed)
889.             You("are frozen in place!");
890.         else
891.             Your("%s are frozen to the %s!", makeplural(body_part(FOOT)),
892.                  surface(u.ux, u.uy));
893.         nomul(-(rn1(10, 25 - 12 * bcsign(otmp))));
894.         gm.multi_reason = "frozen by a potion";
895.         gn.nomovemsg = You_can_move_again;
896.         exercise(A_DEX, FALSE);
897.     }
898. }
899. 
900. staticfn void
901. peffect_sleeping(struct obj *otmp)
902. {
903.     if (Sleep_resistance || Free_action) {
904.         monstseesu(M_SEEN_SLEEP);
905.         You("yawn.");
906.     } else {
907.         You("suddenly fall asleep!");
908.         monstunseesu(M_SEEN_SLEEP);
909.         fall_asleep(-rn1(10, 25 - 12 * bcsign(otmp)), TRUE);
910.     }
911. }
912. 
913. staticfn int
914. peffect_monster_detection(struct obj *otmp)
915. {
916.     if (otmp->blessed) {
917.         int i, x, y;
918. 
919.         if (Detect_monsters)
920.             gp.potion_nothing++;
921.         gp.potion_unkn++;
922.         /* after a while, repeated uses become less effective */
923.         if ((HDetect_monsters & TIMEOUT) >= 300L)
924.             i = 1;
925.         else if (otmp->oclass == SPBOOK_CLASS)
926.             i = rn1(40, 21);
927.         else /* potion */
928.             i = rn2(100) + 100;
929.         incr_itimeout(&HDetect_monsters, i);
930.         for (x = 1; x < COLNO; x++) {
931.             for (y = 0; y < ROWNO; y++) {
932.                 if (levl[x][y].glyph == GLYPH_INVISIBLE) {
933.                     unmap_object(x, y);
934.                     newsym(x, y);
935.                 }
936.                 if (MON_AT(x, y))
937.                     gp.potion_unkn = 0;
938.             }
939.         }
940.         /* if swallowed or underwater, fall through to uncursed case */
941.         if (!u.uswallow && !Underwater) {
942.             see_monsters();
943.             if (gp.potion_unkn)
944.                 You_feel("lonely.");
945.             return 0;
946.         }
947.     }
948.     if (monster_detect(otmp, 0))
949.         return 1; /* nothing detected */
950.     exercise(A_WIS, TRUE);
951.     return 0;
952. }
953. 
954. staticfn int
955. peffect_object_detection(struct obj *otmp)
956. {
957.     if (object_detect(otmp, 0))
958.         return 1; /* nothing detected */
959.     exercise(A_WIS, TRUE);
960.     return 0;
961. }
962. 
963. staticfn void
964. peffect_sickness(struct obj *otmp)
965. {
966.     pline("Yecch!  This stuff tastes like poison.");
967.     if (otmp->blessed) {
968.         pline("(But in fact it was mildly stale %s.)", fruitname(TRUE));
969.         if (!Role_if(PM_HEALER)) {
970.             /* NB: blessed otmp->fromsink is not possible */
971.             losehp(1, "mildly contaminated potion", KILLED_BY_AN);
972.         }
973.     } else {
974.         if (Poison_resistance)
975.             pline("(But in fact it was biologically contaminated %s.)",
976.                   fruitname(TRUE));
977.         if (Role_if(PM_HEALER)) {
978.             pline("Fortunately, you have been immunized.");
979.         } else {
980.             char contaminant[BUFSZ];
981.             int typ = rn2(A_MAX);
982. 
983.             Sprintf(contaminant, "%s%s",
984.                     (Poison_resistance) ? "mildly " : "",
985.                     (otmp->fromsink) ? "contaminated tap water"
986.                     : "contaminated potion");
987.             if (!Fixed_abil) {
988.                 poisontell(typ, FALSE);
989.                 (void) adjattrib(typ, Poison_resistance ? -1 : -rn1(4, 3),
990.                                  1);
991.             }
992.             if (!Poison_resistance) {
993.                 if (otmp->fromsink)
994.                     losehp(rnd(10) + 5 * !!(otmp->cursed), contaminant,
995.                            KILLED_BY);
996.                 else
997.                     losehp(rnd(10) + 5 * !!(otmp->cursed), contaminant,
998.                            KILLED_BY_AN);
999.             } else {
1000.                 /* rnd loss is so that unblessed poorer than blessed */
1001.                 losehp(1 + rn2(2), contaminant,
1002.                        (otmp->fromsink) ? KILLED_BY : KILLED_BY_AN);
1003.             }
1004.             exercise(A_CON, FALSE);
1005.         }
1006.     }
1007.     if (Hallucination) {
1008.         You("are shocked back to your senses!");
1009.         (void) make_hallucinated(0L, FALSE, 0L);
1010.     }
1011. }
1012. 
1013. staticfn void
1014. peffect_confusion(struct obj *otmp)
1015. {
1016.     if (!Confusion) {
1017.         if (Hallucination) {
1018.             pline("What a trippy feeling!");
1019.             gp.potion_unkn++;
1020.         } else
1021.             pline("Huh, What?  Where am I?");
1022.     } else
1023.         gp.potion_nothing++;
1024.     make_confused(itimeout_incr(HConfusion,
1025.                                 rn1(7, 16 - 8 * bcsign(otmp))),
1026.                   FALSE);
1027. }
1028. 
1029. staticfn void
1030. peffect_gain_ability(struct obj *otmp)
1031. {
1032.     if (otmp->cursed) {
1033.         pline("Ulch!  That potion tasted foul!");
1034.         gp.potion_unkn++;
1035.     } else if (Fixed_abil) {
1036.         gp.potion_nothing++;
1037.     } else {      /* If blessed, increase all; if not, try up to */
1038.         int itmp; /* 6 times to find one which can be increased. */
1039.         int ii, i = -1;   /* increment to 0 */
1040.         for (ii = A_MAX; ii > 0; ii--) {
1041.             i = (otmp->blessed ? i + 1 : rn2(A_MAX));
1042.             /* only give "your X is already as high as it can get"
1043.                message on last attempt (except blessed potions) */
1044.             itmp = (otmp->blessed || ii == 1) ? 0 : -1;
1045.             if (adjattrib(i, 1, itmp) && !otmp->blessed)
1046.                 break;
1047.         }
1048.     }
1049. }
1050. 
1051. staticfn void
1052. peffect_speed(struct obj *otmp)
1053. {
1054.     boolean is_speed = (otmp->otyp == POT_SPEED);
1055. 
1056.     /* skip when mounted; heal_legs() would heal steed's legs */
1057.     if (is_speed && Wounded_legs && !otmp->cursed && !u.usteed) {
1058.         heal_legs(0);
1059.         gp.potion_unkn++;
1060.         return;
1061.     }
1062. 
1063.     speed_up(rn1(10, 100 + 60 * bcsign(otmp)));
1064. 
1065.     /* non-cursed potion grants intrinsic speed */
1066.     if (is_speed && !otmp->cursed && !(HFast & INTRINSIC)) {
1067.         Your("quickness feels very natural.");
1068.         HFast |= FROMOUTSIDE;
1069.     }
1070. }
1071. 
1072. staticfn void
1073. peffect_blindness(struct obj *otmp)
1074. {
1075.     if (Blind || ((HBlinded || EBlinded) && BBlinded))
1076.         gp.potion_nothing++;
1077.     make_blinded(itimeout_incr(BlindedTimeout,
1078.                                rn1(200, 250 - 125 * bcsign(otmp))),
1079.                  (boolean) !Blind);
1080. }
1081. 
1082. staticfn void
1083. peffect_gain_level(struct obj *otmp)
1084. {
1085.     if (otmp->cursed) {
1086.         boolean on_lvl_1 = (ledger_no(&u.uz) == 1);
1087. 
1088.         gp.potion_unkn++;
1089.         /* they went up a level */
1090.         if (on_lvl_1 ? u.uhave.amulet : Can_rise_up(u.ux, u.uy, &u.uz)) {
1091.             int newlev;
1092.             d_level newlevel;
1093. 
1094.             if (on_lvl_1) {
1095.                 assign_level(&newlevel, &earth_level);
1096.             } else {
1097.                 newlev = depth(&u.uz) - 1;
1098.                 get_level(&newlevel, newlev);
1099.                 if (on_level(&newlevel, &u.uz)) {
1100.                     pline("It tasted bad.");
1101.                     return;
1102.                 }
1103.             }
1104.             You("rise up, through the %s!", ceiling(u.ux, u.uy));
1105.             goto_level(&newlevel, FALSE, FALSE, FALSE);
1106.         } else {
1107.             You("have an uneasy feeling.");
1108.         }
1109.         return;
1110.     }
1111.     pluslvl(FALSE);
1112.     /* blessed potions place you at a random spot in the
1113.        middle of the new level instead of the low point */
1114.     if (otmp->blessed)
1115.         u.uexp = rndexp(TRUE);
1116. }
1117. 
1118. staticfn void
1119. peffect_healing(struct obj *otmp)
1120. {
1121.     You_feel("better.");
1122.     healup(8 + d(4 + 2 * bcsign(otmp), 4), !otmp->cursed ? 1 : 0,
1123.            !!otmp->blessed, !otmp->cursed);
1124.     exercise(A_CON, TRUE);
1125. }
1126. 
1127. staticfn void
1128. peffect_extra_healing(struct obj *otmp)
1129. {
1130.     You_feel("much better.");
1131.     healup(16 + d(4 + 2 * bcsign(otmp), 8),
1132.            otmp->blessed ? 5 : !otmp->cursed ? 2 : 0, !otmp->cursed,
1133.            TRUE);
1134.     (void) make_hallucinated(0L, TRUE, 0L);
1135.     exercise(A_CON, TRUE);
1136.     exercise(A_STR, TRUE);
1137.     /* blessed potion also heals wounded legs unless riding (where leg
1138.        wounds apply to the steed rather than to the hero) */
1139.     if (Wounded_legs && (otmp->blessed && !u.usteed))
1140.         heal_legs(0);
1141. }
1142. 
1143. staticfn void
1144. peffect_full_healing(struct obj *otmp)
1145. {
1146.     You_feel("completely healed.");
1147.     healup(400, 4 + 4 * bcsign(otmp), !otmp->cursed, TRUE);
1148.     /* Restore one lost level if blessed */
1149.     if (otmp->blessed && u.ulevel < u.ulevelmax) {
1150.         /* when multiple levels have been lost, drinking
1151.            multiple potions will only get half of them back */
1152.         u.ulevelmax -= 1;
1153.         pluslvl(FALSE);
1154.     }
1155.     (void) make_hallucinated(0L, TRUE, 0L);
1156.     exercise(A_STR, TRUE);
1157.     exercise(A_CON, TRUE);
1158.     /* blessed potion heals wounded legs even when riding (so heals steed's
1159.        legs--it's magic); uncursed potion heals hero's legs unless riding */
1160.     if (Wounded_legs && (otmp->blessed || (!otmp->cursed && !u.usteed)))
1161.         heal_legs(0);
1162. }
1163. 
1164. staticfn void
1165. peffect_levitation(struct obj *otmp)
1166. {
1167.     /*
1168.      * BLevitation will be set if levitation is blocked due to being
1169.      * inside rock (currently or formerly in phazing xorn form, perhaps)
1170.      * but it doesn't prevent setting or incrementing Levitation timeout
1171.      * (which will take effect after escaping from the rock if it hasn't
1172.      * expired by then).
1173.      */
1174.     if (!Levitation && !BLevitation) {
1175.         /* kludge to ensure proper operation of float_up() */
1176.         set_itimeout(&HLevitation, 1L);
1177.         float_up();
1178.         /* This used to set timeout back to 0, then increment it below
1179.            for blessed and uncursed effects.  But now we leave it so
1180.            that cursed effect yields "you float down" on next turn.
1181.            Blessed and uncursed get one extra turn duration. */
1182.     } else /* already levitating, or can't levitate */
1183.         gp.potion_nothing++;
1184. 
1185.     if (otmp->cursed) {
1186.         stairway *stway;
1187. 
1188.         /* 'already levitating' used to block the cursed effect(s)
1189.            aside from ~I_SPECIAL; it was not clear whether that was
1190.            intentional; either way, it no longer does (as of 3.6.1) */
1191.         HLevitation &= ~I_SPECIAL; /* can't descend upon demand */
1192.         if (BLevitation) {
1193.             ; /* rising via levitation is blocked */
1194.         } else if ((stway = stairway_at(u.ux, u.uy)) != 0 && stway->up) {
1195.             (void) doup();
1196.             /* in case we're already Levitating, which would have
1197.                resulted in incrementing 'nothing' */
1198.             gp.potion_nothing = 0; /* not nothing after all */
1199.         } else if (has_ceiling(&u.uz)) {
1200.             int dmg = rnd(!uarmh ? 10 : !hard_helmet(uarmh) ? 6 : 3);
1201. 
1202.             You("hit your %s on the %s.", body_part(HEAD),
1203.                 ceiling(u.ux, u.uy));
1204.             losehp(Maybe_Half_Phys(dmg), "colliding with the ceiling",
1205.                    KILLED_BY);
1206.             gp.potion_nothing = 0; /* not nothing after all */
1207.         }
1208.     } else if (otmp->blessed) {
1209.         /* at this point, timeout is already at least 1 */
1210.         incr_itimeout(&HLevitation, rn1(50, 250));
1211.         /* can descend at will (stop levitating via '>') provided timeout
1212.            is the only factor (ie, not also wearing Lev ring or boots) */
1213.         HLevitation |= I_SPECIAL;
1214.     } else /* timeout is already at least 1 */
1215.         incr_itimeout(&HLevitation, rn1(140, 10));
1216. 
1217.     if (Levitation && IS_SINK(levl[u.ux][u.uy].typ))
1218.         spoteffects(FALSE);
1219.     /* levitating blocks flying */
1220.     float_vs_flight();
1221. }
1222. 
1223. staticfn void
1224. peffect_gain_energy(struct obj *otmp)
1225. {
1226.     int num;
1227. 
1228.     if (otmp->cursed)
1229.         You_feel("lackluster.");
1230.     else
1231.         pline("Magical energies course through your body.");
1232. 
1233.     /* old: num = rnd(5) + 5 * otmp->blessed + 1;
1234.      *      blessed:  +7..11 max & current (+9 avg)
1235.      *      uncursed: +2.. 6 max & current (+4 avg)
1236.      *      cursed:   -2.. 6 max & current (-4 avg)
1237.      * new: (3.6.0)
1238.      *      blessed:  +3..18 max (+10.5 avg), +9..54 current (+31.5 avg)
1239.      *      uncursed: +2..12 max (+ 7   avg), +6..36 current (+21   avg)
1240.      *      cursed:   -1.. 6 max (- 3.5 avg), -3..18 current (-10.5 avg)
1241.      */
1242.     num = d(otmp->blessed ? 3 : !otmp->cursed ? 2 : 1, 6);
1243.     if (otmp->cursed)
1244.         num = -num; /* subtract instead of add when cursed */
1245.     u.uenmax += num;
1246.     if (u.uenmax > u.uenpeak)
1247.         u.uenpeak = u.uenmax;
1248.     else if (u.uenmax <= 0)
1249.         u.uenmax = 0;
1250.     u.uen += 3 * num;
1251.     if (u.uen > u.uenmax)
1252.         u.uen = u.uenmax;
1253.     else if (u.uen <= 0)
1254.         u.uen = 0;
1255.     disp.botl = TRUE;
1256.     exercise(A_WIS, TRUE);
1257. }
1258. 
1259. staticfn void
1260. peffect_oil(struct obj *otmp)
1261. {
1262.     boolean good_for_you = FALSE, vulnerable;
1263. 
1264.     if (otmp->lamplit) {
1265.         if (likes_fire(gy.youmonst.data)) {
1266.             pline("Ahh, a refreshing drink.");
1267.             good_for_you = TRUE;
1268.         } else {
1269.             /*
1270.              * Note: if poly'd into green slime, hero ought to take
1271.              * extra damage, but drinking potions in that form isn't
1272.              * possible so there's no need to try to handle that.
1273.              */
1274.             You("burn your %s.", body_part(FACE));
1275.             /* fire damage */
1276.             vulnerable = !Fire_resistance || Cold_resistance;
1277.             losehp(d(vulnerable ? 4 : 2, 4),
1278.                    "quaffing a burning potion of oil",
1279.                    KILLED_BY);
1280.         }
1281.         /*
1282.          * This is slightly iffy because the burning isn't being
1283.          * spread across the body.  But the message is "the slime
1284.          * that covers you burns away" and having that follow
1285.          * "you burn your face" seems consistent enough.
1286.          */
1287.         burn_away_slime();
1288.     } else if (otmp->cursed) {
1289.         pline("This tastes like castor oil.");
1290.     } else {
1291.         pline("That was smooth!");
1292.     }
1293.     exercise(A_WIS, good_for_you);
1294. }
1295. 
1296. staticfn void
1297. peffect_acid(struct obj *otmp)
1298. {
1299.     if (Acid_resistance) {
1300.         /* Not necessarily a creature who _likes_ acid */
1301.         pline("This tastes %s.", Hallucination ? "tangy" : "sour");
1302.     } else {
1303.         int dmg;
1304. 
1305.         pline("This burns%s!",
1306.               otmp->blessed ? " a little" : otmp->cursed ? " a lot"
1307.                                                          : " like acid");
1308.         dmg = d(otmp->cursed ? 2 : 1, otmp->blessed ? 4 : 8);
1309.         losehp(Maybe_Half_Phys(dmg), "potion of acid", KILLED_BY_AN);
1310.         exercise(A_CON, FALSE);
1311.     }
1312.     if (Stoned)
1313.         fix_petrification();
1314.     gp.potion_unkn++; /* holy/unholy water can burn like acid too */
1315. }
1316. 
1317. staticfn void
1318. peffect_polymorph(struct obj *otmp)
1319. {
1320.     You_feel("a little %s.", Hallucination ? "normal" : "strange");
1321.     if (!Unchanging) {
1322.         if (!otmp->blessed || (u.umonnum != u.umonster))
1323.             polyself(POLY_NOFLAGS);
1324.         else {
1325.             polyself(POLY_CONTROLLED|POLY_LOW_CTRL);
1326.             if (u.mtimedone && u.umonnum != u.umonster)
1327.                 u.mtimedone = min(u.mtimedone, rn2(15) + 10);
1328.         }
1329.     }
1330. }
1331. 
1332. int
1333. peffects(struct obj *otmp)
1334. {
1335.     switch (otmp->otyp) {
1336.     case POT_RESTORE_ABILITY:
1337.     case SPE_RESTORE_ABILITY:
1338.         peffect_restore_ability(otmp);
1339.         break;
1340.     case POT_HALLUCINATION:
1341.         peffect_hallucination(otmp);
1342.         break;
1343.     case POT_WATER:
1344.         peffect_water(otmp);
1345.         break;
1346.     case POT_BOOZE:
1347.         peffect_booze(otmp);
1348.         break;
1349.     case POT_ENLIGHTENMENT:
1350.         peffect_enlightenment(otmp);
1351.         break;
1352.     case SPE_INVISIBILITY:
1353.     case POT_INVISIBILITY:
1354.         peffect_invisibility(otmp);
1355.         break;
1356.     case POT_SEE_INVISIBLE: /* tastes like fruit juice in Rogue */
1357.     case POT_FRUIT_JUICE:
1358.         peffect_see_invisible(otmp);
1359.         break;
1360.     case POT_PARALYSIS:
1361.         peffect_paralysis(otmp);
1362.         break;
1363.     case POT_SLEEPING:
1364.         peffect_sleeping(otmp);
1365.         break;
1366.     case POT_MONSTER_DETECTION:
1367.     case SPE_DETECT_MONSTERS:
1368.         if (peffect_monster_detection(otmp))
1369.             return 1;
1370.         break;
1371.     case POT_OBJECT_DETECTION:
1372.     case SPE_DETECT_TREASURE:
1373.         if (peffect_object_detection(otmp))
1374.             return 1;
1375.         break;
1376.     case POT_SICKNESS:
1377.         peffect_sickness(otmp);
1378.         break;
1379.     case POT_CONFUSION:
1380.         peffect_confusion(otmp);
1381.         break;
1382.     case POT_GAIN_ABILITY:
1383.         peffect_gain_ability(otmp);
1384.         break;
1385.     case POT_SPEED:
1386.     case SPE_HASTE_SELF:
1387.         peffect_speed(otmp);
1388.         break;
1389.     case POT_BLINDNESS:
1390.         peffect_blindness(otmp);
1391.         break;
1392.     case POT_GAIN_LEVEL:
1393.         peffect_gain_level(otmp);
1394.         break;
1395.     case POT_HEALING:
1396.         peffect_healing(otmp);
1397.         break;
1398.     case POT_EXTRA_HEALING:
1399.         peffect_extra_healing(otmp);
1400.         break;
1401.     case POT_FULL_HEALING:
1402.         peffect_full_healing(otmp);
1403.         break;
1404.     case POT_LEVITATION:
1405.     case SPE_LEVITATION:
1406.         peffect_levitation(otmp);
1407.         break;
1408.     case POT_GAIN_ENERGY: /* M. Stephenson */
1409.         peffect_gain_energy(otmp);
1410.         break;
1411.     case POT_OIL: /* P. Winner */
1412.         peffect_oil(otmp);
1413.         break;
1414.     case POT_ACID:
1415.         peffect_acid(otmp);
1416.         break;
1417.     case POT_POLYMORPH:
1418.         peffect_polymorph(otmp);
1419.         break;
1420.     default:
1421.         impossible("What a funny potion! (%u)", otmp->otyp);
1422.         return 0;
1423.     }
1424.     return -1;
1425. }
1426. 
1427. void
1428. healup(int nhp, int nxtra, boolean curesick, boolean cureblind)
1429. {
1430.     if (nhp) {
1431.         if (Upolyd) {
1432.             u.mh += nhp;
1433.             if (u.mh > u.mhmax)
1434.                 u.mh = (u.mhmax += nxtra);
1435.         } else {
1436.             u.uhp += nhp;
1437.             if (u.uhp > u.uhpmax) {
1438.                 u.uhp = (u.uhpmax += nxtra);
1439.                 if (u.uhpmax > u.uhppeak)
1440.                     u.uhppeak = u.uhpmax;
1441.             }
1442.         }
1443.     }
1444.     if (cureblind) {
1445.         /* 3.6.1: it's debatable whether healing magic should clean off
1446.            mundane 'dirt', but if it doesn't, blindness isn't cured */
1447.         u.ucreamed = 0;
1448.         make_blinded(0L, TRUE);
1449.         /* heal deafness too */
1450.         make_deaf(0L, TRUE);
1451.     }
1452.     if (curesick) {
1453.         make_vomiting(0L, TRUE);
1454.         make_sick(0L, (char *) 0, TRUE, SICK_ALL);
1455.     }
1456.     disp.botl = TRUE;
1457.     return;
1458. }
1459. 
1460. void
1461. strange_feeling(struct obj *obj, const char *txt)
1462. {
1463.     if (flags.beginner || !txt)
1464.         You("have a %s feeling for a moment, then it passes.",
1465.             Hallucination ? "normal" : "strange");
1466.     else
1467.         pline1(txt);
1468. 
1469.     if (!obj) /* e.g., crystal ball finds no traps */
1470.         return;
1471. 
1472.     if (obj->dknown)
1473.         trycall(obj);
1474. 
1475.     useup(obj);
1476. }
1477. 
1478. static const char *bottlenames[] = { "bottle", "phial", "flagon", "carafe",
1479.                               "flask",  "jar",   "vial" };
1480. static const char *hbottlenames[] = {
1481.     "jug", "pitcher", "barrel", "tin", "bag", "box", "glass", "beaker",
1482.     "tumbler", "vase", "flowerpot", "pan", "thingy", "mug", "teacup",
1483.     "teapot", "keg", "bucket", "thermos", "amphora", "wineskin", "parcel",
1484.     "bowl", "ampoule"
1485. };
1486. 
1487. const char *
1488. bottlename(void)
1489. {
1490.     if (Hallucination)
1491.         return ROLL_FROM(hbottlenames);
1492.     else
1493.         return ROLL_FROM(bottlenames);
1494. }
1495. 
1496. /* handle item dipped into water potion or steed saddle splashed by same */
1497. staticfn boolean
1498. H2Opotion_dip(
1499.     struct obj *potion,    /* water */
1500.     struct obj *targobj,   /* item being dipped into the water */
1501.     boolean useeit,        /* will hero see the glow/aura? */
1502.     const char *objphrase) /* "Your widget glows" or "Steed's saddle glows" */
1503. {
1504.     void (*func)(struct obj *) = (void (*)(struct obj *)) 0;
1505.     const char *glowcolor = 0;
1506. #define COST_alter (-2)
1507. #define COST_none (-1)
1508.     int costchange = COST_none;
1509.     boolean altfmt = FALSE, res = FALSE;
1510. 
1511.     if (!potion || potion->otyp != POT_WATER)
1512.         return FALSE;
1513. 
1514.     if (potion->blessed) {
1515.         if (targobj->cursed) {
1516.             func = uncurse;
1517.             glowcolor = NH_AMBER;
1518.             costchange = COST_UNCURS;
1519.         } else if (!targobj->blessed) {
1520.             func = bless;
1521.             glowcolor = NH_LIGHT_BLUE;
1522.             costchange = COST_alter;
1523.             altfmt = TRUE; /* "with a <color> aura" */
1524.         }
1525.     } else if (potion->cursed) {
1526.         if (targobj->blessed) {
1527.             func = unbless;
1528.             glowcolor = "brown";
1529.             costchange = COST_UNBLSS;
1530.         } else if (!targobj->cursed) {
1531.             func = curse;
1532.             glowcolor = NH_BLACK;
1533.             costchange = COST_alter;
1534.             altfmt = TRUE;
1535.         }
1536.     } else {
1537.         /* dipping into uncursed water; carried() check skips steed saddle */
1538.         if (carried(targobj)) {
1539.             gm.mentioned_water = FALSE; /* water_damage() might set this */
1540.             if (water_damage(targobj, 0, TRUE) != ER_NOTHING)
1541.                 res = TRUE;
1542.             if (gm.mentioned_water)
1543.                 makeknown(POT_WATER);
1544.             gm.mentioned_water = FALSE;
1545.         }
1546.     }
1547.     if (func) {
1548.         /* give feedback before altering the target object;
1549.            this used to set obj->bknown even when not seeing
1550.            the effect; now hero has to see the glow, and bknown
1551.            is cleared instead of set if perception is distorted */
1552.         if (useeit) {
1553.             glowcolor = hcolor(glowcolor);
1554.             if (altfmt)
1555.                 pline("%s with %s aura.", objphrase, an(glowcolor));
1556.             else
1557.                 pline("%s %s.", objphrase, glowcolor);
1558.             iflags.last_msg = PLNMSG_OBJ_GLOWS;
1559.             targobj->bknown = !Hallucination;
1560.         } else {
1561.             /* didn't see what happened:  forget the BUC state if that was
1562.                known unless the bless/curse state of the water is known;
1563.                without this, hero would know the new state even without
1564.                seeing the glow; priest[ess] will immediately relearn it */
1565.             if (!potion->bknown || !potion->dknown)
1566.                 targobj->bknown = 0;
1567.             /* [should the bknown+dknown exception require that water
1568.                be discovered or at least named?] */
1569.         }
1570.         /* potions of water are the only shop goods whose price depends
1571.            on their curse/bless state */
1572.         if (targobj->unpaid && targobj->otyp == POT_WATER) {
1573.             if (costchange == COST_alter)
1574.                 /* added blessing or cursing; update shop
1575.                    bill to reflect item's new higher price */
1576.                 alter_cost(targobj, 0L);
1577.             else if (costchange != COST_none)
1578.                 /* removed blessing or cursing; you
1579.                    degraded it, now you'll have to buy it... */
1580.                 costly_alteration(targobj, costchange);
1581.         }
1582.         /* finally, change curse/bless state */
1583.         (*func)(targobj);
1584.         res = TRUE;
1585.     }
1586.     return res;
1587. #undef COST_alter
1588. #undef COST_none
1589. }
1590. 
1591. /* used when blessed or cursed scroll of light interacts with artifact light;
1592.    if the lit object (Sunsword or gold dragon scales/mail) doesn't resist,
1593.    treat like dipping it in holy or unholy water (BUC change, glow message) */
1594. void
1595. impact_arti_light(
1596.     struct obj *obj, /* wielded Sunsword or worn gold dragon scales/mail */
1597.     boolean worsen,  /* True: lower BUC state unless already cursed;
1598.                       * False: raise BUC state unless already blessed */
1599.     boolean seeit)   /* True: give "<obj> glows <color>" message */
1600. {
1601.     struct obj *otmp;
1602. 
1603.     /* if already worst/best BUC it can be, or if it resists, do nothing */
1604.     if ((worsen ? obj->cursed : obj->blessed) || obj_resists(obj, 25, 75))
1605.         return;
1606. 
1607.     /* curse() and bless() take care of maybe_adjust_light() */
1608.     otmp = mksobj(POT_WATER, TRUE, FALSE);
1609.     if (worsen)
1610.         curse(otmp);
1611.     else
1612.         bless(otmp);
1613.     H2Opotion_dip(otmp, obj, seeit, seeit ? Yobjnam2(obj, "glow") : "");
1614.     dealloc_obj(otmp);
1615. #if 0   /* defer this until caller has used up the scroll so it won't be
1616.          * visible; player was told that it disappeared as hero read it */
1617.     if (carried(obj)) /* carried() will always be True here */
1618.         update_inventory();
1619. #endif
1620.     return;
1621. }
1622. 
1623. /* potion obj hits monster mon, which might be youmonst; obj always used up */
1624. void
1625. potionhit(struct monst *mon, struct obj *obj, int how)
1626. {
1627.     const char *botlnam = bottlename();
1628.     boolean isyou = (mon == &gy.youmonst);
1629.     int distance, tx, ty;
1630.     struct obj *saddle = (struct obj *) 0;
1631.     boolean hit_saddle = FALSE, your_fault = (how <= POTHIT_HERO_THROW);
1632. 
1633.     if (isyou) {
1634.         tx = u.ux, ty = u.uy;
1635.         distance = 0;
1636.         pline_The("%s crashes on your %s and breaks into shards.", botlnam,
1637.                   body_part(HEAD));
1638.         losehp(Maybe_Half_Phys(rnd(2)),
1639.                (how == POTHIT_OTHER_THROW) ? "propelled potion" /* scatter */
1640.                                            : "thrown potion",
1641.                KILLED_BY_AN);
1642.     } else {
1643.         tx = mon->mx, ty = mon->my;
1644.         /* sometimes it hits the saddle */
1645.         if (((mon->misc_worn_check & W_SADDLE)
1646.              && (saddle = which_armor(mon, W_SADDLE)))
1647.             && (!rn2(10)
1648.                 || (obj->otyp == POT_WATER
1649.                     && ((rnl(10) > 7 && obj->cursed)
1650.                         || (rnl(10) < 4 && obj->blessed) || !rn2(3)))))
1651.             hit_saddle = TRUE;
1652.         distance = distu(tx, ty);
1653.         if (!cansee(tx, ty)) {
1654.             Soundeffect(se_potion_crash_and_break, 60);
1655.             pline("Crash!");
1656.         } else {
1657.             char *mnam = mon_nam(mon);
1658.             char buf[BUFSZ];
1659. 
1660.             if (hit_saddle && saddle) {
1661.                 Sprintf(buf, "%s saddle",
1662.                         s_suffix(x_monnam(mon, ARTICLE_THE, (char *) 0,
1663.                                           (SUPPRESS_IT | SUPPRESS_SADDLE),
1664.                                           FALSE)));
1665.             } else if (has_head(mon->data)) {
1666.                 Sprintf(buf, "%s %s", s_suffix(mnam),
1667.                         (gn.notonhead ? "body" : "head"));
1668.             } else {
1669.                 Strcpy(buf, mnam);
1670.             }
1671.             Soundeffect(se_potion_crash_and_break, 60);
1672.             pline_The("%s crashes on %s and breaks into shards.", botlnam,
1673.                       buf);
1674.         }
1675.         if (rn2(5) && mon->mhp > 1 && !hit_saddle)
1676.             mon->mhp--;
1677.     }
1678. 
1679.     /* oil doesn't instantly evaporate; Neither does a saddle hit */
1680.     if (obj->otyp != POT_OIL && !hit_saddle && cansee(tx, ty))
1681.         pline("%s.", Tobjnam(obj, "evaporate"));
1682. 
1683.     if (isyou) {
1684.         switch (obj->otyp) {
1685.         case POT_OIL:
1686.             if (obj->lamplit)
1687.                 explode_oil(obj, u.ux, u.uy);
1688.             break;
1689.         case POT_POLYMORPH:
1690.             You_feel("a little %s.", Hallucination ? "normal" : "strange");
1691.             if (!Unchanging && !Antimagic)
1692.                 polyself(POLY_NOFLAGS);
1693.             break;
1694.         case POT_ACID:
1695.             if (!Acid_resistance) {
1696.                 int dmg;
1697. 
1698.                 pline("This burns%s!",
1699.                       obj->blessed ? " a little"
1700.                                    : obj->cursed ? " a lot" : "");
1701.                 dmg = d(obj->cursed ? 2 : 1, obj->blessed ? 4 : 8);
1702.                 losehp(Maybe_Half_Phys(dmg), "potion of acid", KILLED_BY_AN);
1703.             }
1704.             break;
1705.         }
1706.     } else if (hit_saddle && saddle) {
1707.         char *mnam, buf[BUFSZ], saddle_glows[BUFSZ];
1708.         boolean affected = FALSE;
1709.         boolean useeit = !Blind && canseemon(mon) && cansee(tx, ty);
1710. 
1711.         mnam = x_monnam(mon, ARTICLE_THE, (char *) 0,
1712.                         (SUPPRESS_IT | SUPPRESS_SADDLE), FALSE);
1713.         Sprintf(buf, "%s", upstart(s_suffix(mnam)));
1714. 
1715.         switch (obj->otyp) {
1716.         case POT_WATER:
1717.             Snprintf(saddle_glows, sizeof(saddle_glows), "%s %s",
1718.                      buf, aobjnam(saddle, "glow"));
1719.             affected = H2Opotion_dip(obj, saddle, useeit, saddle_glows);
1720.             break;
1721.         case POT_POLYMORPH:
1722.             /* Do we allow the saddle to polymorph? */
1723.             break;
1724.         }
1725.         if (useeit && !affected)
1726.             pline("%s %s wet.", buf, aobjnam(saddle, "get"));
1727.     } else {
1728.         boolean angermon = your_fault, cureblind = FALSE;
1729. 
1730.         switch (obj->otyp) {
1731.         case POT_FULL_HEALING:
1732.             cureblind = TRUE;
1733.             FALLTHROUGH;
1734.             /*FALLTHRU*/
1735.         case POT_EXTRA_HEALING:
1736.             if (!obj->cursed)
1737.                 cureblind = TRUE;
1738.             FALLTHROUGH;
1739.             /*FALLTHRU*/
1740.         case POT_HEALING:
1741.             if (obj->blessed)
1742.                 cureblind = TRUE;
1743.             if (mon->data == &mons[PM_PESTILENCE])
1744.                 goto do_illness;
1745.             FALLTHROUGH;
1746.             /*FALLTHRU*/
1747.         case POT_RESTORE_ABILITY:
1748.         case POT_GAIN_ABILITY:
1749.  do_healing:
1750.             angermon = FALSE;
1751.             if (mon->mhp < mon->mhpmax) {
1752.                 healmon(mon, mon->mhpmax, 0);
1753.                 if (canseemon(mon))
1754.                     pline("%s looks sound and hale again.", Monnam(mon));
1755.             }
1756.             if (cureblind)
1757.                 mcureblindness(mon, canseemon(mon));
1758.             break;
1759.         case POT_SICKNESS:
1760.             if (mon->data == &mons[PM_PESTILENCE])
1761.                 goto do_healing;
1762.             if (dmgtype(mon->data, AD_DISE)
1763.                 /* won't happen, see prior goto */
1764.                 || dmgtype(mon->data, AD_PEST)
1765.                 /* most common case */
1766.                 || resists_poison(mon)) {
1767.                 if (canseemon(mon))
1768.                     pline("%s looks unharmed.", Monnam(mon));
1769.                 break;
1770.             }
1771.  do_illness:
1772.             if (mon->mhp > 2) {
1773.                 mon->mhp /= 2;
1774.                 if (canseemon(mon))
1775.                     pline("%s looks rather ill.", Monnam(mon));
1776.             }
1777.             break;
1778.         case POT_CONFUSION:
1779.         case POT_BOOZE:
1780.             if (!resist(mon, POTION_CLASS, 0, NOTELL))
1781.                 mon->mconf = TRUE;
1782.             break;
1783.         case POT_INVISIBILITY: {
1784.             boolean sawit = canspotmon(mon),
1785.                     cursed_potion = obj->cursed ? TRUE : FALSE;
1786. 
1787.             angermon = mon->minvis && cursed_potion;
1788.             mon_set_minvis(mon, cursed_potion);
1789.             if (sawit && !canspotmon(mon)) {
1790.                 if (cansee(mon->mx, mon->my))
1791.                     map_invisible(mon->mx, mon->my);
1792.             } else if (sawit && cursed_potion) {
1793.                 pline("%s briefly seems to be transparent.", Monnam(mon));
1794.                 /* see use_misc(muse.c) for comment about map_invisible() */
1795.             } else if (!sawit && canspotmon(mon)) {
1796.                 /* if an invisible mon glyph was present, mon_set_minvis()'s
1797.                    newsym() has gotten rid of it */
1798.                 pline("%s appears!", Monnam(mon));
1799.             }
1800.             break;
1801.         }
1802.         case POT_SLEEPING:
1803.             /* wakeup() doesn't rouse victims of temporary sleep */
1804.             if (sleep_monst(mon, rnd(12), POTION_CLASS)) {
1805.                 pline("%s falls asleep.", Monnam(mon));
1806.                 slept_monst(mon);
1807.             }
1808.             break;
1809.         case POT_PARALYSIS:
1810.             if (mon->mcanmove) {
1811.                 /* really should be rnd(5) for consistency with players
1812.                  * breathing potions, but...
1813.                  */
1814.                 paralyze_monst(mon, rnd(25));
1815.             }
1816.             break;
1817.         case POT_SPEED:
1818.             angermon = FALSE;
1819.             mon_adjust_speed(mon, 1, obj);
1820.             break;
1821.         case POT_BLINDNESS:
1822.             if (haseyes(mon->data) && !mon_perma_blind(mon)) {
1823.                 int btmp = 64 + rn2(32)
1824.                             + rn2(32) * !resist(mon, POTION_CLASS, 0, NOTELL);
1825. 
1826.                 btmp += mon->mblinded;
1827.                 mon->mblinded = min(btmp, 127);
1828.                 mon->mcansee = 0;
1829.             }
1830.             break;
1831.         case POT_WATER:
1832.             if (mon_hates_blessings(mon) /* undead or demon */
1833.                 || is_were(mon->data) || is_vampshifter(mon)) {
1834.                 if (obj->blessed) {
1835.                     pline("%s %s in pain!", Monnam(mon),
1836.                           is_silent(mon->data) ? "writhes" : "shrieks");
1837.                     if (!is_silent(mon->data))
1838.                         wake_nearto(tx, ty, mon->data->mlevel * 10);
1839.                     mon->mhp -= d(2, 6);
1840.                     /* should only be by you */
1841.                     if (DEADMONSTER(mon))
1842.                         killed(mon);
1843.                     else if (is_were(mon->data) && !is_human(mon->data))
1844.                         new_were(mon); /* revert to human */
1845.                 } else if (obj->cursed) {
1846.                     angermon = FALSE;
1847.                     if (canseemon(mon))
1848.                         pline("%s looks healthier.", Monnam(mon));
1849.                     healmon(mon, d(2, 6), 0);
1850.                     if (is_were(mon->data) && is_human(mon->data)
1851.                         && !Protection_from_shape_changers)
1852.                         new_were(mon); /* transform into beast */
1853.                 }
1854.             } else if (mon->data == &mons[PM_GREMLIN]) {
1855.                 angermon = FALSE;
1856.                 (void) split_mon(mon, (struct monst *) 0);
1857.             } else if (mon->data == &mons[PM_IRON_GOLEM]) {
1858.                 if (canseemon(mon))
1859.                     pline("%s rusts.", Monnam(mon));
1860.                 mon->mhp -= d(1, 6);
1861.                 /* should only be by you */
1862.                 if (DEADMONSTER(mon))
1863.                     killed(mon);
1864.             }
1865.             break;
1866.         case POT_OIL:
1867.             if (obj->lamplit)
1868.                 explode_oil(obj, tx, ty);
1869.             break;
1870.         case POT_ACID:
1871.             if (!resists_acid(mon) && !resist(mon, POTION_CLASS, 0, NOTELL)) {
1872.                 pline("%s %s in pain!", Monnam(mon),
1873.                       is_silent(mon->data) ? "writhes" : "shrieks");
1874.                 if (!is_silent(mon->data))
1875.                     wake_nearto(tx, ty, mon->data->mlevel * 10);
1876.                 mon->mhp -= d(obj->cursed ? 2 : 1, obj->blessed ? 4 : 8);
1877.                 if (DEADMONSTER(mon)) {
1878.                     if (your_fault)
1879.                         killed(mon);
1880.                     else
1881.                         monkilled(mon, "", AD_ACID);
1882.                 }
1883.             }
1884.             break;
1885.         case POT_POLYMORPH:
1886.             (void) bhitm(mon, obj);
1887.             break;
1888.         /*
1889.         case POT_GAIN_LEVEL:
1890.         case POT_LEVITATION:
1891.         case POT_FRUIT_JUICE:
1892.         case POT_MONSTER_DETECTION:
1893.         case POT_OBJECT_DETECTION:
1894.             break;
1895.         */
1896.         }
1897.         /* target might have been killed */
1898.         if (!DEADMONSTER(mon)) {
1899.             if (angermon)
1900.                 wakeup(mon, TRUE);
1901.             else
1902.                 mon->msleeping = 0;
1903.         }
1904.     }
1905. 
1906.     /* Note: potionbreathe() does its own docall() */
1907.     if ((distance == 0 || (distance < 3 && !rn2((1+ACURR(A_DEX))/2)))
1908.         && (!breathless(gy.youmonst.data) || haseyes(gy.youmonst.data)))
1909.         potionbreathe(obj);
1910.     else if (obj->dknown && cansee(tx, ty))
1911.         trycall(obj);
1912. 
1913.     if (*u.ushops && obj->unpaid) {
1914.         struct monst *shkp = shop_keeper(*in_rooms(u.ux, u.uy, SHOPBASE));
1915. 
1916.         /* neither of the first two cases should be able to happen;
1917.            only the hero should ever have an unpaid item, and only
1918.            when inside a tended shop */
1919.         if (!shkp) /* if shkp was killed, unpaid ought to cleared already */
1920.             obj->unpaid = 0;
1921.         else if (svc.context.mon_moving) /* obj thrown by monster */
1922.             subfrombill(obj, shkp);
1923.         else /* obj thrown by hero */
1924.             (void) stolen_value(obj, u.ux, u.uy, (boolean) shkp->mpeaceful,
1925.                                 FALSE);
1926.     }
1927.     obfree(obj, (struct obj *) 0);
1928. }
1929. 
1930. /* vapors are inhaled or get in your eyes */
1931. void
1932. potionbreathe(struct obj *obj)
1933. {
1934.     int i, ii, isdone, kn = 0;
1935.     boolean cureblind = FALSE;
1936.     unsigned already_in_use = obj->in_use;
1937. 
1938.     /* potion of unholy water might be wielded; prevent
1939.        you_were() -> drop_weapon() from dropping it so that it
1940.        remains in inventory where our caller expects it to be */
1941.     obj->in_use = 1;
1942. 
1943.     /* wearing a wet towel protects both eyes and breathing, even when
1944.        the breath effect might be beneficial; we still pass down to the
1945.        naming opportunity in case potion was thrown at hero by a monster */
1946.     switch (Half_gas_damage ? TOWEL : obj->otyp) {
1947.     case TOWEL:
1948.         pline("Some vapor passes harmlessly around you.");
1949.         break;
1950.     case POT_RESTORE_ABILITY:
1951.     case POT_GAIN_ABILITY:
1952.         if (obj->cursed) {
1953.             if (!breathless(gy.youmonst.data)) {
1954.                 pline("Ulch!  That potion smells terrible!");
1955.             } else if (haseyes(gy.youmonst.data)) {
1956.                 const char *eyes = body_part(EYE);
1957. 
1958.                 if (eyecount(gy.youmonst.data) != 1)
1959.                     eyes = makeplural(eyes);
1960.                 Your("%s %s!", eyes, vtense(eyes, "sting"));
1961.             }
1962.             break;
1963.         } else {
1964.             i = rn2(A_MAX); /* start at a random point */
1965.             for (isdone = ii = 0; !isdone && ii < A_MAX; ii++) {
1966.                 if (ABASE(i) < AMAX(i)) {
1967.                     ABASE(i)++;
1968.                     /* only first found if not blessed */
1969.                     isdone = !(obj->blessed);
1970.                     disp.botl = TRUE;
1971.                 }
1972.                 if (++i >= A_MAX)
1973.                     i = 0;
1974.             }
1975.         }
1976.         break;
1977.     case POT_FULL_HEALING:
1978.         if (Upolyd && u.mh < u.mhmax)
1979.             u.mh++, disp.botl = TRUE;
1980.         if (u.uhp < u.uhpmax)
1981.             u.uhp++, disp.botl = TRUE;
1982.         cureblind = TRUE;
1983.         FALLTHROUGH;
1984.         /*FALLTHRU*/
1985.     case POT_EXTRA_HEALING:
1986.         if (Upolyd && u.mh < u.mhmax)
1987.             u.mh++, disp.botl = TRUE;
1988.         if (u.uhp < u.uhpmax)
1989.             u.uhp++, disp.botl = TRUE;
1990.         if (!obj->cursed)
1991.             cureblind = TRUE;
1992.         FALLTHROUGH;
1993.         /*FALLTHRU*/
1994.     case POT_HEALING:
1995.         if (Upolyd && u.mh < u.mhmax)
1996.             u.mh++, disp.botl = TRUE;
1997.         if (u.uhp < u.uhpmax)
1998.             u.uhp++, disp.botl = TRUE;
1999.         if (obj->blessed)
2000.             cureblind = TRUE;
2001.         if (cureblind) {
2002.             make_blinded(0L, !u.ucreamed);
2003.             make_deaf(0L, TRUE);
2004.         }
2005.         exercise(A_CON, TRUE);
2006.         break;
2007.     case POT_SICKNESS:
2008.         if (!Role_if(PM_HEALER)) {
2009.             if (Upolyd) {
2010.                 if (u.mh <= 5)
2011.                     u.mh = 1;
2012.                 else
2013.                     u.mh -= 5;
2014.             } else {
2015.                 if (u.uhp <= 5)
2016.                     u.uhp = 1;
2017.                 else
2018.                     u.uhp -= 5;
2019.             }
2020.             disp.botl = TRUE;
2021.             exercise(A_CON, FALSE);
2022.         }
2023.         break;
2024.     case POT_HALLUCINATION:
2025.         You("have a momentary vision.");
2026.         break;
2027.     case POT_CONFUSION:
2028.     case POT_BOOZE:
2029.         if (!Confusion)
2030.             You_feel("somewhat dizzy.");
2031.         make_confused(itimeout_incr(HConfusion, rnd(5)), FALSE);
2032.         break;
2033.     case POT_INVISIBILITY:
2034.         if (!Blind && !Invis) {
2035.             kn++;
2036.             pline("For an instant you %s!",
2037.                   See_invisible ? "could see right through yourself"
2038.                                 : "couldn't see yourself");
2039.         }
2040.         break;
2041.     case POT_PARALYSIS:
2042.         kn++;
2043.         if (!Free_action) {
2044.             pline("%s seems to be holding you.", Something);
2045.             nomul(-rnd(5));
2046.             gm.multi_reason = "frozen by a potion";
2047.             gn.nomovemsg = You_can_move_again;
2048.             exercise(A_DEX, FALSE);
2049.         } else
2050.             You("stiffen momentarily.");
2051.         break;
2052.     case POT_SLEEPING:
2053.         kn++;
2054.         if (!Free_action && !Sleep_resistance) {
2055.             You_feel("rather tired.");
2056.             nomul(-rnd(5));
2057.             gm.multi_reason = "sleeping off a magical draught";
2058.             gn.nomovemsg = You_can_move_again;
2059.             exercise(A_DEX, FALSE);
2060.         } else {
2061.             You("yawn.");
2062.             monstseesu(M_SEEN_SLEEP);
2063.         }
2064.         break;
2065.     case POT_SPEED:
2066.         if (!Fast)
2067.             Your("knees seem more flexible now.");
2068.         incr_itimeout(&HFast, rnd(5));
2069.         exercise(A_DEX, TRUE);
2070.         break;
2071.     case POT_BLINDNESS:
2072.         if (!Blind && !Unaware) {
2073.             kn++;
2074.             pline("It suddenly gets dark.");
2075.         }
2076.         make_blinded(itimeout_incr(BlindedTimeout, rnd(5)), FALSE);
2077.         if (!Blind && !Unaware)
2078.             Your1(vision_clears);
2079.         break;
2080.     case POT_WATER:
2081.         if (u.umonnum == PM_GREMLIN) {
2082.             (void) split_mon(&gy.youmonst, (struct monst *) 0);
2083.         } else if (ismnum(u.ulycn)) {
2084.             /* vapor from [un]holy water will trigger
2085.                transformation but won't cure lycanthropy */
2086.             if (obj->blessed && gy.youmonst.data == &mons[u.ulycn])
2087.                 you_unwere(FALSE);
2088.             else if (obj->cursed && !Upolyd)
2089.                 you_were();
2090.         }
2091.         break;
2092.     case POT_ACID:
2093.     case POT_POLYMORPH:
2094.         exercise(A_CON, FALSE);
2095.         break;
2096.     /*
2097.     case POT_GAIN_LEVEL:
2098.     case POT_GAIN_ENERGY:
2099.     case POT_LEVITATION:
2100.     case POT_FRUIT_JUICE:
2101.     case POT_MONSTER_DETECTION:
2102.     case POT_OBJECT_DETECTION:
2103.     case POT_OIL:
2104.         break;
2105.      */
2106.     }
2107. 
2108.     if (!already_in_use)
2109.         obj->in_use = 0;
2110.     /* note: no obfree() -- that's our caller's responsibility */
2111.     if (obj->dknown) {
2112.         if (kn)
2113.             makeknown(obj->otyp);
2114.         else
2115.             trycall(obj);
2116.     }
2117.     return;
2118. }
2119. 
2120. /* returns the potion type when o1 is dipped in o2 */
2121. staticfn short
2122. mixtype(struct obj *o1, struct obj *o2)
2123. {
2124.     int o1typ = o1->otyp, o2typ = o2->otyp;
2125. 
2126.     /* cut down on the number of cases below */
2127.     if (o1->oclass == POTION_CLASS
2128.         && (o2typ == POT_GAIN_LEVEL || o2typ == POT_GAIN_ENERGY
2129.             || o2typ == POT_HEALING || o2typ == POT_EXTRA_HEALING
2130.             || o2typ == POT_FULL_HEALING || o2typ == POT_ENLIGHTENMENT
2131.             || o2typ == POT_FRUIT_JUICE)) {
2132.         /* swap o1 and o2 */
2133.         o1typ = o2->otyp;
2134.         o2typ = o1->otyp;
2135.     }
2136. 
2137.     switch (o1typ) {
2138.     case POT_HEALING:
2139.         if (o2typ == POT_SPEED)
2140.             return POT_EXTRA_HEALING;
2141.         FALLTHROUGH;
2142.         /*FALLTHRU*/
2143.     case POT_EXTRA_HEALING:
2144.     case POT_FULL_HEALING:
2145.         if (o2typ == POT_GAIN_LEVEL || o2typ == POT_GAIN_ENERGY)
2146.             return (o1typ == POT_HEALING) ? POT_EXTRA_HEALING
2147.                    : (o1typ == POT_EXTRA_HEALING) ? POT_FULL_HEALING
2148.                      : POT_GAIN_ABILITY;
2149.         FALLTHROUGH;
2150.         /*FALLTHRU*/
2151.     case UNICORN_HORN:
2152.         switch (o2typ) {
2153.         case POT_SICKNESS:
2154.             return POT_FRUIT_JUICE;
2155.         case POT_HALLUCINATION:
2156.         case POT_BLINDNESS:
2157.         case POT_CONFUSION:
2158.             return POT_WATER;
2159.         }
2160.         break;
2161.     case AMETHYST: /* "a-methyst" == "not intoxicated" */
2162.         if (o2typ == POT_BOOZE)
2163.             return POT_FRUIT_JUICE;
2164.         break;
2165.     case POT_GAIN_LEVEL:
2166.     case POT_GAIN_ENERGY:
2167.         switch (o2typ) {
2168.         case POT_CONFUSION:
2169.             return (rn2(3) ? POT_BOOZE : POT_ENLIGHTENMENT);
2170.         case POT_HEALING:
2171.             return POT_EXTRA_HEALING;
2172.         case POT_EXTRA_HEALING:
2173.             return POT_FULL_HEALING;
2174.         case POT_FULL_HEALING:
2175.             return POT_GAIN_ABILITY;
2176.         case POT_FRUIT_JUICE:
2177.             return POT_SEE_INVISIBLE;
2178.         case POT_BOOZE:
2179.             return POT_HALLUCINATION;
2180.         }
2181.         break;
2182.     case POT_FRUIT_JUICE:
2183.         switch (o2typ) {
2184.         case POT_SICKNESS:
2185.             return POT_SICKNESS;
2186.         case POT_ENLIGHTENMENT:
2187.         case POT_SPEED:
2188.             return POT_BOOZE;
2189.         case POT_GAIN_LEVEL:
2190.         case POT_GAIN_ENERGY:
2191.             return POT_SEE_INVISIBLE;
2192.         }
2193.         break;
2194.     case POT_ENLIGHTENMENT:
2195.         switch (o2typ) {
2196.         case POT_LEVITATION:
2197.             if (rn2(3))
2198.                 return POT_GAIN_LEVEL;
2199.             break;
2200.         case POT_FRUIT_JUICE:
2201.             return POT_BOOZE;
2202.         case POT_BOOZE:
2203.             return POT_CONFUSION;
2204.         }
2205.         break;
2206.     }
2207. 
2208.     return STRANGE_OBJECT;
2209. }
2210. 
2211. /* getobj callback for object to be dipped (not the thing being dipped into,
2212.  * that uses drink_ok) */
2213. staticfn int
2214. dip_ok(struct obj *obj)
2215. {
2216.     if (!obj)
2217.         return GETOBJ_DOWNPLAY;
2218. 
2219.     /* dipping gold isn't currently implemented */
2220.     if (obj->oclass == COIN_CLASS)
2221.         return GETOBJ_EXCLUDE;
2222. 
2223.     if (inaccessible_equipment(obj, (const char *) 0, FALSE))
2224.         return GETOBJ_EXCLUDE_INACCESS;
2225. 
2226.     return GETOBJ_SUGGEST;
2227. }
2228. 
2229. /* getobj callback for object to be dipped when hero has slippery hands */
2230. staticfn int
2231. dip_hands_ok(struct obj *obj)
2232. {
2233.     if (!obj && (Glib && can_reach_floor(FALSE)))
2234.         return GETOBJ_SUGGEST;
2235. 
2236.     return dip_ok(obj);
2237. }
2238. 
2239. /* call hold_another_object() to deal with a transformed potion; its weight
2240.    won't have changed but it might require an extra slot that isn't available
2241.    or it might merge into some other carried stack */
2242. staticfn void
2243. hold_potion(
2244.     struct obj *potobj,
2245.     const char *drop_fmt, const char *drop_arg,
2246.     const char *hold_msg)
2247. {
2248.     int cap = near_capacity(),
2249.         save_pickup_burden = flags.pickup_burden;
2250. 
2251.     /* prevent a drop due to current setting of the 'pickup_burden' option */
2252.     if (flags.pickup_burden < cap)
2253.         flags.pickup_burden = cap;
2254.     /* remove from inventory after calculating near_capacity() */
2255.     obj_extract_self(potobj);
2256.     /* re-insert into inventory, possibly merging with compatible stack */
2257.     potobj = hold_another_object(potobj, drop_fmt, drop_arg, hold_msg);
2258.     nhUse(potobj);
2259.     flags.pickup_burden = save_pickup_burden;
2260.     update_inventory();
2261.     return;
2262. }
2263. 
2264. /* #dip command - get item to dip, then get potion to dip it into;
2265.    precede with 'm' to bypass fountain, pool, or sink at hero's spot */
2266. int
2267. dodip(void)
2268. {
2269.     static const char Dip_[] = "Dip ";
2270.     struct obj *potion, *obj;
2271.     char qbuf[QBUFSZ], obuf[QBUFSZ];
2272.     const char *shortestname; /* last resort obj name for prompt */
2273.     uchar here = levl[u.ux][u.uy].typ;
2274.     boolean is_hands, at_pool = is_pool(u.ux, u.uy),
2275.             at_fountain = IS_FOUNTAIN(here), at_sink = IS_SINK(here),
2276.             at_here = (!iflags.menu_requested
2277.                        && (at_pool || at_fountain || at_sink));
2278. 
2279.     obj = getobj("dip", at_here ? dip_hands_ok : dip_ok, GETOBJ_PROMPT);
2280.     if (!obj)
2281.         return ECMD_CANCEL;
2282.     if (inaccessible_equipment(obj, "dip", FALSE))
2283.         return ECMD_OK;
2284. 
2285.     is_hands = (obj == &hands_obj);
2286.     shortestname = (is_hands || is_plural(obj) || pair_of(obj)) ? "them"
2287.                                                                 : "it";
2288.     drink_ok_extra = 0;
2289.     /*
2290.      * Bypass safe_qbuf() since it doesn't handle varying suffix without
2291.      * an awful lot of support work.  Format the object once, even though
2292.      * the fountain and pool prompts offer a lot more room for it.
2293.      * 3.6.0 used thesimpleoname() unconditionally, which posed no risk
2294.      * of buffer overflow but drew bug reports because it omits user-
2295.      * supplied type name.
2296.      * getobj: "What do you want to dip <the object> into? [xyz or ?*] "
2297.      */
2298.     if (is_hands) {
2299.         Snprintf(obuf, sizeof obuf, "your %s", makeplural(body_part(HAND)));
2300.     } else {
2301.         Strcpy(obuf, short_oname(obj, doname, thesimpleoname,
2302.                                  /* 128 - (24 + 54 + 1) leaves 49 for
2303.                                     <object> */
2304.                                  QBUFSZ - sizeof "What do you want to dip\
2305.  into? [abdeghjkmnpqstvwyzBCEFHIKLNOQRTUWXZ#-# or ?*] "));
2306.     }
2307. 
2308.     /* preceding #dip with 'm' skips the possibility of dipping into pools,
2309.        fountains, and sinks plus the extra prompting which those entail */
2310.     if (!iflags.menu_requested) {
2311.         /* Is there a fountain to dip into here? */
2312.         if (!can_reach_floor(FALSE)) {
2313.             ; /* can't dip something into fountain or pool if can't reach */
2314.         } else if (at_fountain) {
2315.             Snprintf(qbuf, sizeof(qbuf), "%s%s into the fountain?", Dip_,
2316.                      flags.verbose ? obuf : shortestname);
2317.             /* "Dip <the object> into the fountain?" */
2318.             if (y_n(qbuf) == 'y') {
2319.                 if (!is_hands)
2320.                     obj->pickup_prev = 0;
2321.                 dipfountain(obj);
2322.                 return ECMD_TIME;
2323.             }
2324.             ++drink_ok_extra;
2325.         } else if (at_sink) {
2326.             Snprintf(qbuf, sizeof(qbuf), "%s%s into the sink?", Dip_,
2327.                      flags.verbose ? obuf : shortestname);
2328.             if (y_n(qbuf) == 'y') {
2329.                 if (!is_hands)
2330.                     obj->pickup_prev = 0;
2331.                 dipsink(obj);
2332.                 return ECMD_TIME;
2333.             }
2334.             ++drink_ok_extra;
2335.         } else if (at_pool) {
2336.             const char *pooltype = waterbody_name(u.ux, u.uy);
2337. 
2338.             Snprintf(qbuf, sizeof(qbuf), "%s%s into the %s?", Dip_,
2339.                      flags.verbose ? obuf : shortestname, pooltype);
2340.             /* "Dip <the object> into the {pool, moat, &c}?" */
2341.             if (y_n(qbuf) == 'y') {
2342.                 if (Levitation) {
2343.                     floating_above(pooltype);
2344.                 } else if (u.usteed && !is_swimmer(u.usteed->data)
2345.                            && P_SKILL(P_RIDING) < P_BASIC) {
2346.                     rider_cant_reach(); /* not skilled enough to reach */
2347.                 } else if (is_hands || obj == uarmg) {
2348.                     if (!is_hands)
2349.                         obj->pickup_prev = 0;
2350.                     (void) wash_hands();
2351.                 } else {
2352.                     obj->pickup_prev = 0;
2353.                     if (obj->otyp == POT_ACID)
2354.                         obj->in_use = 1;
2355.                     if (water_damage(obj, 0, TRUE) != ER_DESTROYED
2356.                         && obj->in_use)
2357.                         useup(obj);
2358.                 }
2359.                 return ECMD_TIME;
2360.             }
2361.             ++drink_ok_extra;
2362.         }
2363.     }
2364. 
2365.     /* "What do you want to dip <the object> into? [xyz or ?*] " */
2366.     Snprintf(qbuf, sizeof qbuf, "dip %s into",
2367.              flags.verbose ? obuf : shortestname);
2368.     potion = getobj(qbuf, drink_ok, GETOBJ_NOFLAGS);
2369.     if (!potion)
2370.         return ECMD_CANCEL;
2371.     return potion_dip(obj, potion);
2372. }
2373. 
2374. /* #altdip - #dip with "what to dip?" and "what to dip it into?" asked
2375.    in the opposite order; ignores floor water; used for context-sensitive
2376.    inventory item-action: the potion has already been selected and is in
2377.    cmdq ready to answer the first getobj() prompt */
2378. int
2379. dip_into(void)
2380. {
2381.     struct obj *obj, *potion;
2382.     char qbuf[QBUFSZ];
2383. 
2384.     if (!cmdq_peek(CQ_CANNED)) {
2385.         impossible("dip_into: where is potion?");
2386.         return ECMD_FAIL;
2387.     }
2388.     /* note: drink_ok() callback for quaffing is also used to validate
2389.        a potion to dip into */
2390.     drink_ok_extra = 0; /* affects drink_ok(): haven't been asked about and
2391.                          * declined to use a floor feature like a fountain */
2392.     potion = getobj("dip", drink_ok, GETOBJ_NOFLAGS);
2393.     if (!potion || potion->oclass != POTION_CLASS)
2394.         return ECMD_CANCEL;
2395. 
2396.     /* "What do you want to dip into <the potion>? [abc or ?*] " */
2397.     Snprintf(qbuf, sizeof qbuf, "dip into %s%s",
2398.              is_plural(potion) ? "one of " : "", thesimpleoname(potion));
2399.     obj = getobj(qbuf, dip_ok, GETOBJ_PROMPT);
2400.     if (!obj)
2401.         return ECMD_CANCEL;
2402.     if (inaccessible_equipment(obj, "dip", FALSE))
2403.         return ECMD_OK;
2404.     return potion_dip(obj, potion);
2405. }
2406. 
2407. staticfn void
2408. poof(struct obj *potion)
2409. {
2410.     if (potion->dknown)
2411.         trycall(potion);
2412.     useup(potion);
2413. }
2414. 
2415. /* do dipped potion(s) explode? */
2416. staticfn boolean
2417. dip_potion_explosion(struct obj *obj, int dmg)
2418. {
2419.     if (obj->cursed || obj->otyp == POT_ACID
2420.         || (obj->otyp == POT_OIL && obj->lamplit)
2421.         || !rn2((uarmc && uarmc->otyp == ALCHEMY_SMOCK) ? 30 : 10)) {
2422.         /* it would be better to use up the whole stack in advance
2423.            of the message, but we can't because we need to keep it
2424.            around for potionbreathe() [and we can't set obj->in_use
2425.            to 'amt' because that's not implemented] */
2426.         obj->in_use = 1;
2427.         pline("%sThey explode!", !Deaf ? "BOOM!  " : "");
2428.         wake_nearto(u.ux, u.uy, (BOLT_LIM + 1) * (BOLT_LIM + 1));
2429.         exercise(A_STR, FALSE);
2430.         if (!breathless(gy.youmonst.data) || haseyes(gy.youmonst.data))
2431.             potionbreathe(obj);
2432.         useupall(obj);
2433.         losehp(dmg, /* not physical damage */
2434.                "alchemic blast", KILLED_BY_AN);
2435.         return TRUE;
2436.     }
2437.     return FALSE;
2438. }
2439. 
2440. /* called by dodip() or dip_into() after obj and potion have been chosen */
2441. staticfn int
2442. potion_dip(struct obj *obj, struct obj *potion)
2443. {
2444.     struct obj *singlepotion;
2445.     char qbuf[QBUFSZ];
2446.     short mixture;
2447. 
2448.     if (potion == obj && potion->quan == 1L) {
2449.         pline("That is a potion bottle, not a Klein bottle!");
2450.         return ECMD_OK;
2451.     }
2452.     if (obj == &hands_obj) {
2453.         You("can't fit your %s into the mouth of the bottle!",
2454.             body_part(HAND));
2455.         return ECMD_OK;
2456.     }
2457. 
2458.     obj->pickup_prev = 0; /* no longer 'recently picked up' */
2459.     potion->in_use = TRUE; /* assume it will be used up */
2460.     if (potion->otyp == POT_WATER) {
2461.         boolean useeit = !Blind || (obj == ublindf && Blindfolded_only);
2462.         const char *obj_glows = Yobjnam2(obj, "glow");
2463. 
2464.         if (H2Opotion_dip(potion, obj, useeit, obj_glows)) {
2465.             poof(potion);
2466.             return ECMD_TIME;
2467.         }
2468.     } else if (obj->otyp == POT_POLYMORPH || potion->otyp == POT_POLYMORPH) {
2469.         /* some objects can't be polymorphed */
2470.         if (obj_unpolyable(obj->otyp == POT_POLYMORPH ? potion : obj)) {
2471.             pline1(nothing_happens);
2472.         } else {
2473.             short save_otyp = obj->otyp;
2474. 
2475.             /* KMH, conduct */
2476.             if (!u.uconduct.polypiles++)
2477.                 livelog_printf(LL_CONDUCT, "polymorphed %s first item",
2478.                                uhis());
2479. 
2480.             obj = poly_obj(obj, STRANGE_OBJECT);
2481. 
2482.             /*
2483.              * obj might be gone:
2484.              *  poly_obj() -> set_wear() -> Amulet_on() -> useup()
2485.              * if obj->otyp is worn amulet and becomes AMULET_OF_CHANGE.
2486.              */
2487.             if (!obj) {
2488.                 makeknown(POT_POLYMORPH);
2489.                 return ECMD_TIME;
2490.             } else if (obj->otyp != save_otyp) {
2491.                 makeknown(POT_POLYMORPH);
2492.                 useup(potion);
2493.                 prinv((char *) 0, obj, 0L);
2494.                 return ECMD_TIME;
2495.             } else {
2496.                 pline1(nothing_seems_to_happen);
2497.                 poof(potion);
2498.                 return ECMD_TIME;
2499.             }
2500.         }
2501.         potion->in_use = FALSE; /* didn't go poof */
2502.         return ECMD_TIME;
2503.     } else if (obj->oclass == POTION_CLASS && obj->otyp != potion->otyp) {
2504.         int amt = (int) obj->quan;
2505.         boolean magic;
2506. 
2507.         mixture = mixtype(obj, potion);
2508. 
2509.         magic = (mixture != STRANGE_OBJECT) ? objects[mixture].oc_magic
2510.             : (objects[obj->otyp].oc_magic || objects[potion->otyp].oc_magic);
2511.         Strcpy(qbuf, "The"); /* assume full stack */
2512.         if (amt > (obj->odiluted ? 2 : magic ? 3 : 7)) {
2513.             /* Trying to dip multiple potions will usually affect only a
2514.                subset; pick an amount between 3 and 8, inclusive, for magic
2515.                potion result, between 7 and N for non-magic. If diluted
2516.                potions are being dipped, only two are affected; this is a
2517.                balance fix to prevent cheap mass alchemy of the (very
2518.                common) potion of healing into the (very valuable) potion of
2519.                full healing, whilst permitting both healing->extra healing
2520.                and extra healing->full healing. */
2521.             if (obj->odiluted)
2522.                 amt = 2;
2523.             else if (magic)
2524.                 amt = rnd(min(amt, 8) - (3 - 1)) + (3 - 1); /* 1..6 + 2 */
2525.             else
2526.                 amt = rnd(amt - (7 - 1)) + (7 - 1); /* 1..(N-6) + 6 */
2527. 
2528.             if ((long) amt < obj->quan) {
2529.                 obj = splitobj(obj, (long) amt);
2530.                 Sprintf(qbuf, "%ld of the", obj->quan);
2531.             }
2532.         }
2533.         /* [N of] the {obj(s)} mix(es) with [one of] {the potion}... */
2534.         pline("%s %s %s with %s%s...", qbuf, simpleonames(obj),
2535.               otense(obj, "mix"), (potion->quan > 1L) ? "one of " : "",
2536.               thesimpleoname(potion));
2537.         /* get rid of 'dippee' before potential perm_invent updates */
2538.         useup(potion); /* now gone */
2539.         /* Mixing potions is dangerous...
2540.            KMH, balance patch -- acid is particularly unstable */
2541.         if (dip_potion_explosion(obj, amt + rnd(9)))
2542.             return ECMD_TIME;
2543. 
2544.         obj->blessed = obj->cursed = obj->bknown = 0;
2545.         if (Blind || Hallucination)
2546.             obj->dknown = 0;
2547. 
2548.         if (mixture != STRANGE_OBJECT) {
2549.             obj->otyp = mixture;
2550.         } else {
2551.             struct obj *otmp;
2552. 
2553.             switch (obj->odiluted ? 1 : rnd(8)) {
2554.             case 1:
2555.                 obj->otyp = POT_WATER;
2556.                 break;
2557.             case 2:
2558.             case 3:
2559.                 obj->otyp = POT_SICKNESS;
2560.                 break;
2561.             case 4:
2562.                 otmp = mkobj(POTION_CLASS, FALSE);
2563.                 obj->otyp = otmp->otyp;
2564.                 /* oil uses obj->age field differently from other potions */
2565.                 if (obj->otyp == POT_OIL || otmp->otyp == POT_OIL)
2566.                     fixup_oil(obj, otmp);
2567.                 obfree(otmp, (struct obj *) 0);
2568.                 break;
2569.             default:
2570.                 useupall(obj);
2571.                 pline_The("mixture %sevaporates.",
2572.                           !Blind ? "glows brightly and " : "");
2573.                 return ECMD_TIME;
2574.             }
2575.         }
2576.         obj->odiluted = (obj->otyp != POT_WATER);
2577. 
2578.         if (obj->otyp == POT_WATER && !Hallucination) {
2579.             pline_The("mixture bubbles%s.", Blind ? "" : ", then clears");
2580.         } else if (!Blind) {
2581.             pline_The("mixture looks %s.",
2582.                       hcolor(OBJ_DESCR(objects[obj->otyp])));
2583.         }
2584. 
2585.         /* this is required when 'obj' was split off from a bigger stack,
2586.            so that 'obj' will now be assigned its own inventory slot;
2587.            it has a side-effect of merging 'obj' into another compatible
2588.            stack if there is one, so we do it even when no split has
2589.            been made in order to get the merge result for both cases;
2590.            as a consequence, mixing while Fumbling drops the mixture */
2591.         freeinv(obj);
2592.         hold_potion(obj, "You drop %s!", doname(obj), (const char *) 0);
2593.         return ECMD_TIME;
2594.     }
2595. 
2596.     if (potion->otyp == POT_ACID && obj->otyp == CORPSE
2597.         && obj->corpsenm == PM_LICHEN) {
2598.         pline("%s %s %s around the edges.", The(cxname(obj)),
2599.               otense(obj, "turn"), Blind ? "wrinkled"
2600.                                    : potion->odiluted ? hcolor(NH_ORANGE)
2601.                                      : hcolor(NH_RED));
2602.         potion->in_use = FALSE; /* didn't go poof */
2603.         if (potion->dknown)
2604.             trycall(potion);
2605.         return ECMD_TIME;
2606.     }
2607. 
2608.     if (potion->otyp == POT_WATER && obj->otyp == TOWEL) {
2609.         pline_The("towel soaks it up!");
2610.         /* wetting towel already done via water_damage() in H2Opotion_dip */
2611.         poof(potion);
2612.         return ECMD_TIME;
2613.     }
2614. 
2615.     if (is_poisonable(obj)) {
2616.         if (potion->otyp == POT_SICKNESS && !obj->opoisoned) {
2617.             char buf[BUFSZ];
2618. 
2619.             if (potion->quan > 1L)
2620.                 Sprintf(buf, "One of %s", the(xname(potion)));
2621.             else
2622.                 Strcpy(buf, The(xname(potion)));
2623.             pline("%s forms a coating on %s.", buf, the(xname(obj)));
2624.             obj->opoisoned = TRUE;
2625.             poof(potion);
2626.             return ECMD_TIME;
2627.         } else if (obj->opoisoned && !permapoisoned(obj)
2628.                    && (potion->otyp == POT_HEALING
2629.                        || potion->otyp == POT_EXTRA_HEALING
2630.                        || potion->otyp == POT_FULL_HEALING)) {
2631.             pline("A coating wears off %s.", the(xname(obj)));
2632.             obj->opoisoned = 0;
2633.             poof(potion);
2634.             return ECMD_TIME;
2635.         }
2636.     }
2637. 
2638.     if (potion->otyp == POT_ACID) {
2639.         if (erode_obj(obj, 0, ERODE_CORRODE, EF_GREASE) != ER_NOTHING) {
2640.             poof(potion);
2641.             return ECMD_TIME;
2642.         }
2643.     }
2644. 
2645.     if (potion->otyp == POT_OIL) {
2646.         boolean wisx = FALSE;
2647. 
2648.         if (potion->lamplit) { /* burning */
2649.             fire_damage(obj, TRUE, u.ux, u.uy);
2650.         } else if (potion->cursed) {
2651.             pline_The("potion spills and covers your %s with oil.",
2652.                       fingers_or_gloves(TRUE));
2653.             make_glib((int) (Glib & TIMEOUT) + d(2, 10));
2654.         } else if (obj->oclass != WEAPON_CLASS && !is_weptool(obj)) {
2655.             /* the following cases apply only to weapons */
2656.             goto more_dips;
2657.             /* Oil removes rust and corrosion, but doesn't unburn or repair
2658.              * cracks.  Arrows, etc are classed as metallic due to arrowhead
2659.              * material, but dipping in oil shouldn't repair them.
2660.              */
2661.         } else if ((!is_rustprone(obj) && !is_corrodeable(obj))
2662.                    || is_ammo(obj) || (!obj->oeroded && !obj->oeroded2)) {
2663.             /* uses up potion, doesn't set obj->greased */
2664.             if (!Blind)
2665.                 pline("%s %s with an oily sheen.", Yname2(obj),
2666.                       otense(obj, "gleam"));
2667.             else /*if (!uarmg)*/
2668.                 pline("%s %s oily.", Yname2(obj), otense(obj, "feel"));
2669.         } else {
2670.             pline("%s %s less %s.", Yname2(obj),
2671.                   otense(obj, !Blind ? "are" : "feel"),
2672.                   (obj->oeroded && obj->oeroded2)
2673.                       ? "corroded and rusty"
2674.                       : obj->oeroded ? "rusty" : "corroded");
2675.             if (obj->oeroded > 0)
2676.                 obj->oeroded--;
2677.             if (obj->oeroded2 > 0)
2678.                 obj->oeroded2--;
2679.             wisx = TRUE;
2680.         }
2681.         exercise(A_WIS, wisx);
2682.         if (potion->dknown)
2683.             makeknown(potion->otyp);
2684.         useup(potion);
2685.         return ECMD_TIME;
2686.     }
2687.  more_dips:
2688. 
2689.     /* Allow filling of MAGIC_LAMPs to prevent identification by player */
2690.     if ((obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP)
2691.         && (potion->otyp == POT_OIL)) {
2692.         /* Turn off engine before fueling, turn off fuel too :-)  */
2693.         if (obj->lamplit || potion->lamplit) {
2694.             useup(potion);
2695.             explode(u.ux, u.uy, 11, d(6, 6), 0, EXPL_FIERY);
2696.             exercise(A_WIS, FALSE);
2697.             return ECMD_TIME;
2698.         }
2699.         /* Adding oil to an empty magic lamp renders it into an oil lamp */
2700.         if ((obj->otyp == MAGIC_LAMP) && obj->spe == 0) {
2701.             obj->otyp = OIL_LAMP;
2702.             obj->age = 0;
2703.         }
2704.         if (obj->age > 1000L) {
2705.             pline("%s %s full.", Yname2(obj), otense(obj, "are"));
2706.             potion->in_use = FALSE; /* didn't go poof */
2707.         } else {
2708.             You("fill %s with oil.", yname(obj));
2709.             check_unpaid(potion);        /* Yendorian Fuel Tax */
2710.             /* burns more efficiently in a lamp than in a bottle;
2711.                diluted potion provides less benefit but we don't attempt
2712.                to track that the lamp now also has some non-oil in it */
2713.             obj->age += (!potion->odiluted ? 4L : 3L) * potion->age / 2L;
2714.             if (obj->age > 1500L)
2715.                 obj->age = 1500L;
2716.             useup(potion);
2717.             exercise(A_WIS, TRUE);
2718.         }
2719.         if (potion->dknown)
2720.             makeknown(POT_OIL);
2721.         obj->spe = 1;
2722.         update_inventory();
2723.         return ECMD_TIME;
2724.     }
2725. 
2726.     potion->in_use = FALSE; /* didn't go poof */
2727.     if ((obj->otyp == UNICORN_HORN || obj->otyp == AMETHYST)
2728.         && (mixture = mixtype(obj, potion)) != STRANGE_OBJECT) {
2729.         char oldbuf[BUFSZ], newbuf[BUFSZ];
2730.         short old_otyp = potion->otyp;
2731.         boolean old_dknown = FALSE;
2732.         boolean more_than_one = potion->quan > 1L;
2733. 
2734.         oldbuf[0] = '\0';
2735.         if (potion->dknown) {
2736.             old_dknown = TRUE;
2737.             Sprintf(oldbuf, "%s ", hcolor(OBJ_DESCR(objects[potion->otyp])));
2738.         }
2739.         /* with multiple merged potions, split off one and
2740.            just clear it */
2741.         if (potion->quan > 1L) {
2742.             singlepotion = splitobj(potion, 1L);
2743.         } else
2744.             singlepotion = potion;
2745. 
2746.         costly_alteration(singlepotion, COST_NUTRLZ);
2747.         singlepotion->otyp = mixture;
2748.         singlepotion->blessed = 0;
2749.         if (mixture == POT_WATER)
2750.             singlepotion->cursed = singlepotion->odiluted = 0;
2751.         else
2752.             singlepotion->cursed = obj->cursed; /* odiluted left as-is */
2753.         singlepotion->bknown = FALSE;
2754.         singlepotion->dknown = FALSE; /* provisionally */
2755.         if (!Blind) {
2756.             if (!Hallucination)
2757.                 observe_object(singlepotion);
2758.             *newbuf = '\0';
2759.             if (mixture == POT_WATER && singlepotion->dknown)
2760.                 Sprintf(newbuf, "clears");
2761.             else if (!Blind)
2762.                 Sprintf(newbuf, "turns %s",
2763.                         hcolor(OBJ_DESCR(objects[mixture])));
2764.             if (*newbuf)
2765.                 pline_The("%spotion%s %s.", oldbuf,
2766.                           more_than_one ? " that you dipped into" : "",
2767.                           newbuf);
2768.             else
2769.                 pline("Something happens.");
2770. 
2771.             if (old_dknown
2772.                 && !objects[old_otyp].oc_name_known
2773.                 && !objects[old_otyp].oc_uname) {
2774.                 struct obj fakeobj;
2775. 
2776.                 fakeobj = cg.zeroobj;
2777.                 fakeobj.dknown = 1; /* no need to observe_object */
2778.                 fakeobj.otyp = old_otyp;
2779.                 fakeobj.oclass = POTION_CLASS;
2780.                 docall(&fakeobj);
2781.             }
2782.         }
2783.         /* remove potion from inventory and re-insert it, possibly stacking
2784.            with compatible ones; override 'pickup_burden' while doing so */
2785.         hold_potion(singlepotion, "You juggle and drop %s!",
2786.                     doname(singlepotion), (const char *) 0);
2787.         return ECMD_TIME;
2788.     }
2789. 
2790.     pline("Interesting...");
2791.     return ECMD_TIME;
2792. }
2793. 
2794. /* *monp grants a wish and then leaves the game */
2795. void
2796. mongrantswish(struct monst **monp)
2797. {
2798.     struct monst *mon = *monp;
2799.     int mx = mon->mx, my = mon->my, glyph = glyph_at(mx, my);
2800. 
2801.     /* remove the monster first in case wish proves to be fatal
2802.        (blasted by artifact), to keep it out of resulting bones file */
2803.     mongone(mon);
2804.     *monp = 0; /* inform caller that monster is gone */
2805.     /* hide that removal from player--map is visible during wish prompt */
2806.     tmp_at(DISP_ALWAYS, glyph);
2807.     tmp_at(mx, my);
2808.     /* grant the wish */
2809.     makewish();
2810.     /* clean up */
2811.     tmp_at(DISP_END, 0);
2812. }
2813. 
2814. void
2815. djinni_from_bottle(struct obj *obj)
2816. {
2817.     struct monst *mtmp;
2818.     int chance;
2819. 
2820.     if (!(mtmp = makemon(&mons[PM_DJINNI], u.ux, u.uy, MM_NOMSG))) {
2821.         pline("It turns out to be empty.");
2822.         return;
2823.     }
2824. 
2825.     if (!Blind) {
2826.         pline("In a cloud of smoke, %s emerges!", a_monnam(mtmp));
2827.         pline("%s speaks.", Monnam(mtmp));
2828.     } else {
2829.         You("smell acrid fumes.");
2830.         pline("%s speaks.", Something);
2831.     }
2832. 
2833.     chance = rn2(5);
2834.     if (obj->blessed)
2835.         chance = (chance == 4) ? rnd(4) : 0;
2836.     else if (obj->cursed)
2837.         chance = (chance == 0) ? rn2(4) : 4;
2838.     /* 0,1,2,3,4:  b=80%,5,5,5,5; nc=20%,20,20,20,20; c=5%,5,5,5,80 */
2839. 
2840.     SetVoice(mtmp, 0, 80, 0);
2841.     switch (chance) {
2842.     case 0:
2843.         verbalize("I am in your debt.  I will grant one wish!");
2844.         /* give a wish and discard the monster (mtmp set to null) */
2845.         mongrantswish(&mtmp);
2846.         break;
2847.     case 1:
2848.         verbalize("Thank you for freeing me!");
2849.         (void) tamedog(mtmp, (struct obj *) 0, FALSE);
2850.         break;
2851.     case 2:
2852.         verbalize("You freed me!");
2853.         mtmp->mpeaceful = TRUE;
2854.         set_malign(mtmp);
2855.         break;
2856.     case 3:
2857.         verbalize("It is about time!");
2858.         if (canspotmon(mtmp))
2859.             pline("%s vanishes.", Monnam(mtmp));
2860.         mongone(mtmp);
2861.         break;
2862.     default:
2863.         verbalize("You disturbed me, fool!");
2864.         mtmp->mpeaceful = FALSE;
2865.         set_malign(mtmp);
2866.         break;
2867.     }
2868. }
2869. 
2870. /* clone a gremlin or mold (2nd arg non-null implies heat as the trigger);
2871.    hit points are cut in half (odd HP stays with original) */
2872. struct monst *
2873. split_mon(
2874.     struct monst *mon,  /* monster being split */
2875.     struct monst *mtmp) /* optional attacker whose heat triggered it */
2876. {
2877.     struct monst *mtmp2;
2878.     char reason[BUFSZ];
2879. 
2880.     reason[0] = '\0';
2881.     if (mtmp)
2882.         Sprintf(reason, " from %s heat",
2883.                 (mtmp == &gy.youmonst) ? the_your[1]
2884.                                     : (const char *) s_suffix(mon_nam(mtmp)));
2885. 
2886.     if (mon == &gy.youmonst) {
2887.         if (u.mh > u.mhmax) /* sanity precaution */
2888.             u.mh = u.mhmax;
2889.         mtmp2 = (u.mh > 1) ? cloneu() : (struct monst *) 0;
2890.         if (mtmp2) {
2891.             /* mtmp2 has been created with mhpmax = u.mhmax, mhp = u.mh / 2,
2892.                and u.mh -= mtmp2->mhp; these reductions for both max hp
2893.                can't make either of them exceed corresponding current hp */
2894.             mtmp2->mhpmax = u.mhmax / 2;
2895.             u.mhmax -= mtmp2->mhpmax;
2896.             disp.botl = TRUE;
2897.             You("multiply%s!", reason);
2898.         }
2899.     } else {
2900.         if (mon->mhp > mon->mhpmax) /* sanity precaution */
2901.             mon->mhp = mon->mhpmax;
2902.         mtmp2 = (mon->mhp > 1) ? clone_mon(mon, 0, 0) : (struct monst *) 0;
2903.         if (mtmp2) {
2904.             assert(mon->mhpmax >= mon->mhp); /* mon->mhpmax > 1 */
2905.             /* mtmp2 has been created with mhpmax = mon->mhpmax,
2906.                mhp = mon->mhp / 2, and mon->mh -= mtmp2->mhp;
2907.                dividing max by 2 can't result in it exceeding current */
2908.             mtmp2->mhpmax = mon->mhpmax / 2;
2909.             mon->mhpmax -= mtmp2->mhpmax;
2910.             if (canspotmon(mon))
2911.                 pline("%s multiplies%s!", Monnam(mon), reason);
2912.         }
2913.     }
2914.     return mtmp2;
2915. }
2916. 
2917. /* Character becomes very fast temporarily. */
2918. void
2919. speed_up(long duration)
2920. {
2921.    if (!Very_fast)
2922.        You("are suddenly moving %sfaster.", Fast ? "" : "much ");
2923.    else
2924.        Your("%s get new energy.", makeplural(body_part(LEG)));
2925. 
2926.    exercise(A_DEX, TRUE);
2927.    incr_itimeout(&HFast, duration);
2928. }
2929. 
2930. /*potion.c*/