-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpotion.c
298 lines (255 loc) · 7.73 KB
/
potion.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
/* =============================================================================
* PROGRAM: ularn
* FILENAME: potion.c
*
* DESCRIPTION:
* This module contains definitions and functions for handling potions.
*
* =============================================================================
* EXPORTED VARIABLES
*
* potionname : The name of each potion
*
* =============================================================================
* EXPORTED FUNCTIONS
*
* newpotion : Function to create a new potion with the required probabilities
* quaffpotion : Function to process quaffing a potion.
*
* =============================================================================
*/
#include "potion.h"
#include "dungeon.h"
#include "header.h"
#include "itm.h"
#include "monster.h"
#include "player.h"
#include "ularn_win.h"
/* =============================================================================
* Exported variables
*/
/* name array for magic potions */
char *potionname[MAXPOTION] = {" sleep",
" healing",
" raise level",
" increase ability",
" wisdom",
" strength",
" raise charisma",
" dizziness",
" learning",
" gold detection",
" monster detection",
" forgetfulness",
" water",
" blindness",
" confusion",
" heroism",
" sturdiness",
" giant strength",
" fire resistance",
" treasure finding",
" instant healing",
" cure dianthroritis",
" poison",
" see invisible",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};
/* =============================================================================
* Local variables
*/
/*
* Array to return a potion number created with appropriate probability
* of occurrence.
* Each potion appears in this array a number of times proportionate to
* its probability of occurence.
*/
#define POTION_PROB_SIZE 41
static char potprob[POTION_PROB_SIZE] = {
PSLEEP, PSLEEP, PHEALING, PHEALING, PHEALING, PRAISELEVEL, PINCABILITY,
PINCABILITY, PWISDOM, PWISDOM, PSTRENGTH, PSTRENGTH, PCHARISMA, PCHARISMA,
PDIZZINESS, PDIZZINESS, PLEARNING, PGOLDDET, PGOLDDET, PGOLDDET, PMONSTDET,
PMONSTDET, PMONSTDET, PFORGETFUL, PFORGETFUL, PWATER, PWATER, PBLINDNESS,
PCONFUSION, PHEROISM, PSTURDINESS, PGIANTSTR, PFIRERESIST, PTREASURE,
PTREASURE, PINSTHEAL, PINSTHEAL,
/* No Cure Dianthroritis */
PPOISON, PPOISON, PSEEINVIS, PSEEINVIS};
/* =============================================================================
* Exported functions
*/
/* =============================================================================
* FUNCTION: newpotion
*/
int newpotion(void) { return potprob[rund(POTION_PROB_SIZE)]; }
/* =============================================================================
* FUNCTION: quaffpotion
*/
void quaffpotion(int pot) {
int i, j;
int k;
/* check for within bounds */
if (pot < 0 || pot >= MAXPOTION)
return;
if (potionknown[pot] == 0)
potionknown[pot] = 1;
Printf("\nYou drink a potion of %s.", &potionname[pot][1]);
/*
* In the switch, if no status/attr changes then use return,
* else use break to get the UpdateStatusAndEffects call.
*/
switch (pot) {
case PSLEEP:
Print("\n You fall asleep...");
i = rnd(11) - (c[CONSTITUTION] >> 2) + 2;
while (--i > 0) {
parse2();
nap(1000);
}
Print("\n.. you wake up.");
return;
case PHEALING:
Print("\n You feel better.");
if (c[HP] == c[HPMAX])
/* Already fully healed, so increase max hp */
raisemhp(1);
else if ((c[HP] += rnd(20) + 20 + c[LEVEL]) > c[HPMAX])
c[HP] = c[HPMAX];
break;
case PRAISELEVEL:
Print("\n You feel much more skillful!");
raiselevel();
raisemhp(1);
break;
case PINCABILITY:
Print("\n You feel strange for a moment.");
i = ABILITY_FIRST + rund(ABILITY_COUNT);
c[i]++;
break;
case PWISDOM:
Print("\n You feel more self-confident!");
c[WISDOM] += rnd(2);
break;
case PSTRENGTH:
Print("\n Wow! You feel great!");
if (c[STRENGTH] < 12)
c[STRENGTH] = 12;
else
c[STRENGTH]++;
break;
case PCHARISMA:
Print("\n You feel charismatic!");
c[CHARISMA]++;
break;
case PDIZZINESS:
Print("\n You become dizzy!");
if (--c[STRENGTH] < 3)
c[STRENGTH] = 3;
break;
case PLEARNING:
Print("\n You feel clever!");
c[INTELLIGENCE]++;
break;
case PGOLDDET:
Print("\n You feel greedy...");
nap(2000);
for (i = 0; i < MAXY; i++) {
for (j = 0; j < MAXX; j++)
if ((item[j][i] == OGOLDPILE) || (item[j][i] == OMAXGOLD))
show1cell(j, i);
}
showplayer();
return;
case PMONSTDET:
for (i = 0; i < MAXY; i++) {
for (j = 0; j < MAXX; j++)
if (mitem[j][i].mon)
show1cell(j, i);
}
return;
case PFORGETFUL:
Print("\n You stagger for a moment...");
for (i = 0; i < MAXY; i++)
for (j = 0; j < MAXX; j++)
know[j][i] = OUNKNOWN;
nap(2000);
draws(0, MAXX, 0, MAXY);
return;
case PWATER:
return;
case PBLINDNESS:
Print("\n You can't see anything!");
c[BLINDCOUNT] += 250; /* dang, that's a long time. */
/* erase the character, too! */
showplayer();
return;
case PCONFUSION:
Print("\n You feel confused.");
c[CONFUSE] += 20 + rnd(9);
return;
case PHEROISM:
Print("\n WOW! You feel fantastic!");
if (c[HERO] == 0)
for (i = ABILITY_FIRST; i <= ABILITY_LAST; i++)
c[i] += PHEROISM_BOOST;
c[HERO] += 250;
break;
case PSTURDINESS:
Print("\n You feel healthier!");
c[CONSTITUTION]++;
break;
case PGIANTSTR:
Print("\n You now have incredible bulging muscles!");
if (c[GIANTSTR] == 0)
c[STREXTRA] += PGIANTSTR_BOOST;
c[GIANTSTR] += 700;
break;
case PFIRERESIST:
Print("\n You feel a chill run up your spine!");
c[FIRERESISTANCE] += 1000;
break;
case PTREASURE:
Print("\n You feel greedy...");
nap(2000);
for (i = 0; i < MAXY; i++) {
for (j = 0; j < MAXX; j++) {
k = item[j][i];
if ((k == ODIAMOND) || (k == ORUBY) || (k == OEMERALD) ||
(k == OMAXGOLD) || (k == OSAPPHIRE) || (k == OLARNEYE) ||
(k == OGOLDPILE))
show1cell(j, i);
}
}
showplayer();
return;
case PINSTHEAL:
c[HP] = c[HPMAX];
removecurse();
break;
case PCUREDIANTH:
Print("\n You don't seem to be affected.");
return;
case PPOISON:
Print("\n You feel a sickness engulf you!");
c[HALFDAM] += 200 + rnd(200);
return;
case PSEEINVIS:
Print("\n You feel your vision sharpen.");
c[SEEINVISIBLE] += rnd(1000) + 400;
monstnamelist[INVISIBLESTALKER] = 'I';
return;
default:
break;
}
/* show new stats */
UpdateStatusAndEffects();
return;
}