OSDN Git Service

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