| 40 | | #define STORE_HELP 0x000001 |
|---|
| 41 | | #define STORE_INVEN_CHANGE 0x000002 |
|---|
| 42 | | #define STORE_GOLD_CHANGE 0x000004 |
|---|
| 43 | | #define STORE_HELP_CHANGE 0x000008 |
|---|
| 44 | | #define STORE_FRAME_CHANGE 0x000010 |
|---|
| 45 | | #define STORE_MORE_CHANGE 0x000020 |
|---|
| 46 | | #define STORE_SIZE_CHANGE 0x000040 |
|---|
| | 40 | #define STORE_GOLD_CHANGE 0x01 |
|---|
| | 41 | #define STORE_FRAME_CHANGE 0x02 |
|---|
| | 42 | #define STORE_INVEN 0x10 |
|---|
| | 77 | |
|---|
| | 78 | /* |
|---|
| | 79 | * Shopkeeper welcome messages. |
|---|
| | 80 | * |
|---|
| | 81 | * The shopkeeper's name must come first, then the character's name. |
|---|
| | 82 | */ |
|---|
| | 83 | static const char *comment_welcome[] = |
|---|
| | 84 | { |
|---|
| | 85 | "", |
|---|
| | 86 | "%s nods to you.", |
|---|
| | 87 | "%s says hello.", |
|---|
| | 88 | "%s: \"See anything you like, adventurer?\"", |
|---|
| | 89 | "%s: \"How may I help you, %s?\"", |
|---|
| | 90 | "%s: \"Welcome back, %s.\"", |
|---|
| | 91 | "%s: \"A pleasure to see you again, %s.\"", |
|---|
| | 92 | "%s: \"How may I be of assistance, good %s?\"", |
|---|
| | 93 | "%s: \"You do honour to my humble store, noble %s.\"", |
|---|
| | 94 | "%s: \"I and my family are entirely at your service, glorious %s.\"" |
|---|
| | 95 | }; |
|---|
| 128 | | /* Randomly select one of the entries in an array */ |
|---|
| 129 | | #define ONE_OF(x) x[rand_int(N_ELEMENTS(x))] |
|---|
| | 146 | |
|---|
| | 147 | |
|---|
| | 148 | /* |
|---|
| | 149 | * The greeting a shopkeeper gives the character says a lot about his |
|---|
| | 150 | * general attitude. |
|---|
| | 151 | * |
|---|
| | 152 | * Taken and modified from Sangband 1.0. |
|---|
| | 153 | */ |
|---|
| | 154 | static void prt_welcome(const owner_type *ot_ptr) |
|---|
| | 155 | { |
|---|
| | 156 | char short_name[20]; |
|---|
| | 157 | const char *player_name; |
|---|
| | 158 | |
|---|
| | 159 | const char *owner_name = &b_name[ot_ptr->owner_name]; |
|---|
| | 160 | int i = p_ptr->lev / 5; |
|---|
| | 161 | |
|---|
| | 162 | /* Only show the message one in four times to stop it being irritating. */ |
|---|
| | 163 | if (!rand_int(4)) return; |
|---|
| | 164 | |
|---|
| | 165 | /* Welcome the character */ |
|---|
| | 166 | if (i) |
|---|
| | 167 | { |
|---|
| | 168 | int j; |
|---|
| | 169 | |
|---|
| | 170 | /* Extract the first name of the store owner (stop before the first space) */ |
|---|
| | 171 | for (j = 0; owner_name[j] && owner_name[j] != ' '; j++) |
|---|
| | 172 | short_name[j] = owner_name[j]; |
|---|
| | 173 | |
|---|
| | 174 | /* Truncate the name */ |
|---|
| | 175 | short_name[j] = '\0'; |
|---|
| | 176 | |
|---|
| | 177 | |
|---|
| | 178 | /* Get a title for the character */ |
|---|
| | 179 | if (i == 4) player_name = c_text + cp_ptr->title[(p_ptr->lev - 1) / 5]; |
|---|
| | 180 | else if (rand_int(2)) player_name = op_ptr->full_name; |
|---|
| | 181 | else player_name = "sir"; |
|---|
| | 182 | |
|---|
| | 183 | /* Balthazar says "Welcome" */ |
|---|
| | 184 | prt(format(comment_welcome[i], short_name, player_name), 0, 0); |
|---|
| | 185 | } |
|---|
| | 186 | } |
|---|
| | 187 | |
|---|
| 1459 | | scr_places_x[LOC_PRICE] = Term->wid - 14; |
|---|
| 1460 | | scr_places_x[LOC_AU] = Term->wid - 26; |
|---|
| | 1514 | scr_places_x[LOC_PRICE] = wid - 14; |
|---|
| | 1515 | scr_places_x[LOC_AU] = wid - 26; |
|---|
| | 1516 | scr_places_x[LOC_OWNER] = wid - 2; |
|---|
| | 1517 | scr_places_x[LOC_WEIGHT] = wid - 14; |
|---|
| | 1518 | |
|---|
| | 1519 | /* Add space for for prices */ |
|---|
| | 1520 | if (store_current != STORE_HOME) |
|---|
| | 1521 | scr_places_x[LOC_WEIGHT] -= 10; |
|---|
| 1467 | | scr_places_y[LOC_ITEMS_END] = Term->hgt - 5; |
|---|
| 1468 | | scr_places_y[LOC_MORE] = Term->hgt - 4; |
|---|
| 1469 | | scr_places_y[LOC_HELP_CLEAR] = Term->hgt - 3; |
|---|
| 1470 | | scr_places_y[LOC_HELP_PROMPT] = Term->hgt - 2; |
|---|
| 1471 | | scr_places_y[LOC_AU] = Term->hgt - 2; |
|---|
| 1472 | | |
|---|
| 1473 | | if (store_flags & (STORE_HELP)) |
|---|
| 1474 | | { |
|---|
| 1475 | | scr_places_y[LOC_ITEMS_END] -= 2; |
|---|
| 1476 | | scr_places_y[LOC_MORE] -= 2; |
|---|
| 1477 | | scr_places_y[LOC_HELP_CLEAR] -= 2; |
|---|
| 1478 | | scr_places_y[LOC_HELP_PROMPT] -= 1; |
|---|
| 1479 | | scr_places_y[LOC_AU] -= 3; |
|---|
| 1480 | | } |
|---|
| | 1528 | scr_places_y[LOC_ITEMS_END] = hgt - 7; |
|---|
| | 1529 | scr_places_y[LOC_MORE] = hgt - 6; |
|---|
| | 1530 | scr_places_y[LOC_HELP_CLEAR] = hgt - 5; |
|---|
| | 1531 | scr_places_y[LOC_HELP_PROMPT] = hgt - 3; |
|---|
| | 1532 | scr_places_y[LOC_AU] = hgt - 5; |
|---|
| 1493 | | /* |
|---|
| 1494 | | * Convert a one character label into a store item index. |
|---|
| 1495 | | * |
|---|
| 1496 | | * Return "-1" if the label does not indicate a real store item. |
|---|
| 1497 | | */ |
|---|
| 1498 | | static s16b label_to_store(int c) |
|---|
| 1499 | | { |
|---|
| 1500 | | int i; |
|---|
| 1501 | | |
|---|
| 1502 | | /* Convert */ |
|---|
| 1503 | | i = (islower((unsigned char)c) ? A2I(c) : -1); |
|---|
| 1504 | | |
|---|
| 1505 | | /* Verify the index */ |
|---|
| 1506 | | if ((i < 0) || (i >= store[store_current].stock_num)) return (-1); |
|---|
| 1507 | | |
|---|
| 1508 | | /* Return the index */ |
|---|
| 1509 | | return (i); |
|---|
| 1510 | | } |
|---|
| 1511 | | |
|---|
| 1512 | | #define weight_pos(s) (Term->wid - ((s == STORE_HOME) ? (14) : (24))) |
|---|
| 1513 | | |
|---|
| 1514 | | /* |
|---|
| 1515 | | * Redisplay a single store entry |
|---|
| 1516 | | */ |
|---|
| 1517 | | static void store_display_entry(int item) |
|---|
| | 1545 | static struct sell_objs |
|---|
| | 1546 | { |
|---|
| | 1547 | object_type *o_ptr; |
|---|
| | 1548 | int index; |
|---|
| | 1549 | } sellable[INVEN_TOTAL]; |
|---|
| | 1550 | |
|---|
| | 1551 | static int sellable_total; |
|---|
| | 1552 | |
|---|
| | 1553 | void inven_compile_list(void) |
|---|
| | 1554 | { |
|---|
| | 1555 | object_type *o_ptr; |
|---|
| | 1556 | int i, sell_idx = 0; |
|---|
| | 1557 | |
|---|
| | 1558 | /* Wipe the sellable array */ |
|---|
| | 1559 | C_WIPE(&sellable, INVEN_TOTAL, struct sell_objs); |
|---|
| | 1560 | |
|---|
| | 1561 | /* Go over all the inventory items */ |
|---|
| | 1562 | for (i = 0; i < INVEN_TOTAL; i++) |
|---|
| | 1563 | { |
|---|
| | 1564 | /* Get a copy of the item */ |
|---|
| | 1565 | o_ptr = &inventory[i]; |
|---|
| | 1566 | |
|---|
| | 1567 | /* Forget (nothing)s */ |
|---|
| | 1568 | if (!o_ptr->k_idx) |
|---|
| | 1569 | continue; |
|---|
| | 1570 | |
|---|
| | 1571 | /* Make sure the store will buy this kind of object */ |
|---|
| | 1572 | if (!store_will_buy(store_current, o_ptr)) |
|---|
| | 1573 | continue; |
|---|
| | 1574 | |
|---|
| | 1575 | /* Check it's not cursed */ |
|---|
| | 1576 | if ((i >= INVEN_WIELD) && cursed_p(o_ptr)) |
|---|
| | 1577 | continue; |
|---|
| | 1578 | |
|---|
| | 1579 | /* Add to list */ |
|---|
| | 1580 | sellable[sell_idx].o_ptr = o_ptr; |
|---|
| | 1581 | sellable[sell_idx].index = i; |
|---|
| | 1582 | sell_idx++; |
|---|
| | 1583 | } |
|---|
| | 1584 | |
|---|
| | 1585 | /* Keep track of the total */ |
|---|
| | 1586 | sellable_total = sell_idx; |
|---|
| | 1587 | |
|---|
| | 1588 | return; |
|---|
| | 1589 | } |
|---|
| | 1590 | |
|---|
| | 1591 | /* |
|---|
| | 1592 | * Display a single invenory entry |
|---|
| | 1593 | */ |
|---|
| | 1594 | static void inven_display_entry(menu_type *menu, int oid, bool cursor, int row, int col, int width) |
|---|
| 1571 | | c_put_str(colour, out_val, where, scr_places_x[LOC_PRICE]); |
|---|
| 1572 | | } |
|---|
| 1573 | | } |
|---|
| 1574 | | |
|---|
| 1575 | | |
|---|
| 1576 | | /* |
|---|
| 1577 | | * Display a store's inventory. |
|---|
| 1578 | | */ |
|---|
| 1579 | | static void store_display_inventory(void) |
|---|
| 1580 | | { |
|---|
| 1581 | | int i, start, end; |
|---|
| 1582 | | int no_items; |
|---|
| | 1641 | c_put_str(TERM_WHITE, out_val, row, scr_places_x[LOC_PRICE]); |
|---|
| | 1642 | } |
|---|
| | 1643 | } |
|---|
| | 1644 | |
|---|
| | 1645 | |
|---|
| | 1646 | |
|---|
| | 1647 | |
|---|
| | 1648 | /* |
|---|
| | 1649 | * Redisplay a single store entry |
|---|
| | 1650 | */ |
|---|
| | 1651 | static void store_display_entry(menu_type *menu, int oid, bool cursor, int row, int col, int width) |
|---|
| | 1652 | { |
|---|
| | 1653 | object_type *o_ptr; |
|---|
| | 1654 | s32b x; |
|---|
| | 1655 | |
|---|
| | 1656 | char o_name[80]; |
|---|
| | 1657 | char out_val[160]; |
|---|
| | 1658 | byte colour; |
|---|
| 1586 | | /* Get number of items to show */ |
|---|
| 1587 | | start = scr_places_y[LOC_ITEMS_START]; |
|---|
| 1588 | | end = scr_places_y[LOC_ITEMS_END]; |
|---|
| 1589 | | |
|---|
| 1590 | | no_items = (end - start) + 1; |
|---|
| 1591 | | |
|---|
| 1592 | | /* Display items */ |
|---|
| 1593 | | for (i = 0; i < no_items; i++) |
|---|
| 1594 | | { |
|---|
| 1595 | | /* Clear non-items */ |
|---|
| 1596 | | if ((store_top + i) >= st_ptr->stock_num) |
|---|
| 1597 | | prt("", start + i, 0); |
|---|
| 1598 | | |
|---|
| 1599 | | /* Display items */ |
|---|
| | 1662 | (void)menu; |
|---|
| | 1663 | (void)cursor; |
|---|
| | 1664 | (void)width; |
|---|
| | 1665 | |
|---|
| | 1666 | /* Get the object */ |
|---|
| | 1667 | o_ptr = &st_ptr->stock[oid]; |
|---|
| | 1668 | |
|---|
| | 1669 | /* Describe the object */ |
|---|
| | 1670 | object_desc(o_name, sizeof(o_name), o_ptr, TRUE, 3); |
|---|
| | 1671 | |
|---|
| | 1672 | /* Display the object */ |
|---|
| | 1673 | c_put_str(tval_to_attr[o_ptr->tval & 0x7F], o_name, row, col); |
|---|
| | 1674 | |
|---|
| | 1675 | /* Show weights */ |
|---|
| | 1676 | if (show_weights) |
|---|
| | 1677 | { |
|---|
| | 1678 | int wgt = o_ptr->weight; |
|---|
| | 1679 | |
|---|
| | 1680 | sprintf(out_val, "%3d.%d lb", wgt / 10, wgt % 10); |
|---|
| | 1681 | put_str(out_val, row, scr_places_x[LOC_WEIGHT]); |
|---|
| | 1682 | } |
|---|
| | 1683 | |
|---|
| | 1684 | /* Describe an object (fully) in a store */ |
|---|
| | 1685 | if (store_current != STORE_HOME) |
|---|
| | 1686 | { |
|---|
| | 1687 | /* Extract the "minimum" price */ |
|---|
| | 1688 | x = price_item(o_ptr, FALSE); |
|---|
| | 1689 | |
|---|
| | 1690 | /* Make sure the player can afford it */ |
|---|
| | 1691 | if ((unsigned int) p_ptr->au < (unsigned int) x) |
|---|
| | 1692 | colour = TERM_SLATE; |
|---|
| 1601 | | store_display_entry(store_top + i); |
|---|
| 1602 | | } |
|---|
| 1603 | | } |
|---|
| 1604 | | |
|---|
| | 1694 | colour = TERM_WHITE; |
|---|
| | 1695 | |
|---|
| | 1696 | /* Actually draw the price */ |
|---|
| | 1697 | if (((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_STAFF)) && |
|---|
| | 1698 | (o_ptr->number > 1)) |
|---|
| | 1699 | sprintf(out_val, "%9ld avg", (long)x); |
|---|
| | 1700 | else |
|---|
| | 1701 | sprintf(out_val, "%9ld ", (long)x); |
|---|
| | 1702 | |
|---|
| | 1703 | c_put_str(colour, out_val, row, scr_places_x[LOC_PRICE]); |
|---|
| | 1704 | } |
|---|
| | 1705 | } |
|---|
| 1671 | | if (store_flags & STORE_HELP) |
|---|
| 1672 | | { |
|---|
| 1673 | | /* Prepare help hooks */ |
|---|
| 1674 | | text_out_hook = text_out_to_screen; |
|---|
| 1675 | | text_out_indent = 1; |
|---|
| 1676 | | Term_gotoxy(1, help_loc); |
|---|
| 1677 | | |
|---|
| 1678 | | text_out("Use the "); |
|---|
| 1679 | | text_out_c(TERM_L_GREEN, "movement keys"); |
|---|
| 1680 | | text_out(" and the "); |
|---|
| 1681 | | text_out_c(TERM_L_GREEN, "spacebar"); |
|---|
| 1682 | | text_out(" to navigate the store's inventory, '"); |
|---|
| 1683 | | |
|---|
| 1684 | | text_out_c(TERM_L_GREEN, "p"); |
|---|
| 1685 | | text_out("' to obtain an item, '"); |
|---|
| 1686 | | |
|---|
| 1687 | | text_out_c(TERM_L_GREEN, "s"); |
|---|
| 1688 | | |
|---|
| 1689 | | if (store_current == STORE_HOME) text_out("' to deposit"); |
|---|
| 1690 | | else text_out("' to sell"); |
|---|
| 1691 | | |
|---|
| 1692 | | text_out(" an item, '"); |
|---|
| 1693 | | |
|---|
| 1694 | | if (rogue_like_commands) |
|---|
| 1695 | | text_out_c(TERM_L_GREEN, "x"); |
|---|
| | 1778 | /* Prepare help hooks */ |
|---|
| | 1779 | text_out_hook = text_out_to_screen; |
|---|
| | 1780 | text_out_indent = 1; |
|---|
| | 1781 | Term_gotoxy(1, help_loc); |
|---|
| | 1782 | |
|---|
| | 1783 | text_out("Use the "); |
|---|
| | 1784 | text_out_c(TERM_L_GREEN, "movement keys"); |
|---|
| | 1785 | text_out(" to navigate "); |
|---|
| | 1786 | |
|---|
| | 1787 | if (store_flags & STORE_INVEN) |
|---|
| | 1788 | text_out("your"); |
|---|
| | 1789 | else |
|---|
| | 1790 | text_out("the store's"); |
|---|
| | 1791 | |
|---|
| | 1792 | text_out(" inventory, '"); |
|---|
| | 1793 | |
|---|
| | 1794 | if (rogue_like_commands) |
|---|
| | 1795 | text_out_c(TERM_L_GREEN, "x"); |
|---|
| | 1796 | else |
|---|
| | 1797 | { |
|---|
| | 1798 | if (store_flags & STORE_INVEN) |
|---|
| | 1799 | text_out_c(TERM_L_GREEN, "I"); |
|---|
| 1706 | | { |
|---|
| 1707 | | /* Prompt */ |
|---|
| 1708 | | prt("Press '?' for help.", help_loc, 1); |
|---|
| 1709 | | } |
|---|
| | 1812 | text_out("obtain"); |
|---|
| | 1813 | |
|---|
| | 1814 | text_out(" an item. If you want to "); |
|---|
| | 1815 | |
|---|
| | 1816 | if (store_flags & STORE_INVEN) |
|---|
| | 1817 | { |
|---|
| | 1818 | if (store_current == STORE_HOME) text_out("pick up"); |
|---|
| | 1819 | else text_out("purchase"); |
|---|
| | 1820 | } |
|---|
| | 1821 | else |
|---|
| | 1822 | { |
|---|
| | 1823 | if (store_current == STORE_HOME) text_out("deposit"); |
|---|
| | 1824 | else text_out("sell"); |
|---|
| | 1825 | } |
|---|
| | 1826 | |
|---|
| | 1827 | text_out(" items, press '"); |
|---|
| | 1828 | |
|---|
| | 1829 | text_out_c(TERM_L_GREEN, "TAB"); |
|---|
| | 1830 | text_out("' or '"); |
|---|
| | 1831 | |
|---|
| | 1832 | if (store_flags & STORE_INVEN) |
|---|
| | 1833 | text_out_c(TERM_L_GREEN, "p"); |
|---|
| | 1834 | else |
|---|
| | 1835 | text_out_c(TERM_L_GREEN, "s"); |
|---|
| | 1836 | |
|---|
| | 1837 | text_out("'. "); |
|---|
| | 1838 | |
|---|
| | 1839 | text_out_c(TERM_L_GREEN, "ESC"); |
|---|
| | 1840 | text_out(" exits the building."); |
|---|
| | 1841 | |
|---|
| | 1842 | text_out_indent = 0; |
|---|
| 1729 | | } |
|---|
| 1730 | | |
|---|
| 1731 | | if (store_flags & (STORE_HELP_CHANGE)) |
|---|
| 1732 | | { |
|---|
| 1733 | | store_display_help(); |
|---|
| 1734 | | store_flags &= ~(STORE_HELP_CHANGE); |
|---|
| 1735 | | store_flags |= (STORE_GOLD_CHANGE | STORE_INVEN_CHANGE); |
|---|
| 1736 | | } |
|---|
| 1737 | | |
|---|
| 1738 | | if (store_flags & (STORE_INVEN_CHANGE)) |
|---|
| 1739 | | { |
|---|
| 1740 | | store_display_inventory(); |
|---|
| 1741 | | store_flags &= ~(STORE_INVEN_CHANGE); |
|---|
| 1742 | | store_flags |= (STORE_MORE_CHANGE); |
|---|
| 1743 | | } |
|---|
| 1744 | | |
|---|
| 1745 | | if (store_flags & (STORE_MORE_CHANGE)) |
|---|
| 1746 | | { |
|---|
| 1747 | | const char *p; |
|---|
| 1748 | | store_type *st_ptr = &store[store_current]; |
|---|
| 1749 | | int no_items = (scr_places_y[LOC_ITEMS_END] - |
|---|
| 1750 | | scr_places_y[LOC_ITEMS_START]) + 1; |
|---|
| 1751 | | |
|---|
| 1752 | | /* Visual reminder of more items */ |
|---|
| 1753 | | if ((store_top + no_items) >= st_ptr->stock_num) |
|---|
| 1754 | | { |
|---|
| 1755 | | if (store_top > 0) p = " < more"; |
|---|
| 1756 | | else p = ""; |
|---|
| 1757 | | } |
|---|
| 1758 | | else |
|---|
| 1759 | | { |
|---|
| 1760 | | if (store_top > 0) p = " < more >"; |
|---|
| 1761 | | else p = " more >"; |
|---|
| 1762 | | } |
|---|
| 1763 | | |
|---|
| 1764 | | prt(p, scr_places_y[LOC_MORE], 0); |
|---|
| 1765 | | |
|---|
| 1766 | | store_flags &= ~(STORE_MORE_CHANGE); |
|---|
| 1775 | | |
|---|
| 1776 | | /* Reset the cursor */ |
|---|
| 1777 | | Term_gotoxy(0, 0); |
|---|
| 1778 | | } |
|---|
| 1779 | | |
|---|
| 1780 | | /* |
|---|
| 1781 | | * Hook for terminal size change |
|---|
| 1782 | | */ |
|---|
| 1783 | | void store_display_resize(void) |
|---|
| 1784 | | { |
|---|
| 1785 | | /* Mark the change */ |
|---|
| 1786 | | store_flags |= STORE_SIZE_CHANGE; |
|---|
| 1787 | | |
|---|
| 1788 | | /* Redraw */ |
|---|
| 1789 | | store_redraw(); |
|---|
| 1790 | | } |
|---|
| 1791 | | |
|---|
| 1792 | | |
|---|
| 1793 | | /*** User interaction bits ***/ |
|---|
| 1794 | | |
|---|
| 1795 | | /* |
|---|
| 1796 | | * Get the index of a store object. |
|---|
| 1797 | | * Return TRUE if an object was selected |
|---|
| 1798 | | */ |
|---|
| 1799 | | static bool get_stock(int *com_val, cptr pmt) |
|---|
| 1800 | | { |
|---|
| 1801 | | int item; |
|---|
| 1802 | | char which; |
|---|
| 1803 | | char buf[160]; |
|---|
| 1804 | | char o_name[80]; |
|---|
| 1805 | | char out_val[160]; |
|---|
| 1806 | | object_type *o_ptr; |
|---|
| 1807 | | store_type *st_ptr = &store[store_current]; |
|---|
| 1808 | | |
|---|
| 1809 | | #ifdef ALLOW_REPEAT |
|---|
| 1810 | | |
|---|
| 1811 | | /* Get the item index */ |
|---|
| 1812 | | if (repeat_pull(com_val)) |
|---|
| 1813 | | { |
|---|
| 1814 | | /* Verify the item */ |
|---|
| 1815 | | if ((*com_val >= 0) && (*com_val <= (st_ptr->stock_num - 1))) |
|---|
| 1816 | | { |
|---|
| 1817 | | /* Success */ |
|---|
| 1818 | | return (TRUE); |
|---|
| 1819 | | } |
|---|
| 1820 | | else |
|---|
| 1821 | | { |
|---|
| 1822 | | /* Invalid repeat - reset it */ |
|---|
| 1823 | | repeat_clear(); |
|---|
| 1824 | | } |
|---|
| 1825 | | } |
|---|
| 1826 | | |
|---|
| 1827 | | #endif /* ALLOW_REPEAT */ |
|---|
| 1828 | | |
|---|
| 1829 | | /* Assume failure */ |
|---|
| 1830 | | *com_val = (-1); |
|---|
| 1831 | | |
|---|
| 1832 | | /* Build the prompt */ |
|---|
| 1833 | | strnfmt(buf, sizeof(buf), "%s (%c-%c, ESC to exit)", |
|---|
| 1834 | | pmt, store_to_label(0), store_to_label(st_ptr->stock_num - 1)); |
|---|
| 1835 | | |
|---|
| 1836 | | /* Ask until done */ |
|---|
| 1837 | | while (TRUE) |
|---|
| 1838 | | { |
|---|
| 1839 | | bool verify; |
|---|
| 1840 | | |
|---|
| 1841 | | /* Escape */ |
|---|
| 1842 | | if (!get_com(buf, &which)) return (FALSE); |
|---|
| 1843 | | |
|---|
| 1844 | | /* Note verify */ |
|---|
| 1845 | | verify = (isupper((unsigned char)which) ? TRUE : FALSE); |
|---|
| 1846 | | |
|---|
| 1847 | | /* Lowercase */ |
|---|
| 1848 | | which = tolower((unsigned char)which); |
|---|
| 1849 | | |
|---|
| 1850 | | /* Convert response to item */ |
|---|
| 1851 | | item = label_to_store(which); |
|---|
| 1852 | | |
|---|
| 1853 | | /* Oops */ |
|---|
| 1854 | | if (item < 0) |
|---|
| 1855 | | { |
|---|
| 1856 | | /* Oops */ |
|---|
| 1857 | | bell("Illegal store object choice!"); |
|---|
| 1858 | | |
|---|
| 1859 | | continue; |
|---|
| 1860 | | } |
|---|
| 1861 | | |
|---|
| 1862 | | /* No verification */ |
|---|
| 1863 | | if (!verify) break; |
|---|
| 1864 | | |
|---|
| 1865 | | /* Object */ |
|---|
| 1866 | | o_ptr = &st_ptr->stock[item]; |
|---|
| 1867 | | |
|---|
| 1868 | | /* Describe */ |
|---|
| 1869 | | object_desc(o_name, sizeof(o_name), o_ptr, TRUE, 3); |
|---|
| 1870 | | |
|---|
| 1871 | | /* Prompt */ |
|---|
| 1872 | | strnfmt(out_val, sizeof(out_val), "Try %s? ", o_name); |
|---|
| 1873 | | |
|---|
| 1874 | | /* Query */ |
|---|
| 1875 | | if (!get_check(out_val)) return (FALSE); |
|---|
| 1876 | | |
|---|
| 1877 | | /* Done */ |
|---|
| 1878 | | break; |
|---|
| 1879 | | } |
|---|
| 1880 | | |
|---|
| 1881 | | /* Save item */ |
|---|
| 1882 | | (*com_val) = item; |
|---|
| 1883 | | |
|---|
| 1884 | | #ifdef ALLOW_REPEAT |
|---|
| 1885 | | |
|---|
| 1886 | | repeat_push(*com_val); |
|---|
| 1887 | | |
|---|
| 1888 | | #endif /* ALLOW_REPEAT */ |
|---|
| | 1864 | } |
|---|
| | 1865 | |
|---|
| | 1866 | |
|---|
| | 1867 | /*** Higher-level code ***/ |
|---|
| | 1868 | |
|---|
| | 1869 | |
|---|
| | 1870 | static bool store_get_check(const char *prompt) |
|---|
| | 1871 | { |
|---|
| | 1872 | char ch; |
|---|
| | 1873 | |
|---|
| | 1874 | /* Prompt for it */ |
|---|
| | 1875 | prt(prompt, 0, 0); |
|---|
| | 1876 | |
|---|
| | 1877 | /* Get an answer */ |
|---|
| | 1878 | ch = inkey(); |
|---|
| | 1879 | |
|---|
| | 1880 | /* Erase the prompt */ |
|---|
| | 1881 | prt("", 0, 0); |
|---|
| | 1882 | |
|---|
| | 1883 | if (ch == ESCAPE) return (FALSE); |
|---|
| | 1884 | if (strchr("Nn", ch)) return (FALSE); |
|---|