This repository has been archived by the owner on Nov 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
potions.c
375 lines (351 loc) · 8.13 KB
/
potions.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/*
* Function(s) for dealing with potions
*
* @(#)potions.c 4.46 (Berkeley) 06/07/83
*
* Rogue: Exploring the Dungeons of Doom
* Copyright (C) 1980-1983, 1985, 1999 Michael Toy, Ken Arnold and Glenn Wichman
* All rights reserved.
*
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <curses.h>
#include <ctype.h>
#include "rogue.h"
typedef struct
{
int pa_flags;
void (*pa_daemon)();
int pa_time;
char *pa_high, *pa_straight;
} PACT;
static PACT p_actions[] =
{
{ ISHUH, unconfuse, HUHDURATION, /* P_CONFUSE */
"what a tripy feeling!",
"wait, what's going on here. Huh? What? Who?" },
{ ISHALU, come_down, SEEDURATION, /* P_LSD */
"Oh, wow! Everything seems so cosmic!",
"Oh, wow! Everything seems so cosmic!" },
{ 0, NULL, 0 }, /* P_POISON */
{ 0, NULL, 0 }, /* P_STRENGTH */
{ CANSEE, unsee, SEEDURATION, /* P_SEEINVIS */
prbuf,
prbuf },
{ 0, NULL, 0 }, /* P_HEALING */
{ 0, NULL, 0 }, /* P_MFIND */
{ 0, NULL, 0 }, /* P_TFIND */
{ 0, NULL, 0 }, /* P_RAISE */
{ 0, NULL, 0 }, /* P_XHEAL */
{ 0, NULL, 0 }, /* P_HASTE */
{ 0, NULL, 0 }, /* P_RESTORE */
{ ISBLIND, sight, SEEDURATION, /* P_BLIND */
"oh, bummer! Everything is dark! Help!",
"a cloak of darkness falls around you" },
{ ISLEVIT, land, HEALTIME, /* P_LEVIT */
"oh, wow! You're floating in the air!",
"you start to float in the air" }
};
/*
* quaff:
* Quaff a potion from the pack
*/
void
quaff()
{
THING *obj, *tp, *mp;
bool discardit = FALSE;
bool show, trip;
obj = get_item("quaff", POTION);
/*
* Make certain that it is somethings that we want to drink
*/
if (obj == NULL)
return;
if (obj->o_type != POTION)
{
if (!terse)
msg("yuk! Why would you want to drink that?");
else
msg("that's undrinkable");
return;
}
if (obj == cur_weapon)
cur_weapon = NULL;
/*
* Calculate the effect it has on the poor guy.
*/
trip = on(player, ISHALU);
discardit = (bool)(obj->o_count == 1);
leave_pack(obj, FALSE, FALSE);
switch (obj->o_which)
{
case P_CONFUSE:
do_pot(P_CONFUSE, !trip);
when P_POISON:
pot_info[P_POISON].oi_know = TRUE;
if (ISWEARING(R_SUSTSTR))
msg("you feel momentarily sick");
else
{
chg_str(-(rnd(3) + 1));
msg("you feel very sick now");
come_down();
}
when P_HEALING:
pot_info[P_HEALING].oi_know = TRUE;
if ((pstats.s_hpt += roll(pstats.s_lvl, 4)) > max_hp)
pstats.s_hpt = ++max_hp;
sight();
msg("you begin to feel better");
when P_STRENGTH:
pot_info[P_STRENGTH].oi_know = TRUE;
chg_str(1);
msg("you feel stronger, now. What bulging muscles!");
when P_MFIND:
player.t_flags |= SEEMONST;
fuse((void(*)())turn_see, TRUE, HUHDURATION, AFTER);
if (!turn_see(FALSE))
msg("you have a %s feeling for a moment, then it passes",
choose_str("normal", "strange"));
when P_TFIND:
/*
* Potion of magic detection. Show the potions and scrolls
*/
show = FALSE;
if (lvl_obj != NULL)
{
wclear(hw);
for (tp = lvl_obj; tp != NULL; tp = next(tp))
{
if (is_magic(tp))
{
show = TRUE;
wmove(hw, tp->o_pos.y, tp->o_pos.x);
waddch(hw, MAGIC);
pot_info[P_TFIND].oi_know = TRUE;
}
}
for (mp = mlist; mp != NULL; mp = next(mp))
{
for (tp = mp->t_pack; tp != NULL; tp = next(tp))
{
if (is_magic(tp))
{
show = TRUE;
wmove(hw, mp->t_pos.y, mp->t_pos.x);
waddch(hw, MAGIC);
}
}
}
}
if (show)
{
pot_info[P_TFIND].oi_know = TRUE;
show_win("You sense the presence of magic on this level.--More--");
}
else
msg("you have a %s feeling for a moment, then it passes",
choose_str("normal", "strange"));
when P_LSD:
if (!trip)
{
if (on(player, SEEMONST))
turn_see(FALSE);
start_daemon(visuals, 0, BEFORE);
seenstairs = seen_stairs();
}
do_pot(P_LSD, TRUE);
when P_SEEINVIS:
sprintf(prbuf, "this potion tastes like %s juice", fruit);
show = on(player, CANSEE);
do_pot(P_SEEINVIS, FALSE);
if (!show)
invis_on();
sight();
when P_RAISE:
pot_info[P_RAISE].oi_know = TRUE;
msg("you suddenly feel much more skillful");
raise_level();
when P_XHEAL:
pot_info[P_XHEAL].oi_know = TRUE;
if ((pstats.s_hpt += roll(pstats.s_lvl, 8)) > max_hp)
{
if (pstats.s_hpt > max_hp + pstats.s_lvl + 1)
++max_hp;
pstats.s_hpt = ++max_hp;
}
sight();
come_down();
msg("you begin to feel much better");
when P_HASTE:
pot_info[P_HASTE].oi_know = TRUE;
after = FALSE;
if (add_haste(TRUE))
msg("you feel yourself moving much faster");
when P_RESTORE:
if (ISRING(LEFT, R_ADDSTR))
add_str(&pstats.s_str, -cur_ring[LEFT]->o_arm);
if (ISRING(RIGHT, R_ADDSTR))
add_str(&pstats.s_str, -cur_ring[RIGHT]->o_arm);
if (pstats.s_str < max_stats.s_str)
pstats.s_str = max_stats.s_str;
if (ISRING(LEFT, R_ADDSTR))
add_str(&pstats.s_str, cur_ring[LEFT]->o_arm);
if (ISRING(RIGHT, R_ADDSTR))
add_str(&pstats.s_str, cur_ring[RIGHT]->o_arm);
msg("hey, this tastes great. It make you feel warm all over");
when P_BLIND:
do_pot(P_BLIND, TRUE);
when P_LEVIT:
do_pot(P_LEVIT, TRUE);
#ifdef MASTER
otherwise:
msg("what an odd tasting potion!");
return;
#endif
}
status();
/*
* Throw the item away
*/
call_it(&pot_info[obj->o_which]);
if (discardit)
discard(obj);
return;
}
/*
* is_magic:
* Returns true if an object radiates magic
*/
bool
is_magic(THING *obj)
{
switch (obj->o_type)
{
case ARMOR:
return (bool)((obj->o_flags&ISPROT) || obj->o_arm != a_class[obj->o_which]);
case WEAPON:
return (bool)(obj->o_hplus != 0 || obj->o_dplus != 0);
case POTION:
case SCROLL:
case STICK:
case RING:
case AMULET:
return TRUE;
}
return FALSE;
}
/*
* invis_on:
* Turn on the ability to see invisible
*/
void
invis_on()
{
THING *mp;
player.t_flags |= CANSEE;
for (mp = mlist; mp != NULL; mp = next(mp))
if (on(*mp, ISINVIS) && see_monst(mp) && !on(player, ISHALU))
mvaddch(mp->t_pos.y, mp->t_pos.x, mp->t_disguise);
}
/*
* turn_see:
* Put on or off seeing monsters on this level
*/
bool
turn_see(bool turn_off)
{
THING *mp;
bool can_see, add_new;
add_new = FALSE;
for (mp = mlist; mp != NULL; mp = next(mp))
{
move(mp->t_pos.y, mp->t_pos.x);
can_see = see_monst(mp);
if (turn_off)
{
if (!can_see)
addch(mp->t_oldch);
}
else
{
if (!can_see)
standout();
if (!on(player, ISHALU))
addch(mp->t_type);
else
addch(rnd(26) + 'A');
if (!can_see)
{
standend();
add_new++;
}
}
}
if (turn_off)
player.t_flags &= ~SEEMONST;
else
player.t_flags |= SEEMONST;
return add_new;
}
/*
* seen_stairs:
* Return TRUE if the player has seen the stairs
*/
bool
seen_stairs()
{
THING *tp;
move(stairs.y, stairs.x);
if (inch() == STAIRS) /* it's on the map */
return TRUE;
if (ce(hero, stairs)) /* It's under him */
return TRUE;
/*
* if a monster is on the stairs, this gets hairy
*/
if ((tp = moat(stairs.y, stairs.x)) != NULL)
{
if (see_monst(tp) && on(*tp, ISRUN)) /* if it's visible and awake */
return TRUE; /* it must have moved there */
if (on(player, SEEMONST) /* if she can detect monster */
&& tp->t_oldch == STAIRS) /* and there once were stairs */
return TRUE; /* it must have moved there */
}
return FALSE;
}
/*
* raise_level:
* The guy just magically went up a level.
*/
void
raise_level()
{
pstats.s_exp = e_levels[pstats.s_lvl-1] + 1L;
check_level();
}
/*
* do_pot:
* Do a potion with standard setup. This means it uses a fuse and
* turns on a flag
*/
void
do_pot(int type, bool knowit)
{
PACT *pp;
int t;
pp = &p_actions[type];
if (!pot_info[type].oi_know)
pot_info[type].oi_know = knowit;
t = spread(pp->pa_time);
if (!on(player, pp->pa_flags))
{
player.t_flags |= pp->pa_flags;
fuse(pp->pa_daemon, 0, t, AFTER);
look(FALSE);
}
else
lengthen(pp->pa_daemon, t);
msg(choose_str(pp->pa_high, pp->pa_straight));
}