comparison rogue5/wizard.c @ 33:f502bf60e6e4

Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
author elwin
date Mon, 24 May 2010 20:10:59 +0000
parents
children e7aab31362af
comparison
equal deleted inserted replaced
32:2dcd75e6a736 33:f502bf60e6e4
1 /*
2 * Special wizard commands (some of which are also non-wizard commands
3 * under strange circumstances)
4 *
5 * @(#)wizard.c 4.30 (Berkeley) 02/05/99
6 *
7 * Rogue: Exploring the Dungeons of Doom
8 * Copyright (C) 1980-1983, 1985, 1999 Michael Toy, Ken Arnold and Glenn Wichman
9 * All rights reserved.
10 *
11 * See the file LICENSE.TXT for full copyright and licensing information.
12 */
13
14 #include <stdlib.h>
15 #include <curses.h>
16 #include <string.h>
17 #include <ctype.h>
18 #include "rogue.h"
19
20 /*
21 * whatis:
22 * What a certin object is
23 */
24
25 void
26 whatis(int insist, int type)
27 {
28 THING *obj;
29
30 if (pack == NULL)
31 {
32 msg("you don't have anything in your pack to identify");
33 return;
34 }
35
36 for (;;)
37 {
38 obj = get_item("identify", type);
39 if (insist)
40 {
41 if (n_objs == 0)
42 return;
43 else if (obj == NULL)
44 msg("you must identify something");
45 else if (type && obj->o_type != type &&
46 !(type == R_OR_S && (obj->o_type == RING || obj->o_type == STICK)) )
47 msg("you must identify a %s", type_name(type));
48 else
49 break;
50 }
51 else
52 break;
53 }
54
55 if (obj == NULL)
56 return;
57
58 switch (obj->o_type)
59 {
60 case SCROLL:
61 set_know(obj, scr_info);
62 when POTION:
63 set_know(obj, pot_info);
64 when STICK:
65 set_know(obj, ws_info);
66 when WEAPON:
67 case ARMOR:
68 obj->o_flags |= ISKNOW;
69 when RING:
70 set_know(obj, ring_info);
71 }
72 msg(inv_name(obj, FALSE));
73 }
74
75 /*
76 * set_know:
77 * Set things up when we really know what a thing is
78 */
79
80 void
81 set_know(THING *obj, struct obj_info *info)
82 {
83 char **guess;
84
85 info[obj->o_which].oi_know = TRUE;
86 obj->o_flags |= ISKNOW;
87 guess = &info[obj->o_which].oi_guess;
88 if (*guess)
89 {
90 free(*guess);
91 *guess = NULL;
92 }
93 }
94
95 /*
96 * type_name:
97 * Return a pointer to the name of the type
98 */
99 const char *
100 type_name(int type)
101 {
102 struct h_list *hp;
103 struct h_list tlist[] = {
104 {POTION, "potion", FALSE},
105 {SCROLL, "scroll", FALSE},
106 {FOOD, "food", FALSE},
107 {R_OR_S, "ring, wand or staff", FALSE},
108 {RING, "ring", FALSE},
109 {STICK, "wand or staff", FALSE},
110 {WEAPON, "weapon", FALSE},
111 {ARMOR, "suit of armor", FALSE},
112 };
113
114 for (hp = tlist; hp->h_ch; hp++)
115 if (type == hp->h_ch)
116 return hp->h_desc;
117 /* NOTREACHED */
118 return(0);
119 }
120
121 #ifdef MASTER
122 /*
123 * create_obj:
124 * wizard command for getting anything he wants
125 */
126
127 void
128 create_obj(void)
129 {
130 THING *obj;
131 int ch, bless;
132
133 obj = new_item();
134 msg("type of item: ");
135 obj->o_type = readchar();
136 mpos = 0;
137 msg("which %c do you want? (0-f)", obj->o_type);
138 obj->o_which = (isdigit((ch = readchar())) ? ch - '0' : ch - 'a' + 10);
139 obj->o_group = 0;
140 obj->o_count = 1;
141 mpos = 0;
142 if (obj->o_type == WEAPON || obj->o_type == ARMOR)
143 {
144 msg("blessing? (+,-,n)");
145 bless = readchar();
146 mpos = 0;
147 if (bless == '-')
148 obj->o_flags |= ISCURSED;
149 if (obj->o_type == WEAPON)
150 {
151 init_weapon(obj, obj->o_which);
152 if (bless == '-')
153 obj->o_hplus -= rnd(3)+1;
154 if (bless == '+')
155 obj->o_hplus += rnd(3)+1;
156 }
157 else
158 {
159 obj->o_arm = a_class[obj->o_which];
160 if (bless == '-')
161 obj->o_arm += rnd(3)+1;
162 if (bless == '+')
163 obj->o_arm -= rnd(3)+1;
164 }
165 }
166 else if (obj->o_type == RING)
167 switch (obj->o_which)
168 {
169 case R_PROTECT:
170 case R_ADDSTR:
171 case R_ADDHIT:
172 case R_ADDDAM:
173 msg("blessing? (+,-,n)");
174 bless = readchar();
175 mpos = 0;
176 if (bless == '-')
177 obj->o_flags |= ISCURSED;
178 obj->o_arm = (bless == '-' ? -1 : rnd(2) + 1);
179 when R_AGGR:
180 case R_TELEPORT:
181 obj->o_flags |= ISCURSED;
182 }
183 else if (obj->o_type == STICK)
184 fix_stick(obj);
185 else if (obj->o_type == GOLD)
186 {
187 msg("how much?");
188 get_num(&obj->o_goldval, stdscr);
189 }
190 add_pack(obj, FALSE);
191 }
192 #endif
193
194 /*
195 * telport:
196 * Bamf the hero someplace else
197 */
198
199 void
200 teleport(void)
201 {
202 coord c;
203
204 mvaddch(hero.y, hero.x, floor_at());
205 find_floor(NULL, &c, FALSE, TRUE);
206 if (roomin(&c) != proom)
207 {
208 leave_room(&hero);
209 hero = c;
210 enter_room(&hero);
211 }
212 else
213 {
214 hero = c;
215 look(TRUE);
216 }
217 mvaddch(hero.y, hero.x, PLAYER);
218 /*
219 * turn off ISHELD in case teleportation was done while fighting
220 * a Flytrap
221 */
222 if (on(player, ISHELD)) {
223 player.t_flags &= ~ISHELD;
224 vf_hit = 0;
225 strcpy(monsters['F'-'A'].m_stats.s_dmg, "000x0");
226 }
227 no_move = 0;
228 count = 0;
229 running = FALSE;
230 flush_type();
231 }
232
233 #ifdef MASTER
234 /*
235 * passwd:
236 * See if user knows password
237 */
238 int
239 passwd(void)
240 {
241 char *sp;
242 int c;
243 static char buf[MAXSTR];
244
245 msg("wizard's Password:");
246 mpos = 0;
247 sp = buf;
248 while ((c = readchar()) != '\n' && c != '\r' && c != ESCAPE)
249 if (c == md_killchar())
250 sp = buf;
251 else if (c == md_erasechar() && sp > buf)
252 sp--;
253 else
254 *sp++ = (char) c;
255 if (sp == buf)
256 return FALSE;
257 *sp = '\0';
258 return (strcmp(PASSWD, md_crypt(buf, "mT")) == 0);
259 }
260
261 /*
262 * show_map:
263 * Print out the map for the wizard
264 */
265
266 void
267 show_map(void)
268 {
269 int y, x, real;
270
271 wclear(hw);
272 for (y = 1; y < NUMLINES - 1; y++)
273 for (x = 0; x < NUMCOLS; x++)
274 {
275 real = flat(y, x) & F_REAL;
276 if (!real)
277 wstandout(hw);
278 wmove(hw, y, x);
279 waddch(hw, chat(y, x));
280 if (!(real & F_REAL))
281 wstandend(hw);
282 }
283 show_win("---More (level map)---");
284 }
285 #endif