OSDN Git Service

[Refactor] #40233 Separated articles-on-sale.c/h from store.c/h
[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/store-owners.h"
15 #include "market/store-owner-comments.h"
16 #include "core.h"
17 #include "util.h"
18 #include "term.h"
19
20 #include "floor.h"
21 #include "io/write-diary.h"
22 #include "cmd/cmd-basic.h"
23 #include "cmd/cmd-diary.h"
24 #include "cmd/cmd-draw.h"
25 #include "cmd/cmd-dump.h"
26 #include "cmd/cmd-help.h"
27 #include "cmd/cmd-item.h"
28 #include "cmd/cmd-macro.h"
29 #include "cmd/cmd-smith.h"
30 #include "cmd/cmd-visuals.h"
31 #include "cmd/cmd-zapwand.h"
32 #include "cmd/cmd-magiceat.h"
33 #include "spells.h"
34 #include "store.h"
35 #include "avatar.h"
36 #include "cmd-spell.h"
37 #include "rumor.h"
38 #include "player-status.h"
39 #include "player-class.h"
40 #include "player-inventory.h"
41 #include "object-flavor.h"
42 #include "object-hook.h"
43 #include "floor-events.h"
44 #include "snipe.h"
45 #include "files.h"
46 #include "player-effects.h"
47 #include "player-race.h"
48 #include "mind.h"
49 #include "world.h"
50 #include "objectkind.h"
51 #include "autopick.h"
52 #include "floor-town.h"
53 #include "japanese.h"
54 #include "view-mainwindow.h"
55 #include "wild.h"
56
57 #define MIN_STOCK 12
58
59 static int cur_store_num = 0;
60 static int store_top = 0;
61 static int store_bottom = 0;
62 static int xtra_stock = 0;
63 static store_type *st_ptr = NULL;
64 static const owner_type *ot_ptr = NULL;
65 static s16b old_town_num = 0;
66 static s16b inner_town_num = 0;
67 #define RUMOR_CHANCE 8
68
69 /*** Initialize others ***/
70
71 /*!
72  * @brief 取引成功時の店主のメッセージ処理 /
73  * ブラックマーケットのときは別のメッセージを出す
74  * Successful haggle.
75  * @param player_ptr プレーヤーへの参照ポインタ
76  * @return なし
77  */
78 static void say_comment_1(player_type *player_ptr)
79 {
80 #ifdef JP
81         if (cur_store_num == STORE_BLACK)
82         {
83                 msg_print(comment_1_B[randint0(MAX_COMMENT_1)]);
84         }
85         else
86         {
87                 msg_print(comment_1[randint0(MAX_COMMENT_1)]);
88         }
89 #else
90         msg_print(comment_1[randint0(MAX_COMMENT_1)]);
91 #endif
92
93         if (one_in_(RUMOR_CHANCE))
94         {
95 #ifdef JP
96                 msg_print("店主は耳うちした:");
97 #else
98                 msg_print("The shopkeeper whispers something into your ear:");
99 #endif
100                 display_rumor(player_ptr, TRUE);
101         }
102 }
103
104
105 /*!
106  * @brief プレイヤーがアイテムを買う時の価格代案メッセージ処理 /
107  * Continue haggling (player is buying)
108  * @param value 店主の提示価格
109  * @param annoyed 店主のいらつき度
110  * @return なし
111  */
112 static void say_comment_2(PRICE value, int annoyed)
113 {
114         /* Prepare a string to insert */
115         char    tmp_val[80];
116         sprintf(tmp_val, "%ld", (long)value);
117
118         if (annoyed > 0)
119         {
120                 msg_format(comment_2a[randint0(MAX_COMMENT_2A)], tmp_val);
121                 return;
122         }
123
124 #ifdef JP
125         if (cur_store_num == STORE_BLACK)
126         {
127                 msg_format(comment_2b_B[randint0(MAX_COMMENT_2B)], tmp_val);
128         }
129         else
130         {
131                 msg_format(comment_2b[randint0(MAX_COMMENT_2B)], tmp_val);
132         }
133 #else
134         msg_format(comment_2b[randint0(MAX_COMMENT_2B)], tmp_val);
135 #endif
136 }
137
138
139 /*!
140  * @brief プレイヤーがアイテムを売る時の価格代案メッセージ処理 /
141  * ブラックマーケットのときは別のメッセージを出す
142  * Continue haggling (player is selling)
143  * @param value 店主の提示価格
144  * @param annoyed 店主のいらつき度
145  * @return なし
146  */
147 static void say_comment_3(PRICE value, int annoyed)
148 {
149         char tmp_val[80];
150         sprintf(tmp_val, "%ld", (long)value);
151         if (annoyed > 0)
152         {
153                 msg_format(comment_3a[randint0(MAX_COMMENT_3A)], tmp_val);
154         }
155         else
156         {
157 #ifdef JP
158                 /* ブラックマーケットの時は別のメッセージを出す */
159                 if (cur_store_num == STORE_BLACK)
160                 {
161                         msg_format(comment_3b_B[randint0(MAX_COMMENT_3B)], tmp_val);
162                 }
163                 else
164                 {
165                         msg_format(comment_3b[randint0(MAX_COMMENT_3B)], tmp_val);
166                 }
167 #else
168                 msg_format(comment_3b[randint0(MAX_COMMENT_3B)], tmp_val);
169 #endif
170         }
171 }
172
173
174 /*!
175  * @brief 店主がプレイヤーを追い出す時のメッセージ処理 /
176  * ブラックマーケットの時は別のメッセージを出す
177  * Kick 'da bum out.                                    -RAK-
178  * @return なし
179  */
180 static void say_comment_4(void)
181 {
182 #ifdef JP
183         if (cur_store_num == STORE_BLACK)
184         {
185                 msg_print(comment_4a_B[randint0(MAX_COMMENT_4A)]);
186                 msg_print(comment_4b_B[randint0(MAX_COMMENT_4B)]);
187         }
188         else
189         {
190                 msg_print(comment_4a[randint0(MAX_COMMENT_4A)]);
191                 msg_print(comment_4b[randint0(MAX_COMMENT_4B)]);
192         }
193 #else
194         msg_print(comment_4a[randint0(MAX_COMMENT_4A)]);
195         msg_print(comment_4b[randint0(MAX_COMMENT_4B)]);
196 #endif
197
198 }
199
200
201 /*!
202  * @brief 店主がプレイヤーに取り合わない時のメッセージ処理 /
203  * ブラックマーケットの時は別のメッセージを出す
204  * You are insulting me
205  * @return なし
206  */
207 static void say_comment_5(void)
208 {
209 #ifdef JP
210         if (cur_store_num == STORE_BLACK)
211         {
212                 msg_print(comment_5_B[randint0(MAX_COMMENT_5)]);
213         }
214         else
215         {
216                 msg_print(comment_5[randint0(MAX_COMMENT_5)]);
217         }
218 #else
219         msg_print(comment_5[randint0(MAX_COMMENT_5)]);
220 #endif
221
222 }
223
224
225 /*!
226  * @brief 店主がプレイヤーの提示を理解できなかった時のメッセージ処理 /
227  * That makes no sense.
228  * @return なし
229  */
230 static void say_comment_6(void)
231 {
232         msg_print(comment_6[randint0(MAX_COMMENT_6)]);
233 }
234
235 #define MAX_COMMENT_7A  4
236
237 static concptr comment_7a[MAX_COMMENT_7A] =
238 {
239 #ifdef JP
240         "うわああぁぁ!",
241         "なんてこった!",
242         "誰かがむせび泣く声が聞こえる...。",
243         "店主が悔しげにわめいている!"
244 #else
245         "Arrgghh!",
246         "You bastard!",
247         "You hear someone sobbing...",
248         "The shopkeeper howls in agony!"
249 #endif
250
251 };
252
253 #define MAX_COMMENT_7B  4
254
255 static concptr comment_7b[MAX_COMMENT_7B] =
256 {
257 #ifdef JP
258         "くそう!",
259         "この悪魔め!",
260         "店主が恨めしそうに見ている。",
261         "店主が睨んでいる。"
262 #else
263         "Damn!",
264         "You fiend!",
265         "The shopkeeper curses at you.",
266         "The shopkeeper glares at you."
267 #endif
268
269 };
270
271 #define MAX_COMMENT_7C  4
272
273 static concptr comment_7c[MAX_COMMENT_7C] =
274 {
275 #ifdef JP
276         "すばらしい!",
277         "君が天使に見えるよ!",
278         "店主がクスクス笑っている。",
279         "店主が大声で笑っている。"
280 #else
281         "Cool!",
282         "You've made my day!",
283         "The shopkeeper giggles.",
284         "The shopkeeper laughs loudly."
285 #endif
286
287 };
288
289 #define MAX_COMMENT_7D  4
290
291 static concptr comment_7d[MAX_COMMENT_7D] =
292 {
293 #ifdef JP
294         "やっほぅ!",
295         "こんなおいしい思いをしたら、真面目に働けなくなるなぁ。",
296         "店主は嬉しくて跳ね回っている。",
297         "店主は満面に笑みをたたえている。"
298 #else
299         "Yipee!",
300         "I think I'll retire!",
301         "The shopkeeper jumps for joy.",
302         "The shopkeeper smiles gleefully."
303 #endif
304
305 };
306
307
308 /*!
309  * @brief 店主が交渉を終えた際の反応を返す処理 /
310  * Let a shop-keeper React to a purchase
311  * @param price アイテムの取引額
312  * @param value アイテムの実際価値
313  * @param guess 店主が当初予想していた価値
314  * @return なし
315  * @details
316  * We paid "price", it was worth "value", and we thought it was worth "guess"
317  */
318 static void purchase_analyze(player_type *player_ptr, PRICE price, PRICE value, PRICE guess)
319 {
320         /* Item was worthless, but we bought it */
321         if ((value <= 0) && (price > value))
322         {
323                 msg_print(comment_7a[randint0(MAX_COMMENT_7A)]);
324                 chg_virtue(player_ptr, V_HONOUR, -1);
325                 chg_virtue(player_ptr, V_JUSTICE, -1);
326                 sound(SOUND_STORE1);
327                 return;
328         }
329
330         /* Item was cheaper than we thought, and we paid more than necessary */
331         if ((value < guess) && (price > value))
332         {
333                 msg_print(comment_7b[randint0(MAX_COMMENT_7B)]);
334                 chg_virtue(player_ptr, V_JUSTICE, -1);
335                 if (one_in_(4)) chg_virtue(player_ptr, V_HONOUR, -1);
336                 sound(SOUND_STORE2);
337                 return;
338         }
339
340         /* Item was a good bargain, and we got away with it */
341         if ((value > guess) && (value < (4 * guess)) && (price < value))
342         {
343                 msg_print(comment_7c[randint0(MAX_COMMENT_7C)]);
344                 if (one_in_(4)) chg_virtue(player_ptr, V_HONOUR, -1);
345                 else if (one_in_(4)) chg_virtue(player_ptr, V_HONOUR, 1);
346                 sound(SOUND_STORE3);
347                 return;
348         }
349
350         /* Item was a great bargain, and we got away with it */
351         if ((value > guess) && (price < value))
352         {
353                 msg_print(comment_7d[randint0(MAX_COMMENT_7D)]);
354                 if (one_in_(2)) chg_virtue(player_ptr, V_HONOUR, -1);
355                 if (one_in_(4)) chg_virtue(player_ptr, V_HONOUR, 1);
356                 if (10 * price < value) chg_virtue(player_ptr, V_SACRIFICE, 1);
357                 sound(SOUND_STORE4);
358                 return;
359         }
360 }
361
362 /*
363  * We store the current "store feat" here so everyone can access it
364  */
365 static int cur_store_feat;
366
367 /*
368  * Buying and selling adjustments for race combinations.
369  * Entry[owner][player] gives the basic "cost inflation".
370  */
371 static byte rgold_adj[MAX_RACES][MAX_RACES] =
372 {
373         /*Hum, HfE, Elf,  Hal, Gno, Dwa, HfO, HfT, Dun, HiE, Barbarian,
374          HfOg, HGn, HTn, Cyc, Yek, Klc, Kbd, Nbl, DkE, Drc, Mind Flayer,
375          Imp,  Glm, Skl, Zombie, Vampire, Spectre, Fairy, Beastman, Ent,
376          Angel, Demon, Kutar, Android, Merfolk */
377
378         /* Human */
379         { 100, 105, 105, 110, 113, 115, 120, 125, 100, 105, 100,
380           124, 120, 110, 125, 115, 120, 120, 120, 120, 115, 120,
381           115, 105, 125, 125, 125, 125, 105, 120, 105,  95, 140,
382           100, 120, 110, 105, 110 },
383
384         /* Half-Elf */
385         { 110, 100, 100, 105, 110, 120, 125, 130, 110, 100, 110,
386           120, 115, 108, 115, 110, 110, 120, 120, 115, 115, 110,
387           120, 110, 110, 110, 120, 110, 100, 125, 100,  95, 140,
388           110, 115, 110, 110, 110 },
389
390         /* Elf */
391         { 110, 105, 100, 105, 110, 120, 125, 130, 110, 100, 110,
392           120, 120, 105, 120, 110, 105, 125, 125, 110, 115, 108,
393           120, 115, 110, 110, 120, 110, 100, 125, 100,  95, 140,
394           110, 110, 105, 110, 110 },
395
396         /* Halfling */
397         { 115, 110, 105,  95, 105, 110, 115, 130, 115, 105, 115,
398           125, 120, 120, 125, 115, 110, 120, 120, 120, 115, 115,
399           120, 110, 120, 120, 130, 110, 110, 130, 110,  95, 140,
400           115, 120, 105, 115, 105 },
401
402         /* Gnome */
403         { 115, 115, 110, 105,  95, 110, 115, 130, 115, 110, 115,
404           120, 125, 110, 120, 110, 105, 120, 110, 110, 105, 110,
405           120, 101, 110, 110, 120, 120, 115, 130, 115,  95, 140,
406           115, 110, 110, 115, 110 },
407
408         /* Dwarf */
409         { 115, 120, 120, 110, 110,  95, 125, 135, 115, 120, 115,
410           125, 140, 130, 130, 120, 115, 115, 115, 135, 125, 120,
411           120, 105, 115, 115, 115, 115, 120, 130, 120,  95, 140,
412           115, 110, 115, 115, 120 },
413
414         /* Half-Orc */
415         { 115, 120, 125, 115, 115, 130, 110, 115, 115, 125, 115,
416           110, 110, 120, 110, 120, 125, 115, 115, 110, 120, 110,
417           115, 125, 120, 120, 115, 120, 125, 115, 125,  95, 140,
418           115, 110, 115, 115, 125 },
419
420         /* Half-Troll */
421         { 110, 115, 115, 110, 110, 130, 110, 110, 110, 115, 110,
422           110, 115, 120, 110, 120, 120, 110, 110, 110, 115, 110,
423           110, 115, 112, 112, 115, 112, 120, 110, 120,  95, 140,
424           110, 110, 115, 110, 130 },
425
426         /* Amberite */
427         { 100, 105, 105, 110, 113, 115, 120, 125, 100, 105, 100,
428           120, 120, 105, 120, 115, 105, 115, 120, 110, 105, 105,
429           120, 105, 120, 120, 125, 120, 105, 135, 105,  95, 140,
430           100, 110, 110, 100, 110 },
431
432         /* High_Elf */
433         { 110, 105, 100, 105, 110, 120, 125, 130, 110, 100, 110,
434           125, 125, 101, 120, 115, 110, 115, 125, 110, 110, 110,
435           125, 115, 120, 120, 125, 120, 100, 125, 100,  95, 140,
436           110, 110, 105, 110, 110 },
437
438         /* Human / Barbarian (copied from human) */
439         { 100, 105, 105, 110, 113, 115, 120, 125, 100, 105, 100,
440           124, 120, 110, 125, 115, 120, 120, 120, 120, 115, 120,
441           115, 105, 125, 125, 130, 125, 115, 120, 115,  95, 140,
442           100, 120, 110, 100, 110 },
443
444         /* Half-Ogre: theoretical, copied from half-troll */
445         { 110, 115, 115, 110, 110, 130, 110, 110, 110, 115, 110,
446           110, 115, 120, 110, 120, 120, 110, 110, 110, 115, 110,
447           110, 115, 112, 112, 115, 112, 120, 110, 120,  95, 140,
448           110, 110, 115, 110, 120 },
449
450         /* Half-Giant: theoretical, copied from half-troll */
451         { 110, 115, 115, 110, 110, 130, 110, 110, 110, 115, 110,
452           110, 115, 120, 110, 120, 120, 110, 110, 110, 115, 110,
453           110, 115, 112, 112, 115, 112, 130, 120, 130,  95, 140,
454           110, 110, 115, 110, 115 },
455
456         /* Half-Titan: theoretical, copied from High_Elf */
457         { 110, 105, 100, 105, 110, 120, 125, 130, 110, 100, 110,
458           125, 125, 101, 120, 115, 110, 115, 125, 110, 110, 110,
459           125, 115, 120, 120, 120, 120, 130, 130, 130,  95, 140,
460           110, 110, 115, 110, 108 },
461
462         /* Cyclops: theoretical, copied from half-troll */
463         { 110, 115, 115, 110, 110, 130, 110, 110, 110, 115, 110,
464           110, 115, 120, 110, 120, 120, 110, 110, 110, 115, 110,
465           110, 115, 112, 112, 115, 112, 130, 130, 130,  95, 140,
466           110, 110, 115, 110, 115 },
467
468         /* Yeek: theoretical, copied from Half-Orc */
469         { 115, 120, 125, 115, 115, 130, 110, 115, 115, 125, 115,
470           110, 110, 120, 110, 120, 125, 115, 115, 110, 120, 110,
471           115, 125, 120, 120, 120, 120, 130, 130, 130,  95, 140,
472           115, 110, 115, 115, 110 },
473
474         /* Klackon: theoretical, copied from Gnome */
475         { 115, 115, 110, 105,  95, 110, 115, 130, 115, 110, 115,
476           120, 125, 110, 120, 110, 105, 120, 110, 110, 105, 110,
477           120, 101, 110, 110, 120, 120, 130, 130, 130,  95, 140,
478           115, 110, 115, 115, 110 },
479
480         /* Kobold: theoretical, copied from Half-Orc */
481         { 115, 120, 125, 115, 115, 130, 110, 115, 115, 125, 115,
482           110, 110, 120, 110, 120, 125, 115, 115, 110, 120, 110,
483           115, 125, 120, 120, 120, 120, 130, 130, 130,  95, 140,
484           115, 110, 115, 115, 120 },
485
486         /* Nibelung: theoretical, copied from Dwarf */
487         { 115, 120, 120, 110, 110,  95, 125, 135, 115, 120, 115,
488           125, 140, 130, 130, 120, 115, 115, 115, 135, 125, 120,
489           120, 105, 115, 115, 120, 120, 130, 130, 130,  95, 140,
490           115, 135, 115, 115, 120 },
491
492         /* Dark Elf */
493         { 110, 110, 110, 115, 120, 130, 115, 115, 120, 110, 115,
494           115, 115, 116, 115, 120, 120, 115, 115, 101, 110, 110,
495           110, 110, 112, 122, 110, 110, 110, 115, 110, 120, 120,
496           110, 101, 115, 110, 115 },
497
498         /* Draconian: theoretical, copied from High_Elf */
499         { 110, 105, 100, 105, 110, 120, 125, 130, 110, 100, 110,
500           125, 125, 101, 120, 115, 110, 115, 125, 110, 110, 110,
501           125, 115, 120, 120, 120, 120, 130, 130, 130,  95, 140,
502           110, 110, 115, 110, 115 },
503
504         /* Mind Flayer: theoretical, copied from High_Elf */
505         { 110, 105, 100, 105, 110, 120, 125, 130, 110, 100, 110,
506           125, 125, 101, 120, 115, 110, 115, 125, 110, 110, 110,
507           125, 115, 120, 120, 120, 120, 130, 130, 130,  95, 140,
508           110, 110, 115, 110, 110 },
509
510         /* Imp: theoretical, copied from High_Elf */
511         { 110, 105, 100, 105, 110, 120, 125, 130, 110, 100, 110,
512           125, 125, 101, 120, 115, 110, 115, 125, 110, 110, 110,
513           125, 115, 120, 120, 120, 120, 130, 130, 130, 120, 120,
514           110, 110, 115, 110, 120 },
515
516         /* Golem: theoretical, copied from High_Elf */
517         { 110, 105, 100, 105, 110, 120, 125, 130, 110, 100, 110,
518           125, 125, 101, 120, 115, 110, 115, 125, 110, 110, 110,
519           125, 115, 120, 120, 120, 120, 130, 130, 130,  95, 140,
520           110, 110, 115, 110, 110 },
521
522         /* Skeleton: theoretical, copied from half-orc */
523         { 115, 120, 125, 115, 115, 130, 110, 115, 115, 125, 115,
524           110, 110, 120, 110, 120, 125, 115, 115, 110, 120, 110,
525           115, 125, 120, 120, 120, 120, 130, 130, 130, 120, 120,
526           115, 110, 125, 115, 110 },
527
528         /* Zombie: Theoretical, copied from half-orc */
529         { 115, 120, 125, 115, 115, 130, 110, 115, 115, 125, 115,
530           110, 110, 120, 110, 120, 125, 115, 115, 110, 120, 110,
531           115, 125, 120, 120, 120, 120, 130, 130, 130, 120, 120,
532           115, 110, 125, 115, 110 },
533
534         /* Vampire: Theoretical, copied from half-orc */
535         { 115, 120, 125, 115, 115, 130, 110, 115, 115, 125, 115,
536           110, 110, 120, 110, 120, 125, 115, 115, 110, 120, 110,
537           115, 125, 120, 120, 120, 120, 130, 130, 130, 120, 120,
538           115, 110, 125, 115, 120 },
539
540         /* Spectre: Theoretical, copied from half-orc */
541         { 115, 120, 125, 115, 115, 130, 110, 115, 115, 125, 115,
542           110, 110, 120, 110, 120, 125, 115, 115, 110, 120, 110,
543           115, 125, 120, 120, 120, 120, 130, 130, 130, 120, 120,
544           115, 110, 125, 115, 110 },
545
546         /* Sprite: Theoretical, copied from half-orc */
547         { 115, 120, 125, 115, 115, 130, 110, 115, 115, 125, 115,
548           110, 110, 120, 110, 120, 125, 115, 115, 110, 120, 110,
549           115, 125, 120, 120, 120, 120, 130, 130, 130,  95, 140,
550           115, 110, 105, 115, 110 },
551
552         /* Beastman: Theoretical, copied from half-orc */
553         { 115, 120, 125, 115, 115, 130, 110, 115, 115, 125, 115,
554           110, 110, 120, 110, 120, 125, 115, 115, 110, 120, 110,
555           115, 125, 120, 120, 120, 120, 130, 130, 130,  95, 140,
556           115, 110, 115, 115, 125 },
557
558         /* Ent */
559         { 110, 105, 100, 105, 110, 120, 125, 130, 110, 100, 110,
560           120, 120, 105, 120, 110, 105, 125, 125, 110, 115, 108,
561           120, 115, 110, 110, 120, 110, 100, 125, 100,  95, 140,
562           110, 110, 105, 110, 110 },
563
564         /* Angel */
565         {  95,  95,  95,  95,  95,  95,  95,  95,  95,  95,  95,
566            95,  95,  95,  95,  95,  95,  95,  95,  95,  95,  95,
567            95,  95,  95,  95,  95,  95,  95,  95,  95,  95, 160,
568            95,  95,  95,  95,  95 },
569
570         /* Demon */
571         { 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
572           140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
573           140, 140, 140, 140, 140, 140, 140, 140, 140, 160, 120,
574           140, 140, 140, 140, 140 },
575
576         /* Dunadan */
577         { 100, 105, 105, 110, 113, 115, 120, 125, 100, 105, 100,
578           124, 120, 110, 125, 115, 120, 120, 120, 120, 115, 120,
579           115, 105, 125, 125, 125, 125, 105, 120, 105,  95, 140,
580           100, 120, 110, 100, 110 },
581
582         /* Shadow Fairy */
583         { 110, 110, 110, 115, 120, 130, 115, 115, 120, 110, 115,
584           115, 115, 116, 115, 120, 120, 115, 115, 101, 110, 110,
585           110, 110, 112, 122, 110, 110, 110, 115, 110, 120, 120,
586           110, 101, 115, 110, 115 },
587
588         /* Kutar */
589         { 110, 110, 105, 105, 110, 115, 115, 115, 110, 105, 110,
590           115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115,
591           115, 115, 125, 125, 125, 125, 105, 115, 105,  95, 140,
592           110, 115, 100, 110, 110 },
593
594         /* Android */
595         { 105, 105, 105, 110, 113, 115, 120, 125, 100, 105, 100,
596           124, 120, 110, 125, 115, 120, 120, 120, 120, 115, 120,
597           115, 105, 125, 125, 125, 125, 105, 120, 105,  95, 140,
598           100, 120, 110, 100, 110 },
599
600         /* Merfolk */
601         { 110, 110, 110, 105, 110, 120, 125, 130, 110, 110, 110,
602           120, 115, 108, 115, 110, 110, 120, 120, 115, 115, 110,
603           120, 110, 110, 110, 120, 110, 110, 125, 110,  95, 140,
604           110, 115, 110, 110, 100 },
605 };
606
607
608 /*!
609  * @brief 店舗価格を決定する. 無料にはならない /
610  * Determine the price of an item (qty one) in a store.
611  * @param o_ptr 店舗に並べるオブジェクト構造体の参照ポインタ
612  * @param greed 店主の強欲度
613  * @param flip TRUEならば店主にとっての買取価格、FALSEなら売出価格を計算
614  * @return アイテムの店舗価格
615  * @details
616  * <pre>
617  * This function takes into account the player's charisma, and the
618  * shop-keepers friendliness, and the shop-keeper's base greed, but
619  * never lets a shop-keeper lose money in a transaction.
620  * The "greed" value should exceed 100 when the player is "buying" the
621  * item, and should be less than 100 when the player is "selling" it.
622  * Hack -- the black market always charges twice as much as it should.
623  * Charisma adjustment runs from 80 to 130
624  * Racial adjustment runs from 95 to 130
625  * Since greed/charisma/racial adjustments are centered at 100, we need
626  * to adjust (by 200) to extract a usable multiplier.  Note that the
627  * "greed" value is always something (?).
628  * </pre>
629  */
630 static PRICE price_item(player_type *player_ptr, object_type *o_ptr, int greed, bool flip)
631 {
632         PRICE price = object_value(o_ptr);
633         if (price <= 0) return (0L);
634
635         int factor = rgold_adj[ot_ptr->owner_race][player_ptr->prace];
636         factor += adj_chr_gold[player_ptr->stat_ind[A_CHR]];
637         int adjust;
638         if (flip)
639         {
640                 adjust = 100 + (300 - (greed + factor));
641                 if (adjust > 100) adjust = 100;
642                 if (cur_store_num == STORE_BLACK)
643                         price = price / 2;
644
645                 price = (price * adjust + 50L) / 100L;
646         }
647         else
648         {
649                 adjust = 100 + ((greed + factor) - 300);
650                 if (adjust < 100) adjust = 100;
651                 if (cur_store_num == STORE_BLACK)
652                         price = price * 2;
653
654                 price = (s32b)(((u32b)price * (u32b)adjust + 50UL) / 100UL);
655         }
656
657         if (price <= 0L) return (1L);
658         return (price);
659 }
660
661
662 /*!
663  * @brief 安価な消耗品の販売数を増やし、低確率で割引にする /
664  * Certain "cheap" objects should be created in "piles"
665  * @param o_ptr 店舗に並べるオブジェクト構造体の参照ポインタ
666  * @return なし
667  * @details
668  * <pre>
669  * Some objects can be sold at a "discount" (in small piles)
670  * </pre>
671  */
672 static void mass_produce(object_type *o_ptr)
673 {
674         int size = 1;
675         PRICE cost = object_value(o_ptr);
676         switch (o_ptr->tval)
677         {
678         case TV_FOOD:
679         case TV_FLASK:
680         case TV_LITE:
681         {
682                 if (cost <= 5L) size += damroll(3, 5);
683                 if (cost <= 20L) size += damroll(3, 5);
684                 if (cost <= 50L) size += damroll(2, 2);
685                 break;
686         }
687         case TV_POTION:
688         case TV_SCROLL:
689         {
690                 if (cost <= 60L) size += damroll(3, 5);
691                 if (cost <= 240L) size += damroll(1, 5);
692                 if (o_ptr->sval == SV_SCROLL_STAR_IDENTIFY) size += damroll(3, 5);
693                 if (o_ptr->sval == SV_SCROLL_STAR_REMOVE_CURSE) size += damroll(1, 4);
694                 break;
695         }
696         case TV_LIFE_BOOK:
697         case TV_SORCERY_BOOK:
698         case TV_NATURE_BOOK:
699         case TV_CHAOS_BOOK:
700         case TV_DEATH_BOOK:
701         case TV_TRUMP_BOOK:
702         case TV_ARCANE_BOOK:
703         case TV_CRAFT_BOOK:
704         case TV_DAEMON_BOOK:
705         case TV_CRUSADE_BOOK:
706         case TV_MUSIC_BOOK:
707         case TV_HISSATSU_BOOK:
708         case TV_HEX_BOOK:
709         {
710                 if (cost <= 50L) size += damroll(2, 3);
711                 if (cost <= 500L) size += damroll(1, 3);
712                 break;
713         }
714         case TV_SOFT_ARMOR:
715         case TV_HARD_ARMOR:
716         case TV_SHIELD:
717         case TV_GLOVES:
718         case TV_BOOTS:
719         case TV_CLOAK:
720         case TV_HELM:
721         case TV_CROWN:
722         case TV_SWORD:
723         case TV_POLEARM:
724         case TV_HAFTED:
725         case TV_DIGGING:
726         case TV_BOW:
727         {
728                 if (object_is_artifact(o_ptr)) break;
729                 if (object_is_ego(o_ptr)) break;
730                 if (cost <= 10L) size += damroll(3, 5);
731                 if (cost <= 100L) size += damroll(3, 5);
732                 break;
733         }
734         case TV_SPIKE:
735         case TV_SHOT:
736         case TV_ARROW:
737         case TV_BOLT:
738         {
739                 if (cost <= 5L) size += damroll(5, 5);
740                 if (cost <= 50L) size += damroll(5, 5);
741                 if (cost <= 500L) size += damroll(5, 5);
742                 break;
743         }
744         case TV_FIGURINE:
745         {
746                 if (cost <= 100L) size += damroll(2, 2);
747                 if (cost <= 1000L) size += damroll(2, 2);
748                 break;
749         }
750         case TV_CAPTURE:
751         case TV_STATUE:
752         case TV_CARD:
753         {
754                 size = 1;
755                 break;
756         }
757
758         /*
759          * Because many rods (and a few wands and staffs) are useful mainly
760          * in quantity, the Black Market will occasionally have a bunch of
761          * one kind. -LM-
762          */
763         case TV_ROD:
764         case TV_WAND:
765         case TV_STAFF:
766         {
767                 if ((cur_store_num == STORE_BLACK) && one_in_(3))
768                 {
769                         if (cost < 1601L) size += damroll(1, 5);
770                         else if (cost < 3201L) size += damroll(1, 3);
771                 }
772                 break;
773         }
774         }
775
776         DISCOUNT_RATE discount = 0;
777         if (cost < 5)
778         {
779                 discount = 0;
780         }
781         else if (one_in_(25))
782         {
783                 discount = 25;
784         }
785         else if (one_in_(150))
786         {
787                 discount = 50;
788         }
789         else if (one_in_(300))
790         {
791                 discount = 75;
792         }
793         else if (one_in_(500))
794         {
795                 discount = 90;
796         }
797
798         if (o_ptr->art_name)
799         {
800                 discount = 0;
801         }
802
803         o_ptr->discount = discount;
804         o_ptr->number = size - (size * discount / 100);
805         if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND))
806         {
807                 o_ptr->pval *= (PARAMETER_VALUE)o_ptr->number;
808         }
809 }
810
811
812 /*!
813  * @brief 店舗に並べた品を同一品であるかどうか判定する /
814  * Determine if a store item can "absorb" another item
815  * @param o_ptr 判定するオブジェクト構造体の参照ポインタ1
816  * @param j_ptr 判定するオブジェクト構造体の参照ポインタ2
817  * @return 同一扱いできるならTRUEを返す
818  * @details
819  * <pre>
820  * See "object_similar()" for the same function for the "player"
821  * </pre>
822  */
823 static bool store_object_similar(object_type *o_ptr, object_type *j_ptr)
824 {
825         if (o_ptr == j_ptr) return 0;
826         if (o_ptr->k_idx != j_ptr->k_idx) return 0;
827         if ((o_ptr->pval != j_ptr->pval) && (o_ptr->tval != TV_WAND) && (o_ptr->tval != TV_ROD)) return 0;
828         if (o_ptr->to_h != j_ptr->to_h) return 0;
829         if (o_ptr->to_d != j_ptr->to_d) return 0;
830         if (o_ptr->to_a != j_ptr->to_a) return 0;
831         if (o_ptr->name2 != j_ptr->name2) return 0;
832         if (object_is_artifact(o_ptr) || object_is_artifact(j_ptr)) return 0;
833         for (int i = 0; i < TR_FLAG_SIZE; i++)
834                 if (o_ptr->art_flags[i] != j_ptr->art_flags[i]) return 0;
835         if (o_ptr->xtra1 || j_ptr->xtra1) return 0;
836         if (o_ptr->timeout || j_ptr->timeout) return 0;
837         if (o_ptr->ac != j_ptr->ac)   return 0;
838         if (o_ptr->dd != j_ptr->dd)   return 0;
839         if (o_ptr->ds != j_ptr->ds)   return 0;
840         if (o_ptr->tval == TV_CHEST) return 0;
841         if (o_ptr->tval == TV_STATUE) return 0;
842         if (o_ptr->tval == TV_CAPTURE) return 0;
843         if (o_ptr->discount != j_ptr->discount) return 0;
844         return TRUE;
845 }
846
847
848 /*!
849  * @brief 店舗に並べた品を重ね合わせできるかどうか判定する /
850  * Allow a store item to absorb another item
851  * @param o_ptr 判定するオブジェクト構造体の参照ポインタ1
852  * @param j_ptr 判定するオブジェクト構造体の参照ポインタ2
853  * @return 重ね合わせできるならTRUEを返す
854  * @details
855  * <pre>
856  * See "object_similar()" for the same function for the "player"
857  * </pre>
858  */
859 static void store_object_absorb(object_type *o_ptr, object_type *j_ptr)
860 {
861         int max_num = (o_ptr->tval == TV_ROD) ?
862                 MIN(99, MAX_SHORT / k_info[o_ptr->k_idx].pval) : 99;
863         int total = o_ptr->number + j_ptr->number;
864         int diff = (total > max_num) ? total - max_num : 0;
865         o_ptr->number = (total > max_num) ? max_num : total;
866         if (o_ptr->tval == TV_ROD)
867         {
868                 o_ptr->pval += j_ptr->pval * (j_ptr->number - diff) / j_ptr->number;
869         }
870
871         if (o_ptr->tval == TV_WAND)
872         {
873                 o_ptr->pval += j_ptr->pval * (j_ptr->number - diff) / j_ptr->number;
874         }
875 }
876
877
878 /*!
879  * @brief 店舗に品を置くスペースがあるかどうかの判定を返す /
880  * Check to see if the shop will be carrying too many objects   -RAK-
881  * @param o_ptr 店舗に置きたいオブジェクト構造体の参照ポインタ
882  * @return 置き場がないなら0、重ね合わせできるアイテムがあるなら-1、スペースがあるなら1を返す。
883  * @details
884  * <pre>
885  * Note that the shop, just like a player, will not accept things
886  * it cannot hold.      Before, one could "nuke" potions this way.
887  * Return value is now int:
888  *  0 : No space
889  * -1 : Can be combined to existing slot.
890  *  1 : Cannot be combined but there are empty spaces.
891  * </pre>
892  */
893 static int store_check_num(object_type *o_ptr)
894 {
895         object_type *j_ptr;
896         if ((cur_store_num == STORE_HOME) || (cur_store_num == STORE_MUSEUM))
897         {
898                 bool old_stack_force_notes = stack_force_notes;
899                 bool old_stack_force_costs = stack_force_costs;
900
901                 if (cur_store_num != STORE_HOME)
902                 {
903                         stack_force_notes = FALSE;
904                         stack_force_costs = FALSE;
905                 }
906
907                 for (int i = 0; i < st_ptr->stock_num; i++)
908                 {
909                         j_ptr = &st_ptr->stock[i];
910                         if (object_similar(j_ptr, o_ptr))
911                         {
912                                 if (cur_store_num != STORE_HOME)
913                                 {
914                                         stack_force_notes = old_stack_force_notes;
915                                         stack_force_costs = old_stack_force_costs;
916                                 }
917
918                                 return -1;
919                         }
920                 }
921
922                 if (cur_store_num != STORE_HOME)
923                 {
924                         stack_force_notes = old_stack_force_notes;
925                         stack_force_costs = old_stack_force_costs;
926                 }
927         }
928         else
929         {
930                 for (int i = 0; i < st_ptr->stock_num; i++)
931                 {
932                         j_ptr = &st_ptr->stock[i];
933                         if (store_object_similar(j_ptr, o_ptr)) return -1;
934                 }
935         }
936
937         /* Free space is always usable */
938         /*
939          * オプション powerup_home が設定されていると
940          * 我が家が 20 ページまで使える
941          */
942         if ((cur_store_num == STORE_HOME) && (powerup_home == FALSE))
943         {
944                 if (st_ptr->stock_num < ((st_ptr->stock_size) / 10))
945                 {
946                         return 1;
947                 }
948         }
949         else
950         {
951                 if (st_ptr->stock_num < st_ptr->stock_size)
952                 {
953                         return 1;
954                 }
955         }
956
957         return 0;
958 }
959
960
961 /*!
962  * @brief オブジェクトが祝福されているかの判定を返す /
963  * @param o_ptr 判定したいオブジェクト構造体の参照ポインタ
964  * @return アイテムが祝福されたアイテムならばTRUEを返す
965  */
966 static bool is_blessed_item(object_type *o_ptr)
967 {
968         BIT_FLAGS flgs[TR_FLAG_SIZE];
969         object_flags(o_ptr, flgs);
970         if (have_flag(flgs, TR_BLESSED)) return TRUE;
971         else return FALSE;
972 }
973
974
975 /*!
976  * @brief オブジェクトが所定の店舗で引き取れるかどうかを返す /
977  * Determine if the current store will purchase the given item
978  * @param o_ptr 判定したいオブジェクト構造体の参照ポインタ
979  * @return アイテムが買い取れるならばTRUEを返す
980  * @note
981  * Note that a shop-keeper must refuse to buy "worthless" items
982  */
983 static bool store_will_buy(object_type *o_ptr)
984 {
985         if ((cur_store_num == STORE_HOME) || (cur_store_num == STORE_MUSEUM)) return TRUE;
986         switch (cur_store_num)
987         {
988         case STORE_GENERAL:
989         {
990                 switch (o_ptr->tval)
991                 {
992                 case TV_POTION:
993                         if (o_ptr->sval != SV_POTION_WATER) return FALSE;
994
995                 case TV_WHISTLE:
996                 case TV_FOOD:
997                 case TV_LITE:
998                 case TV_FLASK:
999                 case TV_SPIKE:
1000                 case TV_SHOT:
1001                 case TV_ARROW:
1002                 case TV_BOLT:
1003                 case TV_DIGGING:
1004                 case TV_CLOAK:
1005                 case TV_BOTTLE:
1006                 case TV_FIGURINE:
1007                 case TV_STATUE:
1008                 case TV_CAPTURE:
1009                 case TV_CARD:
1010                         break;
1011                 default:
1012                         return FALSE;
1013                 }
1014
1015                 break;
1016         }
1017         case STORE_ARMOURY:
1018         {
1019                 switch (o_ptr->tval)
1020                 {
1021                 case TV_BOOTS:
1022                 case TV_GLOVES:
1023                 case TV_CROWN:
1024                 case TV_HELM:
1025                 case TV_SHIELD:
1026                 case TV_CLOAK:
1027                 case TV_SOFT_ARMOR:
1028                 case TV_HARD_ARMOR:
1029                 case TV_DRAG_ARMOR:
1030                         break;
1031                 default:
1032                         return FALSE;
1033                 }
1034
1035                 break;
1036         }
1037         case STORE_WEAPON:
1038         {
1039                 switch (o_ptr->tval)
1040                 {
1041                 case TV_SHOT:
1042                 case TV_BOLT:
1043                 case TV_ARROW:
1044                 case TV_BOW:
1045                 case TV_DIGGING:
1046                 case TV_POLEARM:
1047                 case TV_SWORD:
1048                 case TV_HISSATSU_BOOK:
1049                         break;
1050                 case TV_HAFTED:
1051                 {
1052                         if (o_ptr->sval == SV_WIZSTAFF) return FALSE;
1053                 }
1054                 break;
1055                 default:
1056                         return FALSE;
1057                 }
1058
1059                 break;
1060         }
1061         case STORE_TEMPLE:
1062         {
1063                 switch (o_ptr->tval)
1064                 {
1065                 case TV_LIFE_BOOK:
1066                 case TV_CRUSADE_BOOK:
1067                 case TV_SCROLL:
1068                 case TV_POTION:
1069                 case TV_HAFTED:
1070                 {
1071                         break;
1072                 }
1073                 case TV_FIGURINE:
1074                 case TV_STATUE:
1075                 {
1076                         monster_race *r_ptr = &r_info[o_ptr->pval];
1077                         if (!(r_ptr->flags3 & RF3_EVIL))
1078                         {
1079                                 if (r_ptr->flags3 & RF3_GOOD) break;
1080                                 if (r_ptr->flags3 & RF3_ANIMAL) break;
1081                                 if (my_strchr("?!", r_ptr->d_char)) break;
1082                         }
1083                 }
1084                 case TV_POLEARM:
1085                 case TV_SWORD:
1086                 {
1087                         if (is_blessed_item(o_ptr)) break;
1088                 }
1089                 default:
1090                         return FALSE;
1091                 }
1092
1093                 break;
1094         }
1095         case STORE_ALCHEMIST:
1096         {
1097                 switch (o_ptr->tval)
1098                 {
1099                 case TV_SCROLL:
1100                 case TV_POTION:
1101                         break;
1102                 default:
1103                         return FALSE;
1104                 }
1105
1106                 break;
1107         }
1108         case STORE_MAGIC:
1109         {
1110                 switch (o_ptr->tval)
1111                 {
1112                 case TV_SORCERY_BOOK:
1113                 case TV_NATURE_BOOK:
1114                 case TV_CHAOS_BOOK:
1115                 case TV_DEATH_BOOK:
1116                 case TV_TRUMP_BOOK:
1117                 case TV_ARCANE_BOOK:
1118                 case TV_CRAFT_BOOK:
1119                 case TV_DAEMON_BOOK:
1120                 case TV_MUSIC_BOOK:
1121                 case TV_HEX_BOOK:
1122                 case TV_AMULET:
1123                 case TV_RING:
1124                 case TV_STAFF:
1125                 case TV_WAND:
1126                 case TV_ROD:
1127                 case TV_SCROLL:
1128                 case TV_POTION:
1129                 case TV_FIGURINE:
1130                         break;
1131                 case TV_HAFTED:
1132                 {
1133                         if (o_ptr->sval == SV_WIZSTAFF) break;
1134                         else return FALSE;
1135                 }
1136                 default:
1137                         return FALSE;
1138                 }
1139
1140                 break;
1141         }
1142         case STORE_BOOK:
1143         {
1144                 switch (o_ptr->tval)
1145                 {
1146                 case TV_SORCERY_BOOK:
1147                 case TV_NATURE_BOOK:
1148                 case TV_CHAOS_BOOK:
1149                 case TV_DEATH_BOOK:
1150                 case TV_LIFE_BOOK:
1151                 case TV_TRUMP_BOOK:
1152                 case TV_ARCANE_BOOK:
1153                 case TV_CRAFT_BOOK:
1154                 case TV_DAEMON_BOOK:
1155                 case TV_CRUSADE_BOOK:
1156                 case TV_MUSIC_BOOK:
1157                 case TV_HEX_BOOK:
1158                         break;
1159                 default:
1160                         return FALSE;
1161                 }
1162
1163                 break;
1164         }
1165         }
1166
1167         if (object_value(o_ptr) <= 0) return FALSE;
1168         return TRUE;
1169 }
1170
1171
1172 /*!
1173  * @brief 現在の町の指定された店舗のアイテムを整理する /
1174  * Combine and reorder items in store.
1175  * @param store_num 店舗ID
1176  * @return 実際に整理が行われたならばTRUEを返す。
1177  */
1178 bool combine_and_reorder_home(int store_num)
1179 {
1180         store_type *old_st_ptr = st_ptr;
1181         st_ptr = &town_info[1].store[store_num];
1182         bool flag = FALSE;
1183         if (store_num != STORE_HOME)
1184         {
1185                 stack_force_notes = FALSE;
1186                 stack_force_costs = FALSE;
1187         }
1188
1189         bool combined = TRUE;
1190         while (combined)
1191         {
1192                 combined = FALSE;
1193                 for (int i = st_ptr->stock_num - 1; i > 0; i--)
1194                 {
1195                         object_type *o_ptr;
1196                         o_ptr = &st_ptr->stock[i];
1197                         if (!o_ptr->k_idx) continue;
1198                         for (int j = 0; j < i; j++)
1199                         {
1200                                 object_type *j_ptr;
1201                                 j_ptr = &st_ptr->stock[j];
1202                                 if (!j_ptr->k_idx) continue;
1203
1204                                 /*
1205                                  * Get maximum number of the stack if these
1206                                  * are similar, get zero otherwise.
1207                                  */
1208                                 int max_num = object_similar_part(j_ptr, o_ptr);
1209                                 if (max_num == 0 || j_ptr->number >= max_num) continue;
1210
1211                                 if (o_ptr->number + j_ptr->number <= max_num)
1212                                 {
1213                                         object_absorb(j_ptr, o_ptr);
1214                                         st_ptr->stock_num--;
1215                                         int k;
1216                                         for (k = i; k < st_ptr->stock_num; k++)
1217                                         {
1218                                                 st_ptr->stock[k] = st_ptr->stock[k + 1];
1219                                         }
1220
1221                                         object_wipe(&st_ptr->stock[k]);
1222                                         combined = TRUE;
1223                                         break;
1224                                 }
1225
1226                                 ITEM_NUMBER old_num = o_ptr->number;
1227                                 ITEM_NUMBER remain = j_ptr->number + o_ptr->number - max_num;
1228                                 object_absorb(j_ptr, o_ptr);
1229                                 o_ptr->number = remain;
1230                                 if (o_ptr->tval == TV_ROD)
1231                                 {
1232                                         o_ptr->pval = o_ptr->pval * remain / old_num;
1233                                         o_ptr->timeout = o_ptr->timeout * remain / old_num;
1234                                 }
1235                                 else if (o_ptr->tval == TV_WAND)
1236                                 {
1237                                         o_ptr->pval = o_ptr->pval * remain / old_num;
1238                                 }
1239
1240                                 combined = TRUE;
1241                                 break;
1242                         }
1243                 }
1244
1245                 flag |= combined;
1246         }
1247
1248         for (int i = 0; i < st_ptr->stock_num; i++)
1249         {
1250                 object_type *o_ptr;
1251                 o_ptr = &st_ptr->stock[i];
1252                 if (!o_ptr->k_idx) continue;
1253
1254                 s32b o_value = object_value(o_ptr);
1255                 int j;
1256                 for (j = 0; j < st_ptr->stock_num; j++)
1257                 {
1258                         if (object_sort_comp(o_ptr, o_value, &st_ptr->stock[j])) break;
1259                 }
1260
1261                 if (j >= i) continue;
1262
1263                 flag = TRUE;
1264                 object_type *j_ptr;
1265                 object_type forge;
1266                 j_ptr = &forge;
1267                 object_copy(j_ptr, &st_ptr->stock[i]);
1268                 for (int k = i; k > j; k--)
1269                 {
1270                         object_copy(&st_ptr->stock[k], &st_ptr->stock[k - 1]);
1271                 }
1272
1273                 object_copy(&st_ptr->stock[j], j_ptr);
1274         }
1275
1276         st_ptr = old_st_ptr;
1277         bool old_stack_force_notes = stack_force_notes;
1278         bool old_stack_force_costs = stack_force_costs;
1279         if (store_num != STORE_HOME)
1280         {
1281                 stack_force_notes = old_stack_force_notes;
1282                 stack_force_costs = old_stack_force_costs;
1283         }
1284
1285         return flag;
1286 }
1287
1288
1289 /*!
1290  * @brief 我が家にオブジェクトを加える /
1291  * Add the item "o_ptr" to the inventory of the "Home"
1292  * @param o_ptr 加えたいオブジェクトの構造体参照ポインタ
1293  * @return 収めた先のID
1294  * @details
1295  * <pre>
1296  * In all cases, return the slot (or -1) where the object was placed
1297  * Note that this is a hacked up version of "inven_carry()".
1298  * Also note that it may not correctly "adapt" to "knowledge" bacoming
1299  * known, the player may have to pick stuff up and drop it again.
1300  * </pre>
1301  */
1302 static int home_carry(player_type *player_ptr, object_type *o_ptr)
1303 {
1304         if (cur_store_num != STORE_HOME)
1305         {
1306                 stack_force_notes = FALSE;
1307                 stack_force_costs = FALSE;
1308         }
1309
1310         bool old_stack_force_notes = stack_force_notes;
1311         bool old_stack_force_costs = stack_force_costs;
1312         for (int slot = 0; slot < st_ptr->stock_num; slot++)
1313         {
1314                 object_type *j_ptr;
1315                 j_ptr = &st_ptr->stock[slot];
1316                 if (object_similar(j_ptr, o_ptr))
1317                 {
1318                         object_absorb(j_ptr, o_ptr);
1319                         if (cur_store_num != STORE_HOME)
1320                         {
1321                                 stack_force_notes = old_stack_force_notes;
1322                                 stack_force_costs = old_stack_force_costs;
1323                         }
1324
1325                         return (slot);
1326                 }
1327         }
1328
1329         if (cur_store_num != STORE_HOME)
1330         {
1331                 stack_force_notes = old_stack_force_notes;
1332                 stack_force_costs = old_stack_force_costs;
1333         }
1334
1335         /* No space? */
1336         /*
1337          * 隠し機能: オプション powerup_home が設定されていると
1338          *           我が家が 20 ページまで使える
1339          */
1340         if ((cur_store_num != STORE_HOME) || (powerup_home == TRUE))
1341         {
1342                 if (st_ptr->stock_num >= st_ptr->stock_size)
1343                 {
1344                         return -1;
1345                 }
1346         }
1347         else
1348         {
1349                 if (st_ptr->stock_num >= ((st_ptr->stock_size) / 10))
1350                 {
1351                         return -1;
1352                 }
1353         }
1354
1355         PRICE value = object_value(o_ptr);
1356         int slot;
1357         for (slot = 0; slot < st_ptr->stock_num; slot++)
1358         {
1359                 if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
1360         }
1361
1362         for (int i = st_ptr->stock_num; i > slot; i--)
1363         {
1364                 st_ptr->stock[i] = st_ptr->stock[i - 1];
1365         }
1366
1367         st_ptr->stock_num++;
1368         st_ptr->stock[slot] = *o_ptr;
1369         chg_virtue(player_ptr, V_SACRIFICE, -1);
1370         (void)combine_and_reorder_home(cur_store_num);
1371         return slot;
1372 }
1373
1374
1375 /*!
1376  * @brief 店舗にオブジェクトを加える /
1377  * Add the item "o_ptr" to a real stores inventory.
1378  * @param o_ptr 加えたいオブジェクトの構造体参照ポインタ
1379  * @return 収めた先のID
1380  * @details
1381  * <pre>
1382  * In all cases, return the slot (or -1) where the object was placed
1383  * Note that this is a hacked up version of "inven_carry()".
1384  * Also note that it may not correctly "adapt" to "knowledge" bacoming
1385  * known, the player may have to pick stuff up and drop it again.
1386  * </pre>
1387  */
1388 static int store_carry(object_type *o_ptr)
1389 {
1390         PRICE value = object_value(o_ptr);
1391         if (value <= 0) return -1;
1392         o_ptr->ident |= IDENT_FULL_KNOWN;
1393         o_ptr->inscription = 0;
1394         o_ptr->feeling = FEEL_NONE;
1395         int slot;
1396         for (slot = 0; slot < st_ptr->stock_num; slot++)
1397         {
1398                 object_type *j_ptr;
1399                 j_ptr = &st_ptr->stock[slot];
1400                 if (store_object_similar(j_ptr, o_ptr))
1401                 {
1402                         store_object_absorb(j_ptr, o_ptr);
1403                         return slot;
1404                 }
1405         }
1406
1407         if (st_ptr->stock_num >= st_ptr->stock_size) return -1;
1408
1409         for (slot = 0; slot < st_ptr->stock_num; slot++)
1410         {
1411                 object_type *j_ptr;
1412                 j_ptr = &st_ptr->stock[slot];
1413                 if (o_ptr->tval > j_ptr->tval) break;
1414                 if (o_ptr->tval < j_ptr->tval) continue;
1415                 if (o_ptr->sval < j_ptr->sval) break;
1416                 if (o_ptr->sval > j_ptr->sval) continue;
1417                 if (o_ptr->tval == TV_ROD)
1418                 {
1419                         if (o_ptr->pval < j_ptr->pval) break;
1420                         if (o_ptr->pval > j_ptr->pval) continue;
1421                 }
1422
1423                 PRICE j_value = object_value(j_ptr);
1424                 if (value > j_value) break;
1425                 if (value < j_value) continue;
1426         }
1427
1428         for (int i = st_ptr->stock_num; i > slot; i--)
1429         {
1430                 st_ptr->stock[i] = st_ptr->stock[i - 1];
1431         }
1432
1433         st_ptr->stock_num++;
1434         st_ptr->stock[slot] = *o_ptr;
1435         return slot;
1436 }
1437
1438
1439 /*!
1440  * @brief 店舗のオブジェクト数を増やす /
1441  * Add the item "o_ptr" to a real stores inventory.
1442  * @param item 増やしたいアイテムのID
1443  * @param num 増やしたい数
1444  * @return なし
1445  * @details
1446  * <pre>
1447  * Increase, by a given amount, the number of a certain item
1448  * in a certain store.  This can result in zero items.
1449  * </pre>
1450  * @todo numは本来ITEM_NUMBER型にしたい。
1451  */
1452 static void store_item_increase(INVENTORY_IDX item, int num)
1453 {
1454         object_type *o_ptr;
1455         o_ptr = &st_ptr->stock[item];
1456         int cnt = o_ptr->number + num;
1457         if (cnt > 255) cnt = 255;
1458         else if (cnt < 0) cnt = 0;
1459
1460         num = cnt - o_ptr->number;
1461         o_ptr->number += (ITEM_NUMBER)num;
1462 }
1463
1464
1465 /*!
1466  * @brief 店舗のオブジェクト数を削除する /
1467  * Remove a slot if it is empty
1468  * @param item 削除したいアイテムのID
1469  * @return なし
1470  */
1471 static void store_item_optimize(INVENTORY_IDX item)
1472 {
1473         object_type *o_ptr;
1474         o_ptr = &st_ptr->stock[item];
1475         if (!o_ptr->k_idx) return;
1476         if (o_ptr->number) return;
1477
1478         st_ptr->stock_num--;
1479         for (int j = item; j < st_ptr->stock_num; j++)
1480         {
1481                 st_ptr->stock[j] = st_ptr->stock[j + 1];
1482         }
1483
1484         object_wipe(&st_ptr->stock[st_ptr->stock_num]);
1485 }
1486
1487
1488 /*!
1489  * @brief ブラックマーケット用の無価値品の排除判定 /
1490  * This function will keep 'crap' out of the black market.
1491  * @param player_ptr プレーヤーへの参照ポインタ
1492  * @param o_ptr 判定したいオブジェクトの構造体参照ポインタ
1493  * @return ブラックマーケットにとって無価値な品ならばTRUEを返す
1494  * @details
1495  * <pre>
1496  * Crap is defined as any item that is "available" elsewhere
1497  * Based on a suggestion by "Lee Vogt" <lvogt@cig.mcel.mot.com>
1498  * </pre>
1499  */
1500 static bool black_market_crap(player_type *player_ptr, object_type *o_ptr)
1501 {
1502         if (object_is_ego(o_ptr)) return FALSE;
1503
1504         if (o_ptr->to_a > 0) return FALSE;
1505         if (o_ptr->to_h > 0) return FALSE;
1506         if (o_ptr->to_d > 0) return FALSE;
1507
1508         for (int i = 0; i < MAX_STORES; i++)
1509         {
1510                 if (i == STORE_HOME) continue;
1511                 if (i == STORE_MUSEUM) continue;
1512
1513                 for (int j = 0; j < town_info[player_ptr->town_num].store[i].stock_num; j++)
1514                 {
1515                         object_type *j_ptr = &town_info[player_ptr->town_num].store[i].stock[j];
1516                         if (o_ptr->k_idx == j_ptr->k_idx) return TRUE;
1517                 }
1518         }
1519
1520         return FALSE;
1521 }
1522
1523
1524 /*!
1525  * @brief 店舗の品揃え変化のためにアイテムを削除する /
1526  * Attempt to delete (some of) a random item from the store
1527  * @return なし
1528  * @details
1529  * <pre>
1530  * Hack -- we attempt to "maintain" piles of items when possible.
1531  * </pre>
1532  */
1533 static void store_delete(void)
1534 {
1535         INVENTORY_IDX what = (INVENTORY_IDX)randint0(st_ptr->stock_num);
1536         int num = st_ptr->stock[what].number;
1537         if (randint0(100) < 50) num = (num + 1) / 2;
1538         if (randint0(100) < 50) num = 1;
1539         if ((st_ptr->stock[what].tval == TV_ROD) || (st_ptr->stock[what].tval == TV_WAND))
1540         {
1541                 st_ptr->stock[what].pval -= num * st_ptr->stock[what].pval / st_ptr->stock[what].number;
1542         }
1543
1544         store_item_increase(what, -num);
1545         store_item_optimize(what);
1546 }
1547
1548
1549 /*!
1550  * @brief 店舗の品揃え変化のためにアイテムを追加する /
1551  * Creates a random item and gives it to a store
1552  * @param player_ptr プレーヤーへの参照ポインタ
1553  * @return なし
1554  * @details
1555  * <pre>
1556  * This algorithm needs to be rethought.  A lot.
1557  * Currently, "normal" stores use a pre-built array.
1558  * Note -- the "level" given to "obj_get_num()" is a "favored"
1559  * level, that is, there is a much higher chance of getting
1560  * items with a level approaching that of the given level...
1561  * Should we check for "permission" to have the given item?
1562  * </pre>
1563  */
1564 static void store_create(player_type *player_ptr)
1565 {
1566         if (st_ptr->stock_num >= st_ptr->stock_size) return;
1567
1568         for (int tries = 0; tries < 4; tries++)
1569         {
1570                 OBJECT_IDX i;
1571                 DEPTH level;
1572                 if (cur_store_num == STORE_BLACK)
1573                 {
1574                         /* Pick a level for object/magic */
1575                         level = 25 + randint0(25);
1576
1577                         /* Random item (usually of given level) */
1578                         i = get_obj_num(player_ptr, level, 0x00000000);
1579
1580                         /* Handle failure */
1581                         if (i == 0) continue;
1582                 }
1583                 else
1584                 {
1585                         i = st_ptr->table[randint0(st_ptr->table_num)];
1586                         level = rand_range(1, STORE_OBJ_LEVEL);
1587                 }
1588
1589                 object_type forge;
1590                 object_type *q_ptr;
1591                 q_ptr = &forge;
1592                 object_prep(q_ptr, i);
1593                 apply_magic(player_ptr, q_ptr, level, AM_NO_FIXED_ART);
1594                 if (!store_will_buy(q_ptr)) continue;
1595
1596                 if (q_ptr->tval == TV_LITE)
1597                 {
1598                         if (q_ptr->sval == SV_LITE_TORCH) q_ptr->xtra4 = FUEL_TORCH / 2;
1599                         if (q_ptr->sval == SV_LITE_LANTERN) q_ptr->xtra4 = FUEL_LAMP / 2;
1600                 }
1601
1602                 object_known(q_ptr);
1603                 q_ptr->ident |= IDENT_STORE;
1604                 if (q_ptr->tval == TV_CHEST) continue;
1605
1606                 if (cur_store_num == STORE_BLACK)
1607                 {
1608                         if (black_market_crap(player_ptr, q_ptr)) continue;
1609                         if (object_value(q_ptr) < 10) continue;
1610                 }
1611                 else
1612                 {
1613                         if (object_value(q_ptr) <= 0) continue;
1614                 }
1615
1616                 mass_produce(q_ptr);
1617                 (void)store_carry(q_ptr);
1618                 break;
1619         }
1620 }
1621
1622
1623 /*!
1624  * @brief 店舗の割引対象外にするかどうかを判定 /
1625  * Eliminate need to bargain if player has haggled well in the past
1626  * @param minprice アイテムの最低販売価格
1627  * @return 割引を禁止するならTRUEを返す。
1628  */
1629 static bool noneedtobargain(PRICE minprice)
1630 {
1631         PRICE good = st_ptr->good_buy;
1632         PRICE bad = st_ptr->bad_buy;
1633         if (minprice < 10L) return TRUE;
1634         if (good == MAX_SHORT) return TRUE;
1635         if (good > ((3 * bad) + (5 + (minprice / 50)))) return TRUE;
1636
1637         return FALSE;
1638 }
1639
1640
1641 /*!
1642  * @brief 店主の持つプレイヤーに対する売買の良し悪し経験を記憶する /
1643  * Update the bargain info
1644  * @param price 実際の取引価格
1645  * @param minprice 店主の提示した価格
1646  * @param num 売買数
1647  * @return なし
1648  */
1649 static void updatebargain(PRICE price, PRICE minprice, int num)
1650 {
1651         if (!manual_haggle) return;
1652         if ((minprice / num) < 10L) return;
1653         if (price == minprice)
1654         {
1655                 if (st_ptr->good_buy < MAX_SHORT)
1656                 {
1657                         st_ptr->good_buy++;
1658                 }
1659         }
1660         else
1661         {
1662                 if (st_ptr->bad_buy < MAX_SHORT)
1663                 {
1664                         st_ptr->bad_buy++;
1665                 }
1666         }
1667 }
1668
1669
1670 /*!
1671  * @brief 店の商品リストを再表示する /
1672  * Re-displays a single store entry
1673  * @param player_ptr プレーヤーへの参照ポインタ
1674  * @param pos 表示行
1675  * @return なし
1676  */
1677 static void display_entry(player_type *player_ptr, int pos)
1678 {
1679         object_type *o_ptr;
1680         o_ptr = &st_ptr->stock[pos];
1681         int i = (pos % store_bottom);
1682
1683         /* Label it, clear the line --(-- */
1684         char out_val[160];
1685         (void)sprintf(out_val, "%c) ", ((i > 25) ? toupper(I2A(i - 26)) : I2A(i)));
1686         prt(out_val, i + 6, 0);
1687
1688         int cur_col = 3;
1689         if (show_item_graph)
1690         {
1691                 TERM_COLOR a = object_attr(o_ptr);
1692                 SYMBOL_CODE c = object_char(o_ptr);
1693
1694                 Term_queue_bigchar(cur_col, i + 6, a, c, 0, 0);
1695                 if (use_bigtile) cur_col++;
1696
1697                 cur_col += 2;
1698         }
1699
1700         /* Describe an item in the home */
1701         int maxwid = 75;
1702         if ((cur_store_num == STORE_HOME) || (cur_store_num == STORE_MUSEUM))
1703         {
1704                 maxwid = 75;
1705                 if (show_weights) maxwid -= 10;
1706
1707                 GAME_TEXT o_name[MAX_NLEN];
1708                 object_desc(player_ptr, o_name, o_ptr, 0);
1709                 o_name[maxwid] = '\0';
1710                 c_put_str(tval_to_attr[o_ptr->tval], o_name, i + 6, cur_col);
1711                 if (show_weights)
1712                 {
1713                         WEIGHT wgt = o_ptr->weight;
1714 #ifdef JP
1715                         sprintf(out_val, "%3d.%1d kg", lbtokg1(wgt), lbtokg2(wgt));
1716                         put_str(out_val, i + 6, 67);
1717 #else
1718                         (void)sprintf(out_val, "%3d.%d lb", wgt / 10, wgt % 10);
1719                         put_str(out_val, i + 6, 68);
1720 #endif
1721
1722                 }
1723
1724                 return;
1725         }
1726
1727         maxwid = 65;
1728         if (show_weights) maxwid -= 7;
1729
1730         GAME_TEXT o_name[MAX_NLEN];
1731         object_desc(player_ptr, o_name, o_ptr, 0);
1732         o_name[maxwid] = '\0';
1733         c_put_str(tval_to_attr[o_ptr->tval], o_name, i + 6, cur_col);
1734
1735         if (show_weights)
1736         {
1737                 int wgt = o_ptr->weight;
1738 #ifdef JP
1739                 sprintf(out_val, "%3d.%1d", lbtokg1(wgt), lbtokg2(wgt));
1740                 put_str(out_val, i + 6, 60);
1741 #else
1742                 (void)sprintf(out_val, "%3d.%d", wgt / 10, wgt % 10);
1743                 put_str(out_val, i + 6, 61);
1744 #endif
1745
1746         }
1747
1748         s32b x;
1749         if (o_ptr->ident & (IDENT_FIXED))
1750         {
1751                 x = price_item(player_ptr, o_ptr, ot_ptr->min_inflate, FALSE);
1752 #ifdef JP
1753                 (void)sprintf(out_val, "%9ld固", (long)x);
1754 #else
1755                 (void)sprintf(out_val, "%9ld F", (long)x);
1756 #endif
1757                 put_str(out_val, i + 6, 68);
1758                 return;
1759         }
1760
1761         if (!manual_haggle)
1762         {
1763                 x = price_item(player_ptr, o_ptr, ot_ptr->min_inflate, FALSE);
1764                 if (!noneedtobargain(x)) x += x / 10;
1765
1766                 (void)sprintf(out_val, "%9ld  ", (long)x);
1767                 put_str(out_val, i + 6, 68);
1768                 return;
1769         }
1770
1771         x = price_item(player_ptr, o_ptr, ot_ptr->max_inflate, FALSE);
1772         (void)sprintf(out_val, "%9ld  ", (long)x);
1773         put_str(out_val, i + 6, 68);
1774 }
1775
1776
1777 /*!
1778  * @brief 店の商品リストを表示する /
1779  * Displays a store's inventory -RAK-
1780  * @param player_ptr プレーヤーへの参照ポインタ
1781  * @return なし
1782  * @details
1783  * All prices are listed as "per individual object".  -BEN-
1784  */
1785 static void display_store_inventory(player_type *player_ptr)
1786 {
1787         int k;
1788         for (k = 0; k < store_bottom; k++)
1789         {
1790                 if (store_top + k >= st_ptr->stock_num) break;
1791
1792                 display_entry(player_ptr, store_top + k);
1793         }
1794
1795         for (int i = k; i < store_bottom + 1; i++)
1796                 prt("", i + 6, 0);
1797
1798 #ifdef JP
1799         put_str("          ", 5, 20);
1800 #else
1801         put_str("        ", 5, 22);
1802 #endif
1803
1804         if (st_ptr->stock_num > store_bottom)
1805         {
1806                 prt(_("-続く-", "-more-"), k + 6, 3);
1807                 put_str(format(_("(%dページ)  ", "(Page %d)  "), store_top / store_bottom + 1), 5, _(20, 22));
1808         }
1809
1810         if (cur_store_num == STORE_HOME || cur_store_num == STORE_MUSEUM)
1811         {
1812                 k = st_ptr->stock_size;
1813                 if (cur_store_num == STORE_HOME && !powerup_home) k /= 10;
1814 #ifdef JP
1815                 put_str(format("アイテム数:  %4d/%4d", st_ptr->stock_num, k), 19 + xtra_stock, 27);
1816 #else
1817                 put_str(format("Objects:  %4d/%4d", st_ptr->stock_num, k), 19 + xtra_stock, 30);
1818 #endif
1819         }
1820 }
1821
1822
1823 /*!
1824  * @brief プレイヤーの所持金を表示する /
1825  * Displays players gold                                        -RAK-
1826  * @param player_ptr プレーヤーへの参照ポインタ
1827  * @return なし
1828  * @details
1829  */
1830 static void store_prt_gold(player_type *player_ptr)
1831 {
1832         prt(_("手持ちのお金: ", "Gold Remaining: "), 19 + xtra_stock, 53);
1833         char out_val[64];
1834         sprintf(out_val, "%9ld", (long)player_ptr->au);
1835         prt(out_val, 19 + xtra_stock, 68);
1836 }
1837
1838
1839 /*!
1840  * @brief 店舗情報全体を表示するメインルーチン /
1841  * Displays store (after clearing screen)               -RAK-
1842  * @param player_ptr プレーヤーへの参照ポインタ
1843  * @return なし
1844  * @details
1845  */
1846 static void display_store(player_type *player_ptr)
1847 {
1848         Term_clear();
1849         if (cur_store_num == STORE_HOME)
1850         {
1851                 put_str(_("我が家", "Your Home"), 3, 31);
1852                 put_str(_("アイテムの一覧", "Item Description"), 5, 4);
1853                 if (show_weights)
1854                 {
1855                         put_str(_("  重さ", "Weight"), 5, 70);
1856                 }
1857
1858                 store_prt_gold(player_ptr);
1859                 display_store_inventory(player_ptr);
1860                 return;
1861         }
1862
1863         if (cur_store_num == STORE_MUSEUM)
1864         {
1865                 put_str(_("博物館", "Museum"), 3, 31);
1866                 put_str(_("アイテムの一覧", "Item Description"), 5, 4);
1867                 if (show_weights)
1868                 {
1869                         put_str(_("  重さ", "Weight"), 5, 70);
1870                 }
1871
1872                 store_prt_gold(player_ptr);
1873                 display_store_inventory(player_ptr);
1874                 return;
1875         }
1876
1877         concptr store_name = (f_name + f_info[cur_store_feat].name);
1878         concptr owner_name = (ot_ptr->owner_name);
1879         concptr race_name = race_info[ot_ptr->owner_race].title;
1880         char buf[80];
1881         sprintf(buf, "%s (%s)", owner_name, race_name);
1882         put_str(buf, 3, 10);
1883
1884         sprintf(buf, "%s (%ld)", store_name, (long)(ot_ptr->max_cost));
1885         prt(buf, 3, 50);
1886
1887         put_str(_("商品の一覧", "Item Description"), 5, 5);
1888         if (show_weights)
1889         {
1890                 put_str(_("  重さ", "Weight"), 5, 60);
1891         }
1892
1893         put_str(_(" 価格", "Price"), 5, 72);
1894         store_prt_gold(player_ptr);
1895         display_store_inventory(player_ptr);
1896 }
1897
1898
1899 /*!
1900  * @brief 店舗からアイテムを選択する /
1901  * Get the ID of a store item and return its value      -RAK-
1902  * @param com_val 選択IDを返す参照ポインタ
1903  * @param pmt メッセージキャプション
1904  * @param i 選択範囲の最小値
1905  * @param j 選択範囲の最大値
1906  * @return 実際に選択したらTRUE、キャンセルしたらFALSE
1907  */
1908 static int get_stock(COMMAND_CODE *com_val, concptr pmt, int i, int j)
1909 {
1910         if (repeat_pull(com_val) && (*com_val >= i) && (*com_val <= j))
1911         {
1912                 return TRUE;
1913         }
1914
1915         msg_print(NULL);
1916         *com_val = (-1);
1917         char lo = I2A(i);
1918         char hi = (j > 25) ? toupper(I2A(j - 26)) : I2A(j);
1919         char out_val[160];
1920 #ifdef JP
1921         (void)sprintf(out_val, "(%s:%c-%c, ESCで中断) %s",
1922                 (((cur_store_num == STORE_HOME) || (cur_store_num == STORE_MUSEUM)) ? "アイテム" : "商品"),
1923                 lo, hi, pmt);
1924 #else
1925         (void)sprintf(out_val, "(Items %c-%c, ESC to exit) %s",
1926                 lo, hi, pmt);
1927 #endif
1928
1929         char command;
1930         while (TRUE)
1931         {
1932                 if (!get_com(out_val, &command, FALSE)) break;
1933
1934                 COMMAND_CODE k;
1935                 if (islower(command))
1936                         k = A2I(command);
1937                 else if (isupper(command))
1938                         k = A2I(tolower(command)) + 26;
1939                 else
1940                         k = -1;
1941
1942                 if ((k >= i) && (k <= j))
1943                 {
1944                         *com_val = k;
1945                         break;
1946                 }
1947
1948                 bell();
1949         }
1950
1951         prt("", 0, 0);
1952         if (command == ESCAPE) return FALSE;
1953
1954         repeat_push(*com_val);
1955         return TRUE;
1956 }
1957
1958
1959 /*!
1960  * @brief 店主の不満度を増やし、プレイヤーを締め出す判定と処理を行う /
1961  * Increase the insult counter and get angry if too many -RAK-
1962  * @return プレイヤーを締め出す場合TRUEを返す
1963  */
1964 static int increase_insults(void)
1965 {
1966         st_ptr->insult_cur++;
1967         if (st_ptr->insult_cur <= ot_ptr->insult_max) return FALSE;
1968
1969         say_comment_4();
1970
1971         st_ptr->insult_cur = 0;
1972         st_ptr->good_buy = 0;
1973         st_ptr->bad_buy = 0;
1974         st_ptr->store_open = current_world_ptr->game_turn + TURNS_PER_TICK * TOWN_DAWN / 8 + randint1(TURNS_PER_TICK*TOWN_DAWN / 8);
1975
1976         return TRUE;
1977 }
1978
1979
1980 /*!
1981  * @brief 店主の不満度を減らす /
1982  * Decrease insults                             -RAK-
1983  * @return プレイヤーを締め出す場合TRUEを返す
1984  */
1985 static void decrease_insults(void)
1986 {
1987         if (st_ptr->insult_cur) st_ptr->insult_cur--;
1988 }
1989
1990
1991 /*!
1992  * @brief 店主の不満度が増えた場合のみのメッセージを表示する /
1993  * Have insulted while haggling                         -RAK-
1994  * @return プレイヤーを締め出す場合TRUEを返す
1995  */
1996 static int haggle_insults(void)
1997 {
1998         if (increase_insults()) return TRUE;
1999
2000         say_comment_5();
2001         return FALSE;
2002 }
2003
2004 /*
2005  * Mega-Hack -- Enable "increments"
2006  */
2007 static bool allow_inc = FALSE;
2008
2009 /*
2010  * Mega-Hack -- Last "increment" during haggling
2011  */
2012 static s32b last_inc = 0L;
2013
2014 /*!
2015  * @brief 交渉価格を確認と認証の是非を行う /
2016  * Get a haggle
2017  * @param pmt メッセージ
2018  * @param poffer 別途価格提示をした場合の値を返す参照ポインタ
2019  * @param price 現在の交渉価格
2020  * @param final 最終確定価格ならばTRUE
2021  * @return プレイヤーを締め出す場合TRUEを返す
2022  */
2023 static int get_haggle(concptr pmt, s32b *poffer, PRICE price, int final)
2024 {
2025         GAME_TEXT buf[128];
2026         if (!allow_inc) last_inc = 0L;
2027
2028         if (final)
2029         {
2030                 sprintf(buf, _("%s [承諾] ", "%s [accept] "), pmt);
2031         }
2032         else if (last_inc < 0)
2033         {
2034                 sprintf(buf, _("%s [-$%ld] ", "%s [-%ld] "), pmt, (long)(ABS(last_inc)));
2035         }
2036         else if (last_inc > 0)
2037         {
2038                 sprintf(buf, _("%s [+$%ld] ", "%s [+%ld] "), pmt, (long)(ABS(last_inc)));
2039         }
2040         else
2041         {
2042                 sprintf(buf, "%s ", pmt);
2043         }
2044
2045         msg_print(NULL);
2046         GAME_TEXT out_val[160];
2047         while (TRUE)
2048         {
2049                 bool res;
2050                 prt(buf, 0, 0);
2051                 strcpy(out_val, "");
2052
2053                 /*
2054                  * Ask the user for a response.
2055                  * Don't allow to use numpad as cursor key.
2056                  */
2057                 res = askfor_aux(out_val, 32, FALSE);
2058                 prt("", 0, 0);
2059                 if (!res) return FALSE;
2060
2061                 concptr p;
2062                 for (p = out_val; *p == ' '; p++) /* loop */;
2063
2064                 if (*p == '\0')
2065                 {
2066                         if (final)
2067                         {
2068                                 *poffer = price;
2069                                 last_inc = 0L;
2070                                 break;
2071                         }
2072
2073                         if (allow_inc && last_inc)
2074                         {
2075                                 *poffer += last_inc;
2076                                 break;
2077                         }
2078
2079                         msg_print(_("値がおかしいです。", "Invalid response."));
2080                         msg_print(NULL);
2081                 }
2082
2083                 s32b i = atol(p);
2084                 if ((*p == '+' || *p == '-'))
2085                 {
2086                         if (allow_inc)
2087                         {
2088                                 *poffer += i;
2089                                 last_inc = i;
2090                                 break;
2091                         }
2092                 }
2093                 else
2094                 {
2095                         *poffer = i;
2096                         last_inc = 0L;
2097                         break;
2098                 }
2099         }
2100
2101         return TRUE;
2102 }
2103
2104
2105 /*!
2106  * @brief 店主がプレイヤーからの交渉価格を判断する /
2107  * Receive an offer (from the player)
2108  * @param pmt メッセージ
2109  * @param poffer 店主からの交渉価格を返す参照ポインタ
2110  * @param last_offer 現在の交渉価格
2111  * @param factor 店主の価格基準倍率
2112  * @param price アイテムの実価値
2113  * @param final 最終価格確定ならばTRUE
2114  * @return プレイヤーの価格に対して不服ならばTRUEを返す /
2115  * Return TRUE if offer is NOT okay
2116  */
2117 static bool receive_offer(concptr pmt, s32b *poffer, s32b last_offer, int factor, PRICE price, int final)
2118 {
2119         while (TRUE)
2120         {
2121                 if (!get_haggle(pmt, poffer, price, final)) return TRUE;
2122                 if (((*poffer) * factor) >= (last_offer * factor)) break;
2123                 if (haggle_insults()) return TRUE;
2124
2125                 (*poffer) = last_offer;
2126         }
2127
2128         return FALSE;
2129 }
2130
2131
2132 /*!
2133  * @brief プレイヤーが購入する時の値切り処理メインルーチン /
2134  * Haggling routine                             -RAK-
2135  * @param player_ptr プレーヤーへの参照ポインタ
2136  * @param o_ptr オブジェクトの構造体参照ポインタ
2137  * @param price 最終価格を返す参照ポインタ
2138  * @return プレイヤーの価格に対して店主が不服ならばTRUEを返す /
2139  * Return TRUE if purchase is NOT successful
2140  */
2141 static bool purchase_haggle(player_type *player_ptr, object_type *o_ptr, s32b *price)
2142 {
2143         s32b cur_ask = price_item(player_ptr, o_ptr, ot_ptr->max_inflate, FALSE);
2144         s32b final_ask = price_item(player_ptr, o_ptr, ot_ptr->min_inflate, FALSE);
2145         int noneed = noneedtobargain(final_ask);
2146         bool final = FALSE;
2147         concptr pmt = _("提示価格", "Asking");
2148         if (noneed || !manual_haggle)
2149         {
2150                 if (noneed)
2151                 {
2152                         msg_print(_("結局この金額にまとまった。", "You eventually agree upon the price."));
2153                         msg_print(NULL);
2154                 }
2155                 else
2156                 {
2157                         msg_print(_("すんなりとこの金額にまとまった。", "You quickly agree upon the price."));
2158                         msg_print(NULL);
2159                         final_ask += final_ask / 10;
2160                 }
2161
2162                 cur_ask = final_ask;
2163                 pmt = _("最終提示価格", "Final Offer");
2164                 final = TRUE;
2165         }
2166
2167         cur_ask *= o_ptr->number;
2168         final_ask *= o_ptr->number;
2169         s32b min_per = ot_ptr->haggle_per;
2170         s32b max_per = min_per * 3;
2171         s32b last_offer = object_value(o_ptr) * o_ptr->number;
2172         last_offer = last_offer * (200 - (int)(ot_ptr->max_inflate)) / 100L;
2173         if (last_offer <= 0) last_offer = 1;
2174
2175         s32b offer = 0;
2176         allow_inc = FALSE;
2177         bool flag = FALSE;
2178         int annoyed = 0;
2179         bool cancel = FALSE;
2180         *price = 0;
2181         while (!flag)
2182         {
2183                 bool loop_flag = TRUE;
2184
2185                 while (!flag && loop_flag)
2186                 {
2187                         char out_val[160];
2188                         (void)sprintf(out_val, "%s :  %ld", pmt, (long)cur_ask);
2189                         put_str(out_val, 1, 0);
2190                         cancel = receive_offer(_("提示する金額? ", "What do you offer? "), &offer, last_offer, 1, cur_ask, final);
2191                         if (cancel)
2192                         {
2193                                 flag = TRUE;
2194                         }
2195                         else if (offer > cur_ask)
2196                         {
2197                                 say_comment_6();
2198                                 offer = last_offer;
2199                         }
2200                         else if (offer == cur_ask)
2201                         {
2202                                 flag = TRUE;
2203                                 *price = offer;
2204                         }
2205                         else
2206                         {
2207                                 loop_flag = FALSE;
2208                         }
2209                 }
2210
2211                 if (flag) continue;
2212
2213                 s32b x1 = 100 * (offer - last_offer) / (cur_ask - last_offer);
2214                 if (x1 < min_per)
2215                 {
2216                         if (haggle_insults())
2217                         {
2218                                 flag = TRUE;
2219                                 cancel = TRUE;
2220                         }
2221                 }
2222                 else if (x1 > max_per)
2223                 {
2224                         x1 = x1 * 3 / 4;
2225                         if (x1 < max_per) x1 = max_per;
2226                 }
2227
2228                 s32b x2 = rand_range(x1 - 2, x1 + 2);
2229                 s32b x3 = ((cur_ask - offer) * x2 / 100L) + 1;
2230                 if (x3 < 0) x3 = 0;
2231                 cur_ask -= x3;
2232
2233                 if (cur_ask < final_ask)
2234                 {
2235                         final = TRUE;
2236                         cur_ask = final_ask;
2237                         pmt = _("最終提示価格", "What do you offer? ");
2238                         annoyed++;
2239                         if (annoyed > 3)
2240                         {
2241                                 (void)(increase_insults());
2242                                 cancel = TRUE;
2243                                 flag = TRUE;
2244                         }
2245                 }
2246                 else if (offer >= cur_ask)
2247                 {
2248                         flag = TRUE;
2249                         *price = offer;
2250                 }
2251
2252                 last_offer = offer;
2253                 allow_inc = TRUE;
2254                 prt("", 1, 0);
2255                 char out_val[160];
2256                 (void)sprintf(out_val, _("前回の提示金額: $%ld", "Your last offer: %ld"), (long)last_offer);
2257                 put_str(out_val, 1, 39);
2258                 say_comment_2(cur_ask, annoyed);
2259         }
2260
2261         if (cancel) return TRUE;
2262
2263         updatebargain(*price, final_ask, o_ptr->number);
2264         return FALSE;
2265 }
2266
2267
2268 /*!
2269  * @brief プレイヤーが売却する時の値切り処理メインルーチン /
2270  * Haggling routine                             -RAK-
2271  * @param player_ptr プレーヤーへの参照ポインタ
2272  * @param o_ptr オブジェクトの構造体参照ポインタ
2273  * @param price 最終価格を返す参照ポインタ
2274  * @return プレイヤーの価格に対して店主が不服ならばTRUEを返す /
2275  * Return TRUE if purchase is NOT successful
2276  */
2277 static bool sell_haggle(player_type *player_ptr, object_type *o_ptr, s32b *price)
2278 {
2279         s32b cur_ask = price_item(player_ptr, o_ptr, ot_ptr->max_inflate, TRUE);
2280         s32b final_ask = price_item(player_ptr, o_ptr, ot_ptr->min_inflate, TRUE);
2281         int noneed = noneedtobargain(final_ask);
2282         s32b purse = (s32b)(ot_ptr->max_cost);
2283         bool final = FALSE;
2284         concptr pmt = _("提示金額", "Offer");
2285         if (noneed || !manual_haggle || (final_ask >= purse))
2286         {
2287                 if (!manual_haggle && !noneed)
2288                 {
2289                         final_ask -= final_ask / 10;
2290                 }
2291
2292                 if (final_ask >= purse)
2293                 {
2294                         msg_print(_("即座にこの金額にまとまった。", "You instantly agree upon the price."));
2295                         msg_print(NULL);
2296                         final_ask = purse;
2297                 }
2298                 else if (noneed)
2299                 {
2300                         msg_print(_("結局この金額にまとまった。", "You eventually agree upon the price."));
2301                         msg_print(NULL);
2302                 }
2303                 else
2304                 {
2305                         msg_print(_("すんなりとこの金額にまとまった。", "You quickly agree upon the price."));
2306                         msg_print(NULL);
2307                 }
2308
2309                 cur_ask = final_ask;
2310                 final = TRUE;
2311                 pmt = _("最終提示金額", "Final Offer");
2312         }
2313
2314         cur_ask *= o_ptr->number;
2315         final_ask *= o_ptr->number;
2316
2317         s32b min_per = ot_ptr->haggle_per;
2318         s32b max_per = min_per * 3;
2319         s32b last_offer = object_value(o_ptr) * o_ptr->number;
2320         last_offer = last_offer * ot_ptr->max_inflate / 100L;
2321         s32b offer = 0;
2322         allow_inc = FALSE;
2323         bool flag = FALSE;
2324         bool loop_flag;
2325         int annoyed = 0;
2326         bool cancel = FALSE;
2327         *price = 0;
2328         while (!flag)
2329         {
2330                 while (TRUE)
2331                 {
2332                         loop_flag = TRUE;
2333
2334                         char out_val[160];
2335                         (void)sprintf(out_val, "%s :  %ld", pmt, (long)cur_ask);
2336                         put_str(out_val, 1, 0);
2337                         cancel = receive_offer(_("提示する価格? ", "What price do you ask? "),
2338                                 &offer, last_offer, -1, cur_ask, final);
2339
2340                         if (cancel)
2341                         {
2342                                 flag = TRUE;
2343                         }
2344                         else if (offer < cur_ask)
2345                         {
2346                                 say_comment_6();
2347                                 offer = last_offer;
2348                         }
2349                         else if (offer == cur_ask)
2350                         {
2351                                 flag = TRUE;
2352                                 *price = offer;
2353                         }
2354                         else
2355                         {
2356                                 loop_flag = FALSE;
2357                         }
2358
2359                         if (flag || !loop_flag) break;
2360                 }
2361
2362                 if (flag) continue;
2363
2364                 s32b x1 = 100 * (last_offer - offer) / (last_offer - cur_ask);
2365                 if (x1 < min_per)
2366                 {
2367                         if (haggle_insults())
2368                         {
2369                                 flag = TRUE;
2370                                 cancel = TRUE;
2371                         }
2372                 }
2373                 else if (x1 > max_per)
2374                 {
2375                         x1 = x1 * 3 / 4;
2376                         if (x1 < max_per) x1 = max_per;
2377                 }
2378
2379                 s32b x2 = rand_range(x1 - 2, x1 + 2);
2380                 s32b x3 = ((offer - cur_ask) * x2 / 100L) + 1;
2381                 if (x3 < 0) x3 = 0;
2382                 cur_ask += x3;
2383
2384                 if (cur_ask > final_ask)
2385                 {
2386                         cur_ask = final_ask;
2387                         final = TRUE;
2388                         pmt = _("最終提示金額", "Final Offer");
2389
2390                         annoyed++;
2391                         if (annoyed > 3)
2392                         {
2393                                 flag = TRUE;
2394 #ifdef JP
2395                                 /* 追加 $0 で買い取られてしまうのを防止 By FIRST*/
2396                                 cancel = TRUE;
2397 #endif
2398                                 (void)(increase_insults());
2399                         }
2400                 }
2401                 else if (offer <= cur_ask)
2402                 {
2403                         flag = TRUE;
2404                         *price = offer;
2405                 }
2406
2407                 last_offer = offer;
2408                 allow_inc = TRUE;
2409                 prt("", 1, 0);
2410                 char out_val[160];
2411                 (void)sprintf(out_val, _("前回の提示価格 $%ld", "Your last bid %ld"), (long)last_offer);
2412                 put_str(out_val, 1, 39);
2413                 say_comment_3(cur_ask, annoyed);
2414         }
2415
2416         if (cancel) return TRUE;
2417
2418         updatebargain(*price, final_ask, o_ptr->number);
2419         return FALSE;
2420 }
2421
2422
2423 /*!
2424  * @brief 店からの購入処理のメインルーチン /
2425  * Buy an item from a store                     -RAK-
2426  * @param player_ptr プレーヤーへの参照ポインタ
2427  * @return なし
2428  */
2429 static void store_purchase(player_type *player_ptr)
2430 {
2431         if (cur_store_num == STORE_MUSEUM)
2432         {
2433                 msg_print(_("博物館から取り出すことはできません。", "Museum."));
2434                 return;
2435         }
2436
2437         if (st_ptr->stock_num <= 0)
2438         {
2439                 if (cur_store_num == STORE_HOME)
2440                         msg_print(_("我が家には何も置いてありません。", "Your home is empty."));
2441                 else
2442                         msg_print(_("現在商品の在庫を切らしています。", "I am currently out of stock."));
2443                 return;
2444         }
2445
2446         int i = (st_ptr->stock_num - store_top);
2447         if (i > store_bottom) i = store_bottom;
2448
2449         char out_val[160];
2450 #ifdef JP
2451         /* ブラックマーケットの時は別のメッセージ */
2452         switch (cur_store_num) {
2453         case 7:
2454                 sprintf(out_val, "どのアイテムを取りますか? ");
2455                 break;
2456         case 6:
2457                 sprintf(out_val, "どれ? ");
2458                 break;
2459         default:
2460                 sprintf(out_val, "どの品物が欲しいんだい? ");
2461                 break;
2462         }
2463 #else
2464         if (cur_store_num == STORE_HOME)
2465         {
2466                 sprintf(out_val, "Which item do you want to take? ");
2467         }
2468         else
2469         {
2470                 sprintf(out_val, "Which item are you interested in? ");
2471         }
2472 #endif
2473
2474         COMMAND_CODE item;
2475         if (!get_stock(&item, out_val, 0, i - 1)) return;
2476
2477         item = item + store_top;
2478         object_type *o_ptr;
2479         o_ptr = &st_ptr->stock[item];
2480         ITEM_NUMBER amt = 1;
2481         object_type forge;
2482         object_type *j_ptr;
2483         j_ptr = &forge;
2484         object_copy(j_ptr, o_ptr);
2485
2486         /*
2487          * If a rod or wand, allocate total maximum timeouts or charges
2488          * between those purchased and left on the shelf.
2489          */
2490         reduce_charges(j_ptr, o_ptr->number - amt);
2491         j_ptr->number = amt;
2492         if (!inven_carry_okay(j_ptr))
2493         {
2494                 msg_print(_("そんなにアイテムを持てない。", "You cannot carry that many different items."));
2495                 return;
2496         }
2497
2498         PRICE best = price_item(player_ptr, j_ptr, ot_ptr->min_inflate, FALSE);
2499         if (o_ptr->number > 1)
2500         {
2501                 if ((cur_store_num != STORE_HOME) &&
2502                         (o_ptr->ident & IDENT_FIXED))
2503                 {
2504                         msg_format(_("一つにつき $%ldです。", "That costs %ld gold per item."), (long)(best));
2505                 }
2506
2507                 amt = get_quantity(NULL, o_ptr->number);
2508                 if (amt <= 0) return;
2509         }
2510
2511         j_ptr = &forge;
2512         object_copy(j_ptr, o_ptr);
2513
2514         /*
2515          * If a rod or wand, allocate total maximum timeouts or charges
2516          * between those purchased and left on the shelf.
2517          */
2518         reduce_charges(j_ptr, o_ptr->number - amt);
2519         j_ptr->number = amt;
2520         if (!inven_carry_okay(j_ptr))
2521         {
2522                 msg_print(_("ザックにそのアイテムを入れる隙間がない。", "You cannot carry that many items."));
2523                 return;
2524         }
2525
2526         int choice;
2527         COMMAND_CODE item_new;
2528         PRICE price;
2529         if (cur_store_num == STORE_HOME)
2530         {
2531                 bool combined_or_reordered;
2532                 distribute_charges(o_ptr, j_ptr, amt);
2533                 item_new = inven_carry(player_ptr, j_ptr);
2534                 GAME_TEXT o_name[MAX_NLEN];
2535                 object_desc(player_ptr, o_name, &player_ptr->inventory_list[item_new], 0);
2536
2537                 msg_format(_("%s(%c)を取った。", "You have %s (%c)."), o_name, index_to_label(item_new));
2538                 handle_stuff(player_ptr);
2539
2540                 i = st_ptr->stock_num;
2541                 store_item_increase(item, -amt);
2542                 store_item_optimize(item);
2543                 combined_or_reordered = combine_and_reorder_home(STORE_HOME);
2544                 if (i == st_ptr->stock_num)
2545                 {
2546                         if (combined_or_reordered) display_store_inventory(player_ptr);
2547                         else display_entry(player_ptr, item);
2548                 }
2549                 else
2550                 {
2551                         if (st_ptr->stock_num == 0) store_top = 0;
2552                         else if (store_top >= st_ptr->stock_num) store_top -= store_bottom;
2553                         display_store_inventory(player_ptr);
2554
2555                         chg_virtue(player_ptr, V_SACRIFICE, 1);
2556                 }
2557
2558                 return;
2559         }
2560
2561         if (o_ptr->ident & (IDENT_FIXED))
2562         {
2563                 choice = 0;
2564                 price = (best * j_ptr->number);
2565         }
2566         else
2567         {
2568                 GAME_TEXT o_name[MAX_NLEN];
2569                 object_desc(player_ptr, o_name, j_ptr, 0);
2570                 msg_format(_("%s(%c)を購入する。", "Buying %s (%c)."), o_name, I2A(item));
2571                 msg_print(NULL);
2572                 choice = purchase_haggle(player_ptr, j_ptr, &price);
2573                 if (st_ptr->store_open >= current_world_ptr->game_turn) return;
2574         }
2575
2576         if (choice != 0) return;
2577         if (price == (best * j_ptr->number)) o_ptr->ident |= (IDENT_FIXED);
2578         if (player_ptr->au < price)
2579         {
2580                 msg_print(_("お金が足りません。", "You do not have enough gold."));
2581                 return;
2582         }
2583
2584         say_comment_1(player_ptr);
2585         if (cur_store_num == STORE_BLACK)
2586                 chg_virtue(player_ptr, V_JUSTICE, -1);
2587         if ((o_ptr->tval == TV_BOTTLE) && (cur_store_num != STORE_HOME))
2588                 chg_virtue(player_ptr, V_NATURE, -1);
2589
2590         sound(SOUND_BUY);
2591         decrease_insults();
2592         player_ptr->au -= price;
2593         store_prt_gold(player_ptr);
2594         object_aware(player_ptr, j_ptr);
2595         j_ptr->ident &= ~(IDENT_FIXED);
2596         GAME_TEXT o_name[MAX_NLEN];
2597         object_desc(player_ptr, o_name, j_ptr, 0);
2598
2599         msg_format(_("%sを $%ldで購入しました。", "You bought %s for %ld gold."), o_name, (long)price);
2600
2601         strcpy(record_o_name, o_name);
2602         record_turn = current_world_ptr->game_turn;
2603
2604         if (record_buy) exe_write_diary(player_ptr, DIARY_BUY, 0, o_name);
2605         object_desc(player_ptr, o_name, o_ptr, OD_NAME_ONLY);
2606         if (record_rand_art && o_ptr->art_name)
2607                 exe_write_diary(player_ptr, DIARY_ART, 0, o_name);
2608
2609         j_ptr->inscription = 0;
2610         j_ptr->feeling = FEEL_NONE;
2611         j_ptr->ident &= ~(IDENT_STORE);
2612         item_new = inven_carry(player_ptr, j_ptr);
2613
2614         object_desc(player_ptr, o_name, &player_ptr->inventory_list[item_new], 0);
2615         msg_format(_("%s(%c)を手に入れた。", "You have %s (%c)."), o_name, index_to_label(item_new));
2616         autopick_alter_item(player_ptr, item_new, FALSE);
2617         if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND))
2618         {
2619                 o_ptr->pval -= j_ptr->pval;
2620         }
2621
2622         handle_stuff(player_ptr);
2623         i = st_ptr->stock_num;
2624         store_item_increase(item, -amt);
2625         store_item_optimize(item);
2626         if (st_ptr->stock_num == 0)
2627         {
2628                 if (one_in_(STORE_SHUFFLE))
2629                 {
2630                         char buf[80];
2631                         msg_print(_("店主は引退した。", "The shopkeeper retires."));
2632                         store_shuffle(player_ptr, cur_store_num);
2633
2634                         prt("", 3, 0);
2635                         sprintf(buf, "%s (%s)",
2636                                 ot_ptr->owner_name, race_info[ot_ptr->owner_race].title);
2637                         put_str(buf, 3, 10);
2638                         sprintf(buf, "%s (%ld)",
2639                                 (f_name + f_info[cur_store_feat].name), (long)(ot_ptr->max_cost));
2640                         prt(buf, 3, 50);
2641                 }
2642                 else
2643                 {
2644                         msg_print(_("店主は新たな在庫を取り出した。", "The shopkeeper brings out some new stock."));
2645                 }
2646
2647                 for (i = 0; i < 10; i++)
2648                 {
2649                         store_maint(player_ptr, player_ptr->town_num, cur_store_num);
2650                 }
2651
2652                 store_top = 0;
2653                 display_store_inventory(player_ptr);
2654         }
2655         else if (st_ptr->stock_num != i)
2656         {
2657                 if (store_top >= st_ptr->stock_num) store_top -= store_bottom;
2658                 display_store_inventory(player_ptr);
2659         }
2660         else
2661         {
2662                 display_entry(player_ptr, item);
2663         }
2664 }
2665
2666
2667 /*!
2668  * @brief 店からの売却処理のメインルーチン /
2669  * Sell an item to the store (or home)
2670  * @param owner_ptr プレーヤーへの参照ポインタ
2671  * @return なし
2672  */
2673 static void store_sell(player_type *owner_ptr)
2674 {
2675         concptr q;
2676         if (cur_store_num == STORE_HOME)
2677                 q = _("どのアイテムを置きますか? ", "Drop which item? ");
2678         else if (cur_store_num == STORE_MUSEUM)
2679                 q = _("どのアイテムを寄贈しますか? ", "Give which item? ");
2680         else
2681                 q = _("どのアイテムを売りますか? ", "Sell which item? ");
2682
2683         item_tester_hook = store_will_buy;
2684
2685         /* 我が家でおかしなメッセージが出るオリジナルのバグを修正 */
2686         concptr s;
2687         if (cur_store_num == STORE_HOME)
2688         {
2689                 s = _("置けるアイテムを持っていません。", "You don't have any item to drop.");
2690         }
2691         else if (cur_store_num == STORE_MUSEUM)
2692         {
2693                 s = _("寄贈できるアイテムを持っていません。", "You don't have any item to give.");
2694         }
2695         else
2696         {
2697                 s = _("欲しい物がないですねえ。", "You have nothing that I want.");
2698         }
2699
2700         OBJECT_IDX item;
2701         object_type *o_ptr;
2702         o_ptr = choose_object(owner_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
2703         if (!o_ptr) return;
2704
2705         if ((item >= INVEN_RARM) && object_is_cursed(o_ptr))
2706         {
2707                 msg_print(_("ふーむ、どうやらそれは呪われているようだね。", "Hmmm, it seems to be cursed."));
2708                 return;
2709         }
2710
2711         int amt = 1;
2712         if (o_ptr->number > 1)
2713         {
2714                 amt = get_quantity(NULL, o_ptr->number);
2715                 if (amt <= 0) return;
2716         }
2717
2718         object_type forge;
2719         object_type *q_ptr;
2720         q_ptr = &forge;
2721         object_copy(q_ptr, o_ptr);
2722         q_ptr->number = amt;
2723
2724         /*
2725          * Hack -- If a rod or wand, allocate total maximum
2726          * timeouts or charges to those being sold. -LM-
2727          */
2728         if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND))
2729         {
2730                 q_ptr->pval = o_ptr->pval * amt / o_ptr->number;
2731         }
2732
2733         GAME_TEXT o_name[MAX_NLEN];
2734         object_desc(owner_ptr, o_name, q_ptr, 0);
2735
2736         /* Remove any inscription, feeling for stores */
2737         if ((cur_store_num != STORE_HOME) && (cur_store_num != STORE_MUSEUM))
2738         {
2739                 q_ptr->inscription = 0;
2740                 q_ptr->feeling = FEEL_NONE;
2741         }
2742
2743         /* Is there room in the store (or the home?) */
2744         if (!store_check_num(q_ptr))
2745         {
2746                 if (cur_store_num == STORE_HOME)
2747                         msg_print(_("我が家にはもう置く場所がない。", "Your home is full."));
2748
2749                 else if (cur_store_num == STORE_MUSEUM)
2750                         msg_print(_("博物館はもう満杯だ。", "Museum is full."));
2751
2752                 else
2753                         msg_print(_("すいませんが、店にはもう置く場所がありません。", "I have not the room in my store to keep it."));
2754
2755                 return;
2756         }
2757
2758         int choice;
2759         PRICE price, value, dummy;
2760         if ((cur_store_num != STORE_HOME) && (cur_store_num != STORE_MUSEUM))
2761         {
2762                 msg_format(_("%s(%c)を売却する。", "Selling %s (%c)."), o_name, index_to_label(item));
2763                 msg_print(NULL);
2764
2765                 choice = sell_haggle(owner_ptr, q_ptr, &price);
2766                 if (st_ptr->store_open >= current_world_ptr->game_turn) return;
2767
2768                 if (choice == 0)
2769                 {
2770                         say_comment_1(owner_ptr);
2771                         sound(SOUND_SELL);
2772                         if (cur_store_num == STORE_BLACK)
2773                                 chg_virtue(owner_ptr, V_JUSTICE, -1);
2774
2775                         if ((o_ptr->tval == TV_BOTTLE) && (cur_store_num != STORE_HOME))
2776                                 chg_virtue(owner_ptr, V_NATURE, 1);
2777                         decrease_insults();
2778
2779                         owner_ptr->au += price;
2780                         store_prt_gold(owner_ptr);
2781                         dummy = object_value(q_ptr) * q_ptr->number;
2782
2783                         identify_item(owner_ptr, o_ptr);
2784                         q_ptr = &forge;
2785                         object_copy(q_ptr, o_ptr);
2786                         q_ptr->number = amt;
2787                         q_ptr->ident |= IDENT_STORE;
2788
2789                         /*
2790                          * Hack -- If a rod or wand, let the shopkeeper know just
2791                          * how many charges he really paid for. -LM-
2792                          */
2793                         if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND))
2794                         {
2795                                 q_ptr->pval = o_ptr->pval * amt / o_ptr->number;
2796                         }
2797
2798                         value = object_value(q_ptr) * q_ptr->number;
2799                         object_desc(owner_ptr, o_name, q_ptr, 0);
2800                         msg_format(_("%sを $%ldで売却しました。", "You sold %s for %ld gold."), o_name, (long)price);
2801
2802                         if (record_sell) exe_write_diary(owner_ptr, DIARY_SELL, 0, o_name);
2803
2804                         if (!((o_ptr->tval == TV_FIGURINE) && (value > 0)))
2805                         {
2806                                 purchase_analyze(owner_ptr, price, value, dummy);
2807                         }
2808
2809                         /*
2810                          * Hack -- Allocate charges between those wands or rods sold
2811                          * and retained, unless all are being sold. -LM-
2812                          */
2813                         distribute_charges(o_ptr, q_ptr, amt);
2814                         q_ptr->timeout = 0;
2815                         inven_item_increase(owner_ptr, item, -amt);
2816                         inven_item_describe(owner_ptr, item);
2817                         if (o_ptr->number > 0)
2818                                 autopick_alter_item(owner_ptr, item, FALSE);
2819
2820                         inven_item_optimize(owner_ptr, item);
2821                         handle_stuff(owner_ptr);
2822                         int item_pos = store_carry(q_ptr);
2823                         if (item_pos >= 0)
2824                         {
2825                                 store_top = (item_pos / store_bottom) * store_bottom;
2826                                 display_store_inventory(owner_ptr);
2827                         }
2828                 }
2829         }
2830         else if (cur_store_num == STORE_MUSEUM)
2831         {
2832                 char o2_name[MAX_NLEN];
2833                 object_desc(owner_ptr, o2_name, q_ptr, OD_NAME_ONLY);
2834
2835                 if (-1 == store_check_num(q_ptr))
2836                 {
2837                         msg_print(_("それと同じ品物は既に博物館にあるようです。", "The Museum already has one of those items."));
2838                 }
2839                 else
2840                 {
2841                         msg_print(_("博物館に寄贈したものは取り出すことができません!!", "You cannot take back items which have been donated to the Museum!!"));
2842                 }
2843
2844                 if (!get_check(format(_("本当に%sを寄贈しますか?", "Really give %s to the Museum? "), o2_name))) return;
2845
2846                 identify_item(owner_ptr, q_ptr);
2847                 q_ptr->ident |= IDENT_FULL_KNOWN;
2848
2849                 distribute_charges(o_ptr, q_ptr, amt);
2850                 msg_format(_("%sを置いた。(%c)", "You drop %s (%c)."), o_name, index_to_label(item));
2851                 choice = 0;
2852
2853                 vary_item(owner_ptr, item, -amt);
2854                 handle_stuff(owner_ptr);
2855
2856                 int item_pos = home_carry(owner_ptr, q_ptr);
2857                 if (item_pos >= 0)
2858                 {
2859                         store_top = (item_pos / store_bottom) * store_bottom;
2860                         display_store_inventory(owner_ptr);
2861                 }
2862         }
2863         else
2864         {
2865                 distribute_charges(o_ptr, q_ptr, amt);
2866                 msg_format(_("%sを置いた。(%c)", "You drop %s (%c)."), o_name, index_to_label(item));
2867                 choice = 0;
2868                 vary_item(owner_ptr, item, -amt);
2869                 handle_stuff(owner_ptr);
2870                 int item_pos = home_carry(owner_ptr, q_ptr);
2871                 if (item_pos >= 0)
2872                 {
2873                         store_top = (item_pos / store_bottom) * store_bottom;
2874                         display_store_inventory(owner_ptr);
2875                 }
2876         }
2877
2878         if ((choice == 0) && (item >= INVEN_RARM))
2879         {
2880                 calc_android_exp(owner_ptr);
2881                 verify_equip_slot(owner_ptr, item);
2882         }
2883 }
2884
2885
2886 /*!
2887  * @brief 店のアイテムを調べるコマンドのメインルーチン /
2888  * Examine an item in a store                      -JDL-
2889  * @return なし
2890  */
2891 static void store_examine(player_type *player_ptr)
2892 {
2893         if (st_ptr->stock_num <= 0)
2894         {
2895                 if (cur_store_num == STORE_HOME)
2896                         msg_print(_("我が家には何も置いてありません。", "Your home is empty."));
2897                 else if (cur_store_num == STORE_MUSEUM)
2898                         msg_print(_("博物館には何も置いてありません。", "Museum is empty."));
2899                 else
2900                         msg_print(_("現在商品の在庫を切らしています。", "I am currently out of stock."));
2901                 return;
2902         }
2903
2904         int i = (st_ptr->stock_num - store_top);
2905         if (i > store_bottom) i = store_bottom;
2906
2907         char out_val[160];
2908         sprintf(out_val, _("どれを調べますか?", "Which item do you want to examine? "));
2909
2910         COMMAND_CODE item;
2911         if (!get_stock(&item, out_val, 0, i - 1)) return;
2912         item = item + store_top;
2913         object_type *o_ptr;
2914         o_ptr = &st_ptr->stock[item];
2915         if (!OBJECT_IS_FULL_KNOWN(o_ptr))
2916         {
2917                 msg_print(_("このアイテムについて特に知っていることはない。", "You have no special knowledge about that item."));
2918                 return;
2919         }
2920
2921         GAME_TEXT o_name[MAX_NLEN];
2922         object_desc(player_ptr, o_name, o_ptr, 0);
2923         msg_format(_("%sを調べている...", "Examining %s..."), o_name);
2924
2925         if (!screen_object(player_ptr, o_ptr, SCROBJ_FORCE_DETAIL))
2926                 msg_print(_("特に変わったところはないようだ。", "You see nothing special."));
2927
2928         return;
2929 }
2930
2931
2932 /*!
2933  * @brief 博物館のアイテムを除去するコマンドのメインルーチン /
2934  * Remove an item from museum (Originally from TOband)
2935  * @param player_ptr プレーヤーへの参照ポインタ
2936  * @return なし
2937  */
2938 static void museum_remove_object(player_type *player_ptr)
2939 {
2940         if (st_ptr->stock_num <= 0)
2941         {
2942                 msg_print(_("博物館には何も置いてありません。", "Museum is empty."));
2943                 return;
2944         }
2945
2946         int i = st_ptr->stock_num - store_top;
2947         if (i > store_bottom) i = store_bottom;
2948
2949         char out_val[160];
2950         sprintf(out_val, _("どのアイテムの展示をやめさせますか?", "Which item do you want to order to remove? "));
2951
2952         COMMAND_CODE item;
2953         if (!get_stock(&item, out_val, 0, i - 1)) return;
2954
2955         item = item + store_top;
2956         object_type *o_ptr;
2957         o_ptr = &st_ptr->stock[item];
2958
2959         GAME_TEXT o_name[MAX_NLEN];
2960         object_desc(player_ptr, o_name, o_ptr, 0);
2961
2962         msg_print(_("展示をやめさせたアイテムは二度と見ることはできません!", "Once removed from the Museum, an item will be gone forever!"));
2963         if (!get_check(format(_("本当に%sの展示をやめさせますか?", "Really order to remove %s from the Museum? "), o_name))) return;
2964
2965         msg_format(_("%sの展示をやめさせた。", "You ordered to remove %s."), o_name);
2966
2967         store_item_increase(item, -o_ptr->number);
2968         store_item_optimize(item);
2969
2970         (void)combine_and_reorder_home(STORE_MUSEUM);
2971         if (st_ptr->stock_num == 0) store_top = 0;
2972
2973         else if (store_top >= st_ptr->stock_num) store_top -= store_bottom;
2974         display_store_inventory(player_ptr);
2975 }
2976
2977
2978 /*
2979  * Hack -- set this to leave the store
2980  */
2981 static bool leave_store = FALSE;
2982
2983
2984 /*!
2985  * @brief 店舗処理コマンド選択のメインルーチン /
2986  * Process a command in a store
2987  * @param client_ptr 顧客となるクリーチャーの参照ポインタ
2988  * @return なし
2989  * @note
2990  * <pre>
2991  * Note that we must allow the use of a few "special" commands
2992  * in the stores which are not allowed in the dungeon, and we
2993  * must disable some commands which are allowed in the dungeon
2994  * but not in the stores, to prevent chaos.
2995  * </pre>
2996  */
2997 static void store_process_command(player_type *client_ptr)
2998 {
2999         repeat_check();
3000         if (rogue_like_commands && command_cmd == 'l')
3001         {
3002                 command_cmd = 'x';
3003         }
3004
3005         switch (command_cmd)
3006         {
3007         case ESCAPE:
3008         {
3009                 leave_store = TRUE;
3010                 break;
3011         }
3012         case '-':
3013         {
3014                 /* 日本語版追加 */
3015                 /* 1 ページ戻るコマンド: 我が家のページ数が多いので重宝するはず By BUG */
3016                 if (st_ptr->stock_num <= store_bottom) {
3017                         msg_print(_("これで全部です。", "Entire inventory is shown."));
3018                 }
3019                 else {
3020                         store_top -= store_bottom;
3021                         if (store_top < 0)
3022                                 store_top = ((st_ptr->stock_num - 1) / store_bottom) * store_bottom;
3023                         if ((cur_store_num == STORE_HOME) && (powerup_home == FALSE))
3024                                 if (store_top >= store_bottom) store_top = store_bottom;
3025                         display_store_inventory(client_ptr);
3026                 }
3027
3028                 break;
3029         }
3030         case ' ':
3031         {
3032                 if (st_ptr->stock_num <= store_bottom)
3033                 {
3034                         msg_print(_("これで全部です。", "Entire inventory is shown."));
3035                 }
3036                 else
3037                 {
3038                         store_top += store_bottom;
3039                         /*
3040                          * 隠しオプション(powerup_home)がセットされていないときは
3041                          * 我が家では 2 ページまでしか表示しない
3042                          */
3043                         if ((cur_store_num == STORE_HOME) &&
3044                                 (powerup_home == FALSE) &&
3045                                 (st_ptr->stock_num >= STORE_INVEN_MAX))
3046                         {
3047                                 if (store_top >= (STORE_INVEN_MAX - 1))
3048                                 {
3049                                         store_top = 0;
3050                                 }
3051                         }
3052                         else
3053                         {
3054                                 if (store_top >= st_ptr->stock_num) store_top = 0;
3055                         }
3056
3057                         display_store_inventory(client_ptr);
3058                 }
3059
3060                 break;
3061         }
3062         case KTRL('R'):
3063         {
3064                 do_cmd_redraw(client_ptr);
3065                 display_store(client_ptr);
3066                 break;
3067         }
3068         case 'g':
3069         {
3070                 store_purchase(client_ptr);
3071                 break;
3072         }
3073         case 'd':
3074         {
3075                 store_sell(client_ptr);
3076                 break;
3077         }
3078         case 'x':
3079         {
3080                 store_examine(client_ptr);
3081                 break;
3082         }
3083         case '\r':
3084         {
3085                 break;
3086         }
3087         case 'w':
3088         {
3089                 do_cmd_wield(client_ptr);
3090                 break;
3091         }
3092         case 't':
3093         {
3094                 do_cmd_takeoff(client_ptr);
3095                 break;
3096         }
3097         case 'k':
3098         {
3099                 do_cmd_destroy(client_ptr);
3100                 break;
3101         }
3102         case 'e':
3103         {
3104                 do_cmd_equip(client_ptr);
3105                 break;
3106         }
3107         case 'i':
3108         {
3109                 do_cmd_inven(client_ptr);
3110                 break;
3111         }
3112         case 'I':
3113         {
3114                 do_cmd_observe(client_ptr);
3115                 break;
3116         }
3117         case KTRL('I'):
3118         {
3119                 toggle_inventory_equipment(client_ptr);
3120                 break;
3121         }
3122         case 'b':
3123         {
3124                 if ((client_ptr->pclass == CLASS_MINDCRAFTER) ||
3125                         (client_ptr->pclass == CLASS_BERSERKER) ||
3126                         (client_ptr->pclass == CLASS_NINJA) ||
3127                         (client_ptr->pclass == CLASS_MIRROR_MASTER)
3128                         ) do_cmd_mind_browse(client_ptr);
3129                 else if (client_ptr->pclass == CLASS_SMITH)
3130                         do_cmd_kaji(client_ptr, TRUE);
3131                 else if (client_ptr->pclass == CLASS_MAGIC_EATER)
3132                         do_cmd_magic_eater(client_ptr, TRUE, FALSE);
3133                 else if (client_ptr->pclass == CLASS_SNIPER)
3134                         do_cmd_snipe_browse(client_ptr);
3135                 else do_cmd_browse(client_ptr);
3136                 break;
3137         }
3138         case '{':
3139         {
3140                 do_cmd_inscribe(client_ptr);
3141                 break;
3142         }
3143         case '}':
3144         {
3145                 do_cmd_uninscribe(client_ptr);
3146                 break;
3147         }
3148         case '?':
3149         {
3150                 do_cmd_help(client_ptr);
3151                 break;
3152         }
3153         case '/':
3154         {
3155                 do_cmd_query_symbol(client_ptr);
3156                 break;
3157         }
3158         case 'C':
3159         {
3160                 client_ptr->town_num = old_town_num;
3161                 do_cmd_player_status(client_ptr);
3162                 client_ptr->town_num = inner_town_num;
3163                 display_store(client_ptr);
3164                 break;
3165         }
3166         case '!':
3167         {
3168                 (void)Term_user(0);
3169                 break;
3170         }
3171         case '"':
3172         {
3173                 client_ptr->town_num = old_town_num;
3174                 do_cmd_pref(client_ptr);
3175                 client_ptr->town_num = inner_town_num;
3176                 break;
3177         }
3178         case '@':
3179         {
3180                 client_ptr->town_num = old_town_num;
3181                 do_cmd_macros(client_ptr);
3182                 client_ptr->town_num = inner_town_num;
3183                 break;
3184         }
3185         case '%':
3186         {
3187                 client_ptr->town_num = old_town_num;
3188                 do_cmd_visuals(client_ptr);
3189                 client_ptr->town_num = inner_town_num;
3190                 break;
3191         }
3192         case '&':
3193         {
3194                 client_ptr->town_num = old_town_num;
3195                 do_cmd_colors(client_ptr);
3196                 client_ptr->town_num = inner_town_num;
3197                 break;
3198         }
3199         case '=':
3200         {
3201                 do_cmd_options();
3202                 (void)combine_and_reorder_home(STORE_HOME);
3203                 do_cmd_redraw(client_ptr);
3204                 display_store(client_ptr);
3205                 break;
3206         }
3207         case ':':
3208         {
3209                 do_cmd_note();
3210                 break;
3211         }
3212         case 'V':
3213         {
3214                 do_cmd_version();
3215                 break;
3216         }
3217         case KTRL('F'):
3218         {
3219                 do_cmd_feeling(client_ptr);
3220                 break;
3221         }
3222         case KTRL('O'):
3223         {
3224                 do_cmd_message_one();
3225                 break;
3226         }
3227         case KTRL('P'):
3228         {
3229                 do_cmd_messages(0);
3230                 break;
3231         }
3232         case '|':
3233         {
3234                 do_cmd_diary(client_ptr);
3235                 break;
3236         }
3237         case '~':
3238         {
3239                 do_cmd_knowledge(client_ptr);
3240                 break;
3241         }
3242         case '(':
3243         {
3244                 do_cmd_load_screen();
3245                 break;
3246         }
3247         case ')':
3248         {
3249                 do_cmd_save_screen(client_ptr);
3250                 break;
3251         }
3252         default:
3253         {
3254                 if ((cur_store_num == STORE_MUSEUM) && (command_cmd == 'r'))
3255                 {
3256                         museum_remove_object(client_ptr);
3257                 }
3258                 else
3259                 {
3260                         msg_print(_("そのコマンドは店の中では使えません。", "That command does not work in stores."));
3261                 }
3262
3263                 break;
3264         }
3265         }
3266 }
3267
3268
3269 /*!
3270  * @brief 店舗処理全体のメインルーチン /
3271  * Enter a store, and interact with it. *
3272  * @param player_ptr プレーヤーへの参照ポインタ
3273  * @return なし
3274  * @note
3275  * <pre>
3276  * Note that we use the standard "request_command()" function
3277  * to get a command, allowing us to use "command_arg" and all
3278  * command macros and other nifty stuff, but we use the special
3279  * "shopping" argument, to force certain commands to be converted
3280  * into other commands, normally, we convert "p" (pray) and "m"
3281  * (cast magic) into "g" (get), and "s" (search) into "d" (drop).
3282  * </pre>
3283  */
3284 void do_cmd_store(player_type *player_ptr)
3285 {
3286         if (player_ptr->wild_mode) return;
3287         TERM_LEN w, h;
3288         Term_get_size(&w, &h);
3289
3290         xtra_stock = MIN(14 + 26, ((h > 24) ? (h - 24) : 0));
3291         store_bottom = MIN_STOCK + xtra_stock;
3292
3293         grid_type *g_ptr;
3294         g_ptr = &player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x];
3295
3296         if (!cave_have_flag_grid(g_ptr, FF_STORE))
3297         {
3298                 msg_print(_("ここには店がありません。", "You see no store here."));
3299                 return;
3300         }
3301
3302         int which = f_info[g_ptr->feat].subtype;
3303         old_town_num = player_ptr->town_num;
3304         if ((which == STORE_HOME) || (which == STORE_MUSEUM)) player_ptr->town_num = 1;
3305         if (player_ptr->current_floor_ptr->dun_level) player_ptr->town_num = NO_TOWN;
3306         inner_town_num = player_ptr->town_num;
3307
3308         if ((town_info[player_ptr->town_num].store[which].store_open >= current_world_ptr->game_turn) ||
3309                 (ironman_shops))
3310         {
3311                 msg_print(_("ドアに鍵がかかっている。", "The doors are locked."));
3312                 player_ptr->town_num = old_town_num;
3313                 return;
3314         }
3315
3316         int maintain_num = (current_world_ptr->game_turn - town_info[player_ptr->town_num].store[which].last_visit) / (TURNS_PER_TICK * STORE_TICKS);
3317         if (maintain_num > 10)
3318                 maintain_num = 10;
3319         if (maintain_num)
3320         {
3321                 for (int i = 0; i < maintain_num; i++)
3322                         store_maint(player_ptr, player_ptr->town_num, which);
3323
3324                 town_info[player_ptr->town_num].store[which].last_visit = current_world_ptr->game_turn;
3325         }
3326
3327         forget_lite(player_ptr->current_floor_ptr);
3328         forget_view(player_ptr->current_floor_ptr);
3329         current_world_ptr->character_icky = TRUE;
3330         command_arg = 0;
3331         command_rep = 0;
3332         command_new = 0;
3333         get_com_no_macros = TRUE;
3334         cur_store_num = which;
3335         cur_store_feat = g_ptr->feat;
3336         st_ptr = &town_info[player_ptr->town_num].store[cur_store_num];
3337         ot_ptr = &owners[cur_store_num][st_ptr->owner];
3338         store_top = 0;
3339         play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_BUILD);
3340         display_store(player_ptr);
3341         leave_store = FALSE;
3342
3343         while (!leave_store)
3344         {
3345                 prt("", 1, 0);
3346                 clear_from(20 + xtra_stock);
3347                 prt(_(" ESC) 建物から出る", " ESC) Exit from Building."), 21 + xtra_stock, 0);
3348                 if (st_ptr->stock_num > store_bottom)
3349                 {
3350                         prt(_(" -)前ページ", " -) Previous page"), 22 + xtra_stock, 0);
3351                         prt(_(" スペース) 次ページ", " SPACE) Next page"), 23 + xtra_stock, 0);
3352                 }
3353
3354                 if (cur_store_num == STORE_HOME)
3355                 {
3356                         prt(_("g) アイテムを取る", "g) Get an item."), 21 + xtra_stock, 27);
3357                         prt(_("d) アイテムを置く", "d) Drop an item."), 22 + xtra_stock, 27);
3358                         prt(_("x) 家のアイテムを調べる", "x) eXamine an item in the home."), 23 + xtra_stock, 27);
3359                 }
3360                 else if (cur_store_num == STORE_MUSEUM)
3361                 {
3362                         prt(_("d) アイテムを置く", "d) Drop an item."), 21 + xtra_stock, 27);
3363                         prt(_("r) アイテムの展示をやめる", "r) order to Remove an item."), 22 + xtra_stock, 27);
3364                         prt(_("x) 博物館のアイテムを調べる", "x) eXamine an item in the museum."), 23 + xtra_stock, 27);
3365                 }
3366                 else
3367                 {
3368                         prt(_("p) 商品を買う", "p) Purchase an item."), 21 + xtra_stock, 30);
3369                         prt(_("s) アイテムを売る", "s) Sell an item."), 22 + xtra_stock, 30);
3370                         prt(_("x) 商品を調べる", "x) eXamine an item in the shop"), 23 + xtra_stock, 30);
3371                 }
3372
3373                 prt(_("i/e) 持ち物/装備の一覧", "i/e) Inventry/Equipment list"), 21 + xtra_stock, 56);
3374                 if (rogue_like_commands)
3375                 {
3376                         prt(_("w/T) 装備する/はずす", "w/T) Wear/Take off equipment"), 22 + xtra_stock, 56);
3377                 }
3378                 else
3379                 {
3380                         prt(_("w/t) 装備する/はずす", "w/t) Wear/Take off equipment"), 22 + xtra_stock, 56);
3381                 }
3382
3383                 prt(_("コマンド:", "You may: "), 20 + xtra_stock, 0);
3384                 request_command(player_ptr, TRUE);
3385                 store_process_command(player_ptr);
3386
3387                 /*
3388                  * Hack -- To redraw missiles damage and prices in store
3389                  * If player's charisma changes, or if player changes a bow, PU_BONUS is set
3390                  */
3391                 bool need_redraw_store_inv = (player_ptr->update & PU_BONUS) ? TRUE : FALSE;
3392                 current_world_ptr->character_icky = TRUE;
3393                 handle_stuff(player_ptr);
3394                 if (player_ptr->inventory_list[INVEN_PACK].k_idx)
3395                 {
3396                         INVENTORY_IDX item = INVEN_PACK;
3397                         object_type *o_ptr = &player_ptr->inventory_list[item];
3398                         if (cur_store_num != STORE_HOME)
3399                         {
3400                                 if (cur_store_num == STORE_MUSEUM)
3401                                         msg_print(_("ザックからアイテムがあふれそうなので、あわてて博物館から出た...", "Your pack is so full that you flee the Museum..."));
3402                                 else
3403                                         msg_print(_("ザックからアイテムがあふれそうなので、あわてて店から出た...", "Your pack is so full that you flee the store..."));
3404
3405                                 leave_store = TRUE;
3406                         }
3407                         else if (!store_check_num(o_ptr))
3408                         {
3409                                 msg_print(_("ザックからアイテムがあふれそうなので、あわてて家から出た...", "Your pack is so full that you flee your home..."));
3410                                 leave_store = TRUE;
3411                         }
3412                         else
3413                         {
3414                                 int item_pos;
3415                                 object_type forge;
3416                                 object_type *q_ptr;
3417                                 GAME_TEXT o_name[MAX_NLEN];
3418                                 msg_print(_("ザックからアイテムがあふれてしまった!", "Your pack overflows!"));
3419                                 q_ptr = &forge;
3420                                 object_copy(q_ptr, o_ptr);
3421                                 object_desc(player_ptr, o_name, q_ptr, 0);
3422                                 msg_format(_("%sが落ちた。(%c)", "You drop %s (%c)."), o_name, index_to_label(item));
3423                                 vary_item(player_ptr, item, -255);
3424                                 handle_stuff(player_ptr);
3425
3426                                 item_pos = home_carry(player_ptr, q_ptr);
3427                                 if (item_pos >= 0)
3428                                 {
3429                                         store_top = (item_pos / store_bottom) * store_bottom;
3430                                         display_store_inventory(player_ptr);
3431                                 }
3432                         }
3433                 }
3434
3435                 if (need_redraw_store_inv) display_store_inventory(player_ptr);
3436
3437                 if (st_ptr->store_open >= current_world_ptr->game_turn) leave_store = TRUE;
3438         }
3439
3440         select_floor_music(player_ptr);
3441         player_ptr->town_num = old_town_num;
3442         take_turn(player_ptr, 100);
3443         current_world_ptr->character_icky = FALSE;
3444         command_new = 0;
3445         command_see = FALSE;
3446         get_com_no_macros = FALSE;
3447
3448         msg_erase();
3449         Term_clear();
3450
3451         player_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
3452         player_ptr->update |= (PU_MONSTERS);
3453         player_ptr->redraw |= (PR_BASIC | PR_EXTRA | PR_EQUIPPY);
3454         player_ptr->redraw |= (PR_MAP);
3455         player_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3456 }
3457
3458
3459 /*!
3460  * @brief 現在の町の店主を交代させる /
3461  * Shuffle one of the stores.
3462  * @param which 店舗種類のID
3463  * @return なし
3464  */
3465 void store_shuffle(player_type *player_ptr, int which)
3466 {
3467         if (which == STORE_HOME) return;
3468         if (which == STORE_MUSEUM) return;
3469
3470         cur_store_num = which;
3471         st_ptr = &town_info[player_ptr->town_num].store[cur_store_num];
3472         int j = st_ptr->owner;
3473         while (TRUE)
3474         {
3475                 st_ptr->owner = (byte)randint0(MAX_OWNERS);
3476                 if (j == st_ptr->owner) continue;
3477                 int i;
3478                 for (i = 1; i < max_towns; i++)
3479                 {
3480                         if (i == player_ptr->town_num) continue;
3481                         if (st_ptr->owner == town_info[i].store[cur_store_num].owner) break;
3482                 }
3483
3484                 if (i == max_towns) break;
3485         }
3486
3487         ot_ptr = &owners[cur_store_num][st_ptr->owner];
3488         st_ptr->insult_cur = 0;
3489         st_ptr->store_open = 0;
3490         st_ptr->good_buy = 0;
3491         st_ptr->bad_buy = 0;
3492         for (int i = 0; i < st_ptr->stock_num; i++)
3493         {
3494                 object_type *o_ptr;
3495                 o_ptr = &st_ptr->stock[i];
3496                 if (object_is_artifact(o_ptr)) continue;
3497
3498                 o_ptr->discount = 50;
3499                 o_ptr->ident &= ~(IDENT_FIXED);
3500                 o_ptr->inscription = quark_add(_("売出中", "on sale"));
3501         }
3502 }
3503
3504
3505 /*!
3506  * @brief 店の品揃えを変化させる /
3507  * Maintain the inventory at the stores.
3508  * @param player_ptr プレーヤーへの参照ポインタ
3509  * @param town_num 町のID
3510  * @param store_num 店舗種類のID
3511  * @return なし
3512  */
3513 void store_maint(player_type *player_ptr, int town_num, int store_num)
3514 {
3515         cur_store_num = store_num;
3516         if (store_num == STORE_HOME) return;
3517         if (store_num == STORE_MUSEUM) return;
3518
3519         st_ptr = &town_info[town_num].store[store_num];
3520         ot_ptr = &owners[store_num][st_ptr->owner];
3521         st_ptr->insult_cur = 0;
3522         if (store_num == STORE_BLACK)
3523         {
3524                 for (INVENTORY_IDX j = st_ptr->stock_num - 1; j >= 0; j--)
3525                 {
3526                         object_type *o_ptr = &st_ptr->stock[j];
3527                         if (black_market_crap(player_ptr, o_ptr))
3528                         {
3529                                 store_item_increase(j, 0 - o_ptr->number);
3530                                 store_item_optimize(j);
3531                         }
3532                 }
3533         }
3534
3535         INVENTORY_IDX j = st_ptr->stock_num;
3536         j = j - randint1(STORE_TURNOVER);
3537         if (j > STORE_MAX_KEEP) j = STORE_MAX_KEEP;
3538         if (j < STORE_MIN_KEEP) j = STORE_MIN_KEEP;
3539         if (j < 0) j = 0;
3540
3541         while (st_ptr->stock_num > j)
3542                 store_delete();
3543
3544         j = st_ptr->stock_num;
3545         j = j + randint1(STORE_TURNOVER);
3546         if (j > STORE_MAX_KEEP) j = STORE_MAX_KEEP;
3547         if (j < STORE_MIN_KEEP) j = STORE_MIN_KEEP;
3548         if (j >= st_ptr->stock_size) j = st_ptr->stock_size - 1;
3549
3550         while (st_ptr->stock_num < j) store_create(player_ptr);
3551 }
3552
3553
3554 /*!
3555  * @brief 店舗情報を初期化する /
3556  * Initialize the stores
3557  * @param town_num 町のID
3558  * @param store_num 店舗種類のID
3559  * @return なし
3560  */
3561 void store_init(int town_num, int store_num)
3562 {
3563         cur_store_num = store_num;
3564         st_ptr = &town_info[town_num].store[store_num];
3565         while (TRUE)
3566         {
3567                 st_ptr->owner = (byte)randint0(MAX_OWNERS);
3568                 int i;
3569                 for (i = 1; i < max_towns; i++)
3570                 {
3571                         if (i == town_num) continue;
3572                         if (st_ptr->owner == town_info[i].store[store_num].owner) break;
3573                 }
3574
3575                 if (i == max_towns) break;
3576         }
3577
3578         ot_ptr = &owners[store_num][st_ptr->owner];
3579
3580         st_ptr->store_open = 0;
3581         st_ptr->insult_cur = 0;
3582         st_ptr->good_buy = 0;
3583         st_ptr->bad_buy = 0;
3584         st_ptr->stock_num = 0;
3585         st_ptr->last_visit = -10L * TURNS_PER_TICK * STORE_TICKS;
3586         for (int k = 0; k < st_ptr->stock_size; k++)
3587         {
3588                 object_wipe(&st_ptr->stock[k]);
3589         }
3590 }