OSDN Git Service

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