]> granicus.if.org Git - nethack/commitdiff
number_pad:3,4,-1 (trunk only)
authornethack.rankin <nethack.rankin>
Sat, 26 Nov 2005 02:32:49 +0000 (02:32 +0000)
committernethack.rankin <nethack.rankin>
Sat, 26 Nov 2005 02:32:49 +0000 (02:32 +0000)
     Add support requested by a user for number_pad:3 to use a phone-style
keypad layout where 1,2,3 are on the top row and 7,8,9 on the bottom,
opposite of the adding machine layout adopted by computer keyboards.  Also
number_pad:4 combines that with the number_pad:2 hack to give different
behavior for the 5 key (also meta-5 and meta-0).  And number_pad:-1 is a
rather absurd way to support German keyboards which have y and z keys
swapped, avoiding the need to add a new option for that.  With it, z moves
upper-left and y zaps wands, with corresponding swap of the upper case,
control, and meta variations of those two letters.  (There is a "German
keyboard patch" for this floating around the net, but it implements a
compile time configuration setting which results in hard-coded behavior
for those keys.  This implementation lets it be toggled on or off at will.)

     There's more here, intended to ultimately simplify rhack() quite a
bit.  Most of that isn't finished yet.  However, the part that is done
should produce same run-time behavior as before.  I hope....

     iflags.num_pad and iflags.num_pad_mode should now be viewed as opaque
items used for communicating dynamically updated option settings to the
core only.  Ports and/or interfaces which feel inclined to peek at them
should switch to Cmd.num_pad,&c instead.  (I've made that switch for a
couple of places which would have stopped compiling due to sdir and ndir
going away, and for vms+tty where I could directly test the change(s),
possibly plus one or two places which got heldover over from my earlier
attempt that did try to update all of them.  Ports which haven't made the
change yet ought to continue to work as-is though.)

     Eventually ports/interfaces which implement alternate ways to invoke
commands (pull down menus or extra keyboard buttons or whatever) should be
able to scan Cmd.commands[] to figure out which input characters trigger
which nethack functions.  The ones that currently use hardcoded key lists
will probably need to migrate before any dynamic key binding functionality
gets implemented.  (Which may never happen; it's definitely not on my own
to-do list.)  Cmd.serialno is intended to be the way for them figure out
when the commands have been changed (which right now only happens when 'O'
is used to alter the number_pad setting); perhaps a new interface callback
would be better suited for communicating this.

     It may be necessary to rearrange header inclusion so that func_tab.h
gets included before flag.h (and/or struct cmd gets moved from the latter
to the former--but then func_tab.h would be needed in a bunch of places
which don't currently use it) to support some pre-ANSI compilers.  And the
command initialization might need to be moved to somewhere earlier than
init_options() at some point if port/interface initialization starts caring
about it.

include/decl.h
include/extern.h
include/flag.h

index 35e99bb77aba91fe53ada332a92bd2fdaa5f68f8..984d3f097f224f3ad1396ba11527b059c68f49af 100644 (file)
@@ -1,4 +1,4 @@
-/*     SCCS Id: @(#)decl.h     3.5     2004/11/22      */
+/*     SCCS Id: @(#)decl.h     3.5     2005/11/19      */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -203,7 +203,6 @@ E const char *nomovemsg;
 E const char nul[];
 E char lock[];
 
-E const char sdir[], ndir[];
 E const schar xdir[], ydir[], zdir[];
 
 E NEARDATA schar tbx, tby;             /* set in mthrowu.c */
index 6d9f638406f4eef5150b78f9d5894c8874995758..cbca118d0db014989a18d706419dece23ca9c5a7 100644 (file)
@@ -183,6 +183,7 @@ E void FDECL(savech, (CHAR_P));
 #ifdef WIZARD
 E void NDECL(add_debug_extended_commands);
 #endif /* WIZARD */
+E void FDECL(reset_commands, (BOOLEAN_P));
 E void FDECL(rhack, (char *));
 E int NDECL(doextlist);
 E int NDECL(extcmd_via_menu);
index f690cdbca8492799264db5a6c118370a0f23b0e0..4d738c01a357683371edb343f80f3c3215a43edd 100644 (file)
@@ -1,4 +1,4 @@
-/*     SCCS Id: @(#)flag.h     3.5     2003/11/09      */
+/*     SCCS Id: @(#)flag.h     3.5     2005/11/19      */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -307,4 +307,34 @@ extern NEARDATA struct instance_flags iflags;
 #define RUN_STEP       2       /* update display every single step */
 #define RUN_CRAWL      3       /* walk w/ extra delay after each update */
 
+/* command parsing, mainly dealing with number_pad handling;
+   not saved and restored */
+
+#ifdef NHSTDC
+/* forward declaration sufficient to declare pointers */
+struct func_tab;               /* from func_tab.h */
+#endif
+
+/* commands[] is used to directly access cmdlist[] instead of looping
+   through it to find the entry for a given input character;
+   move_X is the character used for moving one step in direction X;
+   alphadirchars corresponds to old sdir,
+   dirchars corresponds to ``iflags.num_pad ? ndir : sdir'';
+   pcHack_compat and phone_layout only matter when num_pad is on,
+   swap_yz only matters when it's off */
+struct cmd {
+    unsigned serialno;     /* incremented after each update */
+    boolean num_pad;       /* same as iflags.num_pad except during updates */
+    boolean pcHack_compat;  /* for numpad:  affects 5, M-5, and M-0 */
+    boolean phone_layout;   /* inverted keypad:  1,2,3 above, 7,8,9 below */
+    boolean swap_yz;       /* German keyboads; use z to move NW, y to zap */
+    char move_W, move_NW, move_N, move_NE,
+        move_E, move_SE, move_S, move_SW;
+    const char *dirchars;   /* current movement/direction characters */
+    const char *alphadirchars; /* same as dirchars if !numpad */
+    const struct func_tab *commands[256]; /* indexed by input character */
+};
+
+extern NEARDATA struct cmd Cmd;
+
 #endif /* FLAG_H */