]> granicus.if.org Git - nethack/commitdiff
Use a menu to pick a container to tip
authorPasi Kallinen <paxed@alt.org>
Sun, 31 May 2015 07:13:49 +0000 (10:13 +0300)
committerPasi Kallinen <paxed@alt.org>
Sun, 31 May 2015 07:13:53 +0000 (10:13 +0300)
If there is more than one container, the #tip command will show a menu;
if there's just one container, prompt for tipping.

As per Boudewijn's suggestion, remove the superfluous
"There is a container here" message.

src/pickup.c

index ce8c6f49aa29cba7dfc6f5519dbc78f7b8a8353f..7e1fcb0cc0b60439a245821255c0d06f5fc9f0df 100644 (file)
@@ -2688,27 +2688,59 @@ dotip()
 
     /* check floor container(s) first; at most one will be accessed */
     if ((boxes = container_at(cc.x, cc.y, TRUE)) > 0) {
-        if (flags.verbose)
-            pline("There %s here.",
-                  (boxes > 1) ? "are containers" : "is a container");
         Sprintf(buf, "You can't tip %s while carrying so much.",
                 !flags.verbose ? "a container" : (boxes > 1) ? "one" : "it");
         if (!check_capacity(buf) && able_to_loot(cc.x, cc.y, FALSE)) {
-            for (cobj = level.objects[cc.x][cc.y]; cobj; cobj = nobj) {
-                nobj = cobj->nexthere;
-                if (!Is_container(cobj))
-                    continue;
 
-                c = ynq(safe_qbuf(qbuf, "There is ", " here, tip it?", cobj,
-                                  doname, ansimpleoname, "container"));
-                if (c == 'q')
+            if (boxes > 1) {
+                /* use menu to pick a container to tip */
+                int n, i;
+                winid win;
+                anything any;
+                menu_item *pick_list = NULL;
+                any = zeroany;
+                win = create_nhwindow(NHW_MENU);
+                start_menu(win);
+
+                for (cobj = level.objects[cc.x][cc.y]; cobj;
+                     cobj = cobj->nexthere)
+                    if (Is_container(cobj)) {
+                        any.a_obj = cobj;
+                        add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE,
+                                 doname(cobj), MENU_UNSELECTED);
+                    }
+                end_menu(win, "Tip which container?");
+                n = select_menu(win, PICK_ONE, &pick_list);
+                destroy_nhwindow(win);
+
+                if (n > 0) {
+                    for (i = 0; i < n; i++) {
+                        tipcontainer(pick_list[i].item.a_obj);
+                        free((genericptr_t) pick_list);
+                        return 1;
+                    }
+                }
+                if (pick_list)
+                    free((genericptr_t) pick_list);
+                if (n == -1)
                     return 0;
-                if (c == 'n')
-                    continue;
+            } else {
+                for (cobj = level.objects[cc.x][cc.y]; cobj; cobj = nobj) {
+                    nobj = cobj->nexthere;
+                    if (!Is_container(cobj))
+                        continue;
 
-                tipcontainer(cobj);
-                return 1;
-            } /* next cobj */
+                    c = ynq(safe_qbuf(qbuf, "There is ", " here, tip it?", cobj,
+                                      doname, ansimpleoname, "container"));
+                    if (c == 'q')
+                        return 0;
+                    if (c == 'n')
+                        continue;
+
+                    tipcontainer(cobj);
+                    return 1;
+                }
+            }
         }
     }