-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscroll.c
More file actions
334 lines (284 loc) · 8.73 KB
/
scroll.c
File metadata and controls
334 lines (284 loc) · 8.73 KB
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
/* =============================================================================
* PROGRAM: ularn
* FILENAME: scroll.c
*
* DESCRIPTION:
* This module handles the processing for scrolls and books.
*
* =============================================================================
* EXPORTED VARIABLES
*
* scrollname : The name of each scroll.
*
* =============================================================================
* EXPORTED FUNCTIONS
*
* newscroll : Function to create a new scroll # with the correct probability
* read_scroll : Function to process reading a scroll.
* readbook : Function to process reading a book.
*
* =============================================================================
*/
#include "scroll.h"
#include "dungeon.h"
#include "dungeon_obj.h"
#include "header.h"
#include "itm.h"
#include "monster.h"
#include "player.h"
#include "potion.h"
#include "spell.h"
#include "ularn_win.h"
/* =============================================================================
* Exported variables
*/
/* name array for scrolls */
char *scrollname[MAXSCROLL] = {" enchant armor",
" enchant weapon",
" enlightenment",
" blank paper",
" create monster",
" create artifact",
" aggravate monsters",
" time warp",
" teleportation",
" expanded awareness",
" haste monsters",
" monster healing",
" spirit protection",
" undead protection",
" stealth",
" magic mapping",
" hold monsters",
" gem perfection",
" spell extension",
" identify",
" remove curse",
" annihilation",
" pulverization",
" life protection",
" ",
" ",
" ",
" "};
/* =============================================================================
* Local variables
*/
/*
* data for the function to read a scroll
*/
static int xh, yh, yl, xl;
/*
* List of attributes affected by spell extension
*/
#define EXTENSION_COUNT 11
static int exten[EXTENSION_COUNT] = {PROTECTIONTIME, DEXCOUNT, STRCOUNT,
CHARMCOUNT, INVISIBILITY, CANCELLATION,
HASTESELF, GLOBE, SCAREMONST,
HOLDMONST, TIMESTOP};
/*
* Array to create scroll numbers with appropriate probability of
* occurrence.
*/
#define SCROLL_PROB_SIZE 81
static char scprob[SCROLL_PROB_SIZE] = {
SENCHANTARM, SENCHANTARM, SENCHANTARM, SENCHANTARM, SENCHANTWEAP,
SENCHANTWEAP, SENCHANTWEAP, SENCHANTWEAP, SENCHANTWEAP, SENLIGHTEN,
SENLIGHTEN, SENLIGHTEN, SENLIGHTEN, SENLIGHTEN, SENLIGHTEN,
SBLANK, SBLANK, SBLANK, SBLANK, SBLANK,
SCREATEMONST, SCREATEMONST, SCREATEMONST, SCREATEITEM, SCREATEITEM,
SCREATEITEM, SCREATEITEM, SCREATEITEM, SAGGMONST, SAGGMONST,
SAGGMONST, SAGGMONST, SAGGMONST, STIMEWARP, STIMEWARP,
STIMEWARP, STIMEWARP, STELEPORT, STELEPORT, STELEPORT,
SAWARENESS, SAWARENESS, SAWARENESS, SAWARENESS, SHASTEMONST,
SHASTEMONST, SHASTEMONST, SHASTEMONST, SMONSTHEAL, SMONSTHEAL,
SMONSTHEAL, SSPIRITPROT, SSPIRITPROT, SSPIRITPROT, SUNDEADPROT,
SUNDEADPROT, SUNDEADPROT, SUNDEADPROT, SSTEALTH, SSTEALTH,
SMAGICMAP, SMAGICMAP, SHOLDMONST, SHOLDMONST, SHOLDMONST,
SGEMPERFECT, SGEMPERFECT, SSPELLEXT, SSPELLEXT, SIDENTIFY,
SIDENTIFY, SIDENTIFY, SREMCURSE, SREMCURSE, SREMCURSE,
SREMCURSE, SANNIHILATE, SPULVERIZE, SPULVERIZE, SPULVERIZE,
SLIFEPROT};
/* =============================================================================
* Exported functions
*/
/* =============================================================================
* FUNCTION: newscroll
*/
int newscroll(void) { return scprob[rund(SCROLL_PROB_SIZE)]; }
/* =============================================================================
* FUNCTION: read_scroll
*/
void read_scroll(int typ) {
int i, j;
if (typ < 0 || typ >= MAXSCROLL)
return; /* be sure we are within bounds */
if (scrollknown[typ] == 0)
scrollknown[typ] = 1;
Printf("\nYou read a scroll of %s.", &(scrollname[typ][1]));
switch (typ) {
case SENCHANTARM:
enchantarmor(ENCH_SCROLL);
return;
case SENCHANTWEAP:
enchweapon(ENCH_SCROLL);
return;
case SENLIGHTEN:
yh = min(playery + 7, MAXY);
xh = min(playerx + 25, MAXX);
yl = max(playery - 7, 0);
xl = max(playerx - 25, 0);
for (i = yl; i < yh; i++) {
for (j = xl; j < xh; j++) {
know[j][i] = item[j][i];
if (mitem[j][i].mon != MONST_NONE)
stealth[j][i] |= STEALTH_SEEN;
}
}
nap(2000);
draws(xl, xh, yl, yh);
return;
case SBLANK:
return;
case SCREATEMONST:
createmonster(makemonst(level + 1));
return;
case SCREATEITEM:
something(playerx, playery, level);
return;
case SAGGMONST:
c[AGGRAVATE] += 800;
return;
case STIMEWARP:
/*
* This code is slightly wrong in that, if gtime is small and
* we can't go back by the required number of mobuls, it's
* still reported that we did. I don't think this is
* critical -- dmr
*/
i = (rnd(1000) - 850) / 100;
if (i == 0)
i = 1;
gtime += 100 * i;
if (gtime < 0)
gtime = 0;
Printf("\nYou go %sward in time by %d mobul%s", (i < 0) ? "back" : "for",
abs(i), plural(i));
adjusttime((long)(i * 100)); /* adjust time for time warping */
return;
case STELEPORT:
oteleport(0);
return;
case SAWARENESS:
c[AWARENESS] += 1800;
return;
case SHASTEMONST:
c[HASTEMONST] += rnd(55) + 12;
Printf(" You feel nervous.");
return;
case SMONSTHEAL:
for (i = 0; i < MAXY; i++) {
for (j = 0; j < MAXX; j++)
if (mitem[j][i].mon)
hitp[j][i] = monster[(int)mitem[j][i].mon].hitpoints;
}
Printf(" You feel uneasy.");
return;
case SSPIRITPROT:
c[SPIRITPRO] += 300 + rnd(200);
UpdateEffects();
return;
case SUNDEADPROT:
c[UNDEADPRO] += 300 + rnd(200);
UpdateEffects();
return;
case SSTEALTH:
c[STEALTH] += 250 + rnd(250);
UpdateEffects();
return;
case SMAGICMAP:
for (i = 0; i < MAXY; i++) {
for (j = 0; j < MAXX; j++) {
know[j][i] = item[j][i];
if (mitem[j][i].mon != MONST_NONE)
stealth[j][i] |= STEALTH_SEEN;
}
}
nap(2000);
draws(0, MAXX, 0, MAXY);
return;
case SHOLDMONST:
c[HOLDMONST] += 30;
UpdateEffects();
return;
case SGEMPERFECT:
for (i = 0; i < IVENSIZE; i++) {
switch (iven[i]) {
case ODIAMOND:
case ORUBY:
case OEMERALD:
case OSAPPHIRE:
j = ivenarg[i];
j *= 2;
if ((j <= 0) && ivenarg[i])
j = 2550;
ivenarg[i] = (short)j;
break;
default:
break;
}
}
break;
case SSPELLEXT:
for (i = 0; i < EXTENSION_COUNT; i++)
c[exten[i]] <<= 1;
break;
case SIDENTIFY:
for (i = 0; i < IVENSIZE; i++) {
if (iven[i] == OPOTION)
potionknown[ivenarg[i]] = 1;
if (iven[i] == OSCROLL)
scrollknown[ivenarg[i]] = 1;
}
break;
case SREMCURSE:
removecurse();
break;
case SANNIHILATE:
annihilate();
break;
case SPULVERIZE:
godirect(SPELL_LIT, 150, "The ray hits the %s.", 10, EFFECT_LIT);
break;
case SLIFEPROT:
c[LIFEPROT]++;
break;
}
}
/* =============================================================================
* FUNCTION: readbook
*/
void readbook(int arg) {
int i, tmp;
if (arg <= 3) {
tmp = max(splev[arg], 1);
i = rund(tmp + 1);
} else {
if (arg >= NLEVELS)
arg = NLEVELS - 1;
/* Stop finding lower level spells deeper in the dungeon */
tmp = max(splev[arg] - 9, 1);
i = rnd(tmp) + 9;
}
/* Learn this spell more */
spelknow[i]++;
Printf("\nSpell \"%s\": %s\n%s.", spelcode[i], spelname[i], speldescript[i]);
/*
* Boost int 40% of the time
*/
if (rnd(10) == 4) {
Print("\nYou feel clever!");
c[INTELLIGENCE]++;
UpdateStatus();
}
}