OSDN Git Service

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