OSDN Git Service

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