OSDN Git Service

Sniper gets 'Lion Slayer' at Old Castle Quest
[hengband/hengband.git] / src / store.c
index 695a5d9..b0e6138 100644 (file)
 
 #include "angband.h"
 
+#define MIN_STOCK 12
 
-#ifdef JP
-/* ²¼¤ÎÊý¤«¤é°ÜÆ°¤·¤Æ¤­¤Þ¤·¤¿ */
 static int cur_store_num = 0;
 static int store_top = 0;
+static int store_bottom = 0;
+static int xtra_stock = 0;
 static store_type *st_ptr = NULL;
-static owner_type *ot_ptr = NULL;
-#endif
+static const owner_type *ot_ptr = NULL;
 static s16b old_town_num = 0;
 static s16b inner_town_num = 0;
 #define RUMOR_CHANCE 8
@@ -306,8 +306,6 @@ static cptr comment_6[MAX_COMMENT_6] =
  */
 static void say_comment_1(void)
 {
-       char rumour[1024];
-
 #ifdef JP
        /* ¥Ö¥é¥Ã¥¯¥Þ¡¼¥±¥Ã¥È¤Î¤È¤­¤ÏÊ̤Υá¥Ã¥»¡¼¥¸¤ò½Ð¤¹ */
        if ( cur_store_num == STORE_BLACK ) {
@@ -324,19 +322,11 @@ static void say_comment_1(void)
        if (one_in_(RUMOR_CHANCE))
        {
 #ifdef JP
-msg_print("Ź¼ç¤Ï¼ª¤¦¤Á¤·¤¿:");
+               msg_print("Ź¼ç¤Ï¼ª¤¦¤Á¤·¤¿:");
 #else
                msg_print("The shopkeeper whispers something into your ear:");
 #endif
-
-
-#ifdef JP
-if (!get_rnd_line_jonly("rumors_j.txt", 0, rumour, 10))
-#else
-               if (!get_rnd_line("rumors.txt", 0, rumour))
-#endif
-
-                       msg_print(rumour);
+               display_rumor(TRUE);
        }
 }
 
@@ -615,43 +605,12 @@ static void purchase_analyze(s32b price, s32b value, s32b guess)
 
 
 
-
-
-#ifdef JP
-/* ÆüËܸìÈǤξì¹ç¤Ï¾å¤ÎÊý¤Ë°ÜÆ°¤·¤Æ¤¢¤ê¤Þ¤¹ */
-#else
-/*
- * We store the current "store number" here so everyone can access it
- */
-static int cur_store_num = 7;
-
-/*
- * We store the current "store page" here so everyone can access it
- */
-static int store_top = 0;
-
-/*
- * We store the current "store pointer" here so everyone can access it
- */
-static store_type *st_ptr = NULL;
-
-/*
- * We store the current "owner type" here so everyone can access it
- */
-static owner_type *ot_ptr = NULL;
-#endif
-
 /*
  * We store the current "store feat" here so everyone can access it
  */
 static int cur_store_feat;
 
 
-
-
-
-
-
 /*
  * Buying and selling adjustments for race combinations.
  * Entry[owner][player] gives the basic "cost inflation".
@@ -661,7 +620,7 @@ static byte rgold_adj[MAX_RACES][MAX_RACES] =
        /*Hum, HfE, Elf,  Hal, Gno, Dwa, HfO, HfT, Dun, HiE, Barbarian,
         HfOg, HGn, HTn, Cyc, Yek, Klc, Kbd, Nbl, DkE, Drc, Mind Flayer,
         Imp,  Glm, Skl, Zombie, Vampire, Spectre, Fairy, Beastman, Ent,
-        Angel, Demon, Kuta*/
+        Angel, Demon, Kuta*/
 
        /* Human */
        { 100, 105, 105, 110, 113, 115, 120, 125, 100, 105, 100,
@@ -873,7 +832,7 @@ static byte rgold_adj[MAX_RACES][MAX_RACES] =
          110, 110, 112, 122, 110, 110, 110, 115, 110, 120, 120,
          110, 101, 115, 110 },
 
-       /* Kuta */
+       /* Kutar */
        { 110, 110, 105, 105, 110, 115, 115, 115, 110, 105, 110,
          115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115,
          115, 115, 125, 125, 125, 125, 105, 115, 105,  95, 140,
@@ -1021,6 +980,7 @@ static void mass_produce(object_type *o_ptr)
                case TV_CRUSADE_BOOK:
                case TV_MUSIC_BOOK:
                case TV_HISSATSU_BOOK:
+               case TV_HEX_BOOK:
                {
                        if (cost <= 50L) size += damroll(2, 3);
                        if (cost <= 500L) size += damroll(1, 3);
@@ -1088,12 +1048,6 @@ static void mass_produce(object_type *o_ptr)
                                if (cost < 1601L) size += damroll(1, 5);
                                else if (cost < 3201L) size += damroll(1, 3);
                        }
-
-                       /* Ensure that mass-produced rods and wands get the correct pvals. */
-                       if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND))
-                       {
-                               o_ptr->pval *= size;
-                       }
                        break;
                }
        }
@@ -1141,6 +1095,12 @@ msg_print("
 
        /* Save the total pile size */
        o_ptr->number = size - (size * discount / 100);
+
+       /* Ensure that mass-produced rods and wands get the correct pvals. */
+       if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND))
+       {
+               o_ptr->pval *= o_ptr->number;
+       }
 }
 
 
@@ -1247,6 +1207,15 @@ static int store_check_num(object_type *o_ptr)
        /* The "home" acts like the player */
        if ((cur_store_num == STORE_HOME) || (cur_store_num == STORE_MUSEUM))
        {
+               bool old_stack_force_notes = stack_force_notes;
+               bool old_stack_force_costs = stack_force_costs;
+
+               if (cur_store_num != STORE_HOME)
+               {
+                       stack_force_notes = FALSE;
+                       stack_force_costs = FALSE;
+               }
+
                /* Check all the items */
                for (i = 0; i < st_ptr->stock_num; i++)
                {
@@ -1254,7 +1223,22 @@ static int store_check_num(object_type *o_ptr)
                        j_ptr = &st_ptr->stock[i];
 
                        /* Can the new object be combined with the old one? */
-                       if (object_similar(j_ptr, o_ptr)) return -1;
+                       if (object_similar(j_ptr, o_ptr))
+                       {
+                               if (cur_store_num != STORE_HOME)
+                               {
+                                       stack_force_notes = old_stack_force_notes;
+                                       stack_force_costs = old_stack_force_costs;
+                               }
+
+                               return -1;
+                       }
+               }
+
+               if (cur_store_num != STORE_HOME)
+               {
+                       stack_force_notes = old_stack_force_notes;
+                       stack_force_costs = old_stack_force_costs;
                }
        }
 
@@ -1468,6 +1452,7 @@ static bool store_will_buy(object_type *o_ptr)
                                case TV_CRAFT_BOOK:
                                case TV_DAEMON_BOOK:
                                case TV_MUSIC_BOOK:
+                               case TV_HEX_BOOK:
                                case TV_AMULET:
                                case TV_RING:
                                case TV_STAFF:
@@ -1504,6 +1489,7 @@ static bool store_will_buy(object_type *o_ptr)
                                case TV_DAEMON_BOOK:
                                case TV_CRUSADE_BOOK:
                                case TV_MUSIC_BOOK:
+                               case TV_HEX_BOOK:
                                        break;
                                default:
                                        return (FALSE);
@@ -1520,6 +1506,165 @@ static bool store_will_buy(object_type *o_ptr)
 }
 
 
+/*
+ * Combine and reorder items in the home
+ */
+bool combine_and_reorder_home(int store_num)
+{
+       int         i, j, k;
+       s32b        o_value;
+       object_type forge, *o_ptr, *j_ptr;
+       bool        flag = FALSE, combined;
+       store_type  *old_st_ptr = st_ptr;
+       bool        old_stack_force_notes = stack_force_notes;
+       bool        old_stack_force_costs = stack_force_costs;
+
+       st_ptr = &town[1].store[store_num];
+       if (store_num != STORE_HOME)
+       {
+               stack_force_notes = FALSE;
+               stack_force_costs = FALSE;
+       }
+
+       do
+       {
+               combined = FALSE;
+
+               /* Combine the items in the home (backwards) */
+               for (i = st_ptr->stock_num - 1; i > 0; i--)
+               {
+                       /* Get the item */
+                       o_ptr = &st_ptr->stock[i];
+
+                       /* Skip empty items */
+                       if (!o_ptr->k_idx) continue;
+
+                       /* Scan the items above that item */
+                       for (j = 0; j < i; j++)
+                       {
+                               int max_num;
+
+                               /* Get the item */
+                               j_ptr = &st_ptr->stock[j];
+
+                               /* Skip empty items */
+                               if (!j_ptr->k_idx) continue;
+
+                               /*
+                                * Get maximum number of the stack if these
+                                * are similar, get zero otherwise.
+                                */
+                               max_num = object_similar_part(j_ptr, o_ptr);
+
+                               /* Can we (partialy) drop "o_ptr" onto "j_ptr"? */
+                               if (max_num && j_ptr->number < max_num)
+                               {
+                                       if (o_ptr->number + j_ptr->number <= max_num)
+                                       {
+                                               /* Add together the item counts */
+                                               object_absorb(j_ptr, o_ptr);
+
+                                               /* One object is gone */
+                                               st_ptr->stock_num--;
+
+                                               /* Slide everything down */
+                                               for (k = i; k < st_ptr->stock_num; k++)
+                                               {
+                                                       /* Structure copy */
+                                                       st_ptr->stock[k] = st_ptr->stock[k + 1];
+                                               }
+
+                                               /* Erase the "final" slot */
+                                               object_wipe(&st_ptr->stock[k]);
+                                       }
+                                       else
+                                       {
+                                               int old_num = o_ptr->number;
+                                               int remain = j_ptr->number + o_ptr->number - max_num;
+
+                                               /* Add together the item counts */
+                                               object_absorb(j_ptr, o_ptr);
+
+                                               o_ptr->number = remain;
+
+                                               /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
+                                               if (o_ptr->tval == TV_ROD)
+                                               {
+                                                       o_ptr->pval =  o_ptr->pval * remain / old_num;
+                                                       o_ptr->timeout = o_ptr->timeout * remain / old_num;
+                                               }
+
+                                               /* Hack -- if wands are stacking, combine the charges. -LM- */
+                                               else if (o_ptr->tval == TV_WAND)
+                                               {
+                                                       o_ptr->pval = o_ptr->pval * remain / old_num;
+                                               }
+                                       }
+
+                                       /* Take note */
+                                       combined = TRUE;
+
+                                       /* Done */
+                                       break;
+                               }
+                       }
+               }
+
+               flag |= combined;
+       }
+       while (combined);
+
+       /* Re-order the items in the home (forwards) */
+       for (i = 0; i < st_ptr->stock_num; i++)
+       {
+               /* Get the item */
+               o_ptr = &st_ptr->stock[i];
+
+               /* Skip empty slots */
+               if (!o_ptr->k_idx) continue;
+
+               /* Get the "value" of the item */
+               o_value = object_value(o_ptr);
+
+               /* Scan every occupied slot */
+               for (j = 0; j < st_ptr->stock_num; j++)
+               {
+                       if (object_sort_comp(o_ptr, o_value, &st_ptr->stock[j])) break;
+               }
+
+               /* Never move down */
+               if (j >= i) continue;
+
+               /* Take note */
+               flag = TRUE;
+
+               /* Get local object */
+               j_ptr = &forge;
+
+               /* Save a copy of the moving item */
+               object_copy(j_ptr, &st_ptr->stock[i]);
+
+               /* Slide the objects */
+               for (k = i; k > j; k--)
+               {
+                       /* Slide the item */
+                       object_copy(&st_ptr->stock[k], &st_ptr->stock[k - 1]);
+               }
+
+               /* Insert the moving item */
+               object_copy(&st_ptr->stock[j], j_ptr);
+       }
+
+       st_ptr = old_st_ptr;
+       if (store_num != STORE_HOME)
+       {
+               stack_force_notes = old_stack_force_notes;
+               stack_force_costs = old_stack_force_costs;
+       }
+
+       return flag;
+}
+
 
 /*
  * Add the item "o_ptr" to the inventory of the "Home"
@@ -1534,10 +1679,17 @@ static bool store_will_buy(object_type *o_ptr)
 static int home_carry(object_type *o_ptr)
 {
        int                             slot;
-       s32b                       value, j_value;
+       s32b                       value;
        int     i;
        object_type *j_ptr;
+       bool old_stack_force_notes = stack_force_notes;
+       bool old_stack_force_costs = stack_force_costs;
 
+       if (cur_store_num != STORE_HOME)
+       {
+               stack_force_notes = FALSE;
+               stack_force_costs = FALSE;
+       }
 
        /* Check each existing item (try to combine) */
        for (slot = 0; slot < st_ptr->stock_num; slot++)
@@ -1551,18 +1703,30 @@ static int home_carry(object_type *o_ptr)
                        /* Save the new number of items */
                        object_absorb(j_ptr, o_ptr);
 
+                       if (cur_store_num != STORE_HOME)
+                       {
+                               stack_force_notes = old_stack_force_notes;
+                               stack_force_costs = old_stack_force_costs;
+                       }
+
                        /* All done */
                        return (slot);
                }
        }
 
+       if (cur_store_num != STORE_HOME)
+       {
+               stack_force_notes = old_stack_force_notes;
+               stack_force_costs = old_stack_force_costs;
+       }
+
        /* No space? */
        /*
         * ±£¤·µ¡Ç½: ¥ª¥×¥·¥ç¥ó powerup_home ¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¤È
         *           ²æ¤¬²È¤¬ 20 ¥Ú¡¼¥¸¤Þ¤Ç»È¤¨¤ë
         */
        /* No space? */
-       if ( powerup_home == TRUE) {
+       if ((cur_store_num != STORE_HOME) || (powerup_home == TRUE)) {
                if (st_ptr->stock_num >= st_ptr->stock_size) {
                        return (-1);
                }
@@ -1580,50 +1744,7 @@ static int home_carry(object_type *o_ptr)
        /* Check existing slots to see if we must "slide" */
        for (slot = 0; slot < st_ptr->stock_num; slot++)
        {
-               /* Get that item */
-               j_ptr = &st_ptr->stock[slot];
-
-               /* Hack -- readable books always come first */
-               if ((o_ptr->tval == mp_ptr->spell_book) &&
-                       (j_ptr->tval != mp_ptr->spell_book)) break;
-               if ((j_ptr->tval == mp_ptr->spell_book) &&
-                       (o_ptr->tval != mp_ptr->spell_book)) continue;
-
-               /* Objects sort by decreasing type */
-               if (o_ptr->tval > j_ptr->tval) break;
-               if (o_ptr->tval < j_ptr->tval) continue;
-
-               /* Can happen in the home */
-               if (!object_is_aware(o_ptr)) continue;
-               if (!object_is_aware(j_ptr)) break;
-
-               /* Objects sort by increasing sval */
-               if (o_ptr->sval < j_ptr->sval) break;
-               if (o_ptr->sval > j_ptr->sval) continue;
-
-               /* Objects in the home can be unknown */
-               if (!object_is_known(o_ptr)) continue;
-               if (!object_is_known(j_ptr)) break;
-
-               /*
-                * Hack:  otherwise identical rods sort by
-                * increasing recharge time --dsb
-                */
-               if (o_ptr->tval == TV_ROD)
-               {
-                       if (o_ptr->pval < j_ptr->pval) break;
-                       if (o_ptr->pval > j_ptr->pval) continue;
-               }
-               if ((o_ptr->tval == TV_CORPSE) || (o_ptr->tval == TV_FIGURINE) || (o_ptr->tval == TV_STATUE))
-               {
-                       if (r_info[o_ptr->pval].level < r_info[j_ptr->pval].level) break;
-                       if ((r_info[o_ptr->pval].level == r_info[j_ptr->pval].level) && (o_ptr->pval < j_ptr->pval)) break;
-               }
-
-               /* Objects sort by decreasing value */
-               j_value = object_value(j_ptr);
-               if (value > j_value) break;
-               if (value < j_value) continue;
+               if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
        }
 
        /* Slide the others up */
@@ -1640,6 +1761,8 @@ static int home_carry(object_type *o_ptr)
 
        chg_virtue(V_SACRIFICE, -1);
 
+       (void)combine_and_reorder_home(cur_store_num);
+
        /* Return the location */
        return (slot);
 }
@@ -2061,10 +2184,10 @@ static void display_entry(int pos)
        o_ptr = &st_ptr->stock[pos];
 
        /* Get the "offset" */
-       i = (pos % 12);
+       i = (pos % store_bottom);
 
        /* Label it, clear the line --(-- */
-       (void)sprintf(out_val, "%c) ", I2A(i));
+       (void)sprintf(out_val, "%c) ", ((i > 25) ? toupper(I2A(i - 26)) : I2A(i)));
        prt(out_val, i+6, 0);
 
        cur_col = 3;
@@ -2079,6 +2202,8 @@ static void display_entry(int pos)
 #endif
 
                Term_queue_bigchar(cur_col, i + 6, a, c, 0, 0);
+               if (use_bigtile) cur_col++;
+
                cur_col += 2;
        }
 
@@ -2193,7 +2318,7 @@ static void display_inventory(void)
        int i, k;
 
        /* Display the next 12 items */
-       for (k = 0; k < 12; k++)
+       for (k = 0; k < store_bottom; k++)
        {
                /* Do not display "dead" items */
                if (store_top + k >= st_ptr->stock_num) break;
@@ -2203,7 +2328,7 @@ static void display_inventory(void)
        }
 
        /* Erase the extra lines and the "more" prompt */
-       for (i = k; i < 13; i++) prt("", i + 6, 0);
+       for (i = k; i < store_bottom + 1; i++) prt("", i + 6, 0);
 
        /* Assume "no current page" */
 #ifdef JP
@@ -2214,7 +2339,7 @@ static void display_inventory(void)
 
 
        /* Visual reminder of "more items" */
-       if (st_ptr->stock_num > 12)
+       if (st_ptr->stock_num > store_bottom)
        {
                /* Show "more" reminder (after the last item) */
 #ifdef JP
@@ -2227,12 +2352,24 @@ static void display_inventory(void)
                /* Indicate the "current page" */
                /* Trailing spaces are to display (Page xx) and (Page x) */
 #ifdef JP
-               put_str(format("(%d¥Ú¡¼¥¸)  ", store_top/12 + 1), 5, 20);
+               put_str(format("(%d¥Ú¡¼¥¸)  ", store_top/store_bottom + 1), 5, 20);
 #else
-               put_str(format("(Page %d)  ", store_top/12 + 1), 5, 20);
+               put_str(format("(Page %d)  ", store_top/store_bottom + 1), 5, 20);
 #endif
 
        }
+
+       if (cur_store_num == STORE_HOME || cur_store_num == STORE_MUSEUM)
+       {
+               k = st_ptr->stock_size;
+
+               if (cur_store_num == STORE_HOME && !powerup_home) k /= 10;
+#ifdef JP
+               put_str(format("¥¢¥¤¥Æ¥à¿ô:  %4d/%4d", st_ptr->stock_num, k), 19 + xtra_stock, 27);
+#else
+               put_str(format("Objects:  %4d/%4d", st_ptr->stock_num, k), 19 + xtra_stock, 30);
+#endif
+       }
 }
 
 
@@ -2244,14 +2381,14 @@ static void store_prt_gold(void)
        char out_val[64];
 
 #ifdef JP
-       prt("¼ê»ý¤Á¤Î¤ª¶â: ", 19, 53);
+       prt("¼ê»ý¤Á¤Î¤ª¶â: ", 19 + xtra_stock, 53);
 #else
-       prt("Gold Remaining: ", 19, 53);
+       prt("Gold Remaining: ", 19 + xtra_stock, 53);
 #endif
 
 
        sprintf(out_val, "%9ld", (long)p_ptr->au);
-       prt(out_val, 19, 68);
+       prt(out_val, 19 + xtra_stock, 68);
 }
 
 
@@ -2386,8 +2523,8 @@ static void display_store(void)
 static int get_stock(int *com_val, cptr pmt, int i, int j)
 {
        char    command;
-
        char    out_val[160];
+       char    lo, hi;
 
 #ifdef ALLOW_REPEAT /* TNB */
 
@@ -2412,13 +2549,15 @@ static int get_stock(int *com_val, cptr pmt, int i, int j)
        *com_val = (-1);
 
        /* Build the prompt */
+       lo = I2A(i);
+       hi = (j > 25) ? toupper(I2A(j - 26)) : I2A(j);
 #ifdef JP
        (void)sprintf(out_val, "(%s:%c-%c, ESC¤ÇÃæÃÇ) %s",
                (((cur_store_num == STORE_HOME) || (cur_store_num == STORE_MUSEUM)) ? "¥¢¥¤¥Æ¥à" : "¾¦ÉÊ"), 
-                                 I2A(i), I2A(j), pmt);
+                                 lo, hi, pmt);
 #else
        (void)sprintf(out_val, "(Items %c-%c, ESC to exit) %s",
-                                 I2A(i), I2A(j), pmt);
+                                 lo, hi, pmt);
 #endif
 
 
@@ -2431,7 +2570,12 @@ static int get_stock(int *com_val, cptr pmt, int i, int j)
                if (!get_com(out_val, &command, FALSE)) break;
 
                /* Convert */
-               k = (islower(command) ? A2I(command) : -1);
+               if (islower(command))
+                       k = A2I(command);
+               else if (isupper(command))
+                       k = A2I(tolower(command)) + 26;
+               else
+                       k = -1;
 
                /* Legal responses */
                if ((k >= i) && (k <= j))
@@ -3183,7 +3327,6 @@ static void store_purchase(void)
 
        char out_val[160];
 
-
        if (cur_store_num == STORE_MUSEUM)
        {
 #ifdef JP
@@ -3219,7 +3362,7 @@ static void store_purchase(void)
        i = (st_ptr->stock_num - store_top);
 
        /* And then restrict it to the current page */
-       if (i > 12) i = 12;
+       if (i > store_bottom) i = store_bottom;
 
        /* Prompt */
 #ifdef JP
@@ -3522,7 +3665,7 @@ msg_format("%s
                                else if (st_ptr->stock_num != i)
                                {
                                        /* Pick the correct screen */
-                                       if (store_top >= st_ptr->stock_num) store_top -= 12;
+                                       if (store_top >= st_ptr->stock_num) store_top -= store_bottom;
 
                                        /* Redraw everything */
                                        display_inventory();
@@ -3553,6 +3696,8 @@ msg_format("%s
        /* Home is much easier */
        else
        {
+               bool combined_or_reordered;
+
                /* Distribute charges of wands/rods */
                distribute_charges(o_ptr, j_ptr, amt);
 
@@ -3580,11 +3725,16 @@ msg_format("%s
                store_item_increase(item, -amt);
                store_item_optimize(item);
 
+               combined_or_reordered = combine_and_reorder_home(STORE_HOME);
+
                /* Hack -- Item is still here */
                if (i == st_ptr->stock_num)
                {
+                       /* Redraw everything */
+                       if (combined_or_reordered) display_inventory();
+
                        /* Redraw the item */
-                       display_entry(item);
+                       else display_entry(item);
                }
 
                /* The item is gone */
@@ -3594,7 +3744,7 @@ msg_format("%s
                        if (st_ptr->stock_num == 0) store_top = 0;
 
                        /* Nothing left on that screen */
-                       else if (store_top >= st_ptr->stock_num) store_top -= 12;
+                       else if (store_top >= st_ptr->stock_num) store_top -= store_bottom;
 
                        /* Redraw everything */
                        display_inventory();
@@ -3900,7 +4050,7 @@ msg_format("%s
                        /* Re-display if item is now in store */
                        if (item_pos >= 0)
                        {
-                               store_top = (item_pos / 12) * 12;
+                               store_top = (item_pos / store_bottom) * store_bottom;
                                display_inventory();
                        }
                }
@@ -3964,7 +4114,7 @@ msg_format("%s
                /* Update store display */
                if (item_pos >= 0)
                {
-                       store_top = (item_pos / 12) * 12;
+                       store_top = (item_pos / store_bottom) * store_bottom;
                        display_inventory();
                }
        }
@@ -3997,7 +4147,7 @@ msg_format("%s
                /* Update store display */
                if (item_pos >= 0)
                {
-                       store_top = (item_pos / 12) * 12;
+                       store_top = (item_pos / store_bottom) * store_bottom;
                        display_inventory();
                }
        }
@@ -4054,7 +4204,7 @@ static void store_examine(void)
        i = (st_ptr->stock_num - store_top);
 
        /* And then restrict it to the current page */
-       if (i > 12) i = 12;
+       if (i > store_bottom) i = store_bottom;
 
        /* Prompt */
 #ifdef JP
@@ -4137,7 +4287,7 @@ static void museum_remove_object(void)
        i = st_ptr->stock_num - store_top;
 
        /* And then restrict it to the current page */
-       if (i > 12) i = 12;
+       if (i > store_bottom) i = store_bottom;
 
        /* Prompt */
 #ifdef JP
@@ -4177,13 +4327,15 @@ static void museum_remove_object(void)
        store_item_increase(item, -o_ptr->number);
        store_item_optimize(item);
 
+       (void)combine_and_reorder_home(STORE_MUSEUM);
+
        /* The item is gone */
 
        /* Nothing left */
        if (st_ptr->stock_num == 0) store_top = 0;
 
        /* Nothing left on that screen */
-       else if (store_top >= st_ptr->stock_num) store_top -= 12;
+       else if (store_top >= st_ptr->stock_num) store_top -= store_bottom;
 
        /* Redraw everything */
        display_inventory();
@@ -4234,7 +4386,7 @@ static void store_process_command(void)
                /* 1 ¥Ú¡¼¥¸Ìá¤ë¥³¥Þ¥ó¥É: ²æ¤¬²È¤Î¥Ú¡¼¥¸¿ô¤¬Â¿¤¤¤Î¤Ç½ÅÊõ¤¹¤ë¤Ï¤º By BUG */
                case '-':
                {
-                       if (st_ptr->stock_num <= 12) {
+                       if (st_ptr->stock_num <= store_bottom) {
 #ifdef JP
                                msg_print("¤³¤ì¤ÇÁ´Éô¤Ç¤¹¡£");
 #else
@@ -4242,11 +4394,11 @@ static void store_process_command(void)
 #endif
                        }
                        else{
-                               store_top -= 12;
+                               store_top -= store_bottom;
                                if ( store_top < 0 )
-                                       store_top = ((st_ptr->stock_num - 1 )/12) * 12;
+                                       store_top = ((st_ptr->stock_num - 1 )/store_bottom) * store_bottom;
                                if ( (cur_store_num == STORE_HOME) && (powerup_home == FALSE) )
-                                       if ( store_top >= 12 ) store_top = 12;
+                                       if ( store_top >= store_bottom ) store_top = store_bottom;
                                display_inventory();
                        }
                        break;
@@ -4255,7 +4407,7 @@ static void store_process_command(void)
                /* Browse */
                case ' ':
                {
-                       if (st_ptr->stock_num <= 12)
+                       if (st_ptr->stock_num <= store_bottom)
                        {
 #ifdef JP
                                msg_print("¤³¤ì¤ÇÁ´Éô¤Ç¤¹¡£");
@@ -4266,7 +4418,7 @@ static void store_process_command(void)
                        }
                        else
                        {
-                               store_top += 12;
+                               store_top += store_bottom;
                                /*
                                 * ±£¤·¥ª¥×¥·¥ç¥ó(powerup_home)¤¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¤È¤­¤Ï
                                 * ²æ¤¬²È¤Ç¤Ï 2 ¥Ú¡¼¥¸¤Þ¤Ç¤·¤«É½¼¨¤·¤Ê¤¤
@@ -4386,7 +4538,18 @@ static void store_process_command(void)
                /* Browse a book */
                case 'b':
                {
-                       do_cmd_browse();
+                       if ( (p_ptr->pclass == CLASS_MINDCRAFTER) ||
+                            (p_ptr->pclass == CLASS_BERSERKER) ||
+                            (p_ptr->pclass == CLASS_NINJA) ||
+                            (p_ptr->pclass == CLASS_MIRROR_MASTER) 
+                            ) do_cmd_mind_browse();
+                       else if (p_ptr->pclass == CLASS_SMITH)
+                               do_cmd_kaji(TRUE);
+                       else if (p_ptr->pclass == CLASS_MAGIC_EATER)
+                               do_cmd_magic_eater(TRUE, FALSE);
+                       else if (p_ptr->pclass == CLASS_SNIPER)
+                               do_cmd_snipe_browse();
+                       else do_cmd_browse();
                        break;
                }
 
@@ -4482,6 +4645,9 @@ static void store_process_command(void)
                case '=':
                {
                        do_cmd_options();
+                       (void)combine_and_reorder_home(STORE_HOME);
+                       do_cmd_redraw();
+                       display_store();
                        break;
                }
 
@@ -4588,7 +4754,14 @@ void do_cmd_store(void)
        int         i;
        cave_type   *c_ptr;
        bool        need_redraw_store_inv; /* To redraw missiles damage and prices in store */
+       int w, h;
+
+       /* Get term size */
+       Term_get_size(&w, &h);
 
+       /* Calculate stocks per 1 page */
+       xtra_stock = MIN(14+26, ((h > 24) ? (h - 24) : 0));
+       store_bottom = MIN_STOCK + xtra_stock;
 
        /* Access the player grid */
        c_ptr = &cave[py][px];
@@ -4663,6 +4836,8 @@ void do_cmd_store(void)
        /* No automatic command */
        command_new = 0;
 
+       /* Do not expand macros */
+       get_com_no_macros = TRUE;
 
        /* Save the store number */
        cur_store_num = which;
@@ -4691,26 +4866,26 @@ void do_cmd_store(void)
                prt("", 1, 0);
 
                /* Clear */
-               clear_from(20);
+               clear_from(20 + xtra_stock);
 
 
                /* Basic commands */
 #ifdef JP
-               prt(" ESC) ·úʪ¤«¤é½Ð¤ë", 21, 0);
+               prt(" ESC) ·úʪ¤«¤é½Ð¤ë", 21 + xtra_stock, 0);
 #else
-               prt(" ESC) Exit from Building.", 21, 0);
+               prt(" ESC) Exit from Building.", 21 + xtra_stock, 0);
 #endif
 
 
                /* Browse if necessary */
-               if (st_ptr->stock_num > 12)
+               if (st_ptr->stock_num > store_bottom)
                {
 #ifdef JP
-                       prt(" -)Á°¥Ú¡¼¥¸", 22, 0);
-                       prt(" ¥¹¥Ú¡¼¥¹) ¼¡¥Ú¡¼¥¸", 23, 0);
+                       prt(" -)Á°¥Ú¡¼¥¸", 22 + xtra_stock, 0);
+                       prt(" ¥¹¥Ú¡¼¥¹) ¼¡¥Ú¡¼¥¸", 23 + xtra_stock, 0);
 #else
-                       prt(" -) Previous page", 22, 0);
-                       prt(" SPACE) Next page", 23, 0);
+                       prt(" -) Previous page", 22 + xtra_stock, 0);
+                       prt(" SPACE) Next page", 23 + xtra_stock, 0);
 #endif
 
                }
@@ -4719,13 +4894,13 @@ void do_cmd_store(void)
                if (cur_store_num == STORE_HOME)
                {
 #ifdef JP
-                       prt("g) ¥¢¥¤¥Æ¥à¤ò¼è¤ë", 21, 27);
-                       prt("d) ¥¢¥¤¥Æ¥à¤òÃÖ¤¯", 22, 27);
-                       prt("x) ²È¤Î¥¢¥¤¥Æ¥à¤òÄ´¤Ù¤ë", 23,27);
+                       prt("g) ¥¢¥¤¥Æ¥à¤ò¼è¤ë", 21 + xtra_stock, 27);
+                       prt("d) ¥¢¥¤¥Æ¥à¤òÃÖ¤¯", 22 + xtra_stock, 27);
+                       prt("x) ²È¤Î¥¢¥¤¥Æ¥à¤òÄ´¤Ù¤ë", 23 + xtra_stock, 27);
 #else
-                       prt("g) Get an item.", 21, 27);
-                       prt("d) Drop an item.", 22, 27);
-                       prt("x) eXamine an item in the home.", 23,27);
+                       prt("g) Get an item.", 21 + xtra_stock, 27);
+                       prt("d) Drop an item.", 22 + xtra_stock, 27);
+                       prt("x) eXamine an item in the home.", 23 + xtra_stock, 27);
 #endif
                }
 
@@ -4733,13 +4908,13 @@ void do_cmd_store(void)
                else if (cur_store_num == STORE_MUSEUM)
                {
 #ifdef JP
-                       prt("d) ¥¢¥¤¥Æ¥à¤òÃÖ¤¯", 21, 27);
-                       prt("r) ¥¢¥¤¥Æ¥à¤ÎŸ¼¨¤ò¤ä¤á¤ë", 22, 27);
-                       prt("x) Çîʪ´Û¤Î¥¢¥¤¥Æ¥à¤òÄ´¤Ù¤ë", 23, 27);
+                       prt("d) ¥¢¥¤¥Æ¥à¤òÃÖ¤¯", 21 + xtra_stock, 27);
+                       prt("r) ¥¢¥¤¥Æ¥à¤ÎŸ¼¨¤ò¤ä¤á¤ë", 22 + xtra_stock, 27);
+                       prt("x) Çîʪ´Û¤Î¥¢¥¤¥Æ¥à¤òÄ´¤Ù¤ë", 23 + xtra_stock, 27);
 #else
-                       prt("d) Drop an item.", 21, 27);
-                       prt("r) order to Remove an item.", 22, 27);
-                       prt("x) eXamine an item in the museum.", 23, 27);
+                       prt("d) Drop an item.", 21 + xtra_stock, 27);
+                       prt("r) order to Remove an item.", 22 + xtra_stock, 27);
+                       prt("x) eXamine an item in the museum.", 23 + xtra_stock, 27);
 #endif
                }
 
@@ -4747,46 +4922,46 @@ void do_cmd_store(void)
                else
                {
 #ifdef JP
-                       prt("p) ¾¦ÉʤòÇ㤦", 21, 30);
-                       prt("s) ¥¢¥¤¥Æ¥à¤òÇä¤ë", 22, 30);
-                       prt("x) ¾¦ÉʤòÄ´¤Ù¤ë", 23,30);
+                       prt("p) ¾¦ÉʤòÇ㤦", 21 + xtra_stock, 30);
+                       prt("s) ¥¢¥¤¥Æ¥à¤òÇä¤ë", 22 + xtra_stock, 30);
+                       prt("x) ¾¦ÉʤòÄ´¤Ù¤ë", 23 + xtra_stock,30);
 #else
-                       prt("p) Purchase an item.", 21, 30);
-                       prt("s) Sell an item.", 22, 30);
-                       prt("x) eXamine an item in the shop", 23,30);
+                       prt("p) Purchase an item.", 21 + xtra_stock, 30);
+                       prt("s) Sell an item.", 22 + xtra_stock, 30);
+                       prt("x) eXamine an item in the shop", 23 + xtra_stock,30);
 #endif
                }
 
 #ifdef JP
                /* ´ðËÜŪ¤Ê¥³¥Þ¥ó¥É¤ÎÄɲÃɽ¼¨ */
 
-               prt("i/e) »ý¤Áʪ/ÁõÈ÷¤Î°ìÍ÷", 21, 56);
+               prt("i/e) »ý¤Áʪ/ÁõÈ÷¤Î°ìÍ÷", 21 + xtra_stock, 56);
 
                if (rogue_like_commands)
                {
-                       prt("w/T) ÁõÈ÷¤¹¤ë/¤Ï¤º¤¹", 22, 56);
+                       prt("w/T) ÁõÈ÷¤¹¤ë/¤Ï¤º¤¹", 22 + xtra_stock, 56);
                }
                else
                {
-                       prt("w/t) ÁõÈ÷¤¹¤ë/¤Ï¤º¤¹", 22, 56);
+                       prt("w/t) ÁõÈ÷¤¹¤ë/¤Ï¤º¤¹", 22 + xtra_stock, 56);
                }
 #else
-               prt("i/e) Inventry/Equipment list", 21, 56);
+               prt("i/e) Inventry/Equipment list", 21 + xtra_stock, 56);
 
                if (rogue_like_commands)
                {
-                       prt("w/T) Wear/Take off equipment", 22, 56);
+                       prt("w/T) Wear/Take off equipment", 22 + xtra_stock, 56);
                }
                else
                {
-                       prt("w/t) Wear/Take off equipment", 22, 56);
+                       prt("w/t) Wear/Take off equipment", 22 + xtra_stock, 56);
                }
 #endif
                /* Prompt */
 #ifdef JP
-               prt("¥³¥Þ¥ó¥É:", 20, 0);
+               prt("¥³¥Þ¥ó¥É:", 20 + xtra_stock, 0);
 #else
-               prt("You may: ", 20, 0);
+               prt("You may: ", 20 + xtra_stock, 0);
 #endif
 
 
@@ -4904,7 +5079,7 @@ void do_cmd_store(void)
                                /* Redraw the home */
                                if (item_pos >= 0)
                                {
-                                       store_top = (item_pos / 12) * 12;
+                                       store_top = (item_pos / store_bottom) * store_bottom;
                                        display_inventory();
                                }
                        }
@@ -4934,6 +5109,8 @@ void do_cmd_store(void)
        /* Hack -- Cancel "see" mode */
        command_see = FALSE;
 
+       /* Allow expanding macros */
+       get_com_no_macros = FALSE;
 
        /* Flush messages XXX XXX XXX */
        msg_print(NULL);