]> granicus.if.org Git - nethack/commitdiff
new command '`' to show discoveries for one class (trunk only)
authornethack.rankin <nethack.rankin>
Thu, 15 Sep 2011 04:16:29 +0000 (04:16 +0000)
committernethack.rankin <nethack.rankin>
Thu, 15 Sep 2011 04:16:29 +0000 (04:16 +0000)
     Use the grave accent (back tick) character as the keystroke for a
new command which prompts for an object class and then shows a subset of
the discovered objects list covering just the selected class.  Similar
to the 'I' variant of 'i' for viewing inventory, and mainly useful once
the '\' discoveries list has grown long.

dat/cmdhelp
dat/help
dat/hh
doc/Guidebook.mn
doc/Guidebook.tex
doc/fixes35.0
include/extern.h
src/artifact.c
src/cmd.c
src/invent.c
src/o_init.c

index b47beb84c41fcacf301de456d81b921ee0d5ae13..811c9bdda762977b949efae14b8ac2f768946fa4 100644 (file)
@@ -82,6 +82,7 @@ Z       Zap (cast) a spell
 &       Tell what a command does
 !       Do a shell escape (only if defined)
 \       Show what object types have been discovered
+`       Show discovered types for one class of objects
 _       Travel via a shortest-path algorithm to a point on the map 
 .       Rest one move while doing nothing
         Rest one move while doing nothing (if rest_on_space option is on)
index 28f681440a75d669de584bd2be9c39825f975d87..7f9ee92abc922bd71c12d89623133515167ab1ca 100644 (file)
--- a/dat/help
+++ b/dat/help
@@ -166,6 +166,7 @@ Commands:
         $       Count your gold pieces.
         +       List the spells you know; also rearrange them if desired.
         \       Show what types of objects have been discovered.
+        `       Show discovered types for one class of objects.
         !       Escape to a shell, if supported in your version and OS.
         #       Introduces one of the "extended" commands.  To get a list of
                 the commands you can use with "#" type "#?".  The extended
diff --git a/dat/hh b/dat/hh
index 75a11f0b243f93ac5aba37ab0284549a2aa35b98..1887547c70ce437c7c4625ca70437c029193f8e5 100644 (file)
--- a/dat/hh
+++ b/dat/hh
@@ -79,6 +79,7 @@ Z       Zap     cast a spell  (use Y instead of Z if number_pad is -1)
 *               ask for combination of ),[,=,",( all at once
 $       gold    count your gold
 +       spells  list the spells you know; also rearrange them if desired
+`       classkn display known items for one class of objects
 _       travel  move via a shortest-path algorithm to a point on the map 
 .       rest    wait a moment
 ,       pickup  pick up all you can carry
index 6a654a2fddbf121cd5d457a9de2cf2d9d6c6d61a..218ad18658b69dba0c1e678a9151eacb83ffec02 100644 (file)
@@ -5,7 +5,7 @@
 .ds vr "NetHack 3.5
 .ds f0 "\*(vr
 .ds f1
-.ds f2 "April 17, 2011
+.ds f2 "September 14, 2011
 .\" labeled paragraph start (should be part of tmac.n, but I don't want to
 .\" make changes to that file)
 .\" .PS word
@@ -767,6 +767,8 @@ be added to the end of the list rather than be inserted into the sorted
 ordering.)
 .lp "\e
 Show what types of objects have been discovered.
+.lp `
+Show discovered types for one class of objects.
 .lp !
 Escape to a shell.
 .lp #
index 6b235f2e867697d60e2c6d84a0cfba74fa1a7503..93fe2794bc53a2bf78ea145ca1bf03a7c9731907 100644 (file)
@@ -33,7 +33,7 @@
 \begin{document}
 %
 % input file: guidebook.mn
-% $Revision: 1.115 $ $Date: 2011/04/24 21:12:06 $
+% $Revision: 1.116 $ $Date: 2011/04/25 03:29:41 $
 %
 %.ds h0 "
 %.ds h1 %.ds h2 \%
@@ -46,7 +46,7 @@
 %.au
 \author{Eric S. Raymond\\
 (Extensively edited and expanded for 3.5)}
-\date{April 17, 2011}
+\date{September 14, 2011}
 
 \maketitle
 
@@ -491,7 +491,7 @@ An amulet or a spider web.
 \item[\tb{*}]
 A gem or rock (possibly valuable, possibly worthless).
 %.lp
-\item[\tb{`}]
+\item[\tb{\`}]
 A boulder or statue.
 %.lp
 \item[\tb{0}]
@@ -957,6 +957,9 @@ ordering.)
 \item[\tb{$\backslash$}]
 Show what types of objects have been discovered.
 %.lp
+\item[\tb{\`}]
+Show discovered types for one class of objects.
+%.lp
 \item[\tb{!}]
 Escape to a shell.
 %.lp
index 771d4d4706fa25dbc20dc013a83316f9a0c14041..f55f7780bd419d5bc6e9f48c0617a4ad036b4b78 100644 (file)
@@ -522,6 +522,7 @@ adopt/adapt/improve the Paranoid_Quit patch; default is paranoid_confirm:pray
 flexibility for specifying "detect <foo>" vs "<foo> detection" when wishing
 when a sokoban puzzle has been completed (last pit or hole filled in),
        stop assessing luck penalties and lift most movement restrictions
+'`' command to show discoveries for one class of objects
 
 
 Platform- and/or Interface-Specific New Features
index d029c70d6f2fdb9e05150aade77d5deffd1c7a82..c7fd206e80302349f6c1b42098f828bf862be3fc 100644 (file)
@@ -1538,6 +1538,7 @@ E void FDECL(restnames, (int));
 E void FDECL(discover_object, (int,BOOLEAN_P,BOOLEAN_P));
 E void FDECL(undiscover_object, (int));
 E int NDECL(dodiscovered);
+E int NDECL(doclassdisco);
 E void NDECL(rename_disco);
 
 /* ### objects.c ### */
index 6f3a7aa27b8829be3b1ed8888b0a6658a072da5f..fdfe1de2ec263dc1b004b4d7f7448e678fc5d374 100644 (file)
@@ -835,6 +835,8 @@ winid tmpwin;               /* supplied by dodiscover() */
 
     for (i = 0; i < NROFARTIFACTS; i++) {
        if (artidisco[i] == 0) break;   /* empty slot implies end of list */
+       if (tmpwin == WIN_ERR) continue; /* for WIN_ERR, we just count */
+
        if (i == 0) putstr(tmpwin, iflags.menu_headings, "Artifacts");
        m = artidisco[i];
        otyp = artilist[m].otyp;
index c1ffd7be6905863c5d5735ddc294f89f798ada6c..079b184fe600f215c16552309d1e413a802096eb 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -78,6 +78,7 @@ extern int NDECL(doopen); /**/
 extern int NDECL(doclose); /**/
 extern int NDECL(dosh); /**/
 extern int NDECL(dodiscovered); /**/
+extern int NDECL(doclassdisco); /**/
 extern int NDECL(doset); /**/
 extern int NDECL(dotogglepickup); /**/
 extern int NDECL(dowhatis); /**/
@@ -2261,6 +2262,7 @@ static const struct func_tab cmdlist[] = {
        {';', TRUE, doquickwhatis},
        {'^', TRUE, doidtrap},
        {'\\', TRUE, dodiscovered},             /* Robert Viduya */
+       {'`', TRUE, doclassdisco},
        {'@', TRUE, dotogglepickup},
        {M('2'), FALSE, dotwoweapon},
        {WEAPON_SYM,  TRUE, doprwep},
index cc5f4e1800832f8e6c287c3602a39b458c770474..9d2ca7dbd25c33cca013632cee9cb2b6eb0a697d 100644 (file)
@@ -1,5 +1,4 @@
 /* NetHack 3.5 invent.c        $Date$  $Revision$ */
-/*     SCCS Id: @(#)invent.c   3.5     2008/10/19      */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -2859,7 +2858,7 @@ long numused;
 STATIC_VAR NEARDATA const char *names[] = { 0,
        "Illegal objects", "Weapons", "Armor", "Rings", "Amulets",
        "Tools", "Comestibles", "Potions", "Scrolls", "Spellbooks",
-       "Wands", "Coins", "Gems", "Boulders/Statues", "Iron balls",
+       "Wands", "Coins", "Gems/Stones", "Boulders/Statues", "Iron balls",
        "Chains", "Venoms"
 };
 
index ad13cf07388756c1816f796b130bbc9cf659af02..d078707dbea37b200b5f9c110eef92cccd79f4cc 100644 (file)
@@ -1,5 +1,4 @@
 /* NetHack 3.5 o_init.c        $Date$  $Revision$ */
-/*     SCCS Id: @(#)o_init.c   3.5     2007/05/21      */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -10,7 +9,7 @@ STATIC_DCL void FDECL(setgemprobs, (d_level*));
 STATIC_DCL void FDECL(shuffle,(int,int,BOOLEAN_P));
 STATIC_DCL void NDECL(shuffle_all);
 STATIC_DCL boolean FDECL(interesting_to_discover,(int));
-
+STATIC_DCL char *FDECL(oclass_to_name, (CHAR_P,char *));
 
 static NEARDATA short disco[NUM_OBJECTS] = DUMMY;
 
@@ -404,6 +403,7 @@ static short uniq_objs[] = {
        BELL_OF_OPENING,
 };
 
+/* the '\' command - show discovered object types */
 int
 dodiscovered()                         /* free after Robert Viduya */
 {
@@ -421,7 +421,7 @@ dodiscovered()                              /* free after Robert Viduya */
     for (i = dis = 0; i < SIZE(uniq_objs); i++)
        if (objects[uniq_objs[i]].oc_name_known) {
            if (!dis++)
-               putstr(tmpwin, iflags.menu_headings, "Unique Items");
+               putstr(tmpwin, iflags.menu_headings, "Unique items");
                Sprintf(buf, "  %s", OBJ_NAME(objects[uniq_objs[i]]));
            putstr(tmpwin, 0, buf);
            ++ct;
@@ -463,6 +463,179 @@ dodiscovered()                            /* free after Robert Viduya */
     return 0;
 }
 
+/* lower case let_to_name() output, which differs from def_oc_syms[].name */
+STATIC_OVL char *
+oclass_to_name(oclass, buf)
+char oclass;
+char *buf;
+{
+    char *s;
+
+    Strcpy(buf, let_to_name(oclass, FALSE));
+    for (s = buf; *s; ++s) *s = lowc(*s);
+    return buf;
+}
+
+/* the '`' command - show discovered object types for one class */
+int
+doclassdisco()
+{
+    static NEARDATA const char
+       prompt[] = "View discoveries for which sort of objects?",
+       havent_discovered_any[] = "haven't discovered any %s yet.",
+       unique_items[] = "unique items", artifact_items[] = "artifacts";
+    char *s, c, oclass, menulet,
+       allclasses[MAXOCLASSES], discosyms[2+MAXOCLASSES+1], buf[BUFSZ];
+    int i, ct, dis, xtras;
+    boolean traditional;
+    winid tmpwin;
+    anything any;
+    menu_item *pick_list = 0;
+
+    discosyms[0] = '\0';
+    traditional = (flags.menu_style == MENU_TRADITIONAL ||
+                  flags.menu_style == MENU_COMBINATION);
+    tmpwin = !traditional ? create_nhwindow(NHW_MENU) : WIN_ERR;
+    any = zeroany;
+    menulet = 'a';
+
+    /* check whether we've discovered any unique objects */
+    for (i = 0; i < SIZE(uniq_objs); i++)
+       if (objects[uniq_objs[i]].oc_name_known) {
+           Strcat(discosyms, "u");
+           if (!traditional) {
+               any.a_int = 'u';
+               add_menu(tmpwin, NO_GLYPH, &any, menulet++, 0, ATR_NONE,
+                        unique_items, MENU_UNSELECTED);
+           }
+           break;
+       }
+
+    /* check whether we've discovered any artifacts */
+    if (disp_artifact_discoveries(WIN_ERR) > 0) {
+       Strcat(discosyms, "a");
+       if (!traditional) {
+           any.a_int = 'a';
+           add_menu(tmpwin, NO_GLYPH, &any, menulet++, 0, ATR_NONE,
+                    artifact_items, MENU_UNSELECTED);
+       }
+    }
+
+    /* collect classes with discoveries, in packorder ordering; several
+       classes are omitted from packorder and one is of interest here */
+    Strcpy(allclasses, flags.inv_order);
+    if (!index(allclasses, VENOM_CLASS))
+       Sprintf(eos(allclasses), "%c", VENOM_CLASS);
+    /* construct discosyms[] */
+    for (s = allclasses; *s; ++s) {
+       oclass = *s;
+       c = def_oc_syms[oclass].sym;
+       for (i = bases[(int)oclass];
+               i < NUM_OBJECTS && objects[i].oc_class == oclass; ++i)
+           if ((dis = disco[i]) != 0 && interesting_to_discover(dis)) {
+               if (!index(discosyms, c)) {
+                   Sprintf(eos(discosyms), "%c", c);
+                   if (!traditional) {
+                       any.a_int = c;
+                       add_menu(tmpwin, NO_GLYPH, &any,
+                                menulet++, c, ATR_NONE,
+                                oclass_to_name(oclass, buf), MENU_UNSELECTED);
+                   }
+               }
+           }
+    }
+
+    /* there might not be anything for us to do... */
+    if (!discosyms[0]) {
+       You(havent_discovered_any, "items");
+       if (tmpwin != WIN_ERR) destroy_nhwindow(tmpwin);
+       return 0;
+    }
+
+    /* have player choose a class */
+    c = '\0';  /* class not chosen yet */
+    if (traditional) {
+       /* we'll prompt even if there's only one viable class; we add all
+          nonviable classes as unseen acceptable choices so player can ask
+          for discoveries of any class whether it has discoveries or not */
+       for (s = allclasses, xtras = 0; *s; ++s) {
+           c = def_oc_syms[*s].sym;
+           if (!index(discosyms, c)) {
+               if (!xtras++) Sprintf(eos(discosyms), "%c", '\033');
+               Sprintf(eos(discosyms), "%c", c);
+           }
+       }
+       /* get the class (via its symbol character) */
+       c = yn_function(prompt, discosyms, '\0');
+#ifdef REDO
+       savech(c);
+#endif
+       if (!c)
+           clear_nhwindow(WIN_MESSAGE);
+    } else {
+       /* menustyle:full or menustyle:partial */
+       if (!discosyms[1] && flags.menu_style == MENU_PARTIAL) {
+           /* only one class; menustyle:partial normally jumps past class
+              filtering straight to final menu so skip class filter here */
+           c = discosyms[0];
+       } else {
+           /* more than one choice, or menustyle:full which normally has
+              an intermediate class selection menu before the final menu */
+           end_menu(tmpwin, prompt);
+           i = select_menu(tmpwin, PICK_ONE, &pick_list);
+           if (i > 0) {
+               c = pick_list[0].item.a_int;
+               free((genericptr_t) pick_list);
+           } /* else c stays 0 */
+       }
+       destroy_nhwindow(tmpwin);
+    }
+    if (!c) return 0;          /* player declined to make a selection */
+
+    /*
+     * show discoveries for object class c
+     */
+    tmpwin = create_nhwindow(NHW_MENU);
+    ct = 0;
+    switch (c) {
+    case 'u':
+       putstr(tmpwin, iflags.menu_headings,
+              upstart(strcpy(buf, unique_items)));
+       for (i = 0; i < SIZE(uniq_objs); i++)
+           if (objects[uniq_objs[i]].oc_name_known) {
+               Sprintf(buf, "  %s", OBJ_NAME(objects[uniq_objs[i]]));
+               putstr(tmpwin, 0, buf);
+               ++ct;
+           }
+       if (!ct) You(havent_discovered_any, unique_items);
+       break;
+    case 'a':
+       /* disp_artifact_discoveries() includes a header */
+       ct = disp_artifact_discoveries(tmpwin);
+       if (!ct) You(havent_discovered_any, artifact_items);
+       break;
+    default:
+       oclass = def_char_to_objclass(c);
+       Sprintf(buf, "Discovered %s", let_to_name(oclass, FALSE));
+       putstr(tmpwin, iflags.menu_headings, buf);
+       for (i = bases[(int)oclass];
+               i < NUM_OBJECTS && objects[i].oc_class == oclass; ++i) {
+           if ((dis = disco[i]) != 0 && interesting_to_discover(dis)) {
+               Sprintf(buf, "%s %s",
+                       objects[dis].oc_pre_discovered ? "*" : " ",
+                       obj_typename(dis));
+               putstr(tmpwin, 0, buf);
+               ++ct;
+           }
+       }
+       if (!ct) You(havent_discovered_any, oclass_to_name(oclass, buf));
+       break;
+    }
+    if (ct) display_nhwindow(tmpwin, TRUE);
+    destroy_nhwindow(tmpwin);
+    return 0;
+}
+
 /* put up nameable subset of discoveries list as a menu */
 void
 rename_disco()