From: nethack.rankin Date: Sat, 26 Nov 2005 02:32:49 +0000 (+0000) Subject: number_pad:3,4,-1 (trunk only) X-Git-Tag: MOVE2GIT~1202 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0076d5fc00bf1a95c290c5a107fda33b711e830a;p=nethack number_pad:3,4,-1 (trunk only) 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. --- diff --git a/include/decl.h b/include/decl.h index 35e99bb77..984d3f097 100644 --- a/include/decl.h +++ b/include/decl.h @@ -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 */ diff --git a/include/extern.h b/include/extern.h index 6d9f63840..cbca118d0 100644 --- a/include/extern.h +++ b/include/extern.h @@ -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); diff --git a/include/flag.h b/include/flag.h index f690cdbca..4d738c01a 100644 --- a/include/flag.h +++ b/include/flag.h @@ -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 */