comparison xrogue/wizard.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 wizard.c - Special wizard commands
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 /*
20 * Special wizard commands (some of which are also non-wizard commands
21 * under strange circumstances)
22 */
23
24 #include <curses.h>
25 #include <ctype.h>
26 #include <string.h>
27 #include "rogue.h"
28 #include "mach_dep.h"
29
30 /*
31 * create_obj:
32 * Create any object for wizard, scroll, magician, or cleric
33 */
34
35 create_obj(prompt, which_item, which_type)
36 bool prompt;
37 int which_item, which_type;
38 {
39 reg struct linked_list *item;
40 reg struct object *obj;
41 reg int wh;
42 char *pt;
43 reg int ch, whc, newtype = 0, msz, newitem;
44 WINDOW *thiswin;
45
46 thiswin = cw;
47 if (prompt) {
48 bool nogood = TRUE;
49
50 thiswin = hw;
51 wclear(hw);
52 wprintw(hw,"Item\t\t\tKey\n\n");
53 wprintw(hw,"%s\t\t\t%c\n%s\t\t\t%c\n",things[TYP_RING].mi_name,RING,
54 things[TYP_STICK].mi_name,STICK);
55 wprintw(hw,"%s\t\t\t%c\n%s\t\t\t%c\n",things[TYP_POTION].mi_name,POTION,
56 things[TYP_SCROLL].mi_name,SCROLL);
57 wprintw(hw,"%s\t\t\t%c\n%s\t\t\t%c\n",things[TYP_ARMOR].mi_name,ARMOR,
58 things[TYP_WEAPON].mi_name,WEAPON);
59 wprintw(hw,"%s\t%c\n",things[TYP_MM].mi_name,MM);
60 wprintw(hw,"%s\t\t\t%c\n",things[TYP_FOOD].mi_name,FOOD);
61 if (wizard) {
62 wprintw(hw,"%s\t\t%c\n",things[TYP_RELIC].mi_name,RELIC);
63 wprintw(hw,"monster\t\t\tm");
64 }
65 wprintw(hw,"\n\nWhat do you want to create? ");
66 draw(hw);
67 do {
68 ch = wgetch(hw);
69 if (ch == ESC) {
70 restscr(cw);
71 return;
72 }
73 switch (ch) {
74 case RING:
75 case STICK:
76 case POTION:
77 case SCROLL:
78 case ARMOR:
79 case WEAPON:
80 case FOOD:
81 case MM:
82 nogood = FALSE;
83 break;
84 case RELIC:
85 case 'm':
86 if (wizard)
87 nogood = FALSE;
88 break;
89 default:
90 nogood = TRUE;
91 }
92 } while (nogood);
93 newitem = ch;
94 }
95 else
96 newitem = which_item;
97
98 pt = "those";
99 msz = 0;
100 if(newitem == 'm') {
101 /* make monster and be done with it */
102 wh = makemonster(TRUE, "create");
103 if (wh > 0) {
104 creat_mons (&player, wh, TRUE);
105 light(&hero);
106 }
107 return;
108 }
109 if(newitem == GOLD) pt = "gold";
110 else if(isatrap(newitem)) pt = "traps";
111
112 switch(newitem) {
113 case POTION: whc = TYP_POTION; msz = MAXPOTIONS;
114 when SCROLL: whc = TYP_SCROLL; msz = MAXSCROLLS;
115 when WEAPON: whc = TYP_WEAPON; msz = MAXWEAPONS;
116 when ARMOR: whc = TYP_ARMOR; msz = MAXARMORS;
117 when RING: whc = TYP_RING; msz = MAXRINGS;
118 when STICK: whc = TYP_STICK; msz = MAXSTICKS;
119 when MM: whc = TYP_MM; msz = MAXMM;
120 when RELIC: whc = TYP_RELIC; msz = MAXRELIC;
121 when FOOD: whc = TYP_FOOD; msz = MAXFOODS;
122 otherwise:
123 if (thiswin == hw)
124 restscr(cw);
125 mpos = 0;
126 msg("Even wizards can't create %s !!",pt);
127 return;
128 }
129 if(msz == 1) { /* if only one type of item */
130 ch = 'a';
131 }
132 else if (prompt) {
133 register struct magic_item *wmi;
134 char wmn;
135 register int ii;
136 int old_prob;
137
138 mpos = 0;
139 wmi = NULL;
140 wmn = 0;
141 switch(newitem) {
142 case POTION: wmi = &p_magic[0];
143 when SCROLL: wmi = &s_magic[0];
144 when RING: wmi = &r_magic[0];
145 when STICK: wmi = &ws_magic[0];
146 when MM: wmi = &m_magic[0];
147 when RELIC: wmi = &rel_magic[0];
148 when FOOD: wmi = &foods[0];
149 when WEAPON: wmn = 1;
150 when ARMOR: wmn = 2;
151 }
152 wclear(hw);
153 thiswin = hw;
154 if (wmi != NULL) {
155 ii = old_prob = 0;
156 while (ii < msz) {
157 if(wmi->mi_prob == old_prob && wizard == FALSE) {
158 msz--; /* can't make a unique item */
159 }
160 else {
161 mvwaddch(hw,ii % 13,ii > 12 ? cols/2 : 0, ii + 'a');
162 waddstr(hw,") ");
163 waddstr(hw,wmi->mi_name);
164 ii++;
165 }
166 old_prob = wmi->mi_prob;
167 wmi++;
168 }
169 }
170 else if (wmn != 0) {
171 for(ii = 0 ; ii < msz ; ii++) {
172 mvwaddch(hw,ii % 13,ii > 12 ? cols/2 : 0, ii + 'a');
173 waddstr(hw,") ");
174 if(wmn == 1)
175 waddstr(hw,weaps[ii].w_name);
176 else
177 waddstr(hw,armors[ii].a_name);
178 }
179 }
180 sprintf(prbuf,"Which %s? ",things[whc].mi_name);
181 mvwaddstr(hw,lines - 1, 0, prbuf);
182 draw(hw);
183 do {
184 ch = wgetch(hw);
185 if (ch == ESC) {
186 restscr(cw);
187 msg("");
188 return;
189 }
190 } until (isalpha(ch));
191 if (thiswin == hw) /* restore screen if need be */
192 restscr(cw);
193 newtype = ch - 'a';
194 if(newtype < 0 || newtype >= msz) { /* if an illegal value */
195 mpos = 0;
196 msg("There is no such %s",things[whc].mi_name);
197 return;
198 }
199 }
200 else
201 newtype = which_type;
202 item = new_item(sizeof *obj); /* get some memory */
203 obj = OBJPTR(item);
204 obj->o_type = newitem; /* store the new items */
205 obj->o_mark[0] = '\0';
206 obj->o_which = newtype;
207 obj->o_group = 0;
208 obj->contents = NULL;
209 obj->o_count = 1;
210 obj->o_flags = 0;
211 obj->o_dplus = obj->o_hplus = 0;
212 obj->o_weight = 0;
213 wh = obj->o_which;
214 mpos = 0;
215 if (!wizard) /* users get 0 to +5 */
216 whc = rnd(6);
217 else /* wizard gets to choose */
218 whc = getbless();
219 if (whc < 0)
220 obj->o_flags |= ISCURSED;
221 switch (obj->o_type) {
222 case WEAPON:
223 case ARMOR:
224 if (obj->o_type == WEAPON) {
225 init_weapon(obj, wh);
226 obj->o_hplus += whc;
227 if (!wizard) whc = rnd(6);
228 obj->o_dplus += whc;
229 }
230 else { /* armor here */
231 obj->o_weight = armors[wh].a_wght;
232 obj->o_ac = armors[wh].a_class - whc;
233 }
234 when RING:
235 r_know[wh] = TRUE;
236 switch(wh) {
237 case R_ADDSTR:
238 case R_ADDWISDOM:
239 case R_ADDINTEL:
240 case R_PROTECT:
241 case R_ADDHIT:
242 case R_ADDDAM:
243 case R_DIGEST:
244 obj->o_ac = whc + 2;
245 break;
246 default:
247 obj->o_ac = 0;
248 }
249 obj->o_weight = things[TYP_RING].mi_wght;
250 when MM:
251 if (whc > 1 && m_magic[wh].mi_bless != 0)
252 obj->o_flags |= ISBLESSED;
253 m_know[wh] = TRUE;
254 switch(wh) {
255 case MM_JUG:
256 switch(rnd(11)) {
257 case 0: obj->o_ac = P_PHASE;
258 when 1: obj->o_ac = P_CLEAR;
259 when 2: obj->o_ac = P_SEEINVIS;
260 when 3: obj->o_ac = P_HEALING;
261 when 4: obj->o_ac = P_MFIND;
262 when 5: obj->o_ac = P_TFIND;
263 when 6: obj->o_ac = P_HASTE;
264 when 7: obj->o_ac = P_RESTORE;
265 when 8: obj->o_ac = P_FLY;
266 when 9: obj->o_ac = P_SKILL;
267 when 10:obj->o_ac = P_FFIND;
268 }
269 when MM_HUNGER:
270 case MM_CHOKE:
271 if (whc < 0 )
272 whc = -whc; /* cannot be negative */
273 obj->o_ac = (whc + 1) * 2;
274 break;
275 when MM_OPEN:
276 case MM_DRUMS:
277 case MM_DISAPPEAR:
278 case MM_KEOGHTOM:
279 if (whc < 0)
280 whc = -whc; /* these cannot be negative */
281 obj->o_ac = (whc + 3) * 5;
282 break;
283 when MM_BRACERS:
284 obj->o_ac = whc + 4;
285 when MM_DISP:
286 obj->o_ac = 3;
287 when MM_PROTECT:
288 obj->o_ac = whc + 4;
289 when MM_SKILLS:
290 if (whc < 2)
291 obj->o_ac = rnd(NUM_CHARTYPES-1);
292 else
293 obj->o_ac = player.t_ctype;
294 when MM_CRYSTAL:
295 obj->o_ac = 1;
296 otherwise:
297 obj->o_ac = 0;
298 }
299 obj->o_weight = things[TYP_MM].mi_wght;
300 when STICK:
301 if (whc > 1 && ws_magic[wh].mi_bless != 0)
302 obj->o_flags |= ISBLESSED;
303 ws_know[wh] = TRUE;
304 fix_stick(obj);
305 when SCROLL:
306 if (whc > 3 && s_magic[wh].mi_bless != 0)
307 obj->o_flags |= ISBLESSED;
308 obj->o_weight = things[TYP_SCROLL].mi_wght;
309 s_know[wh] = TRUE;
310 when POTION:
311 if (whc > 3 && p_magic[wh].mi_bless != 0)
312 obj->o_flags |= ISBLESSED;
313 obj->o_weight = things[TYP_POTION].mi_wght;
314 if (wh == P_ABIL) obj->o_kind = rnd(NUMABILITIES);
315 p_know[wh] = TRUE;
316 when RELIC:
317 obj->o_weight = things[TYP_RELIC].mi_wght;
318 switch (obj->o_which) {
319 case QUILL_NAGROM: obj->o_charges = QUILLCHARGES;
320 when EMORI_CLOAK: obj->o_charges = 1;
321 otherwise: break;
322 }
323 when FOOD:
324 obj->o_weight = things[TYP_FOOD].mi_wght;
325 }
326 mpos = 0;
327 obj->o_flags |= ISKNOW;
328 if (add_pack(item, FALSE) == FALSE) {
329 obj->o_pos = hero;
330 fall(item, TRUE);
331 }
332 }
333
334 /*
335 * getbless:
336 * Get a blessing for a wizards object
337 */
338
339 int
340 getbless()
341 {
342 reg char bless;
343
344 msg("Blessing? (+,-,n)");
345 bless = wgetch(msgw);
346 if (bless == '+')
347 return (15);
348 else if (bless == '-')
349 return (-1);
350 else
351 return (0);
352 }
353
354 /*
355 * get a non-monster death type
356 */
357
358 getdeath()
359 {
360 register int i;
361 int which_death;