OSDN Git Service

[Refactor] #37353 プレイヤーの魔法棒使用処理を cmd-zapwand.c/h に分離。 / Separate player's 'zap wand...
[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 "cmd-zapwand.h"
15
16 #define MIN_STOCK 12
17
18 static int cur_store_num = 0;
19 static int store_top = 0;
20 static int store_bottom = 0;
21 static int xtra_stock = 0;
22 static store_type *st_ptr = NULL;
23 static const owner_type *ot_ptr = NULL;
24 static s16b old_town_num = 0;
25 static s16b inner_town_num = 0;
26 #define RUMOR_CHANCE 8
27
28 #define MAX_COMMENT_1   6
29
30 static cptr comment_1[MAX_COMMENT_1] =
31 {
32 #ifdef JP
33         "オーケーだ。",
34         "結構だ。",
35         "そうしよう!",
36         "賛成だ!",
37         "よし!",
38         "わかった!"
39 #else
40         "Okay.",
41         "Fine.",
42         "Accepted!",
43         "Agreed!",
44         "Done!",
45         "Taken!"
46 #endif
47
48 };
49
50 #ifdef JP
51 /*! ブラックマーケット追加メッセージ(承諾) */
52 static cptr comment_1_B[MAX_COMMENT_1] = {
53         "まあ、それでいいや。",
54         "今日はそれで勘弁してやる。",
55         "分かったよ。",
56         "しょうがない。",
57         "それで我慢するよ。",
58         "こんなもんだろう。"
59 };
60 #endif
61 #define MAX_COMMENT_2A  2
62
63 static cptr comment_2a[MAX_COMMENT_2A] =
64 {
65 #ifdef JP
66         "私の忍耐力を試しているのかい? $%s が最後だ。",
67         "我慢にも限度があるぞ。 $%s が最後だ。"
68 #else
69         "You try my patience.  %s is final.",
70         "My patience grows thin.  %s is final."
71 #endif
72
73 };
74
75 #define MAX_COMMENT_2B  12
76
77 static cptr comment_2b[MAX_COMMENT_2B] =
78 {
79 #ifdef JP
80         " $%s ぐらいは出さなきゃダメだよ。",
81         " $%s なら受け取ってもいいが。",
82         "ハ! $%s 以下はないね。",
83         "何て奴だ! $%s 以下はあり得ないぞ。",
84         "それじゃ少なすぎる! $%s は欲しいところだ。",
85         "バカにしている! $%s はもらわないと。",
86         "嘘だろう! $%s でどうだい?",
87         "おいおい! $%s を考えてくれないか?",
88         "1000匹のオークのノミに苦しめられるがいい! $%s だ。",
89         "お前の大切なものに災いあれ! $%s でどうだ。",
90         "モルゴスに賞味されるがいい!本当は $%s なんだろう?",
91         "お前の母親はオーガか! $%s は出すつもりなんだろ?"
92 #else
93         "I can take no less than %s gold pieces.",
94         "I will accept no less than %s gold pieces.",
95         "Ha!  No less than %s gold pieces.",
96         "You knave!  No less than %s gold pieces.",
97         "That's a pittance!  I want %s gold pieces.",
98         "That's an insult!  I want %s gold pieces.",
99         "As if!  How about %s gold pieces?",
100         "My arse!  How about %s gold pieces?",
101         "May the fleas of 1000 orcs molest you!  Try %s gold pieces.",
102         "May your most favourite parts go moldy!  Try %s gold pieces.",
103         "May Morgoth find you tasty!  Perhaps %s gold pieces?",
104         "Your mother was an Ogre!  Perhaps %s gold pieces?"
105 #endif
106
107 };
108
109 #ifdef JP
110 /*! ブラックマーケット用追加メッセージ(売るとき) */
111 static cptr comment_2b_B[MAX_COMMENT_2B] = {
112         "いくら俺様がお人好しとはいえ $%s が限界だね。嫌なら帰りな。",
113         "金がないのかい、あんた?まずは家に帰って $%s 揃えてきな。",
114         "物の価値が分からん奴だな。これは $%s が普通なんだよ。",
115         "俺の付けた値段に文句があるのか? $%s が限界だ。",
116         "ひょっとして新手の冗談かい? $%s 持ってないなら帰りな。",
117         "うちは他の店とは違うんだよ。$%s ぐらいは出しな。",
118         "買う気がないなら帰りな。 $%s だと言っているんだ。",
119         "話にならないね。 $%s くらい持っているんだろ?",
120         "は?なんだそりゃ? $%s の間違いか、ひょっとして?",
121         "出口はあっちだよ。それとも $%s 出せるのかい、あんたに。",
122         "命知らずな奴だな。 $%s 出せば今日の所は勘弁してやるよ。",
123         "うちの店は貧乏人お断りだ。 $%s ぐらい出せないのかい?"
124 };
125 #endif
126 #define MAX_COMMENT_3A  2
127
128 static cptr comment_3a[MAX_COMMENT_3A] =
129 {
130 #ifdef JP
131         "私の忍耐力を試しているのかい? $%s が最後だ。",
132         "我慢にも限度があるぞ。 $%s が最後だ。"
133 #else
134         "You try my patience.  %s is final.",
135         "My patience grows thin.  %s is final."
136 #endif
137
138 };
139
140
141 #define MAX_COMMENT_3B  12
142
143 static cptr comment_3b[MAX_COMMENT_3B] =
144 {
145 #ifdef JP
146         "本音を言うと $%s でいいんだろ?",
147         " $%s でどうだい?",
148         " $%s ぐらいなら出してもいいが。",
149         " $%s 以上払うなんて考えられないね。",
150         "まあ落ちついて。 $%s でどうだい?",
151         "そのガラクタなら $%s で引き取るよ。",
152         "それじゃ高すぎる! $%s がいいとこだろ。",
153         "どうせいらないんだろ! $%s でいいだろ?",
154         "だめだめ! $%s がずっとお似合いだよ。",
155         "バカにしている! $%s がせいぜいだ。",
156         " $%s なら嬉しいところだがなあ。",
157         " $%s 、それ以上はビタ一文出さないよ!"
158 #else
159         "Perhaps %s gold pieces?",
160         "How about %s gold pieces?",
161         "I will pay no more than %s gold pieces.",
162         "I can afford no more than %s gold pieces.",
163         "Be reasonable.  How about %s gold pieces?",
164         "I'll buy it as scrap for %s gold pieces.",
165         "That is too much!  How about %s gold pieces?",
166         "That looks war surplus!  Say %s gold pieces?",
167         "Never!  %s is more like it.",
168         "That's an insult!  %s is more like it.",
169         "%s gold pieces and be thankful for it!",
170         "%s gold pieces and not a copper more!"
171 #endif
172
173 };
174
175 #ifdef JP
176 /*! ブラックマーケット用追加メッセージ(買い取り) */
177 static cptr comment_3b_B[MAX_COMMENT_3B] = {
178         " $%s ってところだね。そのどうしようもないガラクタは。",
179         "この俺が $%s って言っているんだから、その通りにした方が身のためだぞ。",
180         "俺の優しさに甘えるのもいい加減にしておけ。 $%s だ。",
181         "その品なら $%s で売ってくれているがね、常識ある紳士はみんな。",
182         "こりゃまた、がめつい奴だな。いくら俺が温厚とはいえ $%s が限界だ。",
183         " $%s だ。別に俺はそんなガラクタ欲しくはないんだから。",
184         "俺の鑑定額が気に入らないのか? $%s 、嫌なら帰りな。",
185         " $%s で引き取ってやるよ。喜んで受け取りな、貧乏人。",
186         "物の価値が分からん奴は始末におえんな。それは $%s なんだよ。",
187         "そんなに金が欲しいのか、あんた? $%s で満足できんのか?",
188         "入る店間違えてんじゃないのか? $%s で嫌なら他をあたってくれ。",
189         "俺の言い値にケチをつける奴がいるとは! その度胸に免じて $%s だ。"
190 };
191 #endif
192 #define MAX_COMMENT_4A  4
193
194 static cptr comment_4a[MAX_COMMENT_4A] =
195 {
196 #ifdef JP
197         "もうたくさんだ!何度も私をわずらわせないでくれ!",
198         "うがー!一日の我慢の限度を超えている!",
199         "もういい!時間の無駄以外のなにものでもない!",
200         "もうやってられないよ!顔も見たくない!"
201 #else
202         "Enough!  You have abused me once too often!",
203         "Arghhh!  I have had enough abuse for one day!",
204         "That does it!  You shall waste my time no more!",
205         "This is getting nowhere!  I'm going to Londis!"
206 #endif
207
208 };
209
210 #ifdef JP
211 /*! ブラックマーケット用追加メッセージ(怒りの頂点) */
212 static cptr comment_4a_B[MAX_COMMENT_4A] = {
213         "なめやがって!温厚な俺様でも限界があるってことを知れ!",
214         "俺をここまで怒らせて...命があるだけでもありがたいと思え!",
215         "ふざけてるのか!冷やかしなら相手を見てからにしろ!",
216         "いいかげんにしろ!今度こんなまねしたらただじゃおかねえぞ!"
217 };
218 #endif
219 #define MAX_COMMENT_4B  4
220
221 static cptr comment_4b[MAX_COMMENT_4B] =
222 {
223 #ifdef JP
224         "店から出て行け!",
225         "俺の前から消え失せろ!",
226         "どっかに行っちまえ!",
227         "出ろ、出ろ、出て行け!"
228 #else
229         "Leave my store!",
230         "Get out of my sight!",
231         "Begone, you scoundrel!",
232         "Out, out, out!"
233 #endif
234
235 };
236
237 #ifdef JP
238 /*! ブラックマーケット用追加メッセージ(追い出し) */
239 static cptr comment_4b_B[MAX_COMMENT_4B] = {
240         "二度とうちに来るんじゃねえ!!",
241         "とっとと、どっかへ失せろ!!",
242         "今すぐ消え失せろ!!",
243         "出ていけ!出ていけ!!"
244 };
245 #endif
246 #define MAX_COMMENT_5   8
247
248 static cptr comment_5[MAX_COMMENT_5] =
249 {
250 #ifdef JP
251         "考え直してくれ。",
252         "そりゃおかしい!",
253         "もっと真面目に言ってくれ!",
254         "交渉する気があるのかい?",
255         "冷やかしに来たのか!",
256         "悪い冗談だ!",
257         "我慢くらべかい。",
258         "ふーむ、良い天気だ。"
259 #else
260         "Try again.",
261         "Ridiculous!",
262         "You will have to do better than that!",
263         "Do you wish to do business or not?",
264         "You've got to be kidding!",
265         "You'd better be kidding!",
266         "You try my patience.",
267         "Hmmm, nice weather we're having."
268 #endif
269
270 };
271
272 #ifdef JP
273 /*! ブラックマーケット用追加メッセージ(怒り) */
274 static cptr comment_5_B[MAX_COMMENT_5] = {
275         "時間の無駄だな、これは。",
276         "厄介なお客様だな!",
277         "話して分かる相手じゃなさそうだ。",
278         "痛い目にあいたいらしいな!",
279         "なんて強欲な奴だ!",
280         "話にならん輩だ!",
281         "どうしようもない貧乏人だ!",
282         "喧嘩を売っているのか?"
283 };
284 #endif
285 #define MAX_COMMENT_6   4
286
287 static cptr comment_6[MAX_COMMENT_6] =
288 {
289 #ifdef JP
290         "どうやら聞き間違えたらしい。",
291         "失礼、よく聞こえなかったよ。",
292         "すまない、何だって?",
293         "悪い、もう一度言ってくれる?"
294 #else
295         "I must have heard you wrong.",
296         "I'm sorry, I missed that.",
297         "I'm sorry, what was that?",
298         "Sorry, what was that again?"
299 #endif
300
301 };
302
303
304
305 /*!
306  * @brief 取引成功時の店主のメッセージ処理 /
307  * Successful haggle.
308  * @return なし
309  */
310 static void say_comment_1(void)
311 {
312 #ifdef JP
313         /* ブラックマーケットのときは別のメッセージを出す */
314         if ( cur_store_num == STORE_BLACK ) {
315                 msg_print(comment_1_B[randint0(MAX_COMMENT_1)]);
316         }
317         else{
318                 msg_print(comment_1[randint0(MAX_COMMENT_1)]);
319         }
320 #else
321         msg_print(comment_1[randint0(MAX_COMMENT_1)]);
322 #endif
323
324
325         if (one_in_(RUMOR_CHANCE))
326         {
327 #ifdef JP
328                 msg_print("店主は耳うちした:");
329 #else
330                 msg_print("The shopkeeper whispers something into your ear:");
331 #endif
332                 display_rumor(TRUE);
333         }
334 }
335
336
337 /*!
338  * @brief プレイヤーがアイテムを買う時の価格代案メッセージ処理 /
339  * Continue haggling (player is buying)
340  * @param value 店主の提示価格
341  * @param annoyed 店主のいらつき度
342  * @return なし
343  */
344 static void say_comment_2(s32b value, int annoyed)
345 {
346         char    tmp_val[80];
347
348         /* Prepare a string to insert */
349         sprintf(tmp_val, "%ld", (long)value);
350
351         /* Final offer */
352         if (annoyed > 0)
353         {
354                 /* Formatted message */
355                 msg_format(comment_2a[randint0(MAX_COMMENT_2A)], tmp_val);
356         }
357
358         /* Normal offer */
359         else
360         {
361                 /* Formatted message */
362 #ifdef JP
363                 /* ブラックマーケットの時は別のメッセージを出す */
364                 if ( cur_store_num == STORE_BLACK ){
365                         msg_format(comment_2b_B[randint0(MAX_COMMENT_2B)], tmp_val);
366                 }
367                 else{
368                 msg_format(comment_2b[randint0(MAX_COMMENT_2B)], tmp_val);
369         }
370 #else
371                 msg_format(comment_2b[randint0(MAX_COMMENT_2B)], tmp_val);
372 #endif
373
374         }
375 }
376
377
378 /*!
379  * @brief プレイヤーがアイテムを売る時の価格代案メッセージ処理 /
380  * Continue haggling (player is selling)
381  * @param value 店主の提示価格
382  * @param annoyed 店主のいらつき度
383  * @return なし
384  */
385 static void say_comment_3(s32b value, int annoyed)
386 {
387         char    tmp_val[80];
388
389         /* Prepare a string to insert */
390         sprintf(tmp_val, "%ld", (long)value);
391
392         /* Final offer */
393         if (annoyed > 0)
394         {
395                 /* Formatted message */
396                 msg_format(comment_3a[randint0(MAX_COMMENT_3A)], tmp_val);
397         }
398
399         /* Normal offer */
400         else
401         {
402                 /* Formatted message */
403 #ifdef JP
404                 /* ブラックマーケットの時は別のメッセージを出す */
405                 if ( cur_store_num == STORE_BLACK ){
406                         msg_format(comment_3b_B[randint0(MAX_COMMENT_3B)], tmp_val);
407                 }
408                 else{
409                 msg_format(comment_3b[randint0(MAX_COMMENT_3B)], tmp_val);
410         }
411 #else
412                 msg_format(comment_3b[randint0(MAX_COMMENT_3B)], tmp_val);
413 #endif
414
415         }
416 }
417
418
419 /*!
420  * @brief 店主がプレイヤーを追い出す時のメッセージ処理 /
421  * Kick 'da bum out.                                    -RAK-
422  * @return なし
423  */
424 static void say_comment_4(void)
425 {
426 #ifdef JP
427         /* ブラックマーケットの時は別のメッセージを出す */
428         if ( cur_store_num == STORE_BLACK ){
429                 msg_print(comment_4a_B[randint0(MAX_COMMENT_4A)]);
430                 msg_print(comment_4b_B[randint0(MAX_COMMENT_4B)]);
431         }
432         else{
433                 msg_print(comment_4a[randint0(MAX_COMMENT_4A)]);
434                 msg_print(comment_4b[randint0(MAX_COMMENT_4B)]);
435         }
436 #else
437         msg_print(comment_4a[randint0(MAX_COMMENT_4A)]);
438         msg_print(comment_4b[randint0(MAX_COMMENT_4B)]);
439 #endif
440
441 }
442
443
444 /*!
445  * @brief 店主がプレイヤーに取り合わない時のメッセージ処理 /
446  * You are insulting me
447  * @return なし
448  */
449 static void say_comment_5(void)
450 {
451 #ifdef JP
452         /* ブラックマーケットの時は別のメッセージを出す */
453         if ( cur_store_num == STORE_BLACK ){
454                 msg_print(comment_5_B[randint0(MAX_COMMENT_5)]);
455         }
456         else{
457                 msg_print(comment_5[randint0(MAX_COMMENT_5)]);
458         }
459 #else
460         msg_print(comment_5[randint0(MAX_COMMENT_5)]);
461 #endif
462
463 }
464
465
466 /*!
467  * @brief 店主がプレイヤーの提示を理解できなかった時のメッセージ処理 /
468  * That makes no sense.
469  * @return なし
470  */
471 static void say_comment_6(void)
472 {
473         msg_print(comment_6[randint0(MAX_COMMENT_6)]);
474 }
475
476
477 #define MAX_COMMENT_7A  4
478
479 static cptr comment_7a[MAX_COMMENT_7A] =
480 {
481 #ifdef JP
482         "うわああぁぁ!",
483         "なんてこった!",
484         "誰かがむせび泣く声が聞こえる...。",
485         "店主が悔しげにわめいている!"
486 #else
487         "Arrgghh!",
488         "You bastard!",
489         "You hear someone sobbing...",
490         "The shopkeeper howls in agony!"
491 #endif
492
493 };
494
495 #define MAX_COMMENT_7B  4
496
497 static cptr comment_7b[MAX_COMMENT_7B] =
498 {
499 #ifdef JP
500         "くそう!",
501         "この悪魔め!",
502         "店主が恨めしそうに見ている。",
503         "店主が睨んでいる。"
504 #else
505         "Damn!",
506         "You fiend!",
507         "The shopkeeper curses at you.",
508         "The shopkeeper glares at you."
509 #endif
510
511 };
512
513 #define MAX_COMMENT_7C  4
514
515 static cptr comment_7c[MAX_COMMENT_7C] =
516 {
517 #ifdef JP
518         "すばらしい!",
519         "君が天使に見えるよ!",
520         "店主がクスクス笑っている。",
521         "店主が大声で笑っている。"
522 #else
523         "Cool!",
524         "You've made my day!",
525         "The shopkeeper giggles.",
526         "The shopkeeper laughs loudly."
527 #endif
528
529 };
530
531 #define MAX_COMMENT_7D  4
532
533 static cptr comment_7d[MAX_COMMENT_7D] =
534 {
535 #ifdef JP
536         "やっほぅ!",
537         "こんなおいしい思いをしたら、真面目に働けなくなるなぁ。",
538         "店主は嬉しくて跳ね回っている。",
539         "店主は満面に笑みをたたえている。"
540 #else
541         "Yipee!",
542         "I think I'll retire!",
543         "The shopkeeper jumps for joy.",
544         "The shopkeeper smiles gleefully."
545 #endif
546
547 };
548
549
550 /*!
551  * @brief 店主が交渉を終えた際の反応を返す処理 /
552  * Let a shop-keeper React to a purchase
553  * @param price アイテムの取引額
554  * @param value アイテムの実際価値
555  * @param guess 店主が当初予想していた価値
556  * @return なし
557  * @details 
558  * We paid "price", it was worth "value", and we thought it was worth "guess"
559  */
560 static void purchase_analyze(s32b price, s32b value, s32b guess)
561 {
562         /* Item was worthless, but we bought it */
563         if ((value <= 0) && (price > value))
564         {
565                 /* Comment */
566                 msg_print(comment_7a[randint0(MAX_COMMENT_7A)]);
567
568                 chg_virtue(V_HONOUR, -1);
569                 chg_virtue(V_JUSTICE, -1);
570
571                 /* Sound */
572                 sound(SOUND_STORE1);
573         }
574
575         /* Item was cheaper than we thought, and we paid more than necessary */
576         else if ((value < guess) && (price > value))
577         {
578                 /* Comment */
579                 msg_print(comment_7b[randint0(MAX_COMMENT_7B)]);
580
581                 chg_virtue(V_JUSTICE, -1);
582                 if (one_in_(4))
583                         chg_virtue(V_HONOUR, -1);
584
585                 /* Sound */
586                 sound(SOUND_STORE2);
587         }
588
589         /* Item was a good bargain, and we got away with it */
590         else if ((value > guess) && (value < (4 * guess)) && (price < value))
591         {
592                 /* Comment */
593                 msg_print(comment_7c[randint0(MAX_COMMENT_7C)]);
594
595                 if (one_in_(4))
596                         chg_virtue(V_HONOUR, -1);
597                 else if (one_in_(4))
598                         chg_virtue(V_HONOUR, 1);
599
600                 /* Sound */
601                 sound(SOUND_STORE3);
602         }
603
604         /* Item was a great bargain, and we got away with it */
605         else if ((value > guess) && (price < value))
606         {
607                 /* Comment */
608                 msg_print(comment_7d[randint0(MAX_COMMENT_7D)]);
609
610                 if (one_in_(2))
611                         chg_virtue(V_HONOUR, -1);
612                 if (one_in_(4))
613                         chg_virtue(V_HONOUR, 1);
614
615                 if (10 * price < value)
616                         chg_virtue(V_SACRIFICE, 1);
617
618                 /* Sound */
619                 sound(SOUND_STORE4);
620         }
621 }
622
623
624
625 /*
626  * We store the current "store feat" here so everyone can access it
627  */
628 static int cur_store_feat;
629
630
631 /*
632  * Buying and selling adjustments for race combinations.
633  * Entry[owner][player] gives the basic "cost inflation".
634  */
635 static byte rgold_adj[MAX_RACES][MAX_RACES] =
636 {
637         /*Hum, HfE, Elf,  Hal, Gno, Dwa, HfO, HfT, Dun, HiE, Barbarian,
638          HfOg, HGn, HTn, Cyc, Yek, Klc, Kbd, Nbl, DkE, Drc, Mind Flayer,
639          Imp,  Glm, Skl, Zombie, Vampire, Spectre, Fairy, Beastman, Ent,
640          Angel, Demon, Kutar */
641
642         /* Human */
643         { 100, 105, 105, 110, 113, 115, 120, 125, 100, 105, 100,
644           124, 120, 110, 125, 115, 120, 120, 120, 120, 115, 120,
645           115, 105, 125, 125, 125, 125, 105, 120, 105,  95, 140,
646           100, 120, 110, 105 },
647
648         /* Half-Elf */
649         { 110, 100, 100, 105, 110, 120, 125, 130, 110, 100, 110,
650           120, 115, 108, 115, 110, 110, 120, 120, 115, 115, 110,
651           120, 110, 110, 110, 120, 110, 100, 125, 100,  95, 140,
652           110, 115, 110, 110 },
653
654         /* Elf */
655         { 110, 105, 100, 105, 110, 120, 125, 130, 110, 100, 110,
656           120, 120, 105, 120, 110, 105, 125, 125, 110, 115, 108,
657           120, 115, 110, 110, 120, 110, 100, 125, 100,  95, 140,
658           110, 110, 105, 110 },
659
660         /* Halfling */
661         { 115, 110, 105,  95, 105, 110, 115, 130, 115, 105, 115,
662           125, 120, 120, 125, 115, 110, 120, 120, 120, 115, 115,
663           120, 110, 120, 120, 130, 110, 110, 130, 110,  95, 140,
664           115, 120, 105, 115 },
665
666         /* Gnome */
667         { 115, 115, 110, 105,  95, 110, 115, 130, 115, 110, 115,
668           120, 125, 110, 120, 110, 105, 120, 110, 110, 105, 110,
669           120, 101, 110, 110, 120, 120, 115, 130, 115,  95, 140,
670           115, 110, 110, 115 },
671
672         /* Dwarf */
673         { 115, 120, 120, 110, 110,  95, 125, 135, 115, 120, 115,
674           125, 140, 130, 130, 120, 115, 115, 115, 135, 125, 120,
675           120, 105, 115, 115, 115, 115, 120, 130, 120,  95, 140,
676           115, 110, 115, 115 },
677
678         /* Half-Orc */
679         { 115, 120, 125, 115, 115, 130, 110, 115, 115, 125, 115,
680           110, 110, 120, 110, 120, 125, 115, 115, 110, 120, 110,
681           115, 125, 120, 120, 115, 120, 125, 115, 125,  95, 140,
682           115, 110, 115, 115 },
683
684         /* Half-Troll */
685         { 110, 115, 115, 110, 110, 130, 110, 110, 110, 115, 110,
686           110, 115, 120, 110, 120, 120, 110, 110, 110, 115, 110,
687           110, 115, 112, 112, 115, 112, 120, 110, 120,  95, 140,
688           110, 110, 115, 110 },
689
690         /* Amberite */
691         { 100, 105, 105, 110, 113, 115, 120, 125, 100, 105, 100,
692           120, 120, 105, 120, 115, 105, 115, 120, 110, 105, 105,
693           120, 105, 120, 120, 125, 120, 105, 135, 105,  95, 140,
694           100, 110, 110, 100 },
695
696         /* High_Elf */
697         { 110, 105, 100, 105, 110, 120, 125, 130, 110, 100, 110,
698           125, 125, 101, 120, 115, 110, 115, 125, 110, 110, 110,
699           125, 115, 120, 120, 125, 120, 100, 125, 100,  95, 140,
700           110, 110, 105, 110 },
701
702         /* Human / Barbarian (copied from human) */
703         { 100, 105, 105, 110, 113, 115, 120, 125, 100, 105, 100,
704           124, 120, 110, 125, 115, 120, 120, 120, 120, 115, 120,
705           115, 105, 125, 125, 130, 125, 115, 120, 115,  95, 140,
706           100, 120, 110, 100 },
707
708         /* Half-Ogre: theoretical, copied from half-troll */
709         { 110, 115, 115, 110, 110, 130, 110, 110, 110, 115, 110,
710           110, 115, 120, 110, 120, 120, 110, 110, 110, 115, 110,
711           110, 115, 112, 112, 115, 112, 120, 110, 120,  95, 140,
712           110, 110, 115, 110 },
713
714         /* Half-Giant: theoretical, copied from half-troll */
715         { 110, 115, 115, 110, 110, 130, 110, 110, 110, 115, 110,
716           110, 115, 120, 110, 120, 120, 110, 110, 110, 115, 110,
717           110, 115, 112, 112, 115, 112, 130, 120, 130,  95, 140,
718           110, 110, 115, 110 },
719
720         /* Half-Titan: theoretical, copied from High_Elf */
721         { 110, 105, 100, 105, 110, 120, 125, 130, 110, 100, 110,
722           125, 125, 101, 120, 115, 110, 115, 125, 110, 110, 110,
723           125, 115, 120, 120, 120, 120, 130, 130, 130,  95, 140,
724           110, 110, 115, 110 },
725
726         /* Cyclops: theoretical, copied from half-troll */
727         { 110, 115, 115, 110, 110, 130, 110, 110, 110, 115, 110,
728           110, 115, 120, 110, 120, 120, 110, 110, 110, 115, 110,
729           110, 115, 112, 112, 115, 112, 130, 130, 130,  95, 140,
730           110, 110, 115, 110 },
731
732         /* Yeek: theoretical, copied from Half-Orc */
733         { 115, 120, 125, 115, 115, 130, 110, 115, 115, 125, 115,
734           110, 110, 120, 110, 120, 125, 115, 115, 110, 120, 110,
735           115, 125, 120, 120, 120, 120, 130, 130, 130,  95, 140,
736           115, 110, 115, 115 },
737
738         /* Klackon: theoretical, copied from Gnome */
739         { 115, 115, 110, 105,  95, 110, 115, 130, 115, 110, 115,
740           120, 125, 110, 120, 110, 105, 120, 110, 110, 105, 110,
741           120, 101, 110, 110, 120, 120, 130, 130, 130,  95, 140,
742           115, 110, 115, 115 },
743
744         /* Kobold: theoretical, copied from Half-Orc */
745         { 115, 120, 125, 115, 115, 130, 110, 115, 115, 125, 115,
746           110, 110, 120, 110, 120, 125, 115, 115, 110, 120, 110,
747           115, 125, 120, 120, 120, 120, 130, 130, 130,  95, 140,
748           115, 110, 115, 115 },
749
750         /* Nibelung: theoretical, copied from Dwarf */
751         { 115, 120, 120, 110, 110,  95, 125, 135, 115, 120, 115,
752           125, 140, 130, 130, 120, 115, 115, 115, 135, 125, 120,
753           120, 105, 115, 115, 120, 120, 130, 130, 130,  95, 140,
754           115, 135, 115, 115 },
755
756         /* Dark Elf */
757         { 110, 110, 110, 115, 120, 130, 115, 115, 120, 110, 115,
758           115, 115, 116, 115, 120, 120, 115, 115, 101, 110, 110,
759           110, 110, 112, 122, 110, 110, 110, 115, 110, 120, 120,
760           110, 101, 115, 110 },
761
762         /* Draconian: theoretical, copied from High_Elf */
763         { 110, 105, 100, 105, 110, 120, 125, 130, 110, 100, 110,
764           125, 125, 101, 120, 115, 110, 115, 125, 110, 110, 110,
765           125, 115, 120, 120, 120, 120, 130, 130, 130,  95, 140,
766           110, 110, 115, 110 },
767
768         /* Mind Flayer: theoretical, copied from High_Elf */
769         { 110, 105, 100, 105, 110, 120, 125, 130, 110, 100, 110,
770           125, 125, 101, 120, 115, 110, 115, 125, 110, 110, 110,
771           125, 115, 120, 120, 120, 120, 130, 130, 130,  95, 140,
772           110, 110, 115, 110 },
773
774         /* Imp: theoretical, copied from High_Elf */
775         { 110, 105, 100, 105, 110, 120, 125, 130, 110, 100, 110,
776           125, 125, 101, 120, 115, 110, 115, 125, 110, 110, 110,
777           125, 115, 120, 120, 120, 120, 130, 130, 130, 120, 120,
778           110, 110, 115, 110 },
779
780         /* Golem: theoretical, copied from High_Elf */
781         { 110, 105, 100, 105, 110, 120, 125, 130, 110, 100, 110,
782           125, 125, 101, 120, 115, 110, 115, 125, 110, 110, 110,
783           125, 115, 120, 120, 120, 120, 130, 130, 130,  95, 140,
784           110, 110, 115, 110 },
785
786         /* Skeleton: theoretical, copied from half-orc */
787         { 115, 120, 125, 115, 115, 130, 110, 115, 115, 125, 115,
788           110, 110, 120, 110, 120, 125, 115, 115, 110, 120, 110,
789           115, 125, 120, 120, 120, 120, 130, 130, 130, 120, 120,
790           115, 110, 125, 115 },
791
792         /* Zombie: Theoretical, copied from half-orc */
793         { 115, 120, 125, 115, 115, 130, 110, 115, 115, 125, 115,
794           110, 110, 120, 110, 120, 125, 115, 115, 110, 120, 110,
795           115, 125, 120, 120, 120, 120, 130, 130, 130, 120, 120,
796           115, 110, 125, 115 },
797
798         /* Vampire: Theoretical, copied from half-orc */
799         { 115, 120, 125, 115, 115, 130, 110, 115, 115, 125, 115,
800           110, 110, 120, 110, 120, 125, 115, 115, 110, 120, 110,
801           115, 125, 120, 120, 120, 120, 130, 130, 130, 120, 120,
802           115, 110, 125, 115 },
803
804         /* Spectre: Theoretical, copied from half-orc */
805         { 115, 120, 125, 115, 115, 130, 110, 115, 115, 125, 115,
806           110, 110, 120, 110, 120, 125, 115, 115, 110, 120, 110,
807           115, 125, 120, 120, 120, 120, 130, 130, 130, 120, 120,
808           115, 110, 125, 115 },
809
810         /* Sprite: Theoretical, copied from half-orc */
811         { 115, 120, 125, 115, 115, 130, 110, 115, 115, 125, 115,
812           110, 110, 120, 110, 120, 125, 115, 115, 110, 120, 110,
813           115, 125, 120, 120, 120, 120, 130, 130, 130,  95, 140,
814           115, 110, 105, 115 },
815
816         /* Beastman: Theoretical, copied from half-orc */
817         { 115, 120, 125, 115, 115, 130, 110, 115, 115, 125, 115,
818           110, 110, 120, 110, 120, 125, 115, 115, 110, 120, 110,
819           115, 125, 120, 120, 120, 120, 130, 130, 130,  95, 140,
820           115, 110, 115, 115 },
821
822         /* Ent */
823         { 110, 105, 100, 105, 110, 120, 125, 130, 110, 100, 110,
824           120, 120, 105, 120, 110, 105, 125, 125, 110, 115, 108,
825           120, 115, 110, 110, 120, 110, 100, 125, 100,  95, 140,
826           110, 110, 105, 110 },
827
828         /* Angel */
829         {  95,  95,  95,  95,  95,  95,  95,  95,  95,  95,  95,
830            95,  95,  95,  95,  95,  95,  95,  95,  95,  95,  95,
831            95,  95,  95,  95,  95,  95,  95,  95,  95,  95, 160,
832            95,  95,  95,  95 },
833
834         /* Demon */
835         { 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
836           140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
837           140, 140, 140, 140, 140, 140, 140, 140, 140, 160, 120,
838           140, 140, 140, 140 },
839
840         /* Dunadan */
841         { 100, 105, 105, 110, 113, 115, 120, 125, 100, 105, 100,
842           124, 120, 110, 125, 115, 120, 120, 120, 120, 115, 120,
843           115, 105, 125, 125, 125, 125, 105, 120, 105,  95, 140,
844           100, 120, 110, 100 },
845
846         /* Shadow Fairy */
847         { 110, 110, 110, 115, 120, 130, 115, 115, 120, 110, 115,
848           115, 115, 116, 115, 120, 120, 115, 115, 101, 110, 110,
849           110, 110, 112, 122, 110, 110, 110, 115, 110, 120, 120,
850           110, 101, 115, 110 },
851
852         /* Kutar */
853         { 110, 110, 105, 105, 110, 115, 115, 115, 110, 105, 110,
854           115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115,
855           115, 115, 125, 125, 125, 125, 105, 115, 105,  95, 140,
856           110, 115, 100, 110 },
857
858         /* Android */
859         { 105, 105, 105, 110, 113, 115, 120, 125, 100, 105, 100,
860           124, 120, 110, 125, 115, 120, 120, 120, 120, 115, 120,
861           115, 105, 125, 125, 125, 125, 105, 120, 105,  95, 140,
862           100, 120, 110, 100 },
863 };
864
865
866
867 /*!
868  * @brief 店舗価格を決定する /
869  * Determine the price of an item (qty one) in a store.
870  * @param o_ptr 店舗に並べるオブジェクト構造体の参照ポインタ
871  * @param greed 店主の強欲度
872  * @param flip TRUEならば店主にとっての買取価格、FALSEなら売出価格を計算
873  * @return なし
874  * @details 
875  * <pre>
876  * This function takes into account the player's charisma, and the
877  * shop-keepers friendliness, and the shop-keeper's base greed, but
878  * never lets a shop-keeper lose money in a transaction.
879  * The "greed" value should exceed 100 when the player is "buying" the
880  * item, and should be less than 100 when the player is "selling" it.
881  * Hack -- the black market always charges twice as much as it should.
882  * Charisma adjustment runs from 80 to 130
883  * Racial adjustment runs from 95 to 130
884  * Since greed/charisma/racial adjustments are centered at 100, we need
885  * to adjust (by 200) to extract a usable multiplier.  Note that the
886  * "greed" value is always something (?).
887  * </pre>
888  */
889 static s32b price_item(object_type *o_ptr, int greed, bool flip)
890 {
891         int     factor;
892         int     adjust;
893         s32b    price;
894
895
896         /* Get the value of one of the items */
897         price = object_value(o_ptr);
898
899         /* Worthless items */
900         if (price <= 0) return (0L);
901
902
903         /* Compute the racial factor */
904         factor = rgold_adj[ot_ptr->owner_race][p_ptr->prace];
905
906         /* Add in the charisma factor */
907         factor += adj_chr_gold[p_ptr->stat_ind[A_CHR]];
908
909
910         /* Shop is buying */
911         if (flip)
912         {
913                 /* Adjust for greed */
914                 adjust = 100 + (300 - (greed + factor));
915
916                 /* Never get "silly" */
917                 if (adjust > 100) adjust = 100;
918
919                 /* Mega-Hack -- Black market sucks */
920                 if (cur_store_num == STORE_BLACK)
921                         price = price / 2;
922
923                 /* Compute the final price (with rounding) */
924                 /* Hack -- prevent underflow */
925                 price = (price * adjust + 50L) / 100L;
926         }
927
928         /* Shop is selling */
929         else
930         {
931                 /* Adjust for greed */
932                 adjust = 100 + ((greed + factor) - 300);
933
934                 /* Never get "silly" */
935                 if (adjust < 100) adjust = 100;
936
937                 /* Mega-Hack -- Black market sucks */
938                 if (cur_store_num == STORE_BLACK)
939                         price = price * 2;
940
941                 /* Compute the final price (with rounding) */
942                 /* Hack -- prevent overflow */
943                 price = (s32b)(((u32b)price * (u32b)adjust + 50UL) / 100UL);
944         }
945
946         /* Note -- Never become "free" */
947         if (price <= 0L) return (1L);
948
949         /* Return the price */
950         return (price);
951 }
952
953
954 /*!
955  * @brief 安価な消耗品の販売数を増やし、低確率で割引にする /
956  * Certain "cheap" objects should be created in "piles"
957  * @param o_ptr 店舗に並べるオブジェクト構造体の参照ポインタ
958  * @return なし
959  * @details 
960  * <pre>
961  * Some objects can be sold at a "discount" (in small piles)
962  * </pre>
963  */
964 static void mass_produce(object_type *o_ptr)
965 {
966         int size = 1;
967         DISCOUNT_RATE discount = 0;
968
969         s32b cost = object_value(o_ptr);
970
971
972         /* Analyze the type */
973         switch (o_ptr->tval)
974         {
975                 /* Food, Flasks, and Lites */
976                 case TV_FOOD:
977                 case TV_FLASK:
978                 case TV_LITE:
979                 {
980                         if (cost <= 5L) size += damroll(3, 5);
981                         if (cost <= 20L) size += damroll(3, 5);
982                         if (cost <= 50L) size += damroll(2, 2);
983                         break;
984                 }
985
986                 case TV_POTION:
987                 case TV_SCROLL:
988                 {
989                         if (cost <= 60L) size += damroll(3, 5);
990                         if (cost <= 240L) size += damroll(1, 5);
991                         if (o_ptr->sval == SV_SCROLL_STAR_IDENTIFY) size += damroll(3, 5);
992                         if (o_ptr->sval == SV_SCROLL_STAR_REMOVE_CURSE) size += damroll(1, 4);
993                         break;
994                 }
995
996                 case TV_LIFE_BOOK:
997                 case TV_SORCERY_BOOK:
998                 case TV_NATURE_BOOK:
999                 case TV_CHAOS_BOOK:
1000                 case TV_DEATH_BOOK:
1001                 case TV_TRUMP_BOOK:
1002                 case TV_ARCANE_BOOK:
1003                 case TV_CRAFT_BOOK:
1004                 case TV_DAEMON_BOOK:
1005                 case TV_CRUSADE_BOOK:
1006                 case TV_MUSIC_BOOK:
1007                 case TV_HISSATSU_BOOK:
1008                 case TV_HEX_BOOK:
1009                 {
1010                         if (cost <= 50L) size += damroll(2, 3);
1011                         if (cost <= 500L) size += damroll(1, 3);
1012                         break;
1013                 }
1014
1015                 case TV_SOFT_ARMOR:
1016                 case TV_HARD_ARMOR:
1017                 case TV_SHIELD:
1018                 case TV_GLOVES:
1019                 case TV_BOOTS:
1020                 case TV_CLOAK:
1021                 case TV_HELM:
1022                 case TV_CROWN:
1023                 case TV_SWORD:
1024                 case TV_POLEARM:
1025                 case TV_HAFTED:
1026                 case TV_DIGGING:
1027                 case TV_BOW:
1028                 {
1029                         if (object_is_artifact(o_ptr)) break;
1030                         if (object_is_ego(o_ptr)) break;
1031                         if (cost <= 10L) size += damroll(3, 5);
1032                         if (cost <= 100L) size += damroll(3, 5);
1033                         break;
1034                 }
1035
1036                 case TV_SPIKE:
1037                 case TV_SHOT:
1038                 case TV_ARROW:
1039                 case TV_BOLT:
1040                 {
1041                         if (cost <= 5L) size += damroll(5, 5);
1042                         if (cost <= 50L) size += damroll(5, 5);
1043                         if (cost <= 500L) size += damroll(5, 5);
1044                         break;
1045                 }
1046
1047                 case TV_FIGURINE:
1048                 {
1049                         if (cost <= 100L) size += damroll(2, 2);
1050                         if (cost <= 1000L) size += damroll(2, 2);
1051                         break;
1052                 }
1053
1054                 case TV_CAPTURE:
1055                 case TV_STATUE:
1056                 case TV_CARD:
1057                 {
1058                         size = 1;
1059                         break;
1060                 }
1061
1062                 /*
1063                  * Because many rods (and a few wands and staffs) are useful mainly
1064                  * in quantity, the Black Market will occasionally have a bunch of
1065                  * one kind. -LM-
1066                  */
1067                 case TV_ROD:
1068                 case TV_WAND:
1069                 case TV_STAFF:
1070                 {
1071                         if ((cur_store_num == STORE_BLACK) && one_in_(3))
1072                         {
1073                                 if (cost < 1601L) size += damroll(1, 5);
1074                                 else if (cost < 3201L) size += damroll(1, 3);
1075                         }
1076                         break;
1077                 }
1078         }
1079
1080
1081         /* Pick a discount */
1082         if (cost < 5)
1083         {
1084                 discount = 0;
1085         }
1086         else if (one_in_(25))
1087         {
1088                 discount = 25;
1089         }
1090         else if (one_in_(150))
1091         {
1092                 discount = 50;
1093         }
1094         else if (one_in_(300))
1095         {
1096                 discount = 75;
1097         }
1098         else if (one_in_(500))
1099         {
1100                 discount = 90;
1101         }
1102
1103         if (o_ptr->art_name)
1104         {
1105                 discount = 0;
1106         }
1107
1108         /* Save the discount */
1109         o_ptr->discount = discount;
1110
1111         /* Save the total pile size */
1112         o_ptr->number = size - (size * discount / 100);
1113
1114         /* Ensure that mass-produced rods and wands get the correct pvals. */
1115         if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND))
1116         {
1117                 o_ptr->pval *= (PARAMETER_VALUE)o_ptr->number;
1118         }
1119 }
1120
1121
1122
1123 /*!
1124  * @brief 店舗に並べた品を同一品であるかどうか判定する /
1125  * Determine if a store item can "absorb" another item
1126  * @param o_ptr 判定するオブジェクト構造体の参照ポインタ1
1127  * @param j_ptr 判定するオブジェクト構造体の参照ポインタ2
1128  * @return 同一扱いできるならTRUEを返す
1129  * @details 
1130  * <pre>
1131  * See "object_similar()" for the same function for the "player"
1132  * </pre>
1133  */
1134 static bool store_object_similar(object_type *o_ptr, object_type *j_ptr)
1135 {
1136         int i;
1137
1138         /* Hack -- Identical items cannot be stacked */
1139         if (o_ptr == j_ptr) return (0);
1140
1141         /* Different objects cannot be stacked */
1142         if (o_ptr->k_idx != j_ptr->k_idx) return (0);
1143
1144         /* Different charges (etc) cannot be stacked, unless wands or rods. */
1145         if ((o_ptr->pval != j_ptr->pval) && (o_ptr->tval != TV_WAND) && (o_ptr->tval != TV_ROD)) return (0);
1146
1147         /* Require many identical values */
1148         if (o_ptr->to_h != j_ptr->to_h) return (0);
1149         if (o_ptr->to_d != j_ptr->to_d) return (0);
1150         if (o_ptr->to_a != j_ptr->to_a) return (0);
1151
1152         /* Require identical "ego-item" names */
1153         if (o_ptr->name2 != j_ptr->name2) return (0);
1154
1155         /* Artifacts don't stack! */
1156         if (object_is_artifact(o_ptr) || object_is_artifact(j_ptr)) return (0);
1157
1158         /* Hack -- Identical art_flags! */
1159         for (i = 0; i < TR_FLAG_SIZE; i++)
1160                 if (o_ptr->art_flags[i] != j_ptr->art_flags[i]) return (0);
1161
1162         /* Hack -- Never stack "powerful" items */
1163         if (o_ptr->xtra1 || j_ptr->xtra1) return (0);
1164
1165         /* Hack -- Never stack recharging items */
1166         if (o_ptr->timeout || j_ptr->timeout) return (0);
1167
1168         /* Require many identical values */
1169         if (o_ptr->ac != j_ptr->ac)   return (0);
1170         if (o_ptr->dd != j_ptr->dd)   return (0);
1171         if (o_ptr->ds != j_ptr->ds)   return (0);
1172
1173         /* Hack -- Never stack chests */
1174         if (o_ptr->tval == TV_CHEST) return (0);
1175         if (o_ptr->tval == TV_STATUE) return (0);
1176         if (o_ptr->tval == TV_CAPTURE) return (0);
1177
1178         /* Require matching discounts */
1179         if (o_ptr->discount != j_ptr->discount) return (0);
1180
1181         /* They match, so they must be similar */
1182         return (TRUE);
1183 }
1184
1185
1186 /*!
1187  * @brief 店舗に並べた品を重ね合わせできるかどうか判定する /
1188  * Allow a store item to absorb another item
1189  * @param o_ptr 判定するオブジェクト構造体の参照ポインタ1
1190  * @param j_ptr 判定するオブジェクト構造体の参照ポインタ2
1191  * @return 重ね合わせできるならTRUEを返す
1192  * @details 
1193  * <pre>
1194  * See "object_similar()" for the same function for the "player"
1195  * </pre>
1196  */
1197 static void store_object_absorb(object_type *o_ptr, object_type *j_ptr)
1198 {
1199         int max_num = (o_ptr->tval == TV_ROD) ?
1200                 MIN(99, MAX_SHORT / k_info[o_ptr->k_idx].pval) : 99;
1201         int total = o_ptr->number + j_ptr->number;
1202         int diff = (total > max_num) ? total - max_num : 0;
1203
1204         /* Combine quantity, lose excess items */
1205         o_ptr->number = (total > max_num) ? max_num : total;
1206
1207         /* Hack -- if rods are stacking, add the pvals (maximum timeouts) together. -LM- */
1208         if (o_ptr->tval == TV_ROD)
1209         {
1210                 o_ptr->pval += j_ptr->pval * (j_ptr->number - diff) / j_ptr->number;
1211         }
1212
1213         /* Hack -- if wands are stacking, combine the charges. -LM- */
1214         if (o_ptr->tval == TV_WAND)
1215         {
1216                 o_ptr->pval += j_ptr->pval * (j_ptr->number - diff) / j_ptr->number;
1217         }
1218 }
1219
1220
1221 /*!
1222  * @brief 店舗に品を置くスペースがあるかどうかの判定を返す /
1223  * Check to see if the shop will be carrying too many objects   -RAK-
1224  * @param o_ptr 店舗に置きたいオブジェクト構造体の参照ポインタ
1225  * @return 置き場がないなら0、重ね合わせできるアイテムがあるなら-1、スペースがあるなら1を返す。
1226  * @details 
1227  * <pre>
1228  * Note that the shop, just like a player, will not accept things
1229  * it cannot hold.      Before, one could "nuke" potions this way.
1230  * Return value is now int:
1231  *  0 : No space
1232  * -1 : Can be combined to existing slot.
1233  *  1 : Cannot be combined but there are empty spaces.
1234  * </pre>
1235  */
1236 static int store_check_num(object_type *o_ptr)
1237 {
1238         int        i;
1239         object_type *j_ptr;
1240
1241         /* The "home" acts like the player */
1242         if ((cur_store_num == STORE_HOME) || (cur_store_num == STORE_MUSEUM))
1243         {
1244                 bool old_stack_force_notes = stack_force_notes;
1245                 bool old_stack_force_costs = stack_force_costs;
1246
1247                 if (cur_store_num != STORE_HOME)
1248                 {
1249                         stack_force_notes = FALSE;
1250                         stack_force_costs = FALSE;
1251                 }
1252
1253                 /* Check all the items */
1254                 for (i = 0; i < st_ptr->stock_num; i++)
1255                 {
1256                         /* Get the existing item */
1257                         j_ptr = &st_ptr->stock[i];
1258
1259                         /* Can the new object be combined with the old one? */
1260                         if (object_similar(j_ptr, o_ptr))
1261                         {
1262                                 if (cur_store_num != STORE_HOME)
1263                                 {
1264                                         stack_force_notes = old_stack_force_notes;
1265                                         stack_force_costs = old_stack_force_costs;
1266                                 }
1267
1268                                 return -1;
1269                         }
1270                 }
1271
1272                 if (cur_store_num != STORE_HOME)
1273                 {
1274                         stack_force_notes = old_stack_force_notes;
1275                         stack_force_costs = old_stack_force_costs;
1276                 }
1277         }
1278
1279         /* Normal stores do special stuff */
1280         else
1281         {
1282                 /* Check all the items */
1283                 for (i = 0; i < st_ptr->stock_num; i++)
1284                 {
1285                         /* Get the existing item */
1286                         j_ptr = &st_ptr->stock[i];
1287
1288                         /* Can the new object be combined with the old one? */
1289                         if (store_object_similar(j_ptr, o_ptr)) return -1;
1290                 }
1291         }
1292
1293         /* Free space is always usable */
1294         /*
1295          * オプション powerup_home が設定されていると
1296          * 我が家が 20 ページまで使える
1297          */
1298         if ((cur_store_num == STORE_HOME) && ( powerup_home == FALSE )) {
1299                 if (st_ptr->stock_num < ((st_ptr->stock_size) / 10)) {
1300                         return 1;
1301                 }
1302         }
1303         else{
1304                 if (st_ptr->stock_num < st_ptr->stock_size) {
1305                         return 1;
1306                 }
1307         }
1308
1309         /* But there was no room at the inn... */
1310         return 0;
1311 }
1312
1313 /*!
1314  * @brief オブジェクトが祝福されているかの判定を返す /
1315  * @param o_ptr 判定したいオブジェクト構造体の参照ポインタ
1316  * @return アイテムが祝福されたアイテムならばTRUEを返す
1317  */
1318 static bool is_blessed(object_type *o_ptr)
1319 {
1320         u32b flgs[TR_FLAG_SIZE];
1321         object_flags(o_ptr, flgs);
1322         if (have_flag(flgs, TR_BLESSED)) return (TRUE);
1323         else return (FALSE);
1324 }
1325
1326
1327
1328 /*!
1329  * @brief オブジェクトが所定の店舗で引き取れるかどうかを返す /
1330  * Determine if the current store will purchase the given item
1331  * @param o_ptr 判定したいオブジェクト構造体の参照ポインタ
1332  * @return アイテムが買い取れるならばTRUEを返す
1333  * @note
1334  * Note that a shop-keeper must refuse to buy "worthless" items
1335  */
1336 static bool store_will_buy(object_type *o_ptr)
1337 {
1338         /* Hack -- The Home is simple */
1339         if ((cur_store_num == STORE_HOME) || (cur_store_num == STORE_MUSEUM)) return (TRUE);
1340
1341         /* Switch on the store */
1342         switch (cur_store_num)
1343         {
1344                 /* General Store */
1345                 case STORE_GENERAL:
1346                 {
1347                         /* Analyze the type */
1348                         switch (o_ptr->tval)
1349                         {
1350                                 case TV_POTION:
1351                                         if (o_ptr->sval != SV_POTION_WATER) return FALSE;
1352
1353                                 case TV_WHISTLE:
1354                                 case TV_FOOD:
1355                                 case TV_LITE:
1356                                 case TV_FLASK:
1357                                 case TV_SPIKE:
1358                                 case TV_SHOT:
1359                                 case TV_ARROW:
1360                                 case TV_BOLT:
1361                                 case TV_DIGGING:
1362                                 case TV_CLOAK:
1363                                 case TV_BOTTLE: /* 'Green', recycling Angband */
1364                                 case TV_FIGURINE:
1365                                 case TV_STATUE:
1366                                 case TV_CAPTURE:
1367                                 case TV_CARD:
1368                                 break;
1369                                 default:
1370                                 return (FALSE);
1371                         }
1372                         break;
1373                 }
1374
1375                 /* Armoury */
1376                 case STORE_ARMOURY:
1377                 {
1378                         /* Analyze the type */
1379                         switch (o_ptr->tval)
1380                         {
1381                                 case TV_BOOTS:
1382                                 case TV_GLOVES:
1383                                 case TV_CROWN:
1384                                 case TV_HELM:
1385                                 case TV_SHIELD:
1386                                 case TV_CLOAK:
1387                                 case TV_SOFT_ARMOR:
1388                                 case TV_HARD_ARMOR:
1389                                 case TV_DRAG_ARMOR:
1390                                 break;
1391                                 default:
1392                                 return (FALSE);
1393                         }
1394                         break;
1395                 }
1396
1397                 /* Weapon Shop */
1398                 case STORE_WEAPON:
1399                 {
1400                         /* Analyze the type */
1401                         switch (o_ptr->tval)
1402                         {
1403                                 case TV_SHOT:
1404                                 case TV_BOLT:
1405                                 case TV_ARROW:
1406                                 case TV_BOW:
1407                                 case TV_DIGGING:
1408                                 case TV_POLEARM:
1409                                 case TV_SWORD:
1410                                 case TV_HISSATSU_BOOK:
1411                                 break;
1412                                 case TV_HAFTED:
1413                                 {
1414                                         if(o_ptr->sval == SV_WIZSTAFF) return (FALSE);
1415                                 }
1416                                 break;
1417                                 default:
1418                                 return (FALSE);
1419                         }
1420                         break;
1421                 }
1422
1423                 /* Temple */
1424                 case STORE_TEMPLE:
1425                 {
1426                         /* Analyze the type */
1427                         switch (o_ptr->tval)
1428                         {
1429                                 case TV_LIFE_BOOK:
1430                                 case TV_CRUSADE_BOOK:
1431                                 case TV_SCROLL:
1432                                 case TV_POTION:
1433                                 case TV_HAFTED:
1434                                 {
1435                                         break;
1436                                 }
1437                                 case TV_FIGURINE:
1438                                 case TV_STATUE:
1439                                 {
1440                                         monster_race *r_ptr = &r_info[o_ptr->pval];
1441
1442                                         /* Decline evil */
1443                                         if (!(r_ptr->flags3 & RF3_EVIL))
1444                                         {
1445                                                 /* Accept good */
1446                                                 if (r_ptr->flags3 & RF3_GOOD) break;
1447
1448                                                 /* Accept animals */
1449                                                 if (r_ptr->flags3 & RF3_ANIMAL) break;
1450
1451                                                 /* Accept mimics */
1452                                                 if (my_strchr("?!", r_ptr->d_char)) break;
1453                                         }
1454                                 }
1455                                 case TV_POLEARM:
1456                                 case TV_SWORD:
1457                                 {
1458                                         if (is_blessed(o_ptr)) break;
1459                                 }
1460                                 default:
1461                                 return (FALSE);
1462                         }
1463                         break;
1464                 }
1465
1466                 /* Alchemist */
1467                 case STORE_ALCHEMIST:
1468                 {
1469                         /* Analyze the type */
1470                         switch (o_ptr->tval)
1471                         {
1472                                 case TV_SCROLL:
1473                                 case TV_POTION:
1474                                 break;
1475                                 default:
1476                                 return (FALSE);
1477                         }
1478                         break;
1479                 }
1480
1481                 /* Magic Shop */
1482                 case STORE_MAGIC:
1483                 {
1484                         /* Analyze the type */
1485                         switch (o_ptr->tval)
1486                         {
1487                                 case TV_SORCERY_BOOK:
1488                                 case TV_NATURE_BOOK:
1489                                 case TV_CHAOS_BOOK:
1490                                 case TV_DEATH_BOOK:
1491                                 case TV_TRUMP_BOOK:
1492                                 case TV_ARCANE_BOOK:
1493                                 case TV_CRAFT_BOOK:
1494                                 case TV_DAEMON_BOOK:
1495                                 case TV_MUSIC_BOOK:
1496                                 case TV_HEX_BOOK:
1497                                 case TV_AMULET:
1498                                 case TV_RING:
1499                                 case TV_STAFF:
1500                                 case TV_WAND:
1501                                 case TV_ROD:
1502                                 case TV_SCROLL:
1503                                 case TV_POTION:
1504                                 case TV_FIGURINE:
1505                                 break;
1506                                 case TV_HAFTED:
1507                                 {
1508                                         if(o_ptr->sval == SV_WIZSTAFF) break;
1509                                         else return (FALSE);
1510                                 }
1511                                 default:
1512                                 return (FALSE);
1513                         }
1514                         break;
1515                 }
1516                 /* Bookstore Shop */
1517                 case STORE_BOOK:
1518                 {
1519                         /* Analyze the type */
1520                         switch (o_ptr->tval)
1521                         {
1522                                 case TV_SORCERY_BOOK:
1523                                 case TV_NATURE_BOOK:
1524                                 case TV_CHAOS_BOOK:
1525                                 case TV_DEATH_BOOK:
1526                                 case TV_LIFE_BOOK:
1527                                 case TV_TRUMP_BOOK:
1528                                 case TV_ARCANE_BOOK:
1529                                 case TV_CRAFT_BOOK:
1530                                 case TV_DAEMON_BOOK:
1531                                 case TV_CRUSADE_BOOK:
1532                                 case TV_MUSIC_BOOK:
1533                                 case TV_HEX_BOOK:
1534                                         break;
1535                                 default:
1536                                         return (FALSE);
1537                         }
1538                         break;
1539                 }
1540         }
1541
1542         /* XXX XXX XXX Ignore "worthless" items */
1543         if (object_value(o_ptr) <= 0) return (FALSE);
1544
1545         /* Assume okay */
1546         return (TRUE);
1547 }
1548
1549
1550 /*!
1551  * @brief 現在の町の指定された店舗のアイテムを整理する /
1552  * Combine and reorder items in store.
1553  * @param store_num 店舗ID
1554  * @return 実際に整理が行われたならばTRUEを返す。
1555  */
1556 bool combine_and_reorder_home(int store_num)
1557 {
1558         int         i, j, k;
1559         s32b        o_value;
1560         object_type forge, *o_ptr, *j_ptr;
1561         bool        flag = FALSE, combined;
1562         store_type  *old_st_ptr = st_ptr;
1563         bool        old_stack_force_notes = stack_force_notes;
1564         bool        old_stack_force_costs = stack_force_costs;
1565
1566         st_ptr = &town[1].store[store_num];
1567         if (store_num != STORE_HOME)
1568         {
1569                 stack_force_notes = FALSE;
1570                 stack_force_costs = FALSE;
1571         }
1572
1573         do
1574         {
1575                 combined = FALSE;
1576
1577                 /* Combine the items in the home (backwards) */
1578                 for (i = st_ptr->stock_num - 1; i > 0; i--)
1579                 {
1580                         /* Get the item */
1581                         o_ptr = &st_ptr->stock[i];
1582
1583                         /* Skip empty items */
1584                         if (!o_ptr->k_idx) continue;
1585
1586                         /* Scan the items above that item */
1587                         for (j = 0; j < i; j++)
1588                         {
1589                                 int max_num;
1590
1591                                 /* Get the item */
1592                                 j_ptr = &st_ptr->stock[j];
1593
1594                                 /* Skip empty items */
1595                                 if (!j_ptr->k_idx) continue;
1596
1597                                 /*
1598                                  * Get maximum number of the stack if these
1599                                  * are similar, get zero otherwise.
1600                                  */
1601                                 max_num = object_similar_part(j_ptr, o_ptr);
1602
1603                                 /* Can we (partialy) drop "o_ptr" onto "j_ptr"? */
1604                                 if (max_num && j_ptr->number < max_num)
1605                                 {
1606                                         if (o_ptr->number + j_ptr->number <= max_num)
1607                                         {
1608                                                 /* Add together the item counts */
1609                                                 object_absorb(j_ptr, o_ptr);
1610
1611                                                 /* One object is gone */
1612                                                 st_ptr->stock_num--;
1613
1614                                                 /* Slide everything down */
1615                                                 for (k = i; k < st_ptr->stock_num; k++)
1616                                                 {
1617                                                         /* Structure copy */
1618                                                         st_ptr->stock[k] = st_ptr->stock[k + 1];
1619                                                 }
1620
1621                                                 /* Erase the "final" slot */
1622                                                 object_wipe(&st_ptr->stock[k]);
1623                                         }
1624                                         else
1625                                         {
1626                                                 ITEM_NUMBER old_num = o_ptr->number;
1627                                                 ITEM_NUMBER remain = j_ptr->number + o_ptr->number - max_num;
1628
1629                                                 /* Add together the item counts */
1630                                                 object_absorb(j_ptr, o_ptr);
1631
1632                                                 o_ptr->number = remain;
1633
1634                                                 /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
1635                                                 if (o_ptr->tval == TV_ROD)
1636                                                 {
1637                                                         o_ptr->pval =  o_ptr->pval * remain / old_num;
1638                                                         o_ptr->timeout = o_ptr->timeout * remain / old_num;
1639                                                 }
1640
1641                                                 /* Hack -- if wands are stacking, combine the charges. -LM- */
1642                                                 else if (o_ptr->tval == TV_WAND)
1643                                                 {
1644                                                         o_ptr->pval = o_ptr->pval * remain / old_num;
1645                                                 }
1646                                         }
1647
1648                                         /* Take note */
1649                                         combined = TRUE;
1650
1651                                         /* Done */
1652                                         break;
1653                                 }
1654                         }
1655                 }
1656
1657                 flag |= combined;
1658         }
1659         while (combined);
1660
1661         /* Re-order the items in the home (forwards) */
1662         for (i = 0; i < st_ptr->stock_num; i++)
1663         {
1664                 /* Get the item */
1665                 o_ptr = &st_ptr->stock[i];
1666
1667                 /* Skip empty slots */
1668                 if (!o_ptr->k_idx) continue;
1669
1670                 /* Get the "value" of the item */
1671                 o_value = object_value(o_ptr);
1672
1673                 /* Scan every occupied slot */
1674                 for (j = 0; j < st_ptr->stock_num; j++)
1675                 {
1676                         if (object_sort_comp(o_ptr, o_value, &st_ptr->stock[j])) break;
1677                 }
1678
1679                 /* Never move down */
1680                 if (j >= i) continue;
1681
1682                 /* Take note */
1683                 flag = TRUE;
1684
1685                 /* Get local object */
1686                 j_ptr = &forge;
1687
1688                 /* Save a copy of the moving item */
1689                 object_copy(j_ptr, &st_ptr->stock[i]);
1690
1691                 /* Slide the objects */
1692                 for (k = i; k > j; k--)
1693                 {
1694                         /* Slide the item */
1695                         object_copy(&st_ptr->stock[k], &st_ptr->stock[k - 1]);
1696                 }
1697
1698                 /* Insert the moving item */
1699                 object_copy(&st_ptr->stock[j], j_ptr);
1700         }
1701
1702         st_ptr = old_st_ptr;
1703         if (store_num != STORE_HOME)
1704         {
1705                 stack_force_notes = old_stack_force_notes;
1706                 stack_force_costs = old_stack_force_costs;
1707         }
1708
1709         return flag;
1710 }
1711
1712
1713 /*!
1714  * @brief 我が家にオブジェクトを加える /
1715  * Add the item "o_ptr" to the inventory of the "Home"
1716  * @param o_ptr 加えたいオブジェクトの構造体参照ポインタ
1717  * @return 収めた先のID
1718  * @details
1719  * <pre>
1720  * In all cases, return the slot (or -1) where the object was placed
1721  * Note that this is a hacked up version of "inven_carry()".
1722  * Also note that it may not correctly "adapt" to "knowledge" bacoming
1723  * known, the player may have to pick stuff up and drop it again.
1724  * </pre>
1725  */
1726 static int home_carry(object_type *o_ptr)
1727 {
1728         int                             slot;
1729         s32b                       value;
1730         int     i;
1731         object_type *j_ptr;
1732         bool old_stack_force_notes = stack_force_notes;
1733         bool old_stack_force_costs = stack_force_costs;
1734
1735         if (cur_store_num != STORE_HOME)
1736         {
1737                 stack_force_notes = FALSE;
1738                 stack_force_costs = FALSE;
1739         }
1740
1741         /* Check each existing item (try to combine) */
1742         for (slot = 0; slot < st_ptr->stock_num; slot++)
1743         {
1744                 /* Get the existing item */
1745                 j_ptr = &st_ptr->stock[slot];
1746
1747                 /* The home acts just like the player */
1748                 if (object_similar(j_ptr, o_ptr))
1749                 {
1750                         /* Save the new number of items */
1751                         object_absorb(j_ptr, o_ptr);
1752
1753                         if (cur_store_num != STORE_HOME)
1754                         {
1755                                 stack_force_notes = old_stack_force_notes;
1756                                 stack_force_costs = old_stack_force_costs;
1757                         }
1758
1759                         /* All done */
1760                         return (slot);
1761                 }
1762         }
1763
1764         if (cur_store_num != STORE_HOME)
1765         {
1766                 stack_force_notes = old_stack_force_notes;
1767                 stack_force_costs = old_stack_force_costs;
1768         }
1769
1770         /* No space? */
1771         /*
1772          * 隠し機能: オプション powerup_home が設定されていると
1773          *           我が家が 20 ページまで使える
1774          */
1775         /* No space? */
1776         if ((cur_store_num != STORE_HOME) || (powerup_home == TRUE)) {
1777                 if (st_ptr->stock_num >= st_ptr->stock_size) {
1778                         return (-1);
1779                 }
1780         }
1781         else{
1782                 if (st_ptr->stock_num >= ((st_ptr->stock_size) / 10)) {
1783                         return (-1);
1784                 }
1785         }
1786
1787
1788         /* Determine the "value" of the item */
1789         value = object_value(o_ptr);
1790
1791         /* Check existing slots to see if we must "slide" */
1792         for (slot = 0; slot < st_ptr->stock_num; slot++)
1793         {
1794                 if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
1795         }
1796
1797         /* Slide the others up */
1798         for (i = st_ptr->stock_num; i > slot; i--)
1799         {
1800                 st_ptr->stock[i] = st_ptr->stock[i-1];
1801         }
1802
1803         /* More stuff now */
1804         st_ptr->stock_num++;
1805
1806         /* Insert the new item */
1807         st_ptr->stock[slot] = *o_ptr;
1808
1809         chg_virtue(V_SACRIFICE, -1);
1810
1811         (void)combine_and_reorder_home(cur_store_num);
1812
1813         /* Return the location */
1814         return (slot);
1815 }
1816
1817
1818 /*!
1819  * @brief 店舗にオブジェクトを加える /
1820  * Add the item "o_ptr" to a real stores inventory.
1821  * @param o_ptr 加えたいオブジェクトの構造体参照ポインタ
1822  * @return 収めた先のID
1823  * @details
1824  * <pre>
1825  * In all cases, return the slot (or -1) where the object was placed
1826  * Note that this is a hacked up version of "inven_carry()".
1827  * Also note that it may not correctly "adapt" to "knowledge" bacoming
1828  * known, the player may have to pick stuff up and drop it again.
1829  * </pre>
1830  */
1831 static int store_carry(object_type *o_ptr)
1832 {
1833         int     i, slot;
1834         s32b    value, j_value;
1835         object_type *j_ptr;
1836
1837
1838         /* Evaluate the object */
1839         value = object_value(o_ptr);
1840
1841         /* Cursed/Worthless items "disappear" when sold */
1842         if (value <= 0) return (-1);
1843
1844         /* All store items are fully *identified* */
1845         o_ptr->ident |= IDENT_MENTAL;
1846
1847         /* Erase the inscription */
1848         o_ptr->inscription = 0;
1849
1850         /* Erase the "feeling" */
1851         o_ptr->feeling = FEEL_NONE;
1852
1853         /* Check each existing item (try to combine) */
1854         for (slot = 0; slot < st_ptr->stock_num; slot++)
1855         {
1856                 /* Get the existing item */
1857                 j_ptr = &st_ptr->stock[slot];
1858
1859                 /* Can the existing items be incremented? */
1860                 if (store_object_similar(j_ptr, o_ptr))
1861                 {
1862                         /* Hack -- extra items disappear */
1863                         store_object_absorb(j_ptr, o_ptr);
1864
1865                         /* All done */
1866                         return (slot);
1867                 }
1868         }
1869
1870         /* No space? */
1871         if (st_ptr->stock_num >= st_ptr->stock_size) return (-1);
1872
1873
1874         /* Check existing slots to see if we must "slide" */
1875         for (slot = 0; slot < st_ptr->stock_num; slot++)
1876         {
1877                 /* Get that item */
1878                 j_ptr = &st_ptr->stock[slot];
1879
1880                 /* Objects sort by decreasing type */
1881                 if (o_ptr->tval > j_ptr->tval) break;
1882                 if (o_ptr->tval < j_ptr->tval) continue;
1883
1884                 /* Objects sort by increasing sval */
1885                 if (o_ptr->sval < j_ptr->sval) break;
1886                 if (o_ptr->sval > j_ptr->sval) continue;
1887
1888                 /*
1889                  * Hack:  otherwise identical rods sort by
1890                  * increasing recharge time --dsb
1891                  */
1892                 if (o_ptr->tval == TV_ROD)
1893                 {
1894                         if (o_ptr->pval < j_ptr->pval) break;
1895                         if (o_ptr->pval > j_ptr->pval) continue;
1896                 }
1897
1898                 /* Evaluate that slot */
1899                 j_value = object_value(j_ptr);
1900
1901                 /* Objects sort by decreasing value */
1902                 if (value > j_value) break;
1903                 if (value < j_value) continue;
1904         }
1905
1906         /* Slide the others up */
1907         for (i = st_ptr->stock_num; i > slot; i--)
1908         {
1909                 st_ptr->stock[i] = st_ptr->stock[i-1];
1910         }
1911
1912         /* More stuff now */
1913         st_ptr->stock_num++;
1914
1915         /* Insert the new item */
1916         st_ptr->stock[slot] = *o_ptr;
1917
1918         /* Return the location */
1919         return (slot);
1920 }
1921
1922
1923 /*!
1924  * @brief 店舗のオブジェクト数を増やす /
1925  * Add the item "o_ptr" to a real stores inventory.
1926  * @param item 増やしたいアイテムのID
1927  * @param num 増やしたい数
1928  * @return なし
1929  * @details
1930  * <pre>
1931  * Increase, by a given amount, the number of a certain item
1932  * in a certain store.  This can result in zero items.
1933  * </pre>
1934  * @todo numは本来ITEM_NUMBER型にしたい。
1935  */
1936 static void store_item_increase(int item, int num)
1937 {
1938         int             cnt;
1939         object_type *o_ptr;
1940
1941         /* Get the item */
1942         o_ptr = &st_ptr->stock[item];
1943
1944         /* Verify the number */
1945         cnt = o_ptr->number + num;
1946         if (cnt > 255) cnt = 255;
1947         else if (cnt < 0) cnt = 0;
1948         num = cnt - o_ptr->number;
1949
1950         /* Save the new number */
1951         o_ptr->number += (ITEM_NUMBER)num;
1952 }
1953
1954
1955 /*!
1956  * @brief 店舗のオブジェクト数を削除する /
1957  * Remove a slot if it is empty
1958  * @param item 削除したいアイテムのID
1959  * @return なし
1960  */
1961 static void store_item_optimize(int item)
1962 {
1963         int             j;
1964         object_type *o_ptr;
1965
1966         /* Get the item */
1967         o_ptr = &st_ptr->stock[item];
1968
1969         /* Must exist */
1970         if (!o_ptr->k_idx) return;
1971
1972         /* Must have no items */
1973         if (o_ptr->number) return;
1974
1975         /* One less item */
1976         st_ptr->stock_num--;
1977
1978         /* Slide everyone */
1979         for (j = item; j < st_ptr->stock_num; j++)
1980         {
1981                 st_ptr->stock[j] = st_ptr->stock[j + 1];
1982         }
1983
1984         /* Nuke the final slot */
1985         object_wipe(&st_ptr->stock[j]);
1986 }
1987
1988 /*!
1989  * @brief ブラックマーケット用の無価値品の排除判定 /
1990  * This function will keep 'crap' out of the black market.
1991  * @param o_ptr 判定したいオブジェクトの構造体参照ポインタ
1992  * @return ブラックマーケットにとって無価値な品ならばTRUEを返す
1993  * @details
1994  * <pre>
1995  * Crap is defined as any item that is "available" elsewhere
1996  * Based on a suggestion by "Lee Vogt" <lvogt@cig.mcel.mot.com>
1997  * </pre>
1998  */
1999 static bool black_market_crap(object_type *o_ptr)
2000 {
2001         int     i, j;
2002
2003         /* Ego items are never crap */
2004         if (object_is_ego(o_ptr)) return (FALSE);
2005
2006         /* Good items are never crap */
2007         if (o_ptr->to_a > 0) return (FALSE);
2008         if (o_ptr->to_h > 0) return (FALSE);
2009         if (o_ptr->to_d > 0) return (FALSE);
2010
2011         /* Check all stores */
2012         for (i = 0; i < MAX_STORES; i++)
2013         {
2014                 if (i == STORE_HOME) continue;
2015                 if (i == STORE_MUSEUM) continue;
2016
2017                 /* Check every item in the store */
2018                 for (j = 0; j < town[p_ptr->town_num].store[i].stock_num; j++)
2019                 {
2020                         object_type *j_ptr = &town[p_ptr->town_num].store[i].stock[j];
2021
2022                         /* Duplicate item "type", assume crappy */
2023                         if (o_ptr->k_idx == j_ptr->k_idx) return (TRUE);
2024                 }
2025         }
2026
2027         /* Assume okay */
2028         return (FALSE);
2029 }
2030
2031
2032 /*!
2033  * @brief 店舗の品揃え変化のためにアイテムを削除する /
2034  * Attempt to delete (some of) a random item from the store
2035  * @return なし
2036  * @details
2037  * <pre>
2038  * Hack -- we attempt to "maintain" piles of items when possible.
2039  * </pre>
2040  */
2041 static void store_delete(void)
2042 {
2043         int what, num;
2044
2045         /* Pick a random slot */
2046         what = randint0(st_ptr->stock_num);
2047
2048         /* Determine how many items are here */
2049         num = st_ptr->stock[what].number;
2050
2051         /* Hack -- sometimes, only destroy half the items */
2052         if (randint0(100) < 50) num = (num + 1) / 2;
2053
2054         /* Hack -- sometimes, only destroy a single item */
2055         if (randint0(100) < 50) num = 1;
2056
2057         /* Hack -- decrement the maximum timeouts and total charges of rods and wands. -LM- */
2058         if ((st_ptr->stock[what].tval == TV_ROD) || (st_ptr->stock[what].tval == TV_WAND))
2059         {
2060                 st_ptr->stock[what].pval -= num * st_ptr->stock[what].pval / st_ptr->stock[what].number;
2061         }
2062
2063         /* Actually destroy (part of) the item */
2064         store_item_increase(what, -num);
2065         store_item_optimize(what);
2066 }
2067
2068
2069 /*!
2070  * @brief 店舗の品揃え変化のためにアイテムを追加する /
2071  * Creates a random item and gives it to a store
2072  * @return なし
2073  * @details
2074  * <pre>
2075  * This algorithm needs to be rethought.  A lot.
2076  * Currently, "normal" stores use a pre-built array.
2077  * Note -- the "level" given to "obj_get_num()" is a "favored"
2078  * level, that is, there is a much higher chance of getting
2079  * items with a level approaching that of the given level...
2080  * Should we check for "permission" to have the given item?
2081  * </pre>
2082  */
2083 static void store_create(void)
2084 {
2085         OBJECT_IDX i;
2086         int tries;
2087         DEPTH level;
2088
2089         object_type forge;
2090         object_type *q_ptr;
2091
2092
2093         /* Paranoia -- no room left */
2094         if (st_ptr->stock_num >= st_ptr->stock_size) return;
2095
2096
2097         /* Hack -- consider up to four items */
2098         for (tries = 0; tries < 4; tries++)
2099         {
2100                 /* Black Market */
2101                 if (cur_store_num == STORE_BLACK)
2102                 {
2103                         /* Pick a level for object/magic */
2104                         level = 25 + randint0(25);
2105
2106                         /* Random item (usually of given level) */
2107                         i = get_obj_num(level);
2108
2109                         /* Handle failure */
2110                         if (!i) continue;
2111                 }
2112
2113                 /* Normal Store */
2114                 else
2115                 {
2116                         /* Hack -- Pick an item to sell */
2117                         i = st_ptr->table[randint0(st_ptr->table_num)];
2118
2119                         /* Hack -- fake level for apply_magic() */
2120                         level = rand_range(1, STORE_OBJ_LEVEL);
2121                 }
2122
2123
2124                 /* Get local object */
2125                 q_ptr = &forge;
2126
2127                 /* Create a new object of the chosen kind */
2128                 object_prep(q_ptr, i);
2129
2130                 /* Apply some "low-level" magic (no artifacts) */
2131                 apply_magic(q_ptr, level, AM_NO_FIXED_ART);
2132
2133                 /* Require valid object */
2134                 if (!store_will_buy(q_ptr)) continue;
2135
2136                 /* Hack -- Charge lite's */
2137                 if (q_ptr->tval == TV_LITE)
2138                 {
2139                         if (q_ptr->sval == SV_LITE_TORCH) q_ptr->xtra4 = FUEL_TORCH / 2;
2140                         if (q_ptr->sval == SV_LITE_LANTERN) q_ptr->xtra4 = FUEL_LAMP / 2;
2141                 }
2142
2143
2144                 /* The item is "known" */
2145                 object_known(q_ptr);
2146
2147                 /* Mark it storebought */
2148                 q_ptr->ident |= IDENT_STORE;
2149
2150                 /* Mega-Hack -- no chests in stores */
2151                 if (q_ptr->tval == TV_CHEST) continue;
2152
2153                 /* Prune the black market */
2154                 if (cur_store_num == STORE_BLACK)
2155                 {
2156                         /* Hack -- No "crappy" items */
2157                         if (black_market_crap(q_ptr)) continue;
2158
2159                         /* Hack -- No "cheap" items */
2160                         if (object_value(q_ptr) < 10) continue;
2161
2162                         /* No "worthless" items */
2163                         /* if (object_value(q_ptr) <= 0) continue; */
2164                 }
2165
2166                 /* Prune normal stores */
2167                 else
2168                 {
2169                         /* No "worthless" items */
2170                         if (object_value(q_ptr) <= 0) continue;
2171                 }
2172
2173
2174                 /* Mass produce and/or Apply discount */
2175                 mass_produce(q_ptr);
2176
2177                 /* Attempt to carry the (known) item */
2178                 (void)store_carry(q_ptr);
2179
2180                 /* Definitely done */
2181                 break;
2182         }
2183 }
2184
2185
2186 /*!
2187  * @brief 店舗の割引対象外にするかどうかを判定 /
2188  * Eliminate need to bargain if player has haggled well in the past
2189  * @param minprice アイテムの最低販売価格
2190  * @return 割引を禁止するならTRUEを返す。
2191  */
2192 static bool noneedtobargain(s32b minprice)
2193 {
2194         s32b good = st_ptr->good_buy;
2195         s32b bad = st_ptr->bad_buy;
2196
2197         /* Cheap items are "boring" */
2198         if (minprice < 10L) return (TRUE);
2199
2200         /* Perfect haggling */
2201         if (good == MAX_SHORT) return (TRUE);
2202
2203         /* Reward good haggles, punish bad haggles, notice price */
2204         if (good > ((3 * bad) + (5 + (minprice/50)))) return (TRUE);
2205
2206         /* Return the flag */
2207         return (FALSE);
2208 }
2209
2210
2211 /*!
2212  * @brief 店主の持つプレイヤーに対する売買の良し悪し経験を記憶する /
2213  * Update the bargain info
2214  * @param price 実際の取引価格
2215  * @param minprice 店主の提示した価格
2216  * @param num 売買数 
2217  * @return なし
2218  */
2219 static void updatebargain(s32b price, s32b minprice, int num)
2220 {
2221         /* Hack -- auto-haggle */
2222         if (!manual_haggle) return;
2223
2224         /* Cheap items are "boring" */
2225         if ((minprice/num) < 10L) return;
2226
2227         /* Count the successful haggles */
2228         if (price == minprice)
2229         {
2230                 /* Just count the good haggles */
2231                 if (st_ptr->good_buy < MAX_SHORT)
2232                 {
2233                         st_ptr->good_buy++;
2234                 }
2235         }
2236
2237         /* Count the failed haggles */
2238         else
2239         {
2240                 /* Just count the bad haggles */
2241                 if (st_ptr->bad_buy < MAX_SHORT)
2242                 {
2243                         st_ptr->bad_buy++;
2244                 }
2245         }
2246 }
2247
2248
2249 /*!
2250  * @brief 店の商品リストを再表示する /
2251  * Re-displays a single store entry
2252  * @param pos 表示行
2253  * @return なし
2254  */
2255 static void display_entry(int pos)
2256 {
2257         int             i, cur_col;
2258         object_type     *o_ptr;
2259         s32b            x;
2260
2261         char            o_name[MAX_NLEN];
2262         char            out_val[160];
2263
2264
2265         int maxwid = 75;
2266
2267         /* Get the item */
2268         o_ptr = &st_ptr->stock[pos];
2269
2270         /* Get the "offset" */
2271         i = (pos % store_bottom);
2272
2273         /* Label it, clear the line --(-- */
2274         (void)sprintf(out_val, "%c) ", ((i > 25) ? toupper(I2A(i - 26)) : I2A(i)));
2275         prt(out_val, i+6, 0);
2276
2277         cur_col = 3;
2278         if (show_item_graph)
2279         {
2280                 byte a = object_attr(o_ptr);
2281                 char c = object_char(o_ptr);
2282
2283                 Term_queue_bigchar(cur_col, i + 6, a, c, 0, 0);
2284                 if (use_bigtile) cur_col++;
2285
2286                 cur_col += 2;
2287         }
2288
2289         /* Describe an item in the home */
2290         if ((cur_store_num == STORE_HOME) || (cur_store_num == STORE_MUSEUM))
2291         {
2292                 maxwid = 75;
2293
2294                 /* Leave room for weights, if necessary -DRS- */
2295                 if (show_weights) maxwid -= 10;
2296
2297                 /* Describe the object */
2298                 object_desc(o_name, o_ptr, 0);
2299                 o_name[maxwid] = '\0';
2300                 c_put_str(tval_to_attr[o_ptr->tval], o_name, i+6, cur_col);
2301
2302                 /* Show weights */
2303                 if (show_weights)
2304                 {
2305                         /* Only show the weight of an individual item */
2306                         int wgt = o_ptr->weight;
2307 #ifdef JP
2308                         sprintf(out_val, "%3d.%1d kg", lbtokg1(wgt) , lbtokg2(wgt) );
2309                         put_str(out_val, i+6, 67);
2310 #else
2311                         (void)sprintf(out_val, "%3d.%d lb", wgt / 10, wgt % 10);
2312                         put_str(out_val, i+6, 68);
2313 #endif
2314
2315                 }
2316         }
2317
2318         /* Describe an item (fully) in a store */
2319         else
2320         {
2321                 /* Must leave room for the "price" */
2322                 maxwid = 65;
2323
2324                 /* Leave room for weights, if necessary -DRS- */
2325                 if (show_weights) maxwid -= 7;
2326
2327                 /* Describe the object (fully) */
2328                 object_desc(o_name, o_ptr, 0);
2329                 o_name[maxwid] = '\0';
2330                 c_put_str(tval_to_attr[o_ptr->tval], o_name, i+6, cur_col);
2331
2332                 /* Show weights */
2333                 if (show_weights)
2334                 {
2335                         /* Only show the weight of an individual item */
2336                         int wgt = o_ptr->weight;
2337 #ifdef JP
2338                         sprintf(out_val, "%3d.%1d", lbtokg1(wgt) , lbtokg2(wgt) );
2339                         put_str(out_val, i+6, 60);
2340 #else
2341                         (void)sprintf(out_val, "%3d.%d", wgt / 10, wgt % 10);
2342                         put_str(out_val, i+6, 61);
2343 #endif
2344
2345                 }
2346
2347                 /* Display a "fixed" cost */
2348                 if (o_ptr->ident & (IDENT_FIXED))
2349                 {
2350                         /* Extract the "minimum" price */
2351                         x = price_item(o_ptr, ot_ptr->min_inflate, FALSE);
2352
2353                         /* Actually draw the price (not fixed) */
2354 #ifdef JP
2355 (void)sprintf(out_val, "%9ld固", (long)x);
2356 #else
2357                         (void)sprintf(out_val, "%9ld F", (long)x);
2358 #endif
2359
2360                         put_str(out_val, i+6, 68);
2361                 }
2362
2363                 /* Display a "taxed" cost */
2364                 else if (!manual_haggle)
2365                 {
2366                         /* Extract the "minimum" price */
2367                         x = price_item(o_ptr, ot_ptr->min_inflate, FALSE);
2368
2369                         /* Hack -- Apply Sales Tax if needed */
2370                         if (!noneedtobargain(x)) x += x / 10;
2371
2372                         /* Actually draw the price (with tax) */
2373                         (void)sprintf(out_val, "%9ld  ", (long)x);
2374                         put_str(out_val, i+6, 68);
2375                 }
2376
2377                 /* Display a "haggle" cost */
2378                 else
2379                 {
2380                         /* Extrect the "maximum" price */
2381                         x = price_item(o_ptr, ot_ptr->max_inflate, FALSE);
2382
2383                         /* Actually draw the price (not fixed) */
2384                         (void)sprintf(out_val, "%9ld  ", (long)x);
2385                         put_str(out_val, i+6, 68);
2386                 }
2387         }
2388 }
2389
2390
2391 /*!
2392  * @brief 店の商品リストを表示する /
2393  * Displays a store's inventory                 -RAK-
2394  * @return なし
2395  * @details
2396  * All prices are listed as "per individual object".  -BEN-
2397  */
2398 static void display_inventory(void)
2399 {
2400         int i, k;
2401
2402         /* Display the next 12 items */
2403         for (k = 0; k < store_bottom; k++)
2404         {
2405                 /* Do not display "dead" items */
2406                 if (store_top + k >= st_ptr->stock_num) break;
2407
2408                 /* Display that line */
2409                 display_entry(store_top + k);
2410         }
2411
2412         /* Erase the extra lines and the "more" prompt */
2413         for (i = k; i < store_bottom + 1; i++) prt("", i + 6, 0);
2414
2415         /* Assume "no current page" */
2416 #ifdef JP
2417         put_str("          ", 5, 20);
2418 #else
2419         put_str("        ", 5, 20);
2420 #endif
2421
2422
2423         /* Visual reminder of "more items" */
2424         if (st_ptr->stock_num > store_bottom)
2425         {
2426                 /* Show "more" reminder (after the last item) */
2427 #ifdef JP
2428                 prt("-続く-", k + 6, 3);
2429 #else
2430                 prt("-more-", k + 6, 3);
2431 #endif
2432
2433
2434                 /* Indicate the "current page" */
2435                 /* Trailing spaces are to display (Page xx) and (Page x) */
2436 #ifdef JP
2437                 put_str(format("(%dページ)  ", store_top/store_bottom + 1), 5, 20);
2438 #else
2439                 put_str(format("(Page %d)  ", store_top/store_bottom + 1), 5, 20);
2440 #endif
2441
2442         }
2443
2444         if (cur_store_num == STORE_HOME || cur_store_num == STORE_MUSEUM)
2445         {
2446                 k = st_ptr->stock_size;
2447
2448                 if (cur_store_num == STORE_HOME && !powerup_home) k /= 10;
2449 #ifdef JP
2450                 put_str(format("アイテム数:  %4d/%4d", st_ptr->stock_num, k), 19 + xtra_stock, 27);
2451 #else
2452                 put_str(format("Objects:  %4d/%4d", st_ptr->stock_num, k), 19 + xtra_stock, 30);
2453 #endif
2454         }
2455 }
2456
2457
2458 /*!
2459  * @brief プレイヤーの所持金を表示する /
2460  * Displays players gold                                        -RAK-
2461  * @return なし
2462  * @details
2463  */
2464 static void store_prt_gold(void)
2465 {
2466         char out_val[64];
2467
2468 #ifdef JP
2469         prt("手持ちのお金: ", 19 + xtra_stock, 53);
2470 #else
2471         prt("Gold Remaining: ", 19 + xtra_stock, 53);
2472 #endif
2473
2474
2475         sprintf(out_val, "%9ld", (long)p_ptr->au);
2476         prt(out_val, 19 + xtra_stock, 68);
2477 }
2478
2479 /*!
2480  * @brief 店舗情報全体を表示するメインルーチン /
2481  * Displays store (after clearing screen)               -RAK-
2482  * @return なし
2483  * @details
2484  */
2485 static void display_store(void)
2486 {
2487         char buf[80];
2488
2489
2490         /* Clear screen */
2491         Term_clear();
2492
2493         /* The "Home" is special */
2494         if (cur_store_num == STORE_HOME)
2495         {
2496                 /* Put the owner name */
2497 #ifdef JP
2498                 put_str("我が家", 3, 31);
2499 #else
2500                 put_str("Your Home", 3, 30);
2501 #endif
2502
2503
2504                 /* Label the item descriptions */
2505 #ifdef JP
2506                 put_str("アイテムの一覧", 5, 4);
2507 #else
2508                 put_str("Item Description", 5, 3);
2509 #endif
2510
2511
2512                 /* If showing weights, show label */
2513                 if (show_weights)
2514                 {
2515 #ifdef JP
2516                         put_str("重さ", 5, 72);
2517 #else
2518                         put_str("Weight", 5, 70);
2519 #endif
2520
2521                 }
2522         }
2523
2524         /* The "Home" is special */
2525         else if (cur_store_num == STORE_MUSEUM)
2526         {
2527                 /* Put the owner name */
2528 #ifdef JP
2529                 put_str("博物館", 3, 31);
2530 #else
2531                 put_str("Museum", 3, 30);
2532 #endif
2533
2534
2535                 /* Label the item descriptions */
2536 #ifdef JP
2537                 put_str("アイテムの一覧", 5, 4);
2538 #else
2539                 put_str("Item Description", 5, 3);
2540 #endif
2541
2542
2543                 /* If showing weights, show label */
2544                 if (show_weights)
2545                 {
2546 #ifdef JP
2547                         put_str("重さ", 5, 72);
2548 #else
2549                         put_str("Weight", 5, 70);
2550 #endif
2551
2552                 }
2553         }
2554
2555         /* Normal stores */
2556         else
2557         {
2558                 cptr store_name = (f_name + f_info[cur_store_feat].name);
2559                 cptr owner_name = (ot_ptr->owner_name);
2560                 cptr race_name = race_info[ot_ptr->owner_race].title;
2561
2562                 /* Put the owner name and race */
2563                 sprintf(buf, "%s (%s)", owner_name, race_name);
2564                 put_str(buf, 3, 10);
2565
2566                 /* Show the max price in the store (above prices) */
2567                 sprintf(buf, "%s (%ld)", store_name, (long)(ot_ptr->max_cost));
2568                 prt(buf, 3, 50);
2569
2570                 /* Label the item descriptions */
2571 #ifdef JP
2572                 put_str("商品の一覧", 5, 7);
2573 #else
2574                 put_str("Item Description", 5, 3);
2575 #endif
2576
2577
2578                 /* If showing weights, show label */
2579                 if (show_weights)
2580                 {
2581 #ifdef JP
2582                         put_str("重さ", 5, 62);
2583 #else
2584                         put_str("Weight", 5, 60);
2585 #endif
2586
2587                 }
2588
2589                 /* Label the asking price (in stores) */
2590 #ifdef JP
2591                 put_str("価格", 5, 73);
2592 #else
2593                 put_str("Price", 5, 72);
2594 #endif
2595
2596         }
2597
2598         /* Display the current gold */
2599         store_prt_gold();
2600
2601         /* Draw in the inventory */
2602         display_inventory();
2603 }
2604
2605
2606
2607 /*!
2608  * @brief 店舗からアイテムを選択する /
2609  * Get the ID of a store item and return its value      -RAK-
2610  * @param com_val 選択IDを返す参照ポインタ
2611  * @param pmt メッセージキャプション
2612  * @param i 選択範囲の最小値
2613  * @param j 選択範囲の最大値
2614  * @return 実際に選択したらTRUE、キャンセルしたらFALSE
2615  */
2616 static int get_stock(COMMAND_CODE *com_val, cptr pmt, int i, int j)
2617 {
2618         char    command;
2619         char    out_val[160];
2620         char    lo, hi;
2621
2622 #ifdef ALLOW_REPEAT /* TNB */
2623
2624         /* Get the item index */
2625         if (repeat_pull(com_val))
2626         {
2627                 /* Verify the item */
2628                 if ((*com_val >= i) && (*com_val <= j))
2629                 {
2630                         /* Success */
2631                         return (TRUE);
2632                 }
2633         }
2634
2635 #endif /* ALLOW_REPEAT -- TNB */
2636
2637         /* Paranoia XXX XXX XXX */
2638         msg_print(NULL);
2639
2640
2641         /* Assume failure */
2642         *com_val = (-1);
2643
2644         /* Build the prompt */
2645         lo = I2A(i);
2646         hi = (j > 25) ? toupper(I2A(j - 26)) : I2A(j);
2647 #ifdef JP
2648         (void)sprintf(out_val, "(%s:%c-%c, ESCで中断) %s",
2649                 (((cur_store_num == STORE_HOME) || (cur_store_num == STORE_MUSEUM)) ? "アイテム" : "商品"), 
2650                                   lo, hi, pmt);
2651 #else
2652         (void)sprintf(out_val, "(Items %c-%c, ESC to exit) %s",
2653                                   lo, hi, pmt);
2654 #endif
2655
2656
2657         /* Ask until done */
2658         while (TRUE)
2659         {
2660                 COMMAND_CODE k;
2661
2662                 /* Escape */
2663                 if (!get_com(out_val, &command, FALSE)) break;
2664
2665                 /* Convert */
2666                 if (islower(command))
2667                         k = A2I(command);
2668                 else if (isupper(command))
2669                         k = A2I(tolower(command)) + 26;
2670                 else
2671                         k = -1;
2672
2673                 /* Legal responses */
2674                 if ((k >= i) && (k <= j))
2675                 {
2676                         *com_val = k;
2677                         break;
2678                 }
2679
2680                 /* Oops */
2681                 bell();
2682         }
2683
2684         /* Clear the prompt */
2685         prt("", 0, 0);
2686
2687         /* Cancel */
2688         if (command == ESCAPE) return (FALSE);
2689
2690 #ifdef ALLOW_REPEAT /* TNB */
2691
2692         repeat_push(*com_val);
2693
2694 #endif /* ALLOW_REPEAT -- TNB */
2695
2696         /* Success */
2697         return (TRUE);
2698 }
2699
2700
2701 /*!
2702  * @brief 店主の不満度を増やし、プレイヤーを締め出す判定と処理を行う /
2703  * Increase the insult counter and get angry if too many -RAK-
2704  * @return プレイヤーを締め出す場合TRUEを返す
2705  */
2706 static int increase_insults(void)
2707 {
2708         /* Increase insults */
2709         st_ptr->insult_cur++;
2710
2711         /* Become insulted */
2712         if (st_ptr->insult_cur > ot_ptr->insult_max)
2713         {
2714                 /* Complain */
2715                 say_comment_4();
2716
2717                 /* Reset insults */
2718                 st_ptr->insult_cur = 0;
2719                 st_ptr->good_buy = 0;
2720                 st_ptr->bad_buy = 0;
2721
2722                 /* Open tomorrow */
2723                 st_ptr->store_open = turn + TURNS_PER_TICK*TOWN_DAWN/8 + randint1(TURNS_PER_TICK*TOWN_DAWN/8);
2724
2725                 /* Closed */
2726                 return (TRUE);
2727         }
2728
2729         /* Not closed */
2730         return (FALSE);
2731 }
2732
2733
2734 /*!
2735  * @brief 店主の不満度を減らす /
2736  * Decrease insults                             -RAK-
2737  * @return プレイヤーを締め出す場合TRUEを返す
2738  */
2739 static void decrease_insults(void)
2740 {
2741         /* Decrease insults */
2742         if (st_ptr->insult_cur) st_ptr->insult_cur--;
2743 }
2744
2745
2746 /*!
2747  * @brief 店主の不満度が増えた場合のみのメッセージを表示する /
2748  * Have insulted while haggling                         -RAK-
2749  * @return プレイヤーを締め出す場合TRUEを返す
2750  */
2751 static int haggle_insults(void)
2752 {
2753         /* Increase insults */
2754         if (increase_insults()) return (TRUE);
2755
2756         /* Display and flush insult */
2757         say_comment_5();
2758
2759         /* Still okay */
2760         return (FALSE);
2761 }
2762
2763
2764 /*
2765  * Mega-Hack -- Enable "increments"
2766  */
2767 static bool allow_inc = FALSE;
2768
2769 /*
2770  * Mega-Hack -- Last "increment" during haggling
2771  */
2772 static s32b last_inc = 0L;
2773
2774
2775 /*!
2776  * @brief 交渉価格を確認と認証の是非を行う /
2777  * Get a haggle
2778  * @param pmt メッセージ
2779  * @param poffer 別途価格提示をした場合の値を返す参照ポインタ
2780  * @param price 現在の交渉価格
2781  * @param final 最終確定価格ならばTRUE
2782  * @return プレイヤーを締め出す場合TRUEを返す
2783  */
2784 static int get_haggle(cptr pmt, s32b *poffer, s32b price, int final)
2785 {
2786         s32b            i;
2787
2788         cptr            p;
2789
2790         char                            buf[128];
2791         char            out_val[160];
2792
2793
2794         /* Clear old increment if necessary */
2795         if (!allow_inc) last_inc = 0L;
2796
2797
2798         /* Final offer */
2799         if (final)
2800         {
2801 #ifdef JP
2802                 sprintf(buf, "%s [承諾] ", pmt);
2803 #else
2804                 sprintf(buf, "%s [accept] ", pmt);
2805 #endif
2806
2807         }
2808
2809         /* Old (negative) increment, and not final */
2810         else if (last_inc < 0)
2811         {
2812 #ifdef JP
2813                 sprintf(buf, "%s [-$%ld] ", pmt, (long)(ABS(last_inc)));
2814 #else
2815                 sprintf(buf, "%s [-%ld] ", pmt, (long)(ABS(last_inc)));
2816 #endif
2817
2818         }
2819
2820         /* Old (positive) increment, and not final */
2821         else if (last_inc > 0)
2822         {
2823 #ifdef JP
2824                 sprintf(buf, "%s [+$%ld] ", pmt, (long)(ABS(last_inc)));
2825 #else
2826                 sprintf(buf, "%s [+%ld] ", pmt, (long)(ABS(last_inc)));
2827 #endif
2828
2829         }
2830
2831         /* Normal haggle */
2832         else
2833         {
2834                 sprintf(buf, "%s ", pmt);
2835         }
2836
2837
2838         /* Paranoia XXX XXX XXX */
2839         msg_print(NULL);
2840
2841
2842         /* Ask until done */
2843         while (TRUE)
2844         {
2845                 bool res;
2846
2847                 /* Display prompt */
2848                 prt(buf, 0, 0);
2849
2850                 /* Default */
2851                 strcpy(out_val, "");
2852
2853                 /*
2854                  * Ask the user for a response.
2855                  * Don't allow to use numpad as cursor key.
2856                  */
2857                 res = askfor_aux(out_val, 32, FALSE);
2858
2859                 /* Clear prompt */
2860                 prt("", 0, 0);
2861
2862                 /* Cancelled */
2863                 if (!res) return FALSE;
2864
2865                 /* Skip leading spaces */
2866                 for (p = out_val; *p == ' '; p++) /* loop */;
2867
2868                 /* Empty response */
2869                 if (*p == '\0')
2870                 {
2871                         /* Accept current price */
2872                         if (final)
2873                         {
2874                                 *poffer = price;
2875                                 last_inc = 0L;
2876                                 break;
2877                         }
2878
2879                         /* Use previous increment */
2880                         if (allow_inc && last_inc)
2881                         {
2882                                 *poffer += last_inc;
2883                                 break;
2884                         }
2885                 }
2886
2887                 /* Normal response */
2888                 else
2889                 {
2890                         /* Extract a number */
2891                         i = atol(p);
2892
2893                         /* Handle "incremental" number */
2894                         if ((*p == '+' || *p == '-'))
2895                         {
2896                                 /* Allow increments */
2897                                 if (allow_inc)
2898                                 {
2899                                         /* Use the given "increment" */
2900                                         *poffer += i;
2901                                         last_inc = i;
2902                                         break;
2903                                 }
2904                         }
2905
2906                         /* Handle normal number */
2907                         else
2908                         {
2909                                 /* Use the given "number" */
2910                                 *poffer = i;
2911                                 last_inc = 0L;
2912                                 break;
2913                         }
2914                 }
2915
2916                 /* Warning */
2917 #ifdef JP
2918                 msg_print("値がおかしいです。");
2919 #else
2920                 msg_print("Invalid response.");
2921 #endif
2922
2923                 msg_print(NULL);
2924         }
2925
2926         /* Success */
2927         return (TRUE);
2928 }
2929
2930
2931 /*!
2932  * @brief 店主がプレイヤーからの交渉価格を判断する /
2933  * Receive an offer (from the player)
2934  * @param pmt メッセージ
2935  * @param poffer 店主からの交渉価格を返す参照ポインタ
2936  * @param last_offer 現在の交渉価格
2937  * @param factor 店主の価格基準倍率
2938  * @param price アイテムの実価値
2939  * @param final 最終価格確定ならばTRUE
2940  * @return プレイヤーの価格に対して不服ならばTRUEを返す /
2941  * Return TRUE if offer is NOT okay
2942  */
2943 static bool receive_offer(cptr pmt, s32b *poffer,
2944                           s32b last_offer, int factor,
2945                           s32b price, int final)
2946 {
2947         /* Haggle till done */
2948         while (TRUE)
2949         {
2950                 /* Get a haggle (or cancel) */
2951                 if (!get_haggle(pmt, poffer, price, final)) return (TRUE);
2952
2953                 /* Acceptable offer */
2954                 if (((*poffer) * factor) >= (last_offer * factor)) break;
2955
2956                 /* Insult, and check for kicked out */
2957                 if (haggle_insults()) return (TRUE);
2958
2959                 /* Reject offer (correctly) */
2960                 (*poffer) = last_offer;
2961         }
2962
2963         /* Success */
2964         return (FALSE);
2965 }
2966
2967
2968 /*!
2969  * @brief プレイヤーが購入する時の値切り処理メインルーチン /
2970  * Haggling routine                             -RAK-
2971  * @param o_ptr オブジェクトの構造体参照ポインタ
2972  * @param price 最終価格を返す参照ポインタ
2973  * @return プレイヤーの価格に対して店主が不服ならばTRUEを返す /
2974  * Return TRUE if purchase is NOT successful
2975  */
2976 static bool purchase_haggle(object_type *o_ptr, s32b *price)
2977 {
2978         s32b                       cur_ask, final_ask;
2979         s32b                       last_offer, offer;
2980         s32b                       x1, x2, x3;
2981         s32b                       min_per, max_per;
2982         int                        flag, loop_flag, noneed;
2983         int                        annoyed = 0, final = FALSE;
2984
2985         bool            cancel = FALSE;
2986
2987 #ifdef JP
2988         cptr pmt = "提示価格";
2989 #else
2990         cptr            pmt = "Asking";
2991 #endif
2992
2993
2994         char            out_val[160];
2995
2996
2997         *price = 0;
2998
2999
3000         /* Extract the starting offer and the final offer */
3001         cur_ask = price_item(o_ptr, ot_ptr->max_inflate, FALSE);
3002         final_ask = price_item(o_ptr, ot_ptr->min_inflate, FALSE);
3003
3004         /* Determine if haggling is necessary */
3005         noneed = noneedtobargain(final_ask);
3006
3007         /* No need to haggle */
3008         if (noneed || !manual_haggle)
3009         {
3010                 /* No need to haggle */
3011                 if (noneed)
3012                 {
3013                         /* Message summary */
3014 #ifdef JP
3015                         msg_print("結局この金額にまとまった。");
3016 #else
3017                         msg_print("You eventually agree upon the price.");
3018 #endif
3019
3020                         msg_print(NULL);
3021                 }
3022
3023                 /* No haggle option */
3024                 else
3025                 {
3026                         /* Message summary */
3027 #ifdef JP
3028                         msg_print("すんなりとこの金額にまとまった。");
3029 #else
3030                         msg_print("You quickly agree upon the price.");
3031 #endif
3032
3033                         msg_print(NULL);
3034
3035                         /* Apply Sales Tax */
3036                         final_ask += final_ask / 10;
3037                 }
3038
3039                 /* Final price */
3040                 cur_ask = final_ask;
3041
3042                 /* Go to final offer */
3043 #ifdef JP
3044                 pmt = "最終提示価格";
3045 #else
3046                 pmt = "Final Offer";
3047 #endif
3048
3049                 final = TRUE;
3050         }
3051
3052
3053         /* Haggle for the whole pile */
3054         cur_ask *= o_ptr->number;
3055         final_ask *= o_ptr->number;
3056
3057
3058         /* Haggle parameters */
3059         min_per = ot_ptr->haggle_per;
3060         max_per = min_per * 3;
3061
3062         /* Mega-Hack -- artificial "last offer" value */
3063         last_offer = object_value(o_ptr) * o_ptr->number;
3064         last_offer = last_offer * (200 - (int)(ot_ptr->max_inflate)) / 100L;
3065         if (last_offer <= 0) last_offer = 1;
3066
3067         /* No offer yet */
3068         offer = 0;
3069
3070         /* No incremental haggling yet */
3071         allow_inc = FALSE;
3072
3073         /* Haggle until done */
3074         for (flag = FALSE; !flag; )
3075         {
3076                 loop_flag = TRUE;
3077
3078                 while (!flag && loop_flag)
3079                 {
3080                         (void)sprintf(out_val, "%s :  %ld", pmt, (long)cur_ask);
3081                         put_str(out_val, 1, 0);
3082 #ifdef JP
3083                         cancel = receive_offer("提示する金額? ",
3084 #else
3085                         cancel = receive_offer("What do you offer? ",
3086 #endif
3087
3088                                                &offer, last_offer, 1, cur_ask, final);
3089
3090                         if (cancel)
3091                         {
3092                                 flag = TRUE;
3093                         }
3094                         else if (offer > cur_ask)
3095                         {
3096                                 say_comment_6();
3097                                 offer = last_offer;
3098                         }
3099                         else if (offer == cur_ask)
3100                         {
3101                                 flag = TRUE;
3102                                 *price = offer;
3103                         }
3104                         else
3105                         {
3106                                 loop_flag = FALSE;
3107                         }
3108                 }
3109
3110                 if (!flag)
3111                 {
3112                         x1 = 100 * (offer - last_offer) / (cur_ask - last_offer);
3113                         if (x1 < min_per)
3114                         {
3115                                 if (haggle_insults())
3116                                 {
3117                                         flag = TRUE;
3118                                         cancel = TRUE;
3119                                 }
3120                         }
3121                         else if (x1 > max_per)
3122                         {
3123                                 x1 = x1 * 3 / 4;
3124                                 if (x1 < max_per) x1 = max_per;
3125                         }
3126                         x2 = rand_range(x1-2, x1+2);
3127                         x3 = ((cur_ask - offer) * x2 / 100L) + 1;
3128                         /* don't let the price go up */
3129                         if (x3 < 0) x3 = 0;
3130                         cur_ask -= x3;
3131
3132                         /* Too little */
3133                         if (cur_ask < final_ask)
3134                         {
3135                                 final = TRUE;
3136                                 cur_ask = final_ask;
3137 #ifdef JP
3138                                 pmt = "最終提示価格";
3139 #else
3140                                 pmt = "Final Offer";
3141 #endif
3142
3143                                 annoyed++;
3144                                 if (annoyed > 3)
3145                                 {
3146                                         (void)(increase_insults());
3147                                         cancel = TRUE;
3148                                         flag = TRUE;
3149                                 }
3150                         }
3151                         else if (offer >= cur_ask)
3152                         {
3153                                 flag = TRUE;
3154                                 *price = offer;
3155                         }
3156
3157                         if (!flag)
3158                         {
3159                                 last_offer = offer;
3160                                 allow_inc = TRUE;
3161                                 prt("", 1, 0);
3162 #ifdef JP
3163 (void)sprintf(out_val, "前回の提示金額: $%ld",
3164 #else
3165                                 (void)sprintf(out_val, "Your last offer: %ld",
3166 #endif
3167
3168                                                           (long)last_offer);
3169                                 put_str(out_val, 1, 39);
3170                                 say_comment_2(cur_ask, annoyed);
3171                         }
3172                 }
3173         }
3174
3175         /* Cancel */
3176         if (cancel) return (TRUE);
3177
3178         /* Update bargaining info */
3179         updatebargain(*price, final_ask, o_ptr->number);
3180
3181         /* Do not cancel */
3182         return (FALSE);
3183 }
3184
3185
3186 /*!
3187  * @brief プレイヤーが売却する時の値切り処理メインルーチン /
3188  * Haggling routine                             -RAK-
3189  * @param o_ptr オブジェクトの構造体参照ポインタ
3190  * @param price 最終価格を返す参照ポインタ
3191  * @return プレイヤーの価格に対して店主が不服ならばTRUEを返す /
3192  * Return TRUE if purchase is NOT successful
3193  */
3194 static bool sell_haggle(object_type *o_ptr, s32b *price)
3195 {
3196         s32b    purse, cur_ask, final_ask;
3197         s32b    last_offer = 0, offer = 0;
3198         s32b    x1, x2, x3;
3199         s32b    min_per, max_per;
3200         int     flag, loop_flag, noneed;
3201         int     annoyed = 0, final = FALSE;
3202         bool    cancel = FALSE;
3203 #ifdef JP
3204         cptr pmt = "提示金額";
3205 #else
3206         cptr    pmt = "Offer";
3207 #endif
3208
3209         char    out_val[160];
3210
3211
3212         *price = 0;
3213
3214
3215         /* Obtain the starting offer and the final offer */
3216         cur_ask = price_item(o_ptr, ot_ptr->max_inflate, TRUE);
3217         final_ask = price_item(o_ptr, ot_ptr->min_inflate, TRUE);
3218
3219         /* Determine if haggling is necessary */
3220         noneed = noneedtobargain(final_ask);
3221
3222         /* Get the owner's payout limit */
3223         purse = (s32b)(ot_ptr->max_cost);
3224
3225         /* No need to haggle */
3226         if (noneed || !manual_haggle || (final_ask >= purse))
3227         {
3228                 /* Apply Sales Tax (if needed) */
3229                 if (!manual_haggle && !noneed)
3230                 {
3231                         final_ask -= final_ask / 10;
3232                 }
3233
3234                 /* No reason to haggle */
3235                 if (final_ask >= purse)
3236                 {
3237                         /* Message */
3238 #ifdef JP
3239                         msg_print("即座にこの金額にまとまった。");
3240 #else
3241                         msg_print("You instantly agree upon the price.");
3242 #endif
3243
3244                         msg_print(NULL);
3245
3246                         /* Offer full purse */
3247                         final_ask = purse;
3248                 }
3249
3250                 /* No need to haggle */
3251                 else if (noneed)
3252                 {
3253                         /* Message */
3254 #ifdef JP
3255                         msg_print("結局この金額にまとまった。");
3256 #else
3257                         msg_print("You eventually agree upon the price.");
3258 #endif
3259
3260                         msg_print(NULL);
3261                 }
3262
3263                 /* No haggle option */
3264                 else
3265                 {
3266                         /* Message summary */
3267 #ifdef JP
3268                         msg_print("すんなりとこの金額にまとまった。");
3269 #else
3270                         msg_print("You quickly agree upon the price.");
3271 #endif
3272
3273                         msg_print(NULL);
3274                 }
3275
3276                 /* Final price */
3277                 cur_ask = final_ask;
3278
3279                 /* Final offer */
3280                 final = TRUE;
3281 #ifdef JP
3282                 pmt = "最終提示金額";
3283 #else
3284                 pmt = "Final Offer";
3285 #endif
3286
3287         }
3288
3289         /* Haggle for the whole pile */
3290         cur_ask *= o_ptr->number;
3291         final_ask *= o_ptr->number;
3292
3293
3294         /* XXX XXX XXX Display commands */
3295
3296         /* Haggling parameters */
3297         min_per = ot_ptr->haggle_per;
3298         max_per = min_per * 3;
3299
3300         /* Mega-Hack -- artificial "last offer" value */
3301         last_offer = object_value(o_ptr) * o_ptr->number;
3302         last_offer = last_offer * ot_ptr->max_inflate / 100L;
3303
3304         /* No offer yet */
3305         offer = 0;
3306
3307         /* No incremental haggling yet */
3308         allow_inc = FALSE;
3309
3310         /* Haggle */
3311         for (flag = FALSE; !flag; )
3312         {
3313                 while (1)
3314                 {
3315                         loop_flag = TRUE;
3316
3317                         (void)sprintf(out_val, "%s :  %ld", pmt, (long)cur_ask);
3318                         put_str(out_val, 1, 0);
3319 #ifdef JP
3320                         cancel = receive_offer("提示する価格? ",
3321 #else
3322                         cancel = receive_offer("What price do you ask? ",
3323 #endif
3324
3325                                                                    &offer, last_offer, -1, cur_ask, final);
3326
3327                         if (cancel)
3328                         {
3329                                 flag = TRUE;
3330                         }
3331                         else if (offer < cur_ask)
3332                         {
3333                                 say_comment_6();
3334                                 /* rejected, reset offer for incremental haggling */
3335                                 offer = last_offer;
3336                         }
3337                         else if (offer == cur_ask)
3338                         {
3339                                 flag = TRUE;
3340                                 *price = offer;
3341                         }
3342                         else
3343                         {
3344                                 loop_flag = FALSE;
3345                         }
3346
3347                         /* Stop */
3348                         if (flag || !loop_flag) break;
3349                 }
3350
3351                 if (!flag)
3352                 {
3353                         x1 = 100 * (last_offer - offer) / (last_offer - cur_ask);
3354                         if (x1 < min_per)
3355                         {
3356                                 if (haggle_insults())
3357                                 {
3358                                         flag = TRUE;
3359                                         cancel = TRUE;
3360                                 }
3361                         }
3362                         else if (x1 > max_per)
3363                         {
3364                                 x1 = x1 * 3 / 4;
3365                                 if (x1 < max_per) x1 = max_per;
3366                         }
3367                         x2 = rand_range(x1-2, x1+2);
3368                         x3 = ((offer - cur_ask) * x2 / 100L) + 1;
3369                         /* don't let the price go down */
3370                         if (x3 < 0) x3 = 0;
3371                         cur_ask += x3;
3372
3373                         if (cur_ask > final_ask)
3374                         {
3375                                 cur_ask = final_ask;
3376                                 final = TRUE;
3377 #ifdef JP
3378                                 pmt = "最終提示金額";
3379 #else
3380                                 pmt = "Final Offer";
3381 #endif
3382
3383                                 annoyed++;
3384                                 if (annoyed > 3)
3385                                 {
3386                                         flag = TRUE;
3387 #ifdef JP
3388                                 /* 追加 $0 で買い取られてしまうのを防止 By FIRST*/
3389                                         cancel = TRUE;
3390 #endif
3391                                         (void)(increase_insults());
3392                                 }
3393                         }
3394                         else if (offer <= cur_ask)
3395                         {
3396                                 flag = TRUE;
3397                                 *price = offer;
3398                         }
3399
3400                         if (!flag)
3401                         {
3402                                 last_offer = offer;
3403                                 allow_inc = TRUE;
3404                                 prt("", 1, 0);
3405                                 (void)sprintf(out_val,
3406 #ifdef JP
3407                                               "前回の提示価格 $%ld", (long)last_offer);
3408 #else
3409                                                           "Your last bid %ld", (long)last_offer);
3410 #endif
3411
3412                                 put_str(out_val, 1, 39);
3413                                 say_comment_3(cur_ask, annoyed);
3414                         }
3415                 }
3416         }
3417
3418         /* Cancel */
3419         if (cancel) return (TRUE);
3420
3421         /* Update bargaining info */
3422         updatebargain(*price, final_ask, o_ptr->number);
3423
3424         /* Do not cancel */
3425         return (FALSE);
3426 }
3427
3428
3429 /*!
3430  * @brief 店からの購入処理のメインルーチン /
3431  * Buy an item from a store                     -RAK-
3432  * @return なし
3433  */
3434 static void store_purchase(void)
3435 {
3436         int i, choice;
3437         COMMAND_CODE item, item_new;
3438
3439         ITEM_NUMBER amt;
3440
3441         s32b price, best;
3442
3443         object_type forge;
3444         object_type *j_ptr;
3445
3446         object_type *o_ptr;
3447
3448         char o_name[MAX_NLEN];
3449
3450         char out_val[160];
3451
3452         if (cur_store_num == STORE_MUSEUM)
3453         {
3454 #ifdef JP
3455                 msg_print("博物館から取り出すことはできません。");
3456 #else
3457                 msg_print("Museum.");
3458 #endif
3459                 return;
3460         }
3461
3462         /* Empty? */
3463         if (st_ptr->stock_num <= 0)
3464         {
3465                 if (cur_store_num == STORE_HOME)
3466 #ifdef JP
3467                         msg_print("我が家には何も置いてありません。");
3468 #else
3469                         msg_print("Your home is empty.");
3470 #endif
3471
3472                 else
3473 #ifdef JP
3474                         msg_print("現在商品の在庫を切らしています。");
3475 #else
3476                         msg_print("I am currently out of stock.");
3477 #endif
3478
3479                 return;
3480         }
3481
3482
3483         /* Find the number of objects on this and following pages */
3484         i = (st_ptr->stock_num - store_top);
3485
3486         /* And then restrict it to the current page */
3487         if (i > store_bottom) i = store_bottom;
3488
3489         /* Prompt */
3490 #ifdef JP
3491         /* ブラックマーケットの時は別のメッセージ */
3492         switch( cur_store_num ) {
3493                 case 7:
3494                         sprintf(out_val, "どのアイテムを取りますか? ");
3495                         break;
3496                 case 6:
3497                         sprintf(out_val, "どれ? ");
3498                         break;
3499                 default:
3500                         sprintf(out_val, "どの品物が欲しいんだい? ");
3501                         break;
3502         }
3503 #else
3504         if (cur_store_num == STORE_HOME)
3505         {
3506                 sprintf(out_val, "Which item do you want to take? ");
3507         }
3508         else
3509         {
3510                 sprintf(out_val, "Which item are you interested in? ");
3511         }
3512 #endif
3513
3514
3515         /* Get the item number to be bought */
3516         if (!get_stock(&item, out_val, 0, i - 1)) return;
3517
3518         /* Get the actual index */
3519         item = item + store_top;
3520
3521         /* Get the actual item */
3522         o_ptr = &st_ptr->stock[item];
3523
3524         /* Assume the player wants just one of them */
3525         amt = 1;
3526
3527         /* Get local object */
3528         j_ptr = &forge;
3529
3530         /* Get a copy of the object */
3531         object_copy(j_ptr, o_ptr);
3532
3533         /*
3534          * If a rod or wand, allocate total maximum timeouts or charges
3535          * between those purchased and left on the shelf.
3536          */
3537         reduce_charges(j_ptr, o_ptr->number - amt);
3538
3539         /* Modify quantity */
3540         j_ptr->number = amt;
3541
3542         /* Hack -- require room in pack */
3543         if (!inven_carry_okay(j_ptr))
3544         {
3545 #ifdef JP
3546 msg_print("そんなにアイテムを持てない。");
3547 #else
3548                 msg_print("You cannot carry that many different items.");
3549 #endif
3550
3551                 return;
3552         }
3553
3554         /* Determine the "best" price (per item) */
3555         best = price_item(j_ptr, ot_ptr->min_inflate, FALSE);
3556
3557         /* Find out how many the player wants */
3558         if (o_ptr->number > 1)
3559         {
3560                 /* Hack -- note cost of "fixed" items */
3561                 if ((cur_store_num != STORE_HOME) &&
3562                     (o_ptr->ident & IDENT_FIXED))
3563                 {
3564 #ifdef JP
3565 msg_format("一つにつき $%ldです。", (long)(best));
3566 #else
3567                         msg_format("That costs %ld gold per item.", (long)(best));
3568 #endif
3569
3570                 }
3571
3572                 /* Get a quantity */
3573                 amt = get_quantity(NULL, o_ptr->number);
3574
3575                 /* Allow user abort */
3576                 if (amt <= 0) return;
3577         }
3578
3579         /* Get local object */
3580         j_ptr = &forge;
3581
3582         /* Get desired object */
3583         object_copy(j_ptr, o_ptr);
3584
3585         /*
3586          * If a rod or wand, allocate total maximum timeouts or charges
3587          * between those purchased and left on the shelf.
3588          */
3589         reduce_charges(j_ptr, o_ptr->number - amt);
3590
3591         /* Modify quantity */
3592         j_ptr->number = amt;
3593
3594         /* Hack -- require room in pack */
3595         if (!inven_carry_okay(j_ptr))
3596         {
3597 #ifdef JP
3598                 msg_print("ザックにそのアイテムを入れる隙間がない。");
3599 #else
3600                 msg_print("You cannot carry that many items.");
3601 #endif
3602
3603                 return;
3604         }
3605
3606         /* Attempt to buy it */
3607         if (cur_store_num != STORE_HOME)
3608         {
3609                 /* Fixed price, quick buy */
3610                 if (o_ptr->ident & (IDENT_FIXED))
3611                 {
3612                         /* Assume accept */
3613                         choice = 0;
3614
3615                         /* Go directly to the "best" deal */
3616                         price = (best * j_ptr->number);
3617                 }
3618
3619                 /* Haggle for it */
3620                 else
3621                 {
3622                         /* Describe the object (fully) */
3623                         object_desc(o_name, j_ptr, 0);
3624
3625                         /* Message */
3626 #ifdef JP
3627                         msg_format("%s(%c)を購入する。", o_name, I2A(item));
3628 #else
3629                         msg_format("Buying %s (%c).", o_name, I2A(item));
3630 #endif
3631
3632                         msg_print(NULL);
3633
3634                         /* Haggle for a final price */
3635                         choice = purchase_haggle(j_ptr, &price);
3636
3637                         /* Hack -- Got kicked out */
3638                         if (st_ptr->store_open >= turn) return;
3639                 }
3640
3641                 /* Player wants it */
3642                 if (choice == 0)
3643                 {
3644                         /* Fix the item price (if "correctly" haggled) */
3645                         if (price == (best * j_ptr->number)) o_ptr->ident |= (IDENT_FIXED);
3646
3647                         /* Player can afford it */
3648                         if (p_ptr->au >= price)
3649                         {
3650                                 /* Say "okay" */
3651                                 say_comment_1();
3652
3653                                 if (cur_store_num == STORE_BLACK) /* The black market is illegal! */
3654                                         chg_virtue(V_JUSTICE, -1);
3655                                 if((o_ptr->tval == TV_BOTTLE) && (cur_store_num != STORE_HOME))
3656                                         chg_virtue(V_NATURE, -1);
3657
3658                                 /* Make a sound */
3659                                 sound(SOUND_BUY);
3660
3661                                 /* Be happy */
3662                                 decrease_insults();
3663
3664                                 /* Spend the money */
3665                                 p_ptr->au -= price;
3666
3667                                 /* Update the display */
3668                                 store_prt_gold();
3669
3670                                 /* Hack -- buying an item makes you aware of it */
3671                                 object_aware(j_ptr);
3672
3673                                 /* Hack -- clear the "fixed" flag from the item */
3674                                 j_ptr->ident &= ~(IDENT_FIXED);
3675
3676                                 /* Describe the transaction */
3677                                 object_desc(o_name, j_ptr, 0);
3678
3679                                 /* Message */
3680 #ifdef JP
3681 msg_format("%sを $%ldで購入しました。", o_name, (long)price);
3682 #else
3683                                 msg_format("You bought %s for %ld gold.", o_name, (long)price);
3684 #endif
3685
3686                                 strcpy(record_o_name, o_name);
3687                                 record_turn = turn;
3688
3689                                 if (record_buy) do_cmd_write_nikki(NIKKI_BUY, 0, o_name);
3690                                 object_desc(o_name, o_ptr, OD_NAME_ONLY);
3691                                 if(record_rand_art && o_ptr->art_name)
3692                                         do_cmd_write_nikki(NIKKI_ART, 0, o_name);
3693
3694                                 /* Erase the inscription */
3695                                 j_ptr->inscription = 0;
3696
3697                                 /* Erase the "feeling" */
3698                                 j_ptr->feeling = FEEL_NONE;
3699                                 j_ptr->ident &= ~(IDENT_STORE);
3700                                 /* Give it to the player */
3701                                 item_new = inven_carry(j_ptr);
3702
3703                                 /* Describe the final result */
3704                                 object_desc(o_name, &inventory[item_new], 0);
3705
3706                                 /* Message */
3707 #ifdef JP
3708                                 msg_format("%s(%c)を手に入れた。", o_name, index_to_label(item_new));
3709 #else
3710                                 msg_format("You have %s (%c).",
3711                                                    o_name, index_to_label(item_new));
3712 #endif
3713
3714                                 /* Auto-inscription */
3715                                 autopick_alter_item(item_new, FALSE);
3716
3717                                 /* Now, reduce the original stack's pval. */
3718                                 if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND))
3719                                 {
3720                                         o_ptr->pval -= j_ptr->pval;
3721                                 }
3722
3723                                 /* Handle stuff */
3724                                 handle_stuff();
3725
3726                                 /* Note how many slots the store used to have */
3727                                 i = st_ptr->stock_num;
3728
3729                                 /* Remove the bought items from the store */
3730                                 store_item_increase(item, -amt);
3731                                 store_item_optimize(item);
3732
3733                                 /* Store is empty */
3734                                 if (st_ptr->stock_num == 0)
3735                                 {
3736                                         /* Shuffle */
3737                                         if (one_in_(STORE_SHUFFLE))
3738                                         {
3739                                                 char buf[80];
3740                                                 /* Message */
3741 #ifdef JP
3742                                                 msg_print("店主は引退した。");
3743 #else
3744                                                 msg_print("The shopkeeper retires.");
3745 #endif
3746
3747
3748                                                 /* Shuffle the store */
3749                                                 store_shuffle(cur_store_num);
3750
3751                                                 prt("",3,0);
3752                                                 sprintf(buf, "%s (%s)",
3753                                                         ot_ptr->owner_name, race_info[ot_ptr->owner_race].title);
3754                                                 put_str(buf, 3, 10);
3755                                                 sprintf(buf, "%s (%ld)",
3756                                                         (f_name + f_info[cur_store_feat].name), (long)(ot_ptr->max_cost));
3757                                                 prt(buf, 3, 50);
3758                                         }
3759
3760                                         /* Maintain */
3761                                         else
3762                                         {
3763                                                 /* Message */
3764 #ifdef JP
3765                                                 msg_print("店主は新たな在庫を取り出した。");
3766 #else
3767                                                 msg_print("The shopkeeper brings out some new stock.");
3768 #endif
3769
3770                                         }
3771
3772                                         /* New inventory */
3773                                         for (i = 0; i < 10; i++)
3774                                         {
3775                                                 /* Maintain the store */
3776                                                 store_maint(p_ptr->town_num, cur_store_num);
3777                                         }
3778
3779                                         /* Start over */
3780                                         store_top = 0;
3781
3782                                         /* Redraw everything */
3783                                         display_inventory();
3784                                 }
3785
3786                                 /* The item is gone */
3787                                 else if (st_ptr->stock_num != i)
3788                                 {
3789                                         /* Pick the correct screen */
3790                                         if (store_top >= st_ptr->stock_num) store_top -= store_bottom;
3791
3792                                         /* Redraw everything */
3793                                         display_inventory();
3794                                 }
3795
3796                                 /* Item is still here */
3797                                 else
3798                                 {
3799                                         /* Redraw the item */
3800                                         display_entry(item);
3801                                 }
3802                         }
3803
3804                         /* Player cannot afford it */
3805                         else
3806                         {
3807                                 /* Simple message (no insult) */
3808 #ifdef JP
3809                                 msg_print("お金が足りません。");
3810 #else
3811                                 msg_print("You do not have enough gold.");
3812 #endif
3813
3814                         }
3815                 }
3816         }
3817
3818         /* Home is much easier */
3819         else
3820         {
3821                 bool combined_or_reordered;
3822
3823                 /* Distribute charges of wands/rods */
3824                 distribute_charges(o_ptr, j_ptr, amt);
3825
3826                 /* Give it to the player */
3827                 item_new = inven_carry(j_ptr);
3828
3829                 /* Describe just the result */
3830                 object_desc(o_name, &inventory[item_new], 0);
3831
3832                 /* Message */
3833 #ifdef JP
3834                 msg_format("%s(%c)を取った。",
3835 #else
3836                 msg_format("You have %s (%c).",
3837 #endif
3838  o_name, index_to_label(item_new));
3839
3840                 /* Handle stuff */
3841                 handle_stuff();
3842
3843                 /* Take note if we take the last one */
3844                 i = st_ptr->stock_num;
3845
3846                 /* Remove the items from the home */
3847                 store_item_increase(item, -amt);
3848                 store_item_optimize(item);
3849
3850                 combined_or_reordered = combine_and_reorder_home(STORE_HOME);
3851
3852                 /* Hack -- Item is still here */
3853                 if (i == st_ptr->stock_num)
3854                 {
3855                         /* Redraw everything */
3856                         if (combined_or_reordered) display_inventory();
3857
3858                         /* Redraw the item */
3859                         else display_entry(item);
3860                 }
3861
3862                 /* The item is gone */
3863                 else
3864                 {
3865                         /* Nothing left */
3866                         if (st_ptr->stock_num == 0) store_top = 0;
3867
3868                         /* Nothing left on that screen */
3869                         else if (store_top >= st_ptr->stock_num) store_top -= store_bottom;
3870
3871                         /* Redraw everything */
3872                         display_inventory();
3873
3874                         chg_virtue(V_SACRIFICE, 1);
3875                 }
3876         }
3877
3878         /* Not kicked out */
3879         return;
3880 }
3881
3882
3883 /*!
3884  * @brief 店からの売却処理のメインルーチン /
3885  * Sell an item to the store (or home)
3886  * @return なし
3887  */
3888 static void store_sell(void)
3889 {
3890         int choice;
3891         OBJECT_IDX item;
3892         int item_pos;
3893         int amt;
3894
3895         s32b price, value, dummy;
3896
3897         object_type forge;
3898         object_type *q_ptr;
3899
3900         object_type *o_ptr;
3901
3902         cptr q, s;
3903
3904         char o_name[MAX_NLEN];
3905
3906
3907         /* Prepare a prompt */
3908         if (cur_store_num == STORE_HOME)
3909 #ifdef JP
3910         q = "どのアイテムを置きますか? ";
3911 #else
3912                 q = "Drop which item? ";
3913 #endif
3914
3915         else if (cur_store_num == STORE_MUSEUM)
3916 #ifdef JP
3917         q = "どのアイテムを寄贈しますか? ";
3918 #else
3919                 q = "Give which item? ";
3920 #endif
3921
3922         else
3923 #ifdef JP
3924                 q = "どのアイテムを売りますか? ";
3925 #else
3926                 q = "Sell which item? ";
3927 #endif
3928
3929
3930         item_tester_no_ryoute = TRUE;
3931         /* Only allow items the store will buy */
3932         item_tester_hook = store_will_buy;
3933
3934         /* Get an item */
3935         /* 我が家でおかしなメッセージが出るオリジナルのバグを修正 */
3936         if (cur_store_num == STORE_HOME)
3937         {
3938 #ifdef JP
3939                 s = "置けるアイテムを持っていません。";
3940 #else
3941                 s = "You don't have any item to drop.";
3942 #endif
3943         }
3944         else if (cur_store_num == STORE_MUSEUM)
3945         {
3946 #ifdef JP
3947                 s = "寄贈できるアイテムを持っていません。";
3948 #else
3949                 s = "You don't have any item to give.";
3950 #endif
3951         }
3952         else
3953         {
3954 #ifdef JP
3955                 s = "欲しい物がないですねえ。";
3956 #else
3957                 s = "You have nothing that I want.";
3958 #endif
3959         }
3960
3961         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return;
3962
3963         /* Get the item (in the pack) */
3964         if (item >= 0)
3965         {
3966                 o_ptr = &inventory[item];
3967         }
3968
3969         /* Get the item (on the floor) */
3970         else
3971         {
3972                 o_ptr = &o_list[0 - item];
3973         }
3974
3975
3976         /* Hack -- Cannot remove cursed items */
3977         if ((item >= INVEN_RARM) && object_is_cursed(o_ptr))
3978         {
3979                 /* Oops */
3980 #ifdef JP
3981                 msg_print("ふーむ、どうやらそれは呪われているようだね。");
3982 #else
3983                 msg_print("Hmmm, it seems to be cursed.");
3984 #endif
3985
3986
3987                 /* Nope */
3988                 return;
3989         }
3990
3991
3992         /* Assume one item */
3993         amt = 1;
3994
3995         /* Find out how many the player wants (letter means "all") */
3996         if (o_ptr->number > 1)
3997         {
3998                 /* Get a quantity */
3999                 amt = get_quantity(NULL, o_ptr->number);
4000
4001                 /* Allow user abort */
4002                 if (amt <= 0) return;
4003         }
4004
4005         /* Get local object */
4006         q_ptr = &forge;
4007
4008         /* Get a copy of the object */
4009         object_copy(q_ptr, o_ptr);
4010
4011         /* Modify quantity */
4012         q_ptr->number = amt;
4013
4014         /*
4015          * Hack -- If a rod or wand, allocate total maximum
4016          * timeouts or charges to those being sold. -LM-
4017          */
4018         if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND))
4019         {
4020                 q_ptr->pval = o_ptr->pval * amt / o_ptr->number;
4021         }
4022
4023         /* Get a full description */
4024         object_desc(o_name, q_ptr, 0);
4025
4026         /* Remove any inscription, feeling for stores */
4027         if ((cur_store_num != STORE_HOME) && (cur_store_num != STORE_MUSEUM))
4028         {
4029                 q_ptr->inscription = 0;
4030                 q_ptr->feeling = FEEL_NONE;
4031         }
4032
4033         /* Is there room in the store (or the home?) */
4034         if (!store_check_num(q_ptr))
4035         {
4036                 if (cur_store_num == STORE_HOME)
4037 #ifdef JP
4038                         msg_print("我が家にはもう置く場所がない。");
4039 #else
4040                         msg_print("Your home is full.");
4041 #endif
4042
4043                 else if (cur_store_num == STORE_MUSEUM)
4044 #ifdef JP
4045                         msg_print("博物館はもう満杯だ。");
4046 #else
4047                         msg_print("Museum is full.");
4048 #endif
4049
4050                 else
4051 #ifdef JP
4052                         msg_print("すいませんが、店にはもう置く場所がありません。");
4053 #else
4054                         msg_print("I have not the room in my store to keep it.");
4055 #endif
4056
4057                 return;
4058         }
4059
4060
4061         /* Real store */
4062         if ((cur_store_num != STORE_HOME) && (cur_store_num != STORE_MUSEUM))
4063         {
4064                 /* Describe the transaction */
4065 #ifdef JP
4066                 msg_format("%s(%c)を売却する。", o_name, index_to_label(item));
4067 #else
4068                 msg_format("Selling %s (%c).", o_name, index_to_label(item));
4069 #endif
4070
4071                 msg_print(NULL);
4072
4073                 /* Haggle for it */
4074                 choice = sell_haggle(q_ptr, &price);
4075
4076                 /* Kicked out */
4077                 if (st_ptr->store_open >= turn) return;
4078
4079                 /* Sold... */
4080                 if (choice == 0)
4081                 {
4082                         /* Say "okay" */
4083                         say_comment_1();
4084
4085                         /* Make a sound */
4086                         sound(SOUND_SELL);
4087
4088                         /* Be happy */
4089                         if (cur_store_num == STORE_BLACK) /* The black market is illegal! */
4090                                 chg_virtue(V_JUSTICE, -1);
4091
4092                         if((o_ptr->tval == TV_BOTTLE) && (cur_store_num != STORE_HOME))
4093                                 chg_virtue(V_NATURE, 1);
4094                         decrease_insults();
4095
4096                         /* Get some money */
4097                         p_ptr->au += price;
4098
4099                         /* Update the display */
4100                         store_prt_gold();
4101
4102                         /* Get the "apparent" value */
4103                         dummy = object_value(q_ptr) * q_ptr->number;
4104
4105                         /* Identify it */
4106                         identify_item(o_ptr);
4107
4108                         /* Get local object */
4109                         q_ptr = &forge;
4110
4111                         /* Get a copy of the object */
4112                         object_copy(q_ptr, o_ptr);
4113
4114                         /* Modify quantity */
4115                         q_ptr->number = amt;
4116
4117                         /* Make it look like to be known */
4118                         q_ptr->ident |= IDENT_STORE;
4119
4120                         /*
4121                          * Hack -- If a rod or wand, let the shopkeeper know just
4122                          * how many charges he really paid for. -LM-
4123                          */
4124                         if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND))
4125                         {
4126                                 q_ptr->pval = o_ptr->pval * amt / o_ptr->number;
4127                         }
4128
4129                         /* Get the "actual" value */
4130                         value = object_value(q_ptr) * q_ptr->number;
4131
4132                         /* Get the description all over again */
4133                         object_desc(o_name, q_ptr, 0);
4134
4135                         /* Describe the result (in message buffer) */
4136 #ifdef JP
4137 msg_format("%sを $%ldで売却しました。", o_name, (long)price);
4138 #else
4139                         msg_format("You sold %s for %ld gold.", o_name, (long)price);
4140 #endif
4141
4142                         if (record_sell) do_cmd_write_nikki(NIKKI_SELL, 0, o_name);
4143
4144                         if (!((o_ptr->tval == TV_FIGURINE) && (value > 0)))
4145                         {
4146                          /* Analyze the prices (and comment verbally) unless a figurine*/
4147                         purchase_analyze(price, value, dummy);
4148                         }
4149
4150                         /*
4151                          * Hack -- Allocate charges between those wands or rods sold
4152                          * and retained, unless all are being sold. -LM-
4153                          */
4154                         distribute_charges(o_ptr, q_ptr, amt);
4155
4156                         /* Reset timeouts of the sold items */
4157                         q_ptr->timeout = 0;
4158
4159                         /* Take the item from the player, describe the result */
4160                         inven_item_increase(item, -amt);
4161                         inven_item_describe(item);
4162
4163                         /* If items remain, auto-inscribe before optimizing */
4164                         if (o_ptr->number > 0)
4165                                 autopick_alter_item(item, FALSE);
4166
4167                         inven_item_optimize(item);
4168
4169                         /* Handle stuff */
4170                         handle_stuff();
4171
4172                         /* The store gets that (known) item */
4173                         item_pos = store_carry(q_ptr);
4174
4175                         /* Re-display if item is now in store */
4176                         if (item_pos >= 0)
4177                         {
4178                                 store_top = (item_pos / store_bottom) * store_bottom;
4179                                 display_inventory();
4180                         }
4181                 }
4182         }
4183
4184         /* Player is at museum */
4185         else if (cur_store_num == STORE_MUSEUM)
4186         {
4187                 char o2_name[MAX_NLEN];
4188                 object_desc(o2_name, q_ptr, OD_NAME_ONLY);
4189
4190                 if (-1 == store_check_num(q_ptr))
4191                 {
4192 #ifdef JP
4193                         msg_print("それと同じ品物は既に博物館にあるようです。");
4194 #else
4195                         msg_print("The same object as it is already in the Museum.");
4196 #endif
4197                 }
4198                 else
4199                 {
4200 #ifdef JP
4201                         msg_print("博物館に寄贈したものは取り出すことができません!!");
4202 #else
4203                         msg_print("You cannot take items which is given to the Museum back!!");
4204 #endif
4205                 }
4206 #ifdef JP
4207                 if (!get_check(format("本当に%sを寄贈しますか?", o2_name))) return;
4208 #else
4209                 if (!get_check(format("Really give %s to the Museum? ", o2_name))) return;
4210 #endif
4211
4212                 /* Identify it */
4213                 identify_item(q_ptr);
4214                 q_ptr->ident |= IDENT_MENTAL;
4215
4216                 /* Distribute charges of wands/rods */
4217                 distribute_charges(o_ptr, q_ptr, amt);
4218
4219                 /* Describe */
4220 #ifdef JP
4221                 msg_format("%sを置いた。(%c)", o_name, index_to_label(item));
4222 #else
4223                 msg_format("You drop %s (%c).", o_name, index_to_label(item));
4224 #endif
4225
4226                 choice = 0;
4227
4228                 /* Take it from the players inventory */
4229                 inven_item_increase(item, -amt);
4230                 inven_item_describe(item);
4231                 inven_item_optimize(item);
4232
4233                 /* Handle stuff */
4234                 handle_stuff();
4235
4236                 /* Let the home carry it */
4237                 item_pos = home_carry(q_ptr);
4238
4239                 /* Update store display */
4240                 if (item_pos >= 0)
4241                 {
4242                         store_top = (item_pos / store_bottom) * store_bottom;
4243                         display_inventory();
4244                 }
4245         }
4246         /* Player is at home */
4247         else
4248         {
4249                 /* Distribute charges of wands/rods */
4250                 distribute_charges(o_ptr, q_ptr, amt);
4251
4252                 /* Describe */
4253 #ifdef JP
4254                 msg_format("%sを置いた。(%c)", o_name, index_to_label(item));
4255 #else
4256                 msg_format("You drop %s (%c).", o_name, index_to_label(item));
4257 #endif
4258
4259                 choice = 0;
4260
4261                 /* Take it from the players inventory */
4262                 inven_item_increase(item, -amt);
4263                 inven_item_describe(item);
4264                 inven_item_optimize(item);
4265
4266                 /* Handle stuff */
4267                 handle_stuff();
4268
4269                 /* Let the home carry it */
4270                 item_pos = home_carry(q_ptr);
4271
4272                 /* Update store display */
4273                 if (item_pos >= 0)
4274                 {
4275                         store_top = (item_pos / store_bottom) * store_bottom;
4276                         display_inventory();
4277                 }
4278         }
4279
4280         if ((choice == 0) && (item >= INVEN_RARM))
4281         {
4282                 calc_android_exp();
4283                 kamaenaoshi(item);
4284         }
4285 }
4286
4287
4288 /*!
4289  * @brief 店のアイテムを調べるコマンドのメインルーチン /
4290  * Examine an item in a store                      -JDL-
4291  * @return なし
4292  */
4293 static void store_examine(void)
4294 {
4295         int         i;
4296         COMMAND_CODE item;
4297         object_type *o_ptr;
4298         char        o_name[MAX_NLEN];
4299         char        out_val[160];
4300
4301
4302         /* Empty? */
4303         if (st_ptr->stock_num <= 0)
4304         {
4305                 if (cur_store_num == STORE_HOME)
4306 #ifdef JP
4307                         msg_print("我が家には何も置いてありません。");
4308 #else
4309                         msg_print("Your home is empty.");
4310 #endif
4311
4312                 else if (cur_store_num == STORE_MUSEUM)
4313 #ifdef JP
4314                         msg_print("博物館には何も置いてありません。");
4315 #else
4316                         msg_print("Museum is empty.");
4317 #endif
4318
4319                 else
4320 #ifdef JP
4321                         msg_print("現在商品の在庫を切らしています。");
4322 #else
4323                         msg_print("I am currently out of stock.");
4324 #endif
4325
4326                 return;
4327         }
4328
4329
4330         /* Find the number of objects on this and following pages */
4331         i = (st_ptr->stock_num - store_top);
4332
4333         /* And then restrict it to the current page */
4334         if (i > store_bottom) i = store_bottom;
4335
4336         /* Prompt */
4337 #ifdef JP
4338 sprintf(out_val, "どれを調べますか?");
4339 #else
4340         sprintf(out_val, "Which item do you want to examine? ");
4341 #endif
4342
4343
4344         /* Get the item number to be examined */
4345         if (!get_stock(&item, out_val, 0, i - 1)) return;
4346
4347         /* Get the actual index */
4348         item = item + store_top;
4349
4350         /* Get the actual item */
4351         o_ptr = &st_ptr->stock[item];
4352
4353         /* Require full knowledge */
4354         if (!(o_ptr->ident & IDENT_MENTAL))
4355         {
4356                 /* This can only happen in the home */
4357 #ifdef JP
4358 msg_print("このアイテムについて特に知っていることはない。");
4359 #else
4360                 msg_print("You have no special knowledge about that item.");
4361 #endif
4362
4363                 return;
4364         }
4365
4366         /* Description */
4367         object_desc(o_name, o_ptr, 0);
4368
4369         /* Describe */
4370 #ifdef JP
4371 msg_format("%sを調べている...", o_name);
4372 #else
4373         msg_format("Examining %s...", o_name);
4374 #endif
4375
4376
4377         /* Describe it fully */
4378         if (!screen_object(o_ptr, SCROBJ_FORCE_DETAIL))
4379 #ifdef JP
4380 msg_print("特に変わったところはないようだ。");
4381 #else
4382                 msg_print("You see nothing special.");
4383 #endif
4384
4385
4386         return;
4387 }
4388
4389
4390 /*!
4391  * @brief 博物館のアイテムを除去するコマンドのメインルーチン /
4392  * Remove an item from museum (Originally from TOband)
4393  * @return なし
4394  */
4395 static void museum_remove_object(void)
4396 {
4397         int         i;
4398         COMMAND_CODE item;
4399         object_type *o_ptr;
4400         char        o_name[MAX_NLEN];
4401         char        out_val[160];
4402
4403         /* Empty? */
4404         if (st_ptr->stock_num <= 0)
4405         {
4406 #ifdef JP
4407                 msg_print("博物館には何も置いてありません。");
4408 #else
4409                 msg_print("Museum is empty.");
4410 #endif
4411
4412                 return;
4413         }
4414
4415         /* Find the number of objects on this and following pages */
4416         i = st_ptr->stock_num - store_top;
4417
4418         /* And then restrict it to the current page */
4419         if (i > store_bottom) i = store_bottom;
4420
4421         /* Prompt */
4422 #ifdef JP
4423         sprintf(out_val, "どのアイテムの展示をやめさせますか?");
4424 #else
4425         sprintf(out_val, "Which item do you want to order to remove? ");
4426 #endif
4427
4428         /* Get the item number to be removed */
4429         if (!get_stock(&item, out_val, 0, i - 1)) return;
4430
4431         /* Get the actual index */
4432         item = item + store_top;
4433
4434         /* Get the actual item */
4435         o_ptr = &st_ptr->stock[item];
4436
4437         /* Description */
4438         object_desc(o_name, o_ptr, 0);
4439
4440 #ifdef JP
4441         msg_print("展示をやめさせたアイテムは二度と見ることはできません!");
4442         if (!get_check(format("本当に%sの展示をやめさせますか?", o_name))) return;
4443 #else
4444         msg_print("You cannot see items which is removed from the Museum!");
4445         if (!get_check(format("Really order to remove %s from the Museum? ", o_name))) return;
4446 #endif
4447
4448         /* Message */
4449 #ifdef JP
4450         msg_format("%sの展示をやめさせた。", o_name);
4451 #else
4452         msg_format("You ordered to remove %s.", o_name);
4453 #endif
4454
4455         /* Remove the items from the home */
4456         store_item_increase(item, -o_ptr->number);
4457         store_item_optimize(item);
4458
4459         (void)combine_and_reorder_home(STORE_MUSEUM);
4460
4461         /* The item is gone */
4462
4463         /* Nothing left */
4464         if (st_ptr->stock_num == 0) store_top = 0;
4465
4466         /* Nothing left on that screen */
4467         else if (store_top >= st_ptr->stock_num) store_top -= store_bottom;
4468
4469         /* Redraw everything */
4470         display_inventory();
4471
4472         return;
4473 }
4474
4475
4476 /*
4477  * Hack -- set this to leave the store
4478  */
4479 static bool leave_store = FALSE;
4480
4481
4482 /*!
4483  * @brief 店舗処理コマンド選択のメインルーチン /
4484  * Process a command in a store
4485  * @return なし
4486  * @note
4487  * <pre>
4488  * Note that we must allow the use of a few "special" commands
4489  * in the stores which are not allowed in the dungeon, and we
4490  * must disable some commands which are allowed in the dungeon
4491  * but not in the stores, to prevent chaos.
4492  * </pre>
4493  */
4494 static void store_process_command(void)
4495 {
4496 #ifdef ALLOW_REPEAT /* TNB */
4497
4498         /* Handle repeating the last command */
4499         repeat_check();
4500
4501 #endif /* ALLOW_REPEAT -- TNB */
4502
4503         if (rogue_like_commands && command_cmd == 'l')
4504         {
4505                 command_cmd = 'x';      /* hack! */
4506         }
4507
4508         /* Parse the command */
4509         switch (command_cmd)
4510         {
4511                 /* Leave */
4512                 case ESCAPE:
4513                 {
4514                         leave_store = TRUE;
4515                         break;
4516                 }
4517
4518                 /* 日本語版追加 */
4519                 /* 1 ページ戻るコマンド: 我が家のページ数が多いので重宝するはず By BUG */
4520                 case '-':
4521                 {
4522                         if (st_ptr->stock_num <= store_bottom) {
4523 #ifdef JP
4524                                 msg_print("これで全部です。");
4525 #else
4526                                 msg_print("Entire inventory is shown.");
4527 #endif
4528                         }
4529                         else{
4530                                 store_top -= store_bottom;
4531                                 if ( store_top < 0 )
4532                                         store_top = ((st_ptr->stock_num - 1 )/store_bottom) * store_bottom;
4533                                 if ( (cur_store_num == STORE_HOME) && (powerup_home == FALSE) )
4534                                         if ( store_top >= store_bottom ) store_top = store_bottom;
4535                                 display_inventory();
4536                         }
4537                         break;
4538                 }
4539
4540                 /* Browse */
4541                 case ' ':
4542                 {
4543                         if (st_ptr->stock_num <= store_bottom)
4544                         {
4545 #ifdef JP
4546                                 msg_print("これで全部です。");
4547 #else
4548                                 msg_print("Entire inventory is shown.");
4549 #endif
4550
4551                         }
4552                         else
4553                         {
4554                                 store_top += store_bottom;
4555                                 /*
4556                                  * 隠しオプション(powerup_home)がセットされていないときは
4557                                  * 我が家では 2 ページまでしか表示しない
4558                                  */
4559                                 if ((cur_store_num == STORE_HOME) && 
4560                                     (powerup_home == FALSE) && 
4561                                         (st_ptr->stock_num >= STORE_INVEN_MAX))
4562                                 {
4563                                         if (store_top >= (STORE_INVEN_MAX - 1))
4564                                         {
4565                                                 store_top = 0;
4566                                         }
4567                                 }
4568                                 else
4569                                 {
4570                                         if (store_top >= st_ptr->stock_num) store_top = 0;
4571                                 }
4572
4573                                 display_inventory();
4574                         }
4575                         break;
4576                 }
4577
4578                 /* Redraw */
4579                 case KTRL('R'):
4580                 {
4581                         do_cmd_redraw();
4582                         display_store();
4583                         break;
4584                 }
4585
4586                 /* Get (purchase) */
4587                 case 'g':
4588                 {
4589                         store_purchase();
4590                         break;
4591                 }
4592
4593                 /* Drop (Sell) */
4594                 case 'd':
4595                 {
4596                         store_sell();
4597                         break;
4598                 }
4599
4600                 /* Examine */
4601                 case 'x':
4602                 {
4603                         store_examine();
4604                         break;
4605                 }
4606
4607                 /* Ignore return */
4608                 case '\r':
4609                 {
4610                         break;
4611                 }
4612
4613                 /*** Inventory Commands ***/
4614
4615                 /* Wear/wield equipment */
4616                 case 'w':
4617                 {
4618                         do_cmd_wield();
4619                         break;
4620                 }
4621
4622                 /* Take off equipment */
4623                 case 't':
4624                 {
4625                         do_cmd_takeoff();
4626                         break;
4627                 }
4628
4629                 /* Destroy an item */
4630                 case 'k':
4631                 {
4632                         do_cmd_destroy();
4633                         break;
4634                 }
4635
4636                 /* Equipment list */
4637                 case 'e':
4638                 {
4639                         do_cmd_equip();
4640                         break;
4641                 }
4642
4643                 /* Inventory list */
4644                 case 'i':
4645                 {
4646                         do_cmd_inven();
4647                         break;
4648                 }
4649
4650
4651                 /*** Various commands ***/
4652
4653                 /* Identify an object */
4654                 case 'I':
4655                 {
4656                         do_cmd_observe();
4657                         break;
4658                 }
4659
4660                 /* Hack -- toggle windows */
4661                 case KTRL('I'):
4662                 {
4663                         toggle_inven_equip();
4664                         break;
4665                 }
4666
4667
4668
4669                 /*** Use various objects ***/
4670
4671                 /* Browse a book */
4672                 case 'b':
4673                 {
4674                         if ( (p_ptr->pclass == CLASS_MINDCRAFTER) ||
4675                              (p_ptr->pclass == CLASS_BERSERKER) ||
4676                              (p_ptr->pclass == CLASS_NINJA) ||
4677                              (p_ptr->pclass == CLASS_MIRROR_MASTER) 
4678                              ) do_cmd_mind_browse();
4679                         else if (p_ptr->pclass == CLASS_SMITH)
4680                                 do_cmd_kaji(TRUE);
4681                         else if (p_ptr->pclass == CLASS_MAGIC_EATER)
4682                                 do_cmd_magic_eater(TRUE, FALSE);
4683                         else if (p_ptr->pclass == CLASS_SNIPER)
4684                                 do_cmd_snipe_browse();
4685                         else do_cmd_browse();
4686                         break;
4687                 }
4688
4689                 /* Inscribe an object */
4690                 case '{':
4691                 {
4692                         do_cmd_inscribe();
4693                         break;
4694                 }
4695
4696                 /* Uninscribe an object */
4697                 case '}':
4698                 {
4699                         do_cmd_uninscribe();
4700                         break;
4701                 }
4702
4703
4704
4705                 /*** Help and Such ***/
4706
4707                 /* Help */
4708                 case '?':
4709                 {
4710                         do_cmd_help();
4711                         break;
4712                 }
4713
4714                 /* Identify symbol */
4715                 case '/':
4716                 {
4717                         do_cmd_query_symbol();
4718                         break;
4719                 }
4720
4721                 /* Character description */
4722                 case 'C':
4723                 {
4724                         p_ptr->town_num = old_town_num;
4725                         do_cmd_change_name();
4726                         p_ptr->town_num = inner_town_num;
4727                         display_store();
4728                         break;
4729                 }
4730
4731
4732                 /*** System Commands ***/
4733
4734                 /* Hack -- User interface */
4735                 case '!':
4736                 {
4737                         (void)Term_user(0);
4738                         break;
4739                 }
4740
4741                 /* Single line from a pref file */
4742                 case '"':
4743                 {
4744                         p_ptr->town_num = old_town_num;
4745                         do_cmd_pref();
4746                         p_ptr->town_num = inner_town_num;
4747                         break;
4748                 }
4749
4750                 /* Interact with macros */
4751                 case '@':
4752                 {
4753                         p_ptr->town_num = old_town_num;
4754                         do_cmd_macros();
4755                         p_ptr->town_num = inner_town_num;
4756                         break;
4757                 }
4758
4759                 /* Interact with visuals */
4760                 case '%':
4761                 {
4762                         p_ptr->town_num = old_town_num;
4763                         do_cmd_visuals();
4764                         p_ptr->town_num = inner_town_num;
4765                         break;
4766                 }
4767
4768                 /* Interact with colors */
4769                 case '&':
4770                 {
4771                         p_ptr->town_num = old_town_num;
4772                         do_cmd_colors();
4773                         p_ptr->town_num = inner_town_num;
4774                         break;
4775                 }
4776
4777                 /* Interact with options */
4778                 case '=':
4779                 {
4780                         do_cmd_options();
4781                         (void)combine_and_reorder_home(STORE_HOME);
4782                         do_cmd_redraw();
4783                         display_store();
4784                         break;
4785                 }
4786
4787                 /*** Misc Commands ***/
4788
4789                 /* Take notes */
4790                 case ':':
4791                 {
4792                         do_cmd_note();
4793                         break;
4794                 }
4795
4796                 /* Version info */
4797                 case 'V':
4798                 {
4799                         do_cmd_version();
4800                         break;
4801                 }
4802
4803                 /* Repeat level feeling */
4804                 case KTRL('F'):
4805                 {
4806                         do_cmd_feeling();
4807                         break;
4808                 }
4809
4810                 /* Show previous message */
4811                 case KTRL('O'):
4812                 {
4813                         do_cmd_message_one();
4814                         break;
4815                 }
4816
4817                 /* Show previous messages */
4818                 case KTRL('P'):
4819                 {
4820                         do_cmd_messages(0);
4821                         break;
4822                 }
4823
4824                 case '|':
4825                 {
4826                         do_cmd_nikki();
4827                         break;
4828                 }
4829
4830                 /* Check artifacts, uniques etc. */
4831                 case '~':
4832                 {
4833                         do_cmd_knowledge();
4834                         break;
4835                 }
4836
4837                 /* Load "screen dump" */
4838                 case '(':
4839                 {
4840                         do_cmd_load_screen();
4841                         break;
4842                 }
4843
4844                 /* Save "screen dump" */
4845                 case ')':
4846                 {
4847                         do_cmd_save_screen();
4848                         break;
4849                 }
4850
4851                 /* Hack -- Unknown command */
4852                 default:
4853                 {
4854                         if ((cur_store_num == STORE_MUSEUM) && (command_cmd == 'r'))
4855                         {
4856                                 museum_remove_object();
4857                         }
4858                         else
4859                         {
4860 #ifdef JP
4861                                 msg_print("そのコマンドは店の中では使えません。");
4862 #else
4863                                 msg_print("That command does not work in stores.");
4864 #endif
4865                         }
4866
4867                         break;
4868                 }
4869         }
4870 }
4871
4872
4873 /*!
4874  * @brief 店舗処理全体のメインルーチン /
4875  * Enter a store, and interact with it. *
4876  * @return なし
4877  * @note
4878  * <pre>
4879  * Note that we use the standard "request_command()" function
4880  * to get a command, allowing us to use "command_arg" and all
4881  * command macros and other nifty stuff, but we use the special
4882  * "shopping" argument, to force certain commands to be converted
4883  * into other commands, normally, we convert "p" (pray) and "m"
4884  * (cast magic) into "g" (get), and "s" (search) into "d" (drop).
4885  * </pre>
4886  */
4887 void do_cmd_store(void)
4888 {
4889         int         which;
4890         int         maintain_num;
4891         int         i;
4892         cave_type   *c_ptr;
4893         bool        need_redraw_store_inv; /* To redraw missiles damage and prices in store */
4894         int w, h;
4895
4896         /* Get term size */
4897         Term_get_size(&w, &h);
4898
4899         /* Calculate stocks per 1 page */
4900         xtra_stock = MIN(14+26, ((h > 24) ? (h - 24) : 0));
4901         store_bottom = MIN_STOCK + xtra_stock;
4902
4903         /* Access the player grid */
4904         c_ptr = &cave[p_ptr->y][p_ptr->x];
4905
4906         /* Verify a store */
4907         if (!cave_have_flag_grid(c_ptr, FF_STORE))
4908         {
4909 #ifdef JP
4910                 msg_print("ここには店がありません。");
4911 #else
4912                 msg_print("You see no store here.");
4913 #endif
4914
4915                 return;
4916         }
4917
4918         /* Extract the store code */
4919         which = f_info[c_ptr->feat].subtype;
4920
4921         old_town_num = p_ptr->town_num;
4922         if ((which == STORE_HOME) || (which == STORE_MUSEUM)) p_ptr->town_num = 1;
4923         if (dun_level) p_ptr->town_num = NO_TOWN;
4924         inner_town_num = p_ptr->town_num;
4925
4926         /* Hack -- Check the "locked doors" */
4927         if ((town[p_ptr->town_num].store[which].store_open >= turn) ||
4928             (ironman_shops))
4929         {
4930 #ifdef JP
4931                 msg_print("ドアに鍵がかかっている。");
4932 #else
4933                 msg_print("The doors are locked.");
4934 #endif
4935
4936                 p_ptr->town_num = old_town_num;
4937                 return;
4938         }
4939
4940         /* Calculate the number of store maintainances since the last visit */
4941         maintain_num = (turn - town[p_ptr->town_num].store[which].last_visit) / (TURNS_PER_TICK * STORE_TICKS);
4942
4943         /* Maintain the store max. 10 times */
4944         if (maintain_num > 10) maintain_num = 10;
4945
4946         if (maintain_num)
4947         {
4948                 /* Maintain the store */
4949                 for (i = 0; i < maintain_num; i++)
4950                         store_maint(p_ptr->town_num, which);
4951
4952                 /* Save the visit */
4953                 town[p_ptr->town_num].store[which].last_visit = turn;
4954         }
4955
4956         /* Forget the lite */
4957         forget_lite();
4958
4959         /* Forget the view */
4960         forget_view();
4961
4962
4963         /* Hack -- Character is in "icky" mode */
4964         character_icky = TRUE;
4965
4966
4967         /* No command argument */
4968         command_arg = 0;
4969
4970         /* No repeated command */
4971         command_rep = 0;
4972
4973         /* No automatic command */
4974         command_new = 0;
4975
4976         /* Do not expand macros */
4977         get_com_no_macros = TRUE;
4978
4979         /* Save the store number */
4980         cur_store_num = which;
4981
4982         /* Hack -- save the store feature */
4983         cur_store_feat = c_ptr->feat;
4984
4985         /* Save the store and owner pointers */
4986         st_ptr = &town[p_ptr->town_num].store[cur_store_num];
4987         ot_ptr = &owners[cur_store_num][st_ptr->owner];
4988
4989
4990         /* Start at the beginning */
4991         store_top = 0;
4992
4993         play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_BUILD);
4994
4995         /* Display the store */
4996         display_store();
4997
4998         /* Do not leave */
4999         leave_store = FALSE;
5000
5001         /* Interact with player */
5002         while (!leave_store)
5003         {
5004                 /* Hack -- Clear line 1 */
5005                 prt("", 1, 0);
5006
5007                 /* Clear */
5008                 clear_from(20 + xtra_stock);
5009
5010
5011                 /* Basic commands */
5012 #ifdef JP
5013                 prt(" ESC) 建物から出る", 21 + xtra_stock, 0);
5014 #else
5015                 prt(" ESC) Exit from Building.", 21 + xtra_stock, 0);
5016 #endif
5017
5018
5019                 /* Browse if necessary */
5020                 if (st_ptr->stock_num > store_bottom)
5021                 {
5022 #ifdef JP
5023                         prt(" -)前ページ", 22 + xtra_stock, 0);
5024                         prt(" スペース) 次ページ", 23 + xtra_stock, 0);
5025 #else
5026                         prt(" -) Previous page", 22 + xtra_stock, 0);
5027                         prt(" SPACE) Next page", 23 + xtra_stock, 0);
5028 #endif
5029
5030                 }
5031
5032                 /* Home commands */
5033                 if (cur_store_num == STORE_HOME)
5034                 {
5035 #ifdef JP
5036                         prt("g) アイテムを取る", 21 + xtra_stock, 27);
5037                         prt("d) アイテムを置く", 22 + xtra_stock, 27);
5038                         prt("x) 家のアイテムを調べる", 23 + xtra_stock, 27);
5039 #else
5040                         prt("g) Get an item.", 21 + xtra_stock, 27);
5041                         prt("d) Drop an item.", 22 + xtra_stock, 27);
5042                         prt("x) eXamine an item in the home.", 23 + xtra_stock, 27);
5043 #endif
5044                 }
5045
5046                 /* Museum commands */
5047                 else if (cur_store_num == STORE_MUSEUM)
5048                 {
5049 #ifdef JP
5050                         prt("d) アイテムを置く", 21 + xtra_stock, 27);
5051                         prt("r) アイテムの展示をやめる", 22 + xtra_stock, 27);
5052                         prt("x) 博物館のアイテムを調べる", 23 + xtra_stock, 27);
5053 #else
5054                         prt("d) Drop an item.", 21 + xtra_stock, 27);
5055                         prt("r) order to Remove an item.", 22 + xtra_stock, 27);
5056                         prt("x) eXamine an item in the museum.", 23 + xtra_stock, 27);
5057 #endif
5058                 }
5059
5060                 /* Shop commands XXX XXX XXX */
5061                 else
5062                 {
5063 #ifdef JP
5064                         prt("p) 商品を買う", 21 + xtra_stock, 30);
5065                         prt("s) アイテムを売る", 22 + xtra_stock, 30);
5066                         prt("x) 商品を調べる", 23 + xtra_stock,30);
5067 #else
5068                         prt("p) Purchase an item.", 21 + xtra_stock, 30);
5069                         prt("s) Sell an item.", 22 + xtra_stock, 30);
5070                         prt("x) eXamine an item in the shop", 23 + xtra_stock,30);
5071 #endif
5072                 }
5073
5074 #ifdef JP
5075                 /* 基本的なコマンドの追加表示 */
5076
5077                 prt("i/e) 持ち物/装備の一覧", 21 + xtra_stock, 56);
5078
5079                 if (rogue_like_commands)
5080                 {
5081                         prt("w/T) 装備する/はずす", 22 + xtra_stock, 56);
5082                 }
5083                 else
5084                 {
5085                         prt("w/t) 装備する/はずす", 22 + xtra_stock, 56);
5086                 }
5087 #else
5088                 prt("i/e) Inventry/Equipment list", 21 + xtra_stock, 56);
5089
5090                 if (rogue_like_commands)
5091                 {
5092                         prt("w/T) Wear/Take off equipment", 22 + xtra_stock, 56);
5093                 }
5094                 else
5095                 {
5096                         prt("w/t) Wear/Take off equipment", 22 + xtra_stock, 56);
5097                 }
5098 #endif
5099                 /* Prompt */
5100 #ifdef JP
5101                 prt("コマンド:", 20 + xtra_stock, 0);
5102 #else
5103                 prt("You may: ", 20 + xtra_stock, 0);
5104 #endif
5105
5106
5107                 /* Get a command */
5108                 request_command(TRUE);
5109
5110                 /* Process the command */
5111                 store_process_command();
5112
5113                 /*
5114                  * Hack -- To redraw missiles damage and prices in store
5115                  * If player's charisma changes, or if player changes a bow, PU_BONUS is set
5116                  */
5117                 need_redraw_store_inv = (p_ptr->update & PU_BONUS) ? TRUE : FALSE;
5118
5119                 /* Hack -- Character is still in "icky" mode */
5120                 character_icky = TRUE;
5121
5122                 /* Notice stuff */
5123                 notice_stuff();
5124
5125                 /* Handle stuff */
5126                 handle_stuff();
5127
5128                 /* XXX XXX XXX Pack Overflow */
5129                 if (inventory[INVEN_PACK].k_idx)
5130                 {
5131                         int item = INVEN_PACK;
5132
5133                         object_type *o_ptr = &inventory[item];
5134
5135                         /* Hack -- Flee from the store */
5136                         if (cur_store_num != STORE_HOME)
5137                         {
5138                                 /* Message */
5139 #ifdef JP
5140                                 if (cur_store_num == STORE_MUSEUM)
5141                                         msg_print("ザックからアイテムがあふれそうなので、あわてて博物館から出た...");
5142                                 else
5143                                         msg_print("ザックからアイテムがあふれそうなので、あわてて店から出た...");
5144 #else
5145                                 if (cur_store_num == STORE_MUSEUM)
5146                                         msg_print("Your pack is so full that you flee the Museum...");
5147                                 else
5148                                         msg_print("Your pack is so full that you flee the store...");
5149 #endif
5150
5151
5152                                 /* Leave */
5153                                 leave_store = TRUE;
5154                         }
5155
5156                         /* Hack -- Flee from the home */
5157                         else if (!store_check_num(o_ptr))
5158                         {
5159                                 /* Message */
5160 #ifdef JP
5161                                 msg_print("ザックからアイテムがあふれそうなので、あわてて家から出た...");
5162 #else
5163                                 msg_print("Your pack is so full that you flee your home...");
5164 #endif
5165
5166
5167                                 /* Leave */
5168                                 leave_store = TRUE;
5169                         }
5170
5171                         /* Hack -- Drop items into the home */
5172                         else
5173                         {
5174                                 int item_pos;
5175
5176                                 object_type forge;
5177                                 object_type *q_ptr;
5178
5179                                 char o_name[MAX_NLEN];
5180
5181
5182                                 /* Give a message */
5183 #ifdef JP
5184                                 msg_print("ザックからアイテムがあふれてしまった!");
5185 #else
5186                                 msg_print("Your pack overflows!");
5187 #endif
5188
5189
5190                                 /* Get local object */
5191                                 q_ptr = &forge;
5192
5193                                 /* Grab a copy of the item */
5194                                 object_copy(q_ptr, o_ptr);
5195
5196                                 /* Describe it */
5197                                 object_desc(o_name, q_ptr, 0);
5198
5199                                 /* Message */
5200 #ifdef JP
5201                                 msg_format("%sが落ちた。(%c)", o_name, index_to_label(item));
5202 #else
5203                                 msg_format("You drop %s (%c).", o_name, index_to_label(item));
5204 #endif
5205
5206
5207                                 /* Remove it from the players inventory */
5208                                 inven_item_increase(item, -255);
5209                                 inven_item_describe(item);
5210                                 inven_item_optimize(item);
5211
5212                                 /* Handle stuff */
5213                                 handle_stuff();
5214
5215                                 /* Let the home carry it */
5216                                 item_pos = home_carry(q_ptr);
5217
5218                                 /* Redraw the home */
5219                                 if (item_pos >= 0)
5220                                 {
5221                                         store_top = (item_pos / store_bottom) * store_bottom;
5222                                         display_inventory();
5223                                 }
5224                         }
5225                 }
5226
5227                 /* Hack -- Redisplay store prices if charisma changes */
5228                 /* Hack -- Redraw missiles damage if player changes bow */
5229                 if (need_redraw_store_inv) display_inventory();
5230
5231                 /* Hack -- get kicked out of the store */
5232                 if (st_ptr->store_open >= turn) leave_store = TRUE;
5233         }
5234
5235         select_floor_music();
5236
5237         p_ptr->town_num = old_town_num;
5238
5239         /* Free turn XXX XXX XXX */
5240         p_ptr->energy_use = 100;
5241
5242
5243         /* Hack -- Character is no longer in "icky" mode */
5244         character_icky = FALSE;
5245
5246
5247         /* Hack -- Cancel automatic command */
5248         command_new = 0;
5249
5250         /* Hack -- Cancel "see" mode */
5251         command_see = FALSE;
5252
5253         /* Allow expanding macros */
5254         get_com_no_macros = FALSE;
5255
5256         /* Flush messages XXX XXX XXX */
5257         msg_print(NULL);
5258
5259
5260         /* Clear the screen */
5261         Term_clear();
5262
5263
5264         /* Update everything */
5265         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
5266         p_ptr->update |= (PU_MONSTERS);
5267
5268         /* Redraw entire screen */
5269         p_ptr->redraw |= (PR_BASIC | PR_EXTRA | PR_EQUIPPY);
5270
5271         /* Redraw map */
5272         p_ptr->redraw |= (PR_MAP);
5273
5274         /* Window stuff */
5275         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
5276 }
5277
5278
5279
5280 /*!
5281  * @brief 現在の町の店主を交代させる /
5282  * Shuffle one of the stores.
5283  * @param which 店舗種類のID
5284  * @return なし
5285  */
5286 void store_shuffle(int which)
5287 {
5288         int i, j;
5289
5290
5291         /* Ignore home */
5292         if (which == STORE_HOME) return;
5293         if (which == STORE_MUSEUM) return;
5294
5295
5296         /* Save the store index */
5297         cur_store_num = which;
5298
5299         /* Activate that store */
5300         st_ptr = &town[p_ptr->town_num].store[cur_store_num];
5301
5302         j = st_ptr->owner;
5303         /* Pick a new owner */
5304         while(1)
5305         {
5306                 st_ptr->owner = (byte)randint0(MAX_OWNERS);
5307                 if (j == st_ptr->owner) continue;
5308                 for (i = 1;i < max_towns; i++)
5309                 {
5310                         if (i == p_ptr->town_num) continue;
5311                         if (st_ptr->owner == town[i].store[cur_store_num].owner) break;
5312                 }
5313                 if (i == max_towns) break;
5314         }
5315
5316         /* Activate the new owner */
5317         ot_ptr = &owners[cur_store_num][st_ptr->owner];
5318
5319
5320         /* Reset the owner data */
5321         st_ptr->insult_cur = 0;
5322         st_ptr->store_open = 0;
5323         st_ptr->good_buy = 0;
5324         st_ptr->bad_buy = 0;
5325
5326
5327         /* Hack -- discount all the items */
5328         for (i = 0; i < st_ptr->stock_num; i++)
5329         {
5330                 object_type *o_ptr;
5331
5332                 /* Get the item */
5333                 o_ptr = &st_ptr->stock[i];
5334
5335                 if (!object_is_artifact(o_ptr))
5336                 {
5337                         /* Hack -- Sell all non-artifact old items for "half price" */
5338                         o_ptr->discount = 50;
5339
5340                         /* Hack -- Items are no longer "fixed price" */
5341                         o_ptr->ident &= ~(IDENT_FIXED);
5342
5343                         /* Mega-Hack -- Note that the item is "on sale" */
5344 #ifdef JP
5345                         o_ptr->inscription = quark_add("売出中");
5346 #else
5347                         o_ptr->inscription = quark_add("on sale");
5348 #endif
5349                 }
5350         }
5351 }
5352
5353
5354 /*!
5355  * @brief 店の品揃えを変化させる /
5356  * Maintain the inventory at the stores.
5357  * @param town_num 町のID
5358  * @param store_num 店舗種類のID
5359  * @return なし
5360  */
5361 void store_maint(int town_num, int store_num)
5362 {
5363         int             j;
5364
5365         cur_store_num = store_num;
5366
5367         /* Ignore home */
5368         if (store_num == STORE_HOME) return;
5369         if (store_num == STORE_MUSEUM) return;
5370
5371         /* Activate that store */
5372         st_ptr = &town[town_num].store[store_num];
5373
5374         /* Activate the owner */
5375         ot_ptr = &owners[store_num][st_ptr->owner];
5376
5377         /* Store keeper forgives the player */
5378         st_ptr->insult_cur = 0;
5379
5380         /* Mega-Hack -- prune the black market */
5381         if (store_num == STORE_BLACK)
5382         {
5383                 /* Destroy crappy black market items */
5384                 for (j = st_ptr->stock_num - 1; j >= 0; j--)
5385                 {
5386                         object_type *o_ptr = &st_ptr->stock[j];
5387
5388                         /* Destroy crappy items */
5389                         if (black_market_crap(o_ptr))
5390                         {
5391                                 /* Destroy the item */
5392                                 store_item_increase(j, 0 - o_ptr->number);
5393                                 store_item_optimize(j);
5394                         }
5395                 }
5396         }
5397
5398
5399         /* Choose the number of slots to keep */
5400         j = st_ptr->stock_num;
5401
5402         /* Sell a few items */
5403         j = j - randint1(STORE_TURNOVER);
5404
5405         /* Never keep more than "STORE_MAX_KEEP" slots */
5406         if (j > STORE_MAX_KEEP) j = STORE_MAX_KEEP;
5407
5408         /* Always "keep" at least "STORE_MIN_KEEP" items */
5409         if (j < STORE_MIN_KEEP) j = STORE_MIN_KEEP;
5410
5411         /* Hack -- prevent "underflow" */
5412         if (j < 0) j = 0;
5413
5414         /* Destroy objects until only "j" slots are left */
5415         while (st_ptr->stock_num > j) store_delete();
5416
5417
5418         /* Choose the number of slots to fill */
5419         j = st_ptr->stock_num;
5420
5421         /* Buy some more items */
5422         j = j + randint1(STORE_TURNOVER);
5423
5424         /* Never keep more than "STORE_MAX_KEEP" slots */
5425         if (j > STORE_MAX_KEEP) j = STORE_MAX_KEEP;
5426
5427         /* Always "keep" at least "STORE_MIN_KEEP" items */
5428         if (j < STORE_MIN_KEEP) j = STORE_MIN_KEEP;
5429
5430         /* Hack -- prevent "overflow" */
5431         if (j >= st_ptr->stock_size) j = st_ptr->stock_size - 1;
5432
5433         /* Acquire some new items */
5434         while (st_ptr->stock_num < j) store_create();
5435 }
5436
5437
5438 /*!
5439  * @brief 店舗情報を初期化する /
5440  * Initialize the stores
5441  * @param town_num 町のID
5442  * @param store_num 店舗種類のID
5443  * @return なし
5444  */
5445 void store_init(int town_num, int store_num)
5446 {
5447         int             k;
5448
5449         cur_store_num = store_num;
5450
5451         /* Activate that store */
5452         st_ptr = &town[town_num].store[store_num];
5453
5454
5455         /* Pick an owner */
5456         while(1)
5457         {
5458                 int i;
5459
5460                 st_ptr->owner = (byte)randint0(MAX_OWNERS);
5461                 for (i = 1;i < max_towns; i++)
5462                 {
5463                         if (i == town_num) continue;
5464                         if (st_ptr->owner == town[i].store[store_num].owner) break;
5465                 }
5466                 if (i == max_towns) break;
5467         }
5468
5469         /* Activate the new owner */
5470         ot_ptr = &owners[store_num][st_ptr->owner];
5471
5472
5473         /* Initialize the store */
5474         st_ptr->store_open = 0;
5475         st_ptr->insult_cur = 0;
5476         st_ptr->good_buy = 0;
5477         st_ptr->bad_buy = 0;
5478
5479         /* Nothing in stock */
5480         st_ptr->stock_num = 0;
5481
5482         /*
5483          * MEGA-HACK - Last visit to store is
5484          * BEFORE player birth to enable store restocking
5485          */
5486         st_ptr->last_visit = -10L * TURNS_PER_TICK * STORE_TICKS;
5487
5488         /* Clear any old items */
5489         for (k = 0; k < st_ptr->stock_size; k++)
5490         {
5491                 object_wipe(&st_ptr->stock[k]);
5492         }
5493 }
5494
5495
5496 /*!
5497  * @brief アイテムを町のブラックマーケットに移動させる /
5498  * @param o_ptr 移動させたいオブジェクトの構造体参照ポインタ
5499  * @return なし
5500  */
5501 void move_to_black_market(object_type *o_ptr)
5502 {
5503         /* Not in town */
5504         if (!p_ptr->town_num) return;
5505
5506         st_ptr = &town[p_ptr->town_num].store[STORE_BLACK];
5507
5508         o_ptr->ident |= IDENT_STORE;
5509
5510         (void)store_carry(o_ptr);
5511
5512         object_wipe(o_ptr); /* Don't leave a bogus object behind... */
5513 }
5514