]> granicus.if.org Git - nethack/commitdiff
fix movement prefixes
authorPatR <rankin@nethack.org>
Mon, 7 Feb 2022 01:46:31 +0000 (17:46 -0800)
committerPatR <rankin@nethack.org>
Mon, 7 Feb 2022 01:46:31 +0000 (17:46 -0800)
My earlier change resulted in rejecting all commands entered after
a movement prefix key, rather than just ones that aren't supposed to
take any prefix.

This fixes that and also restores the ability to use 'm>' or 'm<' on
stairs to change levels without auto-pickup at the destination.

doc/fixes3-7-0.txt
include/extern.h
src/cmd.c
src/do.c

index 2e7d69193d63fbca878b8e0b31a0e85fe50db87a..cac6d33c6a1de2bf3eec2e175b8b4342f87fce0c 100644 (file)
@@ -1002,6 +1002,9 @@ cursed scroll of light had special message when wielding Sunsword that didn't
        work for wearing gold dragon scales/mail
 giving a prefix keystroke other than 'm' prior to a command that doesn't use
        prefixes was siliently ignored instead of being rejected
+prior revision broke all prefix usage
+movement command revamp broke 'm>' and 'm<' on stairs to avoid auto-pickup at
+       the destination
 
 curses: 'msg_window' option wasn't functional for curses unless the binary
        also included tty support
index dea9bedbc6cb9d01e1310659f224089497f8dd26..a2bf6ca7ea949b9c030e61a019fb5b749c0e1d10 100644 (file)
@@ -199,6 +199,7 @@ extern boolean status_hilite_menu(void);
 
 /* ### cmd.c ### */
 
+extern void set_move_cmd(int, int);
 extern int do_move_west(void);
 extern int do_move_northwest(void);
 extern int do_move_north(void);
index 1d5daaca01a029f6188ff754fb273ce0e722a5d3..c7d0e5ca7da88bf03c35537764e7e8914781995f 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -105,7 +105,6 @@ static int dotravel(void);
 static int dotravel_target(void);
 static int doclicklook(void);
 static int doterrain(void);
-static void set_move_cmd(int, int);
 static int wiz_wish(void);
 static int wiz_identify(void);
 static int wiz_map(void);
@@ -1844,20 +1843,20 @@ doterrain(void)
     return ECMD_OK; /* no time elapses */
 }
 
-static void
+void
 set_move_cmd(int dir, int run)
 {
+    u.dz = zdir[dir];
+    u.dx = xdir[dir];
+    u.dy = ydir[dir];
     /* #reqmenu -prefix disables autopickup during movement */
     if (iflags.menu_requested)
         g.context.nopick = 1;
     g.context.travel = g.context.travel1 = 0;
-    if (!g.domove_attempting) {
+    if (!g.domove_attempting && !u.dz) {
         g.context.run = run;
         g.domove_attempting |= (!run ? DOMOVE_WALK : DOMOVE_RUSH);
     }
-    u.dz = zdir[dir];
-    u.dx = xdir[dir];
-    u.dy = ydir[dir];
 }
 
 /* move or attack */
@@ -2036,7 +2035,8 @@ int
 do_reqmenu(void)
 {
     if (iflags.menu_requested) {
-        Norep("Double %s prefix, canceled.", visctrl(cmd_from_func(do_reqmenu)));
+        Norep("Double %s prefix, canceled.",
+              visctrl(cmd_from_func(do_reqmenu)));
         iflags.menu_requested = FALSE;
         return ECMD_CANCEL;
     }
@@ -2135,7 +2135,7 @@ struct ext_func_tab extcmdlist[] = {
     { M('d'), "dip", "dip an object into something",
               dodip, AUTOCOMPLETE, NULL },
     { '>',    "down", "go down a staircase",
-              dodown, 0, NULL },
+              dodown, MOVEMENTCMD, NULL },
     { 'd',    "drop", "drop an item",
               dodrop, 0, NULL },
     { 'D',    "droptype", "drop specific item types",
@@ -2320,7 +2320,7 @@ struct ext_func_tab extcmdlist[] = {
     { M('u'), "untrap", "untrap something",
               dountrap, AUTOCOMPLETE, NULL },
     { '<',    "up", "go up a staircase",
-              doup, 0, NULL },
+              doup, MOVEMENTCMD, NULL },
     { '\0',   "vanquished", "list vanquished monsters",
               dovanquished, IFBURIED | AUTOCOMPLETE | WIZMODECMD, NULL },
     { M('v'), "version",
@@ -2386,55 +2386,55 @@ struct ext_func_tab extcmdlist[] = {
     /* movement commands will be bound by reset_commands() */
     /* move or attack */
     { '\0', "movewest", "move west (screen left)",
-            do_move_west, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_move_west, MOVEMENTCMD, NULL },
     { '\0', "movenorthwest", "move northwest (screen upper left)",
-            do_move_northwest, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_move_northwest, MOVEMENTCMD, NULL },
     { '\0', "movenorth", "move north (screen up)",
-            do_move_north, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_move_north, MOVEMENTCMD, NULL },
     { '\0', "movenortheast", "move northeast (screen upper right)",
-            do_move_northeast, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_move_northeast, MOVEMENTCMD, NULL },
     { '\0', "moveeast", "move east (screen right)",
-            do_move_east, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_move_east, MOVEMENTCMD, NULL },
     { '\0', "movesoutheast", "move southeast (screen lower right)",
-            do_move_southeast, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_move_southeast, MOVEMENTCMD, NULL },
     { '\0', "movesouth", "move south (screen down)",
-            do_move_south, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_move_south, MOVEMENTCMD, NULL },
     { '\0', "movesouthwest", "move southwest (screen lower left)",
-            do_move_southwest, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_move_southwest, MOVEMENTCMD, NULL },
     /* rush */
     { '\0', "rushwest", "rush west (screen left)",
-            do_rush_west, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_rush_west, MOVEMENTCMD, NULL },
     { '\0', "rushnorthwest", "rush northwest (screen upper left)",
-            do_rush_northwest, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_rush_northwest, MOVEMENTCMD, NULL },
     { '\0', "rushnorth", "rush north (screen up)",
-            do_rush_north, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_rush_north, MOVEMENTCMD, NULL },
     { '\0', "rushnortheast", "rush northeast (screen upper right)",
-            do_rush_northeast, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_rush_northeast, MOVEMENTCMD, NULL },
     { '\0', "rusheast", "rush east (screen right)",
-            do_rush_east, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_rush_east, MOVEMENTCMD, NULL },
     { '\0', "rushsoutheast", "rush southeast (screen lower right)",
-            do_rush_southeast, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_rush_southeast, MOVEMENTCMD, NULL },
     { '\0', "rushsouth", "rush south (screen down)",
-            do_rush_south, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_rush_south, MOVEMENTCMD, NULL },
     { '\0', "rushsouthwest", "rush southwest (screen lower left)",
-            do_rush_southwest, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_rush_southwest, MOVEMENTCMD, NULL },
     /* run */
     { '\0', "runwest", "run west (screen left)",
-            do_run_west, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_run_west, MOVEMENTCMD, NULL },
     { '\0', "runnorthwest", "run northwest (screen upper left)",
-            do_run_northwest, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_run_northwest, MOVEMENTCMD, NULL },
     { '\0', "runnorth", "run north (screen up)",
-            do_run_north, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_run_north, MOVEMENTCMD, NULL },
     { '\0', "runnortheast", "run northeast (screen upper right)",
-            do_run_northeast, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_run_northeast, MOVEMENTCMD, NULL },
     { '\0', "runeast", "run east (screen right)",
-            do_run_east, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_run_east, MOVEMENTCMD, NULL },
     { '\0', "runsoutheast", "run southeast (screen lower right)",
-            do_run_southeast, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_run_southeast, MOVEMENTCMD, NULL },
     { '\0', "runsouth", "run south (screen down)",
-            do_run_south, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_run_south, MOVEMENTCMD, NULL },
     { '\0', "runsouthwest", "run southwest (screen lower left)",
-            do_run_southwest, MOVEMENTCMD | CMD_M_PREFIX, NULL },
+            do_run_southwest, MOVEMENTCMD, NULL },
 
     /* internal commands: only used by game core, not available for user */
     { '\0',   "clicklook", NULL, doclicklook, INTERNALCMD, NULL },
@@ -3844,13 +3844,14 @@ rhack(char *cmd)
                 /* can_do_extcmd() already gave a message */
                 reset_cmd_vars();
                 res = ECMD_OK;
-            } else if (prefix_seen && !(tlist->flags & PREFIXCMD)
+            } else if (prefix_seen
+                       && !(tlist->flags & (PREFIXCMD | MOVEMENTCMD))
                        && (!was_m_prefix || !accept_menu_prefix(tlist))) {
                 const char *which;
 
                 /* got prefix previously but this command doesn't accept one */
                 which = (prefix_seen->ef_funct == do_reqmenu)
-                           ? "move or request menu"
+                           ? "move-no-pickup or request-menu"
                            : prefix_seen->ef_txt;
                 pline("The %s command does not accept %s prefix.",
                       tlist->ef_txt, which);
index b6e86c4f1099748f5bb58ccf4e7e4805fc23af68..3f881e3b724a21603fb4d98c22f6c45b7b473e1f 100644 (file)
--- a/src/do.c
+++ b/src/do.c
@@ -981,6 +981,8 @@ dodown(void)
     boolean stairs_down = (stway && !stway->up && !stway->isladder),
             ladder_down = (stway && !stway->up &&  stway->isladder);
 
+    set_move_cmd(DIR_DOWN, 0);
+
     if (u_rooted())
         return ECMD_TIME;
 
@@ -1051,7 +1053,7 @@ dodown(void)
                     dotrap(trap, TOOKPLUNGE);
             }
         }
-        return ECMD_TIME; /* came out of hiding; might need '>' again to go down */
+        return ECMD_TIME; /* came out of hiding; need '>' again to go down */
     }
 
     if (u.ustuck) {
@@ -1070,7 +1072,6 @@ dodown(void)
         } else if (!trap || !is_hole(trap->ttyp)
                    || !Can_fall_thru(&u.uz) || !trap->tseen) {
             if (flags.autodig && !g.context.nopick && uwep && is_pick(uwep)) {
-                u.dz = 1; /* the #down command doesn't call set_move_cmd() */
                 return use_pick_axe2(uwep);
             } else {
                 You_cant("go down here.");
@@ -1121,8 +1122,6 @@ 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;
@@ -1136,6 +1135,8 @@ doup(void)
 {
     stairway *stway = stairway_at(u.ux,u.uy);
 
+    set_move_cmd(DIR_UP, 0);
+
     if (u_rooted())
         return ECMD_TIME;
 
@@ -1176,7 +1177,6 @@ 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;