OSDN Git Service

[Refactor] #40399 Separated identification.c/h from object1.c/h
[hengband/hengband.git] / src / store / store.c
1 /*!
2  * @file store.c
3  * @brief 店の処理 / Store commands
4  * @date 2014/02/02
5  * @author
6  * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke\n
7  * This software may be copied and distributed for educational, research, and\n
8  * not for profit purposes provided that this copyright and statement are\n
9  * included in all such copies.\n
10  * 2014 Deskull rearranged comment for Doxygen.
11  */
12
13 #include "store/store.h"
14 #include "autopick/autopick-pref-processor.h"
15 #include "autopick/autopick.h"
16 #include "cmd-action/cmd-spell.h"
17 #include "cmd-io/cmd-diary.h"
18 #include "cmd-io/cmd-dump.h"
19 #include "cmd-io/cmd-help.h"
20 #include "cmd-io/cmd-knowledge.h"
21 #include "cmd-io/cmd-macro.h"
22 #include "cmd-io/cmd-process-screen.h"
23 #include "cmd-item/cmd-item.h"
24 #include "cmd-item/cmd-magiceat.h"
25 #include "cmd-item/cmd-smith.h"
26 #include "cmd-item/cmd-zapwand.h"
27 #include "cmd/cmd-basic.h"
28 #include "cmd/cmd-draw.h"
29 #include "cmd/cmd-visuals.h"
30 #include "combat/snipe.h"
31 #include "core/stuff-handler.h"
32 #include "floor/floor-events.h"
33 #include "floor/floor-town.h"
34 #include "floor/floor.h"
35 #include "floor/wild.h"
36 #include "inventory/inventory-object.h"
37 #include "inventory/player-inventory.h"
38 #include "io/files-util.h"
39 #include "io/write-diary.h"
40 #include "locale/japanese.h"
41 #include "main/music-definitions-table.h"
42 #include "main/sound-definitions-table.h"
43 #include "market/gold-magnification-table.h"
44 #include "mind/mind.h"
45 #include "object-enchant/item-feeling.h"
46 #include "object-enchant/special-object-flags.h"
47 #include "object/item-use-flags.h"
48 #include "object/object-flavor.h"
49 #include "object/object-generator.h"
50 #include "object/object-hook.h"
51 #include "object/object-kind.h"
52 #include "object/object-stack.h"
53 #include "object/object-value.h"
54 #include "perception/identification.h"
55 #include "perception/object-perception.h"
56 #include "player/avatar.h"
57 #include "player/player-class.h"
58 #include "player/player-effects.h"
59 #include "player/player-status.h"
60 #include "player/race-info-table.h"
61 #include "spell/spells3.h"
62 #include "store/black-market.h"
63 #include "store/rumor.h"
64 #include "store/say-comments.h"
65 #include "store/store-owners.h"
66 #include "store/store-util.h"
67 #include "system/angband.h"
68 #include "term/gameterm.h"
69 #include "util/object-sort.h"
70 #include "util/util.h"
71 #include "view/display-main-window.h"
72 #include "view/object-describer.h"
73 #include "world/world.h"
74
75 #define MIN_STOCK 12
76
77 static int store_top = 0;
78 static int store_bottom = 0;
79 static int xtra_stock = 0;
80 static const owner_type *ot_ptr = NULL;
81 static s16b old_town_num = 0;
82 static s16b inner_town_num = 0;
83
84 /*
85  * We store the current "store feat" here so everyone can access it
86  */
87 static int cur_store_feat;
88
89 /*!
90  * @brief 店舗価格を決定する. 無料にはならない /
91  * Determine the price of an item (qty one) in a store.
92  * @param o_ptr 店舗に並べるオブジェクト構造体の参照ポインタ
93  * @param greed 店主の強欲度
94  * @param flip TRUEならば店主にとっての買取価格、FALSEなら売出価格を計算
95  * @return アイテムの店舗価格
96  * @details
97  * <pre>
98  * This function takes into account the player's charisma, and the
99  * shop-keepers friendliness, and the shop-keeper's base greed, but
100  * never lets a shop-keeper lose money in a transaction.
101  * The "greed" value should exceed 100 when the player is "buying" the
102  * item, and should be less than 100 when the player is "selling" it.
103  * Hack -- the black market always charges twice as much as it should.
104  * Charisma adjustment runs from 80 to 130
105  * Racial adjustment runs from 95 to 130
106  * Since greed/charisma/racial adjustments are centered at 100, we need
107  * to adjust (by 200) to extract a usable multiplier.  Note that the
108  * "greed" value is always something (?).
109  * </pre>
110  */
111 static PRICE price_item(player_type *player_ptr, object_type *o_ptr, int greed, bool flip)
112 {
113         PRICE price = object_value(o_ptr);
114         if (price <= 0) return (0L);
115
116         int factor = rgold_adj[ot_ptr->owner_race][player_ptr->prace];
117         factor += adj_chr_gold[player_ptr->stat_ind[A_CHR]];
118         int adjust;
119         if (flip)
120         {
121                 adjust = 100 + (300 - (greed + factor));
122                 if (adjust > 100) adjust = 100;
123                 if (cur_store_num == STORE_BLACK)
124                         price = price / 2;
125
126                 price = (price * adjust + 50L) / 100L;
127         }
128         else
129         {
130                 adjust = 100 + ((greed + factor) - 300);
131                 if (adjust < 100) adjust = 100;
132                 if (cur_store_num == STORE_BLACK)
133                         price = price * 2;
134
135                 price = (s32b)(((u32b)price * (u32b)adjust + 50UL) / 100UL);
136         }
137
138         if (price <= 0L) return (1L);
139         return (price);
140 }
141
142
143 /*!
144  * @brief 店舗に品を置くスペースがあるかどうかの判定を返す /
145  * Check to see if the shop will be carrying too many objects   -RAK-
146  * @param o_ptr 店舗に置きたいオブジェクト構造体の参照ポインタ
147  * @return 置き場がないなら0、重ね合わせできるアイテムがあるなら-1、スペースがあるなら1を返す。
148  * @details
149  * <pre>
150  * Note that the shop, just like a player, will not accept things
151  * it cannot hold.      Before, one could "nuke" potions this way.
152  * Return value is now int:
153  *  0 : No space
154  * -1 : Can be combined to existing slot.
155  *  1 : Cannot be combined but there are empty spaces.
156  * </pre>
157  */
158 static int store_check_num(object_type *o_ptr)
159 {
160         object_type *j_ptr;
161         if ((cur_store_num == STORE_HOME) || (cur_store_num == STORE_MUSEUM))
162         {
163                 bool old_stack_force_notes = stack_force_notes;
164                 bool old_stack_force_costs = stack_force_costs;
165
166                 if (cur_store_num != STORE_HOME)
167                 {
168                         stack_force_notes = FALSE;
169                         stack_force_costs = FALSE;
170                 }
171
172                 for (int i = 0; i < st_ptr->stock_num; i++)
173                 {
174                         j_ptr = &st_ptr->stock[i];
175                         if (object_similar(j_ptr, o_ptr))
176                         {
177                                 if (cur_store_num != STORE_HOME)
178                                 {
179                                         stack_force_notes = old_stack_force_notes;
180                                         stack_force_costs = old_stack_force_costs;
181                                 }
182
183                                 return -1;
184                         }
185                 }
186
187                 if (cur_store_num != STORE_HOME)
188                 {
189                         stack_force_notes = old_stack_force_notes;
190                         stack_force_costs = old_stack_force_costs;
191                 }
192         }
193         else
194         {
195                 for (int i = 0; i < st_ptr->stock_num; i++)
196                 {
197                         j_ptr = &st_ptr->stock[i];
198                         if (store_object_similar(j_ptr, o_ptr)) return -1;
199                 }
200         }
201
202         /* Free space is always usable */
203         /*
204          * オプション powerup_home が設定されていると
205          * 我が家が 20 ページまで使える
206          */
207         if ((cur_store_num == STORE_HOME) && (powerup_home == FALSE))
208         {
209                 if (st_ptr->stock_num < ((st_ptr->stock_size) / 10))
210                 {
211                         return 1;
212                 }
213         }
214         else
215         {
216                 if (st_ptr->stock_num < st_ptr->stock_size)
217                 {
218                         return 1;
219                 }
220         }
221
222         return 0;
223 }
224
225
226 /*!
227  * @brief 現在の町の指定された店舗のアイテムを整理する /
228  * Combine and reorder items in store.
229  * @param store_num 店舗ID
230  * @return 実際に整理が行われたならばTRUEを返す。
231  */
232 bool combine_and_reorder_home(int store_num)
233 {
234     bool old_stack_force_notes = stack_force_notes;
235     bool old_stack_force_costs = stack_force_costs;
236     store_type *old_st_ptr = st_ptr;
237         st_ptr = &town_info[1].store[store_num];
238         bool flag = FALSE;
239         if (store_num != STORE_HOME)
240         {
241                 stack_force_notes = FALSE;
242                 stack_force_costs = FALSE;
243         }
244
245         bool combined = TRUE;
246         while (combined)
247         {
248                 combined = FALSE;
249                 for (int i = st_ptr->stock_num - 1; i > 0; i--)
250                 {
251                         object_type *o_ptr;
252                         o_ptr = &st_ptr->stock[i];
253                         if (!o_ptr->k_idx) continue;
254                         for (int j = 0; j < i; j++)
255                         {
256                                 object_type *j_ptr;
257                                 j_ptr = &st_ptr->stock[j];
258                                 if (!j_ptr->k_idx) continue;
259
260                                 /*
261                                  * Get maximum number of the stack if these
262                                  * are similar, get zero otherwise.
263                                  */
264                                 int max_num = object_similar_part(j_ptr, o_ptr);
265                                 if (max_num == 0 || j_ptr->number >= max_num) continue;
266
267                                 if (o_ptr->number + j_ptr->number <= max_num)
268                                 {
269                                         object_absorb(j_ptr, o_ptr);
270                                         st_ptr->stock_num--;
271                                         int k;
272                                         for (k = i; k < st_ptr->stock_num; k++)
273                                         {
274                                                 st_ptr->stock[k] = st_ptr->stock[k + 1];
275                                         }
276
277                                         object_wipe(&st_ptr->stock[k]);
278                                         combined = TRUE;
279                                         break;
280                                 }
281
282                                 ITEM_NUMBER old_num = o_ptr->number;
283                                 ITEM_NUMBER remain = j_ptr->number + o_ptr->number - max_num;
284                                 object_absorb(j_ptr, o_ptr);
285                                 o_ptr->number = remain;
286                                 if (o_ptr->tval == TV_ROD)
287                                 {
288                                         o_ptr->pval = o_ptr->pval * remain / old_num;
289                                         o_ptr->timeout = o_ptr->timeout * remain / old_num;
290                                 }
291                                 else if (o_ptr->tval == TV_WAND)
292                                 {
293                                         o_ptr->pval = o_ptr->pval * remain / old_num;
294                                 }
295
296                                 combined = TRUE;
297                                 break;
298                         }
299                 }
300
301                 flag |= combined;
302         }
303
304         for (int i = 0; i < st_ptr->stock_num; i++)
305         {
306                 object_type *o_ptr;
307                 o_ptr = &st_ptr->stock[i];
308                 if (!o_ptr->k_idx) continue;
309
310                 s32b o_value = object_value(o_ptr);
311                 int j;
312                 for (j = 0; j < st_ptr->stock_num; j++)
313                 {
314                         if (object_sort_comp(o_ptr, o_value, &st_ptr->stock[j])) break;
315                 }
316
317                 if (j >= i) continue;
318
319                 flag = TRUE;
320                 object_type *j_ptr;
321                 object_type forge;
322                 j_ptr = &forge;
323                 object_copy(j_ptr, &st_ptr->stock[i]);
324                 for (int k = i; k > j; k--)
325                 {
326                         object_copy(&st_ptr->stock[k], &st_ptr->stock[k - 1]);
327                 }
328
329                 object_copy(&st_ptr->stock[j], j_ptr);
330         }
331
332         st_ptr = old_st_ptr;
333         if (store_num != STORE_HOME)
334         {
335                 stack_force_notes = old_stack_force_notes;
336                 stack_force_costs = old_stack_force_costs;
337         }
338
339         return flag;
340 }
341
342
343 /*!
344  * @brief 我が家にオブジェクトを加える /
345  * Add the item "o_ptr" to the inventory of the "Home"
346  * @param o_ptr 加えたいオブジェクトの構造体参照ポインタ
347  * @return 収めた先のID
348  * @details
349  * <pre>
350  * In all cases, return the slot (or -1) where the object was placed
351  * Note that this is a hacked up version of "store_item_to_inventory()".
352  * Also note that it may not correctly "adapt" to "knowledge" bacoming
353  * known, the player may have to pick stuff up and drop it again.
354  * </pre>
355  */
356 static int home_carry(player_type *player_ptr, object_type *o_ptr)
357 {
358     bool old_stack_force_notes = stack_force_notes;
359     bool old_stack_force_costs = stack_force_costs;
360     if (cur_store_num != STORE_HOME)
361         {
362                 stack_force_notes = FALSE;
363                 stack_force_costs = FALSE;
364         }
365
366         for (int slot = 0; slot < st_ptr->stock_num; slot++)
367         {
368                 object_type *j_ptr;
369                 j_ptr = &st_ptr->stock[slot];
370                 if (object_similar(j_ptr, o_ptr))
371                 {
372                         object_absorb(j_ptr, o_ptr);
373                         if (cur_store_num != STORE_HOME)
374                         {
375                                 stack_force_notes = old_stack_force_notes;
376                                 stack_force_costs = old_stack_force_costs;
377                         }
378
379                         return (slot);
380                 }
381         }
382
383         if (cur_store_num != STORE_HOME)
384         {
385                 stack_force_notes = old_stack_force_notes;
386                 stack_force_costs = old_stack_force_costs;
387         }
388
389         /* No space? */
390         /*
391          * 隠し機能: オプション powerup_home が設定されていると
392          *           我が家が 20 ページまで使える
393          */
394         if ((cur_store_num != STORE_HOME) || (powerup_home == TRUE))
395         {
396                 if (st_ptr->stock_num >= st_ptr->stock_size)
397                 {
398                         return -1;
399                 }
400         }
401         else
402         {
403                 if (st_ptr->stock_num >= ((st_ptr->stock_size) / 10))
404                 {
405                         return -1;
406                 }
407         }
408
409         PRICE value = object_value(o_ptr);
410         int slot;
411         for (slot = 0; slot < st_ptr->stock_num; slot++)
412         {
413                 if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
414         }
415
416         for (int i = st_ptr->stock_num; i > slot; i--)
417         {
418                 st_ptr->stock[i] = st_ptr->stock[i - 1];
419         }
420
421         st_ptr->stock_num++;
422         st_ptr->stock[slot] = *o_ptr;
423         chg_virtue(player_ptr, V_SACRIFICE, -1);
424         (void)combine_and_reorder_home(cur_store_num);
425         return slot;
426 }
427
428
429 /*!
430  * @brief 店舗の割引対象外にするかどうかを判定 /
431  * Eliminate need to bargain if player has haggled well in the past
432  * @param minprice アイテムの最低販売価格
433  * @return 割引を禁止するならTRUEを返す。
434  */
435 static bool noneedtobargain(PRICE minprice)
436 {
437         PRICE good = st_ptr->good_buy;
438         PRICE bad = st_ptr->bad_buy;
439         if (minprice < 10L) return TRUE;
440         if (good == MAX_SHORT) return TRUE;
441         if (good > ((3 * bad) + (5 + (minprice / 50)))) return TRUE;
442
443         return FALSE;
444 }
445
446
447 /*!
448  * @brief 店主の持つプレイヤーに対する売買の良し悪し経験を記憶する /
449  * Update the bargain info
450  * @param price 実際の取引価格
451  * @param minprice 店主の提示した価格
452  * @param num 売買数
453  * @return なし
454  */
455 static void updatebargain(PRICE price, PRICE minprice, int num)
456 {
457         if (!manual_haggle) return;
458         if ((minprice / num) < 10L) return;
459         if (price == minprice)
460         {
461                 if (st_ptr->good_buy < MAX_SHORT)
462                 {
463                         st_ptr->good_buy++;
464                 }
465         }
466         else
467         {
468                 if (st_ptr->bad_buy < MAX_SHORT)
469                 {
470                         st_ptr->bad_buy++;
471                 }
472         }
473 }
474
475
476 /*!
477  * @brief 店の商品リストを再表示する /
478  * Re-displays a single store entry
479  * @param player_ptr プレーヤーへの参照ポインタ
480  * @param pos 表示行
481  * @return なし
482  */
483 static void display_entry(player_type *player_ptr, int pos)
484 {
485         object_type *o_ptr;
486         o_ptr = &st_ptr->stock[pos];
487         int i = (pos % store_bottom);
488
489         /* Label it, clear the line --(-- */
490         char out_val[160];
491         (void)sprintf(out_val, "%c) ", ((i > 25) ? toupper(I2A(i - 26)) : I2A(i)));
492         prt(out_val, i + 6, 0);
493
494         int cur_col = 3;
495         if (show_item_graph)
496         {
497                 TERM_COLOR a = object_attr(o_ptr);
498                 SYMBOL_CODE c = object_char(o_ptr);
499
500                 Term_queue_bigchar(cur_col, i + 6, a, c, 0, 0);
501                 if (use_bigtile) cur_col++;
502
503                 cur_col += 2;
504         }
505
506         /* Describe an item in the home */
507         int maxwid = 75;
508         if ((cur_store_num == STORE_HOME) || (cur_store_num == STORE_MUSEUM))
509         {
510                 maxwid = 75;
511                 if (show_weights) maxwid -= 10;
512
513                 GAME_TEXT o_name[MAX_NLEN];
514                 object_desc(player_ptr, o_name, o_ptr, 0);
515                 o_name[maxwid] = '\0';
516                 c_put_str(tval_to_attr[o_ptr->tval], o_name, i + 6, cur_col);
517                 if (show_weights)
518                 {
519                         WEIGHT wgt = o_ptr->weight;
520                         sprintf(out_val, _("%3d.%1d kg", "%3d.%d lb"), _(lbtokg1(wgt), wgt / 10), _(lbtokg2(wgt), wgt % 10));
521                         put_str(out_val, i + 6, _(67, 68));
522                 }
523
524                 return;
525         }
526
527         maxwid = 65;
528         if (show_weights) maxwid -= 7;
529
530         GAME_TEXT o_name[MAX_NLEN];
531         object_desc(player_ptr, o_name, o_ptr, 0);
532         o_name[maxwid] = '\0';
533         c_put_str(tval_to_attr[o_ptr->tval], o_name, i + 6, cur_col);
534
535         if (show_weights)
536         {
537                 int wgt = o_ptr->weight;
538                 sprintf(out_val, "%3d.%1d", _(lbtokg1(wgt), wgt / 10), _(lbtokg2(wgt), wgt % 10));
539                 put_str(out_val, i + 6, _(60, 61));
540         }
541
542         s32b x;
543         if (o_ptr->ident & (IDENT_FIXED))
544         {
545                 x = price_item(player_ptr, o_ptr, ot_ptr->min_inflate, FALSE);
546                 (void)sprintf(out_val, _("%9ld固", "%9ld F"), (long)x);
547                 put_str(out_val, i + 6, 68);
548                 return;
549         }
550
551         if (!manual_haggle)
552         {
553                 x = price_item(player_ptr, o_ptr, ot_ptr->min_inflate, FALSE);
554                 if (!noneedtobargain(x)) x += x / 10;
555
556                 (void)sprintf(out_val, "%9ld  ", (long)x);
557                 put_str(out_val, i + 6, 68);
558                 return;
559         }
560
561         x = price_item(player_ptr, o_ptr, ot_ptr->max_inflate, FALSE);
562         (void)sprintf(out_val, "%9ld  ", (long)x);
563         put_str(out_val, i + 6, 68);
564 }
565
566
567 /*!
568  * @brief 店の商品リストを表示する /
569  * Displays a store's inventory -RAK-
570  * @param player_ptr プレーヤーへの参照ポインタ
571  * @return なし
572  * @details
573  * All prices are listed as "per individual object".  -BEN-
574  */
575 static void display_store_inventory(player_type *player_ptr)
576 {
577         int k;
578         for (k = 0; k < store_bottom; k++)
579         {
580                 if (store_top + k >= st_ptr->stock_num) break;
581
582                 display_entry(player_ptr, store_top + k);
583         }
584
585         for (int i = k; i < store_bottom + 1; i++)
586                 prt("", i + 6, 0);
587
588         put_str(_("          ", "        "), 5, _(20, 22));
589         if (st_ptr->stock_num > store_bottom)
590         {
591                 prt(_("-続く-", "-more-"), k + 6, 3);
592                 put_str(format(_("(%dページ)  ", "(Page %d)  "), store_top / store_bottom + 1), 5, _(20, 22));
593         }
594
595         if (cur_store_num == STORE_HOME || cur_store_num == STORE_MUSEUM)
596         {
597                 k = st_ptr->stock_size;
598                 if (cur_store_num == STORE_HOME && !powerup_home) k /= 10;
599
600                 put_str(format(_("アイテム数:  %4d/%4d", "Objects:  %4d/%4d"), st_ptr->stock_num, k), 19 + xtra_stock, _(27, 30));
601         }
602 }
603
604
605 /*!
606  * @brief プレイヤーの所持金を表示する /
607  * Displays players gold                                        -RAK-
608  * @param player_ptr プレーヤーへの参照ポインタ
609  * @return なし
610  * @details
611  */
612 static void store_prt_gold(player_type *player_ptr)
613 {
614         prt(_("手持ちのお金: ", "Gold Remaining: "), 19 + xtra_stock, 53);
615         char out_val[64];
616         sprintf(out_val, "%9ld", (long)player_ptr->au);
617         prt(out_val, 19 + xtra_stock, 68);
618 }
619
620
621 /*!
622  * @brief 店舗情報全体を表示するメインルーチン /
623  * Displays store (after clearing screen)               -RAK-
624  * @param player_ptr プレーヤーへの参照ポインタ
625  * @return なし
626  * @details
627  */
628 static void display_store(player_type *player_ptr)
629 {
630         Term_clear();
631         if (cur_store_num == STORE_HOME)
632         {
633                 put_str(_("我が家", "Your Home"), 3, 31);
634                 put_str(_("アイテムの一覧", "Item Description"), 5, 4);
635                 if (show_weights)
636                 {
637                         put_str(_("  重さ", "Weight"), 5, 70);
638                 }
639
640                 store_prt_gold(player_ptr);
641                 display_store_inventory(player_ptr);
642                 return;
643         }
644
645         if (cur_store_num == STORE_MUSEUM)
646         {
647                 put_str(_("博物館", "Museum"), 3, 31);
648                 put_str(_("アイテムの一覧", "Item Description"), 5, 4);
649                 if (show_weights)
650                 {
651                         put_str(_("  重さ", "Weight"), 5, 70);
652                 }
653
654                 store_prt_gold(player_ptr);
655                 display_store_inventory(player_ptr);
656                 return;
657         }
658
659         concptr store_name = (f_name + f_info[cur_store_feat].name);
660         concptr owner_name = (ot_ptr->owner_name);
661         concptr race_name = race_info[ot_ptr->owner_race].title;
662         char buf[80];
663         sprintf(buf, "%s (%s)", owner_name, race_name);
664         put_str(buf, 3, 10);
665
666         sprintf(buf, "%s (%ld)", store_name, (long)(ot_ptr->max_cost));
667         prt(buf, 3, 50);
668
669         put_str(_("商品の一覧", "Item Description"), 5, 5);
670         if (show_weights)
671         {
672                 put_str(_("  重さ", "Weight"), 5, 60);
673         }
674
675         put_str(_(" 価格", "Price"), 5, 72);
676         store_prt_gold(player_ptr);
677         display_store_inventory(player_ptr);
678 }
679
680
681 /*!
682  * @brief 店舗からアイテムを選択する /
683  * Get the ID of a store item and return its value      -RAK-
684  * @param com_val 選択IDを返す参照ポインタ
685  * @param pmt メッセージキャプション
686  * @param i 選択範囲の最小値
687  * @param j 選択範囲の最大値
688  * @return 実際に選択したらTRUE、キャンセルしたらFALSE
689  */
690 static int get_stock(COMMAND_CODE *com_val, concptr pmt, int i, int j)
691 {
692         if (repeat_pull(com_val) && (*com_val >= i) && (*com_val <= j))
693         {
694                 return TRUE;
695         }
696
697         msg_print(NULL);
698         *com_val = (-1);
699         char lo = I2A(i);
700         char hi = (j > 25) ? toupper(I2A(j - 26)) : I2A(j);
701         char out_val[160];
702 #ifdef JP
703         (void)sprintf(out_val, "(%s:%c-%c, ESCで中断) %s",
704                 (((cur_store_num == STORE_HOME) || (cur_store_num == STORE_MUSEUM)) ? "アイテム" : "商品"),
705                 lo, hi, pmt);
706 #else
707         (void)sprintf(out_val, "(Items %c-%c, ESC to exit) %s",
708                 lo, hi, pmt);
709 #endif
710
711         char command;
712         while (TRUE)
713         {
714                 if (!get_com(out_val, &command, FALSE)) break;
715
716                 COMMAND_CODE k;
717                 if (islower(command))
718                         k = A2I(command);
719                 else if (isupper(command))
720                         k = A2I(tolower(command)) + 26;
721                 else
722                         k = -1;
723
724                 if ((k >= i) && (k <= j))
725                 {
726                         *com_val = k;
727                         break;
728                 }
729
730                 bell();
731         }
732
733         prt("", 0, 0);
734         if (command == ESCAPE) return FALSE;
735
736         repeat_push(*com_val);
737         return TRUE;
738 }
739
740
741 /*!
742  * @brief 店主の不満度を増やし、プレイヤーを締め出す判定と処理を行う /
743  * Increase the insult counter and get angry if too many -RAK-
744  * @return プレイヤーを締め出す場合TRUEを返す
745  */
746 static int increase_insults(void)
747 {
748         st_ptr->insult_cur++;
749         if (st_ptr->insult_cur <= ot_ptr->insult_max) return FALSE;
750
751         say_comment_4();
752
753         st_ptr->insult_cur = 0;
754         st_ptr->good_buy = 0;
755         st_ptr->bad_buy = 0;
756         st_ptr->store_open = current_world_ptr->game_turn + TURNS_PER_TICK * TOWN_DAWN / 8 + randint1(TURNS_PER_TICK*TOWN_DAWN / 8);
757
758         return TRUE;
759 }
760
761
762 /*!
763  * @brief 店主の不満度を減らす /
764  * Decrease insults                             -RAK-
765  * @return プレイヤーを締め出す場合TRUEを返す
766  */
767 static void decrease_insults(void)
768 {
769         if (st_ptr->insult_cur) st_ptr->insult_cur--;
770 }
771
772
773 /*!
774  * @brief 店主の不満度が増えた場合のみのメッセージを表示する /
775  * Have insulted while haggling                         -RAK-
776  * @return プレイヤーを締め出す場合TRUEを返す
777  */
778 static int haggle_insults(void)
779 {
780         if (increase_insults()) return TRUE;
781
782         say_comment_5();
783         return FALSE;
784 }
785
786 /*
787  * Mega-Hack -- Enable "increments"
788  */
789 static bool allow_inc = FALSE;
790
791 /*
792  * Mega-Hack -- Last "increment" during haggling
793  */
794 static s32b last_inc = 0L;
795
796 /*!
797  * @brief 交渉価格を確認と認証の是非を行う /
798  * Get a haggle
799  * @param pmt メッセージ
800  * @param poffer 別途価格提示をした場合の値を返す参照ポインタ
801  * @param price 現在の交渉価格
802  * @param final 最終確定価格ならばTRUE
803  * @return プレイヤーを締め出す場合TRUEを返す
804  */
805 static int get_haggle(concptr pmt, s32b *poffer, PRICE price, int final)
806 {
807         GAME_TEXT buf[128];
808         if (!allow_inc) last_inc = 0L;
809
810         if (final)
811         {
812                 sprintf(buf, _("%s [承諾] ", "%s [accept] "), pmt);
813         }
814         else if (last_inc < 0)
815         {
816                 sprintf(buf, _("%s [-$%ld] ", "%s [-%ld] "), pmt, (long)(ABS(last_inc)));
817         }
818         else if (last_inc > 0)
819         {
820                 sprintf(buf, _("%s [+$%ld] ", "%s [+%ld] "), pmt, (long)(ABS(last_inc)));
821         }
822         else
823         {
824                 sprintf(buf, "%s ", pmt);
825         }
826
827         msg_print(NULL);
828         GAME_TEXT out_val[160];
829         while (TRUE)
830         {
831                 bool res;
832                 prt(buf, 0, 0);
833                 strcpy(out_val, "");
834
835                 /*
836                  * Ask the user for a response.
837                  * Don't allow to use numpad as cursor key.
838                  */
839                 res = askfor_aux(out_val, 32, FALSE);
840                 prt("", 0, 0);
841                 if (!res) return FALSE;
842
843                 concptr p;
844                 for (p = out_val; *p == ' '; p++) /* loop */;
845
846                 if (*p == '\0')
847                 {
848                         if (final)
849                         {
850                                 *poffer = price;
851                                 last_inc = 0L;
852                                 break;
853                         }
854
855                         if (allow_inc && last_inc)
856                         {
857                                 *poffer += last_inc;
858                                 break;
859                         }
860
861                         msg_print(_("値がおかしいです。", "Invalid response."));
862                         msg_print(NULL);
863                         continue;
864                 }
865
866                 s32b i = atol(p);
867                 if ((*p == '+' || *p == '-'))
868                 {
869                         if (allow_inc)
870                         {
871                                 *poffer += i;
872                                 last_inc = i;
873                                 break;
874                         }
875                 }
876                 else
877                 {
878                         *poffer = i;
879                         last_inc = 0L;
880                         break;
881                 }
882         }
883
884         return TRUE;
885 }
886
887
888 /*!
889  * @brief 店主がプレイヤーからの交渉価格を判断する /
890  * Receive an offer (from the player)
891  * @param pmt メッセージ
892  * @param poffer 店主からの交渉価格を返す参照ポインタ
893  * @param last_offer 現在の交渉価格
894  * @param factor 店主の価格基準倍率
895  * @param price アイテムの実価値
896  * @param final 最終価格確定ならばTRUE
897  * @return プレイヤーの価格に対して不服ならばTRUEを返す /
898  * Return TRUE if offer is NOT okay
899  */
900 static bool receive_offer(concptr pmt, s32b *poffer, s32b last_offer, int factor, PRICE price, int final)
901 {
902         while (TRUE)
903         {
904                 if (!get_haggle(pmt, poffer, price, final)) return TRUE;
905                 if (((*poffer) * factor) >= (last_offer * factor)) break;
906                 if (haggle_insults()) return TRUE;
907
908                 (*poffer) = last_offer;
909         }
910
911         return FALSE;
912 }
913
914
915 /*!
916  * @brief プレイヤーが購入する時の値切り処理メインルーチン /
917  * Haggling routine                             -RAK-
918  * @param player_ptr プレーヤーへの参照ポインタ
919  * @param o_ptr オブジェクトの構造体参照ポインタ
920  * @param price 最終価格を返す参照ポインタ
921  * @return プレイヤーの価格に対して店主が不服ならばTRUEを返す /
922  * Return TRUE if purchase is NOT successful
923  */
924 static bool purchase_haggle(player_type *player_ptr, object_type *o_ptr, s32b *price)
925 {
926         s32b cur_ask = price_item(player_ptr, o_ptr, ot_ptr->max_inflate, FALSE);
927         s32b final_ask = price_item(player_ptr, o_ptr, ot_ptr->min_inflate, FALSE);
928         int noneed = noneedtobargain(final_ask);
929         bool final = FALSE;
930         concptr pmt = _("提示価格", "Asking");
931         if (noneed || !manual_haggle)
932         {
933                 if (noneed)
934                 {
935                         msg_print(_("結局この金額にまとまった。", "You eventually agree upon the price."));
936                         msg_print(NULL);
937                 }
938                 else
939                 {
940                         msg_print(_("すんなりとこの金額にまとまった。", "You quickly agree upon the price."));
941                         msg_print(NULL);
942                         final_ask += final_ask / 10;
943                 }
944
945                 cur_ask = final_ask;
946                 pmt = _("最終提示価格", "Final Offer");
947                 final = TRUE;
948         }
949
950         cur_ask *= o_ptr->number;
951         final_ask *= o_ptr->number;
952         s32b min_per = ot_ptr->haggle_per;
953         s32b max_per = min_per * 3;
954         s32b last_offer = object_value(o_ptr) * o_ptr->number;
955         last_offer = last_offer * (200 - (int)(ot_ptr->max_inflate)) / 100L;
956         if (last_offer <= 0) last_offer = 1;
957
958         s32b offer = 0;
959         allow_inc = FALSE;
960         bool flag = FALSE;
961         int annoyed = 0;
962         bool cancel = FALSE;
963         *price = 0;
964         while (!flag)
965         {
966                 bool loop_flag = TRUE;
967
968                 while (!flag && loop_flag)
969                 {
970                         char out_val[160];
971                         (void)sprintf(out_val, "%s :  %ld", pmt, (long)cur_ask);
972                         put_str(out_val, 1, 0);
973                         cancel = receive_offer(_("提示する金額? ", "What do you offer? "), &offer, last_offer, 1, cur_ask, final);
974                         if (cancel)
975                         {
976                                 flag = TRUE;
977                         }
978                         else if (offer > cur_ask)
979                         {
980                                 say_comment_6();
981                                 offer = last_offer;
982                         }
983                         else if (offer == cur_ask)
984                         {
985                                 flag = TRUE;
986                                 *price = offer;
987                         }
988                         else
989                         {
990                                 loop_flag = FALSE;
991                         }
992                 }
993
994                 if (flag) continue;
995
996                 s32b x1 = 100 * (offer - last_offer) / (cur_ask - last_offer);
997                 if (x1 < min_per)
998                 {
999                         if (haggle_insults())
1000                         {
1001                                 flag = TRUE;
1002                                 cancel = TRUE;
1003                         }
1004                 }
1005                 else if (x1 > max_per)
1006                 {
1007                         x1 = x1 * 3 / 4;
1008                         if (x1 < max_per) x1 = max_per;
1009                 }
1010
1011                 s32b x2 = rand_range(x1 - 2, x1 + 2);
1012                 s32b x3 = ((cur_ask - offer) * x2 / 100L) + 1;
1013                 if (x3 < 0) x3 = 0;
1014                 cur_ask -= x3;
1015
1016                 if (cur_ask < final_ask)
1017                 {
1018                         final = TRUE;
1019                         cur_ask = final_ask;
1020                         pmt = _("最終提示価格", "What do you offer? ");
1021                         annoyed++;
1022                         if (annoyed > 3)
1023                         {
1024                                 (void)(increase_insults());
1025                                 cancel = TRUE;
1026                                 flag = TRUE;
1027                         }
1028                 }
1029                 else if (offer >= cur_ask)
1030                 {
1031                         flag = TRUE;
1032                         *price = offer;
1033                 }
1034
1035                 if (flag) continue;
1036
1037                 last_offer = offer;
1038                 allow_inc = TRUE;
1039                 prt("", 1, 0);
1040                 char out_val[160];
1041                 (void)sprintf(out_val, _("前回の提示金額: $%ld", "Your last offer: %ld"), (long)last_offer);
1042                 put_str(out_val, 1, 39);
1043                 say_comment_2(cur_ask, annoyed);
1044         }
1045
1046         if (cancel) return TRUE;
1047
1048         updatebargain(*price, final_ask, o_ptr->number);
1049         return FALSE;
1050 }
1051
1052
1053 /*!
1054  * @brief プレイヤーが売却する時の値切り処理メインルーチン /
1055  * Haggling routine                             -RAK-
1056  * @param player_ptr プレーヤーへの参照ポインタ
1057  * @param o_ptr オブジェクトの構造体参照ポインタ
1058  * @param price 最終価格を返す参照ポインタ
1059  * @return プレイヤーの価格に対して店主が不服ならばTRUEを返す /
1060  * Return TRUE if purchase is NOT successful
1061  */
1062 static bool sell_haggle(player_type *player_ptr, object_type *o_ptr, s32b *price)
1063 {
1064         s32b cur_ask = price_item(player_ptr, o_ptr, ot_ptr->max_inflate, TRUE);
1065         s32b final_ask = price_item(player_ptr, o_ptr, ot_ptr->min_inflate, TRUE);
1066         int noneed = noneedtobargain(final_ask);
1067         s32b purse = (s32b)(ot_ptr->max_cost);
1068         bool final = FALSE;
1069         concptr pmt = _("提示金額", "Offer");
1070         if (noneed || !manual_haggle || (final_ask >= purse))
1071         {
1072                 if (!manual_haggle && !noneed)
1073                 {
1074                         final_ask -= final_ask / 10;
1075                 }
1076
1077                 if (final_ask >= purse)
1078                 {
1079                         msg_print(_("即座にこの金額にまとまった。", "You instantly agree upon the price."));
1080                         msg_print(NULL);
1081                         final_ask = purse;
1082                 }
1083                 else if (noneed)
1084                 {
1085                         msg_print(_("結局この金額にまとまった。", "You eventually agree upon the price."));
1086                         msg_print(NULL);
1087                 }
1088                 else
1089                 {
1090                         msg_print(_("すんなりとこの金額にまとまった。", "You quickly agree upon the price."));
1091                         msg_print(NULL);
1092                 }
1093
1094                 cur_ask = final_ask;
1095                 final = TRUE;
1096                 pmt = _("最終提示金額", "Final Offer");
1097         }
1098
1099         cur_ask *= o_ptr->number;
1100         final_ask *= o_ptr->number;
1101
1102         s32b min_per = ot_ptr->haggle_per;
1103         s32b max_per = min_per * 3;
1104         s32b last_offer = object_value(o_ptr) * o_ptr->number;
1105         last_offer = last_offer * ot_ptr->max_inflate / 100L;
1106         s32b offer = 0;
1107         allow_inc = FALSE;
1108         bool flag = FALSE;
1109         bool loop_flag;
1110         int annoyed = 0;
1111         bool cancel = FALSE;
1112         *price = 0;
1113         while (!flag)
1114         {
1115                 while (TRUE)
1116                 {
1117                         loop_flag = TRUE;
1118
1119                         char out_val[160];
1120                         (void)sprintf(out_val, "%s :  %ld", pmt, (long)cur_ask);
1121                         put_str(out_val, 1, 0);
1122                         cancel = receive_offer(_("提示する価格? ", "What price do you ask? "),
1123                                 &offer, last_offer, -1, cur_ask, final);
1124
1125                         if (cancel)
1126                         {
1127                                 flag = TRUE;
1128                         }
1129                         else if (offer < cur_ask)
1130                         {
1131                                 say_comment_6();
1132                                 offer = last_offer;
1133                         }
1134                         else if (offer == cur_ask)
1135                         {
1136                                 flag = TRUE;
1137                                 *price = offer;
1138                         }
1139                         else
1140                         {
1141                                 loop_flag = FALSE;
1142                         }
1143
1144                         if (flag || !loop_flag) break;
1145                 }
1146
1147                 if (flag) continue;
1148
1149                 s32b x1 = 100 * (last_offer - offer) / (last_offer - cur_ask);
1150                 if (x1 < min_per)
1151                 {
1152                         if (haggle_insults())
1153                         {
1154                                 flag = TRUE;
1155                                 cancel = TRUE;
1156                         }
1157                 }
1158                 else if (x1 > max_per)
1159                 {
1160                         x1 = x1 * 3 / 4;
1161                         if (x1 < max_per) x1 = max_per;
1162                 }
1163
1164                 s32b x2 = rand_range(x1 - 2, x1 + 2);
1165                 s32b x3 = ((offer - cur_ask) * x2 / 100L) + 1;
1166                 if (x3 < 0) x3 = 0;
1167                 cur_ask += x3;
1168
1169                 if (cur_ask > final_ask)
1170                 {
1171                         cur_ask = final_ask;
1172                         final = TRUE;
1173                         pmt = _("最終提示金額", "Final Offer");
1174
1175                         annoyed++;
1176                         if (annoyed > 3)
1177                         {
1178                                 flag = TRUE;
1179 #ifdef JP
1180                                 /* 追加 $0 で買い取られてしまうのを防止 By FIRST*/
1181                                 cancel = TRUE;
1182 #endif
1183                                 (void)(increase_insults());
1184                         }
1185                 }
1186                 else if (offer <= cur_ask)
1187                 {
1188                         flag = TRUE;
1189                         *price = offer;
1190                 }
1191
1192                 last_offer = offer;
1193                 allow_inc = TRUE;
1194                 prt("", 1, 0);
1195                 char out_val[160];
1196                 (void)sprintf(out_val, _("前回の提示価格 $%ld", "Your last bid %ld"), (long)last_offer);
1197                 put_str(out_val, 1, 39);
1198                 say_comment_3(cur_ask, annoyed);
1199         }
1200
1201         if (cancel) return TRUE;
1202
1203         updatebargain(*price, final_ask, o_ptr->number);
1204         return FALSE;
1205 }
1206
1207
1208 /*!
1209  * @brief 店からの購入処理のメインルーチン /
1210  * Buy an item from a store                     -RAK-
1211  * @param player_ptr プレーヤーへの参照ポインタ
1212  * @return なし
1213  */
1214 static void store_purchase(player_type *player_ptr)
1215 {
1216         if (cur_store_num == STORE_MUSEUM)
1217         {
1218                 msg_print(_("博物館から取り出すことはできません。", "Museum."));
1219                 return;
1220         }
1221
1222         if (st_ptr->stock_num <= 0)
1223         {
1224                 if (cur_store_num == STORE_HOME)
1225                         msg_print(_("我が家には何も置いてありません。", "Your home is empty."));
1226                 else
1227                         msg_print(_("現在商品の在庫を切らしています。", "I am currently out of stock."));
1228                 return;
1229         }
1230
1231         int i = (st_ptr->stock_num - store_top);
1232         if (i > store_bottom) i = store_bottom;
1233
1234         char out_val[160];
1235 #ifdef JP
1236         /* ブラックマーケットの時は別のメッセージ */
1237         switch (cur_store_num)
1238         {
1239         case 7:
1240                 sprintf(out_val, "どのアイテムを取りますか? ");
1241                 break;
1242         case 6:
1243                 sprintf(out_val, "どれ? ");
1244                 break;
1245         default:
1246                 sprintf(out_val, "どの品物が欲しいんだい? ");
1247                 break;
1248         }
1249 #else
1250         if (cur_store_num == STORE_HOME)
1251         {
1252                 sprintf(out_val, "Which item do you want to take? ");
1253         }
1254         else
1255         {
1256                 sprintf(out_val, "Which item are you interested in? ");
1257         }
1258 #endif
1259
1260         COMMAND_CODE item;
1261         if (!get_stock(&item, out_val, 0, i - 1)) return;
1262
1263         item = item + store_top;
1264         object_type *o_ptr;
1265         o_ptr = &st_ptr->stock[item];
1266         ITEM_NUMBER amt = 1;
1267         object_type forge;
1268         object_type *j_ptr;
1269         j_ptr = &forge;
1270         object_copy(j_ptr, o_ptr);
1271
1272         /*
1273          * If a rod or wand, allocate total maximum timeouts or charges
1274          * between those purchased and left on the shelf.
1275          */
1276         reduce_charges(j_ptr, o_ptr->number - amt);
1277         j_ptr->number = amt;
1278         if (!check_store_item_to_inventory(j_ptr))
1279         {
1280                 msg_print(_("そんなにアイテムを持てない。", "You cannot carry that many different items."));
1281                 return;
1282         }
1283
1284         PRICE best = price_item(player_ptr, j_ptr, ot_ptr->min_inflate, FALSE);
1285         if (o_ptr->number > 1)
1286         {
1287                 if ((cur_store_num != STORE_HOME) &&
1288                         (o_ptr->ident & IDENT_FIXED))
1289                 {
1290                         msg_format(_("一つにつき $%ldです。", "That costs %ld gold per item."), (long)(best));
1291                 }
1292
1293                 amt = get_quantity(NULL, o_ptr->number);
1294                 if (amt <= 0) return;
1295         }
1296
1297         j_ptr = &forge;
1298         object_copy(j_ptr, o_ptr);
1299
1300         /*
1301          * If a rod or wand, allocate total maximum timeouts or charges
1302          * between those purchased and left on the shelf.
1303          */
1304         reduce_charges(j_ptr, o_ptr->number - amt);
1305         j_ptr->number = amt;
1306         if (!check_store_item_to_inventory(j_ptr))
1307         {
1308                 msg_print(_("ザックにそのアイテムを入れる隙間がない。", "You cannot carry that many items."));
1309                 return;
1310         }
1311
1312         int choice;
1313         COMMAND_CODE item_new;
1314         PRICE price;
1315         if (cur_store_num == STORE_HOME)
1316         {
1317                 bool combined_or_reordered;
1318                 distribute_charges(o_ptr, j_ptr, amt);
1319                 item_new = store_item_to_inventory(player_ptr, j_ptr);
1320                 GAME_TEXT o_name[MAX_NLEN];
1321                 object_desc(player_ptr, o_name, &player_ptr->inventory_list[item_new], 0);
1322
1323                 msg_format(_("%s(%c)を取った。", "You have %s (%c)."), o_name, index_to_label(item_new));
1324                 handle_stuff(player_ptr);
1325
1326                 i = st_ptr->stock_num;
1327                 store_item_increase(item, -amt);
1328                 store_item_optimize(item);
1329                 combined_or_reordered = combine_and_reorder_home(STORE_HOME);
1330                 if (i == st_ptr->stock_num)
1331                 {
1332                         if (combined_or_reordered) display_store_inventory(player_ptr);
1333                         else display_entry(player_ptr, item);
1334                 }
1335                 else
1336                 {
1337                         if (st_ptr->stock_num == 0) store_top = 0;
1338                         else if (store_top >= st_ptr->stock_num) store_top -= store_bottom;
1339                         display_store_inventory(player_ptr);
1340
1341                         chg_virtue(player_ptr, V_SACRIFICE, 1);
1342                 }
1343
1344                 return;
1345         }
1346
1347         if (o_ptr->ident & (IDENT_FIXED))
1348         {
1349                 choice = 0;
1350                 price = (best * j_ptr->number);
1351         }
1352         else
1353         {
1354                 GAME_TEXT o_name[MAX_NLEN];
1355                 object_desc(player_ptr, o_name, j_ptr, 0);
1356                 msg_format(_("%s(%c)を購入する。", "Buying %s (%c)."), o_name, I2A(item));
1357                 msg_print(NULL);
1358                 choice = purchase_haggle(player_ptr, j_ptr, &price);
1359                 if (st_ptr->store_open >= current_world_ptr->game_turn) return;
1360         }
1361
1362         if (choice != 0) return;
1363         if (price == (best * j_ptr->number)) o_ptr->ident |= (IDENT_FIXED);
1364         if (player_ptr->au < price)
1365         {
1366                 msg_print(_("お金が足りません。", "You do not have enough gold."));
1367                 return;
1368         }
1369
1370         say_comment_1(player_ptr);
1371         if (cur_store_num == STORE_BLACK)
1372                 chg_virtue(player_ptr, V_JUSTICE, -1);
1373         if ((o_ptr->tval == TV_BOTTLE) && (cur_store_num != STORE_HOME))
1374                 chg_virtue(player_ptr, V_NATURE, -1);
1375
1376         sound(SOUND_BUY);
1377         decrease_insults();
1378         player_ptr->au -= price;
1379         store_prt_gold(player_ptr);
1380         object_aware(player_ptr, j_ptr);
1381         j_ptr->ident &= ~(IDENT_FIXED);
1382         GAME_TEXT o_name[MAX_NLEN];
1383         object_desc(player_ptr, o_name, j_ptr, 0);
1384
1385         msg_format(_("%sを $%ldで購入しました。", "You bought %s for %ld gold."), o_name, (long)price);
1386
1387         strcpy(record_o_name, o_name);
1388         record_turn = current_world_ptr->game_turn;
1389
1390         if (record_buy) exe_write_diary(player_ptr, DIARY_BUY, 0, o_name);
1391         object_desc(player_ptr, o_name, o_ptr, OD_NAME_ONLY);
1392         if (record_rand_art && o_ptr->art_name)
1393                 exe_write_diary(player_ptr, DIARY_ART, 0, o_name);
1394
1395         j_ptr->inscription = 0;
1396         j_ptr->feeling = FEEL_NONE;
1397         j_ptr->ident &= ~(IDENT_STORE);
1398         item_new = store_item_to_inventory(player_ptr, j_ptr);
1399
1400         object_desc(player_ptr, o_name, &player_ptr->inventory_list[item_new], 0);
1401         msg_format(_("%s(%c)を手に入れた。", "You have %s (%c)."), o_name, index_to_label(item_new));
1402         autopick_alter_item(player_ptr, item_new, FALSE);
1403         if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND))
1404         {
1405                 o_ptr->pval -= j_ptr->pval;
1406         }
1407
1408         handle_stuff(player_ptr);
1409         i = st_ptr->stock_num;
1410         store_item_increase(item, -amt);
1411         store_item_optimize(item);
1412         if (st_ptr->stock_num == 0)
1413         {
1414                 if (one_in_(STORE_SHUFFLE))
1415                 {
1416                         char buf[80];
1417                         msg_print(_("店主は引退した。", "The shopkeeper retires."));
1418                         store_shuffle(player_ptr, cur_store_num);
1419
1420                         prt("", 3, 0);
1421                         sprintf(buf, "%s (%s)",
1422                                 ot_ptr->owner_name, race_info[ot_ptr->owner_race].title);
1423                         put_str(buf, 3, 10);
1424                         sprintf(buf, "%s (%ld)",
1425                                 (f_name + f_info[cur_store_feat].name), (long)(ot_ptr->max_cost));
1426                         prt(buf, 3, 50);
1427                 }
1428                 else
1429                 {
1430                         msg_print(_("店主は新たな在庫を取り出した。", "The shopkeeper brings out some new stock."));
1431                 }
1432
1433                 for (i = 0; i < 10; i++)
1434                 {
1435                         store_maint(player_ptr, player_ptr->town_num, cur_store_num);
1436                 }
1437
1438                 store_top = 0;
1439                 display_store_inventory(player_ptr);
1440         }
1441         else if (st_ptr->stock_num != i)
1442         {
1443                 if (store_top >= st_ptr->stock_num) store_top -= store_bottom;
1444                 display_store_inventory(player_ptr);
1445         }
1446         else
1447         {
1448                 display_entry(player_ptr, item);
1449         }
1450 }
1451
1452
1453 /*!
1454  * @brief 店からの売却処理のメインルーチン /
1455  * Sell an item to the store (or home)
1456  * @param owner_ptr プレーヤーへの参照ポインタ
1457  * @return なし
1458  */
1459 static void store_sell(player_type *owner_ptr)
1460 {
1461         concptr q;
1462         if (cur_store_num == STORE_HOME)
1463                 q = _("どのアイテムを置きますか? ", "Drop which item? ");
1464         else if (cur_store_num == STORE_MUSEUM)
1465                 q = _("どのアイテムを寄贈しますか? ", "Give which item? ");
1466         else
1467                 q = _("どのアイテムを売りますか? ", "Sell which item? ");
1468
1469         item_tester_hook = store_will_buy;
1470
1471         /* 我が家でおかしなメッセージが出るオリジナルのバグを修正 */
1472         concptr s;
1473         if (cur_store_num == STORE_HOME)
1474         {
1475                 s = _("置けるアイテムを持っていません。", "You don't have any item to drop.");
1476         }
1477         else if (cur_store_num == STORE_MUSEUM)
1478         {
1479                 s = _("寄贈できるアイテムを持っていません。", "You don't have any item to give.");
1480         }
1481         else
1482         {
1483                 s = _("欲しい物がないですねえ。", "You have nothing that I want.");
1484         }
1485
1486         OBJECT_IDX item;
1487         object_type *o_ptr;
1488         o_ptr = choose_object(owner_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
1489         if (!o_ptr) return;
1490
1491         if ((item >= INVEN_RARM) && object_is_cursed(o_ptr))
1492         {
1493                 msg_print(_("ふーむ、どうやらそれは呪われているようだね。", "Hmmm, it seems to be cursed."));
1494                 return;
1495         }
1496
1497         int amt = 1;
1498         if (o_ptr->number > 1)
1499         {
1500                 amt = get_quantity(NULL, o_ptr->number);
1501                 if (amt <= 0) return;
1502         }
1503
1504         object_type forge;
1505         object_type *q_ptr;
1506         q_ptr = &forge;
1507         object_copy(q_ptr, o_ptr);
1508         q_ptr->number = amt;
1509
1510         /*
1511          * Hack -- If a rod or wand, allocate total maximum
1512          * timeouts or charges to those being sold. -LM-
1513          */
1514         if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND))
1515         {
1516                 q_ptr->pval = o_ptr->pval * amt / o_ptr->number;
1517         }
1518
1519         GAME_TEXT o_name[MAX_NLEN];
1520         object_desc(owner_ptr, o_name, q_ptr, 0);
1521
1522         /* Remove any inscription, feeling for stores */
1523         if ((cur_store_num != STORE_HOME) && (cur_store_num != STORE_MUSEUM))
1524         {
1525                 q_ptr->inscription = 0;
1526                 q_ptr->feeling = FEEL_NONE;
1527         }
1528
1529         /* Is there room in the store (or the home?) */
1530         if (!store_check_num(q_ptr))
1531         {
1532                 if (cur_store_num == STORE_HOME)
1533                         msg_print(_("我が家にはもう置く場所がない。", "Your home is full."));
1534
1535                 else if (cur_store_num == STORE_MUSEUM)
1536                         msg_print(_("博物館はもう満杯だ。", "Museum is full."));
1537
1538                 else
1539                         msg_print(_("すいませんが、店にはもう置く場所がありません。", "I have not the room in my store to keep it."));
1540
1541                 return;
1542         }
1543
1544         int choice;
1545         PRICE price, value, dummy;
1546         if ((cur_store_num != STORE_HOME) && (cur_store_num != STORE_MUSEUM))
1547         {
1548                 msg_format(_("%s(%c)を売却する。", "Selling %s (%c)."), o_name, index_to_label(item));
1549                 msg_print(NULL);
1550
1551                 choice = sell_haggle(owner_ptr, q_ptr, &price);
1552                 if (st_ptr->store_open >= current_world_ptr->game_turn) return;
1553
1554                 if (choice == 0)
1555                 {
1556                         say_comment_1(owner_ptr);
1557                         sound(SOUND_SELL);
1558                         if (cur_store_num == STORE_BLACK)
1559                                 chg_virtue(owner_ptr, V_JUSTICE, -1);
1560
1561                         if ((o_ptr->tval == TV_BOTTLE) && (cur_store_num != STORE_HOME))
1562                                 chg_virtue(owner_ptr, V_NATURE, 1);
1563                         decrease_insults();
1564
1565                         owner_ptr->au += price;
1566                         store_prt_gold(owner_ptr);
1567                         dummy = object_value(q_ptr) * q_ptr->number;
1568
1569                         identify_item(owner_ptr, o_ptr);
1570                         q_ptr = &forge;
1571                         object_copy(q_ptr, o_ptr);
1572                         q_ptr->number = amt;
1573                         q_ptr->ident |= IDENT_STORE;
1574
1575                         /*
1576                          * Hack -- If a rod or wand, let the shopkeeper know just
1577                          * how many charges he really paid for. -LM-
1578                          */
1579                         if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND))
1580                         {
1581                                 q_ptr->pval = o_ptr->pval * amt / o_ptr->number;
1582                         }
1583
1584                         value = object_value(q_ptr) * q_ptr->number;
1585                         object_desc(owner_ptr, o_name, q_ptr, 0);
1586                         msg_format(_("%sを $%ldで売却しました。", "You sold %s for %ld gold."), o_name, (long)price);
1587
1588                         if (record_sell) exe_write_diary(owner_ptr, DIARY_SELL, 0, o_name);
1589
1590                         if (!((o_ptr->tval == TV_FIGURINE) && (value > 0)))
1591                         {
1592                                 purchase_analyze(owner_ptr, price, value, dummy);
1593                         }
1594
1595                         /*
1596                          * Hack -- Allocate charges between those wands or rods sold
1597                          * and retained, unless all are being sold. -LM-
1598                          */
1599                         distribute_charges(o_ptr, q_ptr, amt);
1600                         q_ptr->timeout = 0;
1601                         inven_item_increase(owner_ptr, item, -amt);
1602                         inven_item_describe(owner_ptr, item);
1603                         if (o_ptr->number > 0)
1604                                 autopick_alter_item(owner_ptr, item, FALSE);
1605
1606                         inven_item_optimize(owner_ptr, item);
1607                         handle_stuff(owner_ptr);
1608                         int item_pos = store_carry(q_ptr);
1609                         if (item_pos >= 0)
1610                         {
1611                                 store_top = (item_pos / store_bottom) * store_bottom;
1612                                 display_store_inventory(owner_ptr);
1613                         }
1614                 }
1615         }
1616         else if (cur_store_num == STORE_MUSEUM)
1617         {
1618                 char o2_name[MAX_NLEN];
1619                 object_desc(owner_ptr, o2_name, q_ptr, OD_NAME_ONLY);
1620
1621                 if (-1 == store_check_num(q_ptr))
1622                 {
1623                         msg_print(_("それと同じ品物は既に博物館にあるようです。", "The Museum already has one of those items."));
1624                 }
1625                 else
1626                 {
1627                         msg_print(_("博物館に寄贈したものは取り出すことができません!!", "You cannot take back items which have been donated to the Museum!!"));
1628                 }
1629
1630                 if (!get_check(format(_("本当に%sを寄贈しますか?", "Really give %s to the Museum? "), o2_name))) return;
1631
1632                 identify_item(owner_ptr, q_ptr);
1633                 q_ptr->ident |= IDENT_FULL_KNOWN;
1634
1635                 distribute_charges(o_ptr, q_ptr, amt);
1636                 msg_format(_("%sを置いた。(%c)", "You drop %s (%c)."), o_name, index_to_label(item));
1637                 choice = 0;
1638
1639                 vary_item(owner_ptr, item, -amt);
1640                 handle_stuff(owner_ptr);
1641
1642                 int item_pos = home_carry(owner_ptr, q_ptr);
1643                 if (item_pos >= 0)
1644                 {
1645                         store_top = (item_pos / store_bottom) * store_bottom;
1646                         display_store_inventory(owner_ptr);
1647                 }
1648         }
1649         else
1650         {
1651                 distribute_charges(o_ptr, q_ptr, amt);
1652                 msg_format(_("%sを置いた。(%c)", "You drop %s (%c)."), o_name, index_to_label(item));
1653                 choice = 0;
1654                 vary_item(owner_ptr, item, -amt);
1655                 handle_stuff(owner_ptr);
1656                 int item_pos = home_carry(owner_ptr, q_ptr);
1657                 if (item_pos >= 0)
1658                 {
1659                         store_top = (item_pos / store_bottom) * store_bottom;
1660                         display_store_inventory(owner_ptr);
1661                 }
1662         }
1663
1664         if ((choice == 0) && (item >= INVEN_RARM))
1665         {
1666                 calc_android_exp(owner_ptr);
1667                 verify_equip_slot(owner_ptr, item);
1668         }
1669 }
1670
1671
1672 /*!
1673  * @brief 店のアイテムを調べるコマンドのメインルーチン /
1674  * Examine an item in a store                      -JDL-
1675  * @return なし
1676  */
1677 static void store_examine(player_type *player_ptr)
1678 {
1679         if (st_ptr->stock_num <= 0)
1680         {
1681                 if (cur_store_num == STORE_HOME)
1682                         msg_print(_("我が家には何も置いてありません。", "Your home is empty."));
1683                 else if (cur_store_num == STORE_MUSEUM)
1684                         msg_print(_("博物館には何も置いてありません。", "Museum is empty."));
1685                 else
1686                         msg_print(_("現在商品の在庫を切らしています。", "I am currently out of stock."));
1687                 return;
1688         }
1689
1690         int i = (st_ptr->stock_num - store_top);
1691         if (i > store_bottom) i = store_bottom;
1692
1693         char out_val[160];
1694         sprintf(out_val, _("どれを調べますか?", "Which item do you want to examine? "));
1695
1696         COMMAND_CODE item;
1697         if (!get_stock(&item, out_val, 0, i - 1)) return;
1698         item = item + store_top;
1699         object_type *o_ptr;
1700         o_ptr = &st_ptr->stock[item];
1701         if (!object_is_fully_known(o_ptr))
1702         {
1703                 msg_print(_("このアイテムについて特に知っていることはない。", "You have no special knowledge about that item."));
1704                 return;
1705         }
1706
1707         GAME_TEXT o_name[MAX_NLEN];
1708         object_desc(player_ptr, o_name, o_ptr, 0);
1709         msg_format(_("%sを調べている...", "Examining %s..."), o_name);
1710
1711         if (!screen_object(player_ptr, o_ptr, SCROBJ_FORCE_DETAIL))
1712                 msg_print(_("特に変わったところはないようだ。", "You see nothing special."));
1713 }
1714
1715
1716 /*!
1717  * @brief 博物館のアイテムを除去するコマンドのメインルーチン /
1718  * Remove an item from museum (Originally from TOband)
1719  * @param player_ptr プレーヤーへの参照ポインタ
1720  * @return なし
1721  */
1722 static void museum_remove_object(player_type *player_ptr)
1723 {
1724         if (st_ptr->stock_num <= 0)
1725         {
1726                 msg_print(_("博物館には何も置いてありません。", "Museum is empty."));
1727                 return;
1728         }
1729
1730         int i = st_ptr->stock_num - store_top;
1731         if (i > store_bottom) i = store_bottom;
1732
1733         char out_val[160];
1734         sprintf(out_val, _("どのアイテムの展示をやめさせますか?", "Which item do you want to order to remove? "));
1735
1736         COMMAND_CODE item;
1737         if (!get_stock(&item, out_val, 0, i - 1)) return;
1738
1739         item = item + store_top;
1740         object_type *o_ptr;
1741         o_ptr = &st_ptr->stock[item];
1742
1743         GAME_TEXT o_name[MAX_NLEN];
1744         object_desc(player_ptr, o_name, o_ptr, 0);
1745
1746         msg_print(_("展示をやめさせたアイテムは二度と見ることはできません!", "Once removed from the Museum, an item will be gone forever!"));
1747         if (!get_check(format(_("本当に%sの展示をやめさせますか?", "Really order to remove %s from the Museum? "), o_name))) return;
1748
1749         msg_format(_("%sの展示をやめさせた。", "You ordered to remove %s."), o_name);
1750
1751         store_item_increase(item, -o_ptr->number);
1752         store_item_optimize(item);
1753
1754         (void)combine_and_reorder_home(STORE_MUSEUM);
1755         if (st_ptr->stock_num == 0) store_top = 0;
1756
1757         else if (store_top >= st_ptr->stock_num) store_top -= store_bottom;
1758         display_store_inventory(player_ptr);
1759 }
1760
1761
1762 /*
1763  * Hack -- set this to leave the store
1764  */
1765 static bool leave_store = FALSE;
1766
1767
1768 /*!
1769  * @brief 店舗処理コマンド選択のメインルーチン /
1770  * Process a command in a store
1771  * @param client_ptr 顧客となるクリーチャーの参照ポインタ
1772  * @return なし
1773  * @note
1774  * <pre>
1775  * Note that we must allow the use of a few "special" commands
1776  * in the stores which are not allowed in the dungeon, and we
1777  * must disable some commands which are allowed in the dungeon
1778  * but not in the stores, to prevent chaos.
1779  * </pre>
1780  */
1781 static void store_process_command(player_type *client_ptr)
1782 {
1783         repeat_check();
1784         if (rogue_like_commands && command_cmd == 'l')
1785         {
1786                 command_cmd = 'x';
1787         }
1788
1789         switch (command_cmd)
1790         {
1791         case ESCAPE:
1792         {
1793                 leave_store = TRUE;
1794                 break;
1795         }
1796         case '-':
1797         {
1798                 /* 日本語版追加 */
1799                 /* 1 ページ戻るコマンド: 我が家のページ数が多いので重宝するはず By BUG */
1800                 if (st_ptr->stock_num <= store_bottom) {
1801                         msg_print(_("これで全部です。", "Entire inventory is shown."));
1802                 }
1803                 else
1804                 {
1805                         store_top -= store_bottom;
1806                         if (store_top < 0)
1807                                 store_top = ((st_ptr->stock_num - 1) / store_bottom) * store_bottom;
1808                         if ((cur_store_num == STORE_HOME) && (powerup_home == FALSE))
1809                                 if (store_top >= store_bottom) store_top = store_bottom;
1810                         display_store_inventory(client_ptr);
1811                 }
1812
1813                 break;
1814         }
1815         case ' ':
1816         {
1817                 if (st_ptr->stock_num <= store_bottom)
1818                 {
1819                         msg_print(_("これで全部です。", "Entire inventory is shown."));
1820                 }
1821                 else
1822                 {
1823                         store_top += store_bottom;
1824                         /*
1825                          * 隠しオプション(powerup_home)がセットされていないときは
1826                          * 我が家では 2 ページまでしか表示しない
1827                          */
1828                         if ((cur_store_num == STORE_HOME) &&
1829                                 (powerup_home == FALSE) &&
1830                                 (st_ptr->stock_num >= STORE_INVEN_MAX))
1831                         {
1832                                 if (store_top >= (STORE_INVEN_MAX - 1))
1833                                 {
1834                                         store_top = 0;
1835                                 }
1836                         }
1837                         else
1838                         {
1839                                 if (store_top >= st_ptr->stock_num) store_top = 0;
1840                         }
1841
1842                         display_store_inventory(client_ptr);
1843                 }
1844
1845                 break;
1846         }
1847         case KTRL('R'):
1848         {
1849                 do_cmd_redraw(client_ptr);
1850                 display_store(client_ptr);
1851                 break;
1852         }
1853         case 'g':
1854         {
1855                 store_purchase(client_ptr);
1856                 break;
1857         }
1858         case 'd':
1859         {
1860                 store_sell(client_ptr);
1861                 break;
1862         }
1863         case 'x':
1864         {
1865                 store_examine(client_ptr);
1866                 break;
1867         }
1868         case '\r':
1869         {
1870                 break;
1871         }
1872         case 'w':
1873         {
1874                 do_cmd_wield(client_ptr);
1875                 break;
1876         }
1877         case 't':
1878         {
1879                 do_cmd_takeoff(client_ptr);
1880                 break;
1881         }
1882         case 'k':
1883         {
1884                 do_cmd_destroy(client_ptr);
1885                 break;
1886         }
1887         case 'e':
1888         {
1889                 do_cmd_equip(client_ptr);
1890                 break;
1891         }
1892         case 'i':
1893         {
1894                 do_cmd_inven(client_ptr);
1895                 break;
1896         }
1897         case 'I':
1898         {
1899                 do_cmd_observe(client_ptr);
1900                 break;
1901         }
1902         case KTRL('I'):
1903         {
1904                 toggle_inventory_equipment(client_ptr);
1905                 break;
1906         }
1907         case 'b':
1908         {
1909                 if ((client_ptr->pclass == CLASS_MINDCRAFTER) ||
1910                         (client_ptr->pclass == CLASS_BERSERKER) ||
1911                         (client_ptr->pclass == CLASS_NINJA) ||
1912                         (client_ptr->pclass == CLASS_MIRROR_MASTER)
1913                         ) do_cmd_mind_browse(client_ptr);
1914                 else if (client_ptr->pclass == CLASS_SMITH)
1915                         do_cmd_kaji(client_ptr, TRUE);
1916                 else if (client_ptr->pclass == CLASS_MAGIC_EATER)
1917                         do_cmd_magic_eater(client_ptr, TRUE, FALSE);
1918                 else if (client_ptr->pclass == CLASS_SNIPER)
1919                         do_cmd_snipe_browse(client_ptr);
1920                 else do_cmd_browse(client_ptr);
1921                 break;
1922         }
1923         case '{':
1924         {
1925                 do_cmd_inscribe(client_ptr);
1926                 break;
1927         }
1928         case '}':
1929         {
1930                 do_cmd_uninscribe(client_ptr);
1931                 break;
1932         }
1933         case '?':
1934         {
1935                 do_cmd_help(client_ptr);
1936                 break;
1937         }
1938         case '/':
1939         {
1940                 do_cmd_query_symbol(client_ptr);
1941                 break;
1942         }
1943         case 'C':
1944         {
1945                 client_ptr->town_num = old_town_num;
1946                 do_cmd_player_status(client_ptr);
1947                 client_ptr->town_num = inner_town_num;
1948                 display_store(client_ptr);
1949                 break;
1950         }
1951         case '!':
1952         {
1953                 (void)Term_user(0);
1954                 break;
1955         }
1956         case '"':
1957         {
1958                 client_ptr->town_num = old_town_num;
1959                 do_cmd_pref(client_ptr);
1960                 client_ptr->town_num = inner_town_num;
1961                 break;
1962         }
1963         case '@':
1964         {
1965                 client_ptr->town_num = old_town_num;
1966                 do_cmd_macros(client_ptr, process_autopick_file_command);
1967                 client_ptr->town_num = inner_town_num;
1968                 break;
1969         }
1970         case '%':
1971         {
1972                 client_ptr->town_num = old_town_num;
1973                 do_cmd_visuals(client_ptr, process_autopick_file_command);
1974                 client_ptr->town_num = inner_town_num;
1975                 break;
1976         }
1977         case '&':
1978         {
1979                 client_ptr->town_num = old_town_num;
1980                 do_cmd_colors(client_ptr, process_autopick_file_command);
1981                 client_ptr->town_num = inner_town_num;
1982                 break;
1983         }
1984         case '=':
1985         {
1986                 do_cmd_options();
1987                 (void)combine_and_reorder_home(STORE_HOME);
1988                 do_cmd_redraw(client_ptr);
1989                 display_store(client_ptr);
1990                 break;
1991         }
1992         case ':':
1993         {
1994                 do_cmd_note();
1995                 break;
1996         }
1997         case 'V':
1998         {
1999                 do_cmd_version();
2000                 break;
2001         }
2002         case KTRL('F'):
2003         {
2004                 do_cmd_feeling(client_ptr);
2005                 break;
2006         }
2007         case KTRL('O'):
2008         {
2009                 do_cmd_message_one();
2010                 break;
2011         }
2012         case KTRL('P'):
2013         {
2014                 do_cmd_messages(0);
2015                 break;
2016         }
2017         case '|':
2018         {
2019                 do_cmd_diary(client_ptr);
2020                 break;
2021         }
2022         case '~':
2023         {
2024                 do_cmd_knowledge(client_ptr);
2025                 break;
2026         }
2027         case '(':
2028         {
2029                 do_cmd_load_screen();
2030                 break;
2031         }
2032         case ')':
2033         {
2034                 do_cmd_save_screen(client_ptr, process_autopick_file_command);
2035                 break;
2036         }
2037         default:
2038         {
2039                 if ((cur_store_num == STORE_MUSEUM) && (command_cmd == 'r'))
2040                 {
2041                         museum_remove_object(client_ptr);
2042                 }
2043                 else
2044                 {
2045                         msg_print(_("そのコマンドは店の中では使えません。", "That command does not work in stores."));
2046                 }
2047
2048                 break;
2049         }
2050         }
2051 }
2052
2053
2054 /*!
2055  * @brief 店舗処理全体のメインルーチン /
2056  * Enter a store, and interact with it. *
2057  * @param player_ptr プレーヤーへの参照ポインタ
2058  * @return なし
2059  * @note
2060  * <pre>
2061  * Note that we use the standard "request_command()" function
2062  * to get a command, allowing us to use "command_arg" and all
2063  * command macros and other nifty stuff, but we use the special
2064  * "shopping" argument, to force certain commands to be converted
2065  * into other commands, normally, we convert "p" (pray) and "m"
2066  * (cast magic) into "g" (get), and "s" (search) into "d" (drop).
2067  * </pre>
2068  */
2069 void do_cmd_store(player_type *player_ptr)
2070 {
2071         if (player_ptr->wild_mode) return;
2072         TERM_LEN w, h;
2073         Term_get_size(&w, &h);
2074
2075         xtra_stock = MIN(14 + 26, ((h > 24) ? (h - 24) : 0));
2076         store_bottom = MIN_STOCK + xtra_stock;
2077
2078         grid_type *g_ptr;
2079         g_ptr = &player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x];
2080
2081         if (!cave_have_flag_grid(g_ptr, FF_STORE))
2082         {
2083                 msg_print(_("ここには店がありません。", "You see no store here."));
2084                 return;
2085         }
2086
2087         int which = f_info[g_ptr->feat].subtype;
2088         old_town_num = player_ptr->town_num;
2089         if ((which == STORE_HOME) || (which == STORE_MUSEUM)) player_ptr->town_num = 1;
2090         if (player_ptr->current_floor_ptr->dun_level) player_ptr->town_num = NO_TOWN;
2091         inner_town_num = player_ptr->town_num;
2092
2093         if ((town_info[player_ptr->town_num].store[which].store_open >= current_world_ptr->game_turn) ||
2094                 (ironman_shops))
2095         {
2096                 msg_print(_("ドアに鍵がかかっている。", "The doors are locked."));
2097                 player_ptr->town_num = old_town_num;
2098                 return;
2099         }
2100
2101         int maintain_num = (current_world_ptr->game_turn - town_info[player_ptr->town_num].store[which].last_visit) / (TURNS_PER_TICK * STORE_TICKS);
2102         if (maintain_num > 10)
2103                 maintain_num = 10;
2104         if (maintain_num)
2105         {
2106                 for (int i = 0; i < maintain_num; i++)
2107                         store_maint(player_ptr, player_ptr->town_num, which);
2108
2109                 town_info[player_ptr->town_num].store[which].last_visit = current_world_ptr->game_turn;
2110         }
2111
2112         forget_lite(player_ptr->current_floor_ptr);
2113         forget_view(player_ptr->current_floor_ptr);
2114         current_world_ptr->character_icky = TRUE;
2115         command_arg = 0;
2116         command_rep = 0;
2117         command_new = 0;
2118         get_com_no_macros = TRUE;
2119         cur_store_num = which;
2120         cur_store_feat = g_ptr->feat;
2121         st_ptr = &town_info[player_ptr->town_num].store[cur_store_num];
2122         ot_ptr = &owners[cur_store_num][st_ptr->owner];
2123         store_top = 0;
2124         play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_BUILD);
2125         display_store(player_ptr);
2126         leave_store = FALSE;
2127
2128         while (!leave_store)
2129         {
2130                 prt("", 1, 0);
2131                 clear_from(20 + xtra_stock);
2132                 prt(_(" ESC) 建物から出る", " ESC) Exit from Building."), 21 + xtra_stock, 0);
2133                 if (st_ptr->stock_num > store_bottom)
2134                 {
2135                         prt(_(" -)前ページ", " -) Previous page"), 22 + xtra_stock, 0);
2136                         prt(_(" スペース) 次ページ", " SPACE) Next page"), 23 + xtra_stock, 0);
2137                 }
2138
2139                 if (cur_store_num == STORE_HOME)
2140                 {
2141                         prt(_("g) アイテムを取る", "g) Get an item."), 21 + xtra_stock, 27);
2142                         prt(_("d) アイテムを置く", "d) Drop an item."), 22 + xtra_stock, 27);
2143                         prt(_("x) 家のアイテムを調べる", "x) eXamine an item in the home."), 23 + xtra_stock, 27);
2144                 }
2145                 else if (cur_store_num == STORE_MUSEUM)
2146                 {
2147                         prt(_("d) アイテムを置く", "d) Drop an item."), 21 + xtra_stock, 27);
2148                         prt(_("r) アイテムの展示をやめる", "r) order to Remove an item."), 22 + xtra_stock, 27);
2149                         prt(_("x) 博物館のアイテムを調べる", "x) eXamine an item in the museum."), 23 + xtra_stock, 27);
2150                 }
2151                 else
2152                 {
2153                         prt(_("p) 商品を買う", "p) Purchase an item."), 21 + xtra_stock, 30);
2154                         prt(_("s) アイテムを売る", "s) Sell an item."), 22 + xtra_stock, 30);
2155                         prt(_("x) 商品を調べる", "x) eXamine an item in the shop"), 23 + xtra_stock, 30);
2156                 }
2157
2158                 prt(_("i/e) 持ち物/装備の一覧", "i/e) Inventry/Equipment list"), 21 + xtra_stock, 56);
2159                 if (rogue_like_commands)
2160                 {
2161                         prt(_("w/T) 装備する/はずす", "w/T) Wear/Take off equipment"), 22 + xtra_stock, 56);
2162                 }
2163                 else
2164                 {
2165                         prt(_("w/t) 装備する/はずす", "w/t) Wear/Take off equipment"), 22 + xtra_stock, 56);
2166                 }
2167
2168                 prt(_("コマンド:", "You may: "), 20 + xtra_stock, 0);
2169                 request_command(player_ptr, TRUE);
2170                 store_process_command(player_ptr);
2171
2172                 /*
2173                  * Hack -- To redraw missiles damage and prices in store
2174                  * If player's charisma changes, or if player changes a bow, PU_BONUS is set
2175                  */
2176                 bool need_redraw_store_inv = (player_ptr->update & PU_BONUS) ? TRUE : FALSE;
2177                 current_world_ptr->character_icky = TRUE;
2178                 handle_stuff(player_ptr);
2179                 if (player_ptr->inventory_list[INVEN_PACK].k_idx)
2180                 {
2181                         INVENTORY_IDX item = INVEN_PACK;
2182                         object_type *o_ptr = &player_ptr->inventory_list[item];
2183                         if (cur_store_num != STORE_HOME)
2184                         {
2185                                 if (cur_store_num == STORE_MUSEUM)
2186                                         msg_print(_("ザックからアイテムがあふれそうなので、あわてて博物館から出た...", "Your pack is so full that you flee the Museum..."));
2187                                 else
2188                                         msg_print(_("ザックからアイテムがあふれそうなので、あわてて店から出た...", "Your pack is so full that you flee the store..."));
2189
2190                                 leave_store = TRUE;
2191                         }
2192                         else if (!store_check_num(o_ptr))
2193                         {
2194                                 msg_print(_("ザックからアイテムがあふれそうなので、あわてて家から出た...", "Your pack is so full that you flee your home..."));
2195                                 leave_store = TRUE;
2196                         }
2197                         else
2198                         {
2199                                 int item_pos;
2200                                 object_type forge;
2201                                 object_type *q_ptr;
2202                                 GAME_TEXT o_name[MAX_NLEN];
2203                                 msg_print(_("ザックからアイテムがあふれてしまった!", "Your pack overflows!"));
2204                                 q_ptr = &forge;
2205                                 object_copy(q_ptr, o_ptr);
2206                                 object_desc(player_ptr, o_name, q_ptr, 0);
2207                                 msg_format(_("%sが落ちた。(%c)", "You drop %s (%c)."), o_name, index_to_label(item));
2208                                 vary_item(player_ptr, item, -255);
2209                                 handle_stuff(player_ptr);
2210
2211                                 item_pos = home_carry(player_ptr, q_ptr);
2212                                 if (item_pos >= 0)
2213                                 {
2214                                         store_top = (item_pos / store_bottom) * store_bottom;
2215                                         display_store_inventory(player_ptr);
2216                                 }
2217                         }
2218                 }
2219
2220                 if (need_redraw_store_inv) display_store_inventory(player_ptr);
2221
2222                 if (st_ptr->store_open >= current_world_ptr->game_turn) leave_store = TRUE;
2223         }
2224
2225         select_floor_music(player_ptr);
2226         player_ptr->town_num = old_town_num;
2227         take_turn(player_ptr, 100);
2228         current_world_ptr->character_icky = FALSE;
2229         command_new = 0;
2230         command_see = FALSE;
2231         get_com_no_macros = FALSE;
2232
2233         msg_erase();
2234         Term_clear();
2235
2236         player_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
2237         player_ptr->update |= (PU_MONSTERS);
2238         player_ptr->redraw |= (PR_BASIC | PR_EXTRA | PR_EQUIPPY);
2239         player_ptr->redraw |= (PR_MAP);
2240         player_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2241 }
2242
2243
2244 /*!
2245  * @brief 現在の町の店主を交代させる /
2246  * Shuffle one of the stores.
2247  * @param which 店舗種類のID
2248  * @return なし
2249  */
2250 void store_shuffle(player_type *player_ptr, int which)
2251 {
2252         if (which == STORE_HOME) return;
2253         if (which == STORE_MUSEUM) return;
2254
2255         cur_store_num = which;
2256         st_ptr = &town_info[player_ptr->town_num].store[cur_store_num];
2257         int j = st_ptr->owner;
2258         while (TRUE)
2259         {
2260                 st_ptr->owner = (byte)randint0(MAX_OWNERS);
2261                 if (j == st_ptr->owner) continue;
2262                 int i;
2263                 for (i = 1; i < max_towns; i++)
2264                 {
2265                         if (i == player_ptr->town_num) continue;
2266                         if (st_ptr->owner == town_info[i].store[cur_store_num].owner) break;
2267                 }
2268
2269                 if (i == max_towns) break;
2270         }
2271
2272         ot_ptr = &owners[cur_store_num][st_ptr->owner];
2273         st_ptr->insult_cur = 0;
2274         st_ptr->store_open = 0;
2275         st_ptr->good_buy = 0;
2276         st_ptr->bad_buy = 0;
2277         for (int i = 0; i < st_ptr->stock_num; i++)
2278         {
2279                 object_type *o_ptr;
2280                 o_ptr = &st_ptr->stock[i];
2281                 if (object_is_artifact(o_ptr)) continue;
2282
2283                 o_ptr->discount = 50;
2284                 o_ptr->ident &= ~(IDENT_FIXED);
2285                 o_ptr->inscription = quark_add(_("売出中", "on sale"));
2286         }
2287 }
2288
2289
2290 /*!
2291  * @brief 店の品揃えを変化させる /
2292  * Maintain the inventory at the stores.
2293  * @param player_ptr プレーヤーへの参照ポインタ
2294  * @param town_num 町のID
2295  * @param store_num 店舗種類のID
2296  * @return なし
2297  */
2298 void store_maint(player_type *player_ptr, int town_num, int store_num)
2299 {
2300         cur_store_num = store_num;
2301         if (store_num == STORE_HOME) return;
2302         if (store_num == STORE_MUSEUM) return;
2303
2304         st_ptr = &town_info[town_num].store[store_num];
2305         ot_ptr = &owners[store_num][st_ptr->owner];
2306         st_ptr->insult_cur = 0;
2307         if (store_num == STORE_BLACK)
2308         {
2309                 for (INVENTORY_IDX j = st_ptr->stock_num - 1; j >= 0; j--)
2310                 {
2311                         object_type *o_ptr = &st_ptr->stock[j];
2312                         if (black_market_crap(player_ptr, o_ptr))
2313                         {
2314                                 store_item_increase(j, 0 - o_ptr->number);
2315                                 store_item_optimize(j);
2316                         }
2317                 }
2318         }
2319
2320         INVENTORY_IDX j = st_ptr->stock_num;
2321         j = j - randint1(STORE_TURNOVER);
2322         if (j > STORE_MAX_KEEP) j = STORE_MAX_KEEP;
2323         if (j < STORE_MIN_KEEP) j = STORE_MIN_KEEP;
2324         if (j < 0) j = 0;
2325
2326         while (st_ptr->stock_num > j)
2327                 store_delete();
2328
2329         j = st_ptr->stock_num;
2330         j = j + randint1(STORE_TURNOVER);
2331         if (j > STORE_MAX_KEEP) j = STORE_MAX_KEEP;
2332         if (j < STORE_MIN_KEEP) j = STORE_MIN_KEEP;
2333         if (j >= st_ptr->stock_size) j = st_ptr->stock_size - 1;
2334
2335         while (st_ptr->stock_num < j) store_create(player_ptr, black_market_crap);
2336 }
2337
2338
2339 /*!
2340  * @brief 店舗情報を初期化する /
2341  * Initialize the stores
2342  * @param town_num 町のID
2343  * @param store_num 店舗種類のID
2344  * @return なし
2345  */
2346 void store_init(int town_num, int store_num)
2347 {
2348         cur_store_num = store_num;
2349         st_ptr = &town_info[town_num].store[store_num];
2350         while (TRUE)
2351         {
2352                 st_ptr->owner = (byte)randint0(MAX_OWNERS);
2353                 int i;
2354                 for (i = 1; i < max_towns; i++)
2355                 {
2356                         if (i == town_num) continue;
2357                         if (st_ptr->owner == town_info[i].store[store_num].owner) break;
2358                 }
2359
2360                 if (i == max_towns) break;
2361         }
2362
2363         ot_ptr = &owners[store_num][st_ptr->owner];
2364
2365         st_ptr->store_open = 0;
2366         st_ptr->insult_cur = 0;
2367         st_ptr->good_buy = 0;
2368         st_ptr->bad_buy = 0;
2369         st_ptr->stock_num = 0;
2370         st_ptr->last_visit = -10L * TURNS_PER_TICK * STORE_TICKS;
2371         for (int k = 0; k < st_ptr->stock_size; k++)
2372         {
2373                 object_wipe(&st_ptr->stock[k]);
2374         }
2375 }