X Tutup
Skip to content

Commit 00c4e83

Browse files
author
PatR
committed
click_to_cmd() vs #therecmdmenu
Clicking on an adjacent location while 'herecmd_menu' is On didn't run therecmd as intended. If it had, maybe somebody would have noticed how broken it is. This reorganizes the mouse click handling but leaves therecmd commented out since it hasn't been fixed. The #therecmdmenu command and tentative click handling for adjacent spots should probably be removed. They've been in place for slightly over three years and nobody has ever reported that they don't work properly.
1 parent d27b8cb commit 00c4e83

File tree

1 file changed

+38
-18
lines changed

1 file changed

+38
-18
lines changed

src/cmd.c

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* NetHack 3.7 cmd.c $NHDT-Date: 1608175318 2020/12/17 03:21:58 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.436 $ */
1+
/* NetHack 3.7 cmd.c $NHDT-Date: 1608233885 2020/12/17 19:38:05 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.437 $ */
22
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
33
/*-Copyright (c) Robert Patrick Rankin, 2013. */
44
/* NetHack may be freely redistributed. See license for details. */
@@ -4001,6 +4001,9 @@ const char *text;
40014001
}
40024002
}
40034003

4004+
/* offer choice of actions to perform at adjacent location <x,y>;
4005+
does not work as intended because the actions that get invoked
4006+
ask for a direction or target instead of using our <x,y> */
40044007
static char
40054008
there_cmd_menu(doit, x, y)
40064009
boolean doit;
@@ -4074,6 +4077,18 @@ int x, y;
40744077
add_herecmd_menuitem(win, doapply, buf);
40754078
}
40764079
#if 0
4080+
if (mtmp) {
4081+
Sprintf(buf, "%s %s", mon_nam(mtmp),
4082+
!has_mname(mtmp) ? "Name" : "Rename"), ++K;
4083+
/* need a way to pass mtmp or <ux+dx,uy+dy>to an 'int f()' function
4084+
as well as reorganizinging do_mname() to use that function */
4085+
add_herecmd_menuitem(win, XXX(), buf);
4086+
}
4087+
#endif
4088+
#if 0
4089+
/* these are necessary if click_to_cmd() is deferring to us; however,
4090+
moving/fighting aren't implmented as independent commands so don't
4091+
fit our menu's use of command functions */
40774092
if (mtmp || glyph_is_invisible(glyph_at(x, y))) {
40784093
/* "Attack %s", mtmp ? mon_nam(mtmp) : "unseen creature" */
40794094
} else {
@@ -4089,7 +4104,7 @@ int x, y;
40894104
npick = 0;
40904105
}
40914106
destroy_nhwindow(win);
4092-
ch = '\0';
4107+
ch = '\033';
40934108
if (npick > 0) {
40944109
int NDECL((*func)) = picks->item.a_nfunc;
40954110
free((genericptr_t) picks);
@@ -4183,7 +4198,7 @@ boolean doit;
41834198
end_menu(win, "What do you want to do?");
41844199
npick = select_menu(win, PICK_ONE, &picks);
41854200
destroy_nhwindow(win);
4186-
ch = '\0';
4201+
ch = '\033';
41874202
if (npick > 0) {
41884203
int NDECL((*func)) = picks->item.a_nfunc;
41894204
free((genericptr_t) picks);
@@ -4208,16 +4223,33 @@ int x, y, mod;
42084223
{
42094224
static char cmd[4];
42104225
struct obj *o;
4211-
int dir;
4212-
4213-
cmd[1] = '\0';
4226+
int dir, udist;
42144227

4228+
cmd[0] = cmd[1] = '\0';
42154229
if (iflags.clicklook && mod == CLICK_2) {
42164230
g.clicklook_cc.x = x;
42174231
g.clicklook_cc.y = y;
42184232
cmd[0] = g.Cmd.spkeys[NHKF_CLICKLOOK];
42194233
return cmd;
42204234
}
4235+
/* this used to be inside the 'if (flags.travelcmd)' block, but
4236+
handle click-on-self even when travel is disabled; unlike
4237+
accidentally zooming across the level because of a stray click,
4238+
clicking on self can easily be cancelled if it wasn't intended */
4239+
if (iflags.herecmd_menu && isok(x, y)) {
4240+
udist = distu(x, y);
4241+
if (!udist) {
4242+
cmd[0] = here_cmd_menu(FALSE);
4243+
return cmd;
4244+
} else if (udist <= 2) {
4245+
#if 0 /* there_cmd_menu() is broken; the commands it invokes
4246+
* tend to ask for a direction or target instead of using
4247+
* the adjacent coordinates that are being passed to it */
4248+
cmd[0] = there_cmd_menu(FALSE, x, y);
4249+
return cmd;
4250+
#endif
4251+
}
4252+
}
42214253

42224254
x -= u.ux;
42234255
y -= u.uy;
@@ -4233,11 +4265,6 @@ int x, y, mod;
42334265
}
42344266

42354267
if (x == 0 && y == 0) {
4236-
if (iflags.herecmd_menu) {
4237-
cmd[0] = here_cmd_menu(FALSE);
4238-
return cmd;
4239-
}
4240-
42414268
/* here */
42424269
if (IS_FOUNTAIN(levl[u.ux][u.uy].typ)
42434270
|| IS_SINK(levl[u.ux][u.uy].typ)) {
@@ -4264,17 +4291,10 @@ int x, y, mod;
42644291
/* directional commands */
42654292

42664293
dir = xytod(x, y);
4267-
42684294
if (!m_at(u.ux + x, u.uy + y)
42694295
&& !test_move(u.ux, u.uy, x, y, TEST_MOVE)) {
42704296
cmd[1] = g.Cmd.dirchars[dir];
42714297
cmd[2] = '\0';
4272-
if (iflags.herecmd_menu) {
4273-
cmd[0] = there_cmd_menu(FALSE, u.ux + x, u.uy + y);
4274-
if (cmd[0] == '\0')
4275-
cmd[1] = '\0';
4276-
return cmd;
4277-
}
42784298

42794299
if (IS_DOOR(levl[u.ux + x][u.uy + y].typ)) {
42804300
/* slight assistance to player: choose kick/open for them */

0 commit comments

Comments
 (0)
X Tutup