OSDN Git Service

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