used for disclosure and for the ':' choice when looting a container */
| 1591 | |
| 1592 | /* used for disclosure and for the ':' choice when looting a container */ |
| 1593 | void |
| 1594 | container_contents( |
| 1595 | struct obj *list, |
| 1596 | boolean identified, |
| 1597 | boolean all_containers, |
| 1598 | boolean reportempty) |
| 1599 | { |
| 1600 | struct obj *box, *obj; |
| 1601 | char buf[BUFSZ]; |
| 1602 | boolean cat, dumping = iflags.in_dumplog; |
| 1603 | |
| 1604 | for (box = list; box; box = box->nobj) { |
| 1605 | if (Is_container(box) || box->otyp == STATUE) { |
| 1606 | if (!box->cknown || (identified && !box->lknown)) { |
| 1607 | box->cknown = 1; /* we're looking at the contents now */ |
| 1608 | if (identified) |
| 1609 | box->lknown = 1; |
| 1610 | update_inventory(); |
| 1611 | } |
| 1612 | if (box->otyp == BAG_OF_TRICKS) { |
| 1613 | continue; /* wrong type of container */ |
| 1614 | } else if (box->cobj) { |
| 1615 | winid tmpwin = create_nhwindow(NHW_MENU); |
| 1616 | Loot *sortedcobj, *srtc; |
| 1617 | unsigned sortflags; |
| 1618 | |
| 1619 | /* at this stage, the SchroedingerBox() flag is only set |
| 1620 | if the cat inside the box is alive; the box actually |
| 1621 | contains a cat corpse that we'll pretend is not there; |
| 1622 | for dead cat, the flag will be clear and there'll be |
| 1623 | a cat corpse inside the box; either way, inventory |
| 1624 | reports the box as containing "1 item" */ |
| 1625 | cat = SchroedingersBox(box); |
| 1626 | |
| 1627 | Sprintf(buf, "Contents of %s:", the(xname(box))); |
| 1628 | putstr(tmpwin, 0, buf); |
| 1629 | if (!dumping) |
| 1630 | putstr(tmpwin, 0, ""); |
| 1631 | buf[0] = buf[1] = ' '; /* two leading spaces */ |
| 1632 | if (box->cobj && !cat) { |
| 1633 | sortflags = (((flags.sortloot == 'l' |
| 1634 | || flags.sortloot == 'f') |
| 1635 | ? SORTLOOT_LOOT : 0) |
| 1636 | | (flags.sortpack ? SORTLOOT_PACK : 0)); |
| 1637 | sortedcobj = sortloot(&box->cobj, sortflags, FALSE, |
| 1638 | (boolean (*)(OBJ_P)) 0); |
| 1639 | for (srtc = sortedcobj; (obj = srtc->obj) != 0; ++srtc) { |
| 1640 | if (identified) { |
| 1641 | discover_object(obj->otyp, TRUE, TRUE, FALSE); |
| 1642 | obj->dknown = 1; /* observe_object unnecessary */ |
| 1643 | obj->known = obj->bknown = obj->rknown = 1; |
| 1644 | if (Is_container(obj) || obj->otyp == STATUE) |
| 1645 | obj->cknown = obj->lknown = 1; |
| 1646 | } |
| 1647 | Strcpy(&buf[2], doname_with_price(obj)); |
| 1648 | putstr(tmpwin, 0, buf); |
| 1649 | } |
| 1650 | unsortloot(&sortedcobj); |
no test coverage detected