OSDN Git Service

[Refactor] #37353 vault_prep_dragon()整理。 / Refactor vault_prep_dragon().
[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                         /* Get the item */
1579                         o_ptr = &st_ptr->stock[i];
1580
1581                         /* Skip empty items */
1582                         if (!o_ptr->k_idx) continue;
1583
1584                         /* Scan the items above that item */
1585                         for (j = 0; j < i; j++)
1586                         {
1587                                 int max_num;
1588
1589                                 /* Get the item */
1590                                 j_ptr = &st_ptr->stock[j];
1591
1592                                 /* Skip empty items */
1593                                 if (!j_ptr->k_idx) continue;
1594
1595                                 /*
1596                                  * Get maximum number of the stack if these
1597                                  * are similar, get zero otherwise.
1598                                  */
1599                                 max_num = object_similar_part(j_ptr, o_ptr);
1600
1601                                 /* Can we (partialy) drop "o_ptr" onto "j_ptr"? */
1602                                 if (max_num && j_ptr->number < max_num)
1603                                 {
1604                                         if (o_ptr->number + j_ptr->number <= max_num)
1605                                         {
1606                                                 /* Add together the item counts */
1607                                                 object_absorb(j_ptr, o_ptr);
1608
1609                                                 /* One object is gone */
1610                                                 st_ptr->stock_num--;
1611
1612                                                 /* Slide everything down */
1613                                                 for (k = i; k < st_ptr->stock_num; k++)
1614                                                 {
1615                                                         /* Structure copy */
1616                                                         st_ptr->stock[k] = st_ptr->stock[k + 1];
1617                                                 }
1618
1619                                                 /* Erase the "final" slot */
1620                                                 object_wipe(&st_ptr->stock[k]);
1621                                         }
1622                                         else
1623                                         {
1624                                                 ITEM_NUMBER old_num = o_ptr->number;
1625                                                 ITEM_NUMBER remain = j_ptr->number + o_ptr->number - max_num;
1626
1627                                                 /* Add together the item counts */
1628                                                 object_absorb(j_ptr, o_ptr);
1629
1630                                                 o_ptr->number = remain;
1631
1632                                                 /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
1633                                                 if (o_ptr->tval == TV_ROD)
1634                                                 {
1635                                                         o_ptr->pval =  o_ptr->pval * remain / old_num;
1636                                                         o_ptr->timeout = o_ptr->timeout * remain / old_num;
1637                                                 }
1638
1639                                                 /* Hack -- if wands are stacking, combine the charges. -LM- */
1640                                                 else if (o_ptr->tval == TV_WAND)
1641                                                 {
1642                                                         o_ptr->pval = o_ptr->pval * remain / old_num;
1643                                                 }
1644                                         }
1645
1646                                         /* Take note */
1647                                         combined = TRUE;
1648
1649                                         break;
1650                                 }
1651                         }
1652                 }
1653
1654                 flag |= combined;
1655         }
1656         while (combined);
1657
1658         /* Re-order the items in the home (forwards) */
1659         for (i = 0; i < st_ptr->stock_num; i++)
1660         {
1661                 /* Get the item */
1662                 o_ptr = &st_ptr->stock[i];
1663
1664                 /* Skip empty slots */
1665                 if (!o_ptr->k_idx) continue;
1666
1667                 /* Get the "value" of the item */
1668                 o_value = object_value(o_ptr);
1669
1670                 /* Scan every occupied slot */
1671                 for (j = 0; j < st_ptr->stock_num; j++)
1672                 {
1673                         if (object_sort_comp(o_ptr, o_value, &st_ptr->stock[j])) break;
1674                 }
1675
1676                 /* Never move down */
1677                 if (j >= i) continue;
1678
1679                 /* Take note */
1680                 flag = TRUE;
1681
1682                 /* Get local object */
1683                 j_ptr = &forge;
1684
1685                 /* Save a copy of the moving item */
1686                 object_copy(j_ptr, &st_ptr->stock[i]);
1687
1688                 /* Slide the objects */
1689                 for (k = i; k > j; k--)
1690                 {
1691                         /* Slide the item */
1692                         object_copy(&st_ptr->stock[k], &st_ptr->stock[k - 1]);
1693                 }
1694
1695                 /* Insert the moving item */
1696                 object_copy(&st_ptr->stock[j], j_ptr);
1697         }
1698
1699         st_ptr = old_st_ptr;
1700         if (store_num != STORE_HOME)
1701         {
1702                 stack_force_notes = old_stack_force_notes;
1703                 stack_force_costs = old_stack_force_costs;
1704         }
1705
1706         return flag;
1707 }
1708
1709
1710 /*!
1711  * @brief 我が家にオブジェクトを加える /
1712  * Add the item "o_ptr" to the inventory of the "Home"
1713  * @param o_ptr 加えたいオブジェクトの構造体参照ポインタ
1714  * @return 収めた先のID
1715  * @details
1716  * <pre>
1717  * In all cases, return the slot (or -1) where the object was placed
1718  * Note that this is a hacked up version of "inven_carry()".
1719  * Also note that it may not correctly "adapt" to "knowledge" bacoming
1720  * known, the player may have to pick stuff up and drop it again.
1721  * </pre>
1722  */
1723 static int home_carry(object_type *o_ptr)
1724 {
1725         int                             slot;
1726         s32b                       value;
1727         int     i;
1728         object_type *j_ptr;
1729         bool old_stack_force_notes = stack_force_notes;
1730         bool old_stack_force_costs = stack_force_costs;
1731
1732         if (cur_store_num != STORE_HOME)
1733         {
1734                 stack_force_notes = FALSE;
1735                 stack_force_costs = FALSE;
1736         }
1737
1738         /* Check each existing item (try to combine) */
1739         for (slot = 0; slot < st_ptr->stock_num; slot++)
1740         {
1741                 /* Get the existing item */
1742                 j_ptr = &st_ptr->stock[slot];
1743
1744                 /* The home acts just like the player */
1745                 if (object_similar(j_ptr, o_ptr))
1746                 {
1747                         /* Save the new number of items */
1748                         object_absorb(j_ptr, o_ptr);
1749
1750                         if (cur_store_num != STORE_HOME)
1751                         {
1752                                 stack_force_notes = old_stack_force_notes;
1753                                 stack_force_costs = old_stack_force_costs;
1754                         }
1755
1756                         /* All done */
1757                         return (slot);
1758                 }
1759         }
1760
1761         if (cur_store_num != STORE_HOME)
1762         {
1763                 stack_force_notes = old_stack_force_notes;
1764                 stack_force_costs = old_stack_force_costs;
1765         }
1766
1767         /* No space? */
1768         /*
1769          * 隠し機能: オプション powerup_home が設定されていると
1770          *           我が家が 20 ページまで使える
1771          */
1772         /* No space? */
1773         if ((cur_store_num != STORE_HOME) || (powerup_home == TRUE)) {
1774                 if (st_ptr->stock_num >= st_ptr->stock_size) {
1775                         return (-1);
1776                 }
1777         }
1778         else{
1779                 if (st_ptr->stock_num >= ((st_ptr->stock_size) / 10)) {
1780                         return (-1);
1781                 }
1782         }
1783
1784
1785         /* Determine the "value" of the item */
1786         value = object_value(o_ptr);
1787
1788         /* Check existing slots to see if we must "slide" */
1789         for (slot = 0; slot < st_ptr->stock_num; slot++)
1790         {
1791                 if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
1792         }
1793
1794         /* Slide the others up */
1795         for (i = st_ptr->stock_num; i > slot; i--)
1796         {
1797                 st_ptr->stock[i] = st_ptr->stock[i-1];
1798         }
1799
1800         /* More stuff now */
1801         st_ptr->stock_num++;
1802
1803         /* Insert the new item */
1804         st_ptr->stock[slot] = *o_ptr;
1805
1806         chg_virtue(V_SACRIFICE, -1);
1807
1808         (void)combine_and_reorder_home(cur_store_num);
1809
1810         /* Return the location */
1811         return (slot);
1812 }
1813
1814
1815 /*!
1816  * @brief 店舗にオブジェクトを加える /
1817  * Add the item "o_ptr" to a real stores inventory.
1818  * @param o_ptr 加えたいオブジェクトの構造体参照ポインタ
1819  * @return 収めた先のID
1820  * @details
1821  * <pre>
1822  * In all cases, return the slot (or -1) where the object was placed
1823  * Note that this is a hacked up version of "inven_carry()".
1824  * Also note that it may not correctly "adapt" to "knowledge" bacoming
1825  * known, the player may have to pick stuff up and drop it again.
1826  * </pre>
1827  */
1828 static int store_carry(object_type *o_ptr)
1829 {
1830         int     i, slot;
1831         s32b    value, j_value;
1832         object_type *j_ptr;
1833
1834
1835         /* Evaluate the object */
1836         value = object_value(o_ptr);
1837
1838         /* Cursed/Worthless items "disappear" when sold */
1839         if (value <= 0) return (-1);
1840
1841         /* All store items are fully *identified* */
1842         o_ptr->ident |= IDENT_MENTAL;
1843
1844         /* Erase the inscription */
1845         o_ptr->inscription = 0;
1846
1847         /* Erase the "feeling" */
1848         o_ptr->feeling = FEEL_NONE;
1849
1850         /* Check each existing item (try to combine) */
1851         for (slot = 0; slot < st_ptr->stock_num; slot++)
1852         {
1853                 /* Get the existing item */
1854                 j_ptr = &st_ptr->stock[slot];
1855
1856                 /* Can the existing items be incremented? */
1857                 if (store_object_similar(j_ptr, o_ptr))
1858                 {
1859                         /* Hack -- extra items disappear */
1860                         store_object_absorb(j_ptr, o_ptr);
1861
1862                         /* All done */
1863                         return (slot);
1864                 }
1865         }
1866
1867         /* No space? */
1868         if (st_ptr->stock_num >= st_ptr->stock_size) return (-1);
1869
1870
1871         /* Check existing slots to see if we must "slide" */
1872         for (slot = 0; slot < st_ptr->stock_num; slot++)
1873         {
1874                 /* Get that item */
1875                 j_ptr = &st_ptr->stock[slot];
1876
1877                 /* Objects sort by decreasing type */
1878                 if (o_ptr->tval > j_ptr->tval) break;
1879                 if (o_ptr->tval < j_ptr->tval) continue;
1880
1881                 /* Objects sort by increasing sval */
1882                 if (o_ptr->sval < j_ptr->sval) break;
1883                 if (o_ptr->sval > j_ptr->sval) continue;
1884
1885                 /*
1886                  * Hack:  otherwise identical rods sort by
1887                  * increasing recharge time --dsb
1888                  */
1889                 if (o_ptr->tval == TV_ROD)
1890                 {
1891                         if (o_ptr->pval < j_ptr->pval) break;
1892                         if (o_ptr->pval > j_ptr->pval) continue;
1893                 }
1894
1895                 /* Evaluate that slot */
1896                 j_value = object_value(j_ptr);
1897
1898                 /* Objects sort by decreasing value */
1899                 if (value > j_value) break;
1900                 if (value < j_value) continue;
1901         }
1902
1903         /* Slide the others up */
1904         for (i = st_ptr->stock_num; i > slot; i--)
1905         {
1906                 st_ptr->stock[i] = st_ptr->stock[i-1];
1907         }
1908
1909         /* More stuff now */
1910         st_ptr->stock_num++;
1911
1912         /* Insert the new item */
1913         st_ptr->stock[slot] = *o_ptr;
1914
1915         /* Return the location */
1916         return (slot);
1917 }
1918
1919
1920 /*!
1921  * @brief 店舗のオブジェクト数を増やす /
1922  * Add the item "o_ptr" to a real stores inventory.
1923  * @param item 増やしたいアイテムのID
1924  * @param num 増やしたい数
1925  * @return なし
1926  * @details
1927  * <pre>
1928  * Increase, by a given amount, the number of a certain item
1929  * in a certain store.  This can result in zero items.
1930  * </pre>
1931  * @todo numは本来ITEM_NUMBER型にしたい。
1932  */
1933 static void store_item_increase(INVENTORY_IDX item, int num)
1934 {
1935         int             cnt;
1936         object_type *o_ptr;
1937
1938         /* Get the item */
1939         o_ptr = &st_ptr->stock[item];
1940
1941         /* Verify the number */
1942         cnt = o_ptr->number + num;
1943         if (cnt > 255) cnt = 255;
1944         else if (cnt < 0) cnt = 0;
1945         num = cnt - o_ptr->number;
1946
1947         /* Save the new number */
1948         o_ptr->number += (ITEM_NUMBER)num;
1949 }
1950
1951
1952 /*!
1953  * @brief 店舗のオブジェクト数を削除する /
1954  * Remove a slot if it is empty
1955  * @param item 削除したいアイテムのID
1956  * @return なし
1957  */
1958 static void store_item_optimize(INVENTORY_IDX item)
1959 {
1960         int             j;
1961         object_type *o_ptr;
1962
1963         /* Get the item */
1964         o_ptr = &st_ptr->stock[item];
1965
1966         /* Must exist */
1967         if (!o_ptr->k_idx) return;
1968
1969         /* Must have no items */
1970         if (o_ptr->number) return;
1971
1972         /* One less item */
1973         st_ptr->stock_num--;
1974
1975         /* Slide everyone */
1976         for (j = item; j < st_ptr->stock_num; j++)
1977         {
1978                 st_ptr->stock[j] = st_ptr->stock[j + 1];
1979         }
1980
1981         /* Nuke the final slot */
1982         object_wipe(&st_ptr->stock[j]);
1983 }
1984
1985 /*!
1986  * @brief ブラックマーケット用の無価値品の排除判定 /
1987  * This function will keep 'crap' out of the black market.
1988  * @param o_ptr 判定したいオブジェクトの構造体参照ポインタ
1989  * @return ブラックマーケットにとって無価値な品ならばTRUEを返す
1990  * @details
1991  * <pre>
1992  * Crap is defined as any item that is "available" elsewhere
1993  * Based on a suggestion by "Lee Vogt" <lvogt@cig.mcel.mot.com>
1994  * </pre>
1995  */
1996 static bool black_market_crap(object_type *o_ptr)
1997 {
1998         int     i, j;
1999
2000         /* Ego items are never crap */
2001         if (object_is_ego(o_ptr)) return (FALSE);
2002
2003         /* Good items are never crap */
2004         if (o_ptr->to_a > 0) return (FALSE);
2005         if (o_ptr->to_h > 0) return (FALSE);
2006         if (o_ptr->to_d > 0) return (FALSE);
2007
2008         /* Check all stores */
2009         for (i = 0; i < MAX_STORES; i++)
2010         {
2011                 if (i == STORE_HOME) continue;
2012                 if (i == STORE_MUSEUM) continue;
2013
2014                 /* Check every item in the store */
2015                 for (j = 0; j < town[p_ptr->town_num].store[i].stock_num; j++)
2016                 {
2017                         object_type *j_ptr = &town[p_ptr->town_num].store[i].stock[j];
2018
2019                         /* Duplicate item "type", assume crappy */
2020                         if (o_ptr->k_idx == j_ptr->k_idx) return (TRUE);
2021                 }
2022         }
2023
2024         /* Assume okay */
2025         return (FALSE);
2026 }
2027
2028
2029 /*!
2030  * @brief 店舗の品揃え変化のためにアイテムを削除する /
2031  * Attempt to delete (some of) a random item from the store
2032  * @return なし
2033  * @details
2034  * <pre>
2035  * Hack -- we attempt to "maintain" piles of items when possible.
2036  * </pre>
2037  */
2038 static void store_delete(void)
2039 {
2040         INVENTORY_IDX what;
2041         int num;
2042
2043         /* Pick a random slot */
2044         what = (INVENTORY_IDX)randint0(st_ptr->stock_num);
2045
2046         /* Determine how many items are here */
2047         num = st_ptr->stock[what].number;
2048
2049         /* Hack -- sometimes, only destroy half the items */
2050         if (randint0(100) < 50) num = (num + 1) / 2;
2051
2052         /* Hack -- sometimes, only destroy a single item */
2053         if (randint0(100) < 50) num = 1;
2054
2055         /* Hack -- decrement the maximum timeouts and total charges of rods and wands. -LM- */
2056         if ((st_ptr->stock[what].tval == TV_ROD) || (st_ptr->stock[what].tval == TV_WAND))
2057         {
2058                 st_ptr->stock[what].pval -= num * st_ptr->stock[what].pval / st_ptr->stock[what].number;
2059         }
2060
2061         /* Actually destroy (part of) the item */
2062         store_item_increase(what, -num);
2063         store_item_optimize(what);
2064 }
2065
2066
2067 /*!
2068  * @brief 店舗の品揃え変化のためにアイテムを追加する /
2069  * Creates a random item and gives it to a store
2070  * @return なし
2071  * @details
2072  * <pre>
2073  * This algorithm needs to be rethought.  A lot.
2074  * Currently, "normal" stores use a pre-built array.
2075  * Note -- the "level" given to "obj_get_num()" is a "favored"
2076  * level, that is, there is a much higher chance of getting
2077  * items with a level approaching that of the given level...
2078  * Should we check for "permission" to have the given item?
2079  * </pre>
2080  */
2081 static void store_create(void)
2082 {
2083         OBJECT_IDX i;
2084         int tries;
2085         DEPTH level;
2086
2087         object_type forge;
2088         object_type *q_ptr;
2089
2090
2091         /* Paranoia -- no room left */
2092         if (st_ptr->stock_num >= st_ptr->stock_size) return;
2093
2094
2095         /* Hack -- consider up to four items */
2096         for (tries = 0; tries < 4; tries++)
2097         {
2098                 /* Black Market */
2099                 if (cur_store_num == STORE_BLACK)
2100                 {
2101                         /* Pick a level for object/magic */
2102                         level = 25 + randint0(25);
2103
2104                         /* Random item (usually of given level) */
2105                         i = get_obj_num(level);
2106
2107                         /* Handle failure */
2108                         if (!i) continue;
2109                 }
2110
2111                 /* Normal Store */
2112                 else
2113                 {
2114                         /* Hack -- Pick an item to sell */
2115                         i = st_ptr->table[randint0(st_ptr->table_num)];
2116
2117                         /* Hack -- fake level for apply_magic() */
2118                         level = rand_range(1, STORE_OBJ_LEVEL);
2119                 }
2120
2121
2122                 /* Get local object */
2123                 q_ptr = &forge;
2124
2125                 /* Create a new object of the chosen kind */
2126                 object_prep(q_ptr, i);
2127
2128                 /* Apply some "low-level" magic (no artifacts) */
2129                 apply_magic(q_ptr, level, AM_NO_FIXED_ART);
2130
2131                 /* Require valid object */
2132                 if (!store_will_buy(q_ptr)) continue;
2133
2134                 /* Hack -- Charge lite's */
2135                 if (q_ptr->tval == TV_LITE)
2136                 {
2137                         if (q_ptr->sval == SV_LITE_TORCH) q_ptr->xtra4 = FUEL_TORCH / 2;
2138                         if (q_ptr->sval == SV_LITE_LANTERN) q_ptr->xtra4 = FUEL_LAMP / 2;
2139                 }
2140
2141
2142                 /* The item is "known" */
2143                 object_known(q_ptr);
2144
2145                 /* Mark it storebought */
2146                 q_ptr->ident |= IDENT_STORE;
2147
2148                 /* Mega-Hack -- no chests in stores */
2149                 if (q_ptr->tval == TV_CHEST) continue;
2150
2151                 /* Prune the black market */
2152                 if (cur_store_num == STORE_BLACK)
2153                 {
2154                         /* Hack -- No "crappy" items */
2155                         if (black_market_crap(q_ptr)) continue;
2156
2157                         /* Hack -- No "cheap" items */
2158                         if (object_value(q_ptr) < 10) continue;
2159
2160                         /* No "worthless" items */
2161                         /* if (object_value(q_ptr) <= 0) continue; */
2162                 }
2163
2164                 /* Prune normal stores */
2165                 else
2166                 {
2167                         /* No "worthless" items */
2168                         if (object_value(q_ptr) <= 0) continue;
2169                 }
2170
2171
2172                 /* Mass produce and/or Apply discount */
2173                 mass_produce(q_ptr);
2174
2175                 /* Attempt to carry the (known) item */
2176                 (void)store_carry(q_ptr);
2177
2178                 /* Definitely done */
2179                 break;
2180         }
2181 }
2182
2183
2184 /*!
2185  * @brief 店舗の割引対象外にするかどうかを判定 /
2186  * Eliminate need to bargain if player has haggled well in the past
2187  * @param minprice アイテムの最低販売価格
2188  * @return 割引を禁止するならTRUEを返す。
2189  */
2190 static bool noneedtobargain(PRICE minprice)
2191 {
2192         s32b good = st_ptr->good_buy;
2193         s32b bad = st_ptr->bad_buy;
2194
2195         /* Cheap items are "boring" */
2196         if (minprice < 10L) return (TRUE);
2197
2198         /* Perfect haggling */
2199         if (good == MAX_SHORT) return (TRUE);
2200
2201         /* Reward good haggles, punish bad haggles, notice price */
2202         if (good > ((3 * bad) + (5 + (minprice/50)))) return (TRUE);
2203
2204         /* Return the flag */
2205         return (FALSE);
2206 }
2207
2208
2209 /*!
2210  * @brief 店主の持つプレイヤーに対する売買の良し悪し経験を記憶する /
2211  * Update the bargain info
2212  * @param price 実際の取引価格
2213  * @param minprice 店主の提示した価格
2214  * @param num 売買数 
2215  * @return なし
2216  */
2217 static void updatebargain(PRICE price, PRICE minprice, int num)
2218 {
2219         /* Hack -- auto-haggle */
2220         if (!manual_haggle) return;
2221
2222         /* Cheap items are "boring" */
2223         if ((minprice/num) < 10L) return;
2224
2225         /* Count the successful haggles */
2226         if (price == minprice)
2227         {
2228                 /* Just count the good haggles */
2229                 if (st_ptr->good_buy < MAX_SHORT)
2230                 {
2231                         st_ptr->good_buy++;
2232                 }
2233         }
2234
2235         /* Count the failed haggles */
2236         else
2237         {
2238                 /* Just count the bad haggles */
2239                 if (st_ptr->bad_buy < MAX_SHORT)
2240                 {
2241                         st_ptr->bad_buy++;
2242                 }
2243         }
2244 }
2245
2246
2247 /*!
2248  * @brief 店の商品リストを再表示する /
2249  * Re-displays a single store entry
2250  * @param pos 表示行
2251  * @return なし
2252  */
2253 static void display_entry(int pos)
2254 {
2255         int             i, cur_col;
2256         object_type     *o_ptr;
2257         s32b            x;
2258
2259         char            o_name[MAX_NLEN];
2260         char            out_val[160];
2261
2262
2263         int maxwid = 75;
2264
2265         /* Get the item */
2266         o_ptr = &st_ptr->stock[pos];
2267
2268         /* Get the "offset" */
2269         i = (pos % store_bottom);
2270
2271         /* Label it, clear the line --(-- */
2272         (void)sprintf(out_val, "%c) ", ((i > 25) ? toupper(I2A(i - 26)) : I2A(i)));
2273         prt(out_val, i+6, 0);
2274
2275         cur_col = 3;
2276         if (show_item_graph)
2277         {
2278                 byte a = object_attr(o_ptr);
2279                 char c = object_char(o_ptr);
2280
2281                 Term_queue_bigchar(cur_col, i + 6, a, c, 0, 0);
2282                 if (use_bigtile) cur_col++;
2283
2284                 cur_col += 2;
2285         }
2286
2287         /* Describe an item in the home */
2288         if ((cur_store_num == STORE_HOME) || (cur_store_num == STORE_MUSEUM))
2289         {
2290                 maxwid = 75;
2291
2292                 /* Leave room for weights, if necessary -DRS- */
2293                 if (show_weights) maxwid -= 10;
2294
2295                 /* Describe the object */
2296                 object_desc(o_name, o_ptr, 0);
2297                 o_name[maxwid] = '\0';
2298                 c_put_str(tval_to_attr[o_ptr->tval], o_name, i+6, cur_col);
2299
2300                 /* Show weights */
2301                 if (show_weights)
2302                 {
2303                         /* Only show the weight of an individual item */
2304                         int wgt = o_ptr->weight;
2305 #ifdef JP
2306                         sprintf(out_val, "%3d.%1d kg", lbtokg1(wgt) , lbtokg2(wgt) );
2307                         put_str(out_val, i+6, 67);
2308 #else
2309                         (void)sprintf(out_val, "%3d.%d lb", wgt / 10, wgt % 10);
2310                         put_str(out_val, i+6, 68);
2311 #endif
2312
2313                 }
2314         }
2315
2316         /* Describe an item (fully) in a store */
2317         else
2318         {
2319                 /* Must leave room for the "price" */
2320                 maxwid = 65;
2321
2322                 /* Leave room for weights, if necessary -DRS- */
2323                 if (show_weights) maxwid -= 7;
2324
2325                 /* Describe the object (fully) */
2326                 object_desc(o_name, o_ptr, 0);
2327                 o_name[maxwid] = '\0';
2328                 c_put_str(tval_to_attr[o_ptr->tval], o_name, i+6, cur_col);
2329
2330                 /* Show weights */
2331                 if (show_weights)
2332                 {
2333                         /* Only show the weight of an individual item */
2334                         int wgt = o_ptr->weight;
2335 #ifdef JP
2336                         sprintf(out_val, "%3d.%1d", lbtokg1(wgt) , lbtokg2(wgt) );
2337                         put_str(out_val, i+6, 60);
2338 #else
2339                         (void)sprintf(out_val, "%3d.%d", wgt / 10, wgt % 10);
2340                         put_str(out_val, i+6, 61);
2341 #endif
2342
2343                 }
2344
2345                 /* Display a "fixed" cost */
2346                 if (o_ptr->ident & (IDENT_FIXED))
2347                 {
2348                         /* Extract the "minimum" price */
2349                         x = price_item(o_ptr, ot_ptr->min_inflate, FALSE);
2350
2351                         /* Actually draw the price (not fixed) */
2352 #ifdef JP
2353 (void)sprintf(out_val, "%9ld固", (long)x);
2354 #else
2355                         (void)sprintf(out_val, "%9ld F", (long)x);
2356 #endif
2357
2358                         put_str(out_val, i+6, 68);
2359                 }
2360
2361                 /* Display a "taxed" cost */
2362                 else if (!manual_haggle)
2363                 {
2364                         /* Extract the "minimum" price */
2365                         x = price_item(o_ptr, ot_ptr->min_inflate, FALSE);
2366
2367                         /* Hack -- Apply Sales Tax if needed */
2368                         if (!noneedtobargain(x)) x += x / 10;
2369
2370                         /* Actually draw the price (with tax) */
2371                         (void)sprintf(out_val, "%9ld  ", (long)x);
2372                         put_str(out_val, i+6, 68);
2373                 }
2374
2375                 /* Display a "haggle" cost */
2376                 else
2377                 {
2378                         /* Extrect the "maximum" price */
2379                         x = price_item(o_ptr, ot_ptr->max_inflate, FALSE);
2380
2381                         /* Actually draw the price (not fixed) */
2382                         (void)sprintf(out_val, "%9ld  ", (long)x);
2383                         put_str(out_val, i+6, 68);
2384                 }
2385         }
2386 }
2387
2388
2389 /*!
2390  * @brief 店の商品リストを表示する /
2391  * Displays a store's inventory                 -RAK-
2392  * @return なし
2393  * @details
2394  * All prices are listed as "per individual object".  -BEN-
2395  */
2396 static void display_inventory(void)
2397 {
2398         int i, k;
2399
2400         /* Display the next 12 items */
2401         for (k = 0; k < store_bottom; k++)
2402         {
2403                 /* Do not display "dead" items */
2404                 if (store_top + k >= st_ptr->stock_num) break;
2405
2406                 /* Display that line */
2407                 display_entry(store_top + k);
2408         }
2409
2410         /* Erase the extra lines and the "more" prompt */
2411         for (i = k; i < store_bottom + 1; i++) prt("", i + 6, 0);
2412
2413         /* Assume "no current page" */
2414 #ifdef JP
2415         put_str("          ", 5, 20);
2416 #else
2417         put_str("        ", 5, 20);
2418 #endif
2419
2420
2421         /* Visual reminder of "more items" */
2422         if (st_ptr->stock_num > store_bottom)
2423         {
2424                 /* Show "more" reminder (after the last item) */
2425 #ifdef JP
2426                 prt("-続く-", k + 6, 3);
2427 #else
2428                 prt("-more-", k + 6, 3);
2429 #endif
2430
2431
2432                 /* Indicate the "current page" */
2433                 /* Trailing spaces are to display (Page xx) and (Page x) */
2434 #ifdef JP
2435                 put_str(format("(%dページ)  ", store_top/store_bottom + 1), 5, 20);
2436 #else
2437                 put_str(format("(Page %d)  ", store_top/store_bottom + 1), 5, 20);
2438 #endif
2439
2440         }
2441
2442         if (cur_store_num == STORE_HOME || cur_store_num == STORE_MUSEUM)
2443         {
2444                 k = st_ptr->stock_size;
2445
2446                 if (cur_store_num == STORE_HOME && !powerup_home) k /= 10;
2447 #ifdef JP
2448                 put_str(format("アイテム数:  %4d/%4d", st_ptr->stock_num, k), 19 + xtra_stock, 27);
2449 #else
2450                 put_str(format("Objects:  %4d/%4d", st_ptr->stock_num, k), 19 + xtra_stock, 30);
2451 #endif
2452         }
2453 }
2454
2455
2456 /*!
2457  * @brief プレイヤーの所持金を表示する /
2458  * Displays players gold                                        -RAK-
2459  * @return なし
2460  * @details
2461  */
2462 static void store_prt_gold(void)
2463 {
2464         char out_val[64];
2465
2466 #ifdef JP
2467         prt("手持ちのお金: ", 19 + xtra_stock, 53);
2468 #else
2469         prt("Gold Remaining: ", 19 + xtra_stock, 53);
2470 #endif
2471
2472
2473         sprintf(out_val, "%9ld", (long)p_ptr->au);
2474         prt(out_val, 19 + xtra_stock, 68);
2475 }
2476
2477 /*!
2478  * @brief 店舗情報全体を表示するメインルーチン /
2479  * Displays store (after clearing screen)               -RAK-
2480  * @return なし
2481  * @details
2482  */
2483 static void display_store(void)
2484 {
2485         char buf[80];
2486
2487
2488         /* Clear screen */
2489         Term_clear();
2490
2491         /* The "Home" is special */
2492         if (cur_store_num == STORE_HOME)
2493         {
2494                 /* Put the owner name */
2495 #ifdef JP
2496                 put_str("我が家", 3, 31);
2497 #else
2498                 put_str("Your Home", 3, 30);
2499 #endif
2500
2501
2502                 /* Label the item descriptions */
2503 #ifdef JP
2504                 put_str("アイテムの一覧", 5, 4);
2505 #else
2506                 put_str("Item Description", 5, 3);
2507 #endif
2508
2509
2510                 /* If showing weights, show label */
2511                 if (show_weights)
2512                 {
2513 #ifdef JP
2514                         put_str("重さ", 5, 72);
2515 #else
2516                         put_str("Weight", 5, 70);
2517 #endif
2518
2519                 }
2520         }
2521
2522         /* The "Home" is special */
2523         else if (cur_store_num == STORE_MUSEUM)
2524         {
2525                 /* Put the owner name */
2526 #ifdef JP
2527                 put_str("博物館", 3, 31);
2528 #else
2529                 put_str("Museum", 3, 30);
2530 #endif
2531
2532
2533                 /* Label the item descriptions */
2534 #ifdef JP
2535                 put_str("アイテムの一覧", 5, 4);
2536 #else
2537                 put_str("Item Description", 5, 3);
2538 #endif
2539
2540
2541                 /* If showing weights, show label */
2542                 if (show_weights)
2543                 {
2544 #ifdef JP
2545                         put_str("重さ", 5, 72);
2546 #else
2547                         put_str("Weight", 5, 70);
2548 #endif
2549
2550                 }
2551         }
2552
2553         /* Normal stores */
2554         else
2555         {
2556                 cptr store_name = (f_name + f_info[cur_store_feat].name);
2557                 cptr owner_name = (ot_ptr->owner_name);
2558                 cptr race_name = race_info[ot_ptr->owner_race].title;
2559
2560                 /* Put the owner name and race */
2561                 sprintf(buf, "%s (%s)", owner_name, race_name);
2562                 put_str(buf, 3, 10);
2563
2564                 /* Show the max price in the store (above prices) */
2565                 sprintf(buf, "%s (%ld)", store_name, (long)(ot_ptr->max_cost));
2566                 prt(buf, 3, 50);
2567
2568                 /* Label the item descriptions */
2569 #ifdef JP
2570                 put_str("商品の一覧", 5, 7);
2571 #else
2572                 put_str("Item Description", 5, 3);
2573 #endif
2574
2575
2576                 /* If showing weights, show label */
2577                 if (show_weights)
2578                 {
2579 #ifdef JP
2580                         put_str("重さ", 5, 62);
2581 #else
2582                         put_str("Weight", 5, 60);
2583 #endif
2584
2585                 }
2586
2587                 /* Label the asking price (in stores) */
2588 #ifdef JP
2589                 put_str("価格", 5, 73);
2590 #else
2591                 put_str("Price", 5, 72);
2592 #endif
2593
2594         }
2595
2596         /* Display the current gold */
2597         store_prt_gold();
2598
2599         /* Draw in the inventory */
2600         display_inventory();
2601 }
2602
2603
2604
2605 /*!
2606  * @brief 店舗からアイテムを選択する /
2607  * Get the ID of a store item and return its value      -RAK-
2608  * @param com_val 選択IDを返す参照ポインタ
2609  * @param pmt メッセージキャプション
2610  * @param i 選択範囲の最小値
2611  * @param j 選択範囲の最大値
2612  * @return 実際に選択したらTRUE、キャンセルしたらFALSE
2613  */
2614 static int get_stock(COMMAND_CODE *com_val, cptr pmt, int i, int j)
2615 {
2616         char    command;
2617         char    out_val[160];
2618         char    lo, hi;
2619
2620 #ifdef ALLOW_REPEAT /* TNB */
2621
2622         /* Get the item index */
2623         if (repeat_pull(com_val))
2624         {
2625                 /* Verify the item */
2626                 if ((*com_val >= i) && (*com_val <= j))
2627                 {
2628                         /* Success */
2629                         return (TRUE);
2630                 }
2631         }
2632
2633 #endif /* ALLOW_REPEAT -- TNB */
2634
2635         /* Paranoia */
2636         msg_print(NULL);
2637
2638
2639         /* Assume failure */
2640         *com_val = (-1);
2641
2642         /* Build the prompt */
2643         lo = I2A(i);
2644         hi = (j > 25) ? toupper(I2A(j - 26)) : I2A(j);
2645 #ifdef JP
2646         (void)sprintf(out_val, "(%s:%c-%c, ESCで中断) %s",
2647                 (((cur_store_num == STORE_HOME) || (cur_store_num == STORE_MUSEUM)) ? "アイテム" : "商品"), 
2648                                   lo, hi, pmt);
2649 #else
2650         (void)sprintf(out_val, "(Items %c-%c, ESC to exit) %s",
2651                                   lo, hi, pmt);
2652 #endif
2653
2654
2655         /* Ask until done */
2656         while (TRUE)
2657         {
2658                 COMMAND_CODE k;
2659
2660                 /* Escape */
2661                 if (!get_com(out_val, &command, FALSE)) break;
2662
2663                 /* Convert */
2664                 if (islower(command))
2665                         k = A2I(command);
2666                 else if (isupper(command))
2667                         k = A2I(tolower(command)) + 26;
2668                 else
2669                         k = -1;
2670
2671                 /* Legal responses */
2672                 if ((k >= i) && (k <= j))
2673                 {
2674                         *com_val = k;
2675                         break;
2676                 }
2677
2678                 bell();
2679         }
2680
2681         /* Clear the prompt */
2682         prt("", 0, 0);
2683
2684         /* Cancel */
2685         if (command == ESCAPE) return (FALSE);
2686
2687 #ifdef ALLOW_REPEAT /* TNB */
2688
2689         repeat_push(*com_val);
2690
2691 #endif /* ALLOW_REPEAT -- TNB */
2692
2693         /* Success */
2694         return (TRUE);
2695 }
2696
2697
2698 /*!
2699  * @brief 店主の不満度を増やし、プレイヤーを締め出す判定と処理を行う /
2700  * Increase the insult counter and get angry if too many -RAK-
2701  * @return プレイヤーを締め出す場合TRUEを返す
2702  */
2703 static int increase_insults(void)
2704 {
2705         /* Increase insults */
2706         st_ptr->insult_cur++;
2707
2708         /* Become insulted */
2709         if (st_ptr->insult_cur > ot_ptr->insult_max)
2710         {
2711                 /* Complain */
2712                 say_comment_4();
2713
2714                 /* Reset insults */
2715                 st_ptr->insult_cur = 0;
2716                 st_ptr->good_buy = 0;
2717                 st_ptr->bad_buy = 0;
2718
2719                 /* Open tomorrow */
2720                 st_ptr->store_open = turn + TURNS_PER_TICK*TOWN_DAWN/8 + randint1(TURNS_PER_TICK*TOWN_DAWN/8);
2721
2722                 /* Closed */
2723                 return (TRUE);
2724         }
2725
2726         /* Not closed */
2727         return (FALSE);
2728 }
2729
2730
2731 /*!
2732  * @brief 店主の不満度を減らす /
2733  * Decrease insults                             -RAK-
2734  * @return プレイヤーを締め出す場合TRUEを返す
2735  */
2736 static void decrease_insults(void)
2737 {
2738         /* Decrease insults */
2739         if (st_ptr->insult_cur) st_ptr->insult_cur--;
2740 }
2741
2742
2743 /*!
2744  * @brief 店主の不満度が増えた場合のみのメッセージを表示する /
2745  * Have insulted while haggling                         -RAK-
2746  * @return プレイヤーを締め出す場合TRUEを返す
2747  */
2748 static int haggle_insults(void)
2749 {
2750         /* Increase insults */
2751         if (increase_insults()) return (TRUE);
2752
2753         /* Display and flush insult */
2754         say_comment_5();
2755
2756         /* Still okay */
2757         return (FALSE);
2758 }
2759
2760
2761 /*
2762  * Mega-Hack -- Enable "increments"
2763  */
2764 static bool allow_inc = FALSE;
2765
2766 /*
2767  * Mega-Hack -- Last "increment" during haggling
2768  */
2769 static s32b last_inc = 0L;
2770
2771
2772 /*!
2773  * @brief 交渉価格を確認と認証の是非を行う /
2774  * Get a haggle
2775  * @param pmt メッセージ
2776  * @param poffer 別途価格提示をした場合の値を返す参照ポインタ
2777  * @param price 現在の交渉価格
2778  * @param final 最終確定価格ならばTRUE
2779  * @return プレイヤーを締め出す場合TRUEを返す
2780  */
2781 static int get_haggle(cptr pmt, s32b *poffer, PRICE price, int final)
2782 {
2783         s32b            i;
2784
2785         cptr            p;
2786
2787         char                            buf[128];
2788         char            out_val[160];
2789
2790
2791         /* Clear old increment if necessary */
2792         if (!allow_inc) last_inc = 0L;
2793
2794
2795         /* Final offer */
2796         if (final)
2797         {
2798 #ifdef JP
2799                 sprintf(buf, "%s [承諾] ", pmt);
2800 #else
2801                 sprintf(buf, "%s [accept] ", pmt);
2802 #endif
2803
2804         }
2805
2806         /* Old (negative) increment, and not final */
2807         else if (last_inc < 0)
2808         {
2809 #ifdef JP
2810                 sprintf(buf, "%s [-$%ld] ", pmt, (long)(ABS(last_inc)));
2811 #else
2812                 sprintf(buf, "%s [-%ld] ", pmt, (long)(ABS(last_inc)));
2813 #endif
2814
2815         }
2816
2817         /* Old (positive) increment, and not final */
2818         else if (last_inc > 0)
2819         {
2820 #ifdef JP
2821                 sprintf(buf, "%s [+$%ld] ", pmt, (long)(ABS(last_inc)));
2822 #else
2823                 sprintf(buf, "%s [+%ld] ", pmt, (long)(ABS(last_inc)));
2824 #endif
2825
2826         }
2827
2828         /* Normal haggle */
2829         else
2830         {
2831                 sprintf(buf, "%s ", pmt);
2832         }
2833
2834
2835         /* Paranoia */
2836         msg_print(NULL);
2837
2838
2839         /* Ask until done */
2840         while (TRUE)
2841         {
2842                 bool res;
2843
2844                 /* Display prompt */
2845                 prt(buf, 0, 0);
2846
2847                 /* Default */
2848                 strcpy(out_val, "");
2849
2850                 /*
2851                  * Ask the user for a response.
2852                  * Don't allow to use numpad as cursor key.
2853                  */
2854                 res = askfor_aux(out_val, 32, FALSE);
2855
2856                 /* Clear prompt */
2857                 prt("", 0, 0);
2858
2859                 /* Cancelled */
2860                 if (!res) return FALSE;
2861
2862                 /* Skip leading spaces */
2863                 for (p = out_val; *p == ' '; p++) /* loop */;
2864
2865                 /* Empty response */
2866                 if (*p == '\0')
2867                 {
2868                         /* Accept current price */
2869                         if (final)
2870                         {
2871                                 *poffer = price;
2872                                 last_inc = 0L;
2873                                 break;
2874                         }
2875
2876                         /* Use previous increment */
2877                         if (allow_inc && last_inc)
2878                         {
2879                                 *poffer += last_inc;
2880                                 break;
2881                         }
2882                 }
2883
2884                 /* Normal response */
2885                 else
2886                 {
2887                         /* Extract a number */
2888                         i = atol(p);
2889
2890                         /* Handle "incremental" number */
2891                         if ((*p == '+' || *p == '-'))
2892                         {
2893                                 /* Allow increments */
2894                                 if (allow_inc)
2895                                 {
2896                                         /* Use the given "increment" */
2897                                         *poffer += i;
2898                                         last_inc = i;
2899                                         break;
2900                                 }
2901                         }
2902
2903                         /* Handle normal number */
2904                         else
2905                         {
2906                                 /* Use the given "number" */
2907                                 *poffer = i;
2908                                 last_inc = 0L;
2909                                 break;
2910                         }
2911                 }
2912
2913                 /* Warning */
2914 #ifdef JP
2915                 msg_print("値がおかしいです。");
2916 #else
2917                 msg_print("Invalid response.");
2918 #endif
2919
2920                 msg_print(NULL);
2921         }
2922
2923         /* Success */
2924         return (TRUE);
2925 }
2926
2927
2928 /*!
2929  * @brief 店主がプレイヤーからの交渉価格を判断する /
2930  * Receive an offer (from the player)
2931  * @param pmt メッセージ
2932  * @param poffer 店主からの交渉価格を返す参照ポインタ
2933  * @param last_offer 現在の交渉価格
2934  * @param factor 店主の価格基準倍率
2935  * @param price アイテムの実価値
2936  * @param final 最終価格確定ならばTRUE
2937  * @return プレイヤーの価格に対して不服ならばTRUEを返す /
2938  * Return TRUE if offer is NOT okay
2939  */
2940 static bool receive_offer(cptr pmt, s32b *poffer,
2941                           s32b last_offer, int factor,
2942                           PRICE price, int final)
2943 {
2944         /* Haggle till done */
2945         while (TRUE)
2946         {
2947                 /* Get a haggle (or cancel) */
2948                 if (!get_haggle(pmt, poffer, price, final)) return (TRUE);
2949
2950                 /* Acceptable offer */
2951                 if (((*poffer) * factor) >= (last_offer * factor)) break;
2952
2953                 /* Insult, and check for kicked out */
2954                 if (haggle_insults()) return (TRUE);
2955
2956                 /* Reject offer (correctly) */
2957                 (*poffer) = last_offer;
2958         }
2959
2960         /* Success */
2961         return (FALSE);
2962 }
2963
2964
2965 /*!
2966  * @brief プレイヤーが購入する時の値切り処理メインルーチン /
2967  * Haggling routine                             -RAK-
2968  * @param o_ptr オブジェクトの構造体参照ポインタ
2969  * @param price 最終価格を返す参照ポインタ
2970  * @return プレイヤーの価格に対して店主が不服ならばTRUEを返す /
2971  * Return TRUE if purchase is NOT successful
2972  */
2973 static bool purchase_haggle(object_type *o_ptr, s32b *price)
2974 {
2975         s32b                       cur_ask, final_ask;
2976         s32b                       last_offer, offer;
2977         s32b                       x1, x2, x3;
2978         s32b                       min_per, max_per;
2979         int                        flag, loop_flag, noneed;
2980         int                        annoyed = 0, final = FALSE;
2981
2982         bool            cancel = FALSE;
2983
2984 #ifdef JP
2985         cptr pmt = "提示価格";
2986 #else
2987         cptr            pmt = "Asking";
2988 #endif
2989
2990
2991         char            out_val[160];
2992
2993
2994         *price = 0;
2995
2996
2997         /* Extract the starting offer and the final offer */
2998         cur_ask = price_item(o_ptr, ot_ptr->max_inflate, FALSE);
2999         final_ask = price_item(o_ptr, ot_ptr->min_inflate, FALSE);
3000
3001         /* Determine if haggling is necessary */
3002         noneed = noneedtobargain(final_ask);
3003
3004         /* No need to haggle */
3005         if (noneed || !manual_haggle)
3006         {
3007                 /* No need to haggle */
3008                 if (noneed)
3009                 {
3010                         /* Message summary */
3011 #ifdef JP
3012                         msg_print("結局この金額にまとまった。");
3013 #else
3014                         msg_print("You eventually agree upon the price.");
3015 #endif
3016
3017                         msg_print(NULL);
3018                 }
3019
3020                 /* No haggle option */
3021                 else
3022                 {
3023                         /* Message summary */
3024 #ifdef JP
3025                         msg_print("すんなりとこの金額にまとまった。");
3026 #else
3027                         msg_print("You quickly agree upon the price.");
3028 #endif
3029
3030                         msg_print(NULL);
3031
3032                         /* Apply Sales Tax */
3033                         final_ask += final_ask / 10;
3034                 }
3035
3036                 /* Final price */
3037                 cur_ask = final_ask;
3038
3039                 /* Go to final offer */
3040 #ifdef JP
3041                 pmt = "最終提示価格";
3042 #else
3043                 pmt = "Final Offer";
3044 #endif
3045
3046                 final = TRUE;
3047         }
3048
3049
3050         /* Haggle for the whole pile */
3051         cur_ask *= o_ptr->number;
3052         final_ask *= o_ptr->number;
3053
3054
3055         /* Haggle parameters */
3056         min_per = ot_ptr->haggle_per;
3057         max_per = min_per * 3;
3058
3059         /* Mega-Hack -- artificial "last offer" value */
3060         last_offer = object_value(o_ptr) * o_ptr->number;
3061         last_offer = last_offer * (200 - (int)(ot_ptr->max_inflate)) / 100L;
3062         if (last_offer <= 0) last_offer = 1;
3063
3064         /* No offer yet */
3065         offer = 0;
3066
3067         /* No incremental haggling yet */
3068         allow_inc = FALSE;
3069
3070         /* Haggle until done */
3071         for (flag = FALSE; !flag; )
3072         {
3073                 loop_flag = TRUE;
3074
3075                 while (!flag && loop_flag)
3076                 {
3077                         (void)sprintf(out_val, "%s :  %ld", pmt, (long)cur_ask);
3078                         put_str(out_val, 1, 0);
3079 #ifdef JP
3080                         cancel = receive_offer("提示する金額? ",
3081 #else
3082                         cancel = receive_offer("What do you offer? ",
3083 #endif
3084
3085                                                &offer, last_offer, 1, cur_ask, final);
3086
3087                         if (cancel)
3088                         {
3089                                 flag = TRUE;
3090                         }
3091                         else if (offer > cur_ask)
3092                         {
3093                                 say_comment_6();
3094                                 offer = last_offer;
3095                         }
3096                         else if (offer == cur_ask)
3097                         {
3098                                 flag = TRUE;
3099                                 *price = offer;
3100                         }
3101                         else
3102                         {
3103                                 loop_flag = FALSE;
3104                         }
3105                 }
3106
3107                 if (!flag)
3108                 {
3109                         x1 = 100 * (offer - last_offer) / (cur_ask - last_offer);
3110                         if (x1 < min_per)
3111                         {
3112                                 if (haggle_insults())
3113                                 {
3114                                         flag = TRUE;
3115                                         cancel = TRUE;
3116                                 }
3117                         }
3118                         else if (x1 > max_per)
3119                         {
3120                                 x1 = x1 * 3 / 4;
3121                                 if (x1 < max_per) x1 = max_per;
3122                         }
3123                         x2 = rand_range(x1-2, x1+2);
3124                         x3 = ((cur_ask - offer) * x2 / 100L) + 1;
3125                         /* don't let the price go up */
3126                         if (x3 < 0) x3 = 0;
3127                         cur_ask -= x3;
3128
3129                         /* Too little */
3130                         if (cur_ask < final_ask)
3131                         {
3132                                 final = TRUE;
3133                                 cur_ask = final_ask;
3134 #ifdef JP
3135                                 pmt = "最終提示価格";
3136 #else
3137                                 pmt = "Final Offer";
3138 #endif
3139
3140                                 annoyed++;
3141                                 if (annoyed > 3)
3142                                 {
3143                                         (void)(increase_insults());
3144                                         cancel = TRUE;
3145                                         flag = TRUE;
3146                                 }
3147                         }
3148                         else if (offer >= cur_ask)
3149                         {
3150                                 flag = TRUE;
3151                                 *price = offer;
3152                         }
3153
3154                         if (!flag)
3155                         {
3156                                 last_offer = offer;
3157                                 allow_inc = TRUE;
3158                                 prt("", 1, 0);
3159 #ifdef JP
3160 (void)sprintf(out_val, "前回の提示金額: $%ld",
3161 #else
3162                                 (void)sprintf(out_val, "Your last offer: %ld",
3163 #endif
3164
3165                                                           (long)last_offer);
3166                                 put_str(out_val, 1, 39);
3167                                 say_comment_2(cur_ask, annoyed);
3168                         }
3169                 }
3170         }
3171
3172         /* Cancel */
3173         if (cancel) return (TRUE);
3174
3175         /* Update bargaining info */
3176         updatebargain(*price, final_ask, o_ptr->number);
3177
3178         /* Do not cancel */
3179         return (FALSE);
3180 }
3181
3182
3183 /*!
3184  * @brief プレイヤーが売却する時の値切り処理メインルーチン /
3185  * Haggling routine                             -RAK-
3186  * @param o_ptr オブジェクトの構造体参照ポインタ
3187  * @param price 最終価格を返す参照ポインタ
3188  * @return プレイヤーの価格に対して店主が不服ならばTRUEを返す /
3189  * Return TRUE if purchase is NOT successful
3190  */
3191 static bool sell_haggle(object_type *o_ptr, s32b *price)
3192 {
3193         s32b    purse, cur_ask, final_ask;
3194         s32b    last_offer = 0, offer = 0;
3195         s32b    x1, x2, x3;
3196         s32b    min_per, max_per;
3197         int     flag, loop_flag, noneed;
3198         int     annoyed = 0, final = FALSE;
3199         bool    cancel = FALSE;
3200 #ifdef JP
3201         cptr pmt = "提示金額";
3202 #else
3203         cptr    pmt = "Offer";
3204 #endif
3205
3206         char    out_val[160];
3207
3208
3209         *price = 0;
3210
3211
3212         /* Obtain the starting offer and the final offer */
3213         cur_ask = price_item(o_ptr, ot_ptr->max_inflate, TRUE);
3214         final_ask = price_item(o_ptr, ot_ptr->min_inflate, TRUE);
3215
3216         /* Determine if haggling is necessary */
3217         noneed = noneedtobargain(final_ask);
3218
3219         /* Get the owner's payout limit */
3220         purse = (s32b)(ot_ptr->max_cost);
3221
3222         /* No need to haggle */
3223         if (noneed || !manual_haggle || (final_ask >= purse))
3224         {
3225                 /* Apply Sales Tax (if needed) */
3226                 if (!manual_haggle && !noneed)
3227                 {
3228                         final_ask -= final_ask / 10;
3229                 }
3230
3231                 /* No reason to haggle */
3232                 if (final_ask >= purse)
3233                 {
3234 #ifdef JP
3235                         msg_print("即座にこの金額にまとまった。");
3236 #else
3237                         msg_print("You instantly agree upon the price.");
3238 #endif
3239
3240                         msg_print(NULL);
3241
3242                         /* Offer full purse */
3243                         final_ask = purse;
3244                 }
3245
3246                 /* No need to haggle */
3247                 else if (noneed)
3248                 {
3249 #ifdef JP
3250                         msg_print("結局この金額にまとまった。");
3251 #else
3252                         msg_print("You eventually agree upon the price.");
3253 #endif
3254
3255                         msg_print(NULL);
3256                 }
3257
3258                 /* No haggle option */
3259                 else
3260                 {
3261                         /* Message summary */
3262 #ifdef JP
3263                         msg_print("すんなりとこの金額にまとまった。");
3264 #else
3265                         msg_print("You quickly agree upon the price.");
3266 #endif
3267
3268                         msg_print(NULL);
3269                 }
3270
3271                 /* Final price */
3272                 cur_ask = final_ask;
3273
3274                 /* Final offer */
3275                 final = TRUE;
3276 #ifdef JP
3277                 pmt = "最終提示金額";
3278 #else
3279                 pmt = "Final Offer";
3280 #endif
3281
3282         }
3283
3284         /* Haggle for the whole pile */
3285         cur_ask *= o_ptr->number;
3286         final_ask *= o_ptr->number;
3287
3288
3289         /* Display commands */
3290
3291         /* Haggling parameters */
3292         min_per = ot_ptr->haggle_per;
3293         max_per = min_per * 3;
3294
3295         /* Mega-Hack -- artificial "last offer" value */
3296         last_offer = object_value(o_ptr) * o_ptr->number;
3297         last_offer = last_offer * ot_ptr->max_inflate / 100L;
3298
3299         /* No offer yet */
3300         offer = 0;
3301
3302         /* No incremental haggling yet */
3303         allow_inc = FALSE;
3304
3305         /* Haggle */
3306         for (flag = FALSE; !flag; )
3307         {
3308                 while (1)
3309                 {
3310                         loop_flag = TRUE;
3311
3312                         (void)sprintf(out_val, "%s :  %ld", pmt, (long)cur_ask);
3313                         put_str(out_val, 1, 0);
3314 #ifdef JP
3315                         cancel = receive_offer("提示する価格? ",
3316 #else
3317                         cancel = receive_offer("What price do you ask? ",
3318 #endif
3319
3320                                                                    &offer, last_offer, -1, cur_ask, final);
3321
3322                         if (cancel)
3323                         {
3324                                 flag = TRUE;
3325                         }
3326                         else if (offer < cur_ask)
3327                         {
3328                                 say_comment_6();
3329                                 /* rejected, reset offer for incremental haggling */
3330                                 offer = last_offer;
3331                         }
3332                         else if (offer == cur_ask)
3333                         {
3334                                 flag = TRUE;
3335                                 *price = offer;
3336                         }
3337                         else
3338                         {
3339                                 loop_flag = FALSE;
3340                         }
3341
3342                         /* Stop */
3343                         if (flag || !loop_flag) break;
3344                 }
3345
3346                 if (!flag)
3347                 {
3348                         x1 = 100 * (last_offer - offer) / (last_offer - cur_ask);
3349                         if (x1 < min_per)
3350                         {
3351                                 if (haggle_insults())
3352                                 {
3353                                         flag = TRUE;
3354                                         cancel = TRUE;
3355                                 }
3356                         }
3357                         else if (x1 > max_per)
3358                         {
3359                                 x1 = x1 * 3 / 4;
3360                                 if (x1 < max_per) x1 = max_per;
3361                         }
3362                         x2 = rand_range(x1-2, x1+2);
3363                         x3 = ((offer - cur_ask) * x2 / 100L) + 1;
3364                         /* don't let the price go down */
3365                         if (x3 < 0) x3 = 0;
3366                         cur_ask += x3;
3367
3368                         if (cur_ask > final_ask)
3369                         {
3370                                 cur_ask = final_ask;
3371                                 final = TRUE;
3372 #ifdef JP
3373                                 pmt = "最終提示金額";
3374 #else
3375                                 pmt = "Final Offer";
3376 #endif
3377
3378                                 annoyed++;
3379                                 if (annoyed > 3)
3380                                 {
3381                                         flag = TRUE;
3382 #ifdef JP
3383                                 /* 追加 $0 で買い取られてしまうのを防止 By FIRST*/
3384                                         cancel = TRUE;
3385 #endif
3386                                         (void)(increase_insults());
3387                                 }
3388                         }
3389                         else if (offer <= cur_ask)
3390                         {
3391                                 flag = TRUE;
3392                                 *price = offer;
3393                         }
3394
3395                         if (!flag)
3396                         {
3397                                 last_offer = offer;
3398                                 allow_inc = TRUE;
3399                                 prt("", 1, 0);
3400                                 (void)sprintf(out_val,
3401 #ifdef JP
3402                                               "前回の提示価格 $%ld", (long)last_offer);
3403 #else
3404                                                           "Your last bid %ld", (long)last_offer);
3405 #endif
3406
3407                                 put_str(out_val, 1, 39);
3408                                 say_comment_3(cur_ask, annoyed);
3409                         }
3410                 }
3411         }
3412
3413         /* Cancel */
3414         if (cancel) return (TRUE);
3415
3416         /* Update bargaining info */
3417         updatebargain(*price, final_ask, o_ptr->number);
3418
3419         /* Do not cancel */
3420         return (FALSE);
3421 }
3422
3423
3424 /*!
3425  * @brief 店からの購入処理のメインルーチン /
3426  * Buy an item from a store                     -RAK-
3427  * @return なし
3428  */
3429 static void store_purchase(void)
3430 {
3431         int i, choice;
3432         COMMAND_CODE item, item_new;
3433
3434         ITEM_NUMBER amt;
3435
3436         PRICE price, best;
3437
3438         object_type forge;
3439         object_type *j_ptr;
3440
3441         object_type *o_ptr;
3442
3443         char o_name[MAX_NLEN];
3444
3445         char out_val[160];
3446
3447         if (cur_store_num == STORE_MUSEUM)
3448         {
3449 #ifdef JP
3450                 msg_print("博物館から取り出すことはできません。");
3451 #else
3452                 msg_print("Museum.");
3453 #endif
3454                 return;
3455         }
3456
3457         /* Empty? */
3458         if (st_ptr->stock_num <= 0)
3459         {
3460                 if (cur_store_num == STORE_HOME)
3461 #ifdef JP
3462                         msg_print("我が家には何も置いてありません。");
3463 #else
3464                         msg_print("Your home is empty.");
3465 #endif
3466
3467                 else
3468 #ifdef JP
3469                         msg_print("現在商品の在庫を切らしています。");
3470 #else
3471                         msg_print("I am currently out of stock.");
3472 #endif
3473
3474                 return;
3475         }
3476
3477
3478         /* Find the number of objects on this and following pages */
3479         i = (st_ptr->stock_num - store_top);
3480
3481         /* And then restrict it to the current page */
3482         if (i > store_bottom) i = store_bottom;
3483
3484         /* Prompt */
3485 #ifdef JP
3486         /* ブラックマーケットの時は別のメッセージ */
3487         switch( cur_store_num ) {
3488                 case 7:
3489                         sprintf(out_val, "どのアイテムを取りますか? ");
3490                         break;
3491                 case 6:
3492                         sprintf(out_val, "どれ? ");
3493                         break;
3494                 default:
3495                         sprintf(out_val, "どの品物が欲しいんだい? ");
3496                         break;
3497         }
3498 #else
3499         if (cur_store_num == STORE_HOME)
3500         {
3501                 sprintf(out_val, "Which item do you want to take? ");
3502         }
3503         else
3504         {
3505                 sprintf(out_val, "Which item are you interested in? ");
3506         }
3507 #endif
3508
3509
3510         /* Get the item number to be bought */
3511         if (!get_stock(&item, out_val, 0, i - 1)) return;
3512
3513         /* Get the actual index */
3514         item = item + store_top;
3515
3516         /* Get the actual item */
3517         o_ptr = &st_ptr->stock[item];
3518
3519         /* Assume the player wants just one of them */
3520         amt = 1;
3521
3522         /* Get local object */
3523         j_ptr = &forge;
3524
3525         /* Get a copy of the object */
3526         object_copy(j_ptr, o_ptr);
3527
3528         /*
3529          * If a rod or wand, allocate total maximum timeouts or charges
3530          * between those purchased and left on the shelf.
3531          */
3532         reduce_charges(j_ptr, o_ptr->number - amt);
3533
3534         /* Modify quantity */
3535         j_ptr->number = amt;
3536
3537         /* Hack -- require room in pack */
3538         if (!inven_carry_okay(j_ptr))
3539         {
3540 #ifdef JP
3541 msg_print("そんなにアイテムを持てない。");
3542 #else
3543                 msg_print("You cannot carry that many different items.");
3544 #endif
3545
3546                 return;
3547         }
3548
3549         /* Determine the "best" price (per item) */
3550         best = price_item(j_ptr, ot_ptr->min_inflate, FALSE);
3551
3552         /* Find out how many the player wants */
3553         if (o_ptr->number > 1)
3554         {
3555                 /* Hack -- note cost of "fixed" items */
3556                 if ((cur_store_num != STORE_HOME) &&
3557                     (o_ptr->ident & IDENT_FIXED))
3558                 {
3559 #ifdef JP
3560 msg_format("一つにつき $%ldです。", (long)(best));
3561 #else
3562                         msg_format("That costs %ld gold per item.", (long)(best));
3563 #endif
3564
3565                 }
3566
3567                 /* Get a quantity */
3568                 amt = get_quantity(NULL, o_ptr->number);
3569
3570                 /* Allow user abort */
3571                 if (amt <= 0) return;
3572         }
3573
3574         /* Get local object */
3575         j_ptr = &forge;
3576
3577         /* Get desired object */
3578         object_copy(j_ptr, o_ptr);
3579
3580         /*
3581          * If a rod or wand, allocate total maximum timeouts or charges
3582          * between those purchased and left on the shelf.
3583          */
3584         reduce_charges(j_ptr, o_ptr->number - amt);
3585
3586         /* Modify quantity */
3587         j_ptr->number = amt;
3588
3589         /* Hack -- require room in pack */
3590         if (!inven_carry_okay(j_ptr))
3591         {
3592 #ifdef JP
3593                 msg_print("ザックにそのアイテムを入れる隙間がない。");
3594 #else
3595                 msg_print("You cannot carry that many items.");
3596 #endif
3597
3598                 return;
3599         }
3600
3601         /* Attempt to buy it */
3602         if (cur_store_num != STORE_HOME)
3603         {
3604                 /* Fixed price, quick buy */
3605                 if (o_ptr->ident & (IDENT_FIXED))
3606                 {
3607                         /* Assume accept */
3608                         choice = 0;
3609
3610                         /* Go directly to the "best" deal */
3611                         price = (best * j_ptr->number);
3612                 }
3613
3614                 /* Haggle for it */
3615                 else
3616                 {
3617                         /* Describe the object (fully) */
3618                         object_desc(o_name, j_ptr, 0);
3619
3620 #ifdef JP
3621                         msg_format("%s(%c)を購入する。", o_name, I2A(item));
3622 #else
3623                         msg_format("Buying %s (%c).", o_name, I2A(item));
3624 #endif
3625
3626                         msg_print(NULL);
3627
3628                         /* Haggle for a final price */
3629                         choice = purchase_haggle(j_ptr, &price);
3630
3631                         /* Hack -- Got kicked out */
3632                         if (st_ptr->store_open >= turn) return;
3633                 }
3634
3635                 /* Player wants it */
3636                 if (choice == 0)
3637                 {
3638                         /* Fix the item price (if "correctly" haggled) */
3639                         if (price == (best * j_ptr->number)) o_ptr->ident |= (IDENT_FIXED);
3640
3641                         /* Player can afford it */
3642                         if (p_ptr->au >= price)
3643                         {
3644                                 /* Say "okay" */
3645                                 say_comment_1();
3646
3647                                 if (cur_store_num == STORE_BLACK) /* The black market is illegal! */
3648                                         chg_virtue(V_JUSTICE, -1);
3649                                 if((o_ptr->tval == TV_BOTTLE) && (cur_store_num != STORE_HOME))
3650                                         chg_virtue(V_NATURE, -1);
3651
3652                                 /* Make a sound */
3653                                 sound(SOUND_BUY);
3654
3655                                 /* Be happy */
3656                                 decrease_insults();
3657
3658                                 /* Spend the money */
3659                                 p_ptr->au -= price;
3660
3661                                 /* Update the display */
3662                                 store_prt_gold();
3663
3664                                 /* Hack -- buying an item makes you aware of it */
3665                                 object_aware(j_ptr);
3666
3667                                 /* Hack -- clear the "fixed" flag from the item */
3668                                 j_ptr->ident &= ~(IDENT_FIXED);
3669
3670                                 /* Describe the transaction */
3671                                 object_desc(o_name, j_ptr, 0);
3672
3673 #ifdef JP
3674 msg_format("%sを $%ldで購入しました。", o_name, (long)price);
3675 #else
3676                                 msg_format("You bought %s for %ld gold.", o_name, (long)price);
3677 #endif
3678
3679                                 strcpy(record_o_name, o_name);
3680                                 record_turn = turn;
3681
3682                                 if (record_buy) do_cmd_write_nikki(NIKKI_BUY, 0, o_name);
3683                                 object_desc(o_name, o_ptr, OD_NAME_ONLY);
3684                                 if(record_rand_art && o_ptr->art_name)
3685                                         do_cmd_write_nikki(NIKKI_ART, 0, o_name);
3686
3687                                 /* Erase the inscription */
3688                                 j_ptr->inscription = 0;
3689
3690                                 /* Erase the "feeling" */
3691                                 j_ptr->feeling = FEEL_NONE;
3692                                 j_ptr->ident &= ~(IDENT_STORE);
3693                                 /* Give it to the player */
3694                                 item_new = inven_carry(j_ptr);
3695
3696                                 /* Describe the final result */
3697                                 object_desc(o_name, &inventory[item_new], 0);
3698
3699 #ifdef JP
3700                                 msg_format("%s(%c)を手に入れた。", o_name, index_to_label(item_new));
3701 #else
3702                                 msg_format("You have %s (%c).",
3703                                                    o_name, index_to_label(item_new));
3704 #endif
3705
3706                                 /* Auto-inscription */
3707                                 autopick_alter_item(item_new, FALSE);
3708
3709                                 /* Now, reduce the original stack's pval. */
3710                                 if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND))
3711                                 {
3712                                         o_ptr->pval -= j_ptr->pval;
3713                                 }
3714
3715                                 /* Handle stuff */
3716                                 handle_stuff();
3717
3718                                 /* Note how many slots the store used to have */
3719                                 i = st_ptr->stock_num;
3720
3721                                 /* Remove the bought items from the store */
3722                                 store_item_increase(item, -amt);
3723                                 store_item_optimize(item);
3724
3725                                 /* Store is empty */
3726                                 if (st_ptr->stock_num == 0)
3727                                 {
3728                                         /* Shuffle */
3729                                         if (one_in_(STORE_SHUFFLE))
3730                                         {
3731                                                 char buf[80];
3732 #ifdef JP
3733                                                 msg_print("店主は引退した。");
3734 #else
3735                                                 msg_print("The shopkeeper retires.");
3736 #endif
3737
3738
3739                                                 /* Shuffle the store */
3740                                                 store_shuffle(cur_store_num);
3741
3742                                                 prt("",3,0);
3743                                                 sprintf(buf, "%s (%s)",
3744                                                         ot_ptr->owner_name, race_info[ot_ptr->owner_race].title);
3745                                                 put_str(buf, 3, 10);
3746                                                 sprintf(buf, "%s (%ld)",
3747                                                         (f_name + f_info[cur_store_feat].name), (long)(ot_ptr->max_cost));
3748                                                 prt(buf, 3, 50);
3749                                         }
3750
3751                                         /* Maintain */
3752                                         else
3753                                         {
3754 #ifdef JP
3755                                                 msg_print("店主は新たな在庫を取り出した。");
3756 #else
3757                                                 msg_print("The shopkeeper brings out some new stock.");
3758 #endif
3759
3760                                         }
3761
3762                                         /* New inventory */
3763                                         for (i = 0; i < 10; i++)
3764                                         {
3765                                                 /* Maintain the store */
3766                                                 store_maint(p_ptr->town_num, cur_store_num);
3767                                         }
3768
3769                                         /* Start over */
3770                                         store_top = 0;
3771
3772                                         /* Redraw everything */
3773                                         display_inventory();
3774                                 }
3775
3776                                 /* The item is gone */
3777                                 else if (st_ptr->stock_num != i)
3778                                 {
3779                                         /* Pick the correct screen */
3780                                         if (store_top >= st_ptr->stock_num) store_top -= store_bottom;
3781
3782                                         /* Redraw everything */
3783                                         display_inventory();
3784                                 }
3785
3786                                 /* Item is still here */
3787                                 else
3788                                 {
3789                                         /* Redraw the item */
3790                                         display_entry(item);
3791                                 }
3792                         }
3793
3794                         /* Player cannot afford it */
3795                         else
3796                         {
3797                                 /* Simple message (no insult) */
3798 #ifdef JP
3799                                 msg_print("お金が足りません。");
3800 #else
3801                                 msg_print("You do not have enough gold.");
3802 #endif
3803
3804                         }
3805                 }
3806         }
3807
3808         /* Home is much easier */
3809         else
3810         {
3811                 bool combined_or_reordered;
3812
3813                 /* Distribute charges of wands/rods */
3814                 distribute_charges(o_ptr, j_ptr, amt);
3815
3816                 /* Give it to the player */
3817                 item_new = inven_carry(j_ptr);
3818
3819                 /* Describe just the result */
3820                 object_desc(o_name, &inventory[item_new], 0);
3821
3822 #ifdef JP
3823                 msg_format("%s(%c)を取った。",
3824 #else
3825                 msg_format("You have %s (%c).",
3826 #endif
3827  o_name, index_to_label(item_new));
3828
3829                 /* Handle stuff */
3830                 handle_stuff();
3831
3832                 /* Take note if we take the last one */
3833                 i = st_ptr->stock_num;
3834
3835                 /* Remove the items from the home */
3836                 store_item_increase(item, -amt);
3837                 store_item_optimize(item);
3838
3839                 combined_or_reordered = combine_and_reorder_home(STORE_HOME);
3840
3841                 /* Hack -- Item is still here */
3842                 if (i == st_ptr->stock_num)
3843                 {
3844                         /* Redraw everything */
3845                         if (combined_or_reordered) display_inventory();
3846
3847                         /* Redraw the item */
3848                         else display_entry(item);
3849                 }
3850
3851                 /* The item is gone */
3852                 else
3853                 {
3854                         /* Nothing left */
3855                         if (st_ptr->stock_num == 0) store_top = 0;
3856
3857                         /* Nothing left on that screen */
3858                         else if (store_top >= st_ptr->stock_num) store_top -= store_bottom;
3859
3860                         /* Redraw everything */
3861                         display_inventory();
3862
3863                         chg_virtue(V_SACRIFICE, 1);
3864                 }
3865         }
3866
3867         /* Not kicked out */
3868         return;
3869 }
3870
3871
3872 /*!
3873  * @brief 店からの売却処理のメインルーチン /
3874  * Sell an item to the store (or home)
3875  * @return なし
3876  */
3877 static void store_sell(void)
3878 {
3879         int choice;
3880         OBJECT_IDX item;
3881         int item_pos;
3882         int amt;
3883
3884         PRICE price, value, dummy;
3885
3886         object_type forge;
3887         object_type *q_ptr;
3888
3889         object_type *o_ptr;
3890
3891         cptr q, s;
3892
3893         char o_name[MAX_NLEN];
3894
3895
3896         /* Prepare a prompt */
3897         if (cur_store_num == STORE_HOME)
3898 #ifdef JP
3899         q = "どのアイテムを置きますか? ";
3900 #else
3901                 q = "Drop which item? ";
3902 #endif
3903
3904         else if (cur_store_num == STORE_MUSEUM)
3905 #ifdef JP
3906         q = "どのアイテムを寄贈しますか? ";
3907 #else
3908                 q = "Give which item? ";
3909 #endif
3910
3911         else
3912 #ifdef JP
3913                 q = "どのアイテムを売りますか? ";
3914 #else
3915                 q = "Sell which item? ";
3916 #endif
3917
3918
3919         item_tester_no_ryoute = TRUE;
3920         /* Only allow items the store will buy */
3921         item_tester_hook = store_will_buy;
3922
3923         /* 我が家でおかしなメッセージが出るオリジナルのバグを修正 */
3924         if (cur_store_num == STORE_HOME)
3925         {
3926 #ifdef JP
3927                 s = "置けるアイテムを持っていません。";
3928 #else
3929                 s = "You don't have any item to drop.";
3930 #endif
3931         }
3932         else if (cur_store_num == STORE_MUSEUM)
3933         {
3934 #ifdef JP
3935                 s = "寄贈できるアイテムを持っていません。";
3936 #else
3937                 s = "You don't have any item to give.";
3938 #endif
3939         }
3940         else
3941         {
3942 #ifdef JP
3943                 s = "欲しい物がないですねえ。";
3944 #else
3945                 s = "You have nothing that I want.";
3946 #endif
3947         }
3948
3949         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return;
3950
3951         /* Get the item (in the pack) */
3952         if (item >= 0)
3953         {
3954                 o_ptr = &inventory[item];
3955         }
3956
3957         /* Get the item (on the floor) */
3958         else
3959         {
3960                 o_ptr = &o_list[0 - item];
3961         }
3962
3963
3964         /* Hack -- Cannot remove cursed items */
3965         if ((item >= INVEN_RARM) && object_is_cursed(o_ptr))
3966         {
3967 #ifdef JP
3968                 msg_print("ふーむ、どうやらそれは呪われているようだね。");
3969 #else
3970                 msg_print("Hmmm, it seems to be cursed.");
3971 #endif
3972
3973
3974                 return;
3975         }
3976
3977
3978         /* Assume one item */
3979         amt = 1;
3980
3981         /* Find out how many the player wants (letter means "all") */
3982         if (o_ptr->number > 1)
3983         {
3984                 /* Get a quantity */
3985                 amt = get_quantity(NULL, o_ptr->number);
3986
3987                 /* Allow user abort */
3988                 if (amt <= 0) return;
3989         }
3990
3991         /* Get local object */
3992         q_ptr = &forge;
3993
3994         /* Get a copy of the object */
3995         object_copy(q_ptr, o_ptr);
3996
3997         /* Modify quantity */
3998         q_ptr->number = amt;
3999
4000         /*
4001          * Hack -- If a rod or wand, allocate total maximum
4002          * timeouts or charges to those being sold. -LM-
4003          */
4004         if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND))
4005         {
4006                 q_ptr->pval = o_ptr->pval * amt / o_ptr->number;
4007         }
4008
4009         /* Get a full description */
4010         object_desc(o_name, q_ptr, 0);
4011
4012         /* Remove any inscription, feeling for stores */
4013         if ((cur_store_num != STORE_HOME) && (cur_store_num != STORE_MUSEUM))
4014         {
4015                 q_ptr->inscription = 0;
4016                 q_ptr->feeling = FEEL_NONE;
4017         }
4018
4019         /* Is there room in the store (or the home?) */
4020         if (!store_check_num(q_ptr))
4021         {
4022                 if (cur_store_num == STORE_HOME)
4023 #ifdef JP
4024                         msg_print("我が家にはもう置く場所がない。");
4025 #else
4026                         msg_print("Your home is full.");
4027 #endif
4028
4029                 else if (cur_store_num == STORE_MUSEUM)
4030 #ifdef JP
4031                         msg_print("博物館はもう満杯だ。");
4032 #else
4033                         msg_print("Museum is full.");
4034 #endif
4035
4036                 else
4037 #ifdef JP
4038                         msg_print("すいませんが、店にはもう置く場所がありません。");
4039 #else
4040                         msg_print("I have not the room in my store to keep it.");
4041 #endif
4042
4043                 return;
4044         }
4045
4046
4047         /* Real store */
4048         if ((cur_store_num != STORE_HOME) && (cur_store_num != STORE_MUSEUM))
4049         {
4050                 /* Describe the transaction */
4051 #ifdef JP
4052                 msg_format("%s(%c)を売却する。", o_name, index_to_label(item));
4053 #else
4054                 msg_format("Selling %s (%c).", o_name, index_to_label(item));
4055 #endif
4056
4057                 msg_print(NULL);
4058
4059                 /* Haggle for it */
4060                 choice = sell_haggle(q_ptr, &price);
4061
4062                 /* Kicked out */
4063                 if (st_ptr->store_open >= turn) return;
4064
4065                 /* Sold... */
4066                 if (choice == 0)
4067                 {
4068                         /* Say "okay" */
4069                         say_comment_1();
4070
4071                         /* Make a sound */
4072                         sound(SOUND_SELL);
4073
4074                         /* Be happy */
4075                         if (cur_store_num == STORE_BLACK) /* The black market is illegal! */
4076                                 chg_virtue(V_JUSTICE, -1);
4077
4078                         if((o_ptr->tval == TV_BOTTLE) && (cur_store_num != STORE_HOME))
4079                                 chg_virtue(V_NATURE, 1);
4080                         decrease_insults();
4081
4082                         /* Get some money */
4083                         p_ptr->au += price;
4084
4085                         /* Update the display */
4086                         store_prt_gold();
4087
4088                         /* Get the "apparent" value */
4089                         dummy = object_value(q_ptr) * q_ptr->number;
4090
4091                         /* Identify it */
4092                         identify_item(o_ptr);
4093
4094                         /* Get local object */
4095                         q_ptr = &forge;
4096
4097                         /* Get a copy of the object */
4098                         object_copy(q_ptr, o_ptr);
4099
4100                         /* Modify quantity */
4101                         q_ptr->number = amt;
4102
4103                         /* Make it look like to be known */
4104                         q_ptr->ident |= IDENT_STORE;
4105
4106                         /*
4107                          * Hack -- If a rod or wand, let the shopkeeper know just
4108                          * how many charges he really paid for. -LM-
4109                          */
4110                         if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND))
4111                         {
4112                                 q_ptr->pval = o_ptr->pval * amt / o_ptr->number;
4113                         }
4114
4115                         /* Get the "actual" value */
4116                         value = object_value(q_ptr) * q_ptr->number;
4117
4118                         /* Get the description all over again */
4119                         object_desc(o_name, q_ptr, 0);
4120
4121                         /* Describe the result (in message buffer) */
4122 #ifdef JP
4123 msg_format("%sを $%ldで売却しました。", o_name, (long)price);
4124 #else
4125                         msg_format("You sold %s for %ld gold.", o_name, (long)price);
4126 #endif
4127
4128                         if (record_sell) do_cmd_write_nikki(NIKKI_SELL, 0, o_name);
4129
4130                         if (!((o_ptr->tval == TV_FIGURINE) && (value > 0)))
4131                         {
4132                          /* Analyze the prices (and comment verbally) unless a figurine*/
4133                         purchase_analyze(price, value, dummy);
4134                         }
4135
4136                         /*
4137                          * Hack -- Allocate charges between those wands or rods sold
4138                          * and retained, unless all are being sold. -LM-
4139                          */
4140                         distribute_charges(o_ptr, q_ptr, amt);
4141
4142                         /* Reset timeouts of the sold items */
4143                         q_ptr->timeout = 0;
4144
4145                         /* Take the item from the player, describe the result */
4146                         inven_item_increase(item, -amt);
4147                         inven_item_describe(item);
4148
4149                         /* If items remain, auto-inscribe before optimizing */
4150                         if (o_ptr->number > 0)
4151                                 autopick_alter_item(item, FALSE);
4152
4153                         inven_item_optimize(item);
4154
4155                         /* Handle stuff */
4156                         handle_stuff();
4157
4158                         /* The store gets that (known) item */
4159                         item_pos = store_carry(q_ptr);
4160
4161                         /* Re-display if item is now in store */
4162                         if (item_pos >= 0)
4163                         {
4164                                 store_top = (item_pos / store_bottom) * store_bottom;
4165                                 display_inventory();
4166                         }
4167                 }
4168         }
4169
4170         /* Player is at museum */
4171         else if (cur_store_num == STORE_MUSEUM)
4172         {
4173                 char o2_name[MAX_NLEN];
4174                 object_desc(o2_name, q_ptr, OD_NAME_ONLY);
4175
4176                 if (-1 == store_check_num(q_ptr))
4177                 {
4178 #ifdef JP
4179                         msg_print("それと同じ品物は既に博物館にあるようです。");
4180 #else
4181                         msg_print("The same object as it is already in the Museum.");
4182 #endif
4183                 }
4184                 else
4185                 {
4186 #ifdef JP
4187                         msg_print("博物館に寄贈したものは取り出すことができません!!");
4188 #else
4189                         msg_print("You cannot take items which is given to the Museum back!!");
4190 #endif
4191                 }
4192 #ifdef JP
4193                 if (!get_check(format("本当に%sを寄贈しますか?", o2_name))) return;
4194 #else
4195                 if (!get_check(format("Really give %s to the Museum? ", o2_name))) return;
4196 #endif
4197
4198                 /* Identify it */
4199                 identify_item(q_ptr);
4200                 q_ptr->ident |= IDENT_MENTAL;
4201
4202                 /* Distribute charges of wands/rods */
4203                 distribute_charges(o_ptr, q_ptr, amt);
4204
4205                 /* Describe */
4206 #ifdef JP
4207                 msg_format("%sを置いた。(%c)", o_name, index_to_label(item));
4208 #else
4209                 msg_format("You drop %s (%c).", o_name, index_to_label(item));
4210 #endif
4211
4212                 choice = 0;
4213
4214                 /* Take it from the players inventory */
4215                 inven_item_increase(item, -amt);
4216                 inven_item_describe(item);
4217                 inven_item_optimize(item);
4218
4219                 /* Handle stuff */
4220                 handle_stuff();
4221
4222                 /* Let the home carry it */
4223                 item_pos = home_carry(q_ptr);
4224
4225                 /* Update store display */
4226                 if (item_pos >= 0)
4227                 {
4228                         store_top = (item_pos / store_bottom) * store_bottom;
4229                         display_inventory();
4230                 }
4231         }
4232         /* Player is at home */
4233         else
4234         {
4235                 /* Distribute charges of wands/rods */
4236                 distribute_charges(o_ptr, q_ptr, amt);
4237
4238                 /* Describe */
4239 #ifdef JP
4240                 msg_format("%sを置いた。(%c)", o_name, index_to_label(item));
4241 #else
4242                 msg_format("You drop %s (%c).", o_name, index_to_label(item));
4243 #endif
4244
4245                 choice = 0;
4246
4247                 /* Take it from the players inventory */
4248                 inven_item_increase(item, -amt);
4249                 inven_item_describe(item);
4250                 inven_item_optimize(item);
4251
4252                 /* Handle stuff */
4253                 handle_stuff();
4254
4255                 /* Let the home carry it */
4256                 item_pos = home_carry(q_ptr);
4257
4258                 /* Update store display */
4259                 if (item_pos >= 0)
4260                 {
4261                         store_top = (item_pos / store_bottom) * store_bottom;
4262                         display_inventory();
4263                 }
4264         }
4265
4266         if ((choice == 0) && (item >= INVEN_RARM))
4267         {
4268                 calc_android_exp();
4269                 kamaenaoshi(item);
4270         }
4271 }
4272
4273
4274 /*!
4275  * @brief 店のアイテムを調べるコマンドのメインルーチン /
4276  * Examine an item in a store                      -JDL-
4277  * @return なし
4278  */
4279 static void store_examine(void)
4280 {
4281         int         i;
4282         COMMAND_CODE item;
4283         object_type *o_ptr;
4284         char        o_name[MAX_NLEN];
4285         char        out_val[160];
4286
4287
4288         /* Empty? */
4289         if (st_ptr->stock_num <= 0)
4290         {
4291                 if (cur_store_num == STORE_HOME)
4292 #ifdef JP
4293                         msg_print("我が家には何も置いてありません。");
4294 #else
4295                         msg_print("Your home is empty.");
4296 #endif
4297
4298                 else if (cur_store_num == STORE_MUSEUM)
4299 #ifdef JP
4300                         msg_print("博物館には何も置いてありません。");
4301 #else
4302                         msg_print("Museum is empty.");
4303 #endif
4304
4305                 else
4306 #ifdef JP
4307                         msg_print("現在商品の在庫を切らしています。");
4308 #else
4309                         msg_print("I am currently out of stock.");
4310 #endif
4311
4312                 return;
4313         }
4314
4315
4316         /* Find the number of objects on this and following pages */
4317         i = (st_ptr->stock_num - store_top);
4318
4319         /* And then restrict it to the current page */
4320         if (i > store_bottom) i = store_bottom;
4321
4322         /* Prompt */
4323 #ifdef JP
4324 sprintf(out_val, "どれを調べますか?");
4325 #else
4326         sprintf(out_val, "Which item do you want to examine? ");
4327 #endif
4328
4329
4330         /* Get the item number to be examined */
4331         if (!get_stock(&item, out_val, 0, i - 1)) return;
4332
4333         /* Get the actual index */
4334         item = item + store_top;
4335
4336         /* Get the actual item */
4337         o_ptr = &st_ptr->stock[item];
4338
4339         /* Require full knowledge */
4340         if (!(o_ptr->ident & IDENT_MENTAL))
4341         {
4342                 /* This can only happen in the home */
4343 #ifdef JP
4344 msg_print("このアイテムについて特に知っていることはない。");
4345 #else
4346                 msg_print("You have no special knowledge about that item.");
4347 #endif
4348
4349                 return;
4350         }
4351
4352         /* Description */
4353         object_desc(o_name, o_ptr, 0);
4354
4355         /* Describe */
4356 #ifdef JP
4357 msg_format("%sを調べている...", o_name);
4358 #else
4359         msg_format("Examining %s...", o_name);
4360 #endif
4361
4362
4363         /* Describe it fully */
4364         if (!screen_object(o_ptr, SCROBJ_FORCE_DETAIL))
4365 #ifdef JP
4366 msg_print("特に変わったところはないようだ。");
4367 #else
4368                 msg_print("You see nothing special.");
4369 #endif
4370
4371
4372         return;
4373 }
4374
4375
4376 /*!
4377  * @brief 博物館のアイテムを除去するコマンドのメインルーチン /
4378  * Remove an item from museum (Originally from TOband)
4379  * @return なし
4380  */
4381 static void museum_remove_object(void)
4382 {
4383         int         i;
4384         COMMAND_CODE item;
4385         object_type *o_ptr;
4386         char        o_name[MAX_NLEN];
4387         char        out_val[160];
4388
4389         /* Empty? */
4390         if (st_ptr->stock_num <= 0)
4391         {
4392 #ifdef JP
4393                 msg_print("博物館には何も置いてありません。");
4394 #else
4395                 msg_print("Museum is empty.");
4396 #endif
4397
4398                 return;
4399         }
4400
4401         /* Find the number of objects on this and following pages */
4402         i = st_ptr->stock_num - store_top;
4403
4404         /* And then restrict it to the current page */
4405         if (i > store_bottom) i = store_bottom;
4406
4407         /* Prompt */
4408 #ifdef JP
4409         sprintf(out_val, "どのアイテムの展示をやめさせますか?");
4410 #else
4411         sprintf(out_val, "Which item do you want to order to remove? ");
4412 #endif
4413
4414         /* Get the item number to be removed */
4415         if (!get_stock(&item, out_val, 0, i - 1)) return;
4416
4417         /* Get the actual index */
4418         item = item + store_top;
4419
4420         /* Get the actual item */
4421         o_ptr = &st_ptr->stock[item];
4422
4423         /* Description */
4424         object_desc(o_name, o_ptr, 0);
4425
4426 #ifdef JP
4427         msg_print("展示をやめさせたアイテムは二度と見ることはできません!");
4428         if (!get_check(format("本当に%sの展示をやめさせますか?", o_name))) return;
4429 #else
4430         msg_print("You cannot see items which is removed from the Museum!");
4431         if (!get_check(format("Really order to remove %s from the Museum? ", o_name))) return;
4432 #endif
4433
4434 #ifdef JP
4435         msg_format("%sの展示をやめさせた。", o_name);
4436 #else
4437         msg_format("You ordered to remove %s.", o_name);
4438 #endif
4439
4440         /* Remove the items from the home */
4441         store_item_increase(item, -o_ptr->number);
4442         store_item_optimize(item);
4443
4444         (void)combine_and_reorder_home(STORE_MUSEUM);
4445
4446         /* The item is gone */
4447
4448         /* Nothing left */
4449         if (st_ptr->stock_num == 0) store_top = 0;
4450
4451         /* Nothing left on that screen */
4452         else if (store_top >= st_ptr->stock_num) store_top -= store_bottom;
4453
4454         /* Redraw everything */
4455         display_inventory();
4456
4457         return;
4458 }
4459
4460
4461 /*
4462  * Hack -- set this to leave the store
4463  */
4464 static bool leave_store = FALSE;
4465
4466
4467 /*!
4468  * @brief 店舗処理コマンド選択のメインルーチン /
4469  * Process a command in a store
4470  * @return なし
4471  * @note
4472  * <pre>
4473  * Note that we must allow the use of a few "special" commands
4474  * in the stores which are not allowed in the dungeon, and we
4475  * must disable some commands which are allowed in the dungeon
4476  * but not in the stores, to prevent chaos.
4477  * </pre>
4478  */
4479 static void store_process_command(void)
4480 {
4481 #ifdef ALLOW_REPEAT /* TNB */
4482
4483         /* Handle repeating the last command */
4484         repeat_check();
4485
4486 #endif /* ALLOW_REPEAT -- TNB */
4487
4488         if (rogue_like_commands && command_cmd == 'l')
4489         {
4490                 command_cmd = 'x';      /* hack! */
4491         }
4492
4493         /* Parse the command */
4494         switch (command_cmd)
4495         {
4496                 /* Leave */
4497                 case ESCAPE:
4498                 {
4499                         leave_store = TRUE;
4500                         break;
4501                 }
4502
4503                 /* 日本語版追加 */
4504                 /* 1 ページ戻るコマンド: 我が家のページ数が多いので重宝するはず By BUG */
4505                 case '-':
4506                 {
4507                         if (st_ptr->stock_num <= store_bottom) {
4508 #ifdef JP
4509                                 msg_print("これで全部です。");
4510 #else
4511                                 msg_print("Entire inventory is shown.");
4512 #endif
4513                         }
4514                         else{
4515                                 store_top -= store_bottom;
4516                                 if ( store_top < 0 )
4517                                         store_top = ((st_ptr->stock_num - 1 )/store_bottom) * store_bottom;
4518                                 if ( (cur_store_num == STORE_HOME) && (powerup_home == FALSE) )
4519                                         if ( store_top >= store_bottom ) store_top = store_bottom;
4520                                 display_inventory();
4521                         }
4522                         break;
4523                 }
4524
4525                 /* Browse */
4526                 case ' ':
4527                 {
4528                         if (st_ptr->stock_num <= store_bottom)
4529                         {
4530 #ifdef JP
4531                                 msg_print("これで全部です。");
4532 #else
4533                                 msg_print("Entire inventory is shown.");
4534 #endif
4535
4536                         }
4537                         else
4538                         {
4539                                 store_top += store_bottom;
4540                                 /*
4541                                  * 隠しオプション(powerup_home)がセットされていないときは
4542                                  * 我が家では 2 ページまでしか表示しない
4543                                  */
4544                                 if ((cur_store_num == STORE_HOME) && 
4545                                     (powerup_home == FALSE) && 
4546                                         (st_ptr->stock_num >= STORE_INVEN_MAX))
4547                                 {
4548                                         if (store_top >= (STORE_INVEN_MAX - 1))
4549                                         {
4550                                                 store_top = 0;
4551                                         }
4552                                 }
4553                                 else
4554                                 {
4555                                         if (store_top >= st_ptr->stock_num) store_top = 0;
4556                                 }
4557
4558                                 display_inventory();
4559                         }
4560                         break;
4561                 }
4562
4563                 /* Redraw */
4564                 case KTRL('R'):
4565                 {
4566                         do_cmd_redraw();
4567                         display_store();
4568                         break;
4569                 }
4570
4571                 /* Get (purchase) */
4572                 case 'g':
4573                 {
4574                         store_purchase();
4575                         break;
4576                 }
4577
4578                 /* Drop (Sell) */
4579                 case 'd':
4580                 {
4581                         store_sell();
4582                         break;
4583                 }
4584
4585                 /* Examine */
4586                 case 'x':
4587                 {
4588                         store_examine();
4589                         break;
4590                 }
4591
4592                 /* Ignore return */
4593                 case '\r':
4594                 {
4595                         break;
4596                 }
4597
4598                 /*** Inventory Commands ***/
4599
4600                 /* Wear/wield equipment */
4601                 case 'w':
4602                 {
4603                         do_cmd_wield();
4604                         break;
4605                 }
4606
4607                 /* Take off equipment */
4608                 case 't':
4609                 {
4610                         do_cmd_takeoff();
4611                         break;
4612                 }
4613
4614                 /* Destroy an item */
4615                 case 'k':
4616                 {
4617                         do_cmd_destroy();
4618                         break;
4619                 }
4620
4621                 /* Equipment list */
4622                 case 'e':
4623                 {
4624                         do_cmd_equip();
4625                         break;
4626                 }
4627
4628                 /* Inventory list */
4629                 case 'i':
4630                 {
4631                         do_cmd_inven();
4632                         break;
4633                 }
4634
4635
4636                 /*** Various commands ***/
4637
4638                 /* Identify an object */
4639                 case 'I':
4640                 {
4641                         do_cmd_observe();
4642                         break;
4643                 }
4644
4645                 /* Hack -- toggle windows */
4646                 case KTRL('I'):
4647                 {
4648                         toggle_inven_equip();
4649                         break;
4650                 }
4651
4652
4653
4654                 /*** Use various objects ***/
4655
4656                 /* Browse a book */
4657                 case 'b':
4658                 {
4659                         if ( (p_ptr->pclass == CLASS_MINDCRAFTER) ||
4660                              (p_ptr->pclass == CLASS_BERSERKER) ||
4661                              (p_ptr->pclass == CLASS_NINJA) ||
4662                              (p_ptr->pclass == CLASS_MIRROR_MASTER) 
4663                              ) do_cmd_mind_browse();
4664                         else if (p_ptr->pclass == CLASS_SMITH)
4665                                 do_cmd_kaji(TRUE);
4666                         else if (p_ptr->pclass == CLASS_MAGIC_EATER)
4667                                 do_cmd_magic_eater(TRUE, FALSE);
4668                         else if (p_ptr->pclass == CLASS_SNIPER)
4669                                 do_cmd_snipe_browse();
4670                         else do_cmd_browse();
4671                         break;
4672                 }
4673
4674                 /* Inscribe an object */
4675                 case '{':
4676                 {
4677                         do_cmd_inscribe();
4678                         break;
4679                 }
4680
4681                 /* Uninscribe an object */
4682                 case '}':
4683                 {
4684                         do_cmd_uninscribe();
4685                         break;
4686                 }
4687
4688
4689
4690                 /*** Help and Such ***/
4691
4692                 /* Help */
4693                 case '?':
4694                 {
4695                         do_cmd_help();
4696                         break;
4697                 }
4698
4699                 /* Identify symbol */
4700                 case '/':
4701                 {
4702                         do_cmd_query_symbol();
4703                         break;
4704                 }
4705
4706                 /* Character description */
4707                 case 'C':
4708                 {
4709                         p_ptr->town_num = old_town_num;
4710                         do_cmd_change_name();
4711                         p_ptr->town_num = inner_town_num;
4712                         display_store();
4713                         break;
4714                 }
4715
4716
4717                 /*** System Commands ***/
4718
4719                 /* Hack -- User interface */
4720                 case '!':
4721                 {
4722                         (void)Term_user(0);
4723                         break;
4724                 }
4725
4726                 /* Single line from a pref file */
4727                 case '"':
4728                 {
4729                         p_ptr->town_num = old_town_num;
4730                         do_cmd_pref();
4731                         p_ptr->town_num = inner_town_num;
4732                         break;
4733                 }
4734
4735                 /* Interact with macros */
4736                 case '@':
4737                 {
4738                         p_ptr->town_num = old_town_num;
4739                         do_cmd_macros();
4740                         p_ptr->town_num = inner_town_num;
4741                         break;
4742                 }
4743
4744                 /* Interact with visuals */
4745                 case '%':
4746                 {
4747                         p_ptr->town_num = old_town_num;
4748                         do_cmd_visuals();
4749                         p_ptr->town_num = inner_town_num;
4750                         break;
4751                 }
4752
4753                 /* Interact with colors */
4754                 case '&':
4755                 {
4756                         p_ptr->town_num = old_town_num;
4757                         do_cmd_colors();
4758                         p_ptr->town_num = inner_town_num;
4759                         break;
4760                 }
4761
4762                 /* Interact with options */
4763                 case '=':
4764                 {
4765                         do_cmd_options();
4766                         (void)combine_and_reorder_home(STORE_HOME);
4767                         do_cmd_redraw();
4768                         display_store();
4769                         break;
4770                 }
4771
4772                 /*** Misc Commands ***/
4773
4774                 /* Take notes */
4775                 case ':':
4776                 {
4777                         do_cmd_note();
4778                         break;
4779                 }
4780
4781                 /* Version info */
4782                 case 'V':
4783                 {
4784                         do_cmd_version();
4785                         break;
4786                 }
4787
4788                 /* Repeat level feeling */
4789                 case KTRL('F'):
4790                 {
4791                         do_cmd_feeling();
4792                         break;
4793                 }
4794
4795                 /* Show previous message */
4796                 case KTRL('O'):
4797                 {
4798                         do_cmd_message_one();
4799                         break;
4800                 }
4801
4802                 /* Show previous messages */
4803                 case KTRL('P'):
4804                 {
4805                         do_cmd_messages(0);
4806                         break;
4807                 }
4808
4809                 case '|':
4810                 {
4811                         do_cmd_nikki();
4812                         break;
4813                 }
4814
4815                 /* Check artifacts, uniques etc. */
4816                 case '~':
4817                 {
4818                         do_cmd_knowledge();
4819                         break;
4820                 }
4821
4822                 /* Load "screen dump" */
4823                 case '(':
4824                 {
4825                         do_cmd_load_screen();
4826                         break;
4827                 }
4828
4829                 /* Save "screen dump" */
4830                 case ')':
4831                 {
4832                         do_cmd_save_screen();
4833                         break;
4834                 }
4835
4836                 /* Hack -- Unknown command */
4837                 default:
4838                 {
4839                         if ((cur_store_num == STORE_MUSEUM) && (command_cmd == 'r'))
4840                         {
4841                                 museum_remove_object();
4842                         }
4843                         else
4844                         {
4845 #ifdef JP
4846                                 msg_print("そのコマンドは店の中では使えません。");
4847 #else
4848                                 msg_print("That command does not work in stores.");
4849 #endif
4850                         }
4851
4852                         break;
4853                 }
4854         }
4855 }
4856
4857
4858 /*!
4859  * @brief 店舗処理全体のメインルーチン /
4860  * Enter a store, and interact with it. *
4861  * @return なし
4862  * @note
4863  * <pre>
4864  * Note that we use the standard "request_command()" function
4865  * to get a command, allowing us to use "command_arg" and all
4866  * command macros and other nifty stuff, but we use the special
4867  * "shopping" argument, to force certain commands to be converted
4868  * into other commands, normally, we convert "p" (pray) and "m"
4869  * (cast magic) into "g" (get), and "s" (search) into "d" (drop).
4870  * </pre>
4871  */
4872 void do_cmd_store(void)
4873 {
4874         int         which;
4875         int         maintain_num;
4876         int         i;
4877         cave_type   *c_ptr;
4878         bool        need_redraw_store_inv; /* To redraw missiles damage and prices in store */
4879         int w, h;
4880
4881         /* Get term size */
4882         Term_get_size(&w, &h);
4883
4884         /* Calculate stocks per 1 page */
4885         xtra_stock = MIN(14+26, ((h > 24) ? (h - 24) : 0));
4886         store_bottom = MIN_STOCK + xtra_stock;
4887
4888         /* Access the player grid */
4889         c_ptr = &cave[p_ptr->y][p_ptr->x];
4890
4891         /* Verify a store */
4892         if (!cave_have_flag_grid(c_ptr, FF_STORE))
4893         {
4894 #ifdef JP
4895                 msg_print("ここには店がありません。");
4896 #else
4897                 msg_print("You see no store here.");
4898 #endif
4899
4900                 return;
4901         }
4902
4903         /* Extract the store code */
4904         which = f_info[c_ptr->feat].subtype;
4905
4906         old_town_num = p_ptr->town_num;
4907         if ((which == STORE_HOME) || (which == STORE_MUSEUM)) p_ptr->town_num = 1;
4908         if (dun_level) p_ptr->town_num = NO_TOWN;
4909         inner_town_num = p_ptr->town_num;
4910
4911         /* Hack -- Check the "locked doors" */
4912         if ((town[p_ptr->town_num].store[which].store_open >= turn) ||
4913             (ironman_shops))
4914         {
4915 #ifdef JP
4916                 msg_print("ドアに鍵がかかっている。");
4917 #else
4918                 msg_print("The doors are locked.");
4919 #endif
4920
4921                 p_ptr->town_num = old_town_num;
4922                 return;
4923         }
4924
4925         /* Calculate the number of store maintainances since the last visit */
4926         maintain_num = (turn - town[p_ptr->town_num].store[which].last_visit) / (TURNS_PER_TICK * STORE_TICKS);
4927
4928         /* Maintain the store max. 10 times */
4929         if (maintain_num > 10) maintain_num = 10;
4930
4931         if (maintain_num)
4932         {
4933                 /* Maintain the store */
4934                 for (i = 0; i < maintain_num; i++)
4935                         store_maint(p_ptr->town_num, which);
4936
4937                 /* Save the visit */
4938                 town[p_ptr->town_num].store[which].last_visit = turn;
4939         }
4940
4941         /* Forget the lite */
4942         forget_lite();
4943
4944         /* Forget the view */
4945         forget_view();
4946
4947
4948         /* Hack -- Character is in "icky" mode */
4949         character_icky = TRUE;
4950
4951
4952         /* No command argument */
4953         command_arg = 0;
4954
4955         /* No repeated command */
4956         command_rep = 0;
4957
4958         /* No automatic command */
4959         command_new = 0;
4960
4961         /* Do not expand macros */
4962         get_com_no_macros = TRUE;
4963
4964         /* Save the store number */
4965         cur_store_num = which;
4966
4967         /* Hack -- save the store feature */
4968         cur_store_feat = c_ptr->feat;
4969
4970         /* Save the store and owner pointers */
4971         st_ptr = &town[p_ptr->town_num].store[cur_store_num];
4972         ot_ptr = &owners[cur_store_num][st_ptr->owner];
4973
4974
4975         /* Start at the beginning */
4976         store_top = 0;
4977
4978         play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_BUILD);
4979
4980         /* Display the store */
4981         display_store();
4982
4983         /* Do not leave */
4984         leave_store = FALSE;
4985
4986         /* Interact with player */
4987         while (!leave_store)
4988         {
4989                 /* Hack -- Clear line 1 */
4990                 prt("", 1, 0);
4991
4992                 /* Clear */
4993                 clear_from(20 + xtra_stock);
4994
4995
4996                 /* Basic commands */
4997 #ifdef JP
4998                 prt(" ESC) 建物から出る", 21 + xtra_stock, 0);
4999 #else
5000                 prt(" ESC) Exit from Building.", 21 + xtra_stock, 0);
5001 #endif
5002
5003
5004                 /* Browse if necessary */
5005                 if (st_ptr->stock_num > store_bottom)
5006                 {
5007 #ifdef JP
5008                         prt(" -)前ページ", 22 + xtra_stock, 0);
5009                         prt(" スペース) 次ページ", 23 + xtra_stock, 0);
5010 #else
5011                         prt(" -) Previous page", 22 + xtra_stock, 0);
5012                         prt(" SPACE) Next page", 23 + xtra_stock, 0);
5013 #endif
5014
5015                 }
5016
5017                 /* Home commands */
5018                 if (cur_store_num == STORE_HOME)
5019                 {
5020 #ifdef JP
5021                         prt("g) アイテムを取る", 21 + xtra_stock, 27);
5022                         prt("d) アイテムを置く", 22 + xtra_stock, 27);
5023                         prt("x) 家のアイテムを調べる", 23 + xtra_stock, 27);
5024 #else
5025                         prt("g) Get an item.", 21 + xtra_stock, 27);
5026                         prt("d) Drop an item.", 22 + xtra_stock, 27);
5027                         prt("x) eXamine an item in the home.", 23 + xtra_stock, 27);
5028 #endif
5029                 }
5030
5031                 /* Museum commands */
5032                 else if (cur_store_num == STORE_MUSEUM)
5033                 {
5034 #ifdef JP
5035                         prt("d) アイテムを置く", 21 + xtra_stock, 27);
5036                         prt("r) アイテムの展示をやめる", 22 + xtra_stock, 27);
5037                         prt("x) 博物館のアイテムを調べる", 23 + xtra_stock, 27);
5038 #else
5039                         prt("d) Drop an item.", 21 + xtra_stock, 27);
5040                         prt("r) order to Remove an item.", 22 + xtra_stock, 27);
5041                         prt("x) eXamine an item in the museum.", 23 + xtra_stock, 27);
5042 #endif
5043                 }
5044
5045                 /* Shop commands */
5046                 else
5047                 {
5048 #ifdef JP
5049                         prt("p) 商品を買う", 21 + xtra_stock, 30);
5050                         prt("s) アイテムを売る", 22 + xtra_stock, 30);
5051                         prt("x) 商品を調べる", 23 + xtra_stock,30);
5052 #else
5053                         prt("p) Purchase an item.", 21 + xtra_stock, 30);
5054                         prt("s) Sell an item.", 22 + xtra_stock, 30);
5055                         prt("x) eXamine an item in the shop", 23 + xtra_stock,30);
5056 #endif
5057                 }
5058
5059 #ifdef JP
5060                 /* 基本的なコマンドの追加表示 */
5061
5062                 prt("i/e) 持ち物/装備の一覧", 21 + xtra_stock, 56);
5063
5064                 if (rogue_like_commands)
5065                 {
5066                         prt("w/T) 装備する/はずす", 22 + xtra_stock, 56);
5067                 }
5068                 else
5069                 {
5070                         prt("w/t) 装備する/はずす", 22 + xtra_stock, 56);
5071                 }
5072 #else
5073                 prt("i/e) Inventry/Equipment list", 21 + xtra_stock, 56);
5074
5075                 if (rogue_like_commands)
5076                 {
5077                         prt("w/T) Wear/Take off equipment", 22 + xtra_stock, 56);
5078                 }
5079                 else
5080                 {
5081                         prt("w/t) Wear/Take off equipment", 22 + xtra_stock, 56);
5082                 }
5083 #endif
5084                 /* Prompt */
5085 #ifdef JP
5086                 prt("コマンド:", 20 + xtra_stock, 0);
5087 #else
5088                 prt("You may: ", 20 + xtra_stock, 0);
5089 #endif
5090
5091
5092                 /* Get a command */
5093                 request_command(TRUE);
5094
5095                 /* Process the command */
5096                 store_process_command();
5097
5098                 /*
5099                  * Hack -- To redraw missiles damage and prices in store
5100                  * If player's charisma changes, or if player changes a bow, PU_BONUS is set
5101                  */
5102                 need_redraw_store_inv = (p_ptr->update & PU_BONUS) ? TRUE : FALSE;
5103
5104                 /* Hack -- Character is still in "icky" mode */
5105                 character_icky = TRUE;
5106
5107                 /* Notice stuff */
5108                 notice_stuff();
5109
5110                 /* Handle stuff */
5111                 handle_stuff();
5112
5113                 /* Pack Overflow */
5114                 if (inventory[INVEN_PACK].k_idx)
5115                 {
5116                         INVENTORY_IDX item = INVEN_PACK;
5117
5118                         object_type *o_ptr = &inventory[item];
5119
5120                         /* Hack -- Flee from the store */
5121                         if (cur_store_num != STORE_HOME)
5122                         {
5123 #ifdef JP
5124                                 if (cur_store_num == STORE_MUSEUM)
5125                                         msg_print("ザックからアイテムがあふれそうなので、あわてて博物館から出た...");
5126                                 else
5127                                         msg_print("ザックからアイテムがあふれそうなので、あわてて店から出た...");
5128 #else
5129                                 if (cur_store_num == STORE_MUSEUM)
5130                                         msg_print("Your pack is so full that you flee the Museum...");
5131                                 else
5132                                         msg_print("Your pack is so full that you flee the store...");
5133 #endif
5134
5135
5136                                 /* Leave */
5137                                 leave_store = TRUE;
5138                         }
5139
5140                         /* Hack -- Flee from the home */
5141                         else if (!store_check_num(o_ptr))
5142                         {
5143 #ifdef JP
5144                                 msg_print("ザックからアイテムがあふれそうなので、あわてて家から出た...");
5145 #else
5146                                 msg_print("Your pack is so full that you flee your home...");
5147 #endif
5148
5149
5150                                 /* Leave */
5151                                 leave_store = TRUE;
5152                         }
5153
5154                         /* Hack -- Drop items into the home */
5155                         else
5156                         {
5157                                 int item_pos;
5158
5159                                 object_type forge;
5160                                 object_type *q_ptr;
5161
5162                                 char o_name[MAX_NLEN];
5163
5164
5165                                 /* Give a message */
5166 #ifdef JP
5167                                 msg_print("ザックからアイテムがあふれてしまった!");
5168 #else
5169                                 msg_print("Your pack overflows!");
5170 #endif
5171
5172
5173                                 /* Get local object */
5174                                 q_ptr = &forge;
5175
5176                                 /* Grab a copy of the item */
5177                                 object_copy(q_ptr, o_ptr);
5178
5179                                 /* Describe it */
5180                                 object_desc(o_name, q_ptr, 0);
5181
5182 #ifdef JP
5183                                 msg_format("%sが落ちた。(%c)", o_name, index_to_label(item));
5184 #else
5185                                 msg_format("You drop %s (%c).", o_name, index_to_label(item));
5186 #endif
5187
5188
5189                                 /* Remove it from the players inventory */
5190                                 inven_item_increase(item, -255);
5191                                 inven_item_describe(item);
5192                                 inven_item_optimize(item);
5193
5194                                 /* Handle stuff */
5195                                 handle_stuff();
5196
5197                                 /* Let the home carry it */
5198                                 item_pos = home_carry(q_ptr);
5199
5200                                 /* Redraw the home */
5201                                 if (item_pos >= 0)
5202                                 {
5203                                         store_top = (item_pos / store_bottom) * store_bottom;
5204                                         display_inventory();
5205                                 }
5206                         }
5207                 }
5208
5209                 /* Hack -- Redisplay store prices if charisma changes */
5210                 /* Hack -- Redraw missiles damage if player changes bow */
5211                 if (need_redraw_store_inv) display_inventory();
5212
5213                 /* Hack -- get kicked out of the store */
5214                 if (st_ptr->store_open >= turn) leave_store = TRUE;
5215         }
5216
5217         select_floor_music();
5218
5219         p_ptr->town_num = old_town_num;
5220
5221         /* Free turn */
5222         p_ptr->energy_use = 100;
5223
5224
5225         /* Hack -- Character is no longer in "icky" mode */
5226         character_icky = FALSE;
5227
5228
5229         /* Hack -- Cancel automatic command */
5230         command_new = 0;
5231
5232         /* Hack -- Cancel "see" mode */
5233         command_see = FALSE;
5234
5235         /* Allow expanding macros */
5236         get_com_no_macros = FALSE;
5237
5238         /* Flush messages */
5239         msg_print(NULL);
5240
5241
5242         /* Clear the screen */
5243         Term_clear();
5244
5245
5246         /* Update everything */
5247         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
5248         p_ptr->update |= (PU_MONSTERS);
5249
5250         /* Redraw entire screen */
5251         p_ptr->redraw |= (PR_BASIC | PR_EXTRA | PR_EQUIPPY);
5252
5253         /* Redraw map */
5254         p_ptr->redraw |= (PR_MAP);
5255
5256         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
5257 }
5258
5259
5260
5261 /*!
5262  * @brief 現在の町の店主を交代させる /
5263  * Shuffle one of the stores.
5264  * @param which 店舗種類のID
5265  * @return なし
5266  */
5267 void store_shuffle(int which)
5268 {
5269         int i, j;
5270
5271
5272         /* Ignore home */
5273         if (which == STORE_HOME) return;
5274         if (which == STORE_MUSEUM) return;
5275
5276
5277         /* Save the store index */
5278         cur_store_num = which;
5279
5280         /* Activate that store */
5281         st_ptr = &town[p_ptr->town_num].store[cur_store_num];
5282
5283         j = st_ptr->owner;
5284         /* Pick a new owner */
5285         while(1)
5286         {
5287                 st_ptr->owner = (byte)randint0(MAX_OWNERS);
5288                 if (j == st_ptr->owner) continue;
5289                 for (i = 1;i < max_towns; i++)
5290                 {
5291                         if (i == p_ptr->town_num) continue;
5292                         if (st_ptr->owner == town[i].store[cur_store_num].owner) break;
5293                 }
5294                 if (i == max_towns) break;
5295         }
5296
5297         /* Activate the new owner */
5298         ot_ptr = &owners[cur_store_num][st_ptr->owner];
5299
5300
5301         /* Reset the owner data */
5302         st_ptr->insult_cur = 0;
5303         st_ptr->store_open = 0;
5304         st_ptr->good_buy = 0;
5305         st_ptr->bad_buy = 0;
5306
5307
5308         /* Hack -- discount all the items */
5309         for (i = 0; i < st_ptr->stock_num; i++)
5310         {
5311                 object_type *o_ptr;
5312
5313                 /* Get the item */
5314                 o_ptr = &st_ptr->stock[i];
5315
5316                 if (!object_is_artifact(o_ptr))
5317                 {
5318                         /* Hack -- Sell all non-artifact old items for "half price" */
5319                         o_ptr->discount = 50;
5320
5321                         /* Hack -- Items are no longer "fixed price" */
5322                         o_ptr->ident &= ~(IDENT_FIXED);
5323
5324                         /* Mega-Hack -- Note that the item is "on sale" */
5325 #ifdef JP
5326                         o_ptr->inscription = quark_add("売出中");
5327 #else
5328                         o_ptr->inscription = quark_add("on sale");
5329 #endif
5330                 }
5331         }
5332 }
5333
5334
5335 /*!
5336  * @brief 店の品揃えを変化させる /
5337  * Maintain the inventory at the stores.
5338  * @param town_num 町のID
5339  * @param store_num 店舗種類のID
5340  * @return なし
5341  */
5342 void store_maint(int town_num, int store_num)
5343 {
5344         INVENTORY_IDX j;
5345
5346         cur_store_num = store_num;
5347
5348         /* Ignore home */
5349         if (store_num == STORE_HOME) return;
5350         if (store_num == STORE_MUSEUM) return;
5351
5352         /* Activate that store */
5353         st_ptr = &town[town_num].store[store_num];
5354
5355         /* Activate the owner */
5356         ot_ptr = &owners[store_num][st_ptr->owner];
5357
5358         /* Store keeper forgives the player */
5359         st_ptr->insult_cur = 0;
5360
5361         /* Mega-Hack -- prune the black market */
5362         if (store_num == STORE_BLACK)
5363         {
5364                 /* Destroy crappy black market items */
5365                 for (j = st_ptr->stock_num - 1; j >= 0; j--)
5366                 {
5367                         object_type *o_ptr = &st_ptr->stock[j];
5368
5369                         /* Destroy crappy items */
5370                         if (black_market_crap(o_ptr))
5371                         {
5372                                 /* Destroy the item */
5373                                 store_item_increase(j, 0 - o_ptr->number);
5374                                 store_item_optimize(j);
5375                         }
5376                 }
5377         }
5378
5379
5380         /* Choose the number of slots to keep */
5381         j = st_ptr->stock_num;
5382
5383         /* Sell a few items */
5384         j = j - randint1(STORE_TURNOVER);
5385
5386         /* Never keep more than "STORE_MAX_KEEP" slots */
5387         if (j > STORE_MAX_KEEP) j = STORE_MAX_KEEP;
5388
5389         /* Always "keep" at least "STORE_MIN_KEEP" items */
5390         if (j < STORE_MIN_KEEP) j = STORE_MIN_KEEP;
5391
5392         /* Hack -- prevent "underflow" */
5393         if (j < 0) j = 0;
5394
5395         /* Destroy objects until only "j" slots are left */
5396         while (st_ptr->stock_num > j) store_delete();
5397
5398
5399         /* Choose the number of slots to fill */
5400         j = st_ptr->stock_num;
5401
5402         /* Buy some more items */
5403         j = j + randint1(STORE_TURNOVER);
5404
5405         /* Never keep more than "STORE_MAX_KEEP" slots */
5406         if (j > STORE_MAX_KEEP) j = STORE_MAX_KEEP;
5407
5408         /* Always "keep" at least "STORE_MIN_KEEP" items */
5409         if (j < STORE_MIN_KEEP) j = STORE_MIN_KEEP;
5410
5411         /* Hack -- prevent "overflow" */
5412         if (j >= st_ptr->stock_size) j = st_ptr->stock_size - 1;
5413
5414         /* Acquire some new items */
5415         while (st_ptr->stock_num < j) store_create();
5416 }
5417
5418
5419 /*!
5420  * @brief 店舗情報を初期化する /
5421  * Initialize the stores
5422  * @param town_num 町のID
5423  * @param store_num 店舗種類のID
5424  * @return なし
5425  */
5426 void store_init(int town_num, int store_num)
5427 {
5428         int             k;
5429
5430         cur_store_num = store_num;
5431
5432         /* Activate that store */
5433         st_ptr = &town[town_num].store[store_num];
5434
5435
5436         /* Pick an owner */
5437         while(1)
5438         {
5439                 int i;
5440
5441                 st_ptr->owner = (byte)randint0(MAX_OWNERS);
5442                 for (i = 1;i < max_towns; i++)
5443                 {
5444                         if (i == town_num) continue;
5445                         if (st_ptr->owner == town[i].store[store_num].owner) break;
5446                 }
5447                 if (i == max_towns) break;
5448         }
5449
5450         /* Activate the new owner */
5451         ot_ptr = &owners[store_num][st_ptr->owner];
5452
5453
5454         /* Initialize the store */
5455         st_ptr->store_open = 0;
5456         st_ptr->insult_cur = 0;
5457         st_ptr->good_buy = 0;
5458         st_ptr->bad_buy = 0;
5459
5460         /* Nothing in stock */
5461         st_ptr->stock_num = 0;
5462
5463         /*
5464          * MEGA-HACK - Last visit to store is
5465          * BEFORE player birth to enable store restocking
5466          */
5467         st_ptr->last_visit = -10L * TURNS_PER_TICK * STORE_TICKS;
5468
5469         /* Clear any old items */
5470         for (k = 0; k < st_ptr->stock_size; k++)
5471         {
5472                 object_wipe(&st_ptr->stock[k]);
5473         }
5474 }
5475
5476
5477 /*!
5478  * @brief アイテムを町のブラックマーケットに移動させる /
5479  * @param o_ptr 移動させたいオブジェクトの構造体参照ポインタ
5480  * @return なし
5481  */
5482 void move_to_black_market(object_type *o_ptr)
5483 {
5484         /* Not in town */
5485         if (!p_ptr->town_num) return;
5486
5487         st_ptr = &town[p_ptr->town_num].store[STORE_BLACK];
5488
5489         o_ptr->ident |= IDENT_STORE;
5490
5491         (void)store_carry(o_ptr);
5492
5493         object_wipe(o_ptr); /* Don't leave a bogus object behind... */
5494 }
5495