eaa3648ad7d5180b15b586f9da8f8a04bdb16c0b
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
);
157 gift(delta
.y
, delta
.x
);
160 when
'>' : after
= FALSE
; d_level();
161 when
'<' : after
= FALSE
; u_level();
162 when
'?' : after
= FALSE
; help();
163 when
'/' : after
= FALSE
; identify();
165 when
'z' : do_zap(FALSE
);
171 when
'v' : msg("Rogue version %s. (mctesq was here)", release
);
172 when
CTRL('L') : after
= FALSE
; clearok(curscr
,TRUE
);draw(curscr
);
173 when
CTRL('R') : after
= FALSE
; msg(huh
);
178 wmove(cw
, LINES
-1, 0);
184 when
' ' : ; /* Rest command */
190 msg("Not wizard any more");
194 if (wizard
= passwd())
196 msg("You are suddenly as smart as Ken Arnold in dungeon #%d", dnum
);
203 when ESCAPE
: /* Escape */
209 if (wizard
) switch (ch
)
211 case '@' : msg("@ %d,%d", hero
.y
, hero
.x
);
212 when
'C' : create_obj();
213 when
CTRL('I') : inventory(lvl_obj
, 0);
214 when
CTRL('W') : whatis();
215 when
CTRL('D') : level
++; new_level();
216 when
CTRL('U') : level
--; new_level();
217 when
CTRL('F') : show_win(stdscr
, "--More (level map)--");
218 when
CTRL('X') : show_win(mw
, "--More (monsters)--");
219 when
CTRL('T') : teleport();
220 when
CTRL('E') : msg("food left: %d", food_left
);
221 when
CTRL('A') : msg("%d things in your pack", inpack
);
222 when
CTRL('C') : add_pass();
225 register struct linked_list
*item
;
227 if ((item
= get_item("charge", STICK
)) != NULL
)
228 ((struct object
*) ldata(item
))->o_charges
= 10000;
233 register struct linked_list
*item
;
234 register struct object
*obj
;
236 for (i
= 0; i
< 9; i
++)
239 * Give the rogue a sword (+1,+1)
241 item
= new_item(sizeof *obj
);
242 obj
= (struct object
*) ldata(item
);
243 obj
->o_type
= WEAPON
;
244 obj
->o_which
= TWOSWORD
;
245 init_weapon(obj
, SWORD
);
248 add_pack(item
, TRUE
);
251 * And his suit of armor
253 item
= new_item(sizeof *obj
);
254 obj
= (struct object
*) ldata(item
);
256 obj
->o_which
= PLATE_MAIL
;
258 obj
->o_flags
|= ISKNOW
;
260 add_pack(item
, TRUE
);
263 msg("Illegal command '%s'.", unctrl(ch
));
268 msg("Illegal command '%s'.", unctrl(ch
));
273 * turn off flags if no longer needed
279 * If he ran into something to take, let him pick it up.
287 * Kick off the rest if the daemons and fuses
294 if (ISRING(LEFT
, R_SEARCH
))
296 else if (ISRING(LEFT
, R_TELEPORT
) && rnd(100) < 2)
298 if (ISRING(RIGHT
, R_SEARCH
))
300 else if (ISRING(RIGHT
, R_TELEPORT
) && rnd(100) < 2)
307 * Have player make certain, then exit.
314 * Reset the signal in case we got here via an interrupt
316 if (signal(SIGINT
, quit
) != &quit
)
320 if (readchar(cw
) == 'y')
331 signal(SIGINT
, quit
);
343 * Player gropes about him to find hidden things.
352 * Look all around the hero, if there is something hidden there,
353 * give him a chance to find it. If its found, display it.
355 if (on(player
, ISBLIND
))
357 for (x
= hero
.x
- 1; x
<= hero
.x
+ 1; x
++)
358 for (y
= hero
.y
- 1; y
<= hero
.y
+ 1; y
++)
371 register struct trap
*tp
;
373 if (mvwinch(cw
, y
, x
) == TRAP
)
378 tp
->tr_flags
|= ISFOUND
;
379 mvwaddch(cw
, y
, x
, TRAP
);
382 msg(tr_name(tp
->tr_type
));
390 * Give single character help, or the whole mess if he wants it
395 register struct h_list
*strp
= helpstr
;
396 register char helpch
;
399 msg("Character you want help for (* for all): ");
400 helpch
= readchar(cw
);
403 * If its not a *, print the right help string
404 * or an error if he typed a funny character.
411 if (strp
->h_ch
== helpch
)
413 msg("%s%s", unctrl(strp
->h_ch
), strp
->h_desc
);
418 if (strp
->h_ch
!= helpch
)
419 msg("Unknown character '%s'", unctrl(helpch
));
423 * Here we print help for everything.
424 * Then wait before we return to command mode
430 mvwaddstr(hw
, cnt
% 23, cnt
> 22 ? 40 : 0, unctrl(strp
->h_ch
));
431 waddstr(hw
, strp
->h_desc
);
435 wmove(hw
, LINES
-1, 0);
436 wprintw(hw
, "--Press space to continue--");
449 * Tell the player what a certain thing is.
454 register char ch
, *str
;
456 msg("What do you want identified? ");
464 if (isalpha(ch
) && isupper(ch
))
465 str
= monsters
[ch
-'A'].m_name
;
470 str
= "wall of a room";
471 when GOLD
: str
= "gold";
472 when STAIRS
: str
= "passage leading down";
473 when DOOR
: str
= "door";
474 when FLOOR
: str
= "room floor";
475 when PLAYER
: str
= "you";
476 when PASSAGE
: str
= "passage";
477 when TRAP
: str
= "trap";
478 when POTION
: str
= "potion";
479 when SCROLL
: str
= "scroll";
480 when FOOD
: str
= "food";
481 when WEAPON
: str
= "weapon";
482 when
' ' : str
= "solid rock";
483 when ARMOR
: str
= "armor";
484 when AMULET
: str
= "The Amulet of Yendor";
485 when RING
: str
= "ring";
486 when STICK
: str
= "wand or staff";
487 otherwise
: str
= "unknown character";
489 msg("'%s' : %s", unctrl(ch
), str
);
494 * He wants to go down a level
499 if (winat(hero
.y
, hero
.x
) != STAIRS
)
500 msg("I see no way down.");
510 * He wants to go up a level
515 if (winat(hero
.y
, hero
.x
) == STAIRS
)
523 msg("You feel a wrenching sensation in your gut.");
527 msg("I see no way up.");
531 * Let him escape for a while
537 * Set the terminal back to original mode
540 wmove(hw
, LINES
-1, 0);
548 printf("\n[Press return to continue]");
560 * allow a user to call a potion, scroll, or ring something
564 register struct object
*obj
;
565 register struct linked_list
*item
;
566 register char **guess
, *elsewise
;
569 item
= get_item("call", CALLABLE
);
571 * Make certain that it is somethings that we want to wear
575 obj
= (struct object
*) ldata(item
);
581 elsewise
= (r_guess
[obj
->o_which
] != NULL
?
582 r_guess
[obj
->o_which
] : r_stones
[obj
->o_which
]);
586 elsewise
= (p_guess
[obj
->o_which
] != NULL
?
587 p_guess
[obj
->o_which
] : p_colors
[obj
->o_which
]);
591 elsewise
= (s_guess
[obj
->o_which
] != NULL
?
592 s_guess
[obj
->o_which
] : s_names
[obj
->o_which
]);
596 elsewise
= (ws_guess
[obj
->o_which
] != NULL
?
597 ws_guess
[obj
->o_which
] : ws_made
[obj
->o_which
]);
599 msg("You can't call that anything");
602 if (know
[obj
->o_which
])
604 msg("That has already been identified");
611 msg("alled \"%s\"", elsewise
);
615 msg("What do you want to call it? ");
616 strcpy(prbuf
, elsewise
);
617 if (get_str(prbuf
, cw
) == NORM
)
619 if (guess
[obj
->o_which
] != NULL
)
620 free(guess
[obj
->o_which
]);
621 guess
[obj
->o_which
] = malloc((unsigned int) strlen(prbuf
) + 1);
622 if (guess
[obj
->o_which
] != NULL
)
623 strcpy(guess
[obj
->o_which
], prbuf
);