comparison srogue/wizard.c @ 36:2128c7dc8a40

Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
author elwin
date Thu, 25 Nov 2010 12:21:41 +0000
parents
children 7612f48a38ad
comparison
equal deleted inserted replaced
35:05018c63a721 36:2128c7dc8a40
1 /*
2 * Mostly wizard commands. Sometimes used by players.
3 *
4 * @(#)wizard.c 9.0 (rdk) 7/17/84
5 *
6 * Super-Rogue
7 * Copyright (C) 1984 Robert D. Kindelberger
8 * All rights reserved.
9 *
10 * Based on "Rogue: Exploring the Dungeons of Doom"
11 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
12 * All rights reserved.
13 *
14 * See the file LICENSE.TXT for full copyright and licensing information.
15 */
16
17 #include <termios.h>
18 #include <ctype.h>
19 #include "rogue.h"
20 #include <pwd.h>
21 #include "rogue.ext"
22
23 extern struct termios terminal;
24
25 /*
26 * whatis:
27 * What a certain object is
28 */
29 whatis(what)
30 struct linked_list *what;
31 {
32 reg struct object *obj;
33 reg struct linked_list *item;
34 reg int wh;
35
36 if (what == NULL) { /* we need to ask */
37 if ((item = get_item("identify", 0)) == NULL)
38 return;
39 }
40 else /* no need to ask */
41 item = what;
42 obj = OBJPTR(item);
43 setoflg(obj, ISKNOW);
44 wh = obj->o_which;
45 switch (obj->o_type) {
46 case SCROLL:
47 s_know[wh] = TRUE;
48 if (s_guess[wh]) {
49 free(s_guess[wh]);
50 s_guess[wh] = NULL;
51 }
52 when POTION:
53 p_know[wh] = TRUE;
54 if (p_guess[wh]) {
55 free(p_guess[wh]);
56 p_guess[wh] = NULL;
57 }
58 when STICK:
59 ws_know[wh] = TRUE;
60 if (ws_guess[wh]) {
61 free(ws_guess[wh]);
62 ws_guess[wh] = NULL;
63 }
64 when RING:
65 r_know[wh] = TRUE;
66 if (r_guess[wh]) {
67 free(r_guess[wh]);
68 r_guess[wh] = NULL;
69 }
70 }
71 if (what == NULL)
72 msg(inv_name(obj, FALSE));
73 }
74
75
76 /*
77 * create_obj:
78 * Create any object for wizard or scroll (almost)
79 */
80 create_obj(fscr)
81 bool fscr;
82 {
83 reg struct linked_list *item;
84 reg struct object *obj;
85 reg int wh, ch, otype;
86 char newitem, newtype, msz, *oname;
87 struct magic_info *mf;
88 bool nogood = TRUE, inhw = FALSE;
89
90 if (fscr)
91 msg(" ");
92 else if (wizard) {
93 msg("Create what?%s: ", starlist);
94 ch = readchar();
95 mpos = 0;
96 if (ch == ESCAPE)
97 return;
98 else if (ch != '*')
99 nogood = FALSE;
100 }
101 if (nogood) {
102 inhw = TRUE;
103 wclear(hw);
104 wprintw(hw,"Item\tKey\n\n");
105 for (otype = 0; otype < NUMTHINGS; otype++) {
106 if (otype != TYP_AMULET || wizard) {
107 mf = &thnginfo[otype];
108 wprintw(hw,"%s\t %c\n",things[otype].mi_name,mf->mf_show);
109 }
110 }
111 if (wizard)
112 waddstr(hw,"monster\t (A-z)");
113 wprintw(hw,"\n\nWhat do you want to create? ");
114 draw(hw);
115 do {
116 ch = readchar();
117 if (ch == ESCAPE) {
118 after = FALSE;
119 restscr(cw);
120 return;
121 }
122 switch (ch) {
123 case RING: case STICK: case POTION:
124 case SCROLL: case ARMOR: case WEAPON:
125 case FOOD: case AMULET:
126 nogood = FALSE;
127 break;
128 default:
129 if (isalpha(ch))
130 nogood = FALSE;
131 }
132 } while (nogood);
133 }
134 if (isalpha(ch)) {
135 if (inhw)
136 restscr(cw);
137 makemons(ch); /* make monster & be done with it */
138 return;
139 }
140 otype = getindex(ch);
141 if (otype == -1 || (otype == AMULET && !wizard)) {
142 if (inhw)
143 restscr(cw);
144 mpos = 0;
145 msg("You can't create that !!");
146 return;
147 }
148 newitem = ch;
149 mf = &thnginfo[otype];
150 oname = things[otype].mi_name;
151 msz = mf->mf_max;
152 nogood = TRUE;
153 if (msz == 1) { /* if only one type of item */
154 ch = 'a';
155 nogood = FALSE;
156 }
157 else if (!fscr && wizard) {
158 if (!inhw) {
159 msg("Which %s?%s: ", oname, starlist);
160 ch = readchar();
161 if (ch == ESCAPE)
162 return;
163 if (ch != '*')
164 nogood = FALSE;
165 }
166 }
167 if (nogood) {
168 struct magic_item *wmi;
169 int ii;
170
171 mpos = 0;
172 inhw = TRUE;
173 switch(newitem) {
174 case POTION: wmi = &p_magic[0];
175 when SCROLL: wmi = &s_magic[0];
176 when RING: wmi = &r_magic[0];
177 when STICK: wmi = &ws_magic[0];
178 when WEAPON: wmi = &w_magic[0];
179 otherwise: wmi = &a_magic[0];
180 }
181 wclear(hw);
182 for (ii = 0 ; ii < msz ; ii++) {
183 mvwaddch(hw,ii % 13,ii > 12 ? COLS/2 : 0, ii + 'a');
184 waddstr(hw,") ");
185 waddstr(hw,wmi->mi_name);
186 wmi++;
187 }
188 sprintf(prbuf,"Which %s? ", oname);
189 mvwaddstr(hw,LINES - 1, 0, prbuf);
190 draw(hw);
191 do {
192 ch = readchar();
193 if (ch == ESCAPE) {
194 restscr(cw);
195 msg("");
196 return;
197 }
198 } while (!isalpha(ch));
199 }
200 if (inhw) /* restore screen if need be */
201 restscr(cw);
202
203 newtype = tolower(ch) - 'a';
204 if (newtype < 0 || newtype >= msz) { /* if an illegal value */
205 mpos = 0;
206 after = FALSE;
207 if (inhw)
208 restscr(cw);
209 msg("There is no such %s", oname);
210 return;
211 }
212 mpos = 0;
213 item = new_thing(FALSE, newitem, newtype);
214 obj = OBJPTR(item);
215 wh = obj->o_type;
216 if (wh == WEAPON || wh == ARMOR || wh == RING) {
217 if (fscr) /* users get +3 to -3 */
218 ch = rnd(7) - 3;
219 else { /* wizard gets to choose */
220 if (wh == RING)
221 init_ring(obj, TRUE);
222 else
223 ch = getbless();
224 }
225 if (wh == WEAPON)
226 obj->o_hplus = obj->o_dplus = ch;
227 else if (wh == ARMOR)
228 obj->o_ac = armors[obj->o_which].a_class - ch;
229 if (ch < 0)
230 setoflg(obj, ISCURSED);
231 else
232 resoflg(obj, ISCURSED);
233 }
234 mpos = 0;
235 if (fscr)
236 whatis(item); /* identify for aquirement scroll */
237 wh = add_pack(item, FALSE);
238 if (wh == FALSE) /* won't fit in pack */
239 discard(item);
240 }
241
242
243 /*
244 * getbless:
245 * Get a blessing for a wizards object
246 */
247 getbless()
248 {
249 int bless;
250
251 msg("Blessing: ");
252 prbuf[0] = '\0';
253 bless = get_str(prbuf, cw);
254 if (bless == NORM)
255 bless = atoi(prbuf);
256 else
257 bless = 0;
258 return bless;
259 }
260
261 /*
262 * makemons:
263 * Make a monster
264 */
265 makemons(what)
266 int what;
267 {
268 reg int x, y, oktomake = FALSE, appear = 1;
269 struct coord mp;
270
271 oktomake = FALSE;
272 for (x = hero.x - 1 ; x <= hero.x + 1 ; x++) {
273 for (y = hero.y - 1 ; y <= hero.y + 1 ; y++) {
274 if (x != hero.x || y != hero.y) {
275 if (step_ok(winat(y, x)) && rnd(++appear) == 0) {
276 mp.x = x;
277 mp.y = y;
278 oktomake = TRUE;
279 break;
280 }
281 }
282 }
283 }
284 if (oktomake) {
285 new_monster(midx(what), &mp, FALSE);
286 look(FALSE);
287 }
288 return oktomake;
289 }
290
291 /*
292 * telport:
293 * Bamf the thing someplace else
294 */
295 teleport(spot, th)
296 struct coord spot;
297 struct thing *th;
298 {
299 reg int rm, y, x;
300 struct coord oldspot;
301 struct room *rp;
302 bool ishero;
303
304 ishero = (th == &player);
305 oldspot = th->t_pos;
306 y = th->t_pos.y;
307 x = th->t_pos.x;
308 mvwaddch(cw, y, x, th->t_oldch);
309 if (!ishero)
310 mvwaddch(mw, y, x, ' ');
311 rp = roomin(&spot);
312 if (spot.y < 0 || !step_ok(winat(spot.y, spot.x))) {
313 rp = &rooms[rnd_room()];
314 th->t_pos = *rnd_pos(rp);
315 }
316 else
317 th->t_pos = spot;
318 rm = rp - &rooms[0];
319 th->t_room = rp;
320 th->t_oldch = mvwinch(cw, th->t_pos.y, th->t_pos.x);
321 light(&oldspot);
322 th->t_nomove = 0;
323 if (ishero) {
324 light(&hero);
325 mvwaddch(cw, hero.y, hero.x, PLAYER);
326 /*
327 * turn off ISHELD in case teleportation was done
328 * while fighting a Fungi or Bone Devil.
329 */
330 if (pl_on(ISHELD))
331 unhold('F');
332 count = 0;
333 running = FALSE;
334 flushinp(); /* flush typeahead */
335 nochange = FALSE;
336 }
337 else
338 mvwaddch(mw, th->t_pos.y, th->t_pos.x, th->t_type);
339 return rm;
340 }
341
342 /*
343 * passwd:
344 * See if user knows password
345 */
346 passwd()
347 {
348 reg char *sp, c;
349 bool passok;
350 char buf[LINLEN], *xcrypt();
351
352 msg(wizstr);
353 mpos = 0;
354 sp = buf;
355 while ((c = getchar()) != '\n' && c != '\r' && c != ESCAPE)
356 if (c == terminal.c_cc[VKILL])
357 sp = buf;
358 else if (c == terminal.c_cc[VERASE] && sp > buf)
359 sp--;
360 else
361 *sp++ = c;
362 if (sp == buf)
363 passok = FALSE;
364 else {
365 *sp = '\0';
366 passok = (strcmp(PASSWD, xcrypt(buf, "mT")) == 0);
367 }
368 return passok;
369 }