-
Notifications
You must be signed in to change notification settings - Fork 1
/
wizard.c
369 lines (351 loc) · 7.01 KB
/
wizard.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
/*
* Mostly wizard commands. Sometimes used by players.
*
* @(#)wizard.c 9.0 (rdk) 7/17/84
*
* Super-Rogue
* Copyright (C) 1984 Robert D. Kindelberger
* All rights reserved.
*
* Based on "Rogue: Exploring the Dungeons of Doom"
* Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
* All rights reserved.
*
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <termios.h>
#include <ctype.h>
#include "rogue.h"
#include <pwd.h>
#include "rogue.ext"
extern struct termios terminal;
/*
* whatis:
* What a certain object is
*/
whatis(what)
struct linked_list *what;
{
reg struct object *obj;
reg struct linked_list *item;
reg int wh;
if (what == NULL) { /* we need to ask */
if ((item = get_item("identify", 0)) == NULL)
return;
}
else /* no need to ask */
item = what;
obj = OBJPTR(item);
setoflg(obj, ISKNOW);
wh = obj->o_which;
switch (obj->o_type) {
case SCROLL:
s_know[wh] = TRUE;
if (s_guess[wh]) {
free(s_guess[wh]);
s_guess[wh] = NULL;
}
when POTION:
p_know[wh] = TRUE;
if (p_guess[wh]) {
free(p_guess[wh]);
p_guess[wh] = NULL;
}
when STICK:
ws_know[wh] = TRUE;
if (ws_guess[wh]) {
free(ws_guess[wh]);
ws_guess[wh] = NULL;
}
when RING:
r_know[wh] = TRUE;
if (r_guess[wh]) {
free(r_guess[wh]);
r_guess[wh] = NULL;
}
}
if (what == NULL)
msg(inv_name(obj, FALSE));
}
/*
* create_obj:
* Create any object for wizard or scroll (almost)
*/
create_obj(fscr)
bool fscr;
{
reg struct linked_list *item;
reg struct object *obj;
reg int wh, ch, otype;
char newitem, newtype, msz, *oname;
struct magic_info *mf;
bool nogood = TRUE, inhw = FALSE;
if (fscr)
msg(" ");
else if (wizard) {
msg("Create what?%s: ", starlist);
ch = readchar();
mpos = 0;
if (ch == ESCAPE)
return;
else if (ch != '*')
nogood = FALSE;
}
if (nogood) {
inhw = TRUE;
wclear(hw);
wprintw(hw,"Item\tKey\n\n");
for (otype = 0; otype < NUMTHINGS; otype++) {
if (otype != TYP_AMULET || wizard) {
mf = &thnginfo[otype];
wprintw(hw,"%s\t %c\n",things[otype].mi_name,mf->mf_show);
}
}
if (wizard)
waddstr(hw,"monster\t (A-z)");
wprintw(hw,"\n\nWhat do you want to create? ");
draw(hw);
do {
ch = readchar();
if (ch == ESCAPE) {
after = FALSE;
restscr(cw);
return;
}
switch (ch) {
case RING: case STICK: case POTION:
case SCROLL: case ARMOR: case WEAPON:
case FOOD: case AMULET:
nogood = FALSE;
break;
default:
if (isalpha(ch))
nogood = FALSE;
}
} while (nogood);
}
if (isalpha(ch)) {
if (inhw)
restscr(cw);
makemons(ch); /* make monster & be done with it */
return;
}
otype = getindex(ch);
if (otype == -1 || (otype == AMULET && !wizard)) {
if (inhw)
restscr(cw);
mpos = 0;
msg("You can't create that !!");
return;
}
newitem = ch;
mf = &thnginfo[otype];
oname = things[otype].mi_name;
msz = mf->mf_max;
nogood = TRUE;
if (msz == 1) { /* if only one type of item */
ch = 'a';
nogood = FALSE;
}
else if (!fscr && wizard) {
if (!inhw) {
msg("Which %s?%s: ", oname, starlist);
ch = readchar();
if (ch == ESCAPE)
return;
if (ch != '*')
nogood = FALSE;
}
}
if (nogood) {
struct magic_item *wmi;
int ii;
mpos = 0;
inhw = TRUE;
switch(newitem) {
case POTION: wmi = &p_magic[0];
when SCROLL: wmi = &s_magic[0];
when RING: wmi = &r_magic[0];
when STICK: wmi = &ws_magic[0];
when WEAPON: wmi = &w_magic[0];
otherwise: wmi = &a_magic[0];
}
wclear(hw);
for (ii = 0 ; ii < msz ; ii++) {
mvwaddch(hw,ii % 13,ii > 12 ? COLS/2 : 0, ii + 'a');
waddstr(hw,") ");
waddstr(hw,wmi->mi_name);
wmi++;
}
sprintf(prbuf,"Which %s? ", oname);
mvwaddstr(hw,LINES - 1, 0, prbuf);
draw(hw);
do {
ch = readchar();
if (ch == ESCAPE) {
restscr(cw);
msg("");
return;
}
} while (!isalpha(ch));
}
if (inhw) /* restore screen if need be */
restscr(cw);
newtype = tolower(ch) - 'a';
if (newtype < 0 || newtype >= msz) { /* if an illegal value */
mpos = 0;
after = FALSE;
if (inhw)
restscr(cw);
msg("There is no such %s", oname);
return;
}
mpos = 0;
item = new_thing(FALSE, newitem, newtype);
obj = OBJPTR(item);
wh = obj->o_type;
if (wh == WEAPON || wh == ARMOR || wh == RING) {
if (fscr) /* users get +3 to -3 */
ch = rnd(7) - 3;
else { /* wizard gets to choose */
if (wh == RING)
init_ring(obj, TRUE);
else
ch = getbless();
}
if (wh == WEAPON)
obj->o_hplus = obj->o_dplus = ch;
else if (wh == ARMOR)
obj->o_ac = armors[obj->o_which].a_class - ch;
if (ch < 0)
setoflg(obj, ISCURSED);
else
resoflg(obj, ISCURSED);
}
mpos = 0;
if (fscr)
whatis(item); /* identify for aquirement scroll */
wh = add_pack(item, FALSE);
if (wh == FALSE) /* won't fit in pack */
discard(item);
}
/*
* getbless:
* Get a blessing for a wizards object
*/
getbless()
{
int bless;
msg("Blessing: ");
prbuf[0] = '\0';
bless = get_str(prbuf, cw);
if (bless == NORM)
bless = atoi(prbuf);
else
bless = 0;
return bless;
}
/*
* makemons:
* Make a monster
*/
makemons(what)
int what;
{
reg int x, y, oktomake = FALSE, appear = 1;
struct coord mp;
oktomake = FALSE;
for (x = hero.x - 1 ; x <= hero.x + 1 ; x++) {
for (y = hero.y - 1 ; y <= hero.y + 1 ; y++) {
if (x != hero.x || y != hero.y) {
if (step_ok(winat(y, x)) && rnd(++appear) == 0) {
mp.x = x;
mp.y = y;
oktomake = TRUE;
break;
}
}
}
}
if (oktomake) {
new_monster(midx(what), &mp, FALSE);
look(FALSE);
}
return oktomake;
}
/*
* telport:
* Bamf the thing someplace else
*/
teleport(spot, th)
struct coord spot;
struct thing *th;
{
reg int rm, y, x;
struct coord oldspot;
struct room *rp;
bool ishero;
ishero = (th == &player);
oldspot = th->t_pos;
y = th->t_pos.y;
x = th->t_pos.x;
mvwaddch(cw, y, x, th->t_oldch);
if (!ishero)
mvwaddch(mw, y, x, ' ');
rp = roomin(&spot);
if (spot.y < 0 || !step_ok(winat(spot.y, spot.x))) {
rp = &rooms[rnd_room()];
th->t_pos = *rnd_pos(rp);
}
else
th->t_pos = spot;
rm = rp - &rooms[0];
th->t_room = rp;
th->t_oldch = mvwinch(cw, th->t_pos.y, th->t_pos.x);
light(&oldspot);
th->t_nomove = 0;
if (ishero) {
light(&hero);
mvwaddch(cw, hero.y, hero.x, PLAYER);
/*
* turn off ISHELD in case teleportation was done
* while fighting a Fungi or Bone Devil.
*/
if (pl_on(ISHELD))
unhold('F');
count = 0;
running = FALSE;
flushinp(); /* flush typeahead */
nochange = FALSE;
}
else
mvwaddch(mw, th->t_pos.y, th->t_pos.x, th->t_type);
return rm;
}
/*
* passwd:
* See if user knows password
*/
passwd()
{
reg char *sp, c;
bool passok;
char buf[LINLEN], *xcrypt();
msg(wizstr);
mpos = 0;
sp = buf;
while ((c = getchar()) != '\n' && c != '\r' && c != ESCAPE)
if (c == terminal.c_cc[VKILL])
sp = buf;
else if (c == terminal.c_cc[VERASE] && sp > buf)
sp--;
else
*sp++ = c;
if (sp == buf)
passok = FALSE;
else {
*sp = '\0';
passok = (strcmp(PASSWD, xcrypt(buf, "mT")) == 0);
}
return passok;
}