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 ' ':
108 if (count
&& !running
)
113 when
'h' : do_move(0, -1);
114 when
'j' : do_move(1, 0);
115 when
'k' : do_move(-1, 0);
116 when
'l' : do_move(0, 1);
117 when
'y' : do_move(-1, -1);
118 when
'u' : do_move(-1, 1);
119 when
'b' : do_move(1, -1);
120 when
'n' : do_move(1, 1);
121 when
'H' : do_run('h');
122 when
'J' : do_run('j');
123 when
'K' : do_run('k');
124 when
'L' : do_run('l');
125 when
'Y' : do_run('y');
126 when
'U' : do_run('u');
127 when
'B' : do_run('b');
128 when
'N' : do_run('n');
133 missile(delta
.y
, delta
.x
);
134 when
'Q' : after
= FALSE
; quit(0);
135 when
'i' : after
= FALSE
; inventory(pack
, 0);
136 when
'I' : after
= FALSE
; picky_inven();
139 when
'r' : read_scroll();
143 when
'T' : take_off();
144 when
'P' : ring_on();
145 when
'R' : ring_off();
152 flirt(delta
.y
, delta
.x
);
153 when
'>' : after
= FALSE
; d_level();
154 when
'<' : after
= FALSE
; u_level();
155 when
'?' : after
= FALSE
; help();
156 when
'/' : after
= FALSE
; identify();
158 when
'z' : do_zap(FALSE
);
164 when
'v' : msg("Rogue version %s. (mctesq was here)", release
);
165 when
CTRL('L') : after
= FALSE
; clearok(curscr
,TRUE
);draw(curscr
);
166 when
CTRL('R') : after
= FALSE
; msg(huh
);
171 wmove(cw
, LINES
-1, 0);
177 when
' ' : ; /* Rest command */
183 msg("Not wizard any more");
187 if (wizard
= passwd())
189 msg("You are suddenly as smart as Ken Arnold in dungeon #%d", dnum
);
196 when ESCAPE
: /* Escape */
202 if (wizard
) switch (ch
)
204 case '@' : msg("@ %d,%d", hero
.y
, hero
.x
);
205 when
'C' : create_obj();
206 when
CTRL('I') : inventory(lvl_obj
, 0);
207 when
CTRL('W') : whatis();
208 when
CTRL('D') : level
++; new_level();
209 when
CTRL('U') : level
--; new_level();
210 when
CTRL('F') : show_win(stdscr
, "--More (level map)--");
211 when
CTRL('X') : show_win(mw
, "--More (monsters)--");
212 when
CTRL('T') : teleport();
213 when
CTRL('E') : msg("food left: %d", food_left
);
214 when
CTRL('A') : msg("%d things in your pack", inpack
);
215 when
CTRL('C') : add_pass();
218 register struct linked_list
*item
;
220 if ((item
= get_item("charge", STICK
)) != NULL
)
221 ((struct object
*) ldata(item
))->o_charges
= 10000;
226 register struct linked_list
*item
;
227 register struct object
*obj
;
229 for (i
= 0; i
< 9; i
++)
232 * Give the rogue a sword (+1,+1)
234 item
= new_item(sizeof *obj
);
235 obj
= (struct object
*) ldata(item
);
236 obj
->o_type
= WEAPON
;
237 obj
->o_which
= TWOSWORD
;
238 init_weapon(obj
, SWORD
);
241 add_pack(item
, TRUE
);
244 * And his suit of armor
246 item
= new_item(sizeof *obj
);
247 obj
= (struct object
*) ldata(item
);
249 obj
->o_which
= PLATE_MAIL
;
251 obj
->o_flags
|= ISKNOW
;
253 add_pack(item
, TRUE
);
256 msg("Illegal command '%s'.", unctrl(ch
));
261 msg("Illegal command '%s'.", unctrl(ch
));
266 * turn off flags if no longer needed
272 * If he ran into something to take, let him pick it up.
280 * Kick off the rest if the daemons and fuses
287 if (ISRING(LEFT
, R_SEARCH
))
289 else if (ISRING(LEFT
, R_TELEPORT
) && rnd(100) < 2)
291 if (ISRING(RIGHT
, R_SEARCH
))
293 else if (ISRING(RIGHT
, R_TELEPORT
) && rnd(100) < 2)
300 * Have player make certain, then exit.
307 * Reset the signal in case we got here via an interrupt
309 if (signal(SIGINT
, quit
) != &quit
)
313 if (readchar(cw
) == 'y')
324 signal(SIGINT
, quit
);
336 * Player gropes about him to find hidden things.
345 * Look all around the hero, if there is something hidden there,
346 * give him a chance to find it. If its found, display it.
348 if (on(player
, ISBLIND
))
350 for (x
= hero
.x
- 1; x
<= hero
.x
+ 1; x
++)
351 for (y
= hero
.y
- 1; y
<= hero
.y
+ 1; y
++)
364 register struct trap
*tp
;
366 if (mvwinch(cw
, y
, x
) == TRAP
)
371 tp
->tr_flags
|= ISFOUND
;
372 mvwaddch(cw
, y
, x
, TRAP
);
375 msg(tr_name(tp
->tr_type
));
383 * Give single character help, or the whole mess if he wants it
388 register struct h_list
*strp
= helpstr
;
389 register char helpch
;
392 msg("Character you want help for (* for all): ");
393 helpch
= readchar(cw
);
396 * If its not a *, print the right help string
397 * or an error if he typed a funny character.
404 if (strp
->h_ch
== helpch
)
406 msg("%s%s", unctrl(strp
->h_ch
), strp
->h_desc
);
411 if (strp
->h_ch
!= helpch
)
412 msg("Unknown character '%s'", unctrl(helpch
));
416 * Here we print help for everything.
417 * Then wait before we return to command mode
423 mvwaddstr(hw
, cnt
% 23, cnt
> 22 ? 40 : 0, unctrl(strp
->h_ch
));
424 waddstr(hw
, strp
->h_desc
);
428 wmove(hw
, LINES
-1, 0);
429 wprintw(hw
, "--Press space to continue--");
442 * Tell the player what a certain thing is.
447 register char ch
, *str
;
449 msg("What do you want identified? ");
457 if (isalpha(ch
) && isupper(ch
))
458 str
= monsters
[ch
-'A'].m_name
;
463 str
= "wall of a room";
464 when GOLD
: str
= "gold";
465 when STAIRS
: str
= "passage leading down";
466 when DOOR
: str
= "door";
467 when FLOOR
: str
= "room floor";
468 when PLAYER
: str
= "you";
469 when PASSAGE
: str
= "passage";
470 when TRAP
: str
= "trap";
471 when POTION
: str
= "potion";
472 when SCROLL
: str
= "scroll";
473 when FOOD
: str
= "food";
474 when WEAPON
: str
= "weapon";
475 when
' ' : str
= "solid rock";
476 when ARMOR
: str
= "armor";
477 when AMULET
: str
= "The Amulet of Yendor";
478 when RING
: str
= "ring";
479 when STICK
: str
= "wand or staff";
480 otherwise
: str
= "unknown character";
482 msg("'%s' : %s", unctrl(ch
), str
);
487 * He wants to go down a level
492 if (winat(hero
.y
, hero
.x
) != STAIRS
)
493 msg("I see no way down.");
503 * He wants to go up a level
508 if (winat(hero
.y
, hero
.x
) == STAIRS
)
516 msg("You feel a wrenching sensation in your gut.");
520 msg("I see no way up.");
524 * Let him escape for a while
530 * Set the terminal back to original mode
533 wmove(hw
, LINES
-1, 0);
541 printf("\n[Press return to continue]");
553 * allow a user to call a potion, scroll, or ring something
557 register struct object
*obj
;
558 register struct linked_list
*item
;
559 register char **guess
, *elsewise
;
562 item
= get_item("call", CALLABLE
);
564 * Make certain that it is somethings that we want to wear
568 obj
= (struct object
*) ldata(item
);
574 elsewise
= (r_guess
[obj
->o_which
] != NULL
?
575 r_guess
[obj
->o_which
] : r_stones
[obj
->o_which
]);
579 elsewise
= (p_guess
[obj
->o_which
] != NULL
?
580 p_guess
[obj
->o_which
] : p_colors
[obj
->o_which
]);
584 elsewise
= (s_guess
[obj
->o_which
] != NULL
?
585 s_guess
[obj
->o_which
] : s_names
[obj
->o_which
]);
589 elsewise
= (ws_guess
[obj
->o_which
] != NULL
?
590 ws_guess
[obj
->o_which
] : ws_made
[obj
->o_which
]);
592 msg("You can't call that anything");
595 if (know
[obj
->o_which
])
597 msg("That has already been identified");
604 msg("alled \"%s\"", elsewise
);
608 msg("What do you want to call it? ");
609 strcpy(prbuf
, elsewise
);
610 if (get_str(prbuf
, cw
) == NORM
)
612 if (guess
[obj
->o_which
] != NULL
)
613 free(guess
[obj
->o_which
]);
614 guess
[obj
->o_which
] = malloc((unsigned int) strlen(prbuf
) + 1);
615 if (guess
[obj
->o_which
] != NULL
)
616 strcpy(guess
[obj
->o_which
], prbuf
);