OSDN Git Service

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