2 * Read and execute the user commands
4 * @(#)command.c 3.45 (Berkeley) 6/15/81
6 * Rogue: Exploring the Dungeons of Doom
7 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
10 * See the file LICENSE.TXT for full copyright and licensing information.
22 * Process the user commands
28 register int ntimes
= 1; /* Number of player moves */
29 static char countch
, direction
, newcount
= FALSE
;
32 if (on(player
, ISHASTE
)) ntimes
++;
34 * Let the daemons start up
45 wmove(cw
, hero
.y
, hero
.x
);
46 if (!((running
|| count
) && jump
))
47 draw(cw
); /* Draw screen */
51 * Read command or continue run
57 if (running
) ch
= runch
;
58 else if (count
) ch
= countch
;
62 if (mpos
!= 0 && !running
) /* Erase message if its there */
69 if (--no_command
== 0)
70 msg("You can move again.");
83 count
= count
* 10 + (ch
- '0');
88 * turn off count for commands which don't make sense
92 case 'h': case 'j': case 'k': case 'l':
93 case 'y': case 'u': case 'b': case 'n':
94 case 'H': case 'J': case 'K': case 'L':
95 case 'Y': case 'U': case 'B': case 'N':
96 case 'q': case 'r': case 's': case 'f':
97 case 't': case 'C': case 'I': case ' ':
107 if (!on(player
, ISBLIND
))
112 if (count
&& !newcount
)
118 case 'h': case 'j': case 'k': case 'l':
119 case 'y': case 'u': case 'b': case 'n':
128 if (count
&& !running
)
133 when
'h' : do_move(0, -1);
134 when
'j' : do_move(1, 0);
135 when
'k' : do_move(-1, 0);
136 when
'l' : do_move(0, 1);
137 when
'y' : do_move(-1, -1);
138 when
'u' : do_move(-1, 1);
139 when
'b' : do_move(1, -1);
140 when
'n' : do_move(1, 1);
141 when
'H' : do_run('h');
142 when
'J' : do_run('j');
143 when
'K' : do_run('k');
144 when
'L' : do_run('l');
145 when
'Y' : do_run('y');
146 when
'U' : do_run('u');
147 when
'B' : do_run('b');
148 when
'N' : do_run('n');
153 missile(delta
.y
, delta
.x
);
154 when
'Q' : after
= FALSE
; quit(0);
155 when
'i' : after
= FALSE
; inventory(pack
, 0);
156 when
'I' : after
= FALSE
; picky_inven();
159 when
'r' : read_scroll();
163 when
'T' : take_off();
164 when
'P' : ring_on();
165 when
'R' : ring_off();
168 when
'>' : after
= FALSE
; d_level();
169 when
'<' : after
= FALSE
; u_level();
170 when
'?' : after
= FALSE
; help();
171 when
'/' : after
= FALSE
; identify();
173 when
'z' : do_zap(FALSE
);
179 when
'v' : msg("Rogue version %s. (mctesq was here)", release
);
180 when
CTRL('L') : after
= FALSE
; clearok(curscr
,TRUE
);draw(curscr
);
181 when
CTRL('R') : after
= FALSE
; msg(huh
);
186 wmove(cw
, LINES
-1, 0);
192 when
' ' : ; /* Rest command */
198 msg("Not wizard any more");
202 if (wizard
= passwd())
204 msg("You are suddenly as smart as Ken Arnold in dungeon #%d", dnum
);
211 when ESCAPE
: /* Escape */
217 if (wizard
) switch (ch
)
219 case '@' : msg("@ %d,%d", hero
.y
, hero
.x
);
220 when
'C' : create_obj();
221 when
CTRL('I') : inventory(lvl_obj
, 0);
222 when
CTRL('W') : whatis();
223 when
CTRL('D') : level
++; new_level();
224 when
CTRL('U') : level
--; new_level();
225 when
CTRL('F') : show_win(stdscr
, "--More (level map)--");
226 when
CTRL('X') : show_win(mw
, "--More (monsters)--");
227 when
CTRL('T') : teleport();
228 when
CTRL('E') : msg("food left: %d", food_left
);
229 when
CTRL('A') : msg("%d things in your pack", inpack
);
230 when
CTRL('C') : add_pass();
233 register struct linked_list
*item
;
235 if ((item
= get_item("charge", STICK
)) != NULL
)
236 ((struct object
*) ldata(item
))->o_charges
= 10000;
241 register struct linked_list
*item
;
242 register struct object
*obj
;
244 for (i
= 0; i
< 9; i
++)
247 * Give the rogue a sword (+1,+1)
249 item
= new_item(sizeof *obj
);
250 obj
= (struct object
*) ldata(item
);
251 obj
->o_type
= WEAPON
;
252 obj
->o_which
= TWOSWORD
;
253 init_weapon(obj
, SWORD
);
256 add_pack(item
, TRUE
);
259 * And his suit of armor
261 item
= new_item(sizeof *obj
);
262 obj
= (struct object
*) ldata(item
);
264 obj
->o_which
= PLATE_MAIL
;
266 obj
->o_flags
|= ISKNOW
;
268 add_pack(item
, TRUE
);
271 msg("Illegal command '%s'.", unctrl(ch
));
276 msg("Illegal command '%s'.", unctrl(ch
));
281 * turn off flags if no longer needed
287 * If he ran into something to take, let him pick it up.
295 * Kick off the rest if the daemons and fuses
302 if (ISRING(LEFT
, R_SEARCH
))
304 else if (ISRING(LEFT
, R_TELEPORT
) && rnd(100) < 2)
306 if (ISRING(RIGHT
, R_SEARCH
))
308 else if (ISRING(RIGHT
, R_TELEPORT
) && rnd(100) < 2)
315 * Have player make certain, then exit.
322 * Reset the signal in case we got here via an interrupt
324 if (signal(SIGINT
, quit
) != &quit
)
328 if (readchar(cw
) == 'y')
339 signal(SIGINT
, quit
);
351 * Player gropes about him to find hidden things.
360 * Look all around the hero, if there is something hidden there,
361 * give him a chance to find it. If its found, display it.
363 if (on(player
, ISBLIND
))
365 for (x
= hero
.x
- 1; x
<= hero
.x
+ 1; x
++)
366 for (y
= hero
.y
- 1; y
<= hero
.y
+ 1; y
++)
379 register struct trap
*tp
;
381 if (mvwinch(cw
, y
, x
) == TRAP
)
386 tp
->tr_flags
|= ISFOUND
;
387 mvwaddch(cw
, y
, x
, TRAP
);
390 msg(tr_name(tp
->tr_type
));
398 * Give single character help, or the whole mess if he wants it
403 register struct h_list
*strp
= helpstr
;
404 register char helpch
;
407 msg("Character you want help for (* for all): ");
408 helpch
= readchar(cw
);
411 * If its not a *, print the right help string
412 * or an error if he typed a funny character.
419 if (strp
->h_ch
== helpch
)
421 msg("%s%s", unctrl(strp
->h_ch
), strp
->h_desc
);
426 if (strp
->h_ch
!= helpch
)
427 msg("Unknown character '%s'", unctrl(helpch
));
431 * Here we print help for everything.
432 * Then wait before we return to command mode
438 mvwaddstr(hw
, cnt
% 23, cnt
> 22 ? 40 : 0, unctrl(strp
->h_ch
));
439 waddstr(hw
, strp
->h_desc
);
443 wmove(hw
, LINES
-1, 0);
444 wprintw(hw
, "--Press space to continue--");
457 * Tell the player what a certain thing is.
462 register char ch
, *str
;
464 msg("What do you want identified? ");
472 if (isalpha(ch
) && isupper(ch
))
473 str
= monsters
[ch
-'A'].m_name
;
478 str
= "wall of a room";
479 when GOLD
: str
= "gold";
480 when STAIRS
: str
= "passage leading down";
481 when DOOR
: str
= "door";
482 when FLOOR
: str
= "room floor";
483 when PLAYER
: str
= "you";
484 when PASSAGE
: str
= "passage";
485 when TRAP
: str
= "trap";
486 when POTION
: str
= "potion";
487 when SCROLL
: str
= "scroll";
488 when FOOD
: str
= "food";
489 when WEAPON
: str
= "weapon";
490 when
' ' : str
= "solid rock";
491 when ARMOR
: str
= "armor";
492 when AMULET
: str
= "The Amulet of Yendor";
493 when RING
: str
= "ring";
494 when STICK
: str
= "wand or staff";
495 otherwise
: str
= "unknown character";
497 msg("'%s' : %s", unctrl(ch
), str
);
502 * He wants to go down a level
507 if (winat(hero
.y
, hero
.x
) != STAIRS
)
508 msg("I see no way down.");
518 * He wants to go up a level
523 if (winat(hero
.y
, hero
.x
) == STAIRS
)
531 msg("You feel a wrenching sensation in your gut.");
535 msg("I see no way up.");
539 * Let him escape for a while
545 * Set the terminal back to original mode
548 wmove(hw
, LINES
-1, 0);
556 printf("\n[Press return to continue]");
568 * allow a user to call a potion, scroll, or ring something
572 register struct object
*obj
;
573 register struct linked_list
*item
;
574 register char **guess
, *elsewise
;
577 item
= get_item("call", CALLABLE
);
579 * Make certain that it is somethings that we want to wear
583 obj
= (struct object
*) ldata(item
);
589 elsewise
= (r_guess
[obj
->o_which
] != NULL
?
590 r_guess
[obj
->o_which
] : r_stones
[obj
->o_which
]);
594 elsewise
= (p_guess
[obj
->o_which
] != NULL
?
595 p_guess
[obj
->o_which
] : p_colors
[obj
->o_which
]);
599 elsewise
= (s_guess
[obj
->o_which
] != NULL
?
600 s_guess
[obj
->o_which
] : s_names
[obj
->o_which
]);
604 elsewise
= (ws_guess
[obj
->o_which
] != NULL
?
605 ws_guess
[obj
->o_which
] : ws_made
[obj
->o_which
]);
607 msg("You can't call that anything");
610 if (know
[obj
->o_which
])
612 msg("That has already been identified");
619 msg("alled \"%s\"", elsewise
);
623 msg("What do you want to call it? ");
624 strcpy(prbuf
, elsewise
);
625 if (get_str(prbuf
, cw
) == NORM
)
627 if (guess
[obj
->o_which
] != NULL
)
628 free(guess
[obj
->o_which
]);
629 guess
[obj
->o_which
] = malloc((unsigned int) strlen(prbuf
) + 1);
630 if (guess
[obj
->o_which
] != NULL
)
631 strcpy(guess
[obj
->o_which
], prbuf
);