Change special keys into extended commands

Changes most of the special keys used in the main input loop
into extended commands:

- movement keys are now bound to extended commands, eg.
  #movewest and so on.

- m-prefix is now #reqmenu extended command, still bound to
  the 'm' key.

- run, rush, and fight are now extended commands, still bound
  to the same keys as previously.

- nopickup and runnopickup keys are removed.
  Nopickup was using 'm' key, the same as the m-prefix, so
  allow #reqmenu to modify movement commands to disable pickup.

- multiple prefix commands are allowed. This lets user to
  use #reqmenu, followed by #run, followed by movement to simulate
  runnopickup behaviour. (If necessary, adding runnopickup back
  as an extended command would be easy)
This commit is contained in:
Pasi Kallinen
2022-01-16 01:22:17 +02:00
parent dd28139a9e
commit e7fa065203
10 changed files with 591 additions and 502 deletions

View File

@@ -1245,6 +1245,11 @@ To really switch to explore mode, respond with \f(CRy\fP.
You can set the
.op paranoid_confirmation:quit
option to require a response of \f(CRyes\fP instead.
.lp "#fight "
Prefix key to force fight a direction, even if you see nothing
to fight there.
Default key is \(oqF\(cq, or \(oq\-\(cq with
.op number_pad
.lp "#fire "
Fire ammunition from quiver, possibly autowielding a launcher,
or hit with a wielded polearm.
@@ -1439,6 +1444,10 @@ is on.
.lp "#remove "
Remove an accessory (ring, amulet, etc).
Default key is \(oqR\(cq.
.lp "#reqmenu "
Prefix key to modify the behaviour or request menu from some commands.
Prevents autopickup when used with movement commands.
Default key is \(oqm\(cq.
.lp "#retravel"
Travel to a previously selected travel destination.
Default key is \(oqC-_\(cq.
@@ -1451,6 +1460,24 @@ Default key is \(oqM-R\(cq.
Rub a lamp or a stone.
Autocompletes.
Default key is \(oqM-r\(cq.
.lp "#run "
Prefix key to run towards a direction.
Default key is \(oqG\(cq when
.op number_pad
is off,
\(oq5\(cq when
.op number_pad
is set to 1 or 3,
otherwise \(oqM-5\(cq when it is set to 2 or 4.
.lp "#rush "
Prefix key to rush towards a direction.
Default is \(oqg\(cq when
.op number_pad
is off,
\(oqM-5\(cq when
.op number_pad
is set to 1 or 3,
otherwise \(oq5\(cq when it is set to 2 or 4.
.lp "#save "
Save the game and exit the program.
Default key is \(oqS\(cq.
@@ -4775,15 +4802,6 @@ With
.op number_pad
only.
Default is \(oqn\(cq.
.lp fight
Prefix key to force fight a direction.
Default is \(oqF\(cq.
.lp fight.numpad
Prefix key to force fight a direction.
With
.op number_pad
only.
Default is \(oq\-\(cq.
.lp getdir.help
When asked for a direction, the key to show the help.
Default is \(oq?\(cq.
@@ -4874,49 +4892,9 @@ 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 nopickup
Prefix key to move without picking up items.
Default is \(oqm\(cq.
.lp redraw
Key to redraw the screen.
Default is \(oq\(haR\(cq.
.lp redraw.numpad
Key to redraw the screen.
With
.op number_pad
only.
Default is \(oq\(haL\(cq.
.lp repeat
Key to repeat previous command.
Default is \(oq\(haA\(cq.
.lp reqmenu
Prefix key to request menu from some commands.
Default is \(oqm\(cq.
.lp run
Prefix key to run towards a direction.
Default is \(oqG\(cq.
.lp run.nopickup
Prefix key to run towards a direction without picking up items on the way.
Default is \(oqM\(cq.
.lp run.numpad
Prefix key to run towards a direction.
With
.op number_pad
only.
.lp ""
Default is \(oq5\(cq when number_pad is set to 1 or 3,
otherwise \(oqM-5\(cq when it is set to 2 or 4.
.lp rush
Prefix key to rush towards a direction.
Default is \(oqg\(cq.
.lp rush.numpad
Prefix key to rush towards a direction.
With
.op number_pad
only.
.lp ""
Default is \(oqM-5\(cq when number_pad is set to 1 or 3,
otherwise \(oq5\(cq when it is set to 2 or 4.
.hn 2
Configuring Message Types
.pg

View File

@@ -1349,6 +1349,12 @@ You can set the
{\it paranoid\verb+_+confirmation:quit\/}
option to require a response of ``{\tt yes}'' instead.
%.lp
\item[\tb{\#fight}]
Prefix key to force fight a direction, even if you see nothing
to fight there.
Default key is `{\tt F}', or `{\tt -}' with
{\it number\verb+_+pad\/}
%.lp
\item[\tb{\#fire}]
Fire ammunition from quiver, possibly autowielding a launcher,
or hit with a wielded polearm.
@@ -1546,6 +1552,11 @@ 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[\tb{\#reqmenu}]
Prefix key to modify the behaviour or request menu from some commands.
Prevents autopickup when used with movement commands.
Default key is `{\tt m}'.
%.lp
\item[\tb{\#retravel}]
Travel to a previously selected travel destination.
Default key is `{\tt C-_}'.
@@ -1558,6 +1569,26 @@ Default key is `{\tt M-R}'.
\item[\tb{\#rub}]
Rub a lamp or a stone. Autocompletes. Default key is `{\tt M-r}'.
%.lp
\item[\tb{\#run}]
Prefix key to run towards a direction.
Default key is `{\tt G}' when
{\it number\verb+_+pad\/}
is off,
`{\tt 5}' when
{\it number\verb+_+pad\/}
is set to 1~or~3,
otherwise `{\tt M-5}' when it is set to 2~or~4.
%.lp
\item[\tb{\#rush}]
Prefix key to rush towards a direction.
Default key is `{\tt g}' when
{\it number\verb+_+pad\/}
is off,
`{\tt M-5}' when
{\it number\verb+_+pad\/}
is set to 1~or~3,
otherwise `{\tt 5}' when it is set to 2~or~4.
%.lp
\item[\tb{\#save}]
Save the game and exit the program.
Default key is `{\tt S}'.
@@ -5265,13 +5296,6 @@ can only be bound to a single key.
Prefix key to start a count, to repeat a command this many times.
With {\it number\verb+_+pad\/} only. Default is~`{\tt n}'.
%.lp
\item[{\bb{fight}}]
Prefix key to force fight a direction. Default is~`{\tt F}'.
%.lp
\item[{\bb{fight.numpad}}]
Prefix key to force fight a direction. With {\it number\verb+_+pad\/} only.
Default is~`{\tt -}'.
%.lp
\item[{\bb{getdir.help}}]
When asked for a direction, the key to show the help. Default is~`{\tt ?}'.
%.lp
@@ -5375,47 +5399,8 @@ Default is~`{\tt z}'.
When asked for a location, the key to go to previous closest valid location.
Default is~`{\tt Z}'.
%.lp
\item[{\bb{nopickup}}]
Prefix key to move without picking up items. Default is~`{\tt m}'.
%.lp
\item[{\bb{redraw}}]
Key to redraw the screen. Default is~`{\tt \^{}R}'.
%.lp
\item[{\bb{redraw.numpad}}]
Key to redraw the screen. With {\it number\verb+_+pad\/} only.
Default is~`{\tt \^{}L}'.
%.lp
\item[{\bb{repeat}}]
Key to repeat previous command. Default is~`{\tt \^{}A}'.
%.lp
\item[{\bb{reqmenu}}]
Prefix key to request menu from some commands. Default is~`{\tt m}'.
%.lp
\item[{\bb{run}}]
Prefix key to run towards a direction. Default is~`{\tt G}'.
%.lp
\item[{\bb{run.nopickup}}]
Prefix key to run towards a direction without picking up items on the way.
Default is~`{\tt M}'.
%.lp
\item[{\bb{run.numpad}}]
Prefix key to run towards a direction.
With {\it number\verb+_+pad\/} only.
%.lp ""
Default is `{\tt 5}' when number_pad is set to 1~or~3,
otherwise `{\tt M-5}' when it is set to 2~or~4.
%.lp
\item[{\bb{rush}}]
Prefix key to rush towards a direction. Default is~`{\tt g}'.
%.lp
\item[{\bb{rush.numpad}}]
Prefix key to rush towards a direction.
With {\it number\verb+_+pad\/} only.
.lp ""
Default is `{\tt M-5}' when number_pad is set to 1~or~3,
otherwise `{\tt 5}' when it is set to 2~or~4.
\elist

View File

@@ -747,6 +747,7 @@ when two or more shops share a wall and hero uses Passes_walls to carry an
unpaid item from the first shop wasn't noticed
redo the unpaid_cost fix to handle shop items inside hero-owned container
flyers shouldn't fall on arrival when going down holes or trap doors
change movement keys and some special keys into extended commands
Fixes to 3.7.0-x Problems that Were Exposed Via git Repository

View File

@@ -445,20 +445,6 @@ enum nh_keyfunc {
NHKF_ESC = 0,
NHKF_DOAGAIN,
NHKF_REQMENU,
/* run ... clicklook need to be in a continuous block */
NHKF_RUN, /* 'G' */
NHKF_RUN2, /* '5' or M-5 */
NHKF_RUSH, /* 'g' */
NHKF_RUSH2, /* M-5 or '5' */
NHKF_FIGHT, /* 'F' */
NHKF_FIGHT2, /* '-' */
NHKF_NOPICKUP, /* 'm' */
NHKF_RUN_NOPICKUP, /* 'M' */
NHKF_REDRAW,
NHKF_REDRAW2,
NHKF_GETDIR_SELF,
NHKF_GETDIR_SELF2,
NHKF_GETDIR_HELP,
@@ -503,9 +489,6 @@ struct cmd {
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; /* QWERTZ keyboards; use z to move NW, y to zap */
char move[N_DIRS]; /* char used for moving one step in direction */
char rush[N_DIRS];
char run[N_DIRS];
const char *dirchars; /* current movement/direction characters */
const char *alphadirchars; /* same as dirchars if !numpad */
const struct ext_func_tab *commands[256]; /* indexed by input character */

View File

@@ -199,12 +199,41 @@ extern boolean status_hilite_menu(void);
/* ### cmd.c ### */
extern int do_move_west(void);
extern int do_move_northwest(void);
extern int do_move_north(void);
extern int do_move_northeast(void);
extern int do_move_east(void);
extern int do_move_southeast(void);
extern int do_move_south(void);
extern int do_move_southwest(void);
extern int do_rush_west(void);
extern int do_rush_northwest(void);
extern int do_rush_north(void);
extern int do_rush_northeast(void);
extern int do_rush_east(void);
extern int do_rush_southeast(void);
extern int do_rush_south(void);
extern int do_rush_southwest(void);
extern int do_run_west(void);
extern int do_run_northwest(void);
extern int do_run_north(void);
extern int do_run_northeast(void);
extern int do_run_east(void);
extern int do_run_southeast(void);
extern int do_run_south(void);
extern int do_run_southwest(void);
extern int do_reqmenu(void);
extern int do_rush(void);
extern int do_run(void);
extern int do_fight(void);
extern char randomkey(void);
extern void random_response(char *, int);
extern int rnd_extcmd_idx(void);
extern int domonability(void);
extern const struct ext_func_tab *ext_func_tab_from_func(int(*)(void));
extern char cmd_from_func(int(*)(void));
extern char cmd_from_dir(int, int);
extern const char *cmdname_from_func(int(*)(void), char *, boolean);
extern boolean redraw_cmd(char);
extern const char *levltyp_to_name(int);

View File

@@ -15,6 +15,8 @@
#define NOFUZZERCMD 0x20 /* fuzzer cannot execute this command */
#define INTERNALCMD 0x40 /* only for internal use, not for user */
#define CMD_M_PREFIX 0x80 /* accepts menu prefix */
#define PREFIXCMD 0x100 /* prefix command, requires another one after it */
#define MOVEMENTCMD 0x200 /* used to move hero/cursor */
struct ext_func_tab {
uchar key;

848
src/cmd.c

File diff suppressed because it is too large Load Diff

View File

@@ -987,13 +987,8 @@ use_pick_axe(struct obj *obj)
downok = !!can_reach_floor(FALSE);
dsp = dirsyms;
for (dir = 0; dir < N_DIRS_Z; dir++) {
char dirch;
if (dir == DIR_DOWN)
dirch = cmd_from_func(dodown);
else if (dir == DIR_UP)
dirch = cmd_from_func(doup);
else
dirch = g.Cmd.move[dir];
char dirch = cmd_from_dir(dir, MV_WALK);
/* filter out useless directions */
if (u.uswallow) {
; /* all directions are viable when swallowed */

View File

@@ -1120,6 +1120,8 @@ dodown(void)
if (trap && Is_stronghold(&u.uz)) {
goto_hell(FALSE, TRUE);
} else {
if (!trap)
u.dz = 1;
g.at_ladder = (boolean) (levl[u.ux][u.uy].typ == LADDER);
next_level(!trap);
g.at_ladder = FALSE;
@@ -1173,6 +1175,7 @@ doup(void)
return ECMD_OK;
}
g.at_ladder = (boolean) (levl[u.ux][u.uy].typ == LADDER);
u.dz = -1;
prev_level(TRUE);
g.at_ladder = FALSE;
return ECMD_TIME;
@@ -2046,7 +2049,7 @@ cmd_safety_prevention(const char *cmddesc, const char *act, int *flagcounter)
buf[0] = '\0';
if (iflags.cmdassist || !(*flagcounter)++)
Sprintf(buf, " Use '%s' prefix to force %s.",
visctrl(g.Cmd.spkeys[NHKF_REQMENU]), cmddesc);
visctrl(cmd_from_func(do_reqmenu)), cmddesc);
Norep("%s%s", act, buf);
return TRUE;
}

View File

@@ -108,22 +108,25 @@ getpos_help(boolean force, const char *goal)
char sbuf[BUFSZ];
boolean doing_what_is;
winid tmpwin = create_nhwindow(NHW_MENU);
int runkey = iflags.num_pad ? NHKF_RUN2 : NHKF_RUN;
int rushkey = iflags.num_pad ? NHKF_RUSH2 : NHKF_RUSH;
Sprintf(sbuf,
"Use '%s', '%s', '%s', '%s' to move the cursor to %s.", /* hjkl */
visctrl(g.Cmd.move[DIR_W]), visctrl(g.Cmd.move[DIR_S]),
visctrl(g.Cmd.move[DIR_N]), visctrl(g.Cmd.move[DIR_E]), goal);
visctrl(cmd_from_func(do_move_west)),
visctrl(cmd_from_func(do_move_south)),
visctrl(cmd_from_func(do_move_north)),
visctrl(cmd_from_func(do_move_east)), goal);
putstr(tmpwin, 0, sbuf);
Sprintf(sbuf,
"Use '%s', '%s', '%s', '%s' to fast-move the cursor, %s.",
visctrl(g.Cmd.run[DIR_W]), visctrl(g.Cmd.run[DIR_S]),
visctrl(g.Cmd.run[DIR_N]), visctrl(g.Cmd.run[DIR_E]),
visctrl(cmd_from_func(do_run_west)),
visctrl(cmd_from_func(do_run_south)),
visctrl(cmd_from_func(do_run_north)),
visctrl(cmd_from_func(do_run_east)),
fastmovemode[iflags.getloc_moveskip]);
putstr(tmpwin, 0, sbuf);
Sprintf(sbuf, "(or prefix normal move with '%s' or '%s' to fast-move)",
visctrl(g.Cmd.spkeys[runkey]), visctrl(g.Cmd.spkeys[rushkey]));
visctrl(cmd_from_func(do_run)),
visctrl(cmd_from_func(do_rush)));
putstr(tmpwin, 0, sbuf);
putstr(tmpwin, 0, "Or enter a background symbol (ex. '<').");
Sprintf(sbuf, "Use '%s' to move the cursor on yourself.",
@@ -698,8 +701,6 @@ getpos(coord *ccp, boolean force, const char *goal)
schar udx = u.dx, udy = u.dy, udz = u.dz;
int dx, dy;
boolean rushrun = FALSE;
int runkey = iflags.num_pad ? NHKF_RUN2 : NHKF_RUN;
int rushkey = iflags.num_pad ? NHKF_RUSH2 : NHKF_RUSH;
for (i = 0; i < SIZE(pick_chars_def); i++)
pick_chars[i] = g.Cmd.spkeys[pick_chars_def[i].nhkf];
@@ -757,7 +758,7 @@ getpos(coord *ccp, boolean force, const char *goal)
result = -1;
break;
}
if (c == g.Cmd.spkeys[runkey] || c == g.Cmd.spkeys[rushkey]) {
if (c == cmd_from_func(do_run) || c == cmd_from_func(do_rush)) {
c = readchar_poskey(&tx, &ty, &sidx);
rushrun = TRUE;
}
@@ -974,9 +975,11 @@ getpos(coord *ccp, boolean force, const char *goal)
if (!force)
Strcpy(note, "aborted");
else /* hjkl */
Sprintf(note, "use '%c', '%c', '%c', '%c' or '%s'",
g.Cmd.move[DIR_W], g.Cmd.move[DIR_S],
g.Cmd.move[DIR_N], g.Cmd.move[DIR_E],
Sprintf(note, "use '%s', '%s', '%s', '%s' or '%s'",
visctrl(cmd_from_func(do_move_west)),
visctrl(cmd_from_func(do_move_south)),
visctrl(cmd_from_func(do_move_north)),
visctrl(cmd_from_func(do_move_east)),
visctrl(g.Cmd.spkeys[NHKF_GETPOS_PICK]));
pline("Unknown direction: '%s' (%s).", visctrl((char) c),
note);