Changeset 1435
- Timestamp:
- 06/08/09 21:17:05 (9 months ago)
- Location:
- trunk/src
- Files:
-
- 8 modified
-
cmd3.c (modified) (4 diffs)
-
cmds.h (modified) (1 diff)
-
externs.h (modified) (1 diff)
-
game-cmd.c (modified) (2 diffs)
-
game-cmd.h (modified) (1 diff)
-
object/obj-util.c (modified) (1 diff)
-
object/object.h (modified) (1 diff)
-
store.c (modified) (45 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/cmd3.c
r1430 r1435 204 204 object_type *o_ptr; 205 205 206 object_type *i_ptr; 207 object_type object_type_body; 206 object_type destroyed_obj; 208 207 209 208 char o_name[120]; … … 234 233 } 235 234 236 /* Get local object */ 237 i_ptr = &object_type_body; 238 object_copy(i_ptr, o_ptr); 239 240 if ((o_ptr->tval == TV_WAND) || 241 (o_ptr->tval == TV_STAFF) || 242 (o_ptr->tval == TV_ROD)) 243 { 244 /* Calculate the amount of destroyed charges */ 245 i_ptr->pval = o_ptr->pval * amt / o_ptr->number; 246 } 247 248 /* Set quantity */ 249 i_ptr->number = amt; 250 251 /* Describe the destroyed object */ 252 object_desc(o_name, sizeof(o_name), i_ptr, TRUE, ODESC_FULL); 235 /* Describe the destroyed object by taking a copy with the right "amt" */ 236 object_copy_amt(&destroyed_obj, o_ptr, amt); 237 object_desc(o_name, sizeof(o_name), &destroyed_obj, TRUE, ODESC_FULL); 253 238 254 239 /* Artifacts cannot be destroyed */ … … 299 284 object_type *o_ptr; 300 285 301 object_type *i_ptr; 302 object_type object_type_body; 286 object_type obj_to_destroy; 303 287 304 288 char o_name[120]; … … 325 309 if (amt <= 0) return; 326 310 327 /* Get local object */ 328 i_ptr = &object_type_body; 329 object_copy(i_ptr, o_ptr); 330 331 if ((o_ptr->tval == TV_WAND) || 332 (o_ptr->tval == TV_STAFF) || 333 (o_ptr->tval == TV_ROD)) 334 { 335 /* Calculate the amount of destroyed charges */ 336 i_ptr->pval = o_ptr->pval * amt / o_ptr->number; 337 } 338 339 /* Set quantity */ 340 i_ptr->number = amt; 341 342 /* Describe the destroyed object */ 343 object_desc(o_name, sizeof(o_name), i_ptr, TRUE, ODESC_FULL); 311 /* Describe the destroyed object by taking a copy with the right "amt" */ 312 object_copy_amt(&obj_to_destroy, o_ptr, amt); 313 object_desc(o_name, sizeof(o_name), &obj_to_destroy, TRUE, ODESC_FULL); 344 314 345 315 /* Verify destruction */ -
trunk/src/cmds.h
r1417 r1435 132 132 /* store.c */ 133 133 extern void do_cmd_store(cmd_code code, cmd_arg args[]); 134 extern void do_cmd_sell(cmd_code code, cmd_arg args[]); 135 extern void do_cmd_stash(cmd_code code, cmd_arg args[]); 136 extern void do_cmd_buy(cmd_code code, cmd_arg args[]); 137 extern void do_cmd_retrieve(cmd_code code, cmd_arg args[]); 134 138 135 139 /* Types of item use */ -
trunk/src/externs.h
r1433 r1435 566 566 void store_shuffle(int which); 567 567 void store_maint(int which); 568 bool store_overflow(void);569 568 570 569 /* target.c */ -
trunk/src/game-cmd.c
r1431 r1435 213 213 case CMD_DROP: 214 214 case CMD_DESTROY: 215 case CMD_SELL: 216 case CMD_BUY: 217 case CMD_STASH: 218 case CMD_RETRIEVE: 215 219 { 216 220 /* TODO: Number should probably be replaced by 'repeat'ing */ … … 284 288 { CMD_STUDY_BOOK, do_cmd_study_book }, 285 289 { CMD_CAST, do_cmd_cast }, 290 { CMD_SELL, do_cmd_sell }, 291 { CMD_STASH, do_cmd_stash }, 292 { CMD_BUY, do_cmd_buy }, 293 { CMD_RETRIEVE, do_cmd_retrieve }, 286 294 }; 287 295 -
trunk/src/game-cmd.h
r1419 r1435 74 74 CMD_ENTER_STORE, 75 75 CMD_ALTER, 76 76 77 /* Store commands */ 78 CMD_SELL, 79 CMD_BUY, 80 CMD_STASH, 81 CMD_RETRIEVE, 77 82 78 83 /* Hors categorie Commands */ -
trunk/src/object/obj-util.c
r1427 r1435 1775 1775 /* Copy the structure */ 1776 1776 COPY(o_ptr, j_ptr, object_type); 1777 } 1778 1779 /* 1780 * Prepare an object `dst` representing `amt` objects, based on an existing 1781 * object `src` representing at least `amt` objects. 1782 * 1783 * Takes care of the charge redistribution concerns of stacked items. 1784 */ 1785 void object_copy_amt(object_type *dst, object_type *src, int amt) 1786 { 1787 /* Get a copy of the object */ 1788 object_copy(dst, src); 1789 1790 /* Modify quantity */ 1791 dst->number = amt; 1792 1793 /* If the item has charges, set them to the correct level too */ 1794 reduce_charges(dst, src->number - amt); 1777 1795 } 1778 1796 -
trunk/src/object/object.h
r1424 r1435 125 125 void object_wipe(object_type *o_ptr); 126 126 void object_copy(object_type *o_ptr, const object_type *j_ptr); 127 void object_copy_amt(object_type *dst, object_type *src, int amt); 127 128 void object_prep(object_type *o_ptr, int k_idx); 128 129 s16b floor_carry(int y, int x, object_type *j_ptr); -
trunk/src/store.c
r1419 r1435 74 74 /** Variables to maintain state XXX ***/ 75 75 76 /* Current store number */77 static int store_current;78 79 76 /* Flags for the display */ 80 77 static u16b store_flags; … … 384 381 385 382 383 #define STORE_NONE -1 384 385 /* Get the current store number, or STORE_NONE if not in a store */ 386 static int current_store() 387 { 388 if ((cave_feat[p_ptr->py][p_ptr->px] >= FEAT_SHOP_HEAD) && 389 (cave_feat[p_ptr->py][p_ptr->px] <= FEAT_SHOP_TAIL)) 390 return (cave_feat[p_ptr->py][p_ptr->px] - FEAT_SHOP_HEAD); 391 392 return STORE_NONE; 393 } 386 394 387 395 … … 407 415 int adjust; 408 416 s32b price; 409 410 owner_type *ot_ptr = store_owner(store_current); 417 int this_store = current_store(); 418 owner_type *ot_ptr; 419 420 if (this_store == STORE_NONE) return 0L; 421 422 ot_ptr = store_owner(this_store); 411 423 412 424 … … 422 434 423 435 /* Add in the charisma factor */ 424 if ( store_current== STORE_B_MARKET)436 if (this_store == STORE_B_MARKET) 425 437 adjust = 150; 426 438 else … … 436 448 437 449 /* Mega-Hack -- Black market sucks */ 438 if ( store_current== STORE_B_MARKET) price = price / 2;450 if (this_store == STORE_B_MARKET) price = price / 2; 439 451 } 440 452 … … 446 458 447 459 /* Mega-Hack -- Black market sucks */ 448 if ( store_current== STORE_B_MARKET) price = price * 2;460 if (this_store == STORE_B_MARKET) price = price * 2; 449 461 } 450 462 … … 1585 1597 1586 1598 /* Add space for for prices */ 1587 if ( store_current!= STORE_HOME)1599 if (current_store() != STORE_HOME) 1588 1600 scr_places_x[LOC_WEIGHT] -= 10; 1589 1601 … … 1627 1639 byte colour; 1628 1640 1629 store_type *st_ptr = &store[store_current]; 1641 int this_store = current_store(); 1642 store_type *st_ptr = &store[this_store]; 1630 1643 1631 1644 (void)menu; … … 1637 1650 1638 1651 /* Describe the object - preserving insriptions in the home */ 1639 if ( store_current== STORE_HOME) desc = ODESC_FULL;1652 if (this_store == STORE_HOME) desc = ODESC_FULL; 1640 1653 else desc = ODESC_FULL | ODESC_STORE; 1641 1654 object_desc(o_name, sizeof(o_name), o_ptr, TRUE, desc); … … 1650 1663 1651 1664 /* Describe an object (fully) in a store */ 1652 if ( store_current!= STORE_HOME)1665 if (this_store != STORE_HOME) 1653 1666 { 1654 1667 /* Extract the "minimum" price */ … … 1677 1690 { 1678 1691 char buf[80]; 1679 1680 owner_type *ot_ptr = store_owner(store_current); 1692 int this_store = current_store(); 1693 1694 owner_type *ot_ptr = store_owner(this_store); 1681 1695 1682 1696 /* Clear screen */ … … 1684 1698 1685 1699 /* The "Home" is special */ 1686 if ( store_current== STORE_HOME)1700 if (this_store == STORE_HOME) 1687 1701 { 1688 1702 /* Put the owner name */ … … 1699 1713 else 1700 1714 { 1701 const char *store_name = (f_name + f_info[FEAT_SHOP_HEAD + store_current].name);1715 const char *store_name = (f_name + f_info[FEAT_SHOP_HEAD + this_store].name); 1702 1716 const char *owner_name = &b_name[ot_ptr->owner_name]; 1703 1717 … … 1750 1764 text_out_c(TERM_L_GREEN, "p"); 1751 1765 1752 if ( store_current== STORE_HOME) text_out("' picks up");1766 if (current_store() == STORE_HOME) text_out("' picks up"); 1753 1767 else text_out("' purchases"); 1754 1768 … … 1756 1770 1757 1771 text_out_c(TERM_L_GREEN, "d"); 1758 if ( store_current== STORE_HOME) text_out("' drops");1772 if (current_store() == STORE_HOME) text_out("' drops"); 1759 1773 else text_out("' sells"); 1760 1774 … … 1960 1974 1961 1975 /* 1976 * Buy the item with the given index from the current store's inventory. 1977 */ 1978 void do_cmd_buy(cmd_code code, cmd_arg args[]) 1979 { 1980 int item = args[0].item; 1981 int amt = args[1].number; 1982 1983 object_type *o_ptr; 1984 object_type object_type_body; 1985 object_type *i_ptr = &object_type_body; 1986 1987 char o_name[80]; 1988 int price, item_new; 1989 1990 store_type *st_ptr; 1991 int this_store = current_store(); 1992 1993 if (this_store == STORE_NONE) 1994 { 1995 msg_print("You cannot purchase items when not in a store."); 1996 return; 1997 } 1998 1999 st_ptr = &store[this_store]; 2000 2001 /* Get the actual object */ 2002 o_ptr = &st_ptr->stock[item]; 2003 2004 /* Get desired object */ 2005 object_copy_amt(i_ptr, o_ptr, amt); 2006 2007 /* Ensure we have room */ 2008 if (!inven_carry_okay(i_ptr)) 2009 { 2010 msg_print("You cannot carry that many items."); 2011 return; 2012 } 2013 2014 /* Describe the object (fully) */ 2015 object_desc(o_name, sizeof(o_name), i_ptr, TRUE, ODESC_FULL); 2016 2017 /* Extract the price for the entire stack */ 2018 price = price_item(i_ptr, FALSE, i_ptr->number); 2019 2020 if (price > p_ptr->au) 2021 { 2022 msg_print("You cannot afford that purchase."); 2023 return; 2024 } 2025 2026 /* Spend the money */ 2027 p_ptr->au -= price; 2028 2029 /* Update the display */ 2030 store_flags |= STORE_GOLD_CHANGE; 2031 2032 /* Buying an object makes you aware of it */ 2033 object_aware(i_ptr); 2034 2035 /* Combine / Reorder the pack (later) */ 2036 p_ptr->notice |= (PN_COMBINE | PN_REORDER); 2037 2038 /* The object no longer belongs to the store */ 2039 i_ptr->ident &= ~(IDENT_STORE); 2040 2041 /* Message */ 2042 if (one_in_(3)) message(MSG_STORE5, 0, ONE_OF(comment_accept)); 2043 msg_format("You bought %s for %ld gold.", o_name, (long)price); 2044 2045 /* Erase the inscription */ 2046 i_ptr->note = 0; 2047 2048 /* Give it to the player */ 2049 item_new = inven_carry(i_ptr); 2050 2051 /* Message */ 2052 object_desc(o_name, sizeof(o_name), &inventory[item_new], TRUE, ODESC_FULL); 2053 msg_format("You have %s (%c).", o_name, index_to_label(item_new)); 2054 2055 /* Now, reduce the original stack's pval */ 2056 if ((o_ptr->tval == TV_ROD) || 2057 (o_ptr->tval == TV_WAND) || 2058 (o_ptr->tval == TV_STAFF)) 2059 { 2060 o_ptr->pval -= i_ptr->pval; 2061 } 2062 2063 /* Handle stuff */ 2064 handle_stuff(); 2065 2066 /* Remove the bought objects from the store */ 2067 store_item_increase(this_store, item, -amt); 2068 store_item_optimize(this_store, item); 2069 2070 /* Store is empty */ 2071 if (st_ptr->stock_num == 0) 2072 { 2073 int i; 2074 2075 /* Shuffle */ 2076 if (one_in_(STORE_SHUFFLE)) 2077 { 2078 /* Message */ 2079 msg_print("The shopkeeper retires."); 2080 2081 /* Shuffle the store */ 2082 store_shuffle(this_store); 2083 store_flags |= STORE_FRAME_CHANGE; 2084 } 2085 2086 /* Maintain */ 2087 else 2088 { 2089 /* Message */ 2090 msg_print("The shopkeeper brings out some new stock."); 2091 } 2092 2093 /* New inventory */ 2094 for (i = 0; i < 10; ++i) 2095 { 2096 /* Maintain the store */ 2097 store_maint(this_store); 2098 } 2099 } 2100 2101 event_signal(EVENT_INVENTORY); 2102 event_signal(EVENT_EQUIPMENT); 2103 } 2104 2105 /* 2106 * Retrieve the item with the given index from the home's inventory. 2107 */ 2108 void do_cmd_retrieve(cmd_code code, cmd_arg args[]) 2109 { 2110 int item = args[0].item; 2111 int amt = args[1].number; 2112 2113 object_type *o_ptr; 2114 object_type picked_item; 2115 char o_name[80]; 2116 int item_new; 2117 2118 store_type *st_ptr; 2119 2120 if (current_store() != STORE_HOME) 2121 { 2122 msg_print("You are not currently at home."); 2123 return; 2124 } 2125 2126 st_ptr = &store[STORE_HOME]; 2127 2128 /* Get the actual object */ 2129 o_ptr = &st_ptr->stock[item]; 2130 2131 /* Get desired object */ 2132 object_copy_amt(&picked_item, o_ptr, amt); 2133 2134 /* Ensure we have room */ 2135 if (!inven_carry_okay(&picked_item)) 2136 { 2137 msg_print("You cannot carry that many items."); 2138 return; 2139 } 2140 2141 /* Distribute charges of wands, staves, or rods */ 2142 distribute_charges(o_ptr, &picked_item, amt); 2143 2144 /* Give it to the player */ 2145 item_new = inven_carry(&picked_item); 2146 2147 printf("%i, %i\n", amt, picked_item.number); 2148 2149 /* Describe just the result */ 2150 object_desc(o_name, sizeof(o_name), &inventory[item_new], TRUE, ODESC_FULL); 2151 2152 /* Message */ 2153 msg_format("You have %s (%c).", o_name, index_to_label(item_new)); 2154 2155 /* Handle stuff */ 2156 handle_stuff(); 2157 2158 /* Remove the items from the home */ 2159 store_item_increase(STORE_HOME, item, -amt); 2160 store_item_optimize(STORE_HOME, item); 2161 2162 event_signal(EVENT_INVENTORY); 2163 event_signal(EVENT_EQUIPMENT); 2164 } 2165 2166 /* 1962 2167 * Buy an object from a store 1963 2168 */ 1964 2169 static bool store_purchase(int item) 1965 2170 { 1966 int amt, item_new, num; 1967 1968 store_type *st_ptr = &store[store_current]; 2171 int amt, num; 1969 2172 1970 2173 object_type *o_ptr; 1971 2174 1972 object_type *i_ptr;1973 2175 object_type object_type_body; 2176 object_type *i_ptr = &object_type_body; 1974 2177 1975 2178 char o_name[80]; 1976 2179 1977 2180 s32b price; 2181 2182 int this_store = current_store(); 2183 2184 store_type *st_ptr; 2185 2186 if (this_store == STORE_NONE) 2187 { 2188 msg_print("You cannot purchase items when not in a store."); 2189 return FALSE; 2190 } 2191 2192 st_ptr = &store[this_store]; 1978 2193 1979 2194 /* Get the actual object */ … … 1985 2200 prt("", 0, 0); 1986 2201 1987 if ( store_current== STORE_HOME)2202 if (this_store == STORE_HOME) 1988 2203 { 1989 2204 amt = o_ptr->number; … … 2022 2237 2023 2238 strnfmt(o_name, sizeof o_name, "%s how many%s? (max %d) ", 2024 ( store_current== STORE_HOME) ? "Take" : "Buy",2239 (this_store == STORE_HOME) ? "Take" : "Buy", 2025 2240 num ? format(" (you have %d)", num) : "", amt); 2026 2241 … … 2031 2246 if (amt <= 0) return FALSE; 2032 2247 2033 /* Get local object */2034 i_ptr = &object_type_body;2035 2036 2248 /* Get desired object */ 2037 object_copy(i_ptr, o_ptr); 2038 2039 /* 2040 * XXX Stacking 2041 * If a rod or wand, allocate total maximum timeouts or charges 2042 * between those purchased and left on the shelf. 2043 */ 2044 reduce_charges(i_ptr, i_ptr->number - amt); 2045 2046 /* Modify quantity */ 2047 i_ptr->number = amt; 2249 object_copy_amt(i_ptr, o_ptr, amt); 2048 2250 2049 2251 /* Ensure we have room */ … … 2059 2261 2060 2262 /* Attempt to buy it */ 2061 if ( store_current!= STORE_HOME)2263 if (this_store != STORE_HOME) 2062 2264 { 2063 2265 u32b price; … … 2079 2281 if (!response) return FALSE; 2080 2282 2081 2082 /* Spend the money */ 2083 p_ptr->au -= price; 2084 2085 /* Update the display */ 2086 store_flags |= STORE_GOLD_CHANGE; 2087 2088 /* Buying an object makes you aware of it */ 2089 object_aware(i_ptr); 2090 2091 /* Combine / Reorder the pack (later) */ 2092 p_ptr->notice |= (PN_COMBINE | PN_REORDER); 2093 2094 /* The object no longer belongs to the store */ 2095 i_ptr->ident &= ~(IDENT_STORE); 2096 2097 /* Message */ 2098 if (one_in_(3)) message(MSG_STORE5, 0, ONE_OF(comment_accept)); 2099 msg_format("You bought %s for %ld gold.", o_name, (long)price); 2100 2101 /* Erase the inscription */ 2102 i_ptr->note = 0; 2103 2104 /* Give it to the player */ 2105 item_new = inven_carry(i_ptr); 2106 2107 /* Message */ 2108 object_desc(o_name, sizeof(o_name), &inventory[item_new], TRUE, ODESC_FULL); 2109 msg_format("You have %s (%c).", o_name, index_to_label(item_new)); 2283 cmd_insert(CMD_BUY, item, amt); 2110 2284 store_flags |= STORE_KEEP_PROMPT; 2111 2112 /* Now, reduce the original stack's pval */2113 if ((o_ptr->tval == TV_ROD) ||2114 (o_ptr->tval == TV_WAND) ||2115 (o_ptr->tval == TV_STAFF))2116 {2117 o_ptr->pval -= i_ptr->pval;2118 }2119 2120 /* Handle stuff */2121 handle_stuff();2122 2123 /* Remove the bought objects from the store */2124 store_item_increase(store_current, item, -amt);2125 store_item_optimize(store_current, item);2126 2127 /* Store is empty */2128 if (st_ptr->stock_num == 0)2129 {2130 int i;2131 2132 /* Shuffle */2133 if (one_in_(STORE_SHUFFLE))2134 {2135 /* Message */2136 msg_print("The shopkeeper retires.");2137 2138 /* Shuffle the store */2139 store_shuffle(store_current);2140 store_flags |= STORE_FRAME_CHANGE;2141 }2142 2143 /* Maintain */2144 else2145 {2146 /* Message */2147 msg_print("The shopkeeper brings out some new stock.");2148 }2149 2150 /* New inventory */2151 for (i = 0; i < 10; ++i)2152 {2153 /* Maintain the store */2154 store_maint(store_current);2155 }2156 }2157 2285 } 2158 2286 … … 2160 2288 else 2161 2289 { 2162 /* Distribute charges of wands, staves, or rods */ 2163 distribute_charges(o_ptr, i_ptr, amt); 2164 2165 /* Give it to the player */ 2166 item_new = inven_carry(i_ptr); 2167 2168 /* Describe just the result */ 2169 object_desc(o_name, sizeof(o_name), &inventory[item_new], TRUE, ODESC_FULL); 2170 2171 /* Message */ 2172 msg_format("You have %s (%c).", o_name, index_to_label(item_new)); 2290 cmd_insert(CMD_RETRIEVE, item, amt); 2173 2291 store_flags |= STORE_KEEP_PROMPT; 2174 2175 /* Handle stuff */ 2176 handle_stuff(); 2177 2178 /* Remove the items from the home */ 2179 store_item_increase(store_current, item, -amt); 2180 store_item_optimize(store_current, item); 2181 } 2292 } 2293 2294 /* Not kicked out */ 2295 return TRUE; 2296 } 2297 2298 2299 2300 /* 2301 * Determine if the current store will purchase the given object 2302 */ 2303 static bool store_will_buy_tester(const object_type *o_ptr) 2304 { 2305 int this_store = current_store(); 2306 2307 if (this_store == STORE_NONE) return FALSE; 2308 2309 return store_will_buy(this_store, o_ptr); 2310 } 2311 2312 /* 2313 * Sell an item to the current store. 2314 */ 2315 void do_cmd_sell(cmd_code code, cmd_arg args[]) 2316 { 2317 int item = args[0].item; 2318 int amt = args[1].number; 2319 object_type sold_item; 2320 int price, dummy, value; 2321 char o_name[120]; 2322 2323 /* Get the item */ 2324 object_type *o_ptr = object_from_item_idx(item); 2325 2326 /* Cannot remove cursed objects */ 2327 if ((item >= INVEN_WIELD) && cursed_p(o_ptr)) 2328 { 2329 msg_print("Hmmm, it seems to be cursed."); 2330 return; 2331 } 2332 2333 /* Check we are somewhere we can sell the items. */ 2334 if (current_store() == STORE_NONE) 2335 { 2336 msg_print("You cannot sell items when not in a store."); 2337 return; 2338 } 2339 2340 /* Check the store wants the items being sold */ 2341 if (!store_will_buy(current_store(), o_ptr)) 2342 { 2343 msg_print("I do not wish to purchase this item."); 2344 return; 2345 } 2346 2347 /* Get a copy of the object representing the number being sold */ 2348 object_copy_amt(&sold_item, o_ptr, amt); 2349 2350 /* Check if the store has space for the items */ 2351 if (!store_check_num(STORE_HOME, &sold_item)) 2352 { 2353 msg_print("I have not the room in my store to keep it."); 2354 return; 2355 } 2356 2357 price = price_item(&sold_item, TRUE, amt); 2358 2359 /* Get some money */ 2360 p_ptr->au += price; 2361 2362 /* Update the display */ 2363 store_flags |= STORE_GOLD_CHANGE; 2364 2365 /* Identify original object */ 2366 object_aware(o_ptr); 2367 object_known(o_ptr); 2368 2369 /* Update the auto-history if selling an artifact that was previously un-IDed. (Ouch!) */ 2370 if (artifact_p(o_ptr)) 2371 history_add_artifact(o_ptr->name1, TRUE); 2372 2373 /* Combine / Reorder the pack (later) */ 2374 p_ptr->notice |= (PN_COMBINE | PN_REORDER); 2375 2376 /* Redraw stuff */ 2377 p_ptr->redraw |= (PR_INVEN | PR_EQUIP); 2378 2379 /* The object belongs to the store now */ 2380 sold_item.ident |= IDENT_STORE; 2381 2382 /* Get the "apparent" value */ 2383 dummy = object_value(&sold_item, amt); 2384 2385 /* Take a new copy of the now known-about object. */ 2386 object_copy_amt(&sold_item, o_ptr, amt); 2387 2388 /* 2389 * Hack -- Allocate charges between those wands, staves, or rods 2390 * sold and retained, unless all are being sold. 2391 */ 2392 distribute_charges(o_ptr, &sold_item, amt); 2393 2394 /* Get the "actual" value */ 2395 value = object_value(&sold_item, amt); 2396 2397 /* Get the description all over again */ 2398 object_desc(o_name, sizeof(o_name), &sold_item, TRUE, ODESC_FULL); 2399 2400 /* Describe the result (in message buffer) */ 2401 msg_format("You sold %s (%c) for %ld gold.", 2402 o_name, index_to_label(item), (long)price); 2403 2404 /* Analyze the prices (and comment verbally) */ 2405 purchase_analyze(price, value, dummy); 2406 2407 /* Set squelch flag */ 2408 p_ptr->notice |= PN_SQUELCH; 2409 2410 /* Take the object from the player */ 2411 inven_item_increase(item, -amt); 2412 inven_item_optimize(item); 2413 2414 /* Handle stuff */ 2415 handle_stuff(); 2416 2417 /* The store gets that (known) object */ 2418 store_carry(current_store(), &sold_item); 2182 2419 2183 2420 event_signal(EVENT_INVENTORY); 2184 2421 event_signal(EVENT_EQUIPMENT); 2185 2186 /* Not kicked out */ 2187 return TRUE; 2188 } 2189 2190 2191 2192 /* 2193 * Determine if the current store will purchase the given object 2194 */ 2195 static bool store_will_buy_tester(const object_type *o_ptr) 2196 { 2197 return store_will_buy(store_current, o_ptr); 2198 } 2199 2422 } 2423 2424 /* 2425 * Stash an item in the home. 2426 */ 2427 void do_cmd_stash(cmd_code code, cmd_arg args[]) 2428 { 2429 int item = args[0].item; 2430 int amt = args[1].number; 2431 object_type dropped_item; 2432 object_type *o_ptr = object_from_item_idx(item); 2433 char o_name[120]; 2434 2435 /* Check we are somewhere we can stash items. */ 2436 if (current_store() != STORE_HOME) 2437 { 2438 msg_print("You are not in your home."); 2439 return; 2440 } 2441 2442 /* Cannot remove cursed objects */ 2443 if ((item >= INVEN_WIELD) && cursed_p(o_ptr)) 2444 { 2445 msg_print("Hmmm, it seems to be cursed."); 2446 return; 2447 } 2448 2449 /* Get a copy of the object representing the number being sold */ 2450 object_copy_amt(&dropped_item, o_ptr, amt); 2451 2452 if (!store_check_num(STORE_HOME, &dropped_item)) 2453 { 2454 msg_print("Your home is full."); 2455 return; 2456 } 2457 2458 /* Distribute charges of wands/staves/rods */ 2459 distribute_charges(o_ptr, &dropped_item, amt); 2460 2461 /* Describe */ 2462 msg_format("You drop %s (%c).", o_name, index_to_label(item)); 2463 2464 /* Take it from the players inventory */ 2465 inven_item_increase(item, -amt); 2466 inven_item_optimize(item); 2467 2468 /* Handle stuff */ 2469 handle_stuff(); 2470 2471 /* Let the home carry it */ 2472 home_carry(&dropped_item); 2473 2474 event_signal(EVENT_INVENTORY); 2475 event_signal(EVENT_EQUIPMENT); 2476 } 2200 2477 2201 2478 /* … … 2208 2485 2209 2486 object_type *o_ptr; 2210 object_type *i_ptr;2211 2487 object_type object_type_body; 2488 object_type *i_ptr = &object_type_body; 2212 2489 2213 2490 char o_name[120]; … … 2216 2493 const char *reject = "You have nothing that I want. "; 2217 2494 const char *prompt = "Sell which item? "; 2495 2496 int this_store = current_store(); 2497 2498 if (this_store == STORE_NONE) 2499 { 2500 msg_print("You cannot sell items when not in a store."); 2501 return; 2502 } 2218 2503 2219 2504 /* Clear all current messages */ … … 2221 2506 prt("", 0, 0); 2222 2507 2223 if ( store_current== STORE_HOME)2508 if (this_store == STORE_HOME) 2224 2509 prompt = "Drop which item? "; 2225 2510 else … … 2255 2540 if (amt <= 0) return; 2256 2541 2257 2258 /* Get local object */ 2259 i_ptr = &object_type_body; 2260 2261 /* Get a copy of the object */ 2262 object_copy(i_ptr, o_ptr); 2263 2264 /* Modify quantity */ 2265 i_ptr->number = amt; 2266 2267 2268 /* 2269 * XXX Stacking 2270 * If a rod, wand, or staff, allocate total maximum timeouts or charges 2271 * to those being sold. 2272 */ 2273 if ((o_ptr->tval == TV_ROD) || 2274 (o_ptr->tval == TV_WAND) || 2275 (o_ptr->tval == TV_STAFF)) 2276 { 2277 i_ptr->pval = o_ptr->pval * amt / o_ptr->number; 2542 /* Get a copy of the object representing the number being sold */ 2543 object_copy_amt(i_ptr, object_from_item_idx(item), amt); 2544 2545 if (!store_check_num(this_store, i_ptr)) 2546 { 2547 store_flags |= STORE_KEEP_PROMPT; 2548 2549 if (this_store == STORE_HOME) 2550 msg_print("Your home is full."); 2551 2552 else 2553 msg_print("I have not the room in my store to keep it."); 2554 2555 return; 2278 2556 } 2279 2557 … … 2281 2559 object_desc(o_name, sizeof(o_name), i_ptr, TRUE, ODESC_FULL); 2282 2560 2283 2284 /* Is there room in the store (or the home?) */2285 if (!store_check_num(store_current, i_ptr))2286 {2287 store_flags |= STORE_KEEP_PROMPT;2288 2289 if (store_current == STORE_HOME)2290 msg_print("Your home is full.");2291 2292 else2293 msg_print("I have not the room in my store to keep it.");2294 2295 return;2296 }2297 2298 2299 2561 /* Real store */ 2300 if (store_current != STORE_HOME) 2301 { 2302 u32b price, dummy, value; 2303 2562 if (this_store != STORE_HOME) 2563 { 2304 2564 /* Extract the value of the items */ 2305 price = price_item(i_ptr, TRUE, amt);2565 u32b price = price_item(i_ptr, TRUE, amt); 2306 2566 2307 2567 screen_save(); … … 2319 2579 screen_load(); 2320 2580 2321 /* Get some money */ 2322 p_ptr->au += price; 2323 2324 /* Update the display */ 2325 store_flags |= STORE_GOLD_CHANGE; 2326 2327 /* Identify original object */ 2328 object_aware(o_ptr); 2329 object_known(o_ptr); 2330 2331 /* Update the auto-history if selling an artifact that was previously un-IDed. (Ouch!) */ 2332 if (artifact_p(o_ptr)) 2333 history_add_artifact(o_ptr->name1, TRUE); 2334 2335 /* Combine / Reorder the pack (later) */ 2336 p_ptr->notice |= (PN_COMBINE | PN_REORDER); 2337 2338 /* Redraw stuff */ 2339 p_ptr->redraw |= (PR_INVEN | PR_EQUIP); 2340 2341 /* The object belongs to the store now */ 2342 i_ptr->ident |= IDENT_STORE; 2343 2344 /* Get the "apparent" value */ 2345 dummy = object_value(i_ptr, i_ptr->number); 2346 2347 /* Get local object */ 2348 i_ptr = &object_type_body; 2349 2350 /* Get a copy of the object */ 2351 object_copy(i_ptr, o_ptr); 2352 2353 /* Modify quantity */ 2354 i_ptr->number = amt; 2355 2356 /* 2357 * Hack -- Allocate charges between those wands, staves, or rods 2358 * sold and retained, unless all are being sold. 2359 */ 2360 distribute_charges(o_ptr, i_ptr, amt); 2361 2362 /* Get the "actual" value */ 2363 value = object_value(i_ptr, i_ptr->number); 2364 2365 /* Get the description all over again */ 2366 object_desc(o_name, sizeof(o_name), i_ptr, TRUE, ODESC_FULL); 2367 2368 /* Describe the result (in message buffer) */ 2369 msg_format("You sold %s (%c) for %ld gold.", 2370 o_name, index_to_label(item), (long)price); 2581 cmd_insert(CMD_SELL, item, amt); 2582 2371 2583 store_flags |= STORE_KEEP_PROMPT; 2372 2373 /* Analyze the prices (and comment verbally) */2374 purchase_analyze(price, value, dummy);2375 2376 /* Set squelch flag */2377 p_ptr->notice |= PN_SQUELCH;2378 2379 /* Take the object from the player */2380 inven_item_increase(item, -amt);2381 inven_item_optimize(item);2382 2383 /* Handle stuff */2384 handle_stuff();2385 2386 /* The store gets that (known) object */2387 store_carry(store_current, i_ptr);2388 2584 } 2389 2585 … … 2391 2587 else 2392 2588 { 2393 /* Distribute charges of wands/staves/rods */ 2394 distribute_charges(o_ptr, i_ptr, amt); 2395 2396 /* Describe */ 2397 msg_format("You drop %s (%c).", o_name, index_to_label(item)); 2398 store_flags |= STORE_KEEP_PROMPT; 2399 2400 /* Take it from the players inventory */ 2401 inven_item_increase(item, -amt); 2402 inven_item_optimize(item); 2403 2404 /* Handle stuff */ 2405 handle_stuff(); 2406 2407 /* Let the home carry it */ 2408 home_carry(i_ptr); 2409 } 2410 2411 event_signal(EVENT_INVENTORY); 2412 event_signal(EVENT_EQUIPMENT); 2589 cmd_insert(CMD_STASH, item, amt); 2590 } 2413 2591 } 2414 2592 … … 2419 2597 static void store_examine(int item) 2420 2598 { 2421 store_type *st_ptr = &store[ store_current];2599 store_type *st_ptr = &store[current_store()]; 2422 2600 object_type *o_ptr; 2423 2601 bool info_known; … … 2439 2617 /* Show full info in most stores, but normal info in player home */ 2440 2618 info_known = object_info(o_ptr, 2441 ( store_current!= STORE_HOME) ? TRUE : FALSE);2619 (current_store() != STORE_HOME) ? TRUE : FALSE); 2442 2620 2443 2621 if (!info_known) … … 2461 2639 * Flee the store when it overflows. 2462 2640 */ 2463 bool store_overflow(void)2641 static bool store_overflow(void) 2464 2642 { 2465 2643 int item = INVEN_PACK; … … 2468 2646 2469 2647 /* Flee from the store */ 2470 if ( store_current!= STORE_HOME)2648 if (current_store() != STORE_HOME) 2471 2649 { 2472 2650 /* Leave */ … … 2476 2654 2477 2655 /* Flee from the home */ 2478 else if (!store_check_num( store_current, o_ptr))2656 else if (!store_check_num(current_store(), o_ptr)) 2479 2657 { 2480 2658 /* Leave */ … … 2535 2713 bool equip_toggle = FALSE; 2536 2714 bool redraw = FALSE; 2715 bool command_processed = FALSE; 2537 2716 2538 2717 /* Parse the command */ … … 2542 2721 case ESCAPE: 2543 2722 { 2544 returnTRUE;2723 command_processed = TRUE; 2545 2724 break; 2546 2725 } … … 2551 2730 { 2552 2731 store_sell(); 2553 return TRUE; 2732 command_processed = TRUE; 2733 break; 2554 2734 } 2555 2735 … … 2559 2739 { 2560 2740 /* On successful purchase, redraw */ 2561 if (store_purchase(oid)) 2562 return TRUE; 2563 2741 command_processed = store_purchase(oid); 2564 2742 break; 2565 2743 } … … 2579 2757 Term_clear(); 2580 2758 store_flags |= (STORE_FRAME_CHANGE | STORE_GOLD_CHANGE); 2581 return TRUE; 2582 2759 command_processed = TRUE; 2583 2760 break; 2584 2761 } … … 2713 2890 store_flags |= STORE_INIT_CHANGE; 2714 2891 2715 return TRUE; 2892 command_processed = TRUE; 2893 break; 2716 2894 } 2717 2895 … … 2762 2940 } 2763 2941 2764 return TRUE; 2765 } 2766 2942 return command_processed; 2943 } 2767 2944 2768 2945 … … 2772 2949 void do_cmd_store(cmd_code code, cmd_arg args[]) 2773 2950 { 2774 int py = p_ptr->py;2775 int px = p_ptr->px;2776 2777 2951 bool leave = FALSE; 2778 2952 2953 /* Take note of the store number from the terrain feature */ 2954 int this_store = current_store(); 2955 2779 2956 /* Verify that there is a store */ 2780 if (!((cave_feat[py][px] >= FEAT_SHOP_HEAD) && 2781 (cave_feat[py][px] <= FEAT_SHOP_TAIL))) 2957 if (this_store == STORE_NONE) 2782 2958 { 2783 2959 msg_print("You see no store here."); 2784 2960 return; 2785 2961 } 2786 2787 2962 2788 2963 /* Check if we can enter the store */ … … 2807 2982 2808 2983 2809 /*** Set up state ***/2810 2811 /* XXX Take note of the store number from the terrain feature */2812 store_current = (cave_feat[py][px] - FEAT_SHOP_HEAD);2813 2814 2984 2815 2985 … … 2830 3000 int cursor = 0; 2831 3001 2832 store_type *st_ptr = &store[ store_current];3002 store_type *st_ptr = &store[this_store]; 2833 3003 2834 3004 /* Wipe the menu and set it up */ … … 2842 3012 2843 3013 /* Say a friendly hello. */ 2844 if (store_current != STORE_HOME) prt_welcome(store_owner(store_current)); 3014 if (this_store != STORE_HOME) 3015 prt_welcome(store_owner(this_store)); 2845 3016 2846 3017 /* Loop */
