OSDN Git Service

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