OSDN Git Service

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