Newsgroups: rec.games.roguelike.nethack
Cc: nethack-bugs@nethack.org
Subject: repeat travel command (plus travel destination cache)
From: Roderick Schertler <roderick@argon.org>
Date: 20 Jul 2002 14:05:44 -0400
Message-ID: <pzvg7a1dhj.fsf@eeyore.ibcinc.com>
Lines: 131
X-Newsreader: Gnus v5.7/Emacs 20.7

Here's a patch which adds a command to repeat the last travel you were
doing, bound to meta-underscore.  I was inspired to create it when I had
a pet master lich who kept teleporting into my way.  It also contains a
slightly more complete implementation of the travel destination cache.

This patch will also be available at http://www.argon.org/~roderick/.

diff -ur base.0/dat/cmdhelp nethack/dat/cmdhelp
--- base.0/dat/cmdhelp	Wed Mar 20 18:42:27 2002
+++ nethack/dat/cmdhelp	Sat Jul 20 13:48:52 2002
@@ -119,3 +119,4 @@
 M-u     Untrap something (trap, door, or chest)
 M-v     Print compile time options for this version of NetHack
 M-w     Wipe off your face
+M-_     Repeat travel to previous destination
diff -ur base.0/dat/hh nethack/dat/hh
--- base.0/dat/hh	Wed Mar 20 18:42:29 2002
+++ nethack/dat/hh	Sat Jul 20 13:49:11 2002
@@ -104,6 +104,7 @@
 M-u     untrap  untrap something
 M-v     version print compile time options for this version
 M-w     wipe    wipe off your face
+M-_             repeat travel to previous destination
 
 If the "number_pad" option is on, these additional variants are available:
 
diff -ur base.0/doc/Guidebook.mn nethack/doc/Guidebook.mn
--- base.0/doc/Guidebook.mn	Wed Mar 20 18:42:39 2002
+++ nethack/doc/Guidebook.mn	Sat Jul 20 13:49:37 2002
@@ -762,6 +762,8 @@
 #version
 .lp M-w
 #wipe
+.lp M-_
+repeat travel to previous destination
 .pg
 If the
 .op number_pad
diff -ur base.0/doc/Guidebook.tex nethack/doc/Guidebook.tex
--- base.0/doc/Guidebook.tex	Wed Mar 20 18:42:39 2002
+++ nethack/doc/Guidebook.tex	Sat Jul 20 13:49:56 2002
@@ -1024,6 +1024,9 @@
 %.lp
 \item[\tb{M-w}]
 {\tt\#wipe}
+%.lp
+\item[\tb{M-_}]
+repeat travel to previous destination
 \elist
 
 %.pg
diff -ur base.0/src/cmd.c nethack/src/cmd.c
--- base.0/src/cmd.c	Wed Mar 20 18:43:01 2002
+++ nethack/src/cmd.c	Sat Jul 20 13:48:31 2002
@@ -108,6 +108,7 @@
 STATIC_PTR int NDECL(doextcmd);
 STATIC_PTR int NDECL(domonability);
 STATIC_PTR int NDECL(dotravel);
+STATIC_PTR int NDECL(doretravel);
 # ifdef WIZARD
 STATIC_PTR int NDECL(wiz_wish);
 STATIC_PTR int NDECL(wiz_identify);
@@ -1368,6 +1369,7 @@
 	{SPBOOK_SYM, TRUE, dovspell},			/* Mike Stephenson */
 	{'#', TRUE, doextcmd},
 	{'_', TRUE, dotravel},
+	{M('_'), TRUE, doretravel},
 	{0,0,0,0}
 };
 
@@ -2143,8 +2145,13 @@
 	static char cmd[2];
 	coord cc;
 	cmd[1]=0;
-	cc.x = u.ux;
-	cc.y = u.uy;
+	if (u.tx > 0 && u.ty > 0) {
+	    cc.x = u.tx;
+	    cc.y = u.ty;
+	} else {
+	    cc.x = u.ux;
+	    cc.y = u.uy;
+	}
 	pline("Where do you want to travel to?");
 	if (getpos(&cc, TRUE, "the desired destination") < 0) {
 		/* user pressed ESC */
@@ -2153,6 +2160,19 @@
 	u.tx = cc.x;
 	u.ty = cc.y;
 	cmd[0] = CMD_TRAVEL;
+	readchar_queue = cmd;
+	return 0;
+}
+
+STATIC_PTR int
+doretravel()
+{
+	/* Repeat last travel command */
+	static char cmd[2];
+	if (!u.tx || !u.ty)
+	    return dotravel();
+	cmd[0] = CMD_TRAVEL;
+	cmd[1] = 0;
 	readchar_queue = cmd;
 	return 0;
 }
diff -ur base.0/src/do.c nethack/src/do.c
--- base.0/src/do.c	Wed Mar 20 18:43:02 2002
+++ nethack/src/do.c	Sat Jul 20 13:48:31 2002
@@ -983,6 +983,7 @@
 	fill_pit(u.ux, u.uy);
 	u.ustuck = 0;				/* idem */
 	u.uinwater = 0;
+	u.tx = u.ty = 0;
 	keepdogs(FALSE);
 	if (u.uswallow)				/* idem */
 		u.uswldtim = u.uswallow = 0;
diff -ur base.0/sys/amiga/amimenu.c nethack/sys/amiga/amimenu.c
--- base.0/sys/amiga/amimenu.c	Wed Mar 20 18:43:24 2002
+++ nethack/sys/amiga/amimenu.c	Sat Jul 20 13:48:31 2002
@@ -91,5 +91,6 @@
     {  NM_ITEM, "     Your #conduct",                      0, 0, 0, (void *)'#'}, /* "#co\n" */
     {  NM_ITEM, "     #ride your steed",                   0, 0, 0, (void *)'#'}, /* "#ri\n" */
     {  NM_ITEM, "M-2  Switch #twoweapon mode on/off",      0, 0, 0, (void *)(128+'2')},
+    {  NM_ITEM, "M-_  Repeat travel to previous destination", 0, 0, 0, (void *)(128+'_')},
     {  NM_END,  NULL,                                      0, 0, 0, 0}
 };

-- 
Roderick Schertler
roderick@argon.org
