-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommand.c
More file actions
600 lines (582 loc) · 12.4 KB
/
command.c
File metadata and controls
600 lines (582 loc) · 12.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
/*
* Read and execute the user commands
*
* @(#)command.c 4.31 (Berkeley) 4/6/82
*
* Rogue: Exploring the Dungeons of Doom
* Copyright (C) 1980, 1981, 1982 Michael Toy, Ken Arnold and Glenn Wichman
* All rights reserved.
*
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <stdlib.h>
#include <curses.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "rogue.h"
char countch, direction, newcount = FALSE;
/*
* command:
* Process the user commands
*/
command()
{
register char ch;
register int ntimes = 1; /* Number of player moves */
char *unctrol();
if (on(player, ISHASTE))
ntimes++;
/*
* Let the daemons start up
*/
do_daemons(BEFORE);
do_fuses(BEFORE);
while (ntimes--)
{
/*
* these are illegal things for the player to be, so if any are
* set, someone's been poking in memeory
*/
if (on(player, ISSLOW|ISCANC|ISGREED|ISINVIS|ISMEAN|ISREGEN))
auto_save(-1);
look(TRUE);
if (!running)
door_stop = FALSE;
status();
lastscore = purse;
move(hero.y, hero.x);
if (!((running || count) && jump))
refresh(); /* Draw screen */
take = 0;
after = TRUE;
/*
* Read command or continue run
*/
#ifdef WIZARD
if (wizard)
noscore = TRUE;
#endif
if (!no_command)
{
if (running) ch = runch;
else if (count) ch = countch;
else
{
ch = readchar();
if (mpos != 0 && !running) /* Erase message if its there */
msg("");
}
}
else
ch = '.';
if (no_command)
{
if (--no_command == 0)
{
player.t_flags |= ISRUN;
msg("you can move again");
}
}
else
{
/*
* check for prefixes
*/
if (isdigit(ch))
{
count = 0;
newcount = TRUE;
while (isdigit(ch))
{
count = count * 10 + (ch - '0');
ch = readchar();
}
countch = ch;
/*
* turn off count for commands which don't make sense
* to repeat
*/
switch (ch) {
case 'h': case 'j': case 'k': case 'l':
case 'y': case 'u': case 'b': case 'n':
case 'H': case 'J': case 'K': case 'L':
case 'Y': case 'U': case 'B': case 'N':
case 'q': case 'r': case 's': case 'f':
case 't': case 'C': case 'I': case '.':
case 'z':
#ifdef WIZARD
case CTRL('D'): case CTRL('U'):
#endif
break;
default:
count = 0;
}
}
switch (ch)
{
case 'f':
if (!on(player, ISBLIND))
{
door_stop = TRUE;
firstmove = TRUE;
}
if (count && !newcount)
ch = direction;
else
ch = readchar();
switch (ch)
{
case 'h': case 'j': case 'k': case 'l':
case 'y': case 'u': case 'b': case 'n':
ch = toupper(ch);
}
direction = ch;
}
newcount = FALSE;
/*
* execute a command
*/
if (count && !running)
count--;
switch (ch)
{
case '!' : shell();
when 'h' : do_move(0, -1);
when 'j' : do_move(1, 0);
when 'k' : do_move(-1, 0);
when 'l' : do_move(0, 1);
when 'y' : do_move(-1, -1);
when 'u' : do_move(-1, 1);
when 'b' : do_move(1, -1);
when 'n' : do_move(1, 1);
when 'H' : do_run('h');
when 'J' : do_run('j');
when 'K' : do_run('k');
when 'L' : do_run('l');
when 'Y' : do_run('y');
when 'U' : do_run('u');
when 'B' : do_run('b');
when 'N' : do_run('n');
when 't':
if (!get_dir())
after = FALSE;
else
missile(delta.y, delta.x);
when 'Q' : after = FALSE; quit(-1);
when 'i' : after = FALSE; inventory(pack, 0);
when 'I' : after = FALSE; picky_inven();
when 'd' : drop();
when 'q' : quaff();
when 'r' : read_scroll();
when 'e' : eat();
when 'w' : wield();
when 'W' : wear();
when 'T' : take_off();
when 'P' : ring_on();
when 'R' : ring_off();
when 'o' : option(); after = FALSE;
when 'c' : call(); after = FALSE;
when '>' : after = FALSE; d_level();
when '<' : after = FALSE; u_level();
when '?' : after = FALSE; help();
when '/' : after = FALSE; identify();
when 's' : search();
when 'z':
if (get_dir())
do_zap();
else
after = FALSE;
when 'D': after = FALSE; discovered();
when CTRL('R') : after = FALSE; msg(huh);
when CTRL('L') :
after = FALSE;
clearok(curscr,TRUE);
wrefresh(curscr);
when 'v' :
after = FALSE;
msg("rogue version %s. (mctesq was here)", release);
when 'S' :
after = FALSE;
if (save_game())
{
move(LINES-1, 0);
clrtoeol();
refresh();
endwin();
exit(0);
}
when '.' : ; /* Rest command */
when ' ' : after = FALSE; /* "Legal" illegal command */
when '^' :
after = FALSE;
if (get_dir()) {
delta.y += hero.y;
delta.x += hero.x;
if (chat(delta.y, delta.x) != TRAP)
msg("no trap there");
else
msg(tr_name(flat(delta.y, delta.x) & F_TMASK));
}
#ifdef WIZARD
when CTRL('P') :
after = FALSE;
if (wizard)
{
wizard = FALSE;
turn_see(TRUE);
msg("not wizard any more");
}
else
{
if (wizard = passwd())
{
noscore = TRUE;
turn_see(FALSE);
msg("you are suddenly as smart as Ken Arnold in dungeon #%d", dnum);
}
else
msg("sorry");
}
#endif
when ESCAPE : /* Escape */
door_stop = FALSE;
count = 0;
after = FALSE;
otherwise :
after = FALSE;
#ifdef WIZARD
if (wizard) switch (ch)
{
case '@' : msg("@ %d,%d", hero.y, hero.x);
when 'C' : create_obj();
when CTRL('I') : inventory(lvl_obj, 0);
when CTRL('W') : whatis(FALSE);
when CTRL('D') : level++; new_level();
when CTRL('U') : if (level > 1) level--; new_level();
when CTRL('F') : show_map();
when CTRL('T') : teleport();
when CTRL('E') : msg("food left: %d", food_left);
when CTRL('A') : msg("%d things in your pack", inpack);
when CTRL('K') : add_pass();
when CTRL('X') : turn_see(on(player, SEEMONST));
when CTRL('N') :
{
register THING *item;
if ((item = get_item("charge", STICK)) != NULL)
item->o_charges = 10000;
}
when CTRL('H') :
{
register int i;
register THING *obj;
for (i = 0; i < 9; i++)
raise_level();
/*
* Give the rogue a sword (+1,+1)
*/
obj = new_item();
obj->o_type = WEAPON;
obj->o_which = TWOSWORD;
init_weapon(obj, SWORD);
obj->o_hplus = 1;
obj->o_dplus = 1;
obj->o_count = 1;
obj->o_group = 0;
add_pack(obj, TRUE);
cur_weapon = obj;
/*
* And his suit of armor
*/
obj = new_item();
obj->o_type = ARMOR;
obj->o_which = PLATE_MAIL;
obj->o_ac = -5;
obj->o_flags |= ISKNOW;
obj->o_count = 1;
obj->o_group = 0;
cur_armor = obj;
add_pack(obj, TRUE);
}
otherwise :
illcom(ch);
}
else
#endif
illcom(ch);
}
/*
* turn off flags if no longer needed
*/
if (!running)
door_stop = FALSE;
}
/*
* If he ran into something to take, let him pick it up.
*/
if (take != 0)
pick_up(take);
if (!running)
door_stop = FALSE;
if (!after)
ntimes++;
}
do_daemons(AFTER);
do_fuses(AFTER);
if (ISRING(LEFT, R_SEARCH))
search();
else if (ISRING(LEFT, R_TELEPORT) && rnd(50) == 0)
teleport();
if (ISRING(RIGHT, R_SEARCH))
search();
else if (ISRING(RIGHT, R_TELEPORT) && rnd(50) == 0)
teleport();
}
/*
* illcom:
* What to do with an illegal command
*/
illcom(ch)
char ch;
{
save_msg = FALSE;
count = 0;
msg("illegal command '%s'", unctrol(ch));
save_msg = TRUE;
}
/*
* search:
* Player gropes about him to find hidden things.
*/
search()
{
register int y, x;
register char *fp;
register int ey, ex;
if (on(player, ISBLIND))
return;
ey = hero.y + 1;
ex = hero.x + 1;
for (y = hero.y - 1; y <= ey; y++)
for (x = hero.x - 1; x <= ex; x++)
{
if (y == hero.y && x == hero.x)
continue;
fp = &flat(y, x);
if (!(*fp & F_REAL))
switch (chat(y, x))
{
case '|':
case '-':
if (rnd(5) != 0)
break;
chat(y, x) = DOOR;
*fp |= F_REAL;
count = running = FALSE;
break;
case FLOOR:
if (rnd(2) != 0)
break;
chat(y, x) = TRAP;
*fp |= F_REAL;
count = running = FALSE;
msg("%s%s", terse ? "" : "you found ", tr_name(*fp & F_TMASK));
break;
}
}
}
/*
* help:
* Give single character help, or the whole mess if he wants it
*/
help()
{
register const struct h_list *strp = helpstr;
register char helpch;
register int cnt;
msg("character you want help for (* for all): ");
helpch = readchar();
mpos = 0;
/*
* If its not a *, print the right help string
* or an error if he typed a funny character.
*/
if (helpch != '*')
{
move(0, 0);
while (strp->h_ch)
{
if (strp->h_ch == helpch)
{
msg("%s%s", unctrol(strp->h_ch), strp->h_desc);
break;
}
strp++;
}
if (strp->h_ch != helpch)
msg("unknown character '%s'", unctrol(helpch));
return;
}
/*
* Here we print help for everything.
* Then wait before we return to command mode
*/
wclear(hw);
cnt = 0;
while (strp->h_ch)
{
mvwaddstr(hw, cnt % 23, cnt > 22 ? 40 : 0, unctrol(strp->h_ch));
waddstr(hw, strp->h_desc);
cnt++;
strp++;
}
wmove(hw, LINES-1, 0);
wprintw(hw, "--Press space to continue--");
wrefresh(hw);
w_wait_for(hw,' ');
wmove(stdscr, 0, 0);
wclrtoeol(stdscr);
touchwin(stdscr);
clearok(stdscr, TRUE);
refresh();
}
/*
* identify:
* Tell the player what a certain thing is.
*/
identify()
{
register char ch;
register const char *str;
msg("what do you want identified? ");
ch = readchar();
mpos = 0;
if (ch == ESCAPE)
{
msg("");
return;
}
if (isupper(ch))
str = monsters[ch-'A'].m_name;
else switch (ch)
{
case '|':
case '-':
str = "wall of a room";
when GOLD: str = "gold";
when STAIRS : str = "a staircase";
when DOOR: str = "door";
when FLOOR: str = "room floor";
when PLAYER: str = "you";
when PASSAGE: str = "passage";
when TRAP: str = "trap";
when POTION: str = "potion";
when SCROLL: str = "scroll";
when FOOD: str = "food";
when WEAPON: str = "weapon";
when ' ' : str = "solid rock";
when ARMOR: str = "armor";
when AMULET: str = "the Amulet of Yendor";
when RING: str = "ring";
when STICK: str = "wand or staff";
otherwise: str = "unknown character";
}
msg("'%s': %s", unctrol(ch), str);
}
/*
* d_level:
* He wants to go down a level
*/
d_level()
{
if (chat(hero.y, hero.x) != STAIRS)
msg("I see no way down");
else
{
level++;
new_level();
}
}
/*
* u_level:
* He wants to go up a level
*/
u_level()
{
if (chat(hero.y, hero.x) == STAIRS)
if (amulet)
{
level--;
if (level == 0)
total_winner();
new_level();
msg("you feel a wrenching sensation in your gut");
}
else
msg("your way is magically blocked");
else
msg("I see no way up");
}
/*
* call:
* Allow a user to call a potion, scroll, or ring something
*/
call()
{
register THING *obj;
register char **guess;
const char *elsewise;
register bool *know;
obj = get_item("call", CALLABLE);
/*
* Make certain that it is somethings that we want to wear
*/
if (obj == NULL)
return;
switch (obj->o_type)
{
case RING:
guess = r_guess;
know = r_know;
elsewise = (r_guess[obj->o_which] != NULL ?
r_guess[obj->o_which] : r_stones[obj->o_which]);
when POTION:
guess = p_guess;
know = p_know;
elsewise = (p_guess[obj->o_which] != NULL ?
p_guess[obj->o_which] : p_colors[obj->o_which]);
when SCROLL:
guess = s_guess;
know = s_know;
elsewise = (s_guess[obj->o_which] != NULL ?
s_guess[obj->o_which] : s_names[obj->o_which]);
when STICK:
guess = ws_guess;
know = ws_know;
elsewise = (ws_guess[obj->o_which] != NULL ?
ws_guess[obj->o_which] : ws_made[obj->o_which]);
otherwise:
msg("you can't call that anything");
return;
}
if (know[obj->o_which])
{
msg("that has already been identified");
return;
}
if (!terse)
addmsg("Was ");
msg("called \"%s\"", elsewise);
if (terse)
msg("call it: ");
else
msg("what do you want to call it? ");
if (guess[obj->o_which] != NULL)
free(guess[obj->o_which]);
strcpy(prbuf, elsewise);
if (get_str(prbuf, stdscr) == NORM)
{
guess[obj->o_which] = malloc((unsigned int) strlen(prbuf) + 1);
strcpy(guess[obj->o_which], prbuf);
}
}