OSDN Git Service

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