comparison xrogue/potions.c @ 133:e6179860cb76

Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
author John "Elwin" Edwards
date Tue, 21 Apr 2015 08:55:20 -0400
parents
children ce0cf824c192
comparison
equal deleted inserted replaced
124:d10fc4a065ac 133:e6179860cb76
1 /*
2 potions.c - Functions for dealing with potions
3
4 XRogue: Expeditions into the Dungeons of Doom
5 Copyright (C) 1991 Robert Pietkivitch
6 All rights reserved.
7
8 Based on "Advanced Rogue"
9 Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
10 All rights reserved.
11
12 Based on "Rogue: Exploring the Dungeons of Doom"
13 Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
14 All rights reserved.
15
16 See the file LICENSE.TXT for full copyright and licensing information.
17 */
18
19 #include <curses.h>
20 #include "rogue.h"
21
22 /*
23 * add_abil is an array of functions used to change attributes. It must be
24 * ordered according to the attribute definitions in rogue.h.
25 */
26
27 int (*add_abil[NUMABILITIES])() = {
28 add_intelligence, add_strength, add_wisdom, add_dexterity,
29 add_constitution, add_charisma
30 };
31
32 /*
33 * res_abil is an array of functions used to change attributes. It must be
34 * ordered according to the attribute definitions in rogue.h.
35 */
36
37 int (*res_abil[NUMABILITIES])() = {
38 res_intelligence, res_strength, res_wisdom, res_dexterity,
39 res_constitution, res_charisma
40 };
41
42 /*
43 * Increase player's constitution
44 */
45
46 int
47 add_constitution(change)
48 int change;
49 {
50 /* Do the potion */
51 if (change < 0) {
52 msg("You feel less healthy now.");
53 pstats.s_const += change;
54 if (pstats.s_const < 1) {
55 pstats.s_hpt = -1;
56 msg("You collapse! --More--");
57 wait_for(' ');
58 death(D_CONSTITUTION);
59 }
60 }
61 else {
62 msg("You feel healthier now.");
63 pstats.s_const = min(pstats.s_const + change, MAXATT);
64 }
65
66 /* Adjust the maximum */
67 if (max_stats.s_const < pstats.s_const)
68 max_stats.s_const = pstats.s_const;
69
70 return(0);
71 }
72
73 /*
74 * Increase player's charisma
75 */
76
77 int
78 add_charisma(change)
79 int change;
80 {
81 /* Do the potion */
82 if (change < 0) msg("You feel less attractive now.");
83 else msg("You feel more attractive now.");
84
85 pstats.s_charisma += change;
86 if (pstats.s_charisma > MAXATT) pstats.s_charisma = MAXATT;
87 else if (pstats.s_charisma < 3) pstats.s_charisma = 3;
88
89 /* Adjust the maximum */
90 if (max_stats.s_charisma < pstats.s_charisma)
91 max_stats.s_charisma = pstats.s_charisma;
92
93 return(0);
94 }
95
96 /*
97 * Increase player's dexterity
98 */
99
100 int
101 add_dexterity(change)
102 int change;
103 {
104 int ring_str; /* Value of ring strengths */
105
106 /* Undo any ring changes */
107 ring_str = ring_value(R_ADDHIT);
108 pstats.s_dext -= ring_str;
109
110 /* Now do the potion */
111 if (change < 0) msg("You feel less dextrous now.");
112 else msg("You feel more dextrous now. Watch those hands!");
113
114 pstats.s_dext += change;
115 if (pstats.s_dext > MAXATT) pstats.s_dext = MAXATT;
116 else if (pstats.s_dext < 3) pstats.s_dext = 3;
117
118 /* Adjust the maximum */
119 if (max_stats.s_dext < pstats.s_dext)
120 max_stats.s_dext = pstats.s_dext;
121
122 /* Now put back the ring changes */
123 if (ring_str)
124 pstats.s_dext += ring_str;
125
126 return(0);
127 }
128
129 /*
130 * add_haste:
131 * add a haste to the player
132 */
133
134 add_haste(blessed)
135 bool blessed;
136 {
137 int hasttime;
138
139 if (player.t_ctype == C_MONK) { /* monks cannot be slowed or hasted */
140 msg(nothing);
141 return;
142 }
143
144 if (blessed) hasttime = HASTETIME*2;
145 else hasttime = HASTETIME;
146
147 if (on(player, ISSLOW)) { /* Is person slow? */
148 extinguish(noslow);
149 noslow();
150
151 if (blessed) hasttime = HASTETIME/2;
152 else return;
153 }
154
155 if (on(player, ISHASTE)) {
156 msg("You faint from exhaustion.");
157 player.t_no_move += movement(&player) * rnd(hasttime);
158 player.t_action = A_FREEZE;
159 lengthen(nohaste, roll(hasttime,hasttime));
160 }
161 else {
162 msg("You feel yourself moving %sfaster.", blessed ? "much " : "");
163 turn_on(player, ISHASTE);
164 fuse(nohaste, (VOID *)NULL, roll(hasttime, hasttime), AFTER);
165 }
166 }
167
168 /*
169 * Increase player's intelligence
170 */
171
172 int
173 add_intelligence(change)
174 int change;
175 {
176 int ring_str; /* Value of ring strengths */
177
178 /* Undo any ring changes */
179 ring_str = ring_value(R_ADDINTEL);
180 pstats.s_intel -= ring_str;
181
182 /* Now do the potion */
183 if (change < 0) msg("You feel slightly less intelligent now.");
184 else msg("You feel more intelligent now. What a mind!");
185
186 pstats.s_intel += change;
187 if (pstats.s_intel > MAXATT) pstats.s_intel = MAXATT;
188 else if (pstats.s_intel < 3) pstats.s_intel = 3;
189
190 /* Adjust the maximum */
191 if (max_stats.s_intel < pstats.s_intel)
192 max_stats.s_intel = pstats.s_intel;
193
194 /* Now put back the ring changes */
195 if (ring_str)
196 pstats.s_intel += ring_str;
197
198 return(0);
199 }
200
201 /*
202 * this routine makes the hero move slower
203 */
204
205 add_slow()
206 {
207 /* monks cannot be slowed or hasted */
208 if (player.t_ctype == C_MONK || ISWEARING(R_FREEDOM)) {
209 msg(nothing);
210 return;
211 }
212
213 if (on(player, ISHASTE)) { /* Already sped up */
214 extinguish(nohaste);
215 nohaste();
216 }
217 else {
218 msg("You feel yourself moving %sslower.",
219 on(player, ISSLOW) ? "even " : "");
220 if (on(player, ISSLOW))
221 lengthen(noslow, roll(HASTETIME,HASTETIME));
222 else {
223 turn_on(player, ISSLOW);
224 fuse(noslow, (VOID *)NULL, roll(HASTETIME,HASTETIME), AFTER);
225 }
226 }
227 }
228
229 /*
230 * Increase player's strength
231 */
232
233 int
234 add_strength(change)
235 int change;
236 {
237
238 if (change < 0) {
239 msg("You feel slightly weaker now.");
240 chg_str(change);
241 }
242 else {
243 msg("You feel stronger now. What bulging muscles!");
244 chg_str(change);
245 }
246 return(0);
247 }
248
249 /*
250 * Increase player's wisdom
251 */
252
253 int
254 add_wisdom(change)
255 int change;
256 {
257 int ring_str; /* Value of ring strengths */
258
259 /* Undo any ring changes */
260 ring_str = ring_value(R_ADDWISDOM);
261 pstats.s_wisdom -= ring_str;
262
263 /* Now do the potion */
264 if (change < 0) msg("You feel slightly less wise now.");
265 else msg("You feel wiser now. What a sage!");
266
267 pstats.s_wisdom += change;
268 if (pstats.s_wisdom > MAXATT) pstats.s_wisdom = MAXATT;
269 else if (pstats.s_wisdom < 3) pstats.s_wisdom = 3;
270
271 /* Adjust the maximum */
272 if (max_stats.s_wisdom < pstats.s_wisdom)
273 max_stats.s_wisdom = pstats.s_wisdom;
274
275 /* Now put back the ring changes */
276 if (ring_str)
277 pstats.s_wisdom += ring_str;
278
279 return(0);
280 }
281
282 quaff(which, kind, flags, is_potion)
283 int which;
284 int kind;
285 int flags;
286 bool is_potion;
287 {
288 register struct object *obj;
289 register struct linked_list *item, *titem;
290 register struct thing *th;
291 bool cursed, blessed;
292
293 blessed = FALSE;
294 cursed = FALSE;
295 item = NULL;
296
297 if (which < 0) { /* figure out which ourselves */
298 /* This is a potion. */
299 if (player.t_action != C_QUAFF) {
300 int units;
301
302 item = get_item(pack, "quaff", QUAFFABLE, FALSE, FALSE);
303
304 /*
305 * Make certain that it is somethings that we want to drink
306 */
307 if (item == NULL)
308 return;
309
310 /* How long does it take to quaff? */
311 units = usage_time(item);
312 if (units < 0) return;
313
314 player.t_using = item; /* Remember what it is */
315 player.t_no_move = units * movement(&player);
316 if ((OBJPTR(item))->o_type == POTION) player.t_action = C_QUAFF;
317 else player.t_action = C_USE;
318 return;
319 }
320
321 /* We have waited our time, let's quaff the potion */
322 item = player.t_using;
323 player.t_using = NULL;
324 player.t_action = A_NIL;
325
326 obj = OBJPTR(item);
327 /* remove it from the pack */
328 inpack--;
329 detach(pack, item);
330
331 flags = obj->o_flags;
332 which = obj->o_which;
333 kind = obj->o_kind;
334 }
335 cursed = flags & ISCURSED;
336 blessed = flags & ISBLESSED;
337
338 switch(which) {
339 case P_CLEAR:
340 if (cursed) {
341 confus_player();
342 }
343 else {
344 if (blessed) { /* Make player immune for the whole game */
345 extinguish(unclrhead); /* If we have a fuse, put it out */
346 msg("A strong blue aura surrounds your head.");
347 }
348 else { /* Just light a fuse for how long player is safe */
349 if (off(player, ISCLEAR)) {
350 fuse(unclrhead, (VOID *)NULL, CLRDURATION, AFTER);
351 msg("A faint blue aura surrounds your head.");
352 }
353 else { /* If we have a fuse lengthen it, else we
354 * are permanently clear.
355 */
356 if (find_slot(unclrhead) == 0)
357 msg("Your blue aura continues to glow strongly.");
358 else {
359 lengthen(unclrhead, CLRDURATION);
360 msg("Your blue aura brightens for a moment.");
361 }
362 }
363 }
364 turn_on(player, ISCLEAR);
365 /* If player is confused, unconfuse him */
366 if (on(player, ISHUH)) {
367 extinguish(unconfuse);
368 unconfuse();
369 }
370 }
371 when P_HEALING:
372 if (cursed) {
373 msg("You feel worse now.");
374 pstats.s_hpt -= roll(pstats.s_lvl, char_class[player.t_ctype].hit_pts);