Mercurial > hg > early-roguelike
comparison arogue5/command.c @ 63:0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
author | elwin |
---|---|
date | Thu, 09 Aug 2012 22:58:48 +0000 |
parents | |
children | 7aff18a8d508 |
comparison
equal
deleted
inserted
replaced
62:0ef99244acb8 | 63:0ed67132cf10 |
---|---|
1 /* | |
2 * Read and execute the user commands | |
3 * | |
4 * Advanced Rogue | |
5 * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T | |
6 * All rights reserved. | |
7 * | |
8 * Based on "Rogue: Exploring the Dungeons of Doom" | |
9 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman | |
10 * All rights reserved. | |
11 * | |
12 * See the file LICENSE.TXT for full copyright and licensing information. | |
13 */ | |
14 | |
15 #include "curses.h" | |
16 #include <limits.h> | |
17 #include <ctype.h> | |
18 #include <signal.h> | |
19 #include "mach_dep.h" | |
20 #include "rogue.h" | |
21 | |
22 /* | |
23 * command: | |
24 * Process the user commands | |
25 */ | |
26 | |
27 command() | |
28 { | |
29 register char ch; | |
30 register int ntimes = 1; /* Number of player moves */ | |
31 static char countch, direction, newcount = FALSE; | |
32 struct linked_list *item; | |
33 bool an_after = FALSE; | |
34 | |
35 if (on(player, ISHASTE)) { | |
36 ntimes++; | |
37 turns--; /* correct for later */ | |
38 } | |
39 if (on(player, ISSLOW) || on(player, ISDANCE)) { | |
40 if (player.t_turn != TRUE) { | |
41 ntimes--; | |
42 turns++; | |
43 an_after = TRUE; | |
44 } | |
45 player.t_turn ^= TRUE; | |
46 } | |
47 | |
48 /* | |
49 * Let the daemons start up | |
50 */ | |
51 do_daemons(BEFORE); | |
52 do_fuses(BEFORE); | |
53 while (ntimes-- > 0) | |
54 { | |
55 /* One more tick of the clock. */ | |
56 if ((++turns % DAYLENGTH) == 0) { | |
57 daytime ^= TRUE; | |
58 if (levtype == OUTSIDE) { | |
59 if (daytime) msg("The sun rises above the horizon"); | |
60 else msg("The sun sinks below the horizon"); | |
61 } | |
62 light(&hero); | |
63 } | |
64 | |
65 look(after, FALSE); | |
66 if (!running) door_stop = FALSE; | |
67 lastscore = purse; | |
68 wmove(cw, hero.y, hero.x); | |
69 if (!((running || count) && jump)) { | |
70 status(FALSE); | |
71 wmove(cw, hero.y, hero.x); | |
72 draw(cw); /* Draw screen */ | |
73 } | |
74 take = 0; | |
75 after = TRUE; | |
76 /* | |
77 * Read command or continue run | |
78 */ | |
79 if (!no_command) | |
80 { | |
81 if (running) { | |
82 /* If in a corridor or maze, if we are at a turn with only one | |
83 * way to go, turn that way. | |
84 */ | |
85 if ((winat(hero.y, hero.x) == PASSAGE || levtype == MAZELEV) && | |
86 off(player, ISHUH) && (off(player, ISBLIND))) { | |
87 int y, x; | |
88 if (getdelta(runch, &y, &x) == TRUE) { | |
89 corr_move(y, x); | |
90 } | |
91 } | |
92 ch = runch; | |
93 } | |
94 else if (count) ch = countch; | |
95 else | |
96 { | |
97 ch = readchar(); | |
98 if (mpos != 0 && !running) /* Erase message if its there */ | |
99 msg(""); | |
100 } | |
101 } | |
102 else ch = '.'; | |
103 if (no_command) | |
104 { | |
105 if (--no_command == 0) | |
106 msg("You can move again."); | |
107 } | |
108 else | |
109 { | |
110 /* | |
111 * check for prefixes | |
112 */ | |
113 if (isdigit(ch)) | |
114 { | |
115 count = 0; | |
116 newcount = TRUE; | |
117 while (isdigit(ch)) | |
118 { | |
119 count = count * 10 + (ch - '0'); | |
120 if (count > 255) | |
121 count = 255; | |
122 ch = readchar(); | |
123 } | |
124 countch = ch; | |
125 /* | |
126 * turn off count for commands which don't make sense | |
127 * to repeat | |
128 */ | |
129 switch (ch) { | |
130 case 'h': case 'j': case 'k': case 'l': | |
131 case 'y': case 'u': case 'b': case 'n': | |
132 case 'H': case 'J': case 'K': case 'L': | |
133 case 'Y': case 'U': case 'B': case 'N': | |
134 case 'q': case 'r': case 's': case 'f': | |
135 case 't': case 'C': case 'I': case '.': | |
136 case 'z': case 'p': | |
137 break; | |
138 default: | |
139 count = 0; | |
140 } | |
141 } | |
142 | |
143 /* Save current direction */ | |
144 if (!running) /* If running, it is already saved */ | |
145 switch (ch) { | |
146 case 'h': case 'j': case 'k': case 'l': | |
147 case 'y': case 'u': case 'b': case 'n': | |
148 case 'H': case 'J': case 'K': case 'L': | |
149 case 'Y': case 'U': case 'B': case 'N': | |
150 runch = tolower(ch); | |
151 } | |
152 | |
153 /* Perform the action */ | |
154 switch (ch) { | |
155 case 'f': | |
156 if (!on(player, ISBLIND)) | |
157 { | |
158 door_stop = TRUE; | |
159 firstmove = TRUE; | |
160 } | |
161 if (count && !newcount) | |
162 ch = direction; | |
163 else | |
164 ch = readchar(); | |
165 switch (ch) | |
166 { | |
167 case 'h': case 'j': case 'k': case 'l': | |
168 case 'y': case 'u': case 'b': case 'n': | |
169 ch = toupper(ch); | |
170 } | |
171 direction = ch; | |
172 } | |
173 newcount = FALSE; | |
174 /* | |
175 * execute a command | |
176 */ | |
177 if (count && !running) | |
178 count--; | |
179 switch (ch) | |
180 { | |
181 case '!' : shell(); | |
182 when 'h' : do_move(0, -1); | |
183 when 'j' : do_move(1, 0); | |
184 when 'k' : do_move(-1, 0); | |
185 when 'l' : do_move(0, 1); | |
186 when 'y' : do_move(-1, -1); | |
187 when 'u' : do_move(-1, 1); | |
188 when 'b' : do_move(1, -1); | |
189 when 'n' : do_move(1, 1); | |
190 when 'H' : do_run('h'); | |
191 when 'J' : do_run('j'); | |
192 when 'K' : do_run('k'); | |
193 when 'L' : do_run('l'); | |
194 when 'Y' : do_run('y'); | |
195 when 'U' : do_run('u'); | |
196 when 'B' : do_run('b'); | |
197 when 'N' : do_run('n'); | |
198 when 't': | |
199 if((item=get_item(pack,"throw", ALL)) != NULL && get_dir()) | |
200 missile(delta.y, delta.x, item, &player); | |
201 else | |
202 after = FALSE; | |
203 when 'Q' : after = FALSE; quit(-1); | |
204 when 'i' : after = FALSE; inventory(pack, ALL); | |
205 when 'I' : after = FALSE; picky_inven(); | |
206 when 'd' : drop(NULL); | |
207 when 'P' : grab(hero.y, hero.x); | |
208 when 'q' : quaff(-1, NULL, TRUE); | |
209 when 'r' : read_scroll(-1, NULL, TRUE); | |
210 when 'e' : eat(); | |
211 when 'w' : wield(); | |
212 when 'W' : wear(); | |
213 when 'T' : take_off(); | |
214 when 'o' : option(); | |
215 when 'c' : call(FALSE); | |
216 when 'm' : call(TRUE); | |
217 when '>' : after = FALSE; d_level(); | |
218 when '<' : after = FALSE; u_level(); | |
219 when '?' : after = FALSE; help(); | |
220 when '/' : after = FALSE; identify(); | |
221 when CTRL('U') : use_mm(-1); | |
222 when CTRL('T') : | |
223 if (get_dir()) steal(); | |
224 else after = FALSE; | |
225 when 'D' : dip_it(); | |
226 when 'G' : gsense(); | |
227 when '^' : set_trap(&player, hero.y, hero.x); | |
228 when 's' : search(FALSE, FALSE); | |
229 when 'z' : if (!do_zap(TRUE, NULL, FALSE)) | |
230 after=FALSE; | |
231 when 'p' : pray(); | |
232 when 'C' : cast(); | |
233 when 'a' : | |
234 if (get_dir()) | |
235 affect(); | |
236 else after = FALSE; | |
237 when 'v' : after = FALSE; | |
238 msg("Advanced Rogue Version %s.", | |
239 release); | |
240 when CTRL('L') : after = FALSE; clearok(curscr, TRUE); | |
241 touchwin(cw); /* MMMMMMMMMM */ | |
242 when CTRL('R') : after = FALSE; msg(huh); | |
243 when 'S' : | |
244 after = FALSE; | |
245 if (save_game()) | |
246 { | |
247 wclear(cw); | |
248 draw(cw); | |
249 endwin(); | |
250 printf("\n"); | |
251 exit(0); | |
252 } | |
253 when '.' : ; /* Rest command */ | |
254 when ' ' : after = FALSE; /* Do Nothing */ | |
255 #ifdef WIZARD | |
256 when CTRL('P') : | |
257 after = FALSE; | |
258 if (wizard) | |
259 { | |
260 wizard = FALSE; | |
261 trader = 0; | |
262 msg("Not wizard any more"); | |
263 } | |
264 else | |
265 { | |
266 if (waswizard || passwd()) | |
267 { | |
268 msg("Welcome, oh mighty wizard."); | |
269 wizard = waswizard = TRUE; | |
270 } | |
271 else | |
272 msg("Sorry"); | |
273 } | |
274 #endif | |
275 when ESCAPE : /* Escape */ | |
276 door_stop = FALSE; | |
277 count = 0; | |
278 after = FALSE; | |
279 when '#': | |
280 if (levtype == POSTLEV) /* buy something */ | |
281 buy_it(); | |
282 after = FALSE; | |
283 when '$': | |
284 if (levtype == POSTLEV) /* price something */ | |
285 price_it(); | |
286 after = FALSE; | |
287 when '%': | |
288 if (levtype == POSTLEV) /* sell something */ | |
289 sell_it(); | |
290 after = FALSE; | |
291 otherwise : | |
292 after = FALSE; | |
293 #ifdef WIZARD | |
294 if (wizard) switch (ch) | |
295 { | |
296 case 'M' : create_obj(TRUE, 0, 0); | |
297 when CTRL('W') : wanderer(); | |
298 when CTRL('I') : inventory(lvl_obj, ALL); | |
299 when CTRL('Z') : whatis(NULL); | |
300 when CTRL('D') : level++; new_level(NORMLEV); | |
301 when CTRL('F') : overlay(stdscr,cw); | |
302 when CTRL('X') : overlay(mw,cw); | |
303 when CTRL('J') : teleport(); | |
304 when CTRL('E') : sprintf(outstring,"food left: %d\tfood level: %d", | |
305 food_left, foodlev); | |
306 msg(outstring); | |
307 when CTRL('A') : activity(); | |
308 when CTRL('C') : | |
309 { | |
310 int tlev; | |
311 prbuf[0] = '\0'; | |
312 msg("Which level? "); | |
313 if(get_str(prbuf,cw) == NORM) { | |
314 tlev = atoi(prbuf); | |
315 if(tlev < 1) { | |
316 mpos = 0; | |
317 msg("Illegal level."); | |
318 } | |
319 else if (tlev > 199) { | |
320 levtype = MAZELEV; | |
321 level = tlev - 200 + 1; | |
322 } | |
323 else if (tlev > 99) { | |
324 levtype = POSTLEV; | |
325 level = tlev - 100 + 1; | |
326 } | |
327 else { | |
328 levtype = NORMLEV; | |
329 level = tlev; | |
330 } | |
331 new_level(levtype); | |
332 } | |
333 } | |
334 when CTRL('N') : | |
335 { | |
336 if ((item=get_item(pack, "charge", STICK)) != NULL){ | |
337 (OBJPTR(item))->o_charges=10000; | |
338 } | |
339 } | |
340 when CTRL('H') : | |
341 { | |
342 register int i; | |
343 register struct object *obj; | |
344 | |
345 for (i = 0; i < 9; i++) | |
346 raise_level(TRUE); | |
347 /* | |
348 * Give the rogue a sword | |
349 */ | |
350 if(cur_weapon==NULL || cur_weapon->o_type!=RELIC) { | |
351 item = spec_item(WEAPON, TWOSWORD, 5, 5); | |
352 add_pack(item, TRUE, NULL); | |
353 cur_weapon = OBJPTR(item); | |
354 cur_weapon->o_flags |= (ISKNOW | ISPROT); | |
355 } | |
356 /* | |
357 * And his suit of armor | |
358 */ | |
359 if (player.t_ctype == C_THIEF) | |
360 item = spec_item(ARMOR, STUDDED_LEATHER, 10, 0); | |
361 else | |
362 item = spec_item(ARMOR, PLATE_ARMOR, 7, 0); | |
363 obj = OBJPTR(item); | |
364 obj->o_flags |= (ISKNOW | ISPROT); | |
365 obj->o_weight = armors[PLATE_ARMOR].a_wght; | |
366 cur_armor = obj; | |
367 add_pack(item, TRUE, NULL); | |
368 purse += 20000; | |
369 } | |
370 otherwise : | |
371 msg("Illegal command '%s'.", unctrl(ch)); | |
372 count = 0; | |
373 } | |
374 else | |
375 #endif | |
376 { | |
377 msg("Illegal command '%s'.", unctrl(ch)); | |
378 count = 0; | |
379 after = FALSE; | |
380 } | |