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