OSDN Git Service

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