OSDN Git Service

多数のロッドを所持したときにpvalがオーバフローする不具合を修正。
[hengband/hengband.git] / src / store.c
index c6ecf7f..a33cd5e 100644 (file)
@@ -307,19 +307,19 @@ static void say_comment_1(void)
        char rumour[1024];
 
 #ifdef JP
-        /* ¥Ö¥é¥Ã¥¯¥Þ¡¼¥±¥Ã¥È¤Î¤È¤­¤ÏÊ̤Υá¥Ã¥»¡¼¥¸¤ò½Ð¤¹ */
-        if ( cur_store_num == STORE_BLACK ) {
-                msg_print(comment_1_B[rand_int(MAX_COMMENT_1)]);
-        }
-        else{
-                msg_print(comment_1[rand_int(MAX_COMMENT_1)]);
-        }
+       /* ¥Ö¥é¥Ã¥¯¥Þ¡¼¥±¥Ã¥È¤Î¤È¤­¤ÏÊ̤Υá¥Ã¥»¡¼¥¸¤ò½Ð¤¹ */
+       if ( cur_store_num == STORE_BLACK ) {
+               msg_print(comment_1_B[randint0(MAX_COMMENT_1)]);
+       }
+       else{
+               msg_print(comment_1[randint0(MAX_COMMENT_1)]);
+       }
 #else
-       msg_print(comment_1[rand_int(MAX_COMMENT_1)]);
+       msg_print(comment_1[randint0(MAX_COMMENT_1)]);
 #endif
 
 
-       if (randint(RUMOR_CHANCE) == 1)
+       if (one_in_(RUMOR_CHANCE))
        {
 #ifdef JP
 msg_print("Ź¼ç¤Ï¼ª¤¦¤Á¤·¤¿:");
@@ -353,7 +353,7 @@ static void say_comment_2(s32b value, int annoyed)
        if (annoyed > 0)
        {
                /* Formatted message */
-               msg_format(comment_2a[rand_int(MAX_COMMENT_2A)], tmp_val);
+               msg_format(comment_2a[randint0(MAX_COMMENT_2A)], tmp_val);
        }
 
        /* Normal offer */
@@ -363,13 +363,13 @@ static void say_comment_2(s32b value, int annoyed)
 #ifdef JP
                /* ¥Ö¥é¥Ã¥¯¥Þ¡¼¥±¥Ã¥È¤Î»þ¤ÏÊ̤Υá¥Ã¥»¡¼¥¸¤ò½Ð¤¹ */
                if ( cur_store_num == STORE_BLACK ){
-                       msg_format(comment_2b_B[rand_int(MAX_COMMENT_2B)], tmp_val);
+                       msg_format(comment_2b_B[randint0(MAX_COMMENT_2B)], tmp_val);
                }
                else{
-               msg_format(comment_2b[rand_int(MAX_COMMENT_2B)], tmp_val);
+               msg_format(comment_2b[randint0(MAX_COMMENT_2B)], tmp_val);
        }
 #else
-               msg_format(comment_2b[rand_int(MAX_COMMENT_2B)], tmp_val);
+               msg_format(comment_2b[randint0(MAX_COMMENT_2B)], tmp_val);
 #endif
 
        }
@@ -390,7 +390,7 @@ static void say_comment_3(s32b value, int annoyed)
        if (annoyed > 0)
        {
                /* Formatted message */
-               msg_format(comment_3a[rand_int(MAX_COMMENT_3A)], tmp_val);
+               msg_format(comment_3a[randint0(MAX_COMMENT_3A)], tmp_val);
        }
 
        /* Normal offer */
@@ -400,13 +400,13 @@ static void say_comment_3(s32b value, int annoyed)
 #ifdef JP
                /* ¥Ö¥é¥Ã¥¯¥Þ¡¼¥±¥Ã¥È¤Î»þ¤ÏÊ̤Υá¥Ã¥»¡¼¥¸¤ò½Ð¤¹ */
                if ( cur_store_num == STORE_BLACK ){
-                       msg_format(comment_3b_B[rand_int(MAX_COMMENT_3B)], tmp_val);
+                       msg_format(comment_3b_B[randint0(MAX_COMMENT_3B)], tmp_val);
                }
                else{
-               msg_format(comment_3b[rand_int(MAX_COMMENT_3B)], tmp_val);
+               msg_format(comment_3b[randint0(MAX_COMMENT_3B)], tmp_val);
        }
 #else
-               msg_format(comment_3b[rand_int(MAX_COMMENT_3B)], tmp_val);
+               msg_format(comment_3b[randint0(MAX_COMMENT_3B)], tmp_val);
 #endif
 
        }
@@ -419,18 +419,18 @@ static void say_comment_3(s32b value, int annoyed)
 static void say_comment_4(void)
 {
 #ifdef JP
-        /* ¥Ö¥é¥Ã¥¯¥Þ¡¼¥±¥Ã¥È¤Î»þ¤ÏÊ̤Υá¥Ã¥»¡¼¥¸¤ò½Ð¤¹ */
-        if ( cur_store_num == STORE_BLACK ){
-                msg_print(comment_4a_B[rand_int(MAX_COMMENT_4A)]);
-                msg_print(comment_4b_B[rand_int(MAX_COMMENT_4B)]);
-        }
-        else{
-                msg_print(comment_4a[rand_int(MAX_COMMENT_4A)]);
-                msg_print(comment_4b[rand_int(MAX_COMMENT_4B)]);
-        }
+       /* ¥Ö¥é¥Ã¥¯¥Þ¡¼¥±¥Ã¥È¤Î»þ¤ÏÊ̤Υá¥Ã¥»¡¼¥¸¤ò½Ð¤¹ */
+       if ( cur_store_num == STORE_BLACK ){
+               msg_print(comment_4a_B[randint0(MAX_COMMENT_4A)]);
+               msg_print(comment_4b_B[randint0(MAX_COMMENT_4B)]);
+       }
+       else{
+               msg_print(comment_4a[randint0(MAX_COMMENT_4A)]);
+               msg_print(comment_4b[randint0(MAX_COMMENT_4B)]);
+       }
 #else
-       msg_print(comment_4a[rand_int(MAX_COMMENT_4A)]);
-       msg_print(comment_4b[rand_int(MAX_COMMENT_4B)]);
+       msg_print(comment_4a[randint0(MAX_COMMENT_4A)]);
+       msg_print(comment_4b[randint0(MAX_COMMENT_4B)]);
 #endif
 
 }
@@ -442,15 +442,15 @@ static void say_comment_4(void)
 static void say_comment_5(void)
 {
 #ifdef JP
-        /* ¥Ö¥é¥Ã¥¯¥Þ¡¼¥±¥Ã¥È¤Î»þ¤ÏÊ̤Υá¥Ã¥»¡¼¥¸¤ò½Ð¤¹ */
-        if ( cur_store_num == STORE_BLACK ){
-                msg_print(comment_5_B[rand_int(MAX_COMMENT_5)]);
-        }
-        else{
-                msg_print(comment_5[rand_int(MAX_COMMENT_5)]);
-        }
+       /* ¥Ö¥é¥Ã¥¯¥Þ¡¼¥±¥Ã¥È¤Î»þ¤ÏÊ̤Υá¥Ã¥»¡¼¥¸¤ò½Ð¤¹ */
+       if ( cur_store_num == STORE_BLACK ){
+               msg_print(comment_5_B[randint0(MAX_COMMENT_5)]);
+       }
+       else{
+               msg_print(comment_5[randint0(MAX_COMMENT_5)]);
+       }
 #else
-       msg_print(comment_5[rand_int(MAX_COMMENT_5)]);
+       msg_print(comment_5[randint0(MAX_COMMENT_5)]);
 #endif
 
 }
@@ -461,7 +461,7 @@ static void say_comment_5(void)
  */
 static void say_comment_6(void)
 {
-       msg_print(comment_6[rand_int(MAX_COMMENT_6)]);
+       msg_print(comment_6[randint0(MAX_COMMENT_6)]);
 }
 
 
@@ -554,7 +554,7 @@ static void purchase_analyze(s32b price, s32b value, s32b guess)
        if ((value <= 0) && (price > value))
        {
                /* Comment */
-               msg_print(comment_7a[rand_int(MAX_COMMENT_7A)]);
+               msg_print(comment_7a[randint0(MAX_COMMENT_7A)]);
 
                chg_virtue(V_HONOUR, -1);
                chg_virtue(V_JUSTICE, -1);
@@ -567,10 +567,10 @@ static void purchase_analyze(s32b price, s32b value, s32b guess)
        else if ((value < guess) && (price > value))
        {
                /* Comment */
-               msg_print(comment_7b[rand_int(MAX_COMMENT_7B)]);
+               msg_print(comment_7b[randint0(MAX_COMMENT_7B)]);
 
                chg_virtue(V_JUSTICE, -1);
-               if (randint(4)==1)
+               if (one_in_(4))
                        chg_virtue(V_HONOUR, -1);
 
                /* Sound */
@@ -581,11 +581,11 @@ static void purchase_analyze(s32b price, s32b value, s32b guess)
        else if ((value > guess) && (value < (4 * guess)) && (price < value))
        {
                /* Comment */
-               msg_print(comment_7c[rand_int(MAX_COMMENT_7C)]);
+               msg_print(comment_7c[randint0(MAX_COMMENT_7C)]);
 
-               if (randint(4)==1)
+               if (one_in_(4))
                        chg_virtue(V_HONOUR, -1);
-               else if (randint(4)==1)
+               else if (one_in_(4))
                        chg_virtue(V_HONOUR, 1);
 
                /* Sound */
@@ -596,11 +596,11 @@ static void purchase_analyze(s32b price, s32b value, s32b guess)
        else if ((value > guess) && (price < value))
        {
                /* Comment */
-               msg_print(comment_7d[rand_int(MAX_COMMENT_7D)]);
+               msg_print(comment_7d[randint0(MAX_COMMENT_7D)]);
 
-               if (randint(2)==1)
+               if (one_in_(2))
                        chg_virtue(V_HONOUR, -1);
-               if (randint(4)==1)
+               if (one_in_(4))
                        chg_virtue(V_HONOUR, 1);
 
                if (10 * price < value)
@@ -983,6 +983,7 @@ static void mass_produce(object_type *o_ptr)
                {
                        if (cost <= 5L) size += damroll(3, 5);
                        if (cost <= 20L) size += damroll(3, 5);
+                       if (cost <= 50L) size += damroll(2, 2);
                        break;
                }
 
@@ -992,6 +993,7 @@ static void mass_produce(object_type *o_ptr)
                        if (cost <= 60L) size += damroll(3, 5);
                        if (cost <= 240L) size += damroll(1, 5);
                        if (o_ptr->sval == SV_SCROLL_STAR_IDENTIFY) size += damroll(3, 5);
+                       if (o_ptr->sval == SV_SCROLL_STAR_REMOVE_CURSE) size += damroll(1, 4);
                        break;
                }
 
@@ -1004,6 +1006,7 @@ static void mass_produce(object_type *o_ptr)
                case TV_ARCANE_BOOK:
                case TV_ENCHANT_BOOK:
                case TV_DAEMON_BOOK:
+               case TV_CRUSADE_BOOK:
                case TV_MUSIC_BOOK:
                case TV_HISSATSU_BOOK:
                {
@@ -1067,7 +1070,7 @@ static void mass_produce(object_type *o_ptr)
                case TV_WAND:
                case TV_STAFF:
                {
-                       if ((cur_store_num == STORE_BLACK) && (randint(3) == 1))
+                       if ((cur_store_num == STORE_BLACK) && one_in_(3))
                        {
                                if (cost < 1601L) size += damroll(1, 5);
                                else if (cost < 3201L) size += damroll(1, 3);
@@ -1088,19 +1091,19 @@ static void mass_produce(object_type *o_ptr)
        {
                discount = 0;
        }
-       else if (rand_int(25) == 0)
+       else if (one_in_(25))
        {
                discount = 25;
        }
-       else if (rand_int(150) == 0)
+       else if (one_in_(150))
        {
                discount = 50;
        }
-       else if (rand_int(300) == 0)
+       else if (one_in_(300))
        {
                discount = 75;
        }
-       else if (rand_int(500) == 0)
+       else if (one_in_(500))
        {
                discount = 90;
        }
@@ -1136,6 +1139,8 @@ msg_print("
  */
 static bool store_object_similar(object_type *o_ptr, object_type *j_ptr)
 {
+       int i;
+
        /* Hack -- Identical items cannot be stacked */
        if (o_ptr == j_ptr) return (0);
 
@@ -1160,10 +1165,8 @@ static bool store_object_similar(object_type *o_ptr, object_type *j_ptr)
        if (o_ptr->art_name || j_ptr->art_name) return (0);
 
        /* Hack -- Identical art_flags! */
-       if ((o_ptr->art_flags1 != j_ptr->art_flags1) ||
-               (o_ptr->art_flags2 != j_ptr->art_flags2) ||
-               (o_ptr->art_flags3 != j_ptr->art_flags3))
-                       return (0);
+       for (i = 0; i < TR_FLAG_SIZE; i++)
+               if (o_ptr->art_flags[i] != j_ptr->art_flags[i]) return (0);
 
        /* Hack -- Never stack "powerful" items */
        if (o_ptr->xtra1 || j_ptr->xtra1) return (0);
@@ -1194,21 +1197,24 @@ static bool store_object_similar(object_type *o_ptr, object_type *j_ptr)
  */
 static void store_object_absorb(object_type *o_ptr, object_type *j_ptr)
 {
+       int max_num = (o_ptr->tval == TV_ROD) ?
+               MIN(99, MAX_SHORT / k_info[o_ptr->k_idx].pval) : 99;
        int total = o_ptr->number + j_ptr->number;
+       int diff = (total > max_num) ? total - max_num : 0;
 
        /* Combine quantity, lose excess items */
-       o_ptr->number = (total > 99) ? 99 : total;
+       o_ptr->number = (total > max_num) ? max_num : total;
 
        /* Hack -- if rods are stacking, add the pvals (maximum timeouts) together. -LM- */
        if (o_ptr->tval == TV_ROD)
        {
-               o_ptr->pval += j_ptr->pval;
+               o_ptr->pval += j_ptr->pval * (j_ptr->number - diff) / j_ptr->number;
        }
 
        /* Hack -- if wands are stacking, combine the charges. -LM- */
        if (o_ptr->tval == TV_WAND)
        {
-               o_ptr->pval += j_ptr->pval;
+               o_ptr->pval += j_ptr->pval * (j_ptr->number - diff) / j_ptr->number;
        }
 }
 
@@ -1217,28 +1223,17 @@ static void store_object_absorb(object_type *o_ptr, object_type *j_ptr)
  * Check to see if the shop will be carrying too many objects  -RAK-
  * Note that the shop, just like a player, will not accept things
  * it cannot hold.     Before, one could "nuke" potions this way.
+ *
+ * Return value is now int:
+ *  0 : No space
+ * -1 : Can be combined to existing slot.
+ *  1 : Cannot be combined but there are empty spaces.
  */
-static bool store_check_num(object_type *o_ptr)
+static int store_check_num(object_type *o_ptr)
 {
        int        i;
        object_type *j_ptr;
 
-       /* Free space is always usable */
-       /*
-        * ¥ª¥×¥·¥ç¥ó powerup_home ¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¤È
-        * ²æ¤¬²È¤¬ 20 ¥Ú¡¼¥¸¤Þ¤Ç»È¤¨¤ë
-        */
-       if ((cur_store_num == STORE_HOME) && ( powerup_home == FALSE )) {
-               if (st_ptr->stock_num < ((st_ptr->stock_size) / 10)) {
-                       return TRUE;
-               }
-       }
-       else{
-               if (st_ptr->stock_num < st_ptr->stock_size) {
-                       return TRUE;
-               }
-       }
-
        /* The "home" acts like the player */
        if ((cur_store_num == STORE_HOME) || (cur_store_num == STORE_MUSEUM))
        {
@@ -1249,7 +1244,7 @@ static bool 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 (TRUE);
+                       if (object_similar(j_ptr, o_ptr)) return -1;
                }
        }
 
@@ -1263,20 +1258,36 @@ static bool store_check_num(object_type *o_ptr)
                        j_ptr = &st_ptr->stock[i];
 
                        /* Can the new object be combined with the old one? */
-                       if (store_object_similar(j_ptr, o_ptr)) return (TRUE);
+                       if (store_object_similar(j_ptr, o_ptr)) return -1;
+               }
+       }
+
+       /* Free space is always usable */
+       /*
+        * ¥ª¥×¥·¥ç¥ó powerup_home ¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¤È
+        * ²æ¤¬²È¤¬ 20 ¥Ú¡¼¥¸¤Þ¤Ç»È¤¨¤ë
+        */
+       if ((cur_store_num == STORE_HOME) && ( powerup_home == FALSE )) {
+               if (st_ptr->stock_num < ((st_ptr->stock_size) / 10)) {
+                       return 1;
+               }
+       }
+       else{
+               if (st_ptr->stock_num < st_ptr->stock_size) {
+                       return 1;
                }
        }
 
        /* But there was no room at the inn... */
-       return (FALSE);
+       return 0;
 }
 
 
 static bool is_blessed(object_type *o_ptr)
 {
-       u32b f1, f2, f3;
-       object_flags(o_ptr, &f1, &f2, &f3);
-       if (f3 & TR3_BLESSED) return (TRUE);
+       u32b flgs[TR_FLAG_SIZE];
+       object_flags(o_ptr, flgs);
+       if (have_flag(flgs, TR_BLESSED)) return (TRUE);
        else return (FALSE);
 }
 
@@ -1301,6 +1312,9 @@ static bool store_will_buy(object_type *o_ptr)
                        /* Analyze the type */
                        switch (o_ptr->tval)
                        {
+                               case TV_POTION:
+                                       if (o_ptr->sval != SV_POTION_WATER) return FALSE;
+
                                case TV_WHISTLE:
                                case TV_FOOD:
                                case TV_LITE:
@@ -1378,6 +1392,7 @@ static bool store_will_buy(object_type *o_ptr)
                        switch (o_ptr->tval)
                        {
                                case TV_LIFE_BOOK:
+                               case TV_CRUSADE_BOOK:
                                case TV_SCROLL:
                                case TV_POTION:
                                case TV_HAFTED:
@@ -1477,6 +1492,7 @@ static bool store_will_buy(object_type *o_ptr)
                                case TV_ARCANE_BOOK:
                                case TV_ENCHANT_BOOK:
                                case TV_DAEMON_BOOK:
+                               case TV_CRUSADE_BOOK:
                                case TV_MUSIC_BOOK:
                                        break;
                                default:
@@ -1763,10 +1779,6 @@ static void store_item_optimize(int item)
        /* Must have no items */
        if (o_ptr->number) return;
 
-#ifdef USE_SCRIPT
-       object_delete_callback(o_ptr);
-#endif /* USE_SCRIPT */
-
        /* One less item */
        st_ptr->stock_num--;
 
@@ -1828,16 +1840,16 @@ static void store_delete(void)
        int what, num;
 
        /* Pick a random slot */
-       what = rand_int(st_ptr->stock_num);
+       what = randint0(st_ptr->stock_num);
 
        /* Determine how many items are here */
        num = st_ptr->stock[what].number;
 
        /* Hack -- sometimes, only destroy half the items */
-       if (rand_int(100) < 50) num = (num + 1) / 2;
+       if (randint0(100) < 50) num = (num + 1) / 2;
 
        /* Hack -- sometimes, only destroy a single item */
-       if (rand_int(100) < 50) num = 1;
+       if (randint0(100) < 50) num = 1;
 
        /* Hack -- decrement the maximum timeouts and total charges of rods and wands. -LM- */
        if ((st_ptr->stock[what].tval == TV_ROD) || (st_ptr->stock[what].tval == TV_WAND))
@@ -1881,7 +1893,7 @@ static void store_create(void)
                if (cur_store_num == STORE_BLACK)
                {
                        /* Pick a level for object/magic */
-                       level = 25 + rand_int(25);
+                       level = 25 + randint0(25);
 
                        /* Random item (usually of given level) */
                        i = get_obj_num(level);
@@ -1894,7 +1906,7 @@ static void store_create(void)
                else
                {
                        /* Hack -- Pick an item to sell */
-                       i = st_ptr->table[rand_int(st_ptr->table_num)];
+                       i = st_ptr->table[randint0(st_ptr->table_num)];
 
                        /* Hack -- fake level for apply_magic() */
                        level = rand_range(1, STORE_OBJ_LEVEL);
@@ -1954,10 +1966,6 @@ static void store_create(void)
                /* Mass produce and/or Apply discount */
                mass_produce(q_ptr);
 
-#ifdef USE_SCRIPT
-               q_ptr->python = object_create_callback(q_ptr);
-#endif /* USE_SCRIPT */
-
                /* Attempt to carry the (known) item */
                (void)store_carry(q_ptr);
 
@@ -2029,7 +2037,7 @@ static void updatebargain(s32b price, s32b minprice, int num)
  */
 static void display_entry(int pos)
 {
-       int             i;
+       int             i, cur_col;
        object_type     *o_ptr;
        s32b            x;
 
@@ -2049,6 +2057,7 @@ static void display_entry(int pos)
        (void)sprintf(out_val, "%c) ", I2A(i));
        prt(out_val, i+6, 0);
 
+       cur_col = 3;
        if (show_item_graph)
        {
                byte a = object_attr(o_ptr);
@@ -2059,7 +2068,14 @@ static void display_entry(int pos)
                        a |= 0x40;
 #endif
 
-               Term_draw(3, i + 6, a, c);
+               Term_draw(cur_col, i + 6, a, c);
+               if (use_bigtile)
+               {
+                       cur_col++;
+                       if (a & 0x80)
+                               Term_draw(cur_col, i + 6, 255, -1);
+               }
+               cur_col += 2;
        }
 
        /* Describe an item in the home */
@@ -2073,7 +2089,7 @@ static void display_entry(int pos)
                /* Describe the object */
                object_desc(o_name, o_ptr, TRUE, 3);
                o_name[maxwid] = '\0';
-               c_put_str(tval_to_attr[o_ptr->tval], o_name, i+6, show_item_graph ? 5 : 3);
+               c_put_str(tval_to_attr[o_ptr->tval], o_name, i+6, cur_col);
 
                /* Show weights */
                if (show_weights)
@@ -2081,8 +2097,8 @@ static void display_entry(int pos)
                        /* Only show the weight of an individual item */
                        int wgt = o_ptr->weight;
 #ifdef JP
-                        sprintf(out_val, "%3d.%1d kg", lbtokg1(wgt) , lbtokg2(wgt) );
-                        put_str(out_val, i+6, 67);
+                       sprintf(out_val, "%3d.%1d kg", lbtokg1(wgt) , lbtokg2(wgt) );
+                       put_str(out_val, i+6, 67);
 #else
                        (void)sprintf(out_val, "%3d.%d lb", wgt / 10, wgt % 10);
                        put_str(out_val, i+6, 68);
@@ -2103,7 +2119,7 @@ static void display_entry(int pos)
                /* Describe the object (fully) */
                object_desc_store(o_name, o_ptr, TRUE, 3);
                o_name[maxwid] = '\0';
-               c_put_str(tval_to_attr[o_ptr->tval], o_name, i+6, show_item_graph ? 5 : 3);
+               c_put_str(tval_to_attr[o_ptr->tval], o_name, i+6, cur_col);
 
                /* Show weights */
                if (show_weights)
@@ -2111,8 +2127,8 @@ static void display_entry(int pos)
                        /* Only show the weight of an individual item */
                        int wgt = o_ptr->weight;
 #ifdef JP
-                        sprintf(out_val, "%3d.%1d", lbtokg1(wgt) , lbtokg2(wgt) );
-                        put_str(out_val, i+6, 60);
+                       sprintf(out_val, "%3d.%1d", lbtokg1(wgt) , lbtokg2(wgt) );
+                       put_str(out_val, i+6, 60);
 #else
                        (void)sprintf(out_val, "%3d.%d", wgt / 10, wgt % 10);
                        put_str(out_val, i+6, 61);
@@ -2205,10 +2221,11 @@ 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/12 + 1), 5, 20);
 #else
-               put_str(format("(Page %d)", store_top/12 + 1), 5, 20);
+               put_str(format("(Page %d)  ", store_top/12 + 1), 5, 20);
 #endif
 
        }
@@ -2392,8 +2409,8 @@ static int get_stock(int *com_val, cptr pmt, int i, int j)
 
        /* Build the prompt */
 #ifdef JP
-        (void)sprintf(out_val, "(%s:%c-%c, ESC¤ÇÃæÃÇ) %s",
-                (((cur_store_num == STORE_HOME) || (cur_store_num == STORE_MUSEUM)) ? "¥¢¥¤¥Æ¥à" : "¾¦ÉÊ"), 
+       (void)sprintf(out_val, "(%s:%c-%c, ESC¤ÇÃæÃÇ) %s",
+               (((cur_store_num == STORE_HOME) || (cur_store_num == STORE_MUSEUM)) ? "¥¢¥¤¥Æ¥à" : "¾¦ÉÊ"), 
                                  I2A(i), I2A(j), pmt);
 #else
        (void)sprintf(out_val, "(Items %c-%c, ESC to exit) %s",
@@ -2460,7 +2477,7 @@ static int increase_insults(void)
                st_ptr->bad_buy = 0;
 
                /* Open tomorrow */
-               st_ptr->store_open = turn + 25000 + randint(25000);
+               st_ptr->store_open = turn + TURNS_PER_TICK*TOWN_DAWN/8 + randint1(TURNS_PER_TICK*TOWN_DAWN/8);
 
                /* Closed */
                return (TRUE);
@@ -2650,8 +2667,8 @@ static int get_haggle(cptr pmt, s32b *poffer, s32b price, int final)
  * Return TRUE if offer is NOT okay
  */
 static bool receive_offer(cptr pmt, s32b *poffer,
-                          s32b last_offer, int factor,
-                          s32b price, int final)
+                         s32b last_offer, int factor,
+                         s32b price, int final)
 {
        /* Haggle till done */
        while (TRUE)
@@ -2791,7 +2808,7 @@ static bool purchase_haggle(object_type *o_ptr, s32b *price)
                        cancel = receive_offer("What do you offer? ",
 #endif
 
-                                              &offer, last_offer, 1, cur_ask, final);
+                                              &offer, last_offer, 1, cur_ask, final);
 
                        if (cancel)
                        {
@@ -2928,6 +2945,12 @@ static bool sell_haggle(object_type *o_ptr, s32b *price)
        /* No need to haggle */
        if (noneed || !manual_haggle || (final_ask >= purse))
        {
+               /* Apply Sales Tax (if needed) */
+               if (!manual_haggle && !noneed)
+               {
+                       final_ask -= final_ask / 10;
+               }
+
                /* No reason to haggle */
                if (final_ask >= purse)
                {
@@ -2968,9 +2991,6 @@ static bool sell_haggle(object_type *o_ptr, s32b *price)
 #endif
 
                        msg_print(NULL);
-
-                       /* Apply Sales Tax */
-                       final_ask -= final_ask / 10;
                }
 
                /* Final price */
@@ -3104,7 +3124,7 @@ static bool sell_haggle(object_type *o_ptr, s32b *price)
                                prt("", 1, 0);
                                (void)sprintf(out_val,
 #ifdef JP
-                                             "Á°²ó¤ÎÄ󼨲Á³Ê $%ld", (long)last_offer);
+                                             "Á°²ó¤ÎÄ󼨲Á³Ê $%ld", (long)last_offer);
 #else
                                                          "Your last bid %ld", (long)last_offer);
 #endif
@@ -3185,18 +3205,18 @@ static void store_purchase(void)
 
        /* Prompt */
 #ifdef JP
-        /* ¥Ö¥é¥Ã¥¯¥Þ¡¼¥±¥Ã¥È¤Î»þ¤ÏÊ̤Υá¥Ã¥»¡¼¥¸ */
-        switch( cur_store_num ) {
-                case 7:
-                        sprintf(out_val, "¤É¤Î¥¢¥¤¥Æ¥à¤ò¼è¤ê¤Þ¤¹¤«? ");
-                        break;
-                case 6:
-                        sprintf(out_val, "¤É¤ì? ");
-                        break;
-                default:
-                        sprintf(out_val, "¤É¤ÎÉÊʪ¤¬Íߤ·¤¤¤ó¤À¤¤? ");
-                        break;
-        }
+       /* ¥Ö¥é¥Ã¥¯¥Þ¡¼¥±¥Ã¥È¤Î»þ¤ÏÊ̤Υá¥Ã¥»¡¼¥¸ */
+       switch( cur_store_num ) {
+               case 7:
+                       sprintf(out_val, "¤É¤Î¥¢¥¤¥Æ¥à¤ò¼è¤ê¤Þ¤¹¤«? ");
+                       break;
+               case 6:
+                       sprintf(out_val, "¤É¤ì? ");
+                       break;
+               default:
+                       sprintf(out_val, "¤É¤ÎÉÊʪ¤¬Íߤ·¤¤¤ó¤À¤¤? ");
+                       break;
+       }
 #else
        if (cur_store_num == STORE_HOME)
        {
@@ -3344,6 +3364,8 @@ msg_format("%s(%c)
                        /* Player can afford it */
                        if (p_ptr->au >= price)
                        {
+                               int idx;
+
                                /* Say "okay" */
                                say_comment_1();
 
@@ -3408,6 +3430,9 @@ msg_format("%s
                                                   o_name, index_to_label(item_new));
 #endif
 
+                               /* Auto-inscription */
+                               idx = is_autopick(&inventory[item_new]);
+                               auto_inscribe_item(item_new, idx);
 
                                /* Now, reduce the original stack's pval. */
                                if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND))
@@ -3429,7 +3454,7 @@ msg_format("%s
                                if (st_ptr->stock_num == 0)
                                {
                                        /* Shuffle */
-                                       if (rand_int(STORE_SHUFFLE) == 0)
+                                       if (one_in_(STORE_SHUFFLE))
                                        {
                                                char buf[80];
                                                /* Message */
@@ -3863,11 +3888,26 @@ msg_format("%s
        {
                char o2_name[MAX_NLEN];
                object_desc(o2_name, q_ptr, TRUE, 0);
+
+               if (-1 == store_check_num(q_ptr))
+               {
+#ifdef JP
+                       msg_print("¤½¤ì¤ÈƱ¤¸ÉÊʪ¤Ï´û¤ËÇîʪ´Û¤Ë¤¢¤ë¤è¤¦¤Ç¤¹¡£");
+#else
+                       msg_print("The same object as it is already in the Museum.");
+#endif
+               }
+               else
+               {
+#ifdef JP
+                       msg_print("Çîʪ´Û¤Ë´ó£¤·¤¿¤â¤Î¤Ï¼è¤ê½Ð¤¹¤³¤È¤¬¤Ç¤­¤Þ¤»¤ó¡ª¡ª");
+#else
+                       msg_print("You cannot take items which is given to the Museum back!!");
+#endif
+               }
 #ifdef JP
-               msg_print("Çîʪ´Û¤Ë´ó£¤·¤¿¤â¤Î¤Ï¼è¤ê½Ð¤¹¤³¤È¤¬¤Ç¤­¤Þ¤»¤ó¡ª¡ª");
                if (!get_check(format("ËÜÅö¤Ë%s¤ò´ó£¤·¤Þ¤¹¤«¡©", o2_name))) return;
 #else
-               msg_print("You cannot take items which is given to the Museum back!!");
                if (!get_check(format("Really give %s to the Museum? ", o2_name))) return;
 #endif
 
@@ -3960,21 +4000,21 @@ static void store_examine(void)
        {
                if (cur_store_num == STORE_HOME)
 #ifdef JP
-msg_print("²æ¤¬²È¤Ë¤Ï²¿¤âÃÖ¤¤¤Æ¤¢¤ê¤Þ¤»¤ó¡£");
+                       msg_print("²æ¤¬²È¤Ë¤Ï²¿¤âÃÖ¤¤¤Æ¤¢¤ê¤Þ¤»¤ó¡£");
 #else
                        msg_print("Your home is empty.");
 #endif
 
-               if (cur_store_num == STORE_MUSEUM)
+               else if (cur_store_num == STORE_MUSEUM)
 #ifdef JP
-msg_print("Çîʪ´Û¤Ë¤Ï²¿¤âÃÖ¤¤¤Æ¤¢¤ê¤Þ¤»¤ó¡£");
+                       msg_print("Çîʪ´Û¤Ë¤Ï²¿¤âÃÖ¤¤¤Æ¤¢¤ê¤Þ¤»¤ó¡£");
 #else
                        msg_print("Museum is empty.");
 #endif
 
                else
 #ifdef JP
-msg_print("¸½ºß¾¦Éʤκ߸ˤòÀڤ餷¤Æ¤¤¤Þ¤¹¡£");
+                       msg_print("¸½ºß¾¦Éʤκ߸ˤòÀڤ餷¤Æ¤¤¤Þ¤¹¡£");
 #else
                        msg_print("I am currently out of stock.");
 #endif
@@ -4031,7 +4071,7 @@ msg_format("%s
 
 
        /* Describe it fully */
-       if (!identify_fully_aux(o_ptr))
+       if (!screen_object(o_ptr, TRUE))
 #ifdef JP
 msg_print("ÆäËÊѤï¤Ã¤¿¤È¤³¤í¤Ï¤Ê¤¤¤è¤¦¤À¡£");
 #else
@@ -4039,12 +4079,6 @@ msg_print("
 #endif
 
 
-#ifdef USE_SCRIPT
-
-       store_examine_callback(o_ptr);
-
-#endif /* USE_SCRIPT */
-
        return;
 }
 
@@ -4124,23 +4158,23 @@ static void store_process_command(void)
                        else
                        {
                                store_top += 12;
-                                /*
-                                 * ±£¤·¥ª¥×¥·¥ç¥ó(powerup_home)¤¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¤È¤­¤Ï
-                                 * ²æ¤¬²È¤Ç¤Ï 2 ¥Ú¡¼¥¸¤Þ¤Ç¤·¤«É½¼¨¤·¤Ê¤¤
-                                 */
-                                if ((cur_store_num == STORE_HOME) && 
-                                    (powerup_home == FALSE) && 
-                                        (st_ptr->stock_num >= STORE_INVEN_MAX))
-                                {
-                                        if (store_top >= (STORE_INVEN_MAX - 1))
-                                        {
-                                                store_top = 0;
-                                        }
-                                }
-                                else
-                                {
-                                        if (store_top >= st_ptr->stock_num) store_top = 0;
-                                }
+                               /*
+                                * ±£¤·¥ª¥×¥·¥ç¥ó(powerup_home)¤¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¤È¤­¤Ï
+                                * ²æ¤¬²È¤Ç¤Ï 2 ¥Ú¡¼¥¸¤Þ¤Ç¤·¤«É½¼¨¤·¤Ê¤¤
+                                */
+                               if ((cur_store_num == STORE_HOME) && 
+                                   (powerup_home == FALSE) && 
+                                       (st_ptr->stock_num >= STORE_INVEN_MAX))
+                               {
+                                       if (store_top >= (STORE_INVEN_MAX - 1))
+                                       {
+                                               store_top = 0;
+                                       }
+                               }
+                               else
+                               {
+                                       if (store_top >= st_ptr->stock_num) store_top = 0;
+                               }
 
                                display_inventory();
                        }
@@ -4471,7 +4505,7 @@ void do_cmd_store(void)
        }
 
        /* Calculate the number of store maintainances since the last visit */
-       maintain_num = (turn - town[p_ptr->town_num].store[which].last_visit) / (20L * STORE_TURNS);
+       maintain_num = (turn - town[p_ptr->town_num].store[which].last_visit) / (TURNS_PER_TICK * STORE_TURNS);
 
        /* Maintain the store max. 10 times */
        if (maintain_num > 10) maintain_num = 10;
@@ -4562,8 +4596,8 @@ void do_cmd_store(void)
                if (cur_store_num == STORE_HOME)
                {
 #ifdef JP
-                   prt("g) ¥¢¥¤¥Æ¥à¤ò¼è¤ë", 21, 27);
-                   prt("d) ¥¢¥¤¥Æ¥à¤òÃÖ¤¯", 22, 27);
+                  prt("g) ¥¢¥¤¥Æ¥à¤ò¼è¤ë", 21, 27);
+                  prt("d) ¥¢¥¤¥Æ¥à¤òÃÖ¤¯", 22, 27);
                   prt("x) ²È¤Î¥¢¥¤¥Æ¥à¤òÄ´¤Ù¤ë", 23,27);
 #else
                   prt("g) Get an item.", 21, 27);
@@ -4577,7 +4611,7 @@ void do_cmd_store(void)
                else if (cur_store_num == STORE_MUSEUM)
                {
 #ifdef JP
-                   prt("d) ¥¢¥¤¥Æ¥à¤òÃÖ¤¯", 21, 27);
+                  prt("d) ¥¢¥¤¥Æ¥à¤òÃÖ¤¯", 21, 27);
                   prt("x) Çîʪ´Û¤Î¥¢¥¤¥Æ¥à¤òÄ´¤Ù¤ë", 23,27);
 #else
                   prt("d) Drop an item.", 21, 27);
@@ -4590,8 +4624,8 @@ void do_cmd_store(void)
                else
                {
 #ifdef JP
-                        prt("p) ¾¦ÉʤòÇ㤦", 21, 30);
-                        prt("s) ¥¢¥¤¥Æ¥à¤òÇä¤ë", 22, 30);
+                       prt("p) ¾¦ÉʤòÇ㤦", 21, 30);
+                       prt("s) ¥¢¥¤¥Æ¥à¤òÇä¤ë", 22, 30);
                        prt("x) ¾¦ÉʤòÄ´¤Ù¤ë", 23,30);
 #else
                   prt("p) Purchase an item.", 21, 30);
@@ -4602,29 +4636,29 @@ void do_cmd_store(void)
                }
 
 #ifdef JP
-                /* ´ðËÜŪ¤Ê¥³¥Þ¥ó¥É¤ÎÄɲÃɽ¼¨ */
-
-                prt("i/e) »ý¤Áʪ/ÁõÈ÷¤Î°ìÍ÷", 21, 56);
-
-                if( rogue_like_commands == TRUE )
-                {
-                        prt("w/T) ÁõÈ÷¤¹¤ë/¤Ï¤º¤¹", 22, 56);
-                }
-                else
-                {
-                        prt("w/t) ÁõÈ÷¤¹¤ë/¤Ï¤º¤¹", 22, 56);
-                }
+               /* ´ðËÜŪ¤Ê¥³¥Þ¥ó¥É¤ÎÄɲÃɽ¼¨ */
+
+               prt("i/e) »ý¤Áʪ/ÁõÈ÷¤Î°ìÍ÷", 21, 56);
+
+               if( rogue_like_commands == TRUE )
+               {
+                       prt("w/T) ÁõÈ÷¤¹¤ë/¤Ï¤º¤¹", 22, 56);
+               }
+               else
+               {
+                       prt("w/t) ÁõÈ÷¤¹¤ë/¤Ï¤º¤¹", 22, 56);
+               }
 #else
-                prt("i/e) Inventry/Equipment list", 21, 56);
-
-                if( rogue_like_commands == TRUE )
-                {
-                        prt("w/T) Wear/Take off equipment", 22, 56);
-                }
-                else
-                {
-                        prt("w/t) Wear/Take off equipment", 22, 56);
-                }
+               prt("i/e) Inventry/Equipment list", 21, 56);
+
+               if( rogue_like_commands == TRUE )
+               {
+                       prt("w/T) Wear/Take off equipment", 22, 56);
+               }
+               else
+               {
+                       prt("w/t) Wear/Take off equipment", 22, 56);
+               }
 #endif
                /* Prompt */
 #ifdef JP
@@ -4819,7 +4853,7 @@ void store_shuffle(int which)
        /* Pick a new owner */
        while(1)
        {
-               st_ptr->owner = (byte)rand_int(MAX_OWNERS);
+               st_ptr->owner = (byte)randint0(MAX_OWNERS);
                if (j == st_ptr->owner) continue;
                for (i = 1;i < max_towns; i++)
                {
@@ -4913,7 +4947,7 @@ void store_maint(int town_num, int store_num)
        j = st_ptr->stock_num;
 
        /* Sell a few items */
-       j = j - randint(STORE_TURNOVER);
+       j = j - randint1(STORE_TURNOVER);
 
        /* Never keep more than "STORE_MAX_KEEP" slots */
        if (j > STORE_MAX_KEEP) j = STORE_MAX_KEEP;
@@ -4932,7 +4966,7 @@ void store_maint(int town_num, int store_num)
        j = st_ptr->stock_num;
 
        /* Buy some more items */
-       j = j + randint(STORE_TURNOVER);
+       j = j + randint1(STORE_TURNOVER);
 
        /* Never keep more than "STORE_MAX_KEEP" slots */
        if (j > STORE_MAX_KEEP) j = STORE_MAX_KEEP;
@@ -4970,7 +5004,7 @@ void store_init(int town_num, int store_num)
        {
                int i;
 
-               st_ptr->owner = (byte)rand_int(MAX_OWNERS);
+               st_ptr->owner = (byte)randint0(MAX_OWNERS);
                for (i = 1;i < max_towns; i++)
                {
                        if (i == town_num) continue;
@@ -5001,10 +5035,6 @@ void store_init(int town_num, int store_num)
        /* Clear any old items */
        for (k = 0; k < st_ptr->stock_size; k++)
        {
-#ifdef USE_SCRIPT
-               object_delete_callback(&st_ptr->stock[k]);
-#endif /* USE_SCRIPT */
-
                object_wipe(&st_ptr->stock[k]);
        }
 }
@@ -5021,9 +5051,5 @@ void move_to_black_market(object_type *o_ptr)
 
        (void)store_carry(o_ptr);
 
-#ifdef USE_SCRIPT
-       object_delete_callback(o_ptr);
-#endif /* USE_SCRIPT */
-
        object_wipe(o_ptr); /* Don't leave a bogus object behind... */
 }