OSDN Git Service

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