OSDN Git Service

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