OSDN Git Service

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