OSDN Git Service

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