1 /*
2  * Function(s) for dealing with potions
3  *
4  * potions.c	1.4 (AI Design)		2/12/84
5  */
6 
7 #include "rogue.h"
8 #include "curses.h"
9 
10 /*
11  * quaff:
12  *	Quaff a potion from the pack
13  */
14 quaff()
15 {
16     register THING *obj, *th;
17     register bool discardit = FALSE;
18 
19     if ((obj = get_item("quaff", POTION)) == NULL)
20     	return;
21     /*
22      * Make certain that it is somethings that we want to drink
23      */
24     if (obj->o_type != POTION)
25     {
26 	msg("yuk! Why would you want to drink that?");
27 	return;
28     }
29     if (obj == cur_weapon)
30 	cur_weapon = NULL;
31 
32     /*
33      * Calculate the effect it has on the poor guy.
34      */
35     switch (obj->o_which)
36     {
37 	when P_CONFUSE:
38 	    p_know[P_CONFUSE] = TRUE;
39 	    if (!on(player, ISHUH))
40 	    {
41 		if (on(player, ISHUH))
42 		    lengthen(unconfuse, rnd(8)+HUHDURATION);
43 		else
44 		    fuse(unconfuse, 0, rnd(8)+HUHDURATION);
45 		player.t_flags |= ISHUH;
46 		msg("wait, what's going on? Huh? What? Who?");
47 	    }
48 	when P_POISON:
49 	    {
50 		char *sick = "you feel %s sick.";
51 
52 		p_know[P_POISON] = TRUE;
53 		if (!ISWEARING(R_SUSTSTR))
54 		{
55 		    chg_str(-(rnd(3)+1));
56 		    msg(sick, "very");
57 		}
58 		else
59 		    msg(sick, "momentarily");
60 	    }
61 	when P_HEALING:
62 	    p_know[P_HEALING] = TRUE;
63 	    if ((pstats.s_hpt += roll(pstats.s_lvl, 4)) > max_hp)
64 		pstats.s_hpt = ++max_hp;
65 	    sight();
66 	    msg("you begin to feel better");
67 	when P_STRENGTH:
68 	    p_know[P_STRENGTH] = TRUE;
69 	    chg_str(1);
70 	    msg("you feel stronger. What bulging muscles!");
71 	when P_MFIND:
72 #ifndef DEMO
73 	    fuse(turn_see, TRUE, HUHDURATION);
74 	    if (mlist == NULL)
75 		msg("you have a strange feeling%s.",
76 			noterse(" for a moment"));
77 	    else
78 	    {
79                 p_know[P_MFIND] |= turn_see(FALSE);
80                 msg("");
81             }
82 #else	
83 	    msg("you can't move");
84         msg(" and are forced to watch this advertisement");
85 	    msg("rogue: The ULTIMATE Adventure Game");
86 	    msg("the most popular game on UNIX ever!");
87 	    msg("now runs on YOUR IBM PC");
88 	    msg("UNIX is a trademark of Bell Labs");
89             p_know[P_MFIND] = TRUE;
90 #endif
91       when P_TFIND:
92 	    /*
93 	     * Potion of magic detection.  Find everything interesting on
94 	     * the level and show him where they are.  Also give hints as
95 	     * to whether he would want to use the object.
96 	     */
97 	    if (lvl_obj != NULL)
98 	    {
99 		register THING *tp;
100 		register bool show;
101 
102 		show = FALSE;
103 		for (tp = lvl_obj; tp != NULL; tp = next(tp))
104 		{
105 		    if (is_magic(tp))
106 		    {
107 			show = TRUE;
108 			mvwaddch(hw, tp->o_pos.y, tp->o_pos.x, goodch(tp));
109 			p_know[P_TFIND] = TRUE;
110 		    }
111 		}
112 		for (th = mlist; th != NULL; th = next(th))
113 		{
114 		    for (tp = th->t_pack; tp != NULL; tp = next(tp))
115 		    {
116 			if (is_magic(tp))
117 			{
118 			    show = TRUE;
119 			    mvwaddch(hw, th->t_pos.y, th->t_pos.x, MAGIC);
120 			    p_know[P_TFIND] = TRUE;
121 			}
122 		    }
123 		}
124 		if (show)
125 		{
126 		    msg("You sense the presence of magic.");
127 		    break;
128 		}
129 	    }
130 	    msg("you have a strange feeling for a moment%s.",
131 	    		noterse(", then it passes"));
132 	when P_PARALYZE:
133 	    p_know[P_PARALYZE] = TRUE;
134 	    no_command = HOLDTIME;
135 	    player.t_flags &= ~ISRUN;
136 	    msg("you can't move");
137 	when P_SEEINVIS:
138 	    if (!on(player, CANSEE)) {
139 			fuse(unsee, 0, SEEDURATION);
140 			look(FALSE);
141 			invis_on();
142 	    }
143 	    sight();
144 	    msg("this potion tastes like %s juice", fruit);
145 	when P_RAISE:
146 	    p_know[P_RAISE] = TRUE;
147 	    msg("you suddenly feel much more skillful");
148 	    raise_level();
149 	when P_XHEAL:
150 	    p_know[P_XHEAL] = TRUE;
151 	    if ((pstats.s_hpt += roll(pstats.s_lvl, 8)) > max_hp)
152 	    {
153 		if (pstats.s_hpt > max_hp + pstats.s_lvl + 1)
154 		    ++max_hp;
155 		pstats.s_hpt = ++max_hp;
156 	    }
157 	    sight();
158 	    msg("you begin to feel much better");
159 	when P_HASTE:
160 	    p_know[P_HASTE] = TRUE;
161 	    if (add_haste(TRUE))
162 		msg("you feel yourself moving much faster");
163 	when P_RESTORE:
164 	    if (ISRING(LEFT, R_ADDSTR))
165 			add_str(&pstats.s_str, -cur_ring[LEFT]->o_ac);
166 	    if (ISRING(RIGHT, R_ADDSTR))
167 			add_str(&pstats.s_str, -cur_ring[RIGHT]->o_ac);
168 	    if (pstats.s_str < max_stats.s_str)
169 			pstats.s_str = max_stats.s_str;
170 	    if (ISRING(LEFT, R_ADDSTR))
171 			add_str(&pstats.s_str, cur_ring[LEFT]->o_ac);
172 	    if (ISRING(RIGHT, R_ADDSTR))
173 			add_str(&pstats.s_str, cur_ring[RIGHT]->o_ac);
174 		msg("%syou feel warm all over",
175 				noterse("hey, this tastes great.  It makes "));
176 	when P_BLIND:
177 	    p_know[P_BLIND] = TRUE;
178 	    if (!on(player, ISBLIND))
179 	    {
180 		player.t_flags |= ISBLIND;
181 		fuse(sight, 0, SEEDURATION);
182 		look(FALSE);
183 	    }
184 	    msg("a cloak of darkness falls around you");
185 	when P_NOP:
186 	    msg("this potion tastes extremely dull");
187 	otherwise:
188 	    msg("what an odd tasting potion!");
189 	    return;
190     }
191     status();
192     /*
193      * Throw the item away
194      */
195     inpack--;
196     if (obj->o_count > 1)
197 	obj->o_count--;
198     else
199     {
200 	detach(pack, obj);
201         discardit = TRUE;
202     }
203 
204     call_it(p_know[obj->o_which], &p_guess[obj->o_which]);
205 
206     if (discardit)
207 	discard(obj);
208 }
209 
210 /*
211  * invis_on:
212  *	Turn on the ability to see invisible
213  */
214 invis_on()
215 {
216     register THING *th;
217 
218     player.t_flags |= CANSEE;
219     for (th = mlist; th != NULL; th = next(th))
220 	if (on(*th, ISINVIS) && see_monst(th))
221 	{
222 	    mvaddch(th->t_pos.y, th->t_pos.x,th->t_disguise);
223 	}
224 }
225 
226 /*
227  * turn_see:
228  *	Put on or off seeing monsters on this level
229  */
230 turn_see(turn_off)
231 register bool turn_off;
232 {
233     register THING *mp;
234     register bool can_see, add_new;
235     byte was_there;
236 
237     add_new = FALSE;
238     for (mp = mlist; mp != NULL; mp = next(mp)) {
239 		move(mp->t_pos.y, mp->t_pos.x);
240 		can_see = (see_monst(mp) || (was_there = inch()) == mp->t_type);
241 			if (turn_off) {
242 			    if (!see_monst(mp) && mp->t_oldch != '@')
243 					addch(mp->t_oldch);
244 			} else {
245 			    if (!can_see) {
246 					standout();
247 			        mp->t_oldch = was_there;
248 			    }
249 			    addch(mp->t_type);
250 			    if (!can_see) {
251 					standend();
252 					add_new++;
253 			    }
254 			}
255     }
256     player.t_flags |= SEEMONST;
257     if (turn_off)
258 		player.t_flags &= ~SEEMONST;
259     return add_new;
260 }
261 
262 /*
263  * th_effect:
264  *	Compute the effect of this potion hitting a monster.
265  */
266 
267 th_effect(obj, tp)
268 register THING *obj, *tp;
269 {
270     switch (obj->o_which)
271     {
272 	when P_CONFUSE:
273 	case P_BLIND:
274 	    tp->t_flags |= ISHUH;
275 	    msg("the %s appears confused", monsters[tp->t_type-'A'].m_name);
276 	when P_PARALYZE:
277 	    tp->t_flags &= ~ISRUN;
278 	    tp->t_flags |= ISHELD;
279 	when P_HEALING:
280 	case P_XHEAL:
281 	    if ((tp->t_stats.s_hpt += rnd(8)) > tp->t_stats.s_maxhp)
282 		tp->t_stats.s_hpt = ++tp->t_stats.s_maxhp;
283 	when P_RAISE:
284 		tp->t_stats.s_hpt += 8;
285 		tp->t_stats.s_maxhp += 8;
286 		tp->t_stats.s_lvl++;
287 	when P_HASTE:
288 		tp->t_flags |= ISHASTE;
289     }
290     msg("the flask shatters.");
291 }
292 