1 /* $NetBSD: hack.potion.c,v 1.7 2009/06/07 18:30:39 dholland Exp $ */
4 * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * - Neither the name of the Stichting Centrum voor Wiskunde en
20 * Informatica, nor the names of its contributors may be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39 * All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 #include <sys/cdefs.h>
66 __RCSID("$NetBSD: hack.potion.c,v 1.7 2009/06/07 18:30:39 dholland Exp $");
72 static void ghost_from_bottle(void);
77 struct obj
*otmp
, *objs
;
79 int unkn
= 0, nothing
= 0;
81 otmp
= getobj("!", "drink");
84 if (!strcmp(objects
[otmp
->otyp
].oc_descr
, "smoky") && !rn2(13)) {
89 case POT_RESTORE_STRENGTH
:
91 pline("Wow! This makes you feel great!");
92 if (u
.ustr
< u
.ustrmax
) {
99 pline("Ooph! This tastes like liquid fire!");
100 Confusion
+= d(3, 8);
101 /* the whiskey makes us feel better */
102 if (u
.uhp
< u
.uhpmax
)
103 losehp(-1, "bottle of whiskey");
105 pline("You pass out.");
107 nomovemsg
= "You awake with a headache.";
110 case POT_INVISIBILITY
:
111 if (Invis
|| See_invisible
)
115 pline("Gee! All of a sudden, you can't see yourself.");
117 pline("You feel rather airy."), unkn
++;
120 Invis
+= rn1(15, 31);
122 case POT_FRUIT_JUICE
:
123 pline("This tastes like fruit juice.");
127 pline("You begin to feel better.");
130 if (u
.uhp
> u
.uhpmax
)
133 Blind
= 1; /* see on next move */
139 pline("You are motionlessly suspended.");
141 pline("Your feet are frozen to the floor!");
142 nomul(-(rn1(10, 25)));
144 case POT_MONSTER_DETECTION
:
146 strange_feeling(otmp
, "You feel threatened.");
150 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
152 at(mtmp
->mx
, mtmp
->my
, mtmp
->data
->mlet
);
154 pline("You sense the presence of monsters.");
159 case POT_OBJECT_DETECTION
:
161 strange_feeling(otmp
, "You feel a pull downward.");
164 for (objs
= fobj
; objs
; objs
= objs
->nobj
)
165 if (objs
->ox
!= u
.ux
|| objs
->oy
!= u
.uy
)
167 pline("You sense the presence of objects close nearby.");
171 for (objs
= fobj
; objs
; objs
= objs
->nobj
)
172 at(objs
->ox
, objs
->oy
, objs
->olet
);
174 pline("You sense the presence of objects.");
180 pline("Yech! This stuff tastes like poison.");
181 if (Poison_resistance
)
182 pline("(But in fact it was biologically contaminated orange juice.)");
184 losehp(rnd(10), "contaminated potion");
188 pline("Huh, What? Where am I?");
191 Confusion
+= rn1(7, 16);
193 case POT_GAIN_STRENGTH
:
194 pline("Wow do you feel strong!");
196 break; /* > 118 is impossible */
198 u
.ustr
+= rnd(118 - u
.ustr
);
201 if (u
.ustr
> u
.ustrmax
)
211 if (!(Fast
& ~INTRINSIC
))
212 pline("You are suddenly moving much faster.");
214 pline("Your legs get new energy."), unkn
++;
215 Fast
+= rn1(10, 100);
219 pline("A cloud of darkness falls upon you.");
222 Blind
+= rn1(100, 250);
228 case POT_EXTRA_HEALING
:
229 pline("You feel much better.");
231 u
.uhp
+= d(2, 20) + 1;
232 if (u
.uhp
> u
.uhpmax
)
233 u
.uhp
= (u
.uhpmax
+= 2);
244 Levitation
+= rnd(100);
245 u
.uprops
[PROP(RIN_LEVITATION
)].p_tofn
= float_down
;
248 impossible("What a funny potion! (%u)", otmp
->otyp
);
253 pline("You have a peculiar feeling for a moment, then it passes.");
255 if (otmp
->dknown
&& !objects
[otmp
->otyp
].oc_name_known
) {
257 objects
[otmp
->otyp
].oc_name_known
= 1;
258 more_experienced(0, 10);
259 } else if (!objects
[otmp
->otyp
].oc_uname
)
272 pline("You feel more experienced.");
277 u
.uexp
= newuexp() + 1;
278 pline("Welcome to experience level %u.", ++u
.ulevel
);
284 strange_feeling(struct obj
*obj
, const char *txt
)
287 pline("You have a strange feeling for a moment, then it passes.");
290 if (!objects
[obj
->otyp
].oc_name_known
&& !objects
[obj
->otyp
].oc_uname
)
295 static const char *const bottlenames
[] = {
296 "bottle", "phial", "flagon", "carafe", "flask", "jar", "vial"
300 potionhit(struct monst
*mon
, struct obj
*obj
)
302 const char *botlnam
= bottlenames
[rn2(SIZE(bottlenames
))];
303 boolean uclose
, isyou
= (mon
== &youmonst
);
307 pline("The %s crashes on your head and breaks into shivers.",
309 losehp(rnd(2), "thrown potion");
311 uclose
= (dist(mon
->mx
, mon
->my
) < 3);
312 /* perhaps 'E' and 'a' have no head? */
313 pline("The %s crashes on %s's head and breaks into shivers.",
314 botlnam
, monnam(mon
));
315 if (rn2(5) && mon
->mhp
> 1)
318 pline("The %s evaporates.", xname(obj
));
320 if (!isyou
&& !rn2(3))
323 case POT_RESTORE_STRENGTH
:
324 case POT_GAIN_STRENGTH
:
326 case POT_EXTRA_HEALING
:
327 if (mon
->mhp
< mon
->mhpmax
) {
328 mon
->mhp
= mon
->mhpmax
;
329 pline("%s looks sound and hale again!", Monnam(mon
));
342 case POT_INVISIBILITY
:
354 mon
->mblinded
|= 64 + rn2(64);
357 * case POT_GAIN_LEVEL: case POT_LEVITATION: case
358 * POT_FRUIT_JUICE: case POT_MONSTER_DETECTION: case
359 * POT_OBJECT_DETECTION: break;
362 if (uclose
&& rn2(5))
364 obfree(obj
, Null(obj
));
368 potionbreathe(struct obj
*obj
)
371 case POT_RESTORE_STRENGTH
:
372 case POT_GAIN_STRENGTH
:
373 if (u
.ustr
< u
.ustrmax
)
374 u
.ustr
++, flags
.botl
= 1;
377 case POT_EXTRA_HEALING
:
378 if (u
.uhp
< u
.uhpmax
)
379 u
.uhp
++, flags
.botl
= 1;
391 pline("You feel somewhat dizzy.");
394 case POT_INVISIBILITY
:
395 pline("For an instant you couldn't see your right hand.");
398 pline("Something seems to be holding you.");
403 pline("Your knees seem more flexible now.");
407 pline("It suddenly gets dark.");
412 * case POT_GAIN_LEVEL: case POT_LEVITATION: case
413 * POT_FRUIT_JUICE: case POT_MONSTER_DETECTION: case
414 * POT_OBJECT_DETECTION: break;
417 /* note: no obfree() */
421 * -- rudimentary -- to do this correctly requires much more work
422 * -- all sharp weapons get one or more qualities derived from the potions
423 * -- texts on scrolls may be (partially) wiped out; do they become blank?
424 * -- or does their effect change, like under Confusion?
425 * -- all objects may be made invisible by POT_INVISIBILITY
426 * -- If the flask is small, can one dip a large object? Does it magically
427 * -- become a jug? Etc.
432 struct obj
*potion
, *obj
;
434 if (!(obj
= getobj("#", "dip")))
436 if (!(potion
= getobj("!", "dip into")))
438 pline("Interesting...");
439 if (obj
->otyp
== ARROW
|| obj
->otyp
== DART
||
440 obj
->otyp
== CROSSBOW_BOLT
) {
441 if (potion
->otyp
== POT_SICKNESS
) {
451 ghost_from_bottle(void)
455 if (!(mtmp
= makemon(PM_GHOST
, u
.ux
, u
.uy
))) {
456 pline("This bottle turns out to be empty.");
460 pline("As you open the bottle, an enormous ghost emerges!");
461 pline("You are frightened to death, and unable to move.");