| 3868 | cancelled is TRUE if user cancelled the menu pick; hands aren't required |
| 3869 | when tipping to the floor but are when tipping into another container */ |
| 3870 | staticfn struct obj * |
| 3871 | tipcontainer_gettarget( |
| 3872 | struct obj *box, |
| 3873 | boolean *cancelled) |
| 3874 | { |
| 3875 | int n, n_conts; |
| 3876 | winid win; |
| 3877 | anything any; |
| 3878 | char buf[BUFSZ]; |
| 3879 | menu_item *pick_list = (menu_item *) 0; |
| 3880 | struct obj dummyobj, *otmp; |
| 3881 | boolean hands_available = TRUE, exclude_it; |
| 3882 | int clr = NO_COLOR; |
| 3883 | |
| 3884 | #if 0 /* [skip potential early return so that menu response is needed |
| 3885 | * regardless of whether other containers are being carried] */ |
| 3886 | int n_conts = count_target_containers(gi.invent, box); |
| 3887 | |
| 3888 | if (n_conts < 1 || !u_handsy()) { |
| 3889 | if (n_conts >= 1) |
| 3890 | pline("Tipping contents to floor only..."); |
| 3891 | *cancelled = FALSE; |
| 3892 | return (struct obj *) 0; |
| 3893 | } |
| 3894 | #endif |
| 3895 | |
| 3896 | win = create_nhwindow(NHW_MENU); |
| 3897 | start_menu(win, MENU_BEHAVE_STANDARD); |
| 3898 | |
| 3899 | dummyobj = cg.zeroobj; /* lint suppression; only its address matters */ |
| 3900 | any = cg.zeroany; |
| 3901 | any.a_obj = &dummyobj; |
| 3902 | /* tip to floor does not require free hands */ |
| 3903 | add_menu(win, &nul_glyphinfo, &any, '-', 0, ATR_NONE, clr, |
| 3904 | /* [TODO? vary destination string depending on surface()] */ |
| 3905 | "on the floor", MENU_ITEMFLAGS_SELECTED); |
| 3906 | add_menu_str(win, ""); |
| 3907 | |
| 3908 | n_conts = 0; |
| 3909 | for (otmp = gi.invent; otmp; otmp = otmp->nobj) { |
| 3910 | if (otmp == box) |
| 3911 | continue; |
| 3912 | /* skip non-containers; bag of tricks passes Is_container() test, |
| 3913 | only include it if it isn't known to be a bag of tricks */ |
| 3914 | if (!Is_container(otmp) |
| 3915 | || (otmp->otyp == BAG_OF_TRICKS && otmp->dknown |
| 3916 | && objects[otmp->otyp].oc_name_known)) |
| 3917 | continue; |
| 3918 | if (!n_conts++) |
| 3919 | hands_available = u_handsy(); /* might issue message */ |
| 3920 | /* container-to-container tip requires free hands; |
| 3921 | exclude container as possible target when known to be locked */ |
| 3922 | exclude_it = !hands_available || (otmp->olocked && otmp->lknown); |
| 3923 | any = cg.zeroany; |
| 3924 | any.a_obj = !exclude_it ? otmp : 0; |
| 3925 | Sprintf(buf, "%s%s", !exclude_it ? "" : " ", doname(otmp)); |
| 3926 | add_menu(win, &nul_glyphinfo, &any, !exclude_it ? otmp->invlet : 0, 0, |
| 3927 | ATR_NONE, clr, buf, MENU_ITEMFLAGS_NONE); |
no test coverage detected