OSDN Git Service

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