OSDN Git Service

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