From d1c2a37deb44dda8b593eb69b0ba6548c01f390d Mon Sep 17 00:00:00 2001 From: "nethack.allison" Date: Sat, 11 Jan 2003 17:22:58 +0000 Subject: [PATCH] fix buglist entry: menu upon request For "traditional" menu style, pickup and #loot/apply can't accept an 'm' response to bring up a menu upon request when all items involved are of the same class, because the prompt where that response is allowed only gets issued when multiple classes are present. --- doc/Guidebook.mn | 4 ++-- doc/Guidebook.tex | 6 +++--- include/extern.h | 4 ++-- include/flag.h | 2 ++ src/cmd.c | 9 +++++++++ src/invent.c | 7 ++++--- src/pickup.c | 51 ++++++++++++++++++++++++++++++++++++++--------- 7 files changed, 64 insertions(+), 19 deletions(-) diff --git a/doc/Guidebook.mn b/doc/Guidebook.mn index dbbfa859f..a525fddc9 100644 --- a/doc/Guidebook.mn +++ b/doc/Guidebook.mn @@ -5,7 +5,7 @@ .ds vr "NetHack 3.4 .ds f0 "\*(vr .ds f1 -.ds f2 "December 17, 2002 +.ds f2 "January 11, 2003 .mt A Guide to the Mazes of Menace (Guidebook for NetHack) @@ -630,7 +630,7 @@ Look at what is here. .lp ; Show what type of thing a visible symbol corresponds to. .lp , -Pick up some things. +Pick up some things. May be preceded by `m' to force a selection menu. .lp @ Toggle the .op autopickup diff --git a/doc/Guidebook.tex b/doc/Guidebook.tex index 4003d5358..5bb50e173 100644 --- a/doc/Guidebook.tex +++ b/doc/Guidebook.tex @@ -27,7 +27,7 @@ \begin{document} % % input file: guidebook.mn -% $Revision: 1.58 $ $Date: 2002/10/31 08:39:11 $ +% $Revision: 1.59 $ $Date: 2002/12/17 11:19:45 $ % %.ds h0 " %.ds h1 %.ds h2 \% @@ -40,7 +40,7 @@ %.au \author{Eric S. Raymond\\ (Extensively edited and expanded for 3.4)} -\date{December 17, 2002} +\date{January 11, 2003} \maketitle @@ -835,7 +835,7 @@ Look at what is here. Show what type of thing a visible symbol corresponds to. %.lp \item[\tb{,}] -Pick up some things. +Pick up some things. May be preceded by `{\tt m}' to force a selection menu. %.lp \item[\tb{@}] Toggle the {\it autopickup\/} option on and off. diff --git a/include/extern.h b/include/extern.h index 9385f41d4..c5dcad1d7 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1444,10 +1444,10 @@ E void NDECL(getlock); #ifdef GOLDOBJ E int FDECL(collect_obj_classes, - (char *,struct obj *,BOOLEAN_P,boolean FDECL((*),(OBJ_P)))); + (char *,struct obj *,BOOLEAN_P,boolean FDECL((*),(OBJ_P)), int *)); #else E int FDECL(collect_obj_classes, - (char *,struct obj *,BOOLEAN_P,BOOLEAN_P,boolean FDECL((*),(OBJ_P)))); + (char *,struct obj *,BOOLEAN_P,BOOLEAN_P,boolean FDECL((*),(OBJ_P)), int *)); #endif E void FDECL(add_valid_menu_class, (int)); E boolean FDECL(allow_all, (struct obj *)); diff --git a/include/flag.h b/include/flag.h index 11b746d1d..badbd7df2 100644 --- a/include/flag.h +++ b/include/flag.h @@ -165,6 +165,8 @@ struct instance_flags { boolean window_inited; /* true if init_nhwindows() completed */ boolean vision_inited; /* true if vision is ready */ boolean menu_tab_sep; /* Use tabs to separate option menu fields */ + boolean menu_requested; /* Flag for overloaded use of 'm' prefix + * on some non-move commands */ int purge_monsters; /* # of dead monsters still on fmon list */ int *opt_booldup; /* for duplication of boolean opts in config file */ int *opt_compdup; /* for duplication of compound opts in config file */ diff --git a/src/cmd.c b/src/cmd.c index 4ec409001..c84d92d8d 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -1753,6 +1753,7 @@ register char *cmd; boolean do_walk, do_rush, prefix_seen, bad_command, firsttime = (cmd == 0); + iflags.menu_requested = FALSE; if (firsttime) { flags.nopick = 0; cmd = parse(); @@ -1850,6 +1851,14 @@ register char *cmd; } break; } + + /* some special prefix handling */ + /* overload 'm' prefix for ',' to mean "request a menu" */ + if (prefix_seen && cmd[1] == ',') { + iflags.menu_requested = TRUE; + ++cmd; + } + if (do_walk) { if (multi) flags.mv = TRUE; domove(); diff --git a/src/invent.c b/src/invent.c index a762d1da7..e1e965b0e 100644 --- a/src/invent.c +++ b/src/invent.c @@ -1136,6 +1136,7 @@ unsigned *resultflags; int FDECL((*ckfn),(OBJ_P)) = (int FDECL((*),(OBJ_P))) 0; boolean FDECL((*filter),(OBJ_P)) = (boolean FDECL((*),(OBJ_P))) 0; boolean takeoff, ident, allflag, m_seen; + int itemcount; #ifndef GOLDOBJ int oletct, iletct, allowgold, unpaid, oc_of_sym; #else @@ -1172,7 +1173,7 @@ unsigned *resultflags; #ifndef GOLDOBJ (allowgold != 0), #endif - filter); + filter, &itemcount); unpaid = count_unpaid(invent); if (ident && !iletct) { @@ -1928,7 +1929,7 @@ dotypeinv() char c = '\0'; int n, i = 0; char *extra_types, types[BUFSZ]; - int class_count, oclass, unpaid_count; + int class_count, oclass, unpaid_count, itemcount; boolean billx = *u.ushops && doinvbill(0); menu_item *pick_list; boolean traditional = TRUE; @@ -1963,7 +1964,7 @@ dotypeinv() #ifndef GOLDOBJ (u.ugold != 0), #endif - (boolean FDECL((*),(OBJ_P))) 0); + (boolean FDECL((*),(OBJ_P))) 0, &itemcount); if (unpaid_count) { Strcat(types, "u"); class_count++; diff --git a/src/pickup.c b/src/pickup.c index 22648343c..b90a4853d 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -87,23 +87,26 @@ boolean here; /* flag for type of obj list linkage */ #ifndef GOLDOBJ int -collect_obj_classes(ilets, otmp, here, incl_gold, filter) +collect_obj_classes(ilets, otmp, here, incl_gold, filter, itemcount) char ilets[]; register struct obj *otmp; boolean here, incl_gold; boolean FDECL((*filter),(OBJ_P)); +int *itemcount; #else int -collect_obj_classes(ilets, otmp, here, filter) +collect_obj_classes(ilets, otmp, here, filter, itemcount) char ilets[]; register struct obj *otmp; boolean here; boolean FDECL((*filter),(OBJ_P)); +int *itemcount; #endif { register int iletct = 0; register char c; + *itemcount = 0; #ifndef GOLDOBJ if (incl_gold) ilets[iletct++] = def_oc_syms[COIN_CLASS]; @@ -113,6 +116,7 @@ boolean FDECL((*filter),(OBJ_P)); c = def_oc_syms[(int)otmp->oclass]; if (!index(ilets, c) && (!filter || (*filter)(otmp))) ilets[iletct++] = c, ilets[iletct] = '\0'; + *itemcount += 1; otmp = here ? otmp->nexthere : otmp->nobj; } @@ -158,6 +162,7 @@ int *menu_on_demand; boolean not_everything; char qbuf[QBUFSZ]; boolean m_seen; + int itemcount; oclasses[oclassct = 0] = '\0'; *one_at_a_time = *everything = m_seen = FALSE; @@ -165,12 +170,17 @@ int *menu_on_demand; #ifndef GOLDOBJ incl_gold, #endif - (boolean FDECL((*),(OBJ_P))) 0); + (boolean FDECL((*),(OBJ_P))) 0, &itemcount); if (iletct == 0) { return FALSE; } else if (iletct == 1) { oclasses[0] = def_char_to_objclass(ilets[0]); oclasses[1] = '\0'; + if (itemcount && menu_on_demand) { + ilets[iletct++] = 'm'; + *menu_on_demand = 0; + ilets[iletct] = '\0'; + } } else { /* more than one choice available */ const char *where = 0; register char sym, oc_of_sym, *p; @@ -438,9 +448,9 @@ int what; /* should be a long */ goto menu_pickup; } - if (flags.menu_style != MENU_TRADITIONAL) { - /* use menus exclusively */ + if (flags.menu_style != MENU_TRADITIONAL || iflags.menu_requested) { + /* use menus exclusively */ if (count) { /* looking for N of something */ char buf[QBUFSZ]; Sprintf(buf, "Pick %d of what?", count); @@ -1906,7 +1916,7 @@ register int held; struct monst *shkp; boolean one_by_one, allflag, loot_out = FALSE, loot_in = FALSE; char select[MAXOCLASSES+1]; - char qbuf[BUFSZ], emptymsg[BUFSZ]; + char qbuf[BUFSZ], emptymsg[BUFSZ], pbuf[QBUFSZ]; long loss = 0L; int cnt = 0, used = 0, lcnt = 0, menu_on_request; @@ -2040,7 +2050,9 @@ register int held; ask_again2: menu_on_request = 0; add_valid_menu_class(0); /* reset */ - switch (yn_function(qbuf, ":ynq", 'n')) { + Strcpy(pbuf, ":ynq"); + if (cnt) Strcat(pbuf, "m"); + switch (yn_function(qbuf, pbuf, 'n')) { case ':': container_contents(current_container, FALSE, FALSE); goto ask_again2; @@ -2065,6 +2077,10 @@ ask_again2: /*FALLTHRU*/ case 'n': break; + case 'm': + menu_on_request = -2; /* triggers ALL_CLASSES */ + used |= menu_loot(menu_on_request, current_container, FALSE) > 0; + break; case 'q': default: return used; @@ -2084,8 +2100,25 @@ ask_again2: return used; } if (flags.menu_style != MENU_FULL) { - loot_in = (yn_function("Do you wish to put something in?", - ynqchars, 'n') == 'y'); + Sprintf(qbuf, "Do you wish to put %s in?", something); + Strcpy(pbuf, ynqchars); + if (flags.menu_style == MENU_TRADITIONAL && invent && inv_cnt() > 0) + Strcat(pbuf, "m"); + switch (yn_function(qbuf, pbuf, 'n')) { + case 'y': + loot_in = TRUE; + break; + case 'n': + break; + case 'm': + add_valid_menu_class(0); /* reset */ + menu_on_request = -2; /* triggers ALL_CLASSES */ + used |= menu_loot(menu_on_request, current_container, TRUE) > 0; + break; + case 'q': + default: + return used; + } } /* * Gone: being nice about only selecting food if we know we are