From 2e144e814df3e662e42562d2428df689c7457cbf Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Mon, 17 Jan 2022 17:13:59 +0200 Subject: [PATCH] Change repeat into extended command --- doc/Guidebook.mn | 8 ++++---- doc/Guidebook.tex | 9 +++++---- doc/fixes37.0 | 2 -- include/config.h | 7 ------- include/decl.h | 1 - include/extern.h | 1 + src/cmd.c | 36 +++++++++++++++++++----------------- win/Qt/qt_main.cpp | 10 ++-------- 8 files changed, 31 insertions(+), 43 deletions(-) diff --git a/doc/Guidebook.mn b/doc/Guidebook.mn index e9f9e5f4b..d1bccfb92 100644 --- a/doc/Guidebook.mn +++ b/doc/Guidebook.mn @@ -697,7 +697,7 @@ Remove one or more worn items, such as armor. Use \(oqT\(cq (take off) to take off only one piece of armor or \(oqR\(cq (remove) to take off only one accessory. .lp \(haA -Redo the previous command. +Repeat the previous command. .lp c Close a door. .lp C @@ -1444,6 +1444,9 @@ is on. .lp "#remove " Remove an accessory (ring, amulet, etc). Default key is \(oqR\(cq. +.lp "#repeat " +Repeat the previous command. +Default key is \(oq\(haA\(cq. .lp "#reqmenu " Prefix key to modify the behaviour or request menu from some commands. Prevents autopickup when used with movement commands. @@ -4892,9 +4895,6 @@ Default is \(oqz\(cq. .lp getpos.valid.prev When asked for a location, the key to go to previous closest valid location. Default is \(oqZ\(cq. -.lp repeat -Key to repeat previous command. -Default is \(oq\(haA\(cq. .hn 2 Configuring Message Types .pg diff --git a/doc/Guidebook.tex b/doc/Guidebook.tex index f57c34ebe..92c39a868 100644 --- a/doc/Guidebook.tex +++ b/doc/Guidebook.tex @@ -797,7 +797,7 @@ Use `{\tt T}' (take off) to take off only one piece of armor or `{\tt R}' (remove) to take off only one accessory. %.lp \item[\tb{\^{}A}] -Redo the previous command. +Repeat the previous command. %.lp \item[\tb{c}] Close a door. @@ -1552,6 +1552,10 @@ and also `{\tt \^{}L}' if {\it number\verb+_+pad\/} is on. \item[\tb{\#remove}] Remove an accessory (ring, amulet, etc). Default key is `{\tt R}'. %.lp +\item[{\bb{\#repeat}}] +Repeat the previous command. +Default key is~`{\tt \^{}A}'. +%.lp \item[\tb{\#reqmenu}] Prefix key to modify the behaviour or request menu from some commands. Prevents autopickup when used with movement commands. @@ -5398,9 +5402,6 @@ Default is~`{\tt z}'. \item[{\bb{getpos.valid.prev}}] When asked for a location, the key to go to previous closest valid location. Default is~`{\tt Z}'. -%.lp -\item[{\bb{repeat}}] -Key to repeat previous command. Default is~`{\tt \^{}A}'. \elist diff --git a/doc/fixes37.0 b/doc/fixes37.0 index 03e2e3212..e37bb35ee 100644 --- a/doc/fixes37.0 +++ b/doc/fixes37.0 @@ -1294,8 +1294,6 @@ include an indication of monsters' health during farlook feedback (including /M and autodescribe); also include it in death reason when killed by a monster: "killed by {an uninjured newt,a heavily injured mumak}" [later: suppress the indication of monsters' health] -make DOAGAIN (^A) become unconditional; commenting it out in config.h makes - it be bound to NUL, a no-op, but allows BIND=k:repeat to set it to k add support for a single monster species to have distinct male, female, and gender-neutral naming terms add support for a single monster species to have distinct male and female diff --git a/include/config.h b/include/config.h index 4b3bc9218..1e7bc353a 100644 --- a/include/config.h +++ b/include/config.h @@ -483,13 +483,6 @@ typedef unsigned char uchar; #endif #endif -/* The "repeat" key used in cmd.c as NHKF_DOAGAIN; if commented out or the - * value is changed from C('A') to 0, it won't be bound to any keystroke - * unless you use the run-time configuration file's BIND directive for it. - * [Note: C() macro isn't defined yet but it will be before DOAGAIN is used.] - */ -#define DOAGAIN C('A') /* repeat previous command; default is ^A, '\001' */ - /* CONFIG_ERROR_SECURE: If user makes NETHACKOPTIONS point to a file ... * TRUE: Show the first error, nothing else. * FALSE: Show all errors as normal, with line numbers and context. diff --git a/include/decl.h b/include/decl.h index 36aa590e9..3f18f9db6 100644 --- a/include/decl.h +++ b/include/decl.h @@ -443,7 +443,6 @@ struct early_opt { /* special key functions */ enum nh_keyfunc { NHKF_ESC = 0, - NHKF_DOAGAIN, NHKF_GETDIR_SELF, NHKF_GETDIR_SELF2, diff --git a/include/extern.h b/include/extern.h index 9bcc56ae9..d54665590 100644 --- a/include/extern.h +++ b/include/extern.h @@ -227,6 +227,7 @@ extern int do_reqmenu(void); extern int do_rush(void); extern int do_run(void); extern int do_fight(void); +extern int do_repeat(void); extern char randomkey(void); extern void random_response(char *, int); extern int rnd_extcmd_idx(void); diff --git a/src/cmd.c b/src/cmd.c index 6e65ad149..68a8fa5c9 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -2067,6 +2067,21 @@ do_fight(void) return ECMD_OK; } +/* #repeat */ +int +do_repeat(void) +{ + if (!g.in_doagain && g.saveq[0]) { + g.in_doagain = TRUE; + g.stail = 0; + rhack((char *) 0); /* read and execute command */ + g.in_doagain = FALSE; + iflags.menu_requested = FALSE; + return ECMD_TIME; + } + return ECMD_OK; +} + /* extcmdlist: full command list, ordered by command name; commands with no keystroke or with only a meta keystroke generally need to be flagged as autocomplete and ones with a regular keystroke @@ -2199,6 +2214,8 @@ struct ext_func_tab extcmdlist[] = { doredraw, IFBURIED | GENERALCMD, NULL }, { 'R', "remove", "remove an accessory (ring, amulet, etc)", doremring, 0, NULL }, + { C('a'), "repeat", "repeat a previous command", + do_repeat, IFBURIED | GENERALCMD, NULL }, { 'm', "reqmenu", "prefix: request menu or modify command", do_reqmenu, PREFIXCMD, NULL }, { C('_'), "retravel", "travel to previously selected travel location", @@ -2427,7 +2444,6 @@ static const struct { { NHKF_ESC, "cancel current prompt or pending prefix", FALSE }, { NHKF_COUNT, "Prefix: for digits when preceding a command with a count", TRUE }, - { NHKF_DOAGAIN , "repeat: perform the previous command again", FALSE }, { 0, (const char *) 0, FALSE } }; @@ -3295,17 +3311,12 @@ wiz_migrate_mons(void) } #endif -#ifndef DOAGAIN /* might have gotten undefined in config.h */ -#define DOAGAIN '\0' /* undefined => 0, '\0' => no key to activate redo */ -#endif - static struct { int nhkf; uchar key; const char *name; } const spkeys_binds[] = { { NHKF_ESC, '\033', (char *) 0 }, /* no binding */ - { NHKF_DOAGAIN, DOAGAIN, "repeat" }, { NHKF_GETDIR_SELF, '.', "getdir.self" }, { NHKF_GETDIR_SELF2, 's', "getdir.self2" }, { NHKF_GETDIR_HELP, '?', "getdir.help" }, @@ -3692,16 +3703,7 @@ got_prefix_input: iflags.menu_requested = FALSE; return; } - /* DOAGAIN might be '\0'; if so, don't execute it even if *cmd is too */ - if ((*cmd && *cmd == g.Cmd.spkeys[NHKF_DOAGAIN]) - && !g.in_doagain && g.saveq[0]) { - g.in_doagain = TRUE; - g.stail = 0; - rhack((char *) 0); /* read and execute command */ - g.in_doagain = FALSE; - iflags.menu_requested = FALSE; - return; - } + /* Special case of *cmd == ' ' handled better below */ if (!*cmd || *cmd == (char) 0377) { nhbell(); @@ -4631,7 +4633,7 @@ parse(void) g.last_command_count = 0; } else if (g.in_doagain) { g.command_count = g.last_command_count; - } else if (foo && foo == g.Cmd.spkeys[NHKF_DOAGAIN]) { + } else if (foo && foo == cmd_from_func(do_repeat)) { // g.command_count will be set again when we // re-enter with g.in_doagain set true g.command_count = g.last_command_count; diff --git a/win/Qt/qt_main.cpp b/win/Qt/qt_main.cpp index 1b99f3fd9..fabf8453c 100644 --- a/win/Qt/qt_main.cpp +++ b/win/Qt/qt_main.cpp @@ -829,9 +829,7 @@ NetHackQtMainWindow::NetHackQtMainWindow(NetHackQtKeyBuffer& ks) : QSignalMapper* sm = new QSignalMapper(this); connect(sm, SIGNAL(mapped(const QString&)), this, SLOT(doKeys(const QString&))); - // 'donull' is a placeholder here; AddToolButton() will fix it up; - // button will be omitted if DOAGAIN is bound to '\0' - AddToolButton(toolbar, sm, "Again", donull, QPixmap(again_xpm)); + AddToolButton(toolbar, sm, "Again", do_repeat, QPixmap(again_xpm)); // this used to be called "Get" which is confusing to experienced players AddToolButton(toolbar, sm, "Pick up", dopickup, QPixmap(pickup_xpm)); AddToolButton(toolbar, sm, "Drop", doddrop, QPixmap(drop_xpm)); @@ -927,11 +925,7 @@ void NetHackQtMainWindow::AddToolButton(QToolBar *toolbar, QSignalMapper *sm, char actchar[2]; uchar key; - // the ^A command is just a keystroke, not a full blown command function - if (!strcmp(name, "Again")) { - key = ::g.Cmd.spkeys[NHKF_DOAGAIN]; - } else - key = (uchar) cmd_from_func(func); + key = (uchar) cmd_from_func(func); // if key is valid, add a button for it; otherwise omit the command // (won't work as intended if a different command is bound to same key)