OSDN Git Service

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