diff arogue5/command.c @ 63:0ed67132cf10

Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
author elwin
date Thu, 09 Aug 2012 22:58:48 +0000
parents
children 7aff18a8d508
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/arogue5/command.c	Thu Aug 09 22:58:48 2012 +0000
@@ -0,0 +1,938 @@
+/*
+ * Read and execute the user commands
+ *
+ * Advanced Rogue
+ * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
+ * 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 "curses.h"
+#include <limits.h>
+#include <ctype.h>
+#include <signal.h>
+#include "mach_dep.h"
+#include "rogue.h"
+
+/*
+ * command:
+ *	Process the user commands
+ */
+
+command()
+{
+    register char ch;
+    register int ntimes = 1;			/* Number of player moves */
+    static char countch, direction, newcount = FALSE;
+    struct linked_list *item;
+    bool an_after = FALSE;
+
+    if (on(player, ISHASTE)) {
+	ntimes++;
+	turns--;	/* correct for later */
+    }
+    if (on(player, ISSLOW) || on(player, ISDANCE)) {
+	if (player.t_turn != TRUE) {
+	    ntimes--;
+	    turns++;
+	    an_after = TRUE;
+	}
+	player.t_turn ^= TRUE;
+    }
+
+    /*
+     * Let the daemons start up
+     */
+    do_daemons(BEFORE);
+    do_fuses(BEFORE);
+    while (ntimes-- > 0)
+    {	
+	/* One more tick of the clock. */
+	if ((++turns % DAYLENGTH) == 0) {
+	    daytime ^= TRUE;
+	    if (levtype == OUTSIDE) {
+		if (daytime) msg("The sun rises above the horizon");
+		else msg("The sun sinks below the horizon");
+	    }
+	    light(&hero);
+	}
+
+	look(after, FALSE);
+	if (!running) door_stop = FALSE;
+	lastscore = purse;
+	wmove(cw, hero.y, hero.x);
+	if (!((running || count) && jump)) {
+	    status(FALSE);
+	    wmove(cw, hero.y, hero.x);
+	    draw(cw);			/* Draw screen */
+	}
+	take = 0;
+	after = TRUE;
+	/*
+	 * Read command or continue run
+	 */
+	if (!no_command)
+	{
+	    if (running) {
+		/* If in a corridor or maze, if we are at a turn with only one
+		 * way to go, turn that way.
+		 */
+		if ((winat(hero.y, hero.x) == PASSAGE || levtype == MAZELEV) &&
+		    off(player, ISHUH) && (off(player, ISBLIND))) {
+		    int y, x;
+		    if (getdelta(runch, &y, &x) == TRUE) {
+			corr_move(y, x);
+		    }
+		}
+	        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)
+		msg("You can move again.");
+	}
+	else
+	{
+	    /*
+	     * check for prefixes
+	     */
+	    if (isdigit(ch))
+	    {
+		count = 0;
+		newcount = TRUE;
+		while (isdigit(ch))
+		{
+		    count = count * 10 + (ch - '0');
+		    if (count > 255)
+			count = 255;
+		    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: