OSDN Git Service

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