OSDN Git Service

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