Mercurial > hg > early-roguelike
diff srogue/command.c @ 36:2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
| author | elwin |
|---|---|
| date | Thu, 25 Nov 2010 12:21:41 +0000 |
| parents | |
| children | 5ea4a4d8f961 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/srogue/command.c Thu Nov 25 12:21:41 2010 +0000 @@ -0,0 +1,714 @@ +/* + * Read and execute the user commands + * + * @(#)command.c 9.0 (rdk) 7/17/84 + * + * Super-Rogue + * Copyright (C) 1984 Robert D. Kindelberger + * All rights reserved. + * + * Based on "Rogue: Exploring the Dungeons of Doom" + * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman + * All rights reserved. + * + * See the file LICENSE.TXT for full copyright and licensing information. + */ + +#include <ctype.h> +#include <signal.h> +#include <limits.h> +#include "rogue.h" +#include "rogue.ext" +#ifdef __DJGPP__ +#include <process.h> +#endif + +/* + * command: + * Process the user commands + */ +command() +{ + reg char ch; + reg int ntimes = 1; /* Number of player moves */ + static char countch, direction, newcount = FALSE; + + if (pl_on(ISHASTE)) + ntimes++; + /* + * Let the daemons start up + */ + while (ntimes-- > 0) { + do_daemons(BEFORE); + look(TRUE); + if (!running) + door_stop = FALSE; + lastscore = purse; + wmove(cw, hero.y, hero.x); + if (!(running || count)) + draw(cw); /* Draw screen */ + take = 0; + after = TRUE; + /* + * Read command or continue run + */ + if (wizard) + waswizard = TRUE; + if (player.t_nocmd <= 0) { + player.t_nocmd = 0; + 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 (player.t_nocmd > 0) { + if (--player.t_nocmd <= 0) + 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': case 'p': + break; + default: + count = 0; + } + } + switch (ch) { + case 'f': + case 'g': + if (pl_off(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(); after = FALSE; + 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');
