Changeset 1435 for trunk

Show
Ignore:
Timestamp:
06/08/09 21:17:05 (9 months ago)
Author:
ajps
Message:

Move the store commands (buying, selling, and home equivalents) to the new command system.

Location:
trunk/src
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/cmd3.c

    r1430 r1435  
    204204        object_type *o_ptr; 
    205205 
    206         object_type *i_ptr; 
    207         object_type object_type_body; 
     206        object_type destroyed_obj; 
    208207 
    209208        char o_name[120]; 
     
    234233        }        
    235234 
    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); 
    253238 
    254239        /* Artifacts cannot be destroyed */ 
     
    299284        object_type *o_ptr; 
    300285 
    301         object_type *i_ptr; 
    302         object_type object_type_body; 
     286        object_type obj_to_destroy; 
    303287 
    304288        char o_name[120]; 
     
    325309        if (amt <= 0) return; 
    326310 
    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); 
    344314 
    345315        /* Verify destruction */ 
  • trunk/src/cmds.h

    r1417 r1435  
    132132/* store.c */ 
    133133extern void do_cmd_store(cmd_code code, cmd_arg args[]); 
     134extern void do_cmd_sell(cmd_code code, cmd_arg args[]); 
     135extern void do_cmd_stash(cmd_code code, cmd_arg args[]); 
     136extern void do_cmd_buy(cmd_code code, cmd_arg args[]); 
     137extern void do_cmd_retrieve(cmd_code code, cmd_arg args[]); 
    134138 
    135139/* Types of item use */ 
  • trunk/src/externs.h

    r1433 r1435  
    566566void store_shuffle(int which); 
    567567void store_maint(int which); 
    568 bool store_overflow(void); 
    569568 
    570569/* target.c */ 
  • trunk/src/game-cmd.c

    r1431 r1435  
    213213                case CMD_DROP: 
    214214                case CMD_DESTROY: 
     215                case CMD_SELL: 
     216                case CMD_BUY: 
     217                case CMD_STASH: 
     218                case CMD_RETRIEVE: 
    215219                { 
    216220                        /* TODO: Number should probably be replaced by 'repeat'ing */ 
     
    284288        { CMD_STUDY_BOOK, do_cmd_study_book }, 
    285289        { 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 }, 
    286294}; 
    287295 
  • trunk/src/game-cmd.h

    r1419 r1435  
    7474        CMD_ENTER_STORE, 
    7575        CMD_ALTER, 
    76          
     76 
     77    /* Store commands */         
     78        CMD_SELL, 
     79        CMD_BUY, 
     80        CMD_STASH, 
     81        CMD_RETRIEVE, 
    7782 
    7883        /* Hors categorie Commands */ 
  • trunk/src/object/obj-util.c

    r1427 r1435  
    17751775        /* Copy the structure */ 
    17761776        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 */ 
     1785void 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); 
    17771795} 
    17781796 
  • trunk/src/object/object.h

    r1424 r1435  
    125125void object_wipe(object_type *o_ptr); 
    126126void object_copy(object_type *o_ptr, const object_type *j_ptr); 
     127void object_copy_amt(object_type *dst, object_type *src, int amt); 
    127128void object_prep(object_type *o_ptr, int k_idx); 
    128129s16b floor_carry(int y, int x, object_type *j_ptr); 
  • trunk/src/store.c

    r1419 r1435  
    7474/** Variables to maintain state XXX ***/ 
    7575 
    76 /* Current store number */ 
    77 static int store_current; 
    78  
    7976/* Flags for the display */ 
    8077static u16b store_flags; 
     
    384381 
    385382 
     383#define STORE_NONE -1 
     384 
     385/* Get the current store number, or STORE_NONE if not in a store */ 
     386static 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} 
    386394 
    387395 
     
    407415        int adjust; 
    408416        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); 
    411423 
    412424 
     
    422434 
    423435        /* Add in the charisma factor */ 
    424         if (store_current == STORE_B_MARKET) 
     436        if (this_store == STORE_B_MARKET) 
    425437                adjust = 150; 
    426438        else 
     
    436448 
    437449                /* 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; 
    439451        } 
    440452 
     
    446458 
    447459                /* 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; 
    449461        } 
    450462 
     
    15851597 
    15861598        /* Add space for for prices */ 
    1587         if (store_current != STORE_HOME) 
     1599        if (current_store() != STORE_HOME) 
    15881600                scr_places_x[LOC_WEIGHT] -= 10; 
    15891601 
     
    16271639        byte colour; 
    16281640 
    1629         store_type *st_ptr = &store[store_current]; 
     1641        int this_store = current_store();  
     1642        store_type *st_ptr = &store[this_store]; 
    16301643 
    16311644        (void)menu; 
     
    16371650 
    16381651        /* 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; 
    16401653        else desc = ODESC_FULL | ODESC_STORE; 
    16411654        object_desc(o_name, sizeof(o_name), o_ptr, TRUE, desc); 
     
    16501663 
    16511664        /* Describe an object (fully) in a store */ 
    1652         if (store_current != STORE_HOME) 
     1665        if (this_store != STORE_HOME) 
    16531666        { 
    16541667                /* Extract the "minimum" price */ 
     
    16771690{ 
    16781691        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); 
    16811695 
    16821696        /* Clear screen */ 
     
    16841698 
    16851699        /* The "Home" is special */ 
    1686         if (store_current == STORE_HOME) 
     1700        if (this_store == STORE_HOME) 
    16871701        { 
    16881702                /* Put the owner name */ 
     
    16991713        else 
    17001714        { 
    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); 
    17021716                const char *owner_name = &b_name[ot_ptr->owner_name]; 
    17031717 
     
    17501764        text_out_c(TERM_L_GREEN, "p"); 
    17511765 
    1752         if (store_current == STORE_HOME) text_out("' picks up"); 
     1766        if (current_store() == STORE_HOME) text_out("' picks up"); 
    17531767        else text_out("' purchases"); 
    17541768 
     
    17561770 
    17571771        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"); 
    17591773        else text_out("' sells"); 
    17601774 
     
    19601974 
    19611975/* 
     1976 * Buy the item with the given index from the current store's inventory. 
     1977 */ 
     1978void 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 */ 
     2108void 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/* 
    19622167 * Buy an object from a store 
    19632168 */ 
    19642169static bool store_purchase(int item) 
    19652170{ 
    1966         int amt, item_new, num; 
    1967  
    1968         store_type *st_ptr = &store[store_current]; 
     2171        int amt, num; 
    19692172 
    19702173        object_type *o_ptr; 
    19712174 
    1972         object_type *i_ptr; 
    19732175        object_type object_type_body; 
     2176        object_type *i_ptr = &object_type_body; 
    19742177 
    19752178        char o_name[80]; 
    19762179 
    19772180        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]; 
    19782193 
    19792194        /* Get the actual object */ 
     
    19852200        prt("", 0, 0); 
    19862201 
    1987         if (store_current == STORE_HOME) 
     2202        if (this_store == STORE_HOME) 
    19882203        { 
    19892204                amt = o_ptr->number; 
     
    20222237 
    20232238        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", 
    20252240                num ? format(" (you have %d)", num) : "", amt); 
    20262241 
     
    20312246        if (amt <= 0) return FALSE; 
    20322247 
    2033         /* Get local object */ 
    2034         i_ptr = &object_type_body; 
    2035  
    20362248        /* 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); 
    20482250 
    20492251        /* Ensure we have room */ 
     
    20592261 
    20602262        /* Attempt to buy it */ 
    2061         if (store_current != STORE_HOME) 
     2263        if (this_store != STORE_HOME) 
    20622264        { 
    20632265                u32b price; 
     
    20792281                if (!response) return FALSE; 
    20802282 
    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); 
    21102284                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                         else 
    2145                         { 
    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                 } 
    21572285        } 
    21582286 
     
    21602288        else 
    21612289        { 
    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); 
    21732291                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 */ 
     2303static 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 */ 
     2315void 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); 
    21822419 
    21832420        event_signal(EVENT_INVENTORY); 
    21842421        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 */ 
     2427void 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} 
    22002477 
    22012478/* 
     
    22082485 
    22092486        object_type *o_ptr; 
    2210         object_type *i_ptr; 
    22112487        object_type object_type_body; 
     2488        object_type *i_ptr = &object_type_body; 
    22122489 
    22132490        char o_name[120]; 
     
    22162493        const char *reject = "You have nothing that I want. "; 
    22172494        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        } 
    22182503 
    22192504        /* Clear all current messages */ 
     
    22212506        prt("", 0, 0); 
    22222507 
    2223         if (store_current == STORE_HOME) 
     2508        if (this_store == STORE_HOME) 
    22242509                prompt = "Drop which item? "; 
    22252510        else 
     
    22552540        if (amt <= 0) return; 
    22562541 
    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; 
    22782556        } 
    22792557 
     
    22812559        object_desc(o_name, sizeof(o_name), i_ptr, TRUE, ODESC_FULL); 
    22822560 
    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                 else 
    2293                         msg_print("I have not the room in my store to keep it."); 
    2294  
    2295                 return; 
    2296         } 
    2297  
    2298  
    22992561        /* Real store */ 
    2300         if (store_current != STORE_HOME) 
    2301         { 
    2302                 u32b price, dummy, value; 
    2303  
     2562        if (this_store != STORE_HOME) 
     2563        { 
    23042564                /* Extract the value of the items */ 
    2305                 price = price_item(i_ptr, TRUE, amt); 
     2565                u32b price = price_item(i_ptr, TRUE, amt); 
    23062566 
    23072567                screen_save(); 
     
    23192579                screen_load(); 
    23202580 
    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 
    23712583                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); 
    23882584        } 
    23892585 
     
    23912587        else 
    23922588        { 
    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        } 
    24132591} 
    24142592 
     
    24192597static void store_examine(int item) 
    24202598{ 
    2421         store_type *st_ptr = &store[store_current]; 
     2599        store_type *st_ptr = &store[current_store()]; 
    24222600        object_type *o_ptr; 
    24232601        bool info_known; 
     
    24392617        /* Show full info in most stores, but normal info in player home */ 
    24402618        info_known = object_info(o_ptr, 
    2441                         (store_current != STORE_HOME) ? TRUE : FALSE); 
     2619                        (current_store() != STORE_HOME) ? TRUE : FALSE); 
    24422620 
    24432621        if (!info_known) 
     
    24612639 * Flee the store when it overflows. 
    24622640 */ 
    2463 bool store_overflow(void) 
     2641static bool store_overflow(void) 
    24642642{ 
    24652643        int item = INVEN_PACK; 
     
    24682646 
    24692647        /* Flee from the store */ 
    2470         if (store_current != STORE_HOME) 
     2648        if (current_store() != STORE_HOME) 
    24712649        { 
    24722650                /* Leave */ 
     
    24762654 
    24772655        /* Flee from the home */ 
    2478         else if (!store_check_num(store_current, o_ptr)) 
     2656        else if (!store_check_num(current_store(), o_ptr)) 
    24792657        { 
    24802658                /* Leave */ 
     
    25352713        bool equip_toggle = FALSE; 
    25362714        bool redraw = FALSE; 
     2715        bool command_processed = FALSE; 
    25372716 
    25382717        /* Parse the command */ 
     
    25422721                case ESCAPE: 
    25432722                { 
    2544                         return TRUE; 
     2723                        command_processed = TRUE; 
    25452724                        break; 
    25462725                } 
     
    25512730                { 
    25522731                        store_sell(); 
    2553                         return TRUE; 
     2732                        command_processed = TRUE; 
     2733                        break; 
    25542734                } 
    25552735 
     
    25592739                { 
    25602740                        /* On successful purchase, redraw */ 
    2561                         if (store_purchase(oid)) 
    2562                                 return TRUE; 
    2563  
     2741                        command_processed = store_purchase(oid); 
    25642742                        break; 
    25652743                } 
     
    25792757                        Term_clear(); 
    25802758                        store_flags |= (STORE_FRAME_CHANGE | STORE_GOLD_CHANGE); 
    2581                         return TRUE; 
    2582  
     2759                        command_processed = TRUE; 
    25832760                        break; 
    25842761                } 
     
    27132890                        store_flags |= STORE_INIT_CHANGE; 
    27142891 
    2715                         return TRUE; 
     2892                        command_processed = TRUE; 
     2893                        break; 
    27162894                } 
    27172895 
     
    27622940        } 
    27632941         
    2764         return TRUE; 
    2765 } 
    2766  
     2942        return command_processed; 
     2943} 
    27672944 
    27682945 
     
    27722949void do_cmd_store(cmd_code code, cmd_arg args[]) 
    27732950{ 
    2774         int py = p_ptr->py; 
    2775         int px = p_ptr->px; 
    2776  
    27772951        bool leave = FALSE; 
    27782952 
     2953        /* Take note of the store number from the terrain feature */ 
     2954        int this_store = current_store(); 
     2955 
    27792956        /* 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) 
    27822958        { 
    27832959                msg_print("You see no store here."); 
    27842960                return; 
    27852961        } 
    2786  
    27872962 
    27882963        /* Check if we can enter the store */ 
     
    28072982 
    28082983 
    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  
    28142984 
    28152985 
     
    28303000        int cursor = 0; 
    28313001 
    2832         store_type *st_ptr = &store[store_current]; 
     3002        store_type *st_ptr = &store[this_store]; 
    28333003 
    28343004        /* Wipe the menu and set it up */ 
     
    28423012 
    28433013        /* 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)); 
    28453016 
    28463017        /* Loop */