OSDN Git Service

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