OSDN Git Service

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