OSDN Git Service

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