From a5e54356190de26d8aa1a95ac6a584579cf3ee4b Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Wed, 21 Jul 2021 12:23:21 +0300 Subject: [PATCH] Make mouselook use internal extended command ... instead of faking a key press --- include/decl.h | 1 - include/func_tab.h | 1 + src/cmd.c | 35 ++++++++++++++++++++++------------- win/Qt/qt_xcmd.cpp | 2 +- win/X11/winmisc.c | 2 +- win/tty/getline.c | 2 +- 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/include/decl.h b/include/decl.h index 6828ee751..aad46e7c7 100644 --- a/include/decl.h +++ b/include/decl.h @@ -459,7 +459,6 @@ enum nh_keyfunc { NHKF_NOPICKUP, /* 'm' */ NHKF_RUN_NOPICKUP, /* 'M' */ NHKF_DOINV, /* '0' */ - NHKF_CLICKLOOK, NHKF_REDRAW, NHKF_REDRAW2, diff --git a/include/func_tab.h b/include/func_tab.h index 175c4df04..ae4055f46 100644 --- a/include/func_tab.h +++ b/include/func_tab.h @@ -13,6 +13,7 @@ #define GENERALCMD 0x08 /* general command, does not take game time */ #define CMD_NOT_AVAILABLE 0x10 /* recognized but non-functional (!SHELL,&c) */ #define NOFUZZERCMD 0x20 /* fuzzer cannot execute this command */ +#define INTERNALCMD 0x40 /* only for internal use, not for user */ struct ext_func_tab { uchar key; diff --git a/src/cmd.c b/src/cmd.c index a8f5ee38c..93205e2a3 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -16,8 +16,6 @@ #endif #endif -#define CMD_CLICKLOOK (char) 0x8F - #ifdef DUMB /* stuff commented out in extern.h, but needed here */ extern int doapply(void); /**/ extern int dorub(void); /**/ @@ -105,6 +103,7 @@ static boolean can_do_extcmd(const struct ext_func_tab *); static int doextcmd(void); static int dotravel(void); static int dotravel_target(void); +static int doclicklook(void); static int doterrain(void); static int wiz_wish(void); static int wiz_identify(void); @@ -515,7 +514,7 @@ doextlist(void) for (efp = extcmdlist; efp->ef_txt; efp++) { int wizc; - if ((efp->flags & CMD_NOT_AVAILABLE) != 0) + if ((efp->flags & (CMD_NOT_AVAILABLE|INTERNALCMD)) != 0) continue; /* if hiding non-autocomplete commands, skip such */ if (menumode == 1 && (efp->flags & AUTOCOMPLETE) == 0) @@ -651,7 +650,7 @@ extcmd_via_menu(void) any = cg.zeroany; /* populate choices */ for (efp = extcmdlist; efp->ef_txt; efp++) { - if ((efp->flags & CMD_NOT_AVAILABLE) + if ((efp->flags & (CMD_NOT_AVAILABLE|INTERNALCMD)) || !(efp->flags & AUTOCOMPLETE) || (!wizard && (efp->flags & WIZMODECMD))) continue; @@ -2138,6 +2137,8 @@ struct ext_func_tab extcmdlist[] = { wiz_show_wmodes, IFBURIED | AUTOCOMPLETE | WIZMODECMD, NULL }, { 'z', "zap", "zap a wand", dozap, 0, NULL }, + /* internal commands: only used by game core, not available for user */ + { '\0', "clicklook", NULL, doclicklook, INTERNALCMD, NULL }, { '\0', (char *) 0, (char *) 0, donull, 0, (char *) 0 } /* sentinel */ }; @@ -2268,6 +2269,8 @@ bind_key(uchar key, const char *command) for (extcmd = extcmdlist; extcmd->ef_txt; extcmd++) { if (strcmpi(command, extcmd->ef_txt)) continue; + if ((extcmd->flags & INTERNALCMD) != 0) + continue; g.Cmd.commands[key] = extcmd; #if 0 /* silently accept key binding for unavailable command (!SHELL,&c) */ if ((extcmd->flags & CMD_NOT_AVAILABLE) != 0) { @@ -3050,7 +3053,6 @@ static struct { { NHKF_NOPICKUP, 'm', "nopickup" }, { NHKF_RUN_NOPICKUP, 'M', "run.nopickup" }, { NHKF_DOINV, '0', "doinv" }, - { NHKF_CLICKLOOK, CMD_CLICKLOOK, (char *) 0 }, /* no binding */ { NHKF_REDRAW, C('r'), "redraw" }, { NHKF_REDRAW2, C('l'), "redraw.numpad" }, { NHKF_GETDIR_SELF, '.', "getdir.self" }, @@ -3475,7 +3477,7 @@ rhack(char *cmd) /* handle most movement commands */ prefix_seen = FALSE; g.context.travel = g.context.travel1 = 0; - spkey = ch2spkeys(*cmd, NHKF_RUN, NHKF_CLICKLOOK); + spkey = ch2spkeys(*cmd, NHKF_RUN, NHKF_DOINV); switch (spkey) { case NHKF_RUSH2: @@ -3542,12 +3544,6 @@ rhack(char *cmd) g.context.move = FALSE; g.multi = 0; return; - case NHKF_CLICKLOOK: - if (iflags.clicklook) { - g.context.move = FALSE; - do_look(2, &g.clicklook_cc); - } - return; default: if (movecmd(*cmd, MV_WALK)) { /* ordinary movement */ g.context.run = 0; /* only matters here if it was 8 */ @@ -4327,7 +4323,7 @@ click_to_cmd(int x, int y, int mod) if (iflags.clicklook && mod == CLICK_2) { g.clicklook_cc.x = x; g.clicklook_cc.y = y; - cmd[0] = g.Cmd.spkeys[NHKF_CLICKLOOK]; + cmdq_add_ec(doclicklook); return cmd; } /* this used to be inside the 'if (flags.travelcmd)' block, but @@ -4769,6 +4765,19 @@ dotravel_target(void) return 1; } +/* mouse click look command */ +static int +doclicklook(void) +{ + if (!iflags.clicklook || !isok(g.clicklook_cc.x, g.clicklook_cc.y)) + return 0; + + g.context.move = FALSE; + do_look(2, &g.clicklook_cc); + + return 0; +} + /* * Parameter validator for generic yes/no function to prevent * the core from sending too long a prompt string to the diff --git a/win/Qt/qt_xcmd.cpp b/win/Qt/qt_xcmd.cpp index c737a1a28..26e19edfb 100644 --- a/win/Qt/qt_xcmd.cpp +++ b/win/Qt/qt_xcmd.cpp @@ -119,7 +119,7 @@ interesting_command(unsigned indx, int cmds) if (!strcmp("?", extcmdlist[indx].ef_txt)) return true; // some commands might have been compiled-out; don't show them - if ((extcmdlist[indx].flags & CMD_NOT_AVAILABLE) != 0) + if ((extcmdlist[indx].flags & (CMD_NOT_AVAILABLE|INTERNALCMD)) != 0) return false; // if picking from normal mode-only don't show wizard mode commands // or if picking from wizard mode-only don't show normal commands diff --git a/win/X11/winmisc.c b/win/X11/winmisc.c index b67e85b67..23404715f 100644 --- a/win/X11/winmisc.c +++ b/win/X11/winmisc.c @@ -1767,7 +1767,7 @@ ignore_extcmd(int idx) /* #shell or #suspect might not be available; 'extmenu' option controls whether we show full list or just the traditional extended commands */ - if ((extcmdlist[idx].flags & CMD_NOT_AVAILABLE) != 0 + if ((extcmdlist[idx].flags & (CMD_NOT_AVAILABLE|INTERNALCMD)) != 0 || ((extcmdlist[idx].flags & AUTOCOMPLETE) == 0 && !ec_full_list) || strlen(extcmdlist[idx].ef_txt) < 2) /* ignore "#" and "?" */ return TRUE; diff --git a/win/tty/getline.c b/win/tty/getline.c index 850372d9a..2eefd05c5 100644 --- a/win/tty/getline.c +++ b/win/tty/getline.c @@ -252,7 +252,7 @@ ext_cmd_getlin_hook(char *base) com_index = -1; for (oindex = 0; extcmdlist[oindex].ef_txt != (char *) 0; oindex++) { - if (extcmdlist[oindex].flags & CMD_NOT_AVAILABLE) + if (extcmdlist[oindex].flags & (CMD_NOT_AVAILABLE|INTERNALCMD)) continue; if ((extcmdlist[oindex].flags & AUTOCOMPLETE) && !(!wizard && (extcmdlist[oindex].flags & WIZMODECMD))