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

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);