From: PatR Date: Sun, 10 Jul 2022 13:55:16 +0000 (-0700) Subject: restore getdir simulated mouse click X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6ac5525239110c4509dd4fd893acd999d62981ea;p=nethack restore getdir simulated mouse click 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. --- diff --git a/include/flag.h b/include/flag.h index baa7b797b..d41a598f8 100644 --- a/include/flag.h +++ b/include/flag.h @@ -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; diff --git a/src/cmd.c b/src/cmd.c index 0a3b30724..78cb793e3 100644 --- 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"