OSDN Git Service

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