OSDN Git Service

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