OSDN Git Service

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