OSDN Git Service

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