]> granicus.if.org Git - nethack/commitdiff
menu loot suggestion from newsgroup
authornethack.allison <nethack.allison>
Wed, 4 Sep 2002 01:31:20 +0000 (01:31 +0000)
committernethack.allison <nethack.allison>
Wed, 4 Sep 2002 01:31:20 +0000 (01:31 +0000)
Newsgroups: rec.games.roguelike.nethack
Subject: Re: YANI - empty containers interface
<email deleted>
On Mon, 2 Sep 2002 12:13:49 +0300, <email deleted> wrote:
> I find the behaviour when trying to put something in an empty container
> quite irritating. Let's remind it:
> #loot
> "The <container> is empty. Do you want to put something in it? (y/n)"
> This means I have to read the message and to press 'y' or to cancel via
> Esc.
> For comparison, non-empty containers behave like this - please forgive
> me that I've forgotten the exact words:
> #loot
> "Do what?
>  o - take out
>  i - put in
>  b - both of the above"
> So my suggestion is to change the behaviour of empty containers to be
> the same as non-empty ones. That is:
> #loot
> "Do what?
>  i - put in"
> This way, I don't have to look at the container. If I want to put
> something in, pressing 'i' will lead to the same results in both cases.

This part of the suggestion was not implemented, however:

> If I want to take something out, then pressing 'o' or 'b' - although
> they are not in the list of choices - will display a message "This
><container> is empty" and end the #loot-ing session.

src/pickup.c

index 1df2f4353eb934449b0c4507537fc4671be36d25..c52538f02a69e65ff5af3f65fb0da26a6259047d 100644 (file)
@@ -32,7 +32,7 @@ STATIC_PTR int FDECL(in_container,(struct obj *));
 STATIC_PTR int FDECL(ck_bag,(struct obj *));
 STATIC_PTR int FDECL(out_container,(struct obj *));
 STATIC_DCL int FDECL(menu_loot, (int, struct obj *, BOOLEAN_P));
-STATIC_DCL int FDECL(in_or_out_menu, (const char *,struct obj *));
+STATIC_DCL int FDECL(in_or_out_menu, (const char *,struct obj *, BOOLEAN_P, BOOLEAN_P));
 STATIC_DCL int FDECL(container_at, (int, int, BOOLEAN_P));
 STATIC_DCL boolean FDECL(able_to_loot, (int, int));
 STATIC_DCL boolean FDECL(mon_beside, (int, int));
@@ -1911,11 +1911,12 @@ register int held;
        struct monst *shkp;
        boolean one_by_one, allflag, loot_out = FALSE, loot_in = FALSE;
        char select[MAXOCLASSES+1];
-       char qbuf[QBUFSZ];
+       char qbuf[QBUFSZ], emptymsg[QBUFSZ];
        long loss = 0L;
        int cnt = 0, used = 0, lcnt = 0,
            menu_on_request;
 
+       emptymsg[0] = '\0';
        if (obj->olocked) {
            pline("%s to be locked.", Tobjnam(obj, "seem"));
            if (held) You("must put it down to unlock.");
@@ -2003,14 +2004,20 @@ register int held;
 
        obj->owt = weight(obj);
 
-       if (!cnt) {
-           pline("%s %s empty.", Yname2(obj), otense(obj, "are"));
-       } else {
+       if (!cnt) Sprintf(emptymsg, "%s %s empty.", Yname2(obj), otense(obj, "are"));
+       if (cnt || flags.menu_style == MENU_FULL) {
            Sprintf(qbuf, "Do you want to take %s out of %s?",
                    something, yname(obj));
            if (flags.menu_style != MENU_TRADITIONAL) {
                if (flags.menu_style == MENU_FULL) {
-                   int t = in_or_out_menu("Do what?", current_container);
+                   int t;
+                   char menuprompt[QBUFSZ];
+                   boolean outokay = (cnt != 0);
+                   boolean inokay = (invent != 0);
+                   menuprompt[0] = '\0';
+                   if (!cnt) Sprintf(menuprompt, "%s ", emptymsg);
+                   Strcat(menuprompt, "Do what?");
+                   t = in_or_out_menu(menuprompt, current_container, outokay, inokay);
                    if (t <= 0) return 0;
                    loot_out = (t & 0x01) != 0;
                    loot_in  = (t & 0x02) != 0;
@@ -2056,6 +2063,8 @@ ask_again2:
                    return used;
                }
            }
+       } else {
+           pline("%s", emptymsg);              /* <whatever> is empty. */
        }
 
 #ifndef GOLDOBJ
@@ -2067,7 +2076,7 @@ ask_again2:
            You("don't have anything to put in.");
            return used;
        }
-       if (flags.menu_style != MENU_FULL || !cnt) {
+       if (flags.menu_style != MENU_FULL) {
            loot_in = (yn_function("Do you wish to put something in?",
                                   ynqchars, 'n') == 'y');
        }
@@ -2200,9 +2209,10 @@ boolean put_in;
 }
 
 STATIC_OVL int
-in_or_out_menu(prompt, obj)
+in_or_out_menu(prompt, obj, outokay, inokay)
 const char *prompt;
 struct obj *obj;
+boolean outokay, inokay;
 {
     winid win;
     anything any;
@@ -2214,15 +2224,24 @@ struct obj *obj;
     any.a_void = 0;
     win = create_nhwindow(NHW_MENU);
     start_menu(win);
-    any.a_int = 1;
-    Sprintf(buf,"Take %s out of %s", something, the(xname(obj)));
-    add_menu(win, NO_GLYPH, &any, *menuselector++, 0, ATR_NONE, buf, MENU_UNSELECTED);
-    any.a_int = 2;
-    Sprintf(buf,"Put %s into %s", something, the(xname(obj)));
-    add_menu(win, NO_GLYPH, &any, *menuselector++, 0, ATR_NONE, buf, MENU_UNSELECTED);
-    any.a_int = 3;
-    add_menu(win, NO_GLYPH, &any, *menuselector, 0, ATR_NONE,
-               "Both of the above", MENU_UNSELECTED);
+    if (outokay) {
+       any.a_int = 1;
+       Sprintf(buf,"Take %s out of %s", something, the(xname(obj)));
+       add_menu(win, NO_GLYPH, &any, *menuselector, 0, ATR_NONE,
+                       buf, MENU_UNSELECTED);
+    }
+    menuselector++;
+    if (inokay) {
+       any.a_int = 2;
+       Sprintf(buf,"Put %s into %s", something, the(xname(obj)));
+       add_menu(win, NO_GLYPH, &any, *menuselector, 0, ATR_NONE, buf, MENU_UNSELECTED);
+    }
+    menuselector++;
+    if (outokay && inokay) {
+       any.a_int = 3;
+       add_menu(win, NO_GLYPH, &any, *menuselector, 0, ATR_NONE,
+                       "Both of the above", MENU_UNSELECTED);
+    }
     end_menu(win, prompt);
     n = select_menu(win, PICK_ONE, &pick_list);
     destroy_nhwindow(win);