OSDN Git Service

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