]> granicus.if.org Git - nethack/commitdiff
restore getdir simulated mouse click
authorPatR <rankin@nethack.org>
Sun, 10 Jul 2022 13:55:16 +0000 (06:55 -0700)
committerPatR <rankin@nethack.org>
Sun, 10 Jul 2022 13:55:16 +0000 (06:55 -0700)
When getdir is given '_' as a direction, it calls getpos to get a
map location rather than just a direction.  Have getdir()'s caller
explicitly enable that so using '_' for other than #therecmdmenu
doesn't produce a delta that's farther than one step away.

include/flag.h
src/cmd.c

index baa7b797bf3bfc618420a9868761bf6cf7dd8f7b..d41a598f8360f7be7804e3bdbf82a8aab8267002 100644 (file)
@@ -213,6 +213,7 @@ struct instance_flags {
 #define TER_MON    0x08
 #define TER_DETECT 0x10    /* detect_foo magic rather than #terrain */
     boolean getloc_travelmode;
+    int getdir_ok2click;   /* for #therecmdmenu */
     int getloc_click;      /* 0 or CLICK_1 (left) or CLICK_2 (right) */
     int getloc_filter;     /* GFILTER_foo */
     boolean getloc_usemenu;
index 0a3b30724f5c8c38a8a724ef3c11eb19f7726664..78cb793e3777b51612333b731431bb502e45dae7 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -4488,8 +4488,14 @@ getdir(const char *s)
             mod = 0; /* neither CLICK_1 nor CLICK_2 */
         } else {
             /* caller expects simulated click to be relative to hero's spot */
-            u.dx = sgn(cc.x - u.ux);
-            u.dy = sgn(cc.y - u.uy);
+            u.dx = cc.x - u.ux;
+            u.dy = cc.y - u.uy;
+            /* getdir_ok2click actually means ok to click farther than
+               one spot away from hero; adjacent click is always allowed */
+            if (!iflags.getdir_ok2click) {
+                u.dx = sgn(u.dx);
+                u.dy = sgn(u.dy);
+            }
             u.dz = 0;
 
             switch (pos + NHKF_GETPOS_PICK) {
@@ -4761,8 +4767,12 @@ static int
 dotherecmdmenu(void)
 {
     char ch;
+    int dir;
 
-    if (!getdir((const char *) 0) || !isok(u.ux + u.dx, u.uy + u.dy))
+    iflags.getdir_ok2click = TRUE;
+    dir = getdir((const char *) 0);
+    iflags.getdir_ok2click = FALSE;
+    if (!dir || !isok(u.ux + u.dx, u.uy + u.dy))
         return ECMD_CANCEL;
 
     if (u.dx || u.dy)
@@ -5042,12 +5052,26 @@ there_cmd_menu_common(
 /* queue up command(s) to perform #therecmdmenu action */
 static void
 act_on_act(
-    int act,        /* action */
-    coordxy dx, coordxy dy) /* delta to adjacent spot (farther for couple of cases) */
+    int act,                /* action */
+    coordxy dx, coordxy dy) /* delta to adjacent spot (farther sometimes) */
 {
     struct obj *otmp;
     int dir;
 
+    /* there_cmd_menu_far() actions use dx,dy differently */
+    switch (act) {
+    case MCMD_THROW_OBJ:
+    case MCMD_TRAVEL:
+    case MCMD_LOOK_AT:
+        /* keep dx,dy as-is */
+        break;
+    default:
+        /* force dx and dy to be +1, 0, or -1 */
+        dx = sgn(dx);
+        dy = sgn(dy);
+        break;
+    }
+
     switch (act) {
     case MCMD_TRAVEL:
         /* FIXME: player has explicilty picked "travel to this location"