OSDN Git Service

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