OSDN Git Service

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