OSDN Git Service

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