OSDN Git Service

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