#tip command -- empty container contents onto floor */
| 3559 | |
| 3560 | /* #tip command -- empty container contents onto floor */ |
| 3561 | int |
| 3562 | dotip(void) |
| 3563 | { |
| 3564 | struct obj *cobj, *nobj; |
| 3565 | coord cc; |
| 3566 | int boxes; |
| 3567 | char c, buf[BUFSZ], qbuf[BUFSZ]; |
| 3568 | const char *spillage = 0; |
| 3569 | |
| 3570 | /* |
| 3571 | * Doesn't require free hands; |
| 3572 | * limbs are needed to tip floor containers. |
| 3573 | * |
| 3574 | * Note: for menustyle:Traditional, using m prefix forces a menu |
| 3575 | * of floor containers when more than one is present. For other |
| 3576 | * menustyle settings or when fewer than two floor containers are |
| 3577 | * present, using 'm' skips floor and goes straight to invent. |
| 3578 | * This somewhat unintuitive behavior is driven by the way that |
| 3579 | * context-sensitive inventory item actions use m prefix. |
| 3580 | */ |
| 3581 | |
| 3582 | /* at present, can only tip things at current spot, not adjacent ones */ |
| 3583 | cc.x = u.ux, cc.y = u.uy; |
| 3584 | |
| 3585 | /* check floor container(s) first; at most one will be accessed */ |
| 3586 | boxes = container_at(cc.x, cc.y, TRUE); |
| 3587 | /* this is iffy for menustyle:traditional; 'm' prefix is ambiguous |
| 3588 | for it: skip floor vs handle multiple containers via menu */ |
| 3589 | if (boxes > 0 |
| 3590 | && (!iflags.menu_requested |
| 3591 | || (flags.menu_style == MENU_TRADITIONAL && boxes > 1))) { |
| 3592 | Sprintf(buf, "You can't tip %s while carrying so much.", |
| 3593 | !flags.verbose ? "a container" : (boxes > 1) ? "one" : "it"); |
| 3594 | if (!check_capacity(buf) && able_to_loot(cc.x, cc.y, FALSE)) { |
| 3595 | if (boxes > 1) { |
| 3596 | int res; |
| 3597 | /* pick one container via menu or ... */ |
| 3598 | if ((res = choose_tip_container_menu()) != ECMD_OK) |
| 3599 | return res; |
| 3600 | /* else pick-from-gi.invent below */ |
| 3601 | } else { |
| 3602 | for (cobj = svl.level.objects[cc.x][cc.y]; cobj; |
| 3603 | cobj = nobj) { |
| 3604 | nobj = cobj->nexthere; |
| 3605 | if (!Is_container(cobj)) |
| 3606 | continue; |
| 3607 | c = ynq(safe_qbuf(qbuf, "There is ", " here, tip it?", |
| 3608 | cobj, |
| 3609 | doname, ansimpleoname, "container")); |
| 3610 | if (c == 'q') |
| 3611 | return ECMD_OK; |
| 3612 | if (c == 'n') |
| 3613 | continue; |
| 3614 | tipcontainer(cobj); |
| 3615 | /* can only tip one container at a time */ |
| 3616 | return ECMD_TIME; |
| 3617 | } |
| 3618 | } |
nothing calls this directly
no test coverage detected