Source:NetHack 3.6.2/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 3.6.2. To link to a particular line, write [[Source:NetHack 3.6.2/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 3.6	potion.c	$NHDT-Date: 1549074254 2019/02/02 02:24:14 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.160 $ */
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. boolean notonhead = FALSE;
9. 
10. static NEARDATA int nothing, unkn;
11. static NEARDATA const char beverages[] = { POTION_CLASS, 0 };
12. 
13. STATIC_DCL long FDECL(itimeout, (long));
14. STATIC_DCL long FDECL(itimeout_incr, (long, int));
15. STATIC_DCL void NDECL(ghost_from_bottle);
16. STATIC_DCL boolean
17. FDECL(H2Opotion_dip, (struct obj *, struct obj *, BOOLEAN_P, const char *));
18. STATIC_DCL short FDECL(mixtype, (struct obj *, struct obj *));
19. 
20. /* force `val' to be within valid range for intrinsic timeout value */
21. STATIC_OVL long
22. itimeout(val)
23. long val;
24. {
25.     if (val >= TIMEOUT)
26.         val = TIMEOUT;
27.     else if (val < 1)
28.         val = 0;
29. 
30.     return val;
31. }
32. 
33. /* increment `old' by `incr' and force result to be valid intrinsic timeout */
34. STATIC_OVL long
35. itimeout_incr(old, incr)
36. long old;
37. int incr;
38. {
39.     return itimeout((old & TIMEOUT) + (long) incr);
40. }
41. 
42. /* set the timeout field of intrinsic `which' */
43. void
44. set_itimeout(which, val)
45. long *which, val;
46. {
47.     *which &= ~TIMEOUT;
48.     *which |= itimeout(val);
49. }
50. 
51. /* increment the timeout field of intrinsic `which' */
52. void
53. incr_itimeout(which, incr)
54. long *which;
55. int incr;
56. {
57.     set_itimeout(which, itimeout_incr(*which, incr));
58. }
59. 
60. void
61. make_confused(xtime, talk)
62. long xtime;
63. boolean talk;
64. {
65.     long old = HConfusion;
66. 
67.     if (Unaware)
68.         talk = FALSE;
69. 
70.     if (!xtime && old) {
71.         if (talk)
72.             You_feel("less %s now.", Hallucination ? "trippy" : "confused");
73.     }
74.     if ((xtime && !old) || (!xtime && old))
75.         context.botl = TRUE;
76. 
77.     set_itimeout(&HConfusion, xtime);
78. }
79. 
80. void
81. make_stunned(xtime, talk)
82. long xtime;
83. boolean talk;
84. {
85.     long old = HStun;
86. 
87.     if (Unaware)
88.         talk = FALSE;
89. 
90.     if (!xtime && old) {
91.         if (talk)
92.             You_feel("%s now.",
93.                      Hallucination ? "less wobbly" : "a bit steadier");
94.     }
95.     if (xtime && !old) {
96.         if (talk) {
97.             if (u.usteed)
98.                 You("wobble in the saddle.");
99.             else
100.                 You("%s...", stagger(youmonst.data, "stagger"));
101.         }
102.     }
103.     if ((!xtime && old) || (xtime && !old))
104.         context.botl = TRUE;
105. 
106.     set_itimeout(&HStun, xtime);
107. }
108. 
109. /* Sick is overloaded with both fatal illness and food poisoning (via
110.    u.usick_type bit mask), but delayed killer can only support one or
111.    the other at a time.  They should become separate intrinsics.... */
112. void
113. make_sick(xtime, cause, talk, type)
114. long xtime;
115. const char *cause; /* sickness cause */
116. boolean talk;
117. int type;
118. {
119.     struct kinfo *kptr;
120.     long old = Sick;
121. 
122. #if 0   /* tell player even if hero is unconscious */
123.     if (Unaware)
124.         talk = FALSE;
125. #endif
126.     if (xtime > 0L) {
127.         if (Sick_resistance)
128.             return;
129.         if (!old) {
130.             /* newly sick */
131.             You_feel("deathly sick.");
132.         } else {
133.             /* already sick */
134.             if (talk)
135.                 You_feel("%s worse.", xtime <= Sick / 2L ? "much" : "even");
136.         }
137.         set_itimeout(&Sick, xtime);
138.         u.usick_type |= type;
139.         context.botl = TRUE;
140.     } else if (old && (type & u.usick_type)) {
141.         /* was sick, now not */
142.         u.usick_type &= ~type;
143.         if (u.usick_type) { /* only partly cured */
144.             if (talk)
145.                 You_feel("somewhat better.");
146.             set_itimeout(&Sick, Sick * 2); /* approximation */
147.         } else {
148.             if (talk)
149.                 You_feel("cured.  What a relief!");
150.             Sick = 0L; /* set_itimeout(&Sick, 0L) */
151.         }
152.         context.botl = TRUE;
153.     }
154. 
155.     kptr = find_delayed_killer(SICK);
156.     if (Sick) {
157.         exercise(A_CON, FALSE);
158.         /* setting delayed_killer used to be unconditional, but that's
159.            not right when make_sick(0) is called to cure food poisoning
160.            if hero was also fatally ill; this is only approximate */
161.         if (xtime || !old || !kptr) {
162.             int kpfx = ((cause && !strcmp(cause, "#wizintrinsic"))
163.                         ? KILLED_BY : KILLED_BY_AN);
164. 
165.             delayed_killer(SICK, kpfx, cause);
166.         }
167.     } else
168.         dealloc_killer(kptr);
169. }
170. 
171. void
172. make_slimed(xtime, msg)
173. long xtime;
174. const char *msg;
175. {
176.     long old = Slimed;
177. 
178. #if 0   /* tell player even if hero is unconscious */
179.     if (Unaware)
180.         msg = 0;
181. #endif
182.     set_itimeout(&Slimed, xtime);
183.     if ((xtime != 0L) ^ (old != 0L)) {
184.         context.botl = TRUE;
185.         if (msg)
186.             pline("%s", msg);
187.     }
188.     if (!Slimed)
189.         dealloc_killer(find_delayed_killer(SLIMED));
190. }
191. 
192. /* start or stop petrification */
193. void
194. make_stoned(xtime, msg, killedby, killername)
195. long xtime;
196. const char *msg;
197. int killedby;
198. const char *killername;
199. {
200.     long old = Stoned;
201. 
202. #if 0   /* tell player even if hero is unconscious */
203.     if (Unaware)
204.         msg = 0;
205. #endif
206.     set_itimeout(&Stoned, xtime);
207.     if ((xtime != 0L) ^ (old != 0L)) {
208.         context.botl = TRUE;
209.         if (msg)
210.             pline("%s", msg);
211.     }
212.     if (!Stoned)
213.         dealloc_killer(find_delayed_killer(STONED));
214.     else if (!old)
215.         delayed_killer(STONED, killedby, killername);
216. }
217. 
218. void
219. make_vomiting(xtime, talk)
220. long xtime;
221. boolean talk;
222. {
223.     long old = Vomiting;
224. 
225.     if (Unaware)
226.         talk = FALSE;
227. 
228.     set_itimeout(&Vomiting, xtime);
229.     context.botl = TRUE;
230.     if (!xtime && old)
231.         if (talk)
232.             You_feel("much less nauseated now.");
233. }
234. 
235. static const char vismsg[] = "vision seems to %s for a moment but is %s now.";
236. static const char eyemsg[] = "%s momentarily %s.";
237. 
238. void
239. make_blinded(xtime, talk)
240. long xtime;
241. boolean talk;
242. {
243.     long old = Blinded;
244.     boolean u_could_see, can_see_now;
245.     const char *eyes;
246. 
247.     /* we need to probe ahead in case the Eyes of the Overworld
248.        are or will be overriding blindness */
249.     u_could_see = !Blind;
250.     Blinded = xtime ? 1L : 0L;
251.     can_see_now = !Blind;
252.     Blinded = old; /* restore */
253. 
254.     if (Unaware)
255.         talk = FALSE;
256. 
257.     if (can_see_now && !u_could_see) { /* regaining sight */
258.         if (talk) {
259.             if (Hallucination)
260.                 pline("Far out!  Everything is all cosmic again!");
261.             else
262.                 You("can see again.");
263.         }
264.     } else if (old && !xtime) {
265.         /* clearing temporary blindness without toggling blindness */
266.         if (talk) {
267.             if (!haseyes(youmonst.data)) {
268.                 strange_feeling((struct obj *) 0, (char *) 0);
269.             } else if (Blindfolded) {
270.                 eyes = body_part(EYE);
271.                 if (eyecount(youmonst.data) != 1)
272.                     eyes = makeplural(eyes);
273.                 Your(eyemsg, eyes, vtense(eyes, "itch"));
274.             } else { /* Eyes of the Overworld */
275.                 Your(vismsg, "brighten", Hallucination ? "sadder" : "normal");
276.             }
277.         }
278.     }
279. 
280.     if (u_could_see && !can_see_now) { /* losing sight */
281.         if (talk) {
282.             if (Hallucination)
283.                 pline("Oh, bummer!  Everything is dark!  Help!");
284.             else
285.                 pline("A cloud of darkness falls upon you.");
286.         }
287.         /* Before the hero goes blind, set the ball&chain variables. */
288.         if (Punished)
289.             set_bc(0);
290.     } else if (!old && xtime) {
291.         /* setting temporary blindness without toggling blindness */
292.         if (talk) {
293.             if (!haseyes(youmonst.data)) {
294.                 strange_feeling((struct obj *) 0, (char *) 0);
295.             } else if (Blindfolded) {
296.                 eyes = body_part(EYE);
297.                 if (eyecount(youmonst.data) != 1)
298.                     eyes = makeplural(eyes);
299.                 Your(eyemsg, eyes, vtense(eyes, "twitch"));
300.             } else { /* Eyes of the Overworld */
301.                 Your(vismsg, "dim", Hallucination ? "happier" : "normal");
302.             }
303.         }
304.     }
305. 
306.     set_itimeout(&Blinded, xtime);
307. 
308.     if (u_could_see ^ can_see_now) { /* one or the other but not both */
309.         toggle_blindness();
310.     }
311. }
312. 
313. /* blindness has just started or just ended--caller enforces that;
314.    called by Blindf_on(), Blindf_off(), and make_blinded() */
315. void
316. toggle_blindness()
317. {
318.     boolean Stinging = (uwep && (EWarn_of_mon & W_WEP) != 0L);
319. 
320.     /* blindness has just been toggled */
321.     context.botl = TRUE; /* status conditions need update */
322.     vision_full_recalc = 1; /* vision has changed */
323.     /* this vision recalculation used to be deferred until moveloop(),
324.        but that made it possible for vision irregularities to occur
325.        (cited case was force bolt hitting an adjacent potion of blindness
326.        and then a secret door; hero was blinded by vapors but then got the
327.        message "a door appears in the wall" because wall spot was IN_SIGHT) */
328.     vision_recalc(0);
329.     if (Blind_telepat || Infravision || Stinging)
330.         see_monsters(); /* also counts EWarn_of_mon monsters */
331.     /*
332.      * Avoid either of the sequences
333.      * "Sting starts glowing", [become blind], "Sting stops quivering" or
334.      * "Sting starts quivering", [regain sight], "Sting stops glowing"
335.      * by giving "Sting is quivering" when becoming blind or
336.      * "Sting is glowing" when regaining sight so that the eventual
337.      * "stops" message matches the most recent "Sting is ..." one.
338.      */
339.     if (Stinging)
340.         Sting_effects(-1);
341.     /* update dknown flag for inventory picked up while blind */
342.     if (!Blind)
343.         learn_unseen_invent();
344. }
345. 
346. boolean
347. make_hallucinated(xtime, talk, mask)
348. long xtime; /* nonzero if this is an attempt to turn on hallucination */
349. boolean talk;
350. long mask; /* nonzero if resistance status should change by mask */
351. {
352.     long old = HHallucination;
353.     boolean changed = 0;
354.     const char *message, *verb;
355. 
356.     if (Unaware)
357.         talk = FALSE;
358. 
359.     message = (!xtime) ? "Everything %s SO boring now."
360.                        : "Oh wow!  Everything %s so cosmic!";
361.     verb = (!Blind) ? "looks" : "feels";
362. 
363.     if (mask) {
364.         if (HHallucination)
365.             changed = TRUE;
366. 
367.         if (!xtime)
368.             EHalluc_resistance |= mask;
369.         else
370.             EHalluc_resistance &= ~mask;
371.     } else {
372.         if (!EHalluc_resistance && (!!HHallucination != !!xtime))
373.             changed = TRUE;
374.         set_itimeout(&HHallucination, xtime);
375. 
376.         /* clearing temporary hallucination without toggling vision */
377.         if (!changed && !HHallucination && old && talk) {
378.             if (!haseyes(youmonst.data)) {
379.                 strange_feeling((struct obj *) 0, (char *) 0);
380.             } else if (Blind) {
381.                 const char *eyes = body_part(EYE);
382. 
383.                 if (eyecount(youmonst.data) != 1)
384.                     eyes = makeplural(eyes);
385.                 Your(eyemsg, eyes, vtense(eyes, "itch"));
386.             } else { /* Grayswandir */
387.                 Your(vismsg, "flatten", "normal");
388.             }
389.         }
390.     }
391. 
392.     if (changed) {
393.         /* in case we're mimicking an orange (hallucinatory form
394.            of mimicking gold) update the mimicking's-over message */
395.         if (!Hallucination)
396.             eatmupdate();
397. 
398.         if (u.uswallow) {
399.             swallowed(0); /* redraw swallow display */
400.         } else {
401.             /* The see_* routines should be called *before* the pline. */
402.             see_monsters();
403.             see_objects();
404.             see_traps();
405.         }
406. 
407.         /* for perm_inv and anything similar
408.         (eg. Qt windowport's equipped items display) */
409.         update_inventory();
410. 
411.         context.botl = TRUE;
412.         if (talk)
413.             pline(message, verb);
414.     }
415.     return changed;
416. }
417. 
418. void
419. make_deaf(xtime, talk)
420. long xtime;
421. boolean talk;
422. {
423.     long old = HDeaf;
424. 
425.     if (Unaware)
426.         talk = FALSE;
427. 
428.     set_itimeout(&HDeaf, xtime);
429.     if ((xtime != 0L) ^ (old != 0L)) {
430.         context.botl = TRUE;
431.         if (talk)
432.             You(old ? "can hear again." : "are unable to hear anything.");
433.     }
434. }
435. 
436. void
437. self_invis_message()
438. {
439.     pline("%s %s.",
440.           Hallucination ? "Far out, man!  You"
441.                         : "Gee!  All of a sudden, you",
442.           See_invisible ? "can see right through yourself"
443.                         : "can't see yourself");
444. }
445. 
446. STATIC_OVL void
447. ghost_from_bottle()
448. {
449.     struct monst *mtmp = makemon(&mons[PM_GHOST], u.ux, u.uy, NO_MM_FLAGS);
450. 
451.     if (!mtmp) {
452.         pline("This bottle turns out to be empty.");
453.         return;
454.     }
455.     if (Blind) {
456.         pline("As you open the bottle, %s emerges.", something);
457.         return;
458.     }
459.     pline("As you open the bottle, an enormous %s emerges!",
460.           Hallucination ? rndmonnam(NULL) : (const char *) "ghost");
461.     if (flags.verbose)
462.         You("are frightened to death, and unable to move.");
463.     nomul(-3);
464.     multi_reason = "being frightened to death";
465.     nomovemsg = "You regain your composure.";
466. }
467. 
468. /* "Quaffing is like drinking, except you spill more." - Terry Pratchett */
469. int
470. dodrink()
471. {
472.     register struct obj *otmp;
473.     const char *potion_descr;
474. 
475.     if (Strangled) {
476.         pline("If you can't breathe air, how can you drink liquid?");
477.         return 0;
478.     }
479.     /* Is there a fountain to drink from here? */
480.     if (IS_FOUNTAIN(levl[u.ux][u.uy].typ)
481.         /* not as low as floor level but similar restrictions apply */
482.         && can_reach_floor(FALSE)) {
483.         if (yn("Drink from the fountain?") == 'y') {
484.             drinkfountain();
485.             return 1;
486.         }
487.     }
488.     /* Or a kitchen sink? */
489.     if (IS_SINK(levl[u.ux][u.uy].typ)
490.         /* not as low as floor level but similar restrictions apply */
491.         && can_reach_floor(FALSE)) {
492.         if (yn("Drink from the sink?") == 'y') {
493.             drinksink();
494.             return 1;
495.         }
496.     }
497.     /* Or are you surrounded by water? */
498.     if (Underwater && !u.uswallow) {
499.         if (yn("Drink the water around you?") == 'y') {
500.             pline("Do you know what lives in this water?");
501.             return 1;
502.         }
503.     }
504. 
505.     otmp = getobj(beverages, "drink");
506.     if (!otmp)
507.         return 0;
508. 
509.     /* quan > 1 used to be left to useup(), but we need to force
510.        the current potion to be unworn, and don't want to do
511.        that for the entire stack when starting with more than 1.
512.        [Drinking a wielded potion of polymorph can trigger a shape
513.        change which causes hero's weapon to be dropped.  In 3.4.x,
514.        that led to an "object lost" panic since subsequent useup()
515.        was no longer dealing with an inventory item.  Unwearing
516.        the current potion is intended to keep it in inventory.] */
517.     if (otmp->quan > 1L) {
518.         otmp = splitobj(otmp, 1L);
519.         otmp->owornmask = 0L; /* rest of original stuck unaffected */
520.     } else if (otmp->owornmask) {
521.         remove_worn_item(otmp, FALSE);
522.     }
523.     otmp->in_use = TRUE; /* you've opened the stopper */
524. 
525.     potion_descr = OBJ_DESCR(objects[otmp->otyp]);
526.     if (potion_descr) {
527.         if (!strcmp(potion_descr, "milky")
528.             && !(mvitals[PM_GHOST].mvflags & G_GONE)
529.             && !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_GHOST].born))) {
530.             ghost_from_bottle();
531.             useup(otmp);
532.             return 1;
533.         } else if (!strcmp(potion_descr, "smoky")
534.                    && !(mvitals[PM_DJINNI].mvflags & G_GONE)
535.                    && !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_DJINNI].born))) {
536.             djinni_from_bottle(otmp);
537.             useup(otmp);
538.             return 1;
539.         }
540.     }
541.     return dopotion(otmp);
542. }
543. 
544. int
545. dopotion(otmp)
546. register struct obj *otmp;
547. {
548.     int retval;
549. 
550.     otmp->in_use = TRUE;
551.     nothing = unkn = 0;
552.     if ((retval = peffects(otmp)) >= 0)
553.         return retval;
554. 
555.     if (nothing) {
556.         unkn++;
557.         You("have a %s feeling for a moment, then it passes.",
558.             Hallucination ? "normal" : "peculiar");
559.     }
560.     if (otmp->dknown && !objects[otmp->otyp].oc_name_known) {
561.         if (!unkn) {
562.             makeknown(otmp->otyp);
563.             more_experienced(0, 10);
564.         } else if (!objects[otmp->otyp].oc_uname)
565.             docall(otmp);
566.     }
567.     useup(otmp);
568.     return 1;
569. }
570. 
571. int
572. peffects(otmp)
573. register struct obj *otmp;
574. {
575.     register int i, ii, lim;
576. 
577.     switch (otmp->otyp) {
578.     case POT_RESTORE_ABILITY:
579.     case SPE_RESTORE_ABILITY:
580.         unkn++;
581.         if (otmp->cursed) {
582.             pline("Ulch!  This makes you feel mediocre!");
583.             break;
584.         } else {
585.             /* unlike unicorn horn, overrides Fixed_abil */
586.             pline("Wow!  This makes you feel %s!",
587.                   (otmp->blessed)
588.                       ? (unfixable_trouble_count(FALSE) ? "better" : "great")
589.                       : "good");
590.             i = rn2(A_MAX); /* start at a random point */
591.             for (ii = 0; ii < A_MAX; ii++) {
592.                 lim = AMAX(i);
593.                 /* this used to adjust 'lim' for A_STR when u.uhs was
594.                    WEAK or worse, but that's handled via ATEMP(A_STR) now */
595.                 if (ABASE(i) < lim) {
596.                     ABASE(i) = lim;
597.                     context.botl = 1;
598.                     /* only first found if not blessed */
599.                     if (!otmp->blessed)
600.                         break;
601.                 }
602.                 if (++i >= A_MAX)
603.                     i = 0;
604.             }
605. 
606.             /* when using the potion (not the spell) also restore lost levels,
607.                to make the potion more worth keeping around for players with
608.                the spell or with a unihorn; this is better than full healing
609.                in that it can restore all of them, not just half, and a
610.                blessed potion restores them all at once */
611.             if (otmp->otyp == POT_RESTORE_ABILITY && u.ulevel < u.ulevelmax) {
612.                 do {
613.                     pluslvl(FALSE);
614.                 } while (u.ulevel < u.ulevelmax && otmp->blessed);
615.             }
616.         }
617.         break;
618.     case POT_HALLUCINATION:
619.         if (Hallucination || Halluc_resistance)
620.             nothing++;
621.         (void) make_hallucinated(itimeout_incr(HHallucination,
622.                                           rn1(200, 600 - 300 * bcsign(otmp))),
623.                                  TRUE, 0L);
624.         break;
625.     case POT_WATER:
626.         if (!otmp->blessed && !otmp->cursed) {
627.             pline("This tastes like %s.", hliquid("water"));
628.             u.uhunger += rnd(10);
629.             newuhs(FALSE);
630.             break;
631.         }
632.         unkn++;
633.         if (is_undead(youmonst.data) || is_demon(youmonst.data)
634.             || u.ualign.type == A_CHAOTIC) {
635.             if (otmp->blessed) {
636.                 pline("This burns like %s!", hliquid("acid"));
637.                 exercise(A_CON, FALSE);
638.                 if (u.ulycn >= LOW_PM) {
639.                     Your("affinity to %s disappears!",
640.                          makeplural(mons[u.ulycn].mname));
641.                     if (youmonst.data == &mons[u.ulycn])
642.                         you_unwere(FALSE);
643.                     set_ulycn(NON_PM); /* cure lycanthropy */
644.                 }
645.                 losehp(Maybe_Half_Phys(d(2, 6)), "potion of holy water",
646.                        KILLED_BY_AN);
647.             } else if (otmp->cursed) {
648.                 You_feel("quite proud of yourself.");
649.                 healup(d(2, 6), 0, 0, 0);
650.                 if (u.ulycn >= LOW_PM && !Upolyd)
651.                     you_were();
652.                 exercise(A_CON, TRUE);
653.             }
654.         } else {
655.             if (otmp->blessed) {
656.                 You_feel("full of awe.");
657.                 make_sick(0L, (char *) 0, TRUE, SICK_ALL);
658.                 exercise(A_WIS, TRUE);
659.                 exercise(A_CON, TRUE);
660.                 if (u.ulycn >= LOW_PM)
661.                     you_unwere(TRUE); /* "Purified" */
662.                 /* make_confused(0L, TRUE); */
663.             } else {
664.                 if (u.ualign.type == A_LAWFUL) {
665.                     pline("This burns like %s!", hliquid("acid"));
666.                     losehp(Maybe_Half_Phys(d(2, 6)), "potion of unholy water",
667.                            KILLED_BY_AN);
668.                 } else
669.                     You_feel("full of dread.");
670.                 if (u.ulycn >= LOW_PM && !Upolyd)
671.                     you_were();
672.                 exercise(A_CON, FALSE);
673.             }
674.         }
675.         break;
676.     case POT_BOOZE:
677.         unkn++;
678.         pline("Ooph!  This tastes like %s%s!",
679.               otmp->odiluted ? "watered down " : "",
680.               Hallucination ? "dandelion wine" : "liquid fire");
681.         if (!otmp->blessed)
682.             make_confused(itimeout_incr(HConfusion, d(3, 8)), FALSE);
683.         /* the whiskey makes us feel better */
684.         if (!otmp->odiluted)
685.             healup(1, 0, FALSE, FALSE);
686.         u.uhunger += 10 * (2 + bcsign(otmp));
687.         newuhs(FALSE);
688.         exercise(A_WIS, FALSE);
689.         if (otmp->cursed) {
690.             You("pass out.");
691.             multi = -rnd(15);
692.             nomovemsg = "You awake with a headache.";
693.         }
694.         break;
695.     case POT_ENLIGHTENMENT:
696.         if (otmp->cursed) {
697.             unkn++;
698.             You("have an uneasy feeling...");
699.             exercise(A_WIS, FALSE);
700.         } else {
701.             if (otmp->blessed) {
702.                 (void) adjattrib(A_INT, 1, FALSE);
703.                 (void) adjattrib(A_WIS, 1, FALSE);
704.             }
705.             You_feel("self-knowledgeable...");
706.             display_nhwindow(WIN_MESSAGE, FALSE);
707.             enlightenment(MAGICENLIGHTENMENT, ENL_GAMEINPROGRESS);
708.             pline_The("feeling subsides.");
709.             exercise(A_WIS, TRUE);
710.         }
711.         break;
712.     case SPE_INVISIBILITY:
713.         /* spell cannot penetrate mummy wrapping */
714.         if (BInvis && uarmc->otyp == MUMMY_WRAPPING) {
715.             You_feel("rather itchy under %s.", yname(uarmc));
716.             break;
717.         }
718.         /* FALLTHRU */
719.     case POT_INVISIBILITY:
720.         if (Invis || Blind || BInvis) {
721.             nothing++;
722.         } else {
723.             self_invis_message();
724.         }
725.         if (otmp->blessed)
726.             HInvis |= FROMOUTSIDE;
727.         else
728.             incr_itimeout(&HInvis, rn1(15, 31));
729.         newsym(u.ux, u.uy); /* update position */
730.         if (otmp->cursed) {
731.             pline("For some reason, you feel your presence is known.");
732.             aggravate();
733.         }
734.         break;
735.     case POT_SEE_INVISIBLE: /* tastes like fruit juice in Rogue */
736.     case POT_FRUIT_JUICE: {
737.         int msg = Invisible && !Blind;
738. 
739.         unkn++;
740.         if (otmp->cursed)
741.             pline("Yecch!  This tastes %s.",
742.                   Hallucination ? "overripe" : "rotten");
743.         else
744.             pline(
745.                 Hallucination
746.                     ? "This tastes like 10%% real %s%s all-natural beverage."
747.                     : "This tastes like %s%s.",
748.                 otmp->odiluted ? "reconstituted " : "", fruitname(TRUE));
749.         if (otmp->otyp == POT_FRUIT_JUICE) {
750.             u.uhunger += (otmp->odiluted ? 5 : 10) * (2 + bcsign(otmp));
751.             newuhs(FALSE);
752.             break;
753.         }
754.         if (!otmp->cursed) {
755.             /* Tell them they can see again immediately, which
756.              * will help them identify the potion...
757.              */
758.             make_blinded(0L, TRUE);
759.         }
760.         if (otmp->blessed)
761.             HSee_invisible |= FROMOUTSIDE;
762.         else
763.             incr_itimeout(&HSee_invisible, rn1(100, 750));
764.         set_mimic_blocking(); /* do special mimic handling */
765.         see_monsters();       /* see invisible monsters */
766.         newsym(u.ux, u.uy);   /* see yourself! */
767.         if (msg && !Blind) {  /* Blind possible if polymorphed */
768.             You("can see through yourself, but you are visible!");
769.             unkn--;
770.         }
771.         break;
772.     }
773.     case POT_PARALYSIS:
774.         if (Free_action) {
775.             You("stiffen momentarily.");
776.         } else {
777.             if (Levitation || Is_airlevel(&u.uz) || Is_waterlevel(&u.uz))
778.                 You("are motionlessly suspended.");
779.             else if (u.usteed)
780.                 You("are frozen in place!");
781.             else
782.                 Your("%s are frozen to the %s!", makeplural(body_part(FOOT)),
783.                      surface(u.ux, u.uy));
784.             nomul(-(rn1(10, 25 - 12 * bcsign(otmp))));
785.             multi_reason = "frozen by a potion";
786.             nomovemsg = You_can_move_again;
787.             exercise(A_DEX, FALSE);
788.         }
789.         break;
790.     case POT_SLEEPING:
791.         if (Sleep_resistance || Free_action) {
792.             You("yawn.");
793.         } else {
794.             You("suddenly fall asleep!");
795.             fall_asleep(-rn1(10, 25 - 12 * bcsign(otmp)), TRUE);
796.         }
797.         break;
798.     case POT_MONSTER_DETECTION:
799.     case SPE_DETECT_MONSTERS:
800.         if (otmp->blessed) {
801.             int x, y;
802. 
803.             if (Detect_monsters)
804.                 nothing++;
805.             unkn++;
806.             /* after a while, repeated uses become less effective */
807.             if ((HDetect_monsters & TIMEOUT) >= 300L)
808.                 i = 1;
809.             else
810.                 i = rn1(40, 21);
811.             incr_itimeout(&HDetect_monsters, i);
812.             for (x = 1; x < COLNO; x++) {
813.                 for (y = 0; y < ROWNO; y++) {
814.                     if (levl[x][y].glyph == GLYPH_INVISIBLE) {
815.                         unmap_object(x, y);
816.                         newsym(x, y);
817.                     }
818.                     if (MON_AT(x, y))
819.                         unkn = 0;
820.                 }
821.             }
822.             see_monsters();
823.             if (unkn)
824.                 You_feel("lonely.");
825.             break;
826.         }
827.         if (monster_detect(otmp, 0))
828.             return 1; /* nothing detected */
829.         exercise(A_WIS, TRUE);
830.         break;
831.     case POT_OBJECT_DETECTION:
832.     case SPE_DETECT_TREASURE:
833.         if (object_detect(otmp, 0))
834.             return 1; /* nothing detected */
835.         exercise(A_WIS, TRUE);
836.         break;
837.     case POT_SICKNESS:
838.         pline("Yecch!  This stuff tastes like poison.");
839.         if (otmp->blessed) {
840.             pline("(But in fact it was mildly stale %s.)", fruitname(TRUE));
841.             if (!Role_if(PM_HEALER)) {
842.                 /* NB: blessed otmp->fromsink is not possible */
843.                 losehp(1, "mildly contaminated potion", KILLED_BY_AN);
844.             }
845.         } else {
846.             if (Poison_resistance)
847.                 pline("(But in fact it was biologically contaminated %s.)",
848.                       fruitname(TRUE));
849.             if (Role_if(PM_HEALER)) {
850.                 pline("Fortunately, you have been immunized.");
851.             } else {
852.                 char contaminant[BUFSZ];
853.                 int typ = rn2(A_MAX);
854. 
855.                 Sprintf(contaminant, "%s%s",
856.                         (Poison_resistance) ? "mildly " : "",
857.                         (otmp->fromsink) ? "contaminated tap water"
858.                                          : "contaminated potion");
859.                 if (!Fixed_abil) {
860.                     poisontell(typ, FALSE);
861.                     (void) adjattrib(typ, Poison_resistance ? -1 : -rn1(4, 3),
862.                                      1);
863.                 }
864.                 if (!Poison_resistance) {
865.                     if (otmp->fromsink)
866.                         losehp(rnd(10) + 5 * !!(otmp->cursed), contaminant,
867.                                KILLED_BY);
868.                     else
869.                         losehp(rnd(10) + 5 * !!(otmp->cursed), contaminant,
870.                                KILLED_BY_AN);
871.                 } else {
872.                     /* rnd loss is so that unblessed poorer than blessed */
873.                     losehp(1 + rn2(2), contaminant,
874.                            (otmp->fromsink) ? KILLED_BY : KILLED_BY_AN);
875.                 }
876.                 exercise(A_CON, FALSE);
877.             }
878.         }
879.         if (Hallucination) {
880.             You("are shocked back to your senses!");
881.             (void) make_hallucinated(0L, FALSE, 0L);
882.         }
883.         break;
884.     case POT_CONFUSION:
885.         if (!Confusion) {
886.             if (Hallucination) {
887.                 pline("What a trippy feeling!");
888.                 unkn++;
889.             } else
890.                 pline("Huh, What?  Where am I?");
891.         } else
892.             nothing++;
893.         make_confused(itimeout_incr(HConfusion,
894.                                     rn1(7, 16 - 8 * bcsign(otmp))),
895.                       FALSE);
896.         break;
897.     case POT_GAIN_ABILITY:
898.         if (otmp->cursed) {
899.             pline("Ulch!  That potion tasted foul!");
900.             unkn++;
901.         } else if (Fixed_abil) {
902.             nothing++;
903.         } else {      /* If blessed, increase all; if not, try up to */
904.             int itmp; /* 6 times to find one which can be increased. */
905. 
906.             i = -1;   /* increment to 0 */
907.             for (ii = A_MAX; ii > 0; ii--) {
908.                 i = (otmp->blessed ? i + 1 : rn2(A_MAX));
909.                 /* only give "your X is already as high as it can get"
910.                    message on last attempt (except blessed potions) */
911.                 itmp = (otmp->blessed || ii == 1) ? 0 : -1;
912.                 if (adjattrib(i, 1, itmp) && !otmp->blessed)
913.                     break;
914.             }
915.         }
916.         break;
917.     case POT_SPEED:
918.         /* skip when mounted; heal_legs() would heal steed's legs */
919.         if (Wounded_legs && !otmp->cursed && !u.usteed) {
920.             heal_legs(0);
921.             unkn++;
922.             break;
923.         }
924.         /* FALLTHRU */
925.     case SPE_HASTE_SELF:
926.         if (!Very_fast) { /* wwf@doe.carleton.ca */
927.             You("are suddenly moving %sfaster.", Fast ? "" : "much ");
928.         } else {
929.             Your("%s get new energy.", makeplural(body_part(LEG)));
930.             unkn++;
931.         }
932.         exercise(A_DEX, TRUE);
933.         incr_itimeout(&HFast, rn1(10, 100 + 60 * bcsign(otmp)));
934.         break;
935.     case POT_BLINDNESS:
936.         if (Blind)
937.             nothing++;
938.         make_blinded(itimeout_incr(Blinded,
939.                                    rn1(200, 250 - 125 * bcsign(otmp))),
940.                      (boolean) !Blind);
941.         break;
942.     case POT_GAIN_LEVEL:
943.         if (otmp->cursed) {
944.             unkn++;
945.             /* they went up a level */
946.             if ((ledger_no(&u.uz) == 1 && u.uhave.amulet)
947.                 || Can_rise_up(u.ux, u.uy, &u.uz)) {
948.                 const char *riseup = "rise up, through the %s!";
949. 
950.                 if (ledger_no(&u.uz) == 1) {
951.                     You(riseup, ceiling(u.ux, u.uy));
952.                     goto_level(&earth_level, FALSE, FALSE, FALSE);
953.                 } else {
954.                     register int newlev = depth(&u.uz) - 1;
955.                     d_level newlevel;
956. 
957.                     get_level(&newlevel, newlev);
958.                     if (on_level(&newlevel, &u.uz)) {
959.                         pline("It tasted bad.");
960.                         break;
961.                     } else
962.                         You(riseup, ceiling(u.ux, u.uy));
963.                     goto_level(&newlevel, FALSE, FALSE, FALSE);
964.                 }
965.             } else
966.                 You("have an uneasy feeling.");
967.             break;
968.         }
969.         pluslvl(FALSE);
970.         /* blessed potions place you at a random spot in the
971.            middle of the new level instead of the low point */
972.         if (otmp->blessed)
973.             u.uexp = rndexp(TRUE);
974.         break;
975.     case POT_HEALING:
976.         You_feel("better.");
977.         healup(d(6 + 2 * bcsign(otmp), 4), !otmp->cursed ? 1 : 0,
978.                !!otmp->blessed, !otmp->cursed);
979.         exercise(A_CON, TRUE);
980.         break;
981.     case POT_EXTRA_HEALING:
982.         You_feel("much better.");
983.         healup(d(6 + 2 * bcsign(otmp), 8),
984.                otmp->blessed ? 5 : !otmp->cursed ? 2 : 0, !otmp->cursed,
985.                TRUE);
986.         (void) make_hallucinated(0L, TRUE, 0L);
987.         exercise(A_CON, TRUE);
988.         exercise(A_STR, TRUE);
989.         break;
990.     case POT_FULL_HEALING:
991.         You_feel("completely healed.");
992.         healup(400, 4 + 4 * bcsign(otmp), !otmp->cursed, TRUE);
993.         /* Restore one lost level if blessed */
994.         if (otmp->blessed && u.ulevel < u.ulevelmax) {
995.             /* when multiple levels have been lost, drinking
996.                multiple potions will only get half of them back */
997.             u.ulevelmax -= 1;
998.             pluslvl(FALSE);
999.         }
1000.         (void) make_hallucinated(0L, TRUE, 0L);
1001.         exercise(A_STR, TRUE);
1002.         exercise(A_CON, TRUE);
1003.         break;
1004.     case POT_LEVITATION:
1005.     case SPE_LEVITATION:
1006.         /*
1007.          * BLevitation will be set if levitation is blocked due to being
1008.          * inside rock (currently or formerly in phazing xorn form, perhaps)
1009.          * but it doesn't prevent setting or incrementing Levitation timeout
1010.          * (which will take effect after escaping from the rock if it hasn't
1011.          * expired by then).
1012.          */
1013.         if (!Levitation && !BLevitation) {
1014.             /* kludge to ensure proper operation of float_up() */
1015.             set_itimeout(&HLevitation, 1L);
1016.             float_up();
1017.             /* This used to set timeout back to 0, then increment it below
1018.                for blessed and uncursed effects.  But now we leave it so
1019.                that cursed effect yields "you float down" on next turn.
1020.                Blessed and uncursed get one extra turn duration. */
1021.         } else /* already levitating, or can't levitate */
1022.             nothing++;
1023. 
1024.         if (otmp->cursed) {
1025.             /* 'already levitating' used to block the cursed effect(s)
1026.                aside from ~I_SPECIAL; it was not clear whether that was
1027.                intentional; either way, it no longer does (as of 3.6.1) */
1028.             HLevitation &= ~I_SPECIAL; /* can't descend upon demand */
1029.             if (BLevitation) {
1030.                 ; /* rising via levitation is blocked */
1031.             } else if ((u.ux == xupstair && u.uy == yupstair)
1032.                     || (sstairs.up && u.ux == sstairs.sx && u.uy == sstairs.sy)
1033.                     || (xupladder && u.ux == xupladder && u.uy == yupladder)) {
1034.                 (void) doup();
1035.                 /* in case we're already Levitating, which would have
1036.                    resulted in incrementing 'nothing' */
1037.                 nothing = 0; /* not nothing after all */
1038.             } else if (has_ceiling(&u.uz)) {
1039.                 int dmg = rnd(!uarmh ? 10 : !is_metallic(uarmh) ? 6 : 3);
1040. 
1041.                 You("hit your %s on the %s.", body_part(HEAD),
1042.                     ceiling(u.ux, u.uy));
1043.                 losehp(Maybe_Half_Phys(dmg), "colliding with the ceiling",
1044.                        KILLED_BY);
1045.                 nothing = 0; /* not nothing after all */
1046.             }
1047.         } else if (otmp->blessed) {
1048.             /* at this point, timeout is already at least 1 */
1049.             incr_itimeout(&HLevitation, rn1(50, 250));
1050.             /* can descend at will (stop levitating via '>') provided timeout
1051.                is the only factor (ie, not also wearing Lev ring or boots) */
1052.             HLevitation |= I_SPECIAL;
1053.         } else /* timeout is already at least 1 */
1054.             incr_itimeout(&HLevitation, rn1(140, 10));
1055. 
1056.         if (Levitation && IS_SINK(levl[u.ux][u.uy].typ))
1057.             spoteffects(FALSE);
1058.         /* levitating blocks flying */
1059.         float_vs_flight();
1060.         break;
1061.     case POT_GAIN_ENERGY: { /* M. Stephenson */
1062.         int num;
1063. 
1064.         if (otmp->cursed)
1065.             You_feel("lackluster.");
1066.         else
1067.             pline("Magical energies course through your body.");
1068. 
1069.         /* old: num = rnd(5) + 5 * otmp->blessed + 1;
1070.          *      blessed:  +7..11 max & current (+9 avg)
1071.          *      uncursed: +2.. 6 max & current (+4 avg)
1072.          *      cursed:   -2.. 6 max & current (-4 avg)
1073.          * new: (3.6.0)
1074.          *      blessed:  +3..18 max (+10.5 avg), +9..54 current (+31.5 avg)
1075.          *      uncursed: +2..12 max (+ 7   avg), +6..36 current (+21   avg)
1076.          *      cursed:   -1.. 6 max (- 3.5 avg), -3..18 current (-10.5 avg)
1077.          */
1078.         num = d(otmp->blessed ? 3 : !otmp->cursed ? 2 : 1, 6);
1079.         if (otmp->cursed)
1080.             num = -num; /* subtract instead of add when cursed */
1081.         u.uenmax += num;
1082.         if (u.uenmax <= 0)
1083.             u.uenmax = 0;
1084.         u.uen += 3 * num;
1085.         if (u.uen > u.uenmax)
1086.             u.uen = u.uenmax;
1087.         else if (u.uen <= 0)
1088.             u.uen = 0;
1089.         context.botl = 1;
1090.         exercise(A_WIS, TRUE);
1091.         break;
1092.     }
1093.     case POT_OIL: { /* P. Winner */
1094.         boolean good_for_you = FALSE;
1095. 
1096.         if (otmp->lamplit) {
1097.             if (likes_fire(youmonst.data)) {
1098.                 pline("Ahh, a refreshing drink.");
1099.                 good_for_you = TRUE;
1100.             } else {
1101.                 You("burn your %s.", body_part(FACE));
1102.                 /* fire damage */
1103.                 losehp(d(Fire_resistance ? 1 : 3, 4), "burning potion of oil",
1104.                        KILLED_BY_AN);
1105.             }
1106.         } else if (otmp->cursed)
1107.             pline("This tastes like castor oil.");
1108.         else
1109.             pline("That was smooth!");
1110.         exercise(A_WIS, good_for_you);
1111.         break;
1112.     }
1113.     case POT_ACID:
1114.         if (Acid_resistance) {
1115.             /* Not necessarily a creature who _likes_ acid */
1116.             pline("This tastes %s.", Hallucination ? "tangy" : "sour");
1117.         } else {
1118.             int dmg;
1119. 
1120.             pline("This burns%s!",
1121.                   otmp->blessed ? " a little" : otmp->cursed ? " a lot"
1122.                                                              : " like acid");
1123.             dmg = d(otmp->cursed ? 2 : 1, otmp->blessed ? 4 : 8);
1124.             losehp(Maybe_Half_Phys(dmg), "potion of acid", KILLED_BY_AN);
1125.             exercise(A_CON, FALSE);
1126.         }
1127.         if (Stoned)
1128.             fix_petrification();
1129.         unkn++; /* holy/unholy water can burn like acid too */
1130.         break;
1131.     case POT_POLYMORPH:
1132.         You_feel("a little %s.", Hallucination ? "normal" : "strange");
1133.         if (!Unchanging)
1134.             polyself(0);
1135.         break;
1136.     default:
1137.         impossible("What a funny potion! (%u)", otmp->otyp);
1138.         return 0;
1139.     }
1140.     return -1;
1141. }
1142. 
1143. void
1144. healup(nhp, nxtra, curesick, cureblind)
1145. int nhp, nxtra;
1146. register boolean curesick, cureblind;
1147. {
1148.     if (nhp) {
1149.         if (Upolyd) {
1150.             u.mh += nhp;
1151.             if (u.mh > u.mhmax)
1152.                 u.mh = (u.mhmax += nxtra);
1153.         } else {
1154.             u.uhp += nhp;
1155.             if (u.uhp > u.uhpmax)
1156.                 u.uhp = (u.uhpmax += nxtra);
1157.         }
1158.     }
1159.     if (cureblind) {
1160.         /* 3.6.1: it's debatible whether healing magic should clean off
1161.            mundane 'dirt', but if it doesn't, blindness isn't cured */
1162.         u.ucreamed = 0;
1163.         make_blinded(0L, TRUE);
1164.         /* heal deafness too */
1165.         make_deaf(0L, TRUE);
1166.     }
1167.     if (curesick) {
1168.         make_vomiting(0L, TRUE);
1169.         make_sick(0L, (char *) 0, TRUE, SICK_ALL);
1170.     }
1171.     context.botl = 1;
1172.     return;
1173. }
1174. 
1175. void
1176. strange_feeling(obj, txt)
1177. struct obj *obj;
1178. const char *txt;
1179. {
1180.     if (flags.beginner || !txt)
1181.         You("have a %s feeling for a moment, then it passes.",
1182.             Hallucination ? "normal" : "strange");
1183.     else
1184.         pline1(txt);
1185. 
1186.     if (!obj) /* e.g., crystal ball finds no traps */
1187.         return;
1188. 
1189.     if (obj->dknown && !objects[obj->otyp].oc_name_known
1190.         && !objects[obj->otyp].oc_uname)
1191.         docall(obj);
1192. 
1193.     useup(obj);
1194. }
1195. 
1196. const char *bottlenames[] = { "bottle", "phial", "flagon", "carafe",
1197.                               "flask",  "jar",   "vial" };
1198. 
1199. const char *
1200. bottlename()
1201. {
1202.     return bottlenames[rn2(SIZE(bottlenames))];
1203. }
1204. 
1205. /* handle item dipped into water potion or steed saddle splashed by same */
1206. STATIC_OVL boolean
1207. H2Opotion_dip(potion, targobj, useeit, objphrase)
1208. struct obj *potion, *targobj;
1209. boolean useeit;
1210. const char *objphrase; /* "Your widget glows" or "Steed's saddle glows" */
1211. {
1212.     void FDECL((*func), (OBJ_P)) = 0;
1213.     const char *glowcolor = 0;
1214. #define COST_alter (-2)
1215. #define COST_none (-1)
1216.     int costchange = COST_none;
1217.     boolean altfmt = FALSE, res = FALSE;
1218. 
1219.     if (!potion || potion->otyp != POT_WATER)
1220.         return FALSE;
1221. 
1222.     if (potion->blessed) {
1223.         if (targobj->cursed) {
1224.             func = uncurse;
1225.             glowcolor = NH_AMBER;
1226.             costchange = COST_UNCURS;
1227.         } else if (!targobj->blessed) {
1228.             func = bless;
1229.             glowcolor = NH_LIGHT_BLUE;
1230.             costchange = COST_alter;
1231.             altfmt = TRUE; /* "with a <color> aura" */
1232.         }
1233.     } else if (potion->cursed) {
1234.         if (targobj->blessed) {
1235.             func = unbless;
1236.             glowcolor = "brown";
1237.             costchange = COST_UNBLSS;
1238.         } else if (!targobj->cursed) {
1239.             func = curse;
1240.             glowcolor = NH_BLACK;
1241.             costchange = COST_alter;
1242.             altfmt = TRUE;
1243.         }
1244.     } else {
1245.         /* dipping into uncursed water; carried() check skips steed saddle */
1246.         if (carried(targobj)) {
1247.             if (water_damage(targobj, 0, TRUE) != ER_NOTHING)
1248.                 res = TRUE;
1249.         }
1250.     }
1251.     if (func) {
1252.         /* give feedback before altering the target object;
1253.            this used to set obj->bknown even when not seeing
1254.            the effect; now hero has to see the glow, and bknown
1255.            is cleared instead of set if perception is distorted */
1256.         if (useeit) {
1257.             glowcolor = hcolor(glowcolor);
1258.             if (altfmt)
1259.                 pline("%s with %s aura.", objphrase, an(glowcolor));
1260.             else
1261.                 pline("%s %s.", objphrase, glowcolor);
1262.             iflags.last_msg = PLNMSG_OBJ_GLOWS;
1263.             targobj->bknown = !Hallucination;
1264.         }
1265.         /* potions of water are the only shop goods whose price depends
1266.            on their curse/bless state */
1267.         if (targobj->unpaid && targobj->otyp == POT_WATER) {
1268.             if (costchange == COST_alter)
1269.                 /* added blessing or cursing; update shop
1270.                    bill to reflect item's new higher price */
1271.                 alter_cost(targobj, 0L);
1272.             else if (costchange != COST_none)
1273.                 /* removed blessing or cursing; you
1274.                    degraded it, now you'll have to buy it... */
1275.                 costly_alteration(targobj, costchange);
1276.         }
1277.         /* finally, change curse/bless state */
1278.         (*func)(targobj);
1279.         res = TRUE;
1280.     }
1281.     return res;
1282. }
1283. 
1284. /* potion obj hits monster mon, which might be youmonst; obj always used up */
1285. void
1286. potionhit(mon, obj, how)
1287. struct monst *mon;
1288. struct obj *obj;
1289. int how;
1290. {
1291.     const char *botlnam = bottlename();
1292.     boolean isyou = (mon == &youmonst);
1293.     int distance, tx, ty;
1294.     struct obj *saddle = (struct obj *) 0;
1295.     boolean hit_saddle = FALSE, your_fault = (how <= POTHIT_HERO_THROW);
1296. 
1297.     if (isyou) {
1298.         tx = u.ux, ty = u.uy;
1299.         distance = 0;
1300.         pline_The("%s crashes on your %s and breaks into shards.", botlnam,
1301.                   body_part(HEAD));
1302.         losehp(Maybe_Half_Phys(rnd(2)),
1303.                (how == POTHIT_OTHER_THROW) ? "propelled potion" /* scatter */
1304.                                            : "thrown potion",
1305.                KILLED_BY_AN);
1306.     } else {
1307.         tx = mon->mx, ty = mon->my;
1308.         /* sometimes it hits the saddle */
1309.         if (((mon->misc_worn_check & W_SADDLE)
1310.              && (saddle = which_armor(mon, W_SADDLE)))
1311.             && (!rn2(10)
1312.                 || (obj->otyp == POT_WATER
1313.                     && ((rnl(10) > 7 && obj->cursed)
1314.                         || (rnl(10) < 4 && obj->blessed) || !rn2(3)))))
1315.             hit_saddle = TRUE;
1316.         distance = distu(tx, ty);
1317.         if (!cansee(tx, ty)) {
1318.             pline("Crash!");
1319.         } else {
1320.             char *mnam = mon_nam(mon);
1321.             char buf[BUFSZ];
1322. 
1323.             if (hit_saddle && saddle) {
1324.                 Sprintf(buf, "%s saddle",
1325.                         s_suffix(x_monnam(mon, ARTICLE_THE, (char *) 0,
1326.                                           (SUPPRESS_IT | SUPPRESS_SADDLE),
1327.                                           FALSE)));
1328.             } else if (has_head(mon->data)) {
1329.                 Sprintf(buf, "%s %s", s_suffix(mnam),
1330.                         (notonhead ? "body" : "head"));
1331.             } else {
1332.                 Strcpy(buf, mnam);
1333.             }
1334.             pline_The("%s crashes on %s and breaks into shards.", botlnam,
1335.                       buf);
1336.         }
1337.         if (rn2(5) && mon->mhp > 1 && !hit_saddle)
1338.             mon->mhp--;
1339.     }
1340. 
1341.     /* oil doesn't instantly evaporate; Neither does a saddle hit */
1342.     if (obj->otyp != POT_OIL && !hit_saddle && cansee(tx, ty))
1343.         pline("%s.", Tobjnam(obj, "evaporate"));
1344. 
1345.     if (isyou) {
1346.         switch (obj->otyp) {
1347.         case POT_OIL:
1348.             if (obj->lamplit)
1349.                 explode_oil(obj, u.ux, u.uy);
1350.             break;
1351.         case POT_POLYMORPH:
1352.             You_feel("a little %s.", Hallucination ? "normal" : "strange");
1353.             if (!Unchanging && !Antimagic)
1354.                 polyself(0);
1355.             break;
1356.         case POT_ACID:
1357.             if (!Acid_resistance) {
1358.                 int dmg;
1359. 
1360.                 pline("This burns%s!",
1361.                       obj->blessed ? " a little"
1362.                                    : obj->cursed ? " a lot" : "");
1363.                 dmg = d(obj->cursed ? 2 : 1, obj->blessed ? 4 : 8);
1364.                 losehp(Maybe_Half_Phys(dmg), "potion of acid", KILLED_BY_AN);
1365.             }
1366.             break;
1367.         }
1368.     } else if (hit_saddle && saddle) {
1369.         char *mnam, buf[BUFSZ], saddle_glows[BUFSZ];
1370.         boolean affected = FALSE;
1371.         boolean useeit = !Blind && canseemon(mon) && cansee(tx, ty);
1372. 
1373.         mnam = x_monnam(mon, ARTICLE_THE, (char *) 0,
1374.                         (SUPPRESS_IT | SUPPRESS_SADDLE), FALSE);
1375.         Sprintf(buf, "%s", upstart(s_suffix(mnam)));
1376. 
1377.         switch (obj->otyp) {
1378.         case POT_WATER:
1379.             Sprintf(saddle_glows, "%s %s", buf, aobjnam(saddle, "glow"));
1380.             affected = H2Opotion_dip(obj, saddle, useeit, saddle_glows);
1381.             break;
1382.         case POT_POLYMORPH:
1383.             /* Do we allow the saddle to polymorph? */
1384.             break;
1385.         }
1386.         if (useeit && !affected)
1387.             pline("%s %s wet.", buf, aobjnam(saddle, "get"));
1388.     } else {
1389.         boolean angermon = your_fault, cureblind = FALSE;
1390. 
1391.         switch (obj->otyp) {
1392.         case POT_FULL_HEALING:
1393.             cureblind = TRUE;
1394.             /*FALLTHRU*/
1395.         case POT_EXTRA_HEALING:
1396.             if (!obj->cursed)
1397.                 cureblind = TRUE;
1398.             /*FALLTHRU*/
1399.         case POT_HEALING:
1400.             if (obj->blessed)
1401.                 cureblind = TRUE;
1402.             if (mon->data == &mons[PM_PESTILENCE])
1403.                 goto do_illness;
1404.             /*FALLTHRU*/
1405.         case POT_RESTORE_ABILITY:
1406.         case POT_GAIN_ABILITY:
1407.  do_healing:
1408.             angermon = FALSE;
1409.             if (mon->mhp < mon->mhpmax) {
1410.                 mon->mhp = mon->mhpmax;
1411.                 if (canseemon(mon))
1412.                     pline("%s looks sound and hale again.", Monnam(mon));
1413.             }
1414.             if (cureblind)
1415.                 mcureblindness(mon, canseemon(mon));
1416.             break;
1417.         case POT_SICKNESS:
1418.             if (mon->data == &mons[PM_PESTILENCE])
1419.                 goto do_healing;
1420.             if (dmgtype(mon->data, AD_DISE)
1421.                 /* won't happen, see prior goto */
1422.                 || dmgtype(mon->data, AD_PEST)
1423.                 /* most common case */
1424.                 || resists_poison(mon)) {
1425.                 if (canseemon(mon))
1426.                     pline("%s looks unharmed.", Monnam(mon));
1427.                 break;
1428.             }
1429.  do_illness:
1430.             if ((mon->mhpmax > 3) && !resist(mon, POTION_CLASS, 0, NOTELL))
1431.                 mon->mhpmax /= 2;
1432.             if ((mon->mhp > 2) && !resist(mon, POTION_CLASS, 0, NOTELL))
1433.                 mon->mhp /= 2;
1434.             if (mon->mhp > mon->mhpmax)
1435.                 mon->mhp = mon->mhpmax;
1436.             if (canseemon(mon))
1437.                 pline("%s looks rather ill.", Monnam(mon));
1438.             break;
1439.         case POT_CONFUSION:
1440.         case POT_BOOZE:
1441.             if (!resist(mon, POTION_CLASS, 0, NOTELL))
1442.                 mon->mconf = TRUE;
1443.             break;
1444.         case POT_INVISIBILITY: {
1445.             boolean sawit = canspotmon(mon);
1446. 
1447.             angermon = FALSE;
1448.             mon_set_minvis(mon);
1449.             if (sawit && !canspotmon(mon) && cansee(mon->mx, mon->my))
1450.                 map_invisible(mon->mx, mon->my);
1451.             break;
1452.         }
1453.         case POT_SLEEPING:
1454.             /* wakeup() doesn't rouse victims of temporary sleep */
1455.             if (sleep_monst(mon, rnd(12), POTION_CLASS)) {
1456.                 pline("%s falls asleep.", Monnam(mon));
1457.                 slept_monst(mon);
1458.             }
1459.             break;
1460.         case POT_PARALYSIS:
1461.             if (mon->mcanmove) {
1462.                 /* really should be rnd(5) for consistency with players
1463.                  * breathing potions, but...
1464.                  */
1465.                 paralyze_monst(mon, rnd(25));
1466.             }
1467.             break;
1468.         case POT_SPEED:
1469.             angermon = FALSE;
1470.             mon_adjust_speed(mon, 1, obj);
1471.             break;
1472.         case POT_BLINDNESS:
1473.             if (haseyes(mon->data)) {
1474.                 int btmp = 64 + rn2(32)
1475.                             + rn2(32) * !resist(mon, POTION_CLASS, 0, NOTELL);
1476. 
1477.                 btmp += mon->mblinded;
1478.                 mon->mblinded = min(btmp, 127);
1479.                 mon->mcansee = 0;
1480.             }
1481.             break;
1482.         case POT_WATER:
1483.             if (is_undead(mon->data) || is_demon(mon->data)
1484.                 || is_were(mon->data) || is_vampshifter(mon)) {
1485.                 if (obj->blessed) {
1486.                     pline("%s %s in pain!", Monnam(mon),
1487.                           is_silent(mon->data) ? "writhes" : "shrieks");
1488.                     if (!is_silent(mon->data))
1489.                         wake_nearto(tx, ty, mon->data->mlevel * 10);
1490.                     mon->mhp -= d(2, 6);
1491.                     /* should only be by you */
1492.                     if (DEADMONSTER(mon))
1493.                         killed(mon);
1494.                     else if (is_were(mon->data) && !is_human(mon->data))
1495.                         new_were(mon); /* revert to human */
1496.                 } else if (obj->cursed) {
1497.                     angermon = FALSE;
1498.                     if (canseemon(mon))
1499.                         pline("%s looks healthier.", Monnam(mon));
1500.                     mon->mhp += d(2, 6);
1501.                     if (mon->mhp > mon->mhpmax)
1502.                         mon->mhp = mon->mhpmax;
1503.                     if (is_were(mon->data) && is_human(mon->data)
1504.                         && !Protection_from_shape_changers)
1505.                         new_were(mon); /* transform into beast */
1506.                 }
1507.             } else if (mon->data == &mons[PM_GREMLIN]) {
1508.                 angermon = FALSE;
1509.                 (void) split_mon(mon, (struct monst *) 0);
1510.             } else if (mon->data == &mons[PM_IRON_GOLEM]) {
1511.                 if (canseemon(mon))
1512.                     pline("%s rusts.", Monnam(mon));
1513.                 mon->mhp -= d(1, 6);
1514.                 /* should only be by you */
1515.                 if (DEADMONSTER(mon))
1516.                     killed(mon);
1517.             }
1518.             break;
1519.         case POT_OIL:
1520.             if (obj->lamplit)
1521.                 explode_oil(obj, tx, ty);
1522.             break;
1523.         case POT_ACID:
1524.             if (!resists_acid(mon) && !resist(mon, POTION_CLASS, 0, NOTELL)) {
1525.                 pline("%s %s in pain!", Monnam(mon),
1526.                       is_silent(mon->data) ? "writhes" : "shrieks");
1527.                 if (!is_silent(mon->data))
1528.                     wake_nearto(tx, ty, mon->data->mlevel * 10);
1529.                 mon->mhp -= d(obj->cursed ? 2 : 1, obj->blessed ? 4 : 8);
1530.                 if (DEADMONSTER(mon)) {
1531.                     if (your_fault)
1532.                         killed(mon);
1533.                     else
1534.                         monkilled(mon, "", AD_ACID);
1535.                 }
1536.             }
1537.             break;
1538.         case POT_POLYMORPH:
1539.             (void) bhitm(mon, obj);
1540.             break;
1541.         /*
1542.         case POT_GAIN_LEVEL:
1543.         case POT_LEVITATION:
1544.         case POT_FRUIT_JUICE:
1545.         case POT_MONSTER_DETECTION:
1546.         case POT_OBJECT_DETECTION:
1547.             break;
1548.         */
1549.         }
1550.         /* target might have been killed */
1551.         if (!DEADMONSTER(mon)) {
1552.             if (angermon)
1553.                 wakeup(mon, TRUE);
1554.             else
1555.                 mon->msleeping = 0;
1556.         }
1557.     }
1558. 
1559.     /* Note: potionbreathe() does its own docall() */
1560.     if ((distance == 0 || (distance < 3 && rn2(5)))
1561.         && (!breathless(youmonst.data) || haseyes(youmonst.data)))
1562.         potionbreathe(obj);
1563.     else if (obj->dknown && !objects[obj->otyp].oc_name_known
1564.              && !objects[obj->otyp].oc_uname && cansee(tx, ty))
1565.         docall(obj);
1566. 
1567.     if (*u.ushops && obj->unpaid) {
1568.         struct monst *shkp = shop_keeper(*in_rooms(u.ux, u.uy, SHOPBASE));
1569. 
1570.         /* neither of the first two cases should be able to happen;
1571.            only the hero should ever have an unpaid item, and only
1572.            when inside a tended shop */
1573.         if (!shkp) /* if shkp was killed, unpaid ought to cleared already */
1574.             obj->unpaid = 0;
1575.         else if (context.mon_moving) /* obj thrown by monster */
1576.             subfrombill(obj, shkp);
1577.         else /* obj thrown by hero */
1578.             (void) stolen_value(obj, u.ux, u.uy, (boolean) shkp->mpeaceful,
1579.                                 FALSE);
1580.     }
1581.     obfree(obj, (struct obj *) 0);
1582. }
1583. 
1584. /* vapors are inhaled or get in your eyes */
1585. void
1586. potionbreathe(obj)
1587. register struct obj *obj;
1588. {
1589.     int i, ii, isdone, kn = 0;
1590.     boolean cureblind = FALSE;
1591. 
1592.     /* potion of unholy water might be wielded; prevent
1593.        you_were() -> drop_weapon() from dropping it so that it
1594.        remains in inventory where our caller expects it to be */
1595.     obj->in_use = 1;
1596. 
1597.     switch (obj->otyp) {
1598.     case POT_RESTORE_ABILITY:
1599.     case POT_GAIN_ABILITY:
1600.         if (obj->cursed) {
1601.             if (!breathless(youmonst.data))
1602.                 pline("Ulch!  That potion smells terrible!");
1603.             else if (haseyes(youmonst.data)) {
1604.                 const char *eyes = body_part(EYE);
1605. 
1606.                 if (eyecount(youmonst.data) != 1)
1607.                     eyes = makeplural(eyes);
1608.                 Your("%s %s!", eyes, vtense(eyes, "sting"));
1609.             }
1610.             break;
1611.         } else {
1612.             i = rn2(A_MAX); /* start at a random point */
1613.             for (isdone = ii = 0; !isdone && ii < A_MAX; ii++) {
1614.                 if (ABASE(i) < AMAX(i)) {
1615.                     ABASE(i)++;
1616.                     /* only first found if not blessed */
1617.                     isdone = !(obj->blessed);
1618.                     context.botl = 1;
1619.                 }
1620.                 if (++i >= A_MAX)
1621.                     i = 0;
1622.             }
1623.         }
1624.         break;
1625.     case POT_FULL_HEALING:
1626.         if (Upolyd && u.mh < u.mhmax)
1627.             u.mh++, context.botl = 1;
1628.         if (u.uhp < u.uhpmax)
1629.             u.uhp++, context.botl = 1;
1630.         cureblind = TRUE;
1631.         /*FALLTHRU*/
1632.     case POT_EXTRA_HEALING:
1633.         if (Upolyd && u.mh < u.mhmax)
1634.             u.mh++, context.botl = 1;
1635.         if (u.uhp < u.uhpmax)
1636.             u.uhp++, context.botl = 1;
1637.         if (!obj->cursed)
1638.             cureblind = TRUE;
1639.         /*FALLTHRU*/
1640.     case POT_HEALING:
1641.         if (Upolyd && u.mh < u.mhmax)
1642.             u.mh++, context.botl = 1;
1643.         if (u.uhp < u.uhpmax)
1644.             u.uhp++, context.botl = 1;
1645.         if (obj->blessed)
1646.             cureblind = TRUE;
1647.         if (cureblind) {
1648.             make_blinded(0L, !u.ucreamed);
1649.             make_deaf(0L, TRUE);
1650.         }
1651.         exercise(A_CON, TRUE);
1652.         break;
1653.     case POT_SICKNESS:
1654.         if (!Role_if(PM_HEALER)) {
1655.             if (Upolyd) {
1656.                 if (u.mh <= 5)
1657.                     u.mh = 1;
1658.                 else
1659.                     u.mh -= 5;
1660.             } else {
1661.                 if (u.uhp <= 5)
1662.                     u.uhp = 1;
1663.                 else
1664.                     u.uhp -= 5;
1665.             }
1666.             context.botl = 1;
1667.             exercise(A_CON, FALSE);
1668.         }
1669.         break;
1670.     case POT_HALLUCINATION:
1671.         You("have a momentary vision.");
1672.         break;
1673.     case POT_CONFUSION:
1674.     case POT_BOOZE:
1675.         if (!Confusion)
1676.             You_feel("somewhat dizzy.");
1677.         make_confused(itimeout_incr(HConfusion, rnd(5)), FALSE);
1678.         break;
1679.     case POT_INVISIBILITY:
1680.         if (!Blind && !Invis) {
1681.             kn++;
1682.             pline("For an instant you %s!",
1683.                   See_invisible ? "could see right through yourself"
1684.                                 : "couldn't see yourself");
1685.         }
1686.         break;
1687.     case POT_PARALYSIS:
1688.         kn++;
1689.         if (!Free_action) {
1690.             pline("%s seems to be holding you.", Something);
1691.             nomul(-rnd(5));
1692.             multi_reason = "frozen by a potion";
1693.             nomovemsg = You_can_move_again;
1694.             exercise(A_DEX, FALSE);
1695.         } else
1696.             You("stiffen momentarily.");
1697.         break;
1698.     case POT_SLEEPING:
1699.         kn++;
1700.         if (!Free_action && !Sleep_resistance) {
1701.             You_feel("rather tired.");
1702.             nomul(-rnd(5));
1703.             multi_reason = "sleeping off a magical draught";
1704.             nomovemsg = You_can_move_again;
1705.             exercise(A_DEX, FALSE);
1706.         } else
1707.             You("yawn.");
1708.         break;
1709.     case POT_SPEED:
1710.         if (!Fast)
1711.             Your("knees seem more flexible now.");
1712.         incr_itimeout(&HFast, rnd(5));
1713.         exercise(A_DEX, TRUE);
1714.         break;
1715.     case POT_BLINDNESS:
1716.         if (!Blind && !Unaware) {
1717.             kn++;
1718.             pline("It suddenly gets dark.");
1719.         }
1720.         make_blinded(itimeout_incr(Blinded, rnd(5)), FALSE);
1721.         if (!Blind && !Unaware)
1722.             Your1(vision_clears);
1723.         break;
1724.     case POT_WATER:
1725.         if (u.umonnum == PM_GREMLIN) {
1726.             (void) split_mon(&youmonst, (struct monst *) 0);
1727.         } else if (u.ulycn >= LOW_PM) {
1728.             /* vapor from [un]holy water will trigger
1729.                transformation but won't cure lycanthropy */
1730.             if (obj->blessed && youmonst.data == &mons[u.ulycn])
1731.                 you_unwere(FALSE);
1732.             else if (obj->cursed && !Upolyd)
1733.                 you_were();
1734.         }
1735.         break;
1736.     case POT_ACID:
1737.     case POT_POLYMORPH:
1738.         exercise(A_CON, FALSE);
1739.         break;
1740.     /*
1741.     case POT_GAIN_LEVEL:
1742.     case POT_LEVITATION:
1743.     case POT_FRUIT_JUICE:
1744.     case POT_MONSTER_DETECTION:
1745.     case POT_OBJECT_DETECTION:
1746.     case POT_OIL:
1747.         break;
1748.      */
1749.     }
1750.     /* note: no obfree() -- that's our caller's responsibility */
1751.     if (obj->dknown) {
1752.         if (kn)
1753.             makeknown(obj->otyp);
1754.         else if (!objects[obj->otyp].oc_name_known
1755.                  && !objects[obj->otyp].oc_uname)
1756.             docall(obj);
1757.     }
1758. }
1759. 
1760. /* returns the potion type when o1 is dipped in o2 */
1761. STATIC_OVL short
1762. mixtype(o1, o2)
1763. register struct obj *o1, *o2;
1764. {
1765.     /* cut down on the number of cases below */
1766.     if (o1->oclass == POTION_CLASS
1767.         && (o2->otyp == POT_GAIN_LEVEL || o2->otyp == POT_GAIN_ENERGY
1768.             || o2->otyp == POT_HEALING || o2->otyp == POT_EXTRA_HEALING
1769.             || o2->otyp == POT_FULL_HEALING || o2->otyp == POT_ENLIGHTENMENT
1770.             || o2->otyp == POT_FRUIT_JUICE)) {
1771.         struct obj *swp;
1772. 
1773.         swp = o1;
1774.         o1 = o2;
1775.         o2 = swp;
1776.     }
1777. 
1778.     switch (o1->otyp) {
1779.     case POT_HEALING:
1780.         switch (o2->otyp) {
1781.         case POT_SPEED:
1782.         case POT_GAIN_LEVEL:
1783.         case POT_GAIN_ENERGY:
1784.             return POT_EXTRA_HEALING;
1785.         }
1786.     case POT_EXTRA_HEALING:
1787.         switch (o2->otyp) {
1788.         case POT_GAIN_LEVEL:
1789.         case POT_GAIN_ENERGY:
1790.             return POT_FULL_HEALING;
1791.         }
1792.     case POT_FULL_HEALING:
1793.         switch (o2->otyp) {
1794.         case POT_GAIN_LEVEL:
1795.         case POT_GAIN_ENERGY:
1796.             return POT_GAIN_ABILITY;
1797.         }
1798.     case UNICORN_HORN:
1799.         switch (o2->otyp) {
1800.         case POT_SICKNESS:
1801.             return POT_FRUIT_JUICE;
1802.         case POT_HALLUCINATION:
1803.         case POT_BLINDNESS:
1804.         case POT_CONFUSION:
1805.             return POT_WATER;
1806.         }
1807.         break;
1808.     case AMETHYST: /* "a-methyst" == "not intoxicated" */
1809.         if (o2->otyp == POT_BOOZE)
1810.             return POT_FRUIT_JUICE;
1811.         break;
1812.     case POT_GAIN_LEVEL:
1813.     case POT_GAIN_ENERGY:
1814.         switch (o2->otyp) {
1815.         case POT_CONFUSION:
1816.             return (rn2(3) ? POT_BOOZE : POT_ENLIGHTENMENT);
1817.         case POT_HEALING:
1818.             return POT_EXTRA_HEALING;
1819.         case POT_EXTRA_HEALING:
1820.             return POT_FULL_HEALING;
1821.         case POT_FULL_HEALING:
1822.             return POT_GAIN_ABILITY;
1823.         case POT_FRUIT_JUICE:
1824.             return POT_SEE_INVISIBLE;
1825.         case POT_BOOZE:
1826.             return POT_HALLUCINATION;
1827.         }
1828.         break;
1829.     case POT_FRUIT_JUICE:
1830.         switch (o2->otyp) {
1831.         case POT_SICKNESS:
1832.             return POT_SICKNESS;
1833.         case POT_ENLIGHTENMENT:
1834.         case POT_SPEED:
1835.             return POT_BOOZE;
1836.         case POT_GAIN_LEVEL:
1837.         case POT_GAIN_ENERGY:
1838.             return POT_SEE_INVISIBLE;
1839.         }
1840.         break;
1841.     case POT_ENLIGHTENMENT:
1842.         switch (o2->otyp) {
1843.         case POT_LEVITATION:
1844.             if (rn2(3))
1845.                 return POT_GAIN_LEVEL;
1846.             break;
1847.         case POT_FRUIT_JUICE:
1848.             return POT_BOOZE;
1849.         case POT_BOOZE:
1850.             return POT_CONFUSION;
1851.         }
1852.         break;
1853.     }
1854. 
1855.     return STRANGE_OBJECT;
1856. }
1857. 
1858. /* #dip command */
1859. int
1860. dodip()
1861. {
1862.     static const char Dip_[] = "Dip ";
1863.     register struct obj *potion, *obj;
1864.     struct obj *singlepotion;
1865.     uchar here;
1866.     char allowall[2];
1867.     short mixture;
1868.     char qbuf[QBUFSZ], obuf[QBUFSZ];
1869.     const char *shortestname; /* last resort obj name for prompt */
1870. 
1871.     allowall[0] = ALL_CLASSES;
1872.     allowall[1] = '\0';
1873.     if (!(obj = getobj(allowall, "dip")))
1874.         return 0;
1875.     if (inaccessible_equipment(obj, "dip", FALSE))
1876.         return 0;
1877. 
1878.     shortestname = (is_plural(obj) || pair_of(obj)) ? "them" : "it";
1879.     /*
1880.      * Bypass safe_qbuf() since it doesn't handle varying suffix without
1881.      * an awful lot of support work.  Format the object once, even though
1882.      * the fountain and pool prompts offer a lot more room for it.
1883.      * 3.6.0 used thesimpleoname() unconditionally, which posed no risk
1884.      * of buffer overflow but drew bug reports because it omits user-
1885.      * supplied type name.
1886.      * getobj: "What do you want to dip <the object> into? [xyz or ?*] "
1887.      */
1888.     Strcpy(obuf, short_oname(obj, doname, thesimpleoname,
1889.                              /* 128 - (24 + 54 + 1) leaves 49 for <object> */
1890.                              QBUFSZ - sizeof "What do you want to dip \
1891.  into? [abdeghjkmnpqstvwyzBCEFHIKLNOQRTUWXZ#-# or ?*] "));
1892. 
1893.     here = levl[u.ux][u.uy].typ;
1894.     /* Is there a fountain to dip into here? */
1895.     if (IS_FOUNTAIN(here)) {
1896.         Sprintf(qbuf, "%s%s into the fountain?", Dip_,
1897.                 flags.verbose ? obuf : shortestname);
1898.         /* "Dip <the object> into the fountain?" */
1899.         if (yn(qbuf) == 'y') {
1900.             dipfountain(obj);
1901.             return 1;
1902.         }
1903.     } else if (is_pool(u.ux, u.uy)) {
1904.         const char *pooltype = waterbody_name(u.ux, u.uy);
1905. 
1906.         Sprintf(qbuf, "%s%s into the %s?", Dip_,
1907.                 flags.verbose ? obuf : shortestname, pooltype);
1908.         /* "Dip <the object> into the {pool, moat, &c}?" */
1909.         if (yn(qbuf) == 'y') {
1910.             if (Levitation) {
1911.                 floating_above(pooltype);
1912.             } else if (u.usteed && !is_swimmer(u.usteed->data)
1913.                        && P_SKILL(P_RIDING) < P_BASIC) {
1914.                 rider_cant_reach(); /* not skilled enough to reach */
1915.             } else {
1916.                 if (obj->otyp == POT_ACID)
1917.                     obj->in_use = 1;
1918.                 if (water_damage(obj, 0, TRUE) != ER_DESTROYED && obj->in_use)
1919.                     useup(obj);
1920.             }
1921.             return 1;
1922.         }
1923.     }
1924. 
1925.     /* "What do you want to dip <the object> into? [xyz or ?*] " */
1926.     Sprintf(qbuf, "dip %s into", flags.verbose ? obuf : shortestname);
1927.     potion = getobj(beverages, qbuf);
1928.     if (!potion)
1929.         return 0;
1930.     if (potion == obj && potion->quan == 1L) {
1931.         pline("That is a potion bottle, not a Klein bottle!");
1932.         return 0;
1933.     }
1934.     potion->in_use = TRUE; /* assume it will be used up */
1935.     if (potion->otyp == POT_WATER) {
1936.         boolean useeit = !Blind || (obj == ublindf && Blindfolded_only);
1937.         const char *obj_glows = Yobjnam2(obj, "glow");
1938. 
1939.         if (H2Opotion_dip(potion, obj, useeit, obj_glows))
1940.             goto poof;
1941.     } else if (obj->otyp == POT_POLYMORPH || potion->otyp == POT_POLYMORPH) {
1942.         /* some objects can't be polymorphed */
1943.         if (obj->otyp == potion->otyp /* both POT_POLY */
1944.             || obj->otyp == WAN_POLYMORPH || obj->otyp == SPE_POLYMORPH
1945.             || obj == uball || obj == uskin
1946.             || obj_resists(obj->otyp == POT_POLYMORPH ? potion : obj,
1947.                            5, 95)) {
1948.             pline1(nothing_happens);
1949.         } else {
1950.             short save_otyp = obj->otyp;
1951. 
1952.             /* KMH, conduct */
1953.             u.uconduct.polypiles++;
1954. 
1955.             obj = poly_obj(obj, STRANGE_OBJECT);
1956. 
1957.             /*
1958.              * obj might be gone:
1959.              *  poly_obj() -> set_wear() -> Amulet_on() -> useup()
1960.              * if obj->otyp is worn amulet and becomes AMULET_OF_CHANGE.
1961.              */
1962.             if (!obj) {
1963.                 makeknown(POT_POLYMORPH);
1964.                 return 1;
1965.             } else if (obj->otyp != save_otyp) {
1966.                 makeknown(POT_POLYMORPH);
1967.                 useup(potion);
1968.                 prinv((char *) 0, obj, 0L);
1969.                 return 1;
1970.             } else {
1971.                 pline("Nothing seems to happen.");
1972.                 goto poof;
1973.             }
1974.         }
1975.         potion->in_use = FALSE; /* didn't go poof */
1976.         return 1;
1977.     } else if (obj->oclass == POTION_CLASS && obj->otyp != potion->otyp) {
1978.         int amt = (int) obj->quan;
1979.         boolean magic;
1980. 
1981.         mixture = mixtype(obj, potion);
1982. 
1983.         magic = (mixture != STRANGE_OBJECT) ? objects[mixture].oc_magic
1984.             : (objects[obj->otyp].oc_magic || objects[potion->otyp].oc_magic);
1985.         Strcpy(qbuf, "The"); /* assume full stack */
1986.         if (amt > (magic ? 3 : 7)) {
1987.             /* trying to dip multiple potions will usually affect only a
1988.                subset; pick an amount between 3 and 8, inclusive, for magic
1989.                potion result, between 7 and N for non-magic */
1990.             if (magic)
1991.                 amt = rnd(min(amt, 8) - (3 - 1)) + (3 - 1); /* 1..6 + 2 */
1992.             else
1993.                 amt = rnd(amt - (7 - 1)) + (7 - 1); /* 1..(N-6) + 6 */
1994. 
1995.             if ((long) amt < obj->quan) {
1996.                 obj = splitobj(obj, (long) amt);
1997.                 Sprintf(qbuf, "%ld of the", obj->quan);
1998.             }
1999.         }
2000.         /* [N of] the {obj(s)} mix(es) with [one of] {the potion}... */
2001.         pline("%s %s %s with %s%s...", qbuf, simpleonames(obj),
2002.               otense(obj, "mix"), (potion->quan > 1L) ? "one of " : "",
2003.               thesimpleoname(potion));
2004.         /* get rid of 'dippee' before potential perm_invent updates */
2005.         useup(potion); /* now gone */
2006.         /* Mixing potions is dangerous...
2007.            KMH, balance patch -- acid is particularly unstable */
2008.         if (obj->cursed || obj->otyp == POT_ACID || !rn2(10)) {
2009.             /* it would be better to use up the whole stack in advance
2010.                of the message, but we can't because we need to keep it
2011.                around for potionbreathe() [and we can't set obj->in_use
2012.                to 'amt' because that's not implemented] */
2013.             obj->in_use = 1;
2014.             pline("BOOM!  They explode!");
2015.             wake_nearto(u.ux, u.uy, (BOLT_LIM + 1) * (BOLT_LIM + 1));
2016.             exercise(A_STR, FALSE);
2017.             if (!breathless(youmonst.data) || haseyes(youmonst.data))
2018.                 potionbreathe(obj);
2019.             useupall(obj);
2020.             losehp(amt + rnd(9), /* not physical damage */
2021.                    "alchemic blast", KILLED_BY_AN);
2022.             return 1;
2023.         }
2024. 
2025.         obj->blessed = obj->cursed = obj->bknown = 0;
2026.         if (Blind || Hallucination)
2027.             obj->dknown = 0;
2028. 
2029.         if (mixture != STRANGE_OBJECT) {
2030.             obj->otyp = mixture;
2031.         } else {
2032.             switch (obj->odiluted ? 1 : rnd(8)) {
2033.             case 1:
2034.                 obj->otyp = POT_WATER;
2035.                 break;
2036.             case 2:
2037.             case 3:
2038.                 obj->otyp = POT_SICKNESS;
2039.                 break;
2040.             case 4: {
2041.                 struct obj *otmp = mkobj(POTION_CLASS, FALSE);
2042. 
2043.                 obj->otyp = otmp->otyp;
2044.                 obfree(otmp, (struct obj *) 0);
2045.                 break;
2046.             }
2047.             default:
2048.                 useupall(obj);
2049.                 if (!Blind)
2050.                     pline_The("mixture glows brightly and evaporates.");
2051.                 return 1;
2052.             }
2053.         }
2054.         obj->odiluted = (obj->otyp != POT_WATER);
2055. 
2056.         if (obj->otyp == POT_WATER && !Hallucination) {
2057.             pline_The("mixture bubbles%s.", Blind ? "" : ", then clears");
2058.         } else if (!Blind) {
2059.             pline_The("mixture looks %s.",
2060.                       hcolor(OBJ_DESCR(objects[obj->otyp])));
2061.         }
2062. 
2063.         /* this is required when 'obj' was split off from a bigger stack,
2064.            so that 'obj' will now be assigned its own inventory slot;
2065.            it has a side-effect of merging 'obj' into another compatible
2066.            stack if there is one, so we do it even when no split has
2067.            been made in order to get the merge result for both cases;
2068.            as a consequence, mixing while Fumbling drops the mixture */
2069.         freeinv(obj);
2070.         (void) hold_another_object(obj, "You drop %s!", doname(obj),
2071.                                    (const char *) 0);
2072.         return 1;
2073.     }
2074. 
2075.     if (potion->otyp == POT_ACID && obj->otyp == CORPSE
2076.         && obj->corpsenm == PM_LICHEN && !Blind) {
2077.         pline("%s %s %s around the edges.", The(cxname(obj)),
2078.               otense(obj, "turn"),
2079.               potion->odiluted ? hcolor(NH_ORANGE) : hcolor(NH_RED));
2080.         potion->in_use = FALSE; /* didn't go poof */
2081.         return 1;
2082.     }
2083. 
2084.     if (potion->otyp == POT_WATER && obj->otyp == TOWEL) {
2085.         pline_The("towel soaks it up!");
2086.         /* wetting towel already done via water_damage() in H2Opotion_dip */
2087.         goto poof;
2088.     }
2089. 
2090.     if (is_poisonable(obj)) {
2091.         if (potion->otyp == POT_SICKNESS && !obj->opoisoned) {
2092.             char buf[BUFSZ];
2093. 
2094.             if (potion->quan > 1L)
2095.                 Sprintf(buf, "One of %s", the(xname(potion)));
2096.             else
2097.                 Strcpy(buf, The(xname(potion)));
2098.             pline("%s forms a coating on %s.", buf, the(xname(obj)));
2099.             obj->opoisoned = TRUE;
2100.             goto poof;
2101.         } else if (obj->opoisoned && (potion->otyp == POT_HEALING
2102.                                       || potion->otyp == POT_EXTRA_HEALING
2103.                                       || potion->otyp == POT_FULL_HEALING)) {
2104.             pline("A coating wears off %s.", the(xname(obj)));
2105.             obj->opoisoned = 0;
2106.             goto poof;
2107.         }
2108.     }
2109. 
2110.     if (potion->otyp == POT_ACID) {
2111.         if (erode_obj(obj, 0, ERODE_CORRODE, EF_GREASE) != ER_NOTHING)
2112.             goto poof;
2113.     }
2114. 
2115.     if (potion->otyp == POT_OIL) {
2116.         boolean wisx = FALSE;
2117. 
2118.         if (potion->lamplit) { /* burning */
2119.             fire_damage(obj, TRUE, u.ux, u.uy);
2120.         } else if (potion->cursed) {
2121.             pline_The("potion spills and covers your %s with oil.",
2122.                       makeplural(body_part(FINGER)));
2123.             incr_itimeout(&Glib, d(2, 10));
2124.         } else if (obj->oclass != WEAPON_CLASS && !is_weptool(obj)) {
2125.             /* the following cases apply only to weapons */
2126.             goto more_dips;
2127.             /* Oil removes rust and corrosion, but doesn't unburn.
2128.              * Arrows, etc are classed as metallic due to arrowhead
2129.              * material, but dipping in oil shouldn't repair them.
2130.              */
2131.         } else if ((!is_rustprone(obj) && !is_corrodeable(obj))
2132.                    || is_ammo(obj) || (!obj->oeroded && !obj->oeroded2)) {
2133.             /* uses up potion, doesn't set obj->greased */
2134.             pline("%s %s with an oily sheen.", Yname2(obj),
2135.                   otense(obj, "gleam"));
2136.         } else {
2137.             pline("%s %s less %s.", Yname2(obj), otense(obj, "are"),
2138.                   (obj->oeroded && obj->oeroded2)
2139.                       ? "corroded and rusty"
2140.                       : obj->oeroded ? "rusty" : "corroded");
2141.             if (obj->oeroded > 0)
2142.                 obj->oeroded--;
2143.             if (obj->oeroded2 > 0)
2144.                 obj->oeroded2--;
2145.             wisx = TRUE;
2146.         }
2147.         exercise(A_WIS, wisx);
2148.         makeknown(potion->otyp);
2149.         useup(potion);
2150.         return 1;
2151.     }
2152.  more_dips:
2153. 
2154.     /* Allow filling of MAGIC_LAMPs to prevent identification by player */
2155.     if ((obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP)
2156.         && (potion->otyp == POT_OIL)) {
2157.         /* Turn off engine before fueling, turn off fuel too :-)  */
2158.         if (obj->lamplit || potion->lamplit) {
2159.             useup(potion);
2160.             explode(u.ux, u.uy, 11, d(6, 6), 0, EXPL_FIERY);
2161.             exercise(A_WIS, FALSE);
2162.             return 1;
2163.         }
2164.         /* Adding oil to an empty magic lamp renders it into an oil lamp */
2165.         if ((obj->otyp == MAGIC_LAMP) && obj->spe == 0) {
2166.             obj->otyp = OIL_LAMP;
2167.             obj->age = 0;
2168.         }
2169.         if (obj->age > 1000L) {
2170.             pline("%s %s full.", Yname2(obj), otense(obj, "are"));
2171.             potion->in_use = FALSE; /* didn't go poof */
2172.         } else {
2173.             You("fill %s with oil.", yname(obj));
2174.             check_unpaid(potion);        /* Yendorian Fuel Tax */
2175.             /* burns more efficiently in a lamp than in a bottle;
2176.                diluted potion provides less benefit but we don't attempt
2177.                to track that the lamp now also has some non-oil in it */
2178.             obj->age += (!potion->odiluted ? 4L : 3L) * potion->age / 2L;
2179.             if (obj->age > 1500L)
2180.                 obj->age = 1500L;
2181.             useup(potion);
2182.             exercise(A_WIS, TRUE);
2183.         }
2184.         makeknown(POT_OIL);
2185.         obj->spe = 1;
2186.         update_inventory();
2187.         return 1;
2188.     }
2189. 
2190.     potion->in_use = FALSE; /* didn't go poof */
2191.     if ((obj->otyp == UNICORN_HORN || obj->otyp == AMETHYST)
2192.         && (mixture = mixtype(obj, potion)) != STRANGE_OBJECT) {
2193.         char oldbuf[BUFSZ], newbuf[BUFSZ];
2194.         short old_otyp = potion->otyp;
2195.         boolean old_dknown = FALSE;
2196.         boolean more_than_one = potion->quan > 1L;
2197. 
2198.         oldbuf[0] = '\0';
2199.         if (potion->dknown) {
2200.             old_dknown = TRUE;
2201.             Sprintf(oldbuf, "%s ", hcolor(OBJ_DESCR(objects[potion->otyp])));
2202.         }
2203.         /* with multiple merged potions, split off one and
2204.            just clear it */
2205.         if (potion->quan > 1L) {
2206.             singlepotion = splitobj(potion, 1L);
2207.         } else
2208.             singlepotion = potion;
2209. 
2210.         costly_alteration(singlepotion, COST_NUTRLZ);
2211.         singlepotion->otyp = mixture;
2212.         singlepotion->blessed = 0;
2213.         if (mixture == POT_WATER)
2214.             singlepotion->cursed = singlepotion->odiluted = 0;
2215.         else
2216.             singlepotion->cursed = obj->cursed; /* odiluted left as-is */
2217.         singlepotion->bknown = FALSE;
2218.         if (Blind) {
2219.             singlepotion->dknown = FALSE;
2220.         } else {
2221.             singlepotion->dknown = !Hallucination;
2222.             if (mixture == POT_WATER && singlepotion->dknown)
2223.                 Sprintf(newbuf, "clears");
2224.             else
2225.                 Sprintf(newbuf, "turns %s",
2226.                         hcolor(OBJ_DESCR(objects[mixture])));
2227.             pline_The("%spotion%s %s.", oldbuf,
2228.                       more_than_one ? " that you dipped into" : "", newbuf);
2229.             if (!objects[old_otyp].oc_uname
2230.                 && !objects[old_otyp].oc_name_known && old_dknown) {
2231.                 struct obj fakeobj;
2232.                 fakeobj = zeroobj;
2233.                 fakeobj.dknown = 1;
2234.                 fakeobj.otyp = old_otyp;
2235.                 fakeobj.oclass = POTION_CLASS;
2236.                 docall(&fakeobj);
2237.             }
2238.         }
2239.         obj_extract_self(singlepotion);
2240.         singlepotion = hold_another_object(singlepotion,
2241.                                            "You juggle and drop %s!",
2242.                                            doname(singlepotion),
2243.                                            (const char *) 0);
2244.         nhUse(singlepotion);
2245.         update_inventory();
2246.         return 1;
2247.     }
2248. 
2249.     pline("Interesting...");
2250.     return 1;
2251. 
2252.  poof:
2253.     if (!objects[potion->otyp].oc_name_known
2254.         && !objects[potion->otyp].oc_uname)
2255.         docall(potion);
2256.     useup(potion);
2257.     return 1;
2258. }
2259. 
2260. /* *monp grants a wish and then leaves the game */
2261. void
2262. mongrantswish(monp)
2263. struct monst **monp;
2264. {
2265.     struct monst *mon = *monp;
2266.     int mx = mon->mx, my = mon->my, glyph = glyph_at(mx, my);
2267. 
2268.     /* remove the monster first in case wish proves to be fatal
2269.        (blasted by artifact), to keep it out of resulting bones file */
2270.     mongone(mon);
2271.     *monp = 0; /* inform caller that monster is gone */
2272.     /* hide that removal from player--map is visible during wish prompt */
2273.     tmp_at(DISP_ALWAYS, glyph);
2274.     tmp_at(mx, my);
2275.     /* grant the wish */
2276.     makewish();
2277.     /* clean up */
2278.     tmp_at(DISP_END, 0);
2279. }
2280. 
2281. void
2282. djinni_from_bottle(obj)
2283. struct obj *obj;
2284. {
2285.     struct monst *mtmp;
2286.     int chance;
2287. 
2288.     if (!(mtmp = makemon(&mons[PM_DJINNI], u.ux, u.uy, NO_MM_FLAGS))) {
2289.         pline("It turns out to be empty.");
2290.         return;
2291.     }
2292. 
2293.     if (!Blind) {
2294.         pline("In a cloud of smoke, %s emerges!", a_monnam(mtmp));
2295.         pline("%s speaks.", Monnam(mtmp));
2296.     } else {
2297.         You("smell acrid fumes.");
2298.         pline("%s speaks.", Something);
2299.     }
2300. 
2301.     chance = rn2(5);
2302.     if (obj->blessed)
2303.         chance = (chance == 4) ? rnd(4) : 0;
2304.     else if (obj->cursed)
2305.         chance = (chance == 0) ? rn2(4) : 4;
2306.     /* 0,1,2,3,4:  b=80%,5,5,5,5; nc=20%,20,20,20,20; c=5%,5,5,5,80 */
2307. 
2308.     switch (chance) {
2309.     case 0:
2310.         verbalize("I am in your debt.  I will grant one wish!");
2311.         /* give a wish and discard the monster (mtmp set to null) */
2312.         mongrantswish(&mtmp);
2313.         break;
2314.     case 1:
2315.         verbalize("Thank you for freeing me!");
2316.         (void) tamedog(mtmp, (struct obj *) 0);
2317.         break;
2318.     case 2:
2319.         verbalize("You freed me!");
2320.         mtmp->mpeaceful = TRUE;
2321.         set_malign(mtmp);
2322.         break;
2323.     case 3:
2324.         verbalize("It is about time!");
2325.         if (canspotmon(mtmp))
2326.             pline("%s vanishes.", Monnam(mtmp));
2327.         mongone(mtmp);
2328.         break;
2329.     default:
2330.         verbalize("You disturbed me, fool!");
2331.         mtmp->mpeaceful = FALSE;
2332.         set_malign(mtmp);
2333.         break;
2334.     }
2335. }
2336. 
2337. /* clone a gremlin or mold (2nd arg non-null implies heat as the trigger);
2338.    hit points are cut in half (odd HP stays with original) */
2339. struct monst *
2340. split_mon(mon, mtmp)
2341. struct monst *mon,  /* monster being split */
2342.              *mtmp; /* optional attacker whose heat triggered it */
2343. {
2344.     struct monst *mtmp2;
2345.     char reason[BUFSZ];
2346. 
2347.     reason[0] = '\0';
2348.     if (mtmp)
2349.         Sprintf(reason, " from %s heat",
2350.                 (mtmp == &youmonst) ? the_your[1]
2351.                                     : (const char *) s_suffix(mon_nam(mtmp)));
2352. 
2353.     if (mon == &youmonst) {
2354.         mtmp2 = cloneu();
2355.         if (mtmp2) {
2356.             mtmp2->mhpmax = u.mhmax / 2;
2357.             u.mhmax -= mtmp2->mhpmax;
2358.             context.botl = 1;
2359.             You("multiply%s!", reason);
2360.         }
2361.     } else {
2362.         mtmp2 = clone_mon(mon, 0, 0);
2363.         if (mtmp2) {
2364.             mtmp2->mhpmax = mon->mhpmax / 2;
2365.             mon->mhpmax -= mtmp2->mhpmax;
2366.             if (canspotmon(mon))
2367.                 pline("%s multiplies%s!", Monnam(mon), reason);
2368.         }
2369.     }
2370.     return mtmp2;
2371. }
2372. 
2373. /*potion.c*/