OSDN Git Service

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