OSDN Git Service

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