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