OSDN Git Service

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