OSDN Git Service

Add Doxygen comment to bldg.c.
[hengband/hengband.git] / src / bldg.c
1 /*!
2     @file bldg.c
3     @brief Ä®¤Î»ÜÀß½èÍý / Building commands
4     @date 2013/12/23
5     @author
6     Created by Ken Wigle for Kangband - a variant of Angband 2.8.3\n
7     -KMW-\n
8     \n
9     Rewritten for Kangband 2.8.3i using Kamband's version of\n
10     bldg.c as written by Ivan Tkatchev\n
11     \n
12     Changed for ZAngband by Robert Ruehlmann\n
13 */
14
15 #include "angband.h"
16
17
18 /*!
19  * ¥ë¡¼¥×Ãæ¤Ç / hack as in leave_store in store.c
20  */
21 static bool leave_bldg = FALSE;
22
23 /*!
24  * @brief »ÜÀßËè¤ËÀßÄꤵ¤ì¤¿¼ï²¡¢¿¦¶È¡¢ËâË¡Îΰè¥Õ¥é¥°¤¬¥×¥ì¥¤¥ä¡¼¤È°ìÃפ¹¤ë¤«¤òȽÄꤹ¤ë¡£
25  * @details ³Æ¼ï¥®¥ë¥É¤ä»û±¡¤Ê¤É¡¢ÆÃÄê¤Î¿¦¶È¤Ê¤é¤ÐÍ¥¶øÁ¼ÃÖ¤òÆÀ¤é¤ì¤ë»ÜÀß¡¢
26  * ¤¢¤ë¤¤¤Ï¿©Æ²¤Ê¤ÉÆÃÄê¤Î¼ï²¤Ç¤ÏÍøÍѤǤ­¤Ê¤¤»ÜÀߤÎȽÄê½èÍý¤ò¹Ô¤¦¡£
27  * @param bldg »ÜÀß¹½Â¤ÂΤλ²¾È¥Ý¥¤¥ó¥¿
28  * @return ¼ï²¡¢¿¦¶È¡¢ËâË¡Îΰè¤Î¤¤¤º¤ì¤«¤¬°ìÃפ·¤Æ¤¤¤ë¤«¤ÎÀ§Èó¡£
29  */
30 static bool is_owner(building_type *bldg)
31 {
32         if (bldg->member_class[p_ptr->pclass] == BUILDING_OWNER)
33         {
34                 return (TRUE);
35         }
36
37         if (bldg->member_race[p_ptr->prace] == BUILDING_OWNER)
38         {
39                 return (TRUE);
40         }
41
42         if ((is_magic(p_ptr->realm1) && (bldg->member_realm[p_ptr->realm1] == BUILDING_OWNER)) ||
43                 (is_magic(p_ptr->realm2) && (bldg->member_realm[p_ptr->realm2] == BUILDING_OWNER)))
44         {
45                 return (TRUE);
46         }
47
48         return (FALSE);
49 }
50
51 /*!
52  * @brief »ÜÀßËè¤ËÀßÄꤵ¤ì¤¿¼ï²¡¢¿¦¶È¡¢ËâË¡Îΰè¥Õ¥é¥°¤¬¥×¥ì¥¤¥ä¡¼¤È°ìÃפ¹¤ë¤«¤òȽÄꤹ¤ë¡£
53  ¡Ê¥¹¥Ú¥ë¥Þ¥¹¥¿¡¼¤ÎÆÃÊÌȽÄê¤Ä¤­¡Ë
54  * @details ³Æ¼ï¥®¥ë¥É¤ä»û±¡¤Ê¤É¡¢ÆÃÄê¤Î¿¦¶È¤Ê¤é¤ÐÍ¥¶øÁ¼ÃÖ¤òÆÀ¤é¤ì¤ë»ÜÀß¡¢
55  * ¤¢¤ë¤¤¤Ï¿©Æ²¤Ê¤ÉÆÃÄê¤Î¼ï²¤Ç¤ÏÍøÍѤǤ­¤Ê¤¤»ÜÀߤÎȽÄê½èÍý¤ò¹Ô¤¦¡£
56  * @param bldg »ÜÀß¹½Â¤ÂΤλ²¾È¥Ý¥¤¥ó¥¿
57  * @return ¼ï²¡¢¿¦¶È¡¢ËâË¡Îΰè¤Î¤¤¤º¤ì¤«¤¬°ìÃפ·¤Æ¤¤¤ë¤«¤ÎÀ§Èó¡£
58  * @todo is_owner()¤È¤Î¼Â¼ÁŪ¤Ê¿½Å¼ÂÁõ¤Ê¤Î¤Ç¡¢¥ê¥Õ¥¡¥¯¥¿¥ê¥ó¥°¤ò¹Ô¤¦¤Ù¤­¤Ç¤¢¤ë¡£
59  */
60 static bool is_member(building_type *bldg)
61 {
62         if (bldg->member_class[p_ptr->pclass])
63         {
64                 return (TRUE);
65         }
66
67         if (bldg->member_race[p_ptr->prace])
68         {
69                 return (TRUE);
70         }
71
72         if ((is_magic(p_ptr->realm1) && bldg->member_realm[p_ptr->realm1]) ||
73             (is_magic(p_ptr->realm2) && bldg->member_realm[p_ptr->realm2]))
74         {
75                 return (TRUE);
76         }
77
78
79         if (p_ptr->pclass == CLASS_SORCERER)
80         {
81                 int i;
82                 bool OK = FALSE;
83                 for (i = 0; i < MAX_MAGIC; i++)
84                 {
85                         if (bldg->member_realm[i+1]) OK = TRUE;
86                 }
87                 return OK;
88         }
89         return (FALSE);
90 }
91
92 /*!
93  * @brief ¥³¥ó¥½¡¼¥ë¤Ëɽ¼¨¤µ¤ì¤¿»ÜÀߤ˴ؤ¹¤ë¾ðÊó¤ò¾Ãµî¤¹¤ë / Clear the building information
94  * @details ¾Ãµî¤Ï¹ÔËè¤Ë¥Ì¥ëʸ»úÎó¤Ç¹Ô¤ï¤ì¤ë¡£
95  * @param min_row ³«»Ï¹ÔÈÖ¹æ
96  * @param max_row ËöÈø¹ÔÈÖ¹æ
97  * @return ¤Ê¤·
98  */
99 static void clear_bldg(int min_row, int max_row)
100 {
101         int   i;
102
103         for (i = min_row; i <= max_row; i++)
104                 prt("", i, 0);
105 }
106
107 /*!
108  * @brief ½ê»ý¶â¤òɽ¼¨¤¹¤ë¡£
109  * @param ¤Ê¤·
110  * @return ¤Ê¤·
111  */
112 static void building_prt_gold(void)
113 {
114         char tmp_str[80];
115
116 #ifdef JP
117 prt("¼ê»ý¤Á¤Î¤ª¶â: ", 23,53);
118 #else
119         prt("Gold Remaining: ", 23, 53);
120 #endif
121
122
123         sprintf(tmp_str, "%9ld", (long)p_ptr->au);
124         prt(tmp_str, 23, 68);
125 }
126
127 /*!
128  * @brief »ÜÀߤΥµ¡¼¥Ó¥¹°ìÍ÷¤òɽ¼¨¤¹¤ë / Display a building.
129  * @param bldg »ÜÀß¹½Â¤ÂΤλ²¾È¥Ý¥¤¥ó¥¿
130  * @return ¤Ê¤·
131  */
132 static void show_building(building_type* bldg)
133 {
134         char buff[20];
135         int i;
136         byte action_color;
137         char tmp_str[80];
138
139         Term_clear();
140         sprintf(tmp_str, "%s (%s) %35s", bldg->owner_name, bldg->owner_race, bldg->name);
141         prt(tmp_str, 2, 1);
142
143
144         for (i = 0; i < 8; i++)
145         {
146                 if (bldg->letters[i])
147                 {
148                         if (bldg->action_restr[i] == 0)
149                         {
150                                 if ((is_owner(bldg) && (bldg->member_costs[i] == 0)) ||
151                                         (!is_owner(bldg) && (bldg->other_costs[i] == 0)))
152                                 {
153                                         action_color = TERM_WHITE;
154                                         buff[0] = '\0';
155                                 }
156                                 else if (is_owner(bldg))
157                                 {
158                                         action_color = TERM_YELLOW;
159 #ifdef JP
160 sprintf(buff, "($%ld)", (long int)bldg->member_costs[i]);
161 #else
162                                         sprintf(buff, "(%ldgp)", (long int)bldg->member_costs[i]);
163 #endif
164
165                                 }
166                                 else
167                                 {
168                                         action_color = TERM_YELLOW;
169 #ifdef JP
170 sprintf(buff, "($%ld)", (long int)bldg->other_costs[i]);
171 #else
172                                         sprintf(buff, "(%ldgp)", (long int)bldg->other_costs[i]);
173 #endif
174
175                                 }
176                         }
177                         else if (bldg->action_restr[i] == 1)
178                         {
179                                 if (!is_member(bldg))
180                                 {
181                                         action_color = TERM_L_DARK;
182 #ifdef JP
183 strcpy(buff, "(ÊÄŹ)");
184 #else
185                                         strcpy(buff, "(closed)");
186 #endif
187
188                                 }
189                                 else if ((is_owner(bldg) && (bldg->member_costs[i] == 0)) ||
190                                         (is_member(bldg) && (bldg->other_costs[i] == 0)))
191                                 {
192                                         action_color = TERM_WHITE;
193                                         buff[0] = '\0';
194                                 }
195                                 else if (is_owner(bldg))
196                                 {
197                                         action_color = TERM_YELLOW;
198 #ifdef JP
199 sprintf(buff, "($%ld)", (long int)bldg->member_costs[i]);
200 #else
201                                         sprintf(buff, "(%ldgp)", (long int)bldg->member_costs[i]);
202 #endif
203
204                                 }
205                                 else
206                                 {
207                                         action_color = TERM_YELLOW;
208 #ifdef JP
209 sprintf(buff, "($%ld)", (long int)bldg->other_costs[i]);
210 #else
211                                         sprintf(buff, "(%ldgp)", (long int)bldg->other_costs[i]);
212 #endif
213
214                                 }
215                         }
216                         else
217                         {
218                                 if (!is_owner(bldg))
219                                 {
220                                         action_color = TERM_L_DARK;
221 #ifdef JP
222 strcpy(buff, "(ÊÄŹ)");
223 #else
224                                         strcpy(buff, "(closed)");
225 #endif
226
227                                 }
228                                 else if (bldg->member_costs[i] != 0)
229                                 {
230                                         action_color = TERM_YELLOW;
231 #ifdef JP
232 sprintf(buff, "($%ld)", (long int)bldg->member_costs[i]);
233 #else
234                                         sprintf(buff, "(%ldgp)", (long int)bldg->member_costs[i]);
235 #endif
236
237                                 }
238                                 else
239                                 {
240                                         action_color = TERM_WHITE;
241                                         buff[0] = '\0';
242                                 }
243                         }
244
245                         sprintf(tmp_str," %c) %s %s", bldg->letters[i], bldg->act_names[i], buff);
246                         c_put_str(action_color, tmp_str, 19+(i/2), 35*(i%2));
247                 }
248         }
249
250 #ifdef JP
251 prt(" ESC) ·úʪ¤ò½Ð¤ë", 23, 0);
252 #else
253         prt(" ESC) Exit building", 23, 0);
254 #endif
255
256 }
257
258 /*!
259  * @brief Æ®µ»¾ì¤ËÆþ¤ë¥³¥Þ¥ó¥É¤Î½èÍý / arena commands
260  * @param cmd Æ®µ»¾ì½èÍý¤ÎID
261  * @return ¤Ê¤·
262  */
263 static void arena_comm(int cmd)
264 {
265         monster_race    *r_ptr;
266         cptr            name;
267
268
269         switch (cmd)
270         {
271                 case BACT_ARENA:
272                         if (p_ptr->arena_number == MAX_ARENA_MONS)
273                         {
274                                 clear_bldg(5, 19);
275 #ifdef JP
276 prt("¥¢¥ê¡¼¥Ê¤ÎÍ¥¾¡¼Ô¡ª", 5, 0);
277 prt("¤ª¤á¤Ç¤È¤¦¡ª¤¢¤Ê¤¿¤ÏÁ´¤Æ¤ÎŨ¤òÅݤ·¤Þ¤·¤¿¡£", 7, 0); 
278 prt("¾Þ¶â¤È¤·¤Æ $1,000,000 ¤¬Í¿¤¨¤é¤ì¤Þ¤¹¡£", 8, 0);
279 #else
280                                 prt("               Arena Victor!", 5, 0);
281                                 prt("Congratulations!  You have defeated all before you.", 7, 0);
282                                 prt("For that, receive the prize: 1,000,000 gold pieces", 8, 0);
283 #endif
284
285                                 prt("", 10, 0);
286                                 prt("", 11, 0);
287                                 p_ptr->au += 1000000L;
288 #ifdef JP
289 msg_print("¥¹¥Ú¡¼¥¹¥­¡¼¤Ç³¹Ô");
290 #else
291                                 msg_print("Press the space bar to continue");
292 #endif
293
294                                 msg_print(NULL);
295                                 p_ptr->arena_number++;
296                         }
297                         else if (p_ptr->arena_number > MAX_ARENA_MONS)
298                         {
299                                 if (p_ptr->arena_number < MAX_ARENA_MONS+2)
300                                 {
301 #ifdef JP
302 msg_print("·¯¤Î¤¿¤á¤ËºÇ¶¯¤ÎÄ©Àï¼Ô¤òÍÑ°Õ¤·¤Æ¤ª¤¤¤¿¡£");
303 #else
304                                         msg_print("The strongest challenger is waiting for you.");
305 #endif
306
307                                         msg_print(NULL);
308 #ifdef JP
309                                         if (get_check("Ä©À魯¤ë¤«¤Í¡©"))
310 #else
311                                         if (get_check("Do you fight? "))
312 #endif
313                                         {       
314 #ifdef JP
315                         msg_print("»à¤Ì¤¬¤è¤¤¡£");
316 #else
317                                             msg_print("Die, maggots.");
318 #endif
319                                                 msg_print(NULL);
320                                         
321                                                 p_ptr->exit_bldg = FALSE;
322                                                 reset_tim_flags();
323
324                                                 /* Save the surface floor as saved floor */
325                                                 prepare_change_floor_mode(CFM_SAVE_FLOORS);
326
327                                                 p_ptr->inside_arena = TRUE;
328                                                 p_ptr->leaving = TRUE;
329                                                 leave_bldg = TRUE;
330                                         }
331                                         else
332                                         {
333 #ifdef JP
334 msg_print("»ÄÇ°¤À¡£");
335 #else
336                                                 msg_print("We are disappointed.");
337 #endif
338                                         }
339                                 }
340                                 else
341                                 {
342 #ifdef JP
343 msg_print("¤¢¤Ê¤¿¤Ï¥¢¥ê¡¼¥Ê¤ËÆþ¤ê¡¢¤·¤Ð¤é¤¯¤Î´Ö±É¸÷¤Ë¤Ò¤¿¤Ã¤¿¡£");
344 #else
345                                         msg_print("You enter the arena briefly and bask in your glory.");
346 #endif
347
348                                         msg_print(NULL);
349                                 }
350                         }
351                         else if (p_ptr->riding && (p_ptr->pclass != CLASS_BEASTMASTER) && (p_ptr->pclass != CLASS_CAVALRY))
352                         {
353 #ifdef JP
354 msg_print("¥Ú¥Ã¥È¤Ë¾è¤Ã¤¿¤Þ¤Þ¤Ç¤Ï¥¢¥ê¡¼¥Ê¤ØÆþ¤ì¤µ¤»¤Æ¤â¤é¤¨¤Ê¤«¤Ã¤¿¡£");
355 #else
356                                 msg_print("You don't have permission to enter with pet.");
357 #endif
358
359                                 msg_print(NULL);
360                         }
361                         else
362                         {
363                                 p_ptr->exit_bldg = FALSE;
364                                 reset_tim_flags();
365
366                                 /* Save the surface floor as saved floor */
367                                 prepare_change_floor_mode(CFM_SAVE_FLOORS);
368
369                                 p_ptr->inside_arena = TRUE;
370                                 p_ptr->leaving = TRUE;
371                                 leave_bldg = TRUE;
372                         }
373                         break;
374                 case BACT_POSTER:
375                         if (p_ptr->arena_number == MAX_ARENA_MONS)
376 #ifdef JP
377 msg_print("¤¢¤Ê¤¿¤Ï¾¡Íø¼Ô¤À¡£ ¥¢¥ê¡¼¥Ê¤Ç¤Î¥»¥ì¥â¥Ë¡¼¤Ë»²²Ã¤·¤Ê¤µ¤¤¡£");
378 #else
379                                 msg_print("You are victorious. Enter the arena for the ceremony.");
380 #endif
381
382                         else if (p_ptr->arena_number > MAX_ARENA_MONS)
383                         {
384 #ifdef JP
385 msg_print("¤¢¤Ê¤¿¤Ï¤¹¤Ù¤Æ¤ÎŨ¤Ë¾¡Íø¤·¤¿¡£");
386 #else
387                                 msg_print("You have won against all foes.");
388 #endif
389                         }
390                         else
391                         {
392                                 r_ptr = &r_info[arena_info[p_ptr->arena_number].r_idx];
393                                 name = (r_name + r_ptr->name);
394 #ifdef JP
395 msg_format("%s ¤ËÄ©À魯¤ë¤â¤Î¤Ï¤¤¤Ê¤¤¤«¡©", name);
396 #else
397                                 msg_format("Do I hear any challenges against: %s", name);
398 #endif
399                         }
400                         break;
401                 case BACT_ARENA_RULES:
402
403                         /* Save screen */
404                         screen_save();
405
406                         /* Peruse the arena help file */
407 #ifdef JP
408 (void)show_file(TRUE, "arena_j.txt", NULL, 0, 0);
409 #else
410                         (void)show_file(TRUE, "arena.txt", NULL, 0, 0);
411 #endif
412
413
414                         /* Load screen */
415                         screen_load();
416
417                         break;
418         }
419 }
420
421 /*!
422  * @brief ¥«¥¸¥Î¤Î¥¹¥í¥Ã¥È¥·¥ó¥Ü¥ë¤òɽ¼¨¤¹¤ë / display fruit for dice slots
423  * @param row ¥·¥ó¥Ü¥ë¤òɽ¼¨¤¹¤ë¹Ô¤Î¾åü
424  * @param col ¥·¥ó¥Ü¥ë¤òɽ¼¨¤¹¤ë¹Ô¤Îº¸Ã¼
425  * @param fruit É½¼¨¤¹¤ë¥·¥ó¥Ü¥ëID
426  * @return ¤Ê¤·
427  */
428 static void display_fruit(int row, int col, int fruit)
429 {
430         switch (fruit)
431         {
432                 case 0: /* lemon */
433 #ifdef JP
434                         c_put_str(TERM_YELLOW, "   ####.", row, col);
435                         c_put_str(TERM_YELLOW, "  #    #", row + 1, col);
436                         c_put_str(TERM_YELLOW, " #     #", row + 2, col);
437                         c_put_str(TERM_YELLOW, "#      #", row + 3, col);
438                         c_put_str(TERM_YELLOW, "#      #", row + 4, col);
439                         c_put_str(TERM_YELLOW, "#     # ", row + 5, col);
440                         c_put_str(TERM_YELLOW, "#    #  ", row + 6, col);
441                         c_put_str(TERM_YELLOW, ".####   ", row + 7, col);
442                         prt(                   " ¥ì¥â¥ó ", row + 8, col);
443 #else
444                         c_put_str(TERM_YELLOW, "   ####.", row, col);
445                         c_put_str(TERM_YELLOW, "  #    #", row + 1, col);
446                         c_put_str(TERM_YELLOW, " #     #", row + 2, col);
447                         c_put_str(TERM_YELLOW, "#      #", row + 3, col);
448                         c_put_str(TERM_YELLOW, "#      #", row + 4, col);
449                         c_put_str(TERM_YELLOW, "#     # ", row + 5, col);
450                         c_put_str(TERM_YELLOW, "#    #  ", row + 6, col);
451                         c_put_str(TERM_YELLOW, ".####   ", row + 7, col);
452                         prt(                   " Lemon  ", row + 8, col);
453 #endif
454
455                         break;
456                 case 1: /* orange */
457 #ifdef JP
458                         c_put_str(TERM_ORANGE, "   ##   ", row, col);
459                         c_put_str(TERM_ORANGE, "  #..#  ", row + 1, col);
460                         c_put_str(TERM_ORANGE, " #....# ", row + 2, col);
461                         c_put_str(TERM_ORANGE, "#......#", row + 3, col);
462                         c_put_str(TERM_ORANGE, "#......#", row + 4, col);
463                         c_put_str(TERM_ORANGE, " #....# ", row + 5, col);
464                         c_put_str(TERM_ORANGE, "  #..#  ", row + 6, col);
465                         c_put_str(TERM_ORANGE, "   ##   ", row + 7, col);
466                         prt(                   "¥ª¥ì¥ó¥¸", row + 8, col);
467 #else
468                         c_put_str(TERM_ORANGE, "   ##   ", row, col);
469                         c_put_str(TERM_ORANGE, "  #..#  ", row + 1, col);
470                         c_put_str(TERM_ORANGE, " #....# ", row + 2, col);
471                         c_put_str(TERM_ORANGE, "#......#", row + 3, col);
472                         c_put_str(TERM_ORANGE, "#......#", row + 4, col);
473                         c_put_str(TERM_ORANGE, " #....# ", row + 5, col);
474                         c_put_str(TERM_ORANGE, "  #..#  ", row + 6, col);
475                         c_put_str(TERM_ORANGE, "   ##   ", row + 7, col);
476                         prt(                   " Orange ", row + 8, col);
477 #endif
478
479                         break;
480                 case 2: /* sword */
481 #ifdef JP
482                         c_put_str(TERM_SLATE, "   ¦«   " , row, col);
483                         c_put_str(TERM_SLATE, "   ||   " , row + 1, col);
484                         c_put_str(TERM_SLATE, "   ||   " , row + 2, col);
485                         c_put_str(TERM_SLATE, "   ||   " , row + 3, col);
486                         c_put_str(TERM_SLATE, "   ||   " , row + 4, col);
487                         c_put_str(TERM_SLATE, "   ||   " , row + 5, col);
488                         c_put_str(TERM_UMBER, " |=°¡=| " , row + 6, col);
489                         c_put_str(TERM_UMBER, "   ÌÜ   " , row + 7, col);
490                         prt(                  "   ·õ   " , row + 8, col);
491 #else
492                         c_put_str(TERM_SLATE, "   /\\   " , row, col);
493                         c_put_str(TERM_SLATE, "   ##   " , row + 1, col);
494                         c_put_str(TERM_SLATE, "   ##   " , row + 2, col);
495                         c_put_str(TERM_SLATE, "   ##   " , row + 3, col);
496                         c_put_str(TERM_SLATE, "   ##   " , row + 4, col);
497                         c_put_str(TERM_SLATE, "   ##   " , row + 5, col);
498                         c_put_str(TERM_UMBER, " ###### " , row + 6, col);
499                         c_put_str(TERM_UMBER, "   ##   " , row + 7, col);
500                         prt(                  " Sword  " , row + 8, col);
501 #endif
502
503                         break;
504                 case 3: /* shield */
505 #ifdef JP
506                         c_put_str(TERM_SLATE, " ###### ", row, col);
507                         c_put_str(TERM_SLATE, "#      #", row + 1, col);
508                         c_put_str(TERM_SLATE, "# ++++ #", row + 2, col);
509                         c_put_str(TERM_SLATE, "# +==+ #", row + 3, col);
510                         c_put_str(TERM_SLATE, "#  ++  #", row + 4, col);
511                         c_put_str(TERM_SLATE, " #    # ", row + 5, col);
512                         c_put_str(TERM_SLATE, "  #  #  ", row + 6, col);
513                         c_put_str(TERM_SLATE, "   ##   ", row + 7, col);
514                         prt(                  "   ½â   ", row + 8, col);
515 #else
516                         c_put_str(TERM_SLATE, " ###### ", row, col);
517                         c_put_str(TERM_SLATE, "#      #", row + 1, col);
518                         c_put_str(TERM_SLATE, "# ++++ #", row + 2, col);
519                         c_put_str(TERM_SLATE, "# +==+ #", row + 3, col);
520                         c_put_str(TERM_SLATE, "#  ++  #", row + 4, col);
521                         c_put_str(TERM_SLATE, " #    # ", row + 5, col);
522                         c_put_str(TERM_SLATE, "  #  #  ", row + 6, col);
523                         c_put_str(TERM_SLATE, "   ##   ", row + 7, col);
524                         prt(                  " Shield ", row + 8, col);
525 #endif
526
527                         break;
528                 case 4: /* plum */
529 #ifdef JP
530                         c_put_str(TERM_VIOLET, "   ##   ", row, col);
531                         c_put_str(TERM_VIOLET, " ###### ", row + 1, col);
532                         c_put_str(TERM_VIOLET, "########", row + 2, col);
533                         c_put_str(TERM_VIOLET, "########", row + 3, col);
534                         c_put_str(TERM_VIOLET, "########", row + 4, col);
535                         c_put_str(TERM_VIOLET, " ###### ", row + 5, col);
536                         c_put_str(TERM_VIOLET, "  ####  ", row + 6, col);
537                         c_put_str(TERM_VIOLET, "   ##   ", row + 7, col);
538                         prt(                   " ¥×¥é¥à ", row + 8, col);
539 #else
540                         c_put_str(TERM_VIOLET, "   ##   ", row, col);
541                         c_put_str(TERM_VIOLET, " ###### ", row + 1, col);
542                         c_put_str(TERM_VIOLET, "########", row + 2, col);
543                         c_put_str(TERM_VIOLET, "########", row + 3, col);
544                         c_put_str(TERM_VIOLET, "########", row + 4, col);
545                         c_put_str(TERM_VIOLET, " ###### ", row + 5, col);
546                         c_put_str(TERM_VIOLET, "  ####  ", row + 6, col);
547                         c_put_str(TERM_VIOLET, "   ##   ", row + 7, col);
548                         prt(                   "  Plum  ", row + 8, col);
549 #endif
550
551                         break;
552                 case 5: /* cherry */
553 #ifdef JP
554                         c_put_str(TERM_RED, "      ##", row, col);
555                         c_put_str(TERM_RED, "   ###  ", row + 1, col);
556                         c_put_str(TERM_RED, "  #..#  ", row + 2, col);
557                         c_put_str(TERM_RED, "  #..#  ", row + 3, col);
558                         c_put_str(TERM_RED, " ###### ", row + 4, col);
559                         c_put_str(TERM_RED, "#..##..#", row + 5, col);
560                         c_put_str(TERM_RED, "#..##..#", row + 6, col);
561                         c_put_str(TERM_RED, " ##  ## ", row + 7, col);
562                         prt(                "¥Á¥§¥ê¡¼", row + 8, col);
563 #else
564                         c_put_str(TERM_RED, "      ##", row, col);
565                         c_put_str(TERM_RED, "   ###  ", row + 1, col);
566                         c_put_str(TERM_RED, "  #..#  ", row + 2, col);
567                         c_put_str(TERM_RED, "  #..#  ", row + 3, col);
568                         c_put_str(TERM_RED, " ###### ", row + 4, col);
569                         c_put_str(TERM_RED, "#..##..#", row + 5, col);
570                         c_put_str(TERM_RED, "#..##..#", row + 6, col);
571                         c_put_str(TERM_RED, " ##  ## ", row + 7, col);
572                         prt(                " Cherry ", row + 8, col);
573 #endif
574
575                         break;
576         }
577 }
578
579 /*
580  * kpoker no (tyuto-hannpa na)pakuri desu...
581  * joker ha shineru node haitte masen.
582  *
583  * TODO: donataka! tsukutte!
584  *  - agatta yaku no kiroku (like DQ).
585  *  - kakkoii card no e.
586  *  - sousa-sei no koujyo.
587  *  - code wo wakariyasuku.
588  *  - double up.
589  *  - Joker... -- done.
590  *
591  * 9/13/2000 --Koka
592  * 9/15/2000 joker wo jissou. soreto, code wo sukosi kakikae. --Habu
593  */
594 #define SUIT_OF(card)  ((card) / 13)
595 #define NUM_OF(card)   ((card) % 13)
596 #define IS_JOKER(card) ((card) == 52)
597
598 static int cards[5]; /* tefuda no card */
599
600 static void reset_deck(int deck[])
601 {
602         int i;
603         for (i = 0; i < 53; i++) deck[i] = i;
604
605         /* shuffle cards */
606         for (i = 0; i < 53; i++){
607                 int tmp1 = randint0(53 - i) + i;
608                 int tmp2 = deck[i];
609                 deck[i] = deck[tmp1];
610                 deck[tmp1] = tmp2;
611         }
612 }
613
614 static bool have_joker(void)
615 {
616         int i;
617
618         for (i = 0; i < 5; i++){
619           if(IS_JOKER(cards[i])) return TRUE;
620         }
621         return FALSE;
622 }
623
624 static bool find_card_num(int num)
625 {
626         int i;
627         for (i = 0; i < 5; i++)
628                 if (NUM_OF(cards[i]) == num && !IS_JOKER(cards[i])) return TRUE;
629         return FALSE;
630 }
631
632 static bool yaku_check_flush(void)
633 {
634         int i, suit;
635         bool joker_is_used = FALSE;
636
637         suit = IS_JOKER(cards[0]) ? SUIT_OF(cards[1]) : SUIT_OF(cards[0]);
638         for (i = 0; i < 5; i++){
639                 if (SUIT_OF(cards[i]) != suit){
640                   if(have_joker() && !joker_is_used)
641                     joker_is_used = TRUE;
642                   else
643                     return FALSE;
644                 }
645         }
646
647         return TRUE;
648 }
649
650 static int yaku_check_straight(void)
651 {
652         int i, lowest = 99;
653         bool joker_is_used = FALSE;
654
655         /* get lowest */
656         for (i = 0; i < 5; i++)
657         {
658                 if (NUM_OF(cards[i]) < lowest && !IS_JOKER(cards[i]))
659                         lowest = NUM_OF(cards[i]);
660         }
661         
662         if (yaku_check_flush())
663         {
664           if( lowest == 0 ){
665                 for (i = 0; i < 4; i++)
666                 {
667                         if (!find_card_num(9 + i)){
668                                 if( have_joker() && !joker_is_used )
669                                   joker_is_used = TRUE;
670                                 else
671                                   break;
672                         }
673                 }
674                 if (i == 4) return 3; /* Wow! Royal Flush!!! */
675           }
676           if( lowest == 9 ){
677                 for (i = 0; i < 3; i++)
678                 {
679                         if (!find_card_num(10 + i))
680                                 break;
681                 }
682                 if (i == 3 && have_joker()) return 3; /* Wow! Royal Flush!!! */
683           }
684         }
685
686         joker_is_used = FALSE;
687         for (i = 0; i < 5; i++)
688         {
689                 if (!find_card_num(lowest + i)){
690                   if( have_joker() && !joker_is_used )
691                     joker_is_used = TRUE;
692                   else
693                     return 0;
694                 }
695         }
696         
697         if (yaku_check_flush())
698                 return 2; /* Straight Flush */
699
700         return 1;
701 }
702
703 /*
704  * 0:nopair 1:1 pair 2:2 pair 3:3 cards 4:full house 6:4cards
705  */
706 static int yaku_check_pair(void)
707 {
708         int i, i2, matching = 0;
709
710         for (i = 0; i < 5; i++)
711         {
712                 for (i2 = i+1; i2 < 5; i2++)
713                 {
714                         if (IS_JOKER(cards[i]) || IS_JOKER(cards[i2])) continue;
715                         if (NUM_OF(cards[i]) == NUM_OF(cards[i2]))
716                                 matching++;
717                 }
718         }
719
720         if(have_joker()){
721           switch(matching){
722           case 0:
723             matching = 1;
724             break;
725           case 1:
726             matching = 3;
727             break;
728           case 2:
729             matching = 4;
730             break;
731           case 3:
732             matching = 6;
733             break;
734           case 6:
735             matching = 7;
736             break;
737           default:
738             /* don't reach */
739             break;
740           }
741         }
742
743         return matching;
744 }
745
746 #define ODDS_5A 3000
747 #define ODDS_5C 400
748 #define ODDS_RF 200
749 #define ODDS_SF 80
750 #define ODDS_4C 16
751 #define ODDS_FH 12
752 #define ODDS_FL 8
753 #define ODDS_ST 4
754 #define ODDS_3C 1
755 #define ODDS_2P 1
756
757 static int yaku_check(void)
758 {
759         prt("                            ", 4, 3);
760
761         switch(yaku_check_straight()){
762         case 3: /* RF! */
763 #ifdef JP
764                 c_put_str(TERM_YELLOW, "¥í¥¤¥ä¥ë¥¹¥È¥ì¡¼¥È¥Õ¥é¥Ã¥·¥å",  4,  3);
765 #else
766                 c_put_str(TERM_YELLOW, "Royal Flush",  4,  3);
767 #endif
768                 return ODDS_RF;
769         case 2: /* SF! */
770 #ifdef JP
771                 c_put_str(TERM_YELLOW, "¥¹¥È¥ì¡¼¥È¥Õ¥é¥Ã¥·¥å",  4,  3);
772 #else
773                 c_put_str(TERM_YELLOW, "Straight Flush",  4,  3);
774 #endif
775                 return ODDS_SF;
776         case 1:
777 #ifdef JP
778                 c_put_str(TERM_YELLOW, "¥¹¥È¥ì¡¼¥È",  4,  3);
779 #else
780                 c_put_str(TERM_YELLOW, "Straight",  4,  3);
781 #endif
782                 return ODDS_ST;
783         default:
784                 /* Not straight -- fall through */
785                 break;
786         }
787
788         if (yaku_check_flush())
789         {
790
791 #ifdef JP
792         c_put_str(TERM_YELLOW, "¥Õ¥é¥Ã¥·¥å",  4,  3);
793 #else
794         c_put_str(TERM_YELLOW, "Flush",  4,  3);
795 #endif
796                 return ODDS_FL;
797         }
798
799         switch (yaku_check_pair())
800         {
801         case 1:
802 #ifdef JP
803                 c_put_str(TERM_YELLOW, "¥ï¥ó¥Ú¥¢",  4,  3);
804 #else
805                 c_put_str(TERM_YELLOW, "One pair",  4,  3);
806 #endif
807                 return 0;
808         case 2:
809 #ifdef JP
810                 c_put_str(TERM_YELLOW, "¥Ä¡¼¥Ú¥¢",  4,  3);
811 #else
812                 c_put_str(TERM_YELLOW, "Two pair",  4,  3);
813 #endif
814                 return ODDS_2P;
815         case 3:
816 #ifdef JP
817                 c_put_str(TERM_YELLOW, "¥¹¥ê¡¼¥«¡¼¥É",  4,  3);
818 #else
819                 c_put_str(TERM_YELLOW, "Three of a kind",  4,  3);
820 #endif
821                 return ODDS_3C;
822         case 4:
823 #ifdef JP
824                 c_put_str(TERM_YELLOW, "¥Õ¥ë¥Ï¥¦¥¹",  4,  3);
825 #else
826                 c_put_str(TERM_YELLOW, "Full house",  4,  3);
827 #endif
828                 return ODDS_FH;
829         case 6:
830 #ifdef JP
831                 c_put_str(TERM_YELLOW, "¥Õ¥©¡¼¥«¡¼¥É",  4,  3);
832 #else
833                 c_put_str(TERM_YELLOW, "Four of a kind",  4,  3);
834 #endif
835                 return ODDS_4C;
836         case 7:
837                 if (!NUM_OF(cards[0]) || !NUM_OF(cards[1]))
838                 {
839 #ifdef JP
840                         c_put_str(TERM_YELLOW, "¥Õ¥¡¥¤¥Ö¥¨¡¼¥¹",  4,  3);
841 #else
842                         c_put_str(TERM_YELLOW, "Five ace",  4,  3);
843 #endif
844                         return ODDS_5A;
845                 }
846                 else
847                 {
848 #ifdef JP
849                         c_put_str(TERM_YELLOW, "¥Õ¥¡¥¤¥Ö¥«¡¼¥É",  4,  3);
850 #else
851                         c_put_str(TERM_YELLOW, "Five of a kind",  4,  3);
852 #endif
853                         return ODDS_5C;
854                 }
855         default:
856                 break;
857         }
858         return 0;
859 }
860
861 static void display_kaeruka(int hoge, int kaeruka[])
862 {
863         int i;
864         char col = TERM_WHITE;
865         for (i = 0; i < 5; i++)
866         {
867                 if (i == hoge) col = TERM_YELLOW;
868                 else if(kaeruka[i]) col = TERM_WHITE;
869                 else col = TERM_L_BLUE;
870 #ifdef JP
871                 if(kaeruka[i])
872                         c_put_str(col, "¤«¤¨¤ë", 14,  5+i*16);
873                 else
874                         c_put_str(col, "¤Î¤³¤¹", 14,  5+i*16);
875 #else
876                 if(kaeruka[i])
877                         c_put_str(col, "Change", 14,  5+i*16);
878                 else
879                         c_put_str(col, " Stay ", 14,  5+i*16);
880 #endif
881         }
882         if (hoge > 4) col = TERM_YELLOW;
883         else col = TERM_WHITE;
884 #ifdef JP
885         c_put_str(col, "·èÄê", 16,  38);
886 #else
887         c_put_str(col, "Sure", 16,  38);
888 #endif
889
890         /* Hilite current option */
891         if (hoge < 5) move_cursor(14, 5+hoge*16);
892         else move_cursor(16, 38);
893 }
894
895
896 static void display_cards(void)
897 {
898         int i, j;
899         char suitcolor[4] = {TERM_YELLOW, TERM_L_RED, TERM_L_BLUE, TERM_L_GREEN};
900 #ifdef JP
901         cptr suit[4] = {"¡ú", "¡ü", "¢ù", "¢÷"};
902         cptr card_grph[13][7] = {{"£Á   %s     ",
903                                   "     ÊÑ     ",
904                                   "     ¶ò     ",
905                                   "     ÈÚ     ",
906                                   "     ÅÜ     ",
907                                   "     %s     ",
908                                   "          £Á"},
909                                  {"£²          ",
910                                   "     %s     ",
911                                   "            ",
912                                   "            ",
913                                   "            ",
914                                   "     %s     ",
915                                   "          £²"},
916                                  {"£³          ",
917                                   "     %s     ",
918                                   "            ",
919                                   "     %s     ",
920                                   "            ",
921                                   "     %s     ",
922                                   "          £³"},
923                                  {"£´          ",
924                                   "   %s  %s   ",
925                                   "            ",
926                                   "            ",
927                                   "            ",
928                                   "   %s  %s   ",
929                                   "          £´"},
930                                  {"£µ          ",
931                                   "   %s  %s   ",
932                                   "            ",
933                                   "     %s     ",
934                                   "            ",
935                                   "   %s  %s   ",
936                                   "          £µ"},
937                                  {"£¶          ",
938                                   "   %s  %s   ",
939                                   "            ",
940                                   "   %s  %s   ",
941                                   "            ",
942                                   "   %s  %s   ",
943                                   "          £¶"},
944                                  {"£·          ",
945                                   "   %s  %s   ",
946                                   "     %s     ",
947                                   "   %s  %s   ",
948                                   "            ",
949                                   "   %s  %s   ",
950                                   "          £·"},
951                                  {"£¸          ",
952                                   "   %s  %s   ",
953                                   "     %s     ",
954                                   "   %s  %s   ",
955                                   "     %s     ",
956                                   "   %s  %s   ",
957                                   "          £¸"},
958                                  {"£¹ %s  %s   ",
959                                   "            ",
960                                   "   %s  %s   ",
961                                   "     %s     ",
962                                   "   %s  %s   ",
963                                   "            ",
964                                   "   %s  %s £¹"},
965                                  {"10 %s  %s   ",
966                                   "     %s     ",
967                                   "   %s  %s   ",
968                                   "            ",
969                                   "   %s  %s   ",
970                                   "     %s     ",
971                                   "   %s  %s 10"},
972                                  {"£Ê   ¦«     ",
973                                   "%s   ||     ",
974                                   "     ||     ",
975                                   "     ||     ",
976                                   "     ||     ",
977                                   "   |=°¡=| %s",
978                                   "     ÌÜ   £Ê"},
979                                  {"£Ñ ######   ",
980                                   "%s#      #  ",
981                                   "  # ++++ #  ",
982                                   "  # +==+ #  ",
983                                   "   # ++ #   ",
984                                   "    #  #  %s",
985                                   "     ##   £Ñ"},
986                                  {"£Ë          ",
987                                   "%s ¡®¢Þ¡­   ",
988                                   "  ¦Ã¦Ã¦Ã¦Ë  ",
989                                   "  ¦Ï ¦Ï ¦É  ",
990                                   "   ¦Ô    ¢ß ",
991                                   "    ¦Ò ¥Î %s",
992                                   "          £Ë"}};
993         cptr joker_grph[7] = {    "            ",
994                                   "     £Ê     ",
995                                   "     £Ï     ",
996                                   "     £Ë     ",
997                                   "     £Å     ",
998                                   "     £Ò     ",
999                                   "            "};
1000
1001 #else
1002
1003         cptr suit[4] = {"[]", "qp", "<>", "db"};
1004         cptr card_grph[13][7] = {{"A    %s     ",
1005                                   "     He     ",
1006                                   "     ng     ",
1007                                   "     ba     ",
1008                                   "     nd     ",
1009                                   "     %s     ",
1010                                   "           A"},
1011                                  {"2           ",
1012                                   "     %s     ",
1013                                   "            ",
1014                                   "            ",
1015                                   "            ",
1016                                   "     %s     ",
1017                                   "           2"},
1018                                  {"3           ",
1019                                   "     %s     ",
1020                                   "            ",
1021                                   "     %s     ",
1022                                   "            ",
1023                                   "     %s     ",
1024                                   "           3"},
1025                                  {"4           ",
1026                                   "   %s  %s   ",
1027                                   "            ",
1028                                   "            ",
1029                                   "            ",
1030                                   "   %s  %s   ",
1031                                   "           4"},
1032                                  {"5           ",
1033                                   "   %s  %s   ",
1034                                   "            ",
1035                                   "     %s     ",
1036                                   "            ",
1037                                   "   %s  %s   ",
1038                                   "           5"},
1039                                  {"6           ",
1040                                   "   %s  %s   ",
1041                                   "            ",
1042                                   "   %s  %s   ",
1043                                   "            ",
1044                                   "   %s  %s   ",
1045                                   "           6"},
1046                                  {"7           ",
1047                                   "   %s  %s   ",
1048                                   "     %s     ",
1049                                   "   %s  %s   ",
1050                                   "            ",
1051                                   "   %s  %s   ",
1052                                   "           7"},
1053                                  {"8           ",
1054                                   "   %s  %s   ",
1055                                   "     %s     ",
1056                                   "   %s  %s   ",
1057                                   "     %s     ",
1058                                   "   %s  %s   ",
1059                                   "           8"},
1060                                  {"9  %s  %s   ",
1061                                   "            ",
1062                                   "   %s  %s   ",
1063                                   "     %s     ",
1064                                   "   %s  %s   ",
1065                                   "            ",
1066                                   "   %s  %s  9"},
1067                                  {"10 %s  %s   ",
1068                                   "     %s     ",
1069                                   "   %s  %s   ",
1070                                   "            ",
1071                                   "   %s  %s   ",
1072                                   "     %s     ",
1073                                   "   %s  %s 10"},
1074                                  {"J    /\\     ",
1075                                   "%s   ||     ",
1076                                   "     ||     ",
1077                                   "     ||     ",
1078                                   "     ||     ",
1079                                   "   |=HH=| %s",
1080                                   "     ][    J"},
1081                                  {"Q  ######   ",
1082                                   "%s#      #  ",
1083                                   "  # ++++ #  ",
1084                                   "  # +==+ #  ",
1085                                   "   # ++ #   ",
1086                                   "    #  #  %s",
1087                                   "     ##    Q"},
1088                                  {"K           ",
1089                                   "%s _'~~`_   ",
1090                                   "   jjjjj$&  ",
1091                                   "   q q uu   ",
1092                                   "   c    &   ",
1093                                   "    v__/  %s",
1094                                   "           K"}};
1095         cptr joker_grph[7] = {    "            ",
1096                                   "     J      ",
1097                                   "     O      ",
1098                                   "     K      ",
1099                                   "     E      ",
1100                                   "     R      ",
1101                                   "            "};
1102 #endif
1103
1104         for (i = 0; i < 5; i++)
1105         {
1106 #ifdef JP
1107                 prt("¨®¨¬¨¬¨¬¨¬¨¬¨¬¨¯",  5,  i*16);
1108 #else
1109                 prt(" +------------+ ",  5,  i*16);
1110 #endif
1111         }
1112
1113         for (i = 0; i < 5; i++)
1114         {
1115                 for (j = 0; j < 7; j++)
1116                 {
1117 #ifdef JP
1118                         prt("¨­",  j+6,  i*16);
1119 #else
1120                         prt(" |",  j+6,  i*16);
1121 #endif
1122                         if(IS_JOKER(cards[i]))
1123                                 c_put_str(TERM_VIOLET, joker_grph[j],  j+6,  2+i*16);
1124                         else
1125                                 c_put_str(suitcolor[SUIT_OF(cards[i])], format(card_grph[NUM_OF(cards[i])][j], suit[SUIT_OF(cards[i])], suit[SUIT_OF(cards[i])]),  j+6,  2+i*16);
1126 #ifdef JP
1127                         prt("¨­",  j+6,  i*16+14);
1128 #else
1129                         prt("| ",  j+6,  i*16+14);
1130 #endif
1131                 }
1132         }
1133         for (i = 0; i < 5; i++)
1134         {
1135 #ifdef JP
1136                 prt("¨±¨¬¨¬¨¬¨¬¨¬¨¬¨°", 13,  i*16);
1137 #else
1138                 prt(" +------------+ ", 13,  i*16);
1139 #endif
1140         }
1141 }
1142
1143 static int do_poker(void)
1144 {
1145         int i, k = 2;
1146         char cmd;
1147         int deck[53]; /* yamafuda : 0...52 */
1148         int deck_ptr = 0;
1149         int kaeruka[5]; /* 0:kaenai 1:kaeru */
1150
1151         bool done = FALSE;
1152         bool kettei = TRUE;
1153         bool kakikae = TRUE;
1154
1155         reset_deck(deck);
1156
1157         for (i = 0; i < 5; i++)
1158         {
1159                 cards[i] = deck[deck_ptr++];
1160                 kaeruka[i] = 0; /* default:nokosu */
1161         }
1162         
1163 #if 0
1164         /* debug:RF */
1165         cards[0] = 12;
1166         cards[1] = 0;
1167         cards[2] = 9;
1168         cards[3] = 11;
1169         cards[4] = 10;
1170 #endif
1171 #if 0
1172         /* debug:SF */
1173         cards[0] = 3;
1174         cards[1] = 2;
1175         cards[2] = 4;
1176         cards[3] = 6;
1177         cards[4] = 5;
1178 #endif
1179 #if 0
1180         /* debug:Four Cards */
1181         cards[0] = 0;
1182         cards[1] = 0 + 13 * 1;
1183         cards[2] = 0 + 13 * 2;
1184         cards[3] = 0 + 13 * 3;
1185         cards[4] = 51;
1186 #endif
1187 #if 0
1188         /* debug:Straight */
1189         cards[0] = 1;
1190         cards[1] = 0 + 13;
1191         cards[2] = 3;
1192         cards[3] = 2 + 26;
1193         cards[4] = 4;
1194 #endif
1195 #if 0
1196         /* debug */
1197         cards[0] = 52;
1198         cards[1] = 0;
1199         cards[2] = 1;
1200         cards[3] = 2;
1201         cards[4] = 3;
1202 #endif
1203
1204         /* suteruno wo kimeru */
1205 #ifdef JP
1206         prt("»Ä¤¹¥«¡¼¥É¤ò·è¤á¤Æ²¼¤µ¤¤(Êý¸þ¤Ç°ÜÆ°, ¥¹¥Ú¡¼¥¹¤ÇÁªÂò)¡£", 0, 0);
1207 #else
1208         prt("Stay witch? ", 0, 0);
1209 #endif
1210
1211         display_cards();
1212         yaku_check();
1213
1214         while (!done)
1215         {
1216                 if (kakikae) display_kaeruka(k+kettei*5, kaeruka);
1217                 kakikae = FALSE;
1218                 cmd = inkey();
1219                 switch (cmd)
1220                 {
1221                 case '6': case 'l': case 'L': case KTRL('F'):
1222                         if (!kettei) k = (k+1)%5;
1223                         else {k = 0;kettei = FALSE;}
1224                         kakikae = TRUE;
1225                         break;
1226                 case '4': case 'h': case 'H': case KTRL('B'):
1227                         if (!kettei) k = (k+4)%5;
1228                         else {k = 4;kettei = FALSE;}
1229                         kakikae = TRUE;
1230                         break;
1231                 case '2': case 'j': case 'J': case KTRL('N'):
1232                         if (!kettei) {kettei = TRUE;kakikae = TRUE;}
1233                         break;
1234                 case '8': case 'k': case 'K': case KTRL('P'):
1235                         if (kettei) {kettei = FALSE;kakikae = TRUE;}
1236                         break;
1237                 case ' ': case '\r':
1238                         if (kettei) done = TRUE;
1239                         else {kaeruka[k] = !kaeruka[k];kakikae = TRUE;}
1240                         break;
1241                 default:
1242                         break;
1243                 }
1244         }
1245         
1246         prt("",0,0);
1247
1248         for (i = 0; i < 5; i++)
1249                 if (kaeruka[i] == 1) cards[i] = deck[deck_ptr++]; /* soshite toru */
1250
1251         display_cards();
1252         
1253         return yaku_check();
1254 }
1255 #undef SUIT_OF
1256 #undef NUM_OF
1257 #undef IS_JOKER
1258 /* end of poker codes --Koka */
1259
1260 /*
1261  * gamble_comm
1262  */
1263 static bool gamble_comm(int cmd)
1264 {
1265         int i;
1266         int roll1, roll2, roll3, choice, odds, win;
1267         s32b wager;
1268         s32b maxbet;
1269         s32b oldgold;
1270
1271         char out_val[160], tmp_str[80], again;
1272         cptr p;
1273
1274         screen_save();
1275
1276         if (cmd == BACT_GAMBLE_RULES)
1277         {
1278                 /* Peruse the gambling help file */
1279 #ifdef JP
1280 (void)show_file(TRUE, "jgambling.txt", NULL, 0, 0);
1281 #else
1282                 (void)show_file(TRUE, "gambling.txt", NULL, 0, 0);
1283 #endif
1284
1285         }
1286         else
1287         {
1288                 /* No money */
1289                 if (p_ptr->au < 1)
1290                 {
1291 #ifdef JP
1292                         msg_print("¤ª¤¤¡ª¤ª¤Þ¤¨°ìʸ¤Ê¤·¤¸¤ã¤Ê¤¤¤«¡ª¤³¤Ã¤«¤é½Ð¤Æ¤¤¤±¡ª");
1293 #else
1294                         msg_print("Hey! You don't have gold - get out of here!");
1295 #endif
1296
1297                         msg_print(NULL);
1298                         screen_load();
1299                         return FALSE;
1300                 }
1301
1302                 clear_bldg(5, 23);
1303
1304                 maxbet = p_ptr->lev * 200;
1305
1306                 /* We can't bet more than we have */
1307                 maxbet = MIN(maxbet, p_ptr->au);
1308
1309                 /* Get the wager */
1310                 strcpy(out_val, "");
1311 #ifdef JP
1312 sprintf(tmp_str,"ÅÒ¤±¶â (1-%ld)¡©", (long int)maxbet);
1313 #else
1314                 sprintf(tmp_str,"Your wager (1-%ld) ? ", (long int)maxbet);
1315 #endif
1316
1317
1318                 /*
1319                  * Use get_string() because we may need more than
1320                  * the s16b value returned by get_quantity().
1321                  */
1322                 if (get_string(tmp_str, out_val, 32))
1323                 {
1324                         /* Strip spaces */
1325                         for (p = out_val; *p == ' '; p++);
1326
1327                         /* Get the wager */
1328                         wager = atol(p);
1329
1330                         if (wager > p_ptr->au)
1331                         {
1332 #ifdef JP
1333 msg_print("¤ª¤¤¡ª¶â¤¬Â­¤ê¤Ê¤¤¤¸¤ã¤Ê¤¤¤«¡ª½Ð¤Æ¤¤¤±¡ª");
1334 #else
1335                                 msg_print("Hey! You don't have the gold - get out of here!");
1336 #endif
1337
1338                                 msg_print(NULL);
1339                                 screen_load();
1340                                 return (FALSE);
1341                         }
1342                         else if (wager > maxbet)
1343                         {
1344 #ifdef JP
1345 msg_format("%ld¥´¡¼¥ë¥É¤À¤±¼õ¤±¤è¤¦¡£»Ä¤ê¤Ï¼è¤Ã¤È¤­¤Ê¡£", (long int)maxbet);
1346 #else
1347                                 msg_format("I'll take %ld gold of that. Keep the rest.", (long int)maxbet);
1348 #endif
1349
1350                                 wager = maxbet;
1351                         }
1352                         else if (wager < 1)
1353                         {
1354 #ifdef JP
1355 msg_print("£Ï£Ë¡¢£±¥´¡¼¥ë¥É¤«¤é¤Ï¤¸¤á¤è¤¦¡£");
1356 #else
1357                                 msg_print("Ok, we'll start with 1 gold.");
1358 #endif
1359
1360
1361                                 wager = 1;
1362                         }
1363                         msg_print(NULL);
1364                         win = FALSE;
1365                         odds = 0;
1366                         oldgold = p_ptr->au;
1367
1368 #ifdef JP
1369 sprintf(tmp_str, "¥²¡¼¥àÁ°¤Î½ê»ý¶â: %9ld", (long int)oldgold);
1370 #else
1371                         sprintf(tmp_str, "Gold before game: %9ld", (long int)oldgold);
1372 #endif
1373
1374                         prt(tmp_str, 20, 2);
1375
1376 #ifdef JP
1377 sprintf(tmp_str, "¸½ºß¤Î³Ý¤±¶â:     %9ld", (long int)wager);
1378 #else
1379                         sprintf(tmp_str, "Current Wager:    %9ld", (long int)wager);
1380 #endif
1381
1382                         prt(tmp_str, 21, 2);
1383
1384                         do
1385                         {
1386                                 p_ptr->au -= wager;
1387                                 switch (cmd)
1388                                 {
1389                                  case BACT_IN_BETWEEN: /* Game of In-Between */
1390 #ifdef JP
1391 c_put_str(TERM_GREEN, "¥¤¥ó¡¦¥Ó¥È¥¤¡¼¥ó",5,2);
1392 #else
1393                                         c_put_str(TERM_GREEN, "In Between", 5, 2);
1394 #endif
1395
1396                                         odds = 4;
1397                                         win = FALSE;
1398                                         roll1 = randint1(10);
1399                                         roll2 = randint1(10);
1400                                         choice = randint1(10);
1401 #ifdef JP
1402 sprintf(tmp_str, "¹õ¥À¥¤¥¹: %d        ¹õ¥À¥¤¥¹: %d", roll1, roll2);
1403 #else
1404                                         sprintf(tmp_str, "Black die: %d       Black Die: %d", roll1, roll2);
1405 #endif
1406
1407                                         prt(tmp_str, 8, 3);
1408 #ifdef JP
1409 sprintf(tmp_str, "ÀÖ¥À¥¤¥¹: %d", choice);
1410 #else
1411                                         sprintf(tmp_str, "Red die: %d", choice);
1412 #endif
1413
1414                                         prt(tmp_str, 11, 14);
1415                                         if (((choice > roll1) && (choice < roll2)) ||
1416                                                 ((choice < roll1) && (choice > roll2)))
1417                                                 win = TRUE;
1418                                         break;
1419                                 case BACT_CRAPS:  /* Game of Craps */
1420 #ifdef JP
1421 c_put_str(TERM_GREEN, "¥¯¥é¥Ã¥×¥¹", 5, 2);
1422 #else
1423                                         c_put_str(TERM_GREEN, "Craps", 5, 2);
1424 #endif
1425
1426                                         win = 3;
1427                                         odds = 2;
1428                                         roll1 = randint1(6);
1429                                         roll2 = randint1(6);
1430                                         roll3 = roll1 +  roll2;
1431                                         choice = roll3;
1432 #ifdef JP
1433 sprintf(tmp_str, "£±¿¶¤ê¤á: %d %d      Total: %d", roll1, 
1434 #else
1435                                         sprintf(tmp_str, "First roll: %d %d    Total: %d", roll1,
1436 #endif
1437
1438                                                  roll2, roll3);
1439                                         prt(tmp_str, 7, 5);
1440                                         if ((roll3 == 7) || (roll3 == 11))
1441                                                 win = TRUE;
1442                                         else if ((roll3 == 2) || (roll3 == 3) || (roll3 == 12))
1443                                                 win = FALSE;
1444                                         else
1445                                                 do
1446                                                 {
1447 #ifdef JP
1448 msg_print("¤Ê¤Ë¤«¥­¡¼¤ò²¡¤¹¤È¤â¤¦°ì²ó¿¶¤ê¤Þ¤¹¡£");
1449 #else
1450                                                         msg_print("Hit any key to roll again");
1451 #endif
1452
1453                                                         msg_print(NULL);
1454                                                         roll1 = randint1(6);
1455                                                         roll2 = randint1(6);
1456                                                         roll3 = roll1 +  roll2;
1457
1458 #ifdef JP
1459 sprintf(tmp_str, "½ÐÌÜ: %d %d          ¹ç·×:      %d",
1460 #else
1461                                                         sprintf(tmp_str, "Roll result: %d %d   Total:     %d",
1462 #endif
1463
1464                                                                  roll1, roll2, roll3);
1465                                                         prt(tmp_str, 8, 5);
1466                                                         if (roll3 == choice)
1467                                                                 win = TRUE;
1468                                                         else if (roll3 == 7)
1469                                                                 win = FALSE;
1470                                                 } while ((win != TRUE) && (win != FALSE));
1471                                         break;
1472
1473                                 case BACT_SPIN_WHEEL:  /* Spin the Wheel Game */
1474                                         win = FALSE;
1475                                         odds = 9;
1476 #ifdef JP
1477 c_put_str(TERM_GREEN, "¥ë¡¼¥ì¥Ã¥È", 5, 2);
1478 #else
1479                                         c_put_str(TERM_GREEN, "Wheel", 5, 2);
1480 #endif
1481
1482                                         prt("0  1  2  3  4  5  6  7  8  9", 7, 5);
1483                                         prt("--------------------------------", 8, 3);
1484                                         strcpy(out_val, "");
1485 #ifdef JP
1486 get_string("²¿ÈÖ¡© (0-9): ", out_val, 32);
1487 #else
1488                                         get_string("Pick a number (0-9): ", out_val, 32);
1489 #endif
1490
1491                                         for (p = out_val; iswspace(*p); p++);
1492                                         choice = atol(p);
1493                                         if (choice < 0)
1494                                         {
1495 #ifdef JP
1496 msg_print("0È֤ˤ·¤È¤¯¤¼¡£");
1497 #else
1498                                                 msg_print("I'll put you down for 0.");
1499 #endif
1500
1501                                                 choice = 0;
1502                                         }
1503                                         else if (choice > 9)
1504                                         {
1505 #ifdef JP
1506 msg_print("£Ï£Ë¡¢9È֤ˤ·¤È¤¯¤¼¡£");
1507 #else
1508                                                 msg_print("Ok, I'll put you down for 9.");
1509 #endif
1510
1511                                                 choice = 9;
1512                                         }
1513                                         msg_print(NULL);
1514                                         roll1 = randint0(10);
1515 #ifdef JP
1516 sprintf(tmp_str, "¥ë¡¼¥ì¥Ã¥È¤Ï²ó¤ê¡¢»ß¤Þ¤Ã¤¿¡£¾¡¼Ô¤Ï %dÈÖ¤À¡£",
1517 #else
1518                                         sprintf(tmp_str, "The wheel spins to a stop and the winner is %d",
1519 #endif
1520
1521                                                 roll1);
1522                                         prt(tmp_str, 13, 3);
1523                                         prt("", 9, 0);
1524                                         prt("*", 9, (3 * roll1 + 5));
1525                                         if (roll1 == choice)
1526                                                 win = TRUE;
1527                                         break;
1528
1529                                 case BACT_DICE_SLOTS: /* The Dice Slots */
1530 #ifdef JP
1531 c_put_str(TERM_GREEN, "¥À¥¤¥¹¡¦¥¹¥í¥Ã¥È", 5, 2);
1532                                         c_put_str(TERM_YELLOW, "¥ì¥â¥ó   ¥ì¥â¥ó            2", 6, 37);
1533                                         c_put_str(TERM_YELLOW, "¥ì¥â¥ó   ¥ì¥â¥ó   ¥ì¥â¥ó   5", 7, 37);
1534                                         c_put_str(TERM_ORANGE, "¥ª¥ì¥ó¥¸ ¥ª¥ì¥ó¥¸ ¥ª¥ì¥ó¥¸ 10", 8, 37);
1535                                         c_put_str(TERM_UMBER, "·õ       ·õ       ·õ       20", 9, 37);
1536                                         c_put_str(TERM_SLATE, "½â       ½â       ½â       50", 10, 37);
1537                                         c_put_str(TERM_VIOLET, "¥×¥é¥à   ¥×¥é¥à   ¥×¥é¥à   200", 11, 37);
1538                                         c_put_str(TERM_RED, "¥Á¥§¥ê¡¼ ¥Á¥§¥ê¡¼ ¥Á¥§¥ê¡¼ 1000", 12, 37);
1539 #else
1540                                         c_put_str(TERM_GREEN, "Dice Slots", 5, 2);
1541 #endif
1542
1543                                         win = FALSE;
1544                                         roll1 = randint1(21);
1545                                         for (i=6;i>0;i--)
1546                                         {
1547                                                 if ((roll1-i) < 1)
1548                                                 {
1549                                                         roll1 = 7-i;
1550                                                         break;
1551                                                 }
1552                                                 roll1 -= i;
1553                                         }
1554                                         roll2 = randint1(21);
1555                                         for (i=6;i>0;i--)
1556                                         {
1557                                                 if ((roll2-i) < 1)
1558                                                 {
1559                                                         roll2 = 7-i;
1560                                                         break;
1561                                                 }
1562                                                 roll2 -= i;
1563                                         }
1564                                         choice = randint1(21);
1565                                         for (i=6;i>0;i--)
1566                                         {
1567                                                 if ((choice-i) < 1)
1568                                                 {
1569                                                         choice = 7-i;
1570                                                         break;
1571                                                 }
1572                                                 choice -= i;
1573                                         }
1574                                         put_str("/--------------------------\\", 7, 2);
1575                                         prt("\\--------------------------/", 17, 2);
1576                                         display_fruit(8,  3, roll1 - 1);
1577                                         display_fruit(8, 12, roll2 - 1);
1578                                         display_fruit(8, 21, choice - 1);
1579                                         if ((roll1 == roll2) && (roll2 == choice))
1580                                         {
1581                                                 win = TRUE;
1582                                                 switch(roll1)
1583                                                 {
1584                                                 case 1:
1585                                                         odds = 5;break;
1586                                                 case 2:
1587                                                         odds = 10;break;
1588                                                 case 3:
1589                                                         odds = 20;break;
1590                                                 case 4:
1591                                                         odds = 50;break;
1592                                                 case 5:
1593                                                         odds = 200;break;
1594                                                 case 6:
1595                                                         odds = 1000;break;
1596                                                 }
1597                                         }
1598                                         else if ((roll1 == 1) && (roll2 == 1))
1599                                         {
1600                                                 win = TRUE;
1601                                                 odds = 2;
1602                                         }
1603                                         break;
1604                                 case BACT_POKER:
1605                                         win = FALSE;
1606                                         odds = do_poker();
1607                                         if (odds) win = TRUE;
1608                                         break;
1609                                 }
1610
1611                                 if (win)
1612                                 {
1613 #ifdef JP
1614 prt("¤¢¤Ê¤¿¤Î¾¡¤Á", 16, 37);
1615 #else
1616                                         prt("YOU WON", 16, 37);
1617 #endif
1618
1619                                         p_ptr->au += odds * wager;
1620 #ifdef JP
1621 sprintf(tmp_str, "ÇÜΨ: %d", odds);
1622 #else
1623                                         sprintf(tmp_str, "Payoff: %d", odds);
1624 #endif
1625
1626                                         prt(tmp_str, 17, 37);
1627                                 }
1628                                 else
1629                                 {
1630 #ifdef JP
1631 prt("¤¢¤Ê¤¿¤ÎÉ餱", 16, 37);
1632 #else
1633                                         prt("You Lost", 16, 37);
1634 #endif
1635
1636                                         prt("", 17, 37);
1637                                 }
1638 #ifdef JP
1639 sprintf(tmp_str, "¸½ºß¤Î½ê»ý¶â:     %9ld", (long int)p_ptr->au);
1640 #else
1641                                 sprintf(tmp_str, "Current Gold:     %9ld", (long int)p_ptr->au);
1642 #endif
1643
1644                                 prt(tmp_str, 22, 2);
1645 #ifdef JP
1646 prt("¤â¤¦°ìÅÙ(Y/N)¡©", 18, 37);
1647 #else
1648                                 prt("Again(Y/N)?", 18, 37);
1649 #endif
1650
1651                                 move_cursor(18, 52);
1652                                 again = inkey();
1653                                 prt("", 16, 37);
1654                                 prt("", 17, 37);
1655                                 prt("", 18, 37);
1656                                 if (wager > p_ptr->au)
1657                                 {
1658 #ifdef JP
1659 msg_print("¤ª¤¤¡ª¶â¤¬Â­¤ê¤Ê¤¤¤¸¤ã¤Ê¤¤¤«¡ª¤³¤³¤«¤é½Ð¤Æ¹Ô¤±¡ª");
1660 #else
1661                                         msg_print("Hey! You don't have the gold - get out of here!");
1662 #endif
1663
1664                                         msg_print(NULL);
1665
1666                                         /* Get out here */
1667                                         break;
1668                                 }
1669                         } while ((again == 'y') || (again == 'Y'));
1670
1671                         prt("", 18, 37);
1672                         if (p_ptr->au >= oldgold)
1673                         {
1674 #ifdef JP
1675 msg_print("¡Öº£²ó¤ÏÌÙ¤±¤¿¤Ê¡ª¤Ç¤â¼¡¤Ï¤³¤Ã¤Á¤¬¾¡¤Ã¤Æ¤ä¤ë¤«¤é¤Ê¡¢ÀäÂФˡª¡×");
1676 #else
1677                                 msg_print("You came out a winner! We'll win next time, I'm sure.");
1678 #endif
1679                                 chg_virtue(V_CHANCE, 3);
1680                         }
1681                         else
1682                         {
1683 #ifdef JP
1684 msg_print("¡Ö¶â¤ò¥¹¥Ã¤Æ¤·¤Þ¤Ã¤¿¤Ê¡¢¤ï¤Ï¤Ï¡ª¤¦¤Á¤Ëµ¢¤Ã¤¿Êý¤¬¤¤¤¤¤¼¡£¡×");
1685 #else
1686                                 msg_print("You lost gold! Haha, better head home.");
1687 #endif
1688                                 chg_virtue(V_CHANCE, -3);
1689                         }
1690                 }
1691                 msg_print(NULL);
1692         }
1693         screen_load();
1694         return (TRUE);
1695 }
1696
1697 static bool vault_aux_battle(int r_idx)
1698 {
1699         int i;
1700         int dam = 0;
1701
1702         monster_race *r_ptr = &r_info[r_idx];
1703
1704         /* Decline town monsters */
1705 /*      if (!mon_hook_dungeon(r_idx)) return FALSE; */
1706
1707         /* Decline unique monsters */
1708 /*      if (r_ptr->flags1 & (RF1_UNIQUE)) return (FALSE); */
1709 /*      if (r_ptr->flags7 & (RF7_NAZGUL)) return (FALSE); */
1710
1711         if (r_ptr->flags1 & (RF1_NEVER_MOVE)) return (FALSE);
1712         if (r_ptr->flags2 & (RF2_MULTIPLY)) return (FALSE);
1713         if (r_ptr->flags2 & (RF2_QUANTUM)) return (FALSE);
1714         if (r_ptr->flags7 & (RF7_AQUATIC)) return (FALSE);
1715         if (r_ptr->flags7 & (RF7_CHAMELEON)) return (FALSE);
1716
1717         for (i = 0; i < 4; i++)
1718         {
1719                 if (r_ptr->blow[i].method == RBM_EXPLODE) return (FALSE);
1720                 if (r_ptr->blow[i].effect != RBE_DR_MANA) dam += r_ptr->blow[i].d_dice;
1721         }
1722         if (!dam && !(r_ptr->flags4 & (RF4_BOLT_MASK | RF4_BEAM_MASK | RF4_BALL_MASK | RF4_BREATH_MASK)) && !(r_ptr->flags5 & (RF5_BOLT_MASK | RF5_BEAM_MASK | RF5_BALL_MASK | RF5_BREATH_MASK)) && !(r_ptr->flags6 & (RF6_BOLT_MASK | RF6_BEAM_MASK | RF6_BALL_MASK | RF6_BREATH_MASK))) return (FALSE);
1723
1724         /* Okay */
1725         return (TRUE);
1726 }
1727
1728 void battle_monsters(void)
1729 {
1730         int total, i;
1731         int max_dl = 0;
1732         int mon_level;
1733         int power[4];
1734         bool tekitou;
1735         bool old_inside_battle = p_ptr->inside_battle;
1736
1737         for (i = 0; i < max_d_idx; i++)
1738                 if (max_dl < max_dlv[i]) max_dl = max_dlv[i];
1739
1740         mon_level = randint1(MIN(max_dl, 122))+5;
1741         if (randint0(100) < 60)
1742         {
1743                 i = randint1(MIN(max_dl, 122))+5;
1744                 mon_level = MAX(i, mon_level);
1745         }
1746         if (randint0(100) < 30)
1747         {
1748                 i = randint1(MIN(max_dl, 122))+5;
1749                 mon_level = MAX(i, mon_level);
1750         }
1751
1752         while (1)
1753         {
1754                 total = 0;
1755                 tekitou = FALSE;
1756                 for(i=0;i<4;i++)
1757                 {
1758                         int r_idx, j;
1759                         while (1)
1760                         {
1761                                 get_mon_num_prep(vault_aux_battle, NULL);
1762                                 p_ptr->inside_battle = TRUE;
1763                                 r_idx = get_mon_num(mon_level);
1764                                 p_ptr->inside_battle = old_inside_battle;
1765                                 if (!r_idx) continue;
1766
1767                                 if ((r_info[r_idx].flags1 & RF1_UNIQUE) || (r_info[r_idx].flags7 & RF7_UNIQUE2))
1768                                 {
1769                                         if ((r_info[r_idx].level + 10) > mon_level) continue;
1770                                 }
1771
1772                                 for (j = 0; j < i; j++)
1773                                         if(r_idx == battle_mon[j]) break;
1774                                 if (j<i) continue;
1775
1776                                 break;
1777                         }
1778                         battle_mon[i] = r_idx;
1779                         if (r_info[r_idx].level < 45) tekitou = TRUE;
1780                 }
1781
1782                 for (i=0;i<4;i++)
1783                 {
1784                         monster_race *r_ptr = &r_info[battle_mon[i]];
1785                         int num_taisei = count_bits(r_ptr->flagsr & (RFR_IM_ACID | RFR_IM_ELEC | RFR_IM_FIRE | RFR_IM_COLD | RFR_IM_POIS));
1786
1787                         if (r_ptr->flags1 & RF1_FORCE_MAXHP)
1788                                 power[i] = r_ptr->hdice * r_ptr->hside * 2;
1789                         else
1790                                 power[i] = r_ptr->hdice * (r_ptr->hside + 1);
1791                         power[i] = power[i] * (100 + r_ptr->level) / 100;
1792                         if (r_ptr->speed > 110)
1793                                 power[i] = power[i] * (r_ptr->speed * 2 - 110) / 100;
1794                         if (r_ptr->speed < 110)
1795                                 power[i] = power[i] * (r_ptr->speed - 20) / 100;
1796                         if (num_taisei > 2)
1797                                 power[i] = power[i] * (num_taisei*2+5) / 10;
1798                         else if (r_ptr->flags6 & RF6_INVULNER)
1799                                 power[i] = power[i] * 4 / 3;
1800                         else if (r_ptr->flags6 & RF6_HEAL)
1801                                 power[i] = power[i] * 4 / 3;
1802                         else if (r_ptr->flags5 & RF5_DRAIN_MANA)
1803                                 power[i] = power[i] * 11 / 10;
1804                         if (r_ptr->flags1 & RF1_RAND_25)
1805                                 power[i] = power[i] * 9 / 10;
1806                         if (r_ptr->flags1 & RF1_RAND_50)
1807                                 power[i] = power[i] * 9 / 10;
1808
1809                         switch (battle_mon[i])
1810                         {
1811                                 case MON_GREEN_G:
1812                                 case MON_THAT_BAT:
1813                                 case MON_GHOST_Q:
1814                                         power[i] /= 4;
1815                                         break;
1816                                 case MON_LOST_SOUL:
1817                                 case MON_GHOST:
1818                                         power[i] /= 2;
1819                                         break;
1820                                 case MON_UND_BEHOLDER:
1821                                 case MON_SANTACLAUS:
1822                                 case MON_ULT_BEHOLDER:
1823                                 case MON_UNGOLIANT:
1824                                 case MON_ATLACH_NACHA:
1825                                 case MON_Y_GOLONAC:
1826                                         power[i] = power[i] * 3 / 5;
1827                                         break;
1828                                 case MON_ROBIN_HOOD:
1829                                 case MON_RICH:
1830                                 case MON_LICH:
1831                                 case MON_COLOSSUS:
1832                                 case MON_CRYPT_THING:
1833                                 case MON_MASTER_LICH:
1834                                 case MON_DREADMASTER:
1835                                 case MON_DEMILICH:
1836                                 case MON_SHADOWLORD:
1837                                 case MON_ARCHLICH:
1838                                 case MON_BLEYS:
1839                                 case MON_CAINE:
1840                                 case MON_JULIAN:
1841                                 case MON_VENOM_WYRM:
1842                                 case MON_MASTER_MYS:
1843                                 case MON_G_MASTER_MYS:
1844                                         power[i] = power[i] * 3 / 4;
1845                                         break;
1846                                 case MON_VORPAL_BUNNY:
1847                                 case MON_SHAGRAT:
1848                                 case MON_GORBAG:
1849                                 case MON_LOG_MASTER:
1850                                 case MON_JURT:
1851                                 case MON_GRAV_HOUND:
1852                                 case MON_SHIM_VOR:
1853                                 case MON_JUBJUB:
1854                                 case MON_CLUB_DEMON:
1855                                 case MON_LLOIGOR:
1856                                 case MON_NIGHTCRAWLER:
1857                                 case MON_NIGHTWALKER:
1858                                 case MON_RAPHAEL:
1859                                 case MON_SHAMBLER:
1860                                 case MON_SKY_DRAKE:
1861                                 case MON_GERARD:
1862                                 case MON_G_CTHULHU:
1863                                 case MON_SPECT_WYRM:
1864                                 case MON_BAZOOKER:
1865                                 case MON_GCWADL:
1866                                 case MON_KIRIN:
1867                                 case MON_FENGHUANG:
1868                                         power[i] = power[i] * 4 / 3;
1869                                         break;
1870                                 case MON_UMBER_HULK:
1871                                 case MON_FIRE_VOR:
1872                                 case MON_WATER_VOR:
1873                                 case MON_COLD_VOR:
1874                                 case MON_ENERGY_VOR:
1875                                 case MON_GACHAPIN:
1876                                 case MON_REVENANT:
1877                                 case MON_NEXUS_VOR:
1878                                 case MON_PLASMA_VOR:
1879                                 case MON_TIME_VOR:
1880                                 case MON_MANDOR:
1881                                 case MON_KAVLAX:
1882                                 case MON_RINALDO:
1883                                 case MON_STORMBRINGER:
1884                                 case MON_TIME_HOUND:
1885                                 case MON_PLASMA_HOUND:
1886                                 case MON_TINDALOS:
1887                                 case MON_CHAOS_VOR:
1888                                 case MON_AETHER_VOR:
1889                                 case MON_AETHER_HOUND:
1890                                 case MON_CANTORAS:
1891                                 case MON_GODZILLA:
1892                                 case MON_TARRASQUE:
1893                                 case MON_DESTROYER:
1894                                 case MON_MORGOTH:
1895                                 case MON_SERPENT:
1896                                 case MON_OROCHI:
1897                                 case MON_D_ELF_SHADE:
1898                                 case MON_MANA_HOUND:
1899                                 case MON_SHARD_VOR:
1900                                 case MON_BANORLUPART:
1901                                 case MON_BOTEI:
1902                                 case MON_JAIAN:
1903                                 case MON_BAHAMUT:
1904                                 case MON_WAHHA:
1905                                         power[i] = power[i] * 3 / 2;
1906                                         break;
1907                                 case MON_ROLENTO:
1908                                 case MON_CYBER:
1909                                 case MON_CYBER_KING:
1910                                 case MON_UNICORN_ORD:
1911                                         power[i] = power[i] * 5 / 3;
1912                                         break;
1913                                 case MON_ARCH_VILE:
1914                                 case MON_PHANTOM_B:
1915                                 case MON_WYRM_POWER:
1916                                         power[i] *= 2;
1917                                         break;
1918                                 case MON_NODENS:
1919                                 case MON_CULVERIN:
1920                                         power[i] *= 3;
1921                                         break;
1922                                 case MON_ECHIZEN:
1923                                         power[i] *= 9;
1924                                         break;
1925                                 case MON_HAGURE:
1926                                         power[i] *= 100000;
1927                                         break;
1928                                 default:
1929                                         break;
1930                         }
1931                         total += power[i];
1932                 }
1933                 for (i=0;i<4;i++)
1934                 {
1935                         power[i] = total*60/power[i];
1936                         if (tekitou && ((power[i] < 160) || power[i] > 1500)) break;
1937                         if ((power[i] < 160) && randint0(20)) break;
1938                         if (power[i] < 101) power[i] = 100 + randint1(5);
1939                         mon_odds[i] = power[i];
1940                 }
1941                 if (i == 4) break;
1942         }
1943 }
1944
1945 static bool kakutoujou(void)
1946 {
1947         s32b maxbet;
1948         s32b wager;
1949         char out_val[160], tmp_str[80];
1950         cptr p;
1951
1952         if ((turn - old_battle) > TURNS_PER_TICK*250)
1953         {
1954                 battle_monsters();
1955                 old_battle = turn;
1956         }
1957
1958         screen_save();
1959
1960         /* No money */
1961         if (p_ptr->au < 1)
1962         {
1963 #ifdef JP
1964                 msg_print("¤ª¤¤¡ª¤ª¤Þ¤¨°ìʸ¤Ê¤·¤¸¤ã¤Ê¤¤¤«¡ª¤³¤Ã¤«¤é½Ð¤Æ¤¤¤±¡ª");
1965 #else
1966                 msg_print("Hey! You don't have gold - get out of here!");
1967 #endif
1968
1969                 msg_print(NULL);
1970                 screen_load();
1971                 return FALSE;
1972         }
1973         else
1974         {
1975                 int i;
1976
1977                 clear_bldg(4, 10);
1978
1979 #ifdef JP
1980                 prt("¥â¥ó¥¹¥¿¡¼                                                     ÇÜΨ", 4, 4);
1981 #else
1982                 prt("Monsters                                                       Odds", 4, 4);
1983 #endif
1984                 for (i=0;i<4;i++)
1985                 {
1986                         char buf[80];
1987                         monster_race *r_ptr = &r_info[battle_mon[i]];
1988
1989 #ifdef JP
1990                         sprintf(buf,"%d) %-58s  %4ld.%02ldÇÜ", i+1, format("%s%s",r_name + r_ptr->name, (r_ptr->flags1 & RF1_UNIQUE) ? "¤â¤É¤­" : "      "), (long int)mon_odds[i]/100, (long int)mon_odds[i]%100);
1991 #else
1992                         sprintf(buf,"%d) %-58s  %4ld.%02ld", i+1, format("%s%s", (r_ptr->flags1 & RF1_UNIQUE) ? "Fake " : "", r_name + r_ptr->name), (long int)mon_odds[i]/100, (long int)mon_odds[i]%100);
1993 #endif
1994                         prt(buf, 5+i, 1);
1995                 }
1996
1997 #ifdef JP
1998                 prt("¤É¤ì¤ËÅÒ¤±¤Þ¤¹¤«:", 0, 0);
1999 #else
2000                 prt("Which monster: ", 0, 0);
2001 #endif
2002                 while(1)
2003                 {
2004                         i = inkey();
2005
2006                         if (i == ESCAPE)
2007                         {
2008                                 screen_load();
2009                                 return FALSE;
2010                         }
2011                         if (i >= '1' && i <= '4')
2012                         {
2013                                 sel_monster = i-'1';
2014                                 battle_odds = mon_odds[sel_monster];
2015                                 break;
2016                         }
2017                         else bell();
2018                 }
2019
2020                 clear_bldg(4,4);
2021                 for (i=0;i<4;i++)
2022                         if (i !=sel_monster) clear_bldg(i+5,i+5);
2023
2024                 maxbet = p_ptr->lev * 200;
2025
2026                 /* We can't bet more than we have */
2027                 maxbet = MIN(maxbet, p_ptr->au);
2028
2029                 /* Get the wager */
2030                 strcpy(out_val, "");
2031 #ifdef JP
2032 sprintf(tmp_str,"ÅÒ¤±¶â (1-%ld)¡©", (long int)maxbet);
2033 #else
2034                 sprintf(tmp_str,"Your wager (1-%ld) ? ", (long int)maxbet);
2035 #endif
2036
2037
2038                 /*
2039                  * Use get_string() because we may need more than
2040                  * the s16b value returned by get_quantity().
2041                  */
2042                 if (get_string(tmp_str, out_val, 32))
2043                 {
2044                         /* Strip spaces */
2045                         for (p = out_val; *p == ' '; p++);
2046
2047                         /* Get the wager */
2048                         wager = atol(p);
2049
2050                         if (wager > p_ptr->au)
2051                         {
2052 #ifdef JP
2053 msg_print("¤ª¤¤¡ª¶â¤¬Â­¤ê¤Ê¤¤¤¸¤ã¤Ê¤¤¤«¡ª½Ð¤Æ¤¤¤±¡ª");
2054 #else
2055                                 msg_print("Hey! You don't have the gold - get out of here!");
2056 #endif
2057
2058                                 msg_print(NULL);
2059                                 screen_load();
2060                                 return (FALSE);
2061                         }
2062                         else if (wager > maxbet)
2063                         {
2064 #ifdef JP
2065 msg_format("%ld¥´¡¼¥ë¥É¤À¤±¼õ¤±¤è¤¦¡£»Ä¤ê¤Ï¼è¤Ã¤È¤­¤Ê¡£", (long int)maxbet);
2066 #else
2067                                 msg_format("I'll take %ld gold of that. Keep the rest.",(long int) maxbet);
2068 #endif
2069
2070                                 wager = maxbet;
2071                         }
2072                         else if (wager < 1)
2073                         {
2074 #ifdef JP
2075 msg_print("£Ï£Ë¡¢£±¥´¡¼¥ë¥É¤Ç¤¤¤³¤¦¡£");
2076 #else
2077                                 msg_print("Ok, we'll start with 1 gold.");
2078 #endif
2079
2080
2081                                 wager = 1;
2082                         }
2083                         msg_print(NULL);
2084                         battle_odds = MAX(wager+1, wager * battle_odds / 100);
2085                         kakekin = wager;
2086                         p_ptr->au -= wager;
2087                         reset_tim_flags();
2088
2089                         /* Save the surface floor as saved floor */
2090                         prepare_change_floor_mode(CFM_SAVE_FLOORS);
2091
2092                         p_ptr->inside_battle = TRUE;
2093                         p_ptr->leaving = TRUE;
2094
2095                         leave_bldg = TRUE;
2096                         screen_load();
2097
2098                         return (TRUE);
2099                 }
2100         }
2101         screen_load();
2102
2103         return (FALSE);
2104 }
2105
2106 static void today_target(void)
2107 {
2108         char buf[160];
2109         monster_race *r_ptr = &r_info[today_mon];
2110
2111         clear_bldg(4,18);
2112 #ifdef JP
2113 c_put_str(TERM_YELLOW, "ËÜÆü¤Î¾Þ¶â¼ó", 5, 10);
2114 #else
2115         prt("Wanted monster that changes from day to day", 5, 10);
2116 #endif
2117 #ifdef JP
2118         sprintf(buf,"¥¿¡¼¥²¥Ã¥È¡§ %s",r_name + r_ptr->name);
2119 #else
2120         sprintf(buf,"target: %s",r_name + r_ptr->name);
2121 #endif
2122         c_put_str(TERM_YELLOW, buf, 6, 10);
2123 #ifdef JP
2124         sprintf(buf,"»àÂΠ---- $%d",r_ptr->level * 50 + 100);
2125 #else
2126         sprintf(buf,"corpse   ---- $%d",r_ptr->level * 50 + 100);
2127 #endif
2128         prt(buf, 8, 10);
2129 #ifdef JP
2130         sprintf(buf,"¹ü   ---- $%d",r_ptr->level * 30 + 60);
2131 #else
2132         sprintf(buf,"skeleton ---- $%d",r_ptr->level * 30 + 60);
2133 #endif
2134         prt(buf, 9, 10);
2135         p_ptr->today_mon = today_mon;
2136 }
2137
2138 static void tsuchinoko(void)
2139 {
2140         clear_bldg(4,18);
2141 #ifdef JP
2142 c_put_str(TERM_YELLOW, "°ì³ÍÀé¶â¤ÎÂç¥Á¥ã¥ó¥¹¡ª¡ª¡ª", 5, 10);
2143 c_put_str(TERM_YELLOW, "¥¿¡¼¥²¥Ã¥È¡§¸¸¤ÎÄÁ½Ã¡Ö¥Ä¥Á¥Î¥³¡×", 6, 10);
2144 c_put_str(TERM_WHITE, "À¸¤±Êá¤ê ---- $1,000,000", 8, 10);
2145 c_put_str(TERM_WHITE, "»àÂΠ    ----   $200,000", 9, 10);
2146 c_put_str(TERM_WHITE, "¹ü       ----   $100,000", 10, 10);
2147 #else
2148 c_put_str(TERM_YELLOW, "Big chance to quick money!!!", 5, 10);
2149 c_put_str(TERM_YELLOW, "target: the rarest animal 'Tsuchinoko'", 6, 10);
2150 c_put_str(TERM_WHITE, "catch alive ---- $1,000,000", 8, 10);
2151 c_put_str(TERM_WHITE, "corpse      ----   $200,000", 9, 10);
2152 c_put_str(TERM_WHITE, "bones       ----   $100,000", 10, 10);
2153 #endif
2154 }
2155
2156 static void shoukinkubi(void)
2157 {
2158         int i;
2159         int y = 0;
2160
2161         clear_bldg(4,18);
2162
2163 #ifdef JP
2164         prt("»àÂΤò»ý¤Áµ¢¤ì¤ÐÊó½·¤òº¹¤·¾å¤²¤Þ¤¹¡£",4 ,10);
2165 c_put_str(TERM_YELLOW, "¸½ºß¤Î¾Þ¶â¼ó", 6, 10);
2166 #else
2167         prt("Offer a prize when you bring a wanted monster's corpse",4 ,10);
2168 c_put_str(TERM_YELLOW, "Wanted monsters", 6, 10);
2169 #endif
2170
2171         for (i = 0; i < MAX_KUBI; i++)
2172         {
2173                 byte color;
2174                 cptr done_mark;
2175                 monster_race *r_ptr = &r_info[(kubi_r_idx[i] > 10000 ? kubi_r_idx[i] - 10000 : kubi_r_idx[i])];
2176
2177                 if (kubi_r_idx[i] > 10000)
2178                 {
2179                         color = TERM_RED;
2180 #ifdef JP
2181                         done_mark = "(ºÑ)";
2182 #else
2183                         done_mark = "(done)";
2184 #endif
2185                 }
2186                 else
2187                 {
2188                         color = TERM_WHITE;
2189                         done_mark = "";
2190                 }
2191
2192                 c_prt(color, format("%s %s", r_name + r_ptr->name, done_mark), y+7, 10);
2193
2194                 y = (y+1) % 10;
2195                 if (!y && (i < MAX_KUBI -1))
2196                 {
2197 #ifdef JP
2198                         prt("²¿¤«¥­¡¼¤ò²¡¤·¤Æ¤¯¤À¤µ¤¤", 0, 0);
2199 #else
2200                         prt("Hit any key.", 0, 0);
2201 #endif
2202                         (void)inkey();
2203                         prt("", 0, 0);
2204                         clear_bldg(7,18);
2205                 }
2206         }
2207 }
2208
2209
2210 /* List of prize object */
2211 static struct {
2212         s16b tval;
2213         s16b sval;
2214 } prize_list[MAX_KUBI] = 
2215 {
2216         {TV_POTION, SV_POTION_CURING},
2217         {TV_POTION, SV_POTION_SPEED},
2218         {TV_POTION, SV_POTION_SPEED},
2219         {TV_POTION, SV_POTION_RESISTANCE},
2220         {TV_POTION, SV_POTION_ENLIGHTENMENT},
2221
2222         {TV_POTION, SV_POTION_HEALING},
2223         {TV_POTION, SV_POTION_RESTORE_MANA},
2224         {TV_SCROLL, SV_SCROLL_STAR_DESTRUCTION},
2225         {TV_POTION, SV_POTION_STAR_ENLIGHTENMENT},
2226         {TV_SCROLL, SV_SCROLL_SUMMON_PET},
2227
2228         {TV_SCROLL, SV_SCROLL_GENOCIDE},
2229         {TV_POTION, SV_POTION_STAR_HEALING},
2230         {TV_POTION, SV_POTION_STAR_HEALING},
2231         {TV_POTION, SV_POTION_NEW_LIFE},
2232         {TV_SCROLL, SV_SCROLL_MASS_GENOCIDE},
2233
2234         {TV_POTION, SV_POTION_LIFE},
2235         {TV_POTION, SV_POTION_LIFE},
2236         {TV_POTION, SV_POTION_AUGMENTATION},
2237         {TV_POTION, SV_POTION_INVULNERABILITY},
2238         {TV_SCROLL, SV_SCROLL_ARTIFACT},
2239 };
2240
2241
2242 /* Get prize */
2243 static bool kankin(void)
2244 {
2245         int i, j;
2246         bool change = FALSE;
2247         char o_name[MAX_NLEN];
2248         object_type *o_ptr;
2249
2250         /* Loop for inventory and right/left arm */
2251         for (i = 0; i <= INVEN_LARM; i++)
2252         {
2253                 o_ptr = &inventory[i];
2254
2255                 /* Living Tsuchinoko worthes $1000000 */
2256                 if ((o_ptr->tval == TV_CAPTURE) && (o_ptr->pval == MON_TSUCHINOKO))
2257                 {
2258                         char buf[MAX_NLEN+20];
2259                         object_desc(o_name, o_ptr, 0);
2260 #ifdef JP
2261                         sprintf(buf, "%s ¤ò´¹¶â¤·¤Þ¤¹¤«¡©",o_name);
2262 #else
2263                         sprintf(buf, "Convert %s into money? ",o_name);
2264 #endif
2265                         if (get_check(buf))
2266                         {
2267 #ifdef JP
2268                                 msg_format("¾Þ¶â %ld¡ð¤ò¼ê¤ËÆþ¤ì¤¿¡£", (long int)(1000000L * o_ptr->number));
2269 #else
2270                                 msg_format("You get %ldgp.", (long int)(1000000L * o_ptr->number));
2271 #endif
2272                                 p_ptr->au += 1000000L * o_ptr->number;
2273                                 p_ptr->redraw |= (PR_GOLD);
2274                                 inven_item_increase(i, -o_ptr->number);
2275                                 inven_item_describe(i);
2276                                 inven_item_optimize(i);
2277                         }
2278                         change = TRUE;
2279                 }
2280         }
2281
2282         for (i = 0; i < INVEN_PACK; i++)
2283         {
2284                 o_ptr = &inventory[i];
2285
2286                 /* Corpse of Tsuchinoko worthes $200000 */
2287                 if ((o_ptr->tval == TV_CORPSE) && (o_ptr->sval == SV_CORPSE) && (o_ptr->pval == MON_TSUCHINOKO))
2288                 {
2289                         char buf[MAX_NLEN+20];
2290                         object_desc(o_name, o_ptr, 0);
2291 #ifdef JP
2292                         sprintf(buf, "%s ¤ò´¹¶â¤·¤Þ¤¹¤«¡©",o_name);
2293 #else
2294                         sprintf(buf, "Convert %s into money? ",o_name);
2295 #endif
2296                         if (get_check(buf))
2297                         {
2298 #ifdef JP
2299                                 msg_format("¾Þ¶â %ld¡ð¤ò¼ê¤ËÆþ¤ì¤¿¡£", (long int)(200000L * o_ptr->number));
2300 #else
2301                                 msg_format("You get %ldgp.", (long int)(200000L * o_ptr->number));
2302 #endif
2303                                 p_ptr->au += 200000L * o_ptr->number;
2304                                 p_ptr->redraw |= (PR_GOLD);
2305                                 inven_item_increase(i, -o_ptr->number);
2306                                 inven_item_describe(i);
2307                                 inven_item_optimize(i);
2308                         }
2309                         change = TRUE;
2310                 }
2311         }
2312
2313         for (i = 0; i < INVEN_PACK; i++)
2314         {
2315                 o_ptr = &inventory[i];
2316
2317                 /* Bones of Tsuchinoko worthes $100000 */
2318                 if ((o_ptr->tval == TV_CORPSE) && (o_ptr->sval == SV_SKELETON) && (o_ptr->pval == MON_TSUCHINOKO))
2319                 {
2320                         char buf[MAX_NLEN+20];
2321                         object_desc(o_name, o_ptr, 0);
2322 #ifdef JP
2323                         sprintf(buf, "%s ¤ò´¹¶â¤·¤Þ¤¹¤«¡©",o_name);
2324 #else
2325                         sprintf(buf, "Convert %s into money? ",o_name);
2326 #endif
2327                         if (get_check(buf))
2328                         {
2329 #ifdef JP
2330                                 msg_format("¾Þ¶â %ld¡ð¤ò¼ê¤ËÆþ¤ì¤¿¡£", (long int)(100000L * o_ptr->number));
2331 #else
2332                                 msg_format("You get %ldgp.", (long int)(100000L * o_ptr->number));
2333 #endif
2334                                 p_ptr->au += 100000L * o_ptr->number;
2335                                 p_ptr->redraw |= (PR_GOLD);
2336                                 inven_item_increase(i, -o_ptr->number);
2337                                 inven_item_describe(i);
2338                                 inven_item_optimize(i);
2339                         }
2340                         change = TRUE;
2341                 }
2342         }
2343
2344         for (i = 0; i < INVEN_PACK; i++)
2345         {
2346                 o_ptr = &inventory[i];
2347                 if ((o_ptr->tval == TV_CORPSE) && (o_ptr->sval == SV_CORPSE) && (streq(r_name + r_info[o_ptr->pval].name, r_name + r_info[today_mon].name)))
2348                 {
2349                         char buf[MAX_NLEN+20];
2350                         object_desc(o_name, o_ptr, 0);
2351 #ifdef JP
2352                         sprintf(buf, "%s ¤ò´¹¶â¤·¤Þ¤¹¤«¡©",o_name);
2353 #else
2354                         sprintf(buf, "Convert %s into money? ",o_name);
2355 #endif
2356                         if (get_check(buf))
2357                         {
2358 #ifdef JP
2359                                 msg_format("¾Þ¶â %ld¡ð¤ò¼ê¤ËÆþ¤ì¤¿¡£", (long int)((r_info[today_mon].level * 50 + 100) * o_ptr->number));
2360 #else
2361                                 msg_format("You get %ldgp.", (long int)((r_info[today_mon].level * 50 + 100) * o_ptr->number));
2362 #endif
2363                                 p_ptr->au += (r_info[today_mon].level * 50 + 100) * o_ptr->number;
2364                                 p_ptr->redraw |= (PR_GOLD);
2365                                 inven_item_increase(i, -o_ptr->number);
2366                                 inven_item_describe(i);
2367                                 inven_item_optimize(i);
2368                         }
2369                         change = TRUE;
2370                 }
2371         }
2372
2373         for (i = 0; i < INVEN_PACK; i++)
2374         {
2375                 o_ptr = &inventory[i];
2376
2377                 if ((o_ptr->tval == TV_CORPSE) && (o_ptr->sval == SV_SKELETON) && (streq(r_name + r_info[o_ptr->pval].name, r_name + r_info[today_mon].name)))
2378                 {
2379                         char buf[MAX_NLEN+20];
2380                         object_desc(o_name, o_ptr, 0);
2381 #ifdef JP
2382                         sprintf(buf, "%s ¤ò´¹¶â¤·¤Þ¤¹¤«¡©",o_name);
2383 #else
2384                         sprintf(buf, "Convert %s into money? ",o_name);
2385 #endif
2386                         if (get_check(buf))
2387                         {
2388 #ifdef JP
2389                                 msg_format("¾Þ¶â %ld¡ð¤ò¼ê¤ËÆþ¤ì¤¿¡£", (long int)((r_info[today_mon].level * 30 + 60) * o_ptr->number));
2390 #else
2391                                 msg_format("You get %ldgp.", (long int)((r_info[today_mon].level * 30 + 60) * o_ptr->number));
2392 #endif
2393                                 p_ptr->au += (r_info[today_mon].level * 30 + 60) * o_ptr->number;
2394                                 p_ptr->redraw |= (PR_GOLD);
2395                                 inven_item_increase(i, -o_ptr->number);
2396                                 inven_item_describe(i);
2397                                 inven_item_optimize(i);
2398                         }
2399                         change = TRUE;
2400                 }
2401         }
2402
2403         for (j = 0; j < MAX_KUBI; j++)
2404         {
2405                 /* Need reverse order --- Positions will be changed in the loop */
2406                 for (i = INVEN_PACK-1; i >= 0; i--)
2407                 {
2408                         o_ptr = &inventory[i];
2409                         if ((o_ptr->tval == TV_CORPSE) && (o_ptr->pval == kubi_r_idx[j]))
2410                         {
2411                                 char buf[MAX_NLEN+20];
2412                                 int num, k, item_new;
2413                                 object_type forge;
2414
2415                                 object_desc(o_name, o_ptr, 0);
2416 #ifdef JP
2417                                 sprintf(buf, "%s¤òÅϤ·¤Þ¤¹¤«¡©",o_name);
2418 #else
2419                                 sprintf(buf, "Hand %s over? ",o_name);
2420 #endif
2421                                 if (!get_check(buf)) continue;
2422
2423 #if 0 /* Obsoleted */
2424 #ifdef JP
2425                                 msg_format("¾Þ¶â %ld¡ð¤ò¼ê¤ËÆþ¤ì¤¿¡£", (r_info[kubi_r_idx[j]].level + 1) * 300 * o_ptr->number);
2426 #else
2427                                 msg_format("You get %ldgp.", (r_info[kubi_r_idx[j]].level + 1) * 300 * o_ptr->number);
2428 #endif
2429                                 p_ptr->au += (r_info[kubi_r_idx[j]].level+1) * 300 * o_ptr->number;
2430                                 p_ptr->redraw |= (PR_GOLD);
2431                                 inven_item_increase(i, -o_ptr->number);
2432                                 inven_item_describe(i);
2433                                 inven_item_optimize(i);
2434                                 chg_virtue(V_JUSTICE, 5);
2435                                 kubi_r_idx[j] += 10000;
2436
2437                                 change = TRUE;
2438 #endif /* Obsoleted */
2439
2440                                 /* Hand it first */
2441                                 inven_item_increase(i, -o_ptr->number);
2442                                 inven_item_describe(i);
2443                                 inven_item_optimize(i);
2444
2445                                 chg_virtue(V_JUSTICE, 5);
2446                                 kubi_r_idx[j] += 10000;
2447
2448                                 /* Count number of unique corpses already handed */
2449                                 for (num = 0, k = 0; k < MAX_KUBI; k++)
2450                                 {
2451                                         if (kubi_r_idx[k] >= 10000) num++;
2452                                 }
2453
2454 #ifdef JP
2455                                 msg_format("¤³¤ì¤Ç¹ç·× %d ¥Ý¥¤¥ó¥È³ÍÆÀ¤·¤Þ¤·¤¿¡£", num);
2456 #else
2457                                 msg_format("You earned %d point%s total.", num, (num > 1 ? "s" : ""));
2458 #endif
2459
2460                                 /* Prepare to make a prize */
2461                                 object_prep(&forge, lookup_kind(prize_list[num-1].tval, prize_list[num-1].sval));
2462                                 apply_magic(&forge, object_level, AM_NO_FIXED_ART);
2463
2464                                 /* Identify it fully */
2465                                 object_aware(&forge);
2466                                 object_known(&forge);
2467
2468                                 /*
2469                                  * Hand it --- Assume there is an empty slot.
2470                                  * Since a corpse is handed at first,
2471                                  * there is at least one empty slot.
2472                                  */
2473                                 item_new = inven_carry(&forge);
2474
2475                                 /* Describe the object */
2476                                 object_desc(o_name, &forge, 0);
2477 #ifdef JP
2478                                 msg_format("%s(%c)¤òÌã¤Ã¤¿¡£", o_name, index_to_label(item_new));
2479 #else
2480                                 msg_format("You get %s (%c). ", o_name, index_to_label(item_new));
2481 #endif
2482
2483                                 /* Auto-inscription */
2484                                 autopick_alter_item(item_new, FALSE);
2485
2486                                 /* Handle stuff */
2487                                 handle_stuff();
2488
2489                                 change = TRUE;
2490                         }
2491                 }
2492         }
2493
2494         if (!change)
2495         {
2496 #ifdef JP
2497                 msg_print("¾Þ¶â¤òÆÀ¤é¤ì¤½¤¦¤Ê¤â¤Î¤Ï»ý¤Ã¤Æ¤¤¤Ê¤«¤Ã¤¿¡£");
2498 #else
2499                 msg_print("You have nothing.");
2500 #endif
2501                 msg_print(NULL);
2502                 return FALSE;
2503         }
2504         return TRUE;
2505 }
2506
2507 bool get_nightmare(int r_idx)
2508 {
2509         monster_race *r_ptr = &r_info[r_idx];
2510
2511         /* Require eldritch horrors */
2512         if (!(r_ptr->flags2 & (RF2_ELDRITCH_HORROR))) return (FALSE);
2513
2514         /* Require high level */
2515         if (r_ptr->level <= p_ptr->lev) return (FALSE);
2516
2517         /* Accept this monster */
2518         return (TRUE);
2519 }
2520
2521
2522 void have_nightmare(int r_idx)
2523 {
2524         bool happened = FALSE;
2525         monster_race *r_ptr = &r_info[r_idx];
2526         int power = r_ptr->level + 10;
2527         char m_name[80];
2528         cptr desc = r_name + r_ptr->name;
2529
2530         /* Describe it */
2531 #ifndef JP
2532         if (!(r_ptr->flags1 & RF1_UNIQUE))
2533                 sprintf(m_name, "%s %s", (is_a_vowel(desc[0]) ? "an" : "a"), desc);
2534         else
2535 #endif
2536                 sprintf(m_name, "%s", desc);
2537
2538         if (!(r_ptr->flags1 & RF1_UNIQUE))
2539         {
2540                 if (r_ptr->flags1 & RF1_FRIENDS) power /= 2;
2541         }
2542         else power *= 2;
2543
2544         if (saving_throw(p_ptr->skill_sav * 100 / power))
2545         {
2546 #ifdef JP
2547                 msg_format("Ì´¤ÎÃæ¤Ç%s¤ËÄɤ¤¤«¤±¤é¤ì¤¿¡£", m_name);
2548 #else
2549                 msg_format("%^s chases you through your dreams.", m_name);
2550 #endif
2551
2552                 /* Safe */
2553                 return;
2554         }
2555
2556         if (p_ptr->image)
2557         {
2558                 /* Something silly happens... */
2559 #ifdef JP
2560                 msg_format("%s%s¤Î´é¤ò¸«¤Æ¤·¤Þ¤Ã¤¿¡ª",
2561 #else
2562                 msg_format("You behold the %s visage of %s!",
2563 #endif
2564
2565                                           funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
2566
2567                 if (one_in_(3))
2568                 {
2569                         msg_print(funny_comments[randint0(MAX_SAN_COMMENT)]);
2570                         p_ptr->image = p_ptr->image + randint1(r_ptr->level);
2571                 }
2572
2573                 /* Never mind; we can't see it clearly enough */
2574                 return;
2575         }
2576
2577         /* Something frightening happens... */
2578 #ifdef JP
2579         msg_format("%s%s¤Î´é¤ò¸«¤Æ¤·¤Þ¤Ã¤¿¡ª",
2580 #else
2581         msg_format("You behold the %s visage of %s!",
2582 #endif
2583
2584                                   horror_desc[randint0(MAX_SAN_HORROR)], desc);
2585
2586         r_ptr->r_flags2 |= RF2_ELDRITCH_HORROR;
2587
2588         if (!p_ptr->mimic_form)
2589         {
2590                 switch (p_ptr->prace)
2591                 {
2592                 /* Demons may make a saving throw */
2593                 case RACE_IMP:
2594                 case RACE_DEMON:
2595                         if (saving_throw(20 + p_ptr->lev)) return;
2596                         break;
2597                 /* Undead may make a saving throw */
2598                 case RACE_SKELETON:
2599                 case RACE_ZOMBIE:
2600                 case RACE_SPECTRE:
2601                 case RACE_VAMPIRE:
2602                         if (saving_throw(10 + p_ptr->lev)) return;
2603                         break;
2604                 }
2605         }
2606         else
2607         {
2608                 /* Demons may make a saving throw */
2609                 if (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)
2610                 {
2611                         if (saving_throw(20 + p_ptr->lev)) return;
2612                 }
2613                 /* Undead may make a saving throw */
2614                 else if (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_UNDEAD)
2615                 {
2616                         if (saving_throw(10 + p_ptr->lev)) return;
2617                 }
2618         }
2619
2620         /* Mind blast */
2621         if (!saving_throw(p_ptr->skill_sav * 100 / power))
2622         {
2623                 if (!p_ptr->resist_conf)
2624                 {
2625                         (void)set_confused(p_ptr->confused + randint0(4) + 4);
2626                 }
2627                 if (!p_ptr->resist_chaos && one_in_(3))
2628                 {
2629                         (void)set_image(p_ptr->image + randint0(250) + 150);
2630                 }
2631                 return;
2632         }
2633
2634         /* Lose int & wis */
2635         if (!saving_throw(p_ptr->skill_sav * 100 / power))
2636         {
2637                 do_dec_stat(A_INT);
2638                 do_dec_stat(A_WIS);
2639                 return;
2640         }
2641
2642         /* Brain smash */
2643         if (!saving_throw(p_ptr->skill_sav * 100 / power))
2644         {
2645                 if (!p_ptr->resist_conf)
2646                 {
2647                         (void)set_confused(p_ptr->confused + randint0(4) + 4);
2648                 }
2649                 if (!p_ptr->free_act)
2650                 {
2651                         (void)set_paralyzed(p_ptr->paralyzed + randint0(4) + 4);
2652                 }
2653                 while (!saving_throw(p_ptr->skill_sav))
2654                 {
2655                         (void)do_dec_stat(A_INT);
2656                 }
2657                 while (!saving_throw(p_ptr->skill_sav))
2658                 {
2659                         (void)do_dec_stat(A_WIS);
2660                 }
2661                 if (!p_ptr->resist_chaos)
2662                 {
2663                         (void)set_image(p_ptr->image + randint0(250) + 150);
2664                 }
2665                 return;
2666         }
2667
2668
2669         /* Amnesia */
2670         if (!saving_throw(p_ptr->skill_sav * 100 / power))
2671         {
2672                 if (lose_all_info())
2673                 {
2674 #ifdef JP
2675 msg_print("¤¢¤Þ¤ê¤Î¶²ÉݤËÁ´¤Æ¤Î¤³¤È¤ò˺¤ì¤Æ¤·¤Þ¤Ã¤¿¡ª");
2676 #else
2677                         msg_print("You forget everything in your utmost terror!");
2678 #endif
2679
2680                 }
2681                 return;
2682         }
2683
2684         /* Else gain permanent insanity */
2685         if ((p_ptr->muta3 & MUT3_MORONIC) && (p_ptr->muta2 & MUT2_BERS_RAGE) &&
2686                 ((p_ptr->muta2 & MUT2_COWARDICE) || (p_ptr->resist_fear)) &&
2687                 ((p_ptr->muta2 & MUT2_HALLU) || (p_ptr->resist_chaos)))
2688         {
2689                 /* The poor bastard already has all possible insanities! */
2690                 return;
2691         }
2692
2693         while (!happened)
2694         {
2695                 switch (randint1(4))
2696                 {
2697                         case 1:
2698                         {
2699                                 if (!(p_ptr->muta3 & MUT3_MORONIC))
2700                                 {
2701                                         if ((p_ptr->stat_use[A_INT] < 4) && (p_ptr->stat_use[A_WIS] < 4))
2702                                         {
2703 #ifdef JP
2704 msg_print("¤¢¤Ê¤¿¤Ï´°àú¤ÊÇϼ¯¤Ë¤Ê¤Ã¤¿¤è¤¦¤Êµ¤¤¬¤·¤¿¡£¤·¤«¤·¤½¤ì¤Ï¸µ¡¹¤À¤Ã¤¿¡£");
2705 #else
2706                                                 msg_print("You turn into an utter moron!");
2707 #endif
2708                                         }
2709                                         else
2710                                         {
2711 #ifdef JP
2712 msg_print("¤¢¤Ê¤¿¤Ï´°àú¤ÊÇϼ¯¤Ë¤Ê¤Ã¤¿¡ª");
2713 #else
2714                                                 msg_print("You turn into an utter moron!");
2715 #endif
2716                                         }
2717
2718                                         if (p_ptr->muta3 & MUT3_HYPER_INT)
2719                                         {
2720 #ifdef JP
2721 msg_print("¤¢¤Ê¤¿¤ÎǾ¤ÏÀ¸ÂÎ¥³¥ó¥Ô¥å¡¼¥¿¤Ç¤Ï¤Ê¤¯¤Ê¤Ã¤¿¡£");
2722 #else
2723                                                 msg_print("Your brain is no longer a living computer.");
2724 #endif
2725
2726                                                 p_ptr->muta3 &= ~(MUT3_HYPER_INT);
2727                                         }
2728                                         p_ptr->muta3 |= MUT3_MORONIC;
2729                                         happened = TRUE;
2730                                 }
2731                                 break;
2732                         }
2733                         case 2:
2734                         {
2735                                 if (!(p_ptr->muta2 & MUT2_COWARDICE) && !p_ptr->resist_fear)
2736                                 {
2737 #ifdef JP
2738 msg_print("¤¢¤Ê¤¿¤Ï¥Ñ¥é¥Î¥¤¥¢¤Ë¤Ê¤Ã¤¿¡ª");
2739 #else
2740                                         msg_print("You become paranoid!");
2741 #endif
2742
2743
2744                                         /* Duh, the following should never happen, but anyway... */
2745                                         if (p_ptr->muta3 & MUT3_FEARLESS)
2746                                         {
2747 #ifdef JP
2748 msg_print("¤¢¤Ê¤¿¤Ï¤â¤¦¶²¤ìÃΤ餺¤Ç¤Ï¤Ê¤¯¤Ê¤Ã¤¿¡£");
2749 #else
2750                                                 msg_print("You are no longer fearless.");
2751 #endif
2752
2753                                                 p_ptr->muta3 &= ~(MUT3_FEARLESS);
2754                                         }
2755
2756                                         p_ptr->muta2 |= MUT2_COWARDICE;
2757                                         happened = TRUE;
2758                                 }
2759                                 break;
2760                         }
2761                         case 3:
2762                         {
2763                                 if (!(p_ptr->muta2 & MUT2_HALLU) && !p_ptr->resist_chaos)
2764                                 {
2765 #ifdef JP
2766 msg_print("¸¸³Ð¤ò¤Ò¤­µ¯¤³¤¹Àº¿ÀºøÍð¤Ë´Ù¤Ã¤¿¡ª");
2767 #else
2768                                         msg_print("You are afflicted by a hallucinatory insanity!");
2769 #endif
2770
2771                                         p_ptr->muta2 |= MUT2_HALLU;
2772                                         happened = TRUE;
2773                                 }
2774                                 break;
2775                         }
2776                         default:
2777                         {
2778                                 if (!(p_ptr->muta2 & MUT2_BERS_RAGE))
2779                                 {
2780 #ifdef JP
2781 msg_print("·ãÎõ¤Ê´¶¾ð¤Îȯºî¤Ë¤ª¤½¤ï¤ì¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿¡ª");
2782 #else
2783                                         msg_print("You become subject to fits of berserk rage!");
2784 #endif
2785
2786                                         p_ptr->muta2 |= MUT2_BERS_RAGE;
2787                                         happened = TRUE;
2788                                 }
2789                                 break;
2790                         }
2791                 }
2792         }
2793
2794         p_ptr->update |= PU_BONUS;
2795         handle_stuff();
2796 }
2797
2798
2799 /*
2800  * inn commands
2801  * Note that resting for the night was a perfect way to avoid player
2802  * ghosts in the town *if* you could only make it to the inn in time (-:
2803  * Now that the ghosts are temporarily disabled in 2.8.X, this function
2804  * will not be that useful.  I will keep it in the hopes the player
2805  * ghost code does become a reality again. Does help to avoid filthy urchins.
2806  * Resting at night is also a quick way to restock stores -KMW-
2807  */
2808 static bool inn_comm(int cmd)
2809 {
2810         switch (cmd)
2811         {
2812                 case BACT_FOOD: /* Buy food & drink */
2813                         if (p_ptr->food >= PY_FOOD_FULL)
2814                         {
2815 #ifdef JP
2816                                 msg_print("º£¤ÏËþÊ¢¤À¡£");
2817 #else
2818                                 msg_print("You are full now.");
2819 #endif
2820                                 return FALSE;
2821                         }
2822
2823 #ifdef JP
2824 msg_print("¥Ð¡¼¥Æ¥ó¤Ï¤¤¤¯¤é¤«¤Î¿©¤Ùʪ¤È¥Ó¡¼¥ë¤ò¤¯¤ì¤¿¡£");
2825 #else
2826                         msg_print("The barkeep gives you some gruel and a beer.");
2827 #endif
2828
2829                         (void)set_food(PY_FOOD_MAX - 1);
2830                         break;
2831
2832                 case BACT_REST: /* Rest for the night */
2833                         if ((p_ptr->poisoned) || (p_ptr->cut))
2834                         {
2835 #ifdef JP
2836                                 msg_print("¤¢¤Ê¤¿¤ËɬÍפʤΤÏÉô²°¤Ç¤Ï¤Ê¤¯¡¢¼£ÎżԤǤ¹¡£");
2837 #else
2838                                 msg_print("You need a healer, not a room.");
2839 #endif
2840
2841                                 msg_print(NULL);
2842 #ifdef JP
2843                                 msg_print("¤¹¤ß¤Þ¤»¤ó¡¢¤Ç¤â¤¦¤Á¤Ç狼¤Ë»à¤Ê¤ì¤Á¤ãº¤¤ê¤Þ¤¹¤ó¤Ç¡£");
2844 #else
2845                                 msg_print("Sorry, but don't want anyone dying in here.");
2846 #endif
2847                         }
2848                         else
2849                         {
2850                                 s32b oldturn = turn;
2851                                 int prev_day, prev_hour, prev_min;
2852
2853                                 extract_day_hour_min(&prev_day, &prev_hour, &prev_min);
2854 #ifdef JP
2855                                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "½É²°¤ËÇñ¤Þ¤Ã¤¿¡£");
2856 #else
2857                                 if ((prev_hour >= 6) && (prev_hour <= 17)) do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "stay over daytime at the inn.");
2858                                 else do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "stay over night at the inn.");
2859 #endif
2860                                 turn = (turn / (TURNS_PER_TICK*TOWN_DAWN/2) + 1) * (TURNS_PER_TICK*TOWN_DAWN/2);
2861                                 if (dungeon_turn < dungeon_turn_limit)
2862                                 {
2863                                         dungeon_turn += MIN(turn - oldturn, TURNS_PER_TICK * 250);
2864                                         if (dungeon_turn > dungeon_turn_limit) dungeon_turn = dungeon_turn_limit;
2865                                 }
2866
2867                                 prevent_turn_overflow();
2868
2869                                 if ((prev_hour >= 18) && (prev_hour <= 23)) do_cmd_write_nikki(NIKKI_HIGAWARI, 0, NULL);
2870                                 p_ptr->chp = p_ptr->mhp;
2871
2872                                 if (ironman_nightmare)
2873                                 {
2874 #ifdef JP
2875                                         msg_print("̲¤ê¤Ë½¢¤¯¤È¶²¤í¤·¤¤¸÷·Ê¤¬¿´¤ò¤è¤®¤Ã¤¿¡£");
2876 #else
2877                                         msg_print("Horrible visions flit through your mind as you sleep.");
2878 #endif
2879
2880                                         /* Pick a nightmare */
2881                                         get_mon_num_prep(get_nightmare, NULL);
2882
2883                                         /* Have some nightmares */
2884                                         while(1)
2885                                         {
2886                                                 have_nightmare(get_mon_num(MAX_DEPTH));
2887
2888                                                 if (!one_in_(3)) break;
2889                                         }
2890
2891                                         /* Remove the monster restriction */
2892                                         get_mon_num_prep(NULL, NULL);
2893
2894 #ifdef JP
2895                                         msg_print("¤¢¤Ê¤¿¤ÏÀ䶫¤·¤ÆÌܤò³Ð¤Þ¤·¤¿¡£");
2896                                         do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "°­Ì´¤Ë¤¦¤Ê¤µ¤ì¤Æ¤è¤¯Ì²¤ì¤Ê¤«¤Ã¤¿¡£");
2897 #else
2898                                         msg_print("You awake screaming.");
2899                                         do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "be troubled by a nightmare.");
2900 #endif
2901                                 }
2902                                 else
2903                                 {
2904                                         set_blind(0);
2905                                         set_confused(0);
2906                                         p_ptr->stun = 0;
2907                                         p_ptr->chp = p_ptr->mhp;
2908                                         p_ptr->csp = p_ptr->msp;
2909                                         if (p_ptr->pclass == CLASS_MAGIC_EATER)
2910                                         {
2911                                                 int i;
2912                                                 for (i = 0; i < 72; i++)
2913                                                 {
2914                                                         p_ptr->magic_num1[i] = p_ptr->magic_num2[i]*EATER_CHARGE;
2915                                                 }
2916                                                 for (; i < 108; i++)
2917                                                 {
2918                                                         p_ptr->magic_num1[i] = 0;
2919                                                 }
2920                                         }
2921
2922                                         if ((prev_hour >= 6) && (prev_hour <= 17))
2923                                         {
2924 #ifdef JP
2925                                                 msg_print("¤¢¤Ê¤¿¤Ï¥ê¥Õ¥ì¥Ã¥·¥å¤·¤ÆÌܳФᡢͼÊý¤ò·Þ¤¨¤¿¡£");
2926                                                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "ͼÊý¤ò·Þ¤¨¤¿¡£");
2927 #else
2928                                                 msg_print("You awake refreshed for the evening.");
2929                                                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "awake refreshed.");
2930 #endif
2931                                         }
2932                                         else
2933                                         {
2934 #ifdef JP
2935                                                 msg_print("¤¢¤Ê¤¿¤Ï¥ê¥Õ¥ì¥Ã¥·¥å¤·¤ÆÌܳФᡢ¿·¤¿¤ÊÆü¤ò·Þ¤¨¤¿¡£");
2936                                                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "¤¹¤¬¤¹¤¬¤·¤¤Ä«¤ò·Þ¤¨¤¿¡£");
2937 #else
2938                                                 msg_print("You awake refreshed for the new day.");
2939                                                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "awake refreshed.");
2940 #endif
2941                                         }
2942                                 }
2943                         }
2944                         break;
2945
2946                 case BACT_RUMORS: /* Listen for rumors */
2947                         {
2948                                 display_rumor(TRUE);
2949                                 break;
2950                         }
2951         }
2952
2953         return (TRUE);
2954 }
2955
2956
2957 /*
2958  * Display quest information
2959  */
2960 static void get_questinfo(int questnum, bool do_init)
2961 {
2962         int     i;
2963         int     old_quest;
2964         char    tmp_str[80];
2965
2966
2967         /* Clear the text */
2968         for (i = 0; i < 10; i++)
2969         {
2970                 quest_text[i][0] = '\0';
2971         }
2972
2973         quest_text_line = 0;
2974
2975         /* Set the quest number temporary */
2976         old_quest = p_ptr->inside_quest;
2977         p_ptr->inside_quest = questnum;
2978
2979         /* Get the quest text */
2980         init_flags = INIT_SHOW_TEXT;
2981         if (do_init) init_flags |= INIT_ASSIGN;
2982
2983         process_dungeon_file("q_info.txt", 0, 0, 0, 0);
2984
2985         /* Reset the old quest number */
2986         p_ptr->inside_quest = old_quest;
2987
2988         /* Print the quest info */
2989 #ifdef JP
2990 sprintf(tmp_str, "¥¯¥¨¥¹¥È¾ðÊó (´í¸±ÅÙ: %d ³¬ÁêÅö)", quest[questnum].level);
2991 #else
2992         sprintf(tmp_str, "Quest Information (Danger level: %d)", quest[questnum].level);
2993 #endif
2994
2995         prt(tmp_str, 5, 0);
2996
2997         prt(quest[questnum].name, 7, 0);
2998
2999         for (i = 0; i < 10; i++)
3000         {
3001                 c_put_str(TERM_YELLOW, quest_text[i], i + 8, 0);
3002         }
3003 }
3004
3005
3006 /*
3007  * Request a quest from the Lord.
3008  */
3009 static void castle_quest(void)
3010 {
3011         int             q_index = 0;
3012         monster_race    *r_ptr;
3013         quest_type      *q_ptr;
3014         cptr            name;
3015
3016
3017         clear_bldg(4, 18);
3018
3019         /* Current quest of the building */
3020         q_index = cave[py][px].special;
3021
3022         /* Is there a quest available at the building? */
3023         if (!q_index)
3024         {
3025 #ifdef JP
3026 put_str("º£¤Î¤È¤³¤í¥¯¥¨¥¹¥È¤Ï¤¢¤ê¤Þ¤»¤ó¡£", 8, 0);
3027 #else
3028                 put_str("I don't have a quest for you at the moment.", 8, 0);
3029 #endif
3030
3031                 return;
3032         }
3033
3034         q_ptr = &quest[q_index];
3035
3036         /* Quest is completed */
3037         if (q_ptr->status == QUEST_STATUS_COMPLETED)
3038         {
3039                 /* Rewarded quest */
3040                 q_ptr->status = QUEST_STATUS_REWARDED;
3041
3042                 get_questinfo(q_index, FALSE);
3043
3044                 reinit_wilderness = TRUE;
3045         }
3046         /* Failed quest */
3047         else if (q_ptr->status == QUEST_STATUS_FAILED)
3048         {
3049                 get_questinfo(q_index, FALSE);
3050
3051                 /* Mark quest as done (but failed) */
3052                 q_ptr->status = QUEST_STATUS_FAILED_DONE;
3053
3054                 reinit_wilderness = TRUE;
3055         }
3056         /* Quest is still unfinished */
3057         else if (q_ptr->status == QUEST_STATUS_TAKEN)
3058         {
3059 #ifdef JP
3060 put_str("¤¢¤Ê¤¿¤Ï¸½ºß¤Î¥¯¥¨¥¹¥È¤ò½ªÎ»¤µ¤»¤Æ¤¤¤Þ¤»¤ó¡ª", 8, 0);
3061 #else
3062                 put_str("You have not completed your current quest yet!", 8, 0);
3063 #endif
3064
3065 #ifdef JP
3066 put_str("CTRL-Q¤ò»È¤¨¤Ð¥¯¥¨¥¹¥È¤Î¾õÂÖ¤¬¥Á¥§¥Ã¥¯¤Ç¤­¤Þ¤¹¡£", 9, 0);
3067 #else
3068                 put_str("Use CTRL-Q to check the status of your quest.", 9, 0);
3069 #endif
3070
3071 #ifdef JP
3072 put_str("¥¯¥¨¥¹¥È¤ò½ª¤ï¤é¤»¤¿¤éÌá¤Ã¤ÆÍè¤Æ²¼¤µ¤¤¡£", 12, 0);
3073 #else
3074                 put_str("Return when you have completed your quest.", 12, 0);
3075 #endif
3076
3077         }
3078         /* No quest yet */
3079         else if (q_ptr->status == QUEST_STATUS_UNTAKEN)
3080         {
3081                 q_ptr->status = QUEST_STATUS_TAKEN;
3082
3083                 reinit_wilderness = TRUE;
3084
3085                 /* Assign a new quest */
3086                 if (q_ptr->type == QUEST_TYPE_KILL_ANY_LEVEL)
3087                 {
3088                         if (q_ptr->r_idx == 0)
3089                         {
3090                                 /* Random monster at least 5 - 10 levels out of deep */
3091                                 q_ptr->r_idx = get_mon_num(q_ptr->level + 4 + randint1(6));
3092                         }
3093
3094                         r_ptr = &r_info[q_ptr->r_idx];
3095
3096                         while ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->rarity != 1))
3097                         {
3098                                 q_ptr->r_idx = get_mon_num(q_ptr->level) + 4 + randint1(6);
3099                                 r_ptr = &r_info[q_ptr->r_idx];
3100                         }
3101
3102                         if (q_ptr->max_num == 0)
3103                         {
3104                                 /* Random monster number */
3105                                 if (randint1(10) > 7)
3106                                         q_ptr->max_num = 1;
3107                                 else
3108                                         q_ptr->max_num = randint1(3) + 1;
3109                         }
3110
3111                         q_ptr->cur_num = 0;
3112                         name = (r_name + r_ptr->name);
3113 #ifdef JP
3114 msg_format("¥¯¥¨¥¹¥È: %s¤ò %dÂÎÅݤ¹", name,q_ptr->max_num);
3115 #else
3116                         msg_format("Your quest: kill %d %s", q_ptr->max_num, name);
3117 #endif
3118
3119                 }
3120                 else
3121                 {
3122                         get_questinfo(q_index, TRUE);
3123                 }
3124         }
3125 }
3126
3127
3128 /*
3129  * Display town history
3130  */
3131 static void town_history(void)
3132 {
3133         /* Save screen */
3134         screen_save();
3135
3136         /* Peruse the building help file */
3137 #ifdef JP
3138 (void)show_file(TRUE, "jbldg.txt", NULL, 0, 0);
3139 #else
3140         (void)show_file(TRUE, "bldg.txt", NULL, 0, 0);
3141 #endif
3142
3143
3144         /* Load screen */
3145         screen_load();
3146 }
3147
3148 /* critical happens at i / 10000 */
3149 s16b calc_crit_ratio_shot(int weight, int plus_ammo, int plus_bow,  int dam)
3150 {
3151         int i;
3152         object_type *j_ptr =  &inventory[INVEN_BOW];
3153         
3154         /* Extract "shot" power */
3155         i = p_ptr->to_h_b + plus_ammo;
3156         
3157         if (p_ptr->tval_ammo == TV_BOLT)
3158                 i = (p_ptr->skill_thb + (p_ptr->weapon_exp[0][j_ptr->sval] / 400 + i) * BTH_PLUS_ADJ);
3159         else
3160                 i = (p_ptr->skill_thb + ((p_ptr->weapon_exp[0][j_ptr->sval] - (WEAPON_EXP_MASTER / 2)) / 200 + i) * BTH_PLUS_ADJ);
3161
3162         /* Snipers can shot more critically with crossbows */
3163         if (p_ptr->concent) i += ((i * p_ptr->concent) / 5);
3164         if ((p_ptr->pclass == CLASS_SNIPER) && (p_ptr->tval_ammo == TV_BOLT)) i *= 2;
3165         
3166         /* Good bow makes more critical */
3167         i += plus_bow * 8 * (p_ptr->concent ? p_ptr->concent + 5 : 5);
3168         
3169         if (i < 0) i = 0;
3170         
3171         return i;
3172 }
3173
3174 s16b calc_expect_crit_shot(int weight, int plus_ammo, int plus_bow,  int dam)
3175 {
3176         u32b num;
3177         int i, k, crit;
3178         i = calc_crit_ratio_shot(weight, plus_ammo, plus_bow, dam);
3179         
3180         k = 0;
3181         num = 0;
3182         
3183         crit = MIN(500, 900/weight);
3184         num += dam * 3 /2 * crit;
3185         k = crit;
3186         
3187         crit = MIN(500, 1350/weight);
3188         crit -= k;
3189         num += dam * 2 * crit;
3190         k += crit;
3191         
3192         if(k < 500)
3193         {
3194                 crit = 500 - k;
3195                 num += dam * 3 * crit;
3196         }
3197         
3198         num /= 500;
3199         
3200         num *= i;
3201         num += (10000 - i) * dam;
3202         num /= 10000;
3203         
3204         return num;
3205 }
3206
3207 s16b calc_expect_crit(int weight, int plus, int dam, s16b meichuu, bool dokubari)
3208 {
3209         u32b k, num;
3210         int i;
3211         
3212         if(dokubari) return dam;
3213         
3214         i = (weight + (meichuu * 3 + plus * 5) + p_ptr->skill_thn);
3215         if (i < 0) i = 0;
3216         
3217         k = weight;
3218         num = 0;
3219         
3220         if (k < 400)                                            num += (2 * dam + 5) * (400 - k);
3221         if (k < 700)                                            num += (2 * dam + 10) * (MIN(700, k + 650) - MAX(400, k));
3222         if (k > (700 - 650) && k < 900)         num += (3 * dam + 15) * (MIN(900, k + 650) - MAX(700, k));
3223         if (k > (900 - 650) && k < 1300)                num += (3 * dam + 20) * (MIN(1300, k + 650) - MAX(900, k));
3224         if (k > (1300 - 650))                                   num += (7 * dam / 2 + 25) * MIN(650, k - (1300 - 650));
3225         
3226         num /= 650;
3227         if(p_ptr->pclass == CLASS_NINJA)
3228         {
3229                 num *= i;
3230                 num += (4444 - i) * dam;
3231                 num /= 4444;
3232         }
3233         else
3234         {
3235                 num *= i;
3236                 num += (5000 - i) * dam;
3237                 num /= 5000;
3238         }
3239         
3240         return num;
3241 }
3242
3243 static s16b calc_slaydam(int dam, int mult, int div, bool force)
3244 {
3245         int tmp;
3246         if(force)
3247         {
3248                 tmp = dam * 60;
3249                 tmp *= mult * 3;
3250                 tmp /= div * 2;
3251                 tmp += dam * 60 * 2;
3252                 tmp /= 60;
3253         }
3254         else
3255         {
3256                 tmp = dam * 60;
3257                 tmp *= mult; 
3258                 tmp /= div;
3259                 tmp /= 60;
3260         }
3261         return tmp;
3262 }
3263
3264 static u32b calc_expect_dice(u32b dam, int mult, int div, bool force, int weight, int plus, s16b meichuu, bool dokubari, int vorpal_mult, int vorpal_div)
3265 {
3266         dam = calc_slaydam(dam, mult, div, force);
3267         dam = calc_expect_crit(weight, plus, dam, meichuu, dokubari);
3268         dam = calc_slaydam(dam, vorpal_mult, vorpal_div, FALSE);
3269         return dam;
3270 }
3271
3272 /*
3273  * Display the damage figure of an object
3274  * (used by compare_weapon_aux)
3275  *
3276  * Only accurate for the current weapon, because it includes
3277  * the current +dam of the player.
3278  */
3279 static void show_weapon_dmg(int r, int c, int mindice, int maxdice, int blows, int dam_bonus, cptr attr, byte color)
3280 {
3281         char tmp_str[80];
3282         int mindam, maxdam;
3283         
3284         mindam = blows * (mindice + dam_bonus);
3285         maxdam = blows * (maxdice + dam_bonus);
3286
3287         /* Print the intro text */
3288         c_put_str(color, attr, r, c);
3289
3290         /* Calculate the min and max damage figures */
3291 #ifdef JP
3292         sprintf(tmp_str, "£±¥¿¡¼¥ó: %d-%d ¥À¥á¡¼¥¸",
3293 #else
3294         sprintf(tmp_str, "Attack: %d-%d damage",
3295 #endif
3296                         mindam, maxdam);
3297         
3298         /* Print the damage */
3299         put_str(tmp_str, r, c + 8);
3300 }
3301
3302
3303 /*
3304  * Show the damage figures for the various monster types
3305  *
3306  * Only accurate for the current weapon, because it includes
3307  * the current number of blows for the player.
3308  */
3309 static void compare_weapon_aux(object_type *o_ptr, int col, int r)
3310 {
3311         u32b flgs[TR_FLAG_SIZE];
3312         int blow = p_ptr->num_blow[0];
3313         bool force = FALSE;
3314         bool dokubari = FALSE;
3315         
3316         /* Effective dices */
3317         int eff_dd = o_ptr->dd + p_ptr->to_dd[0];
3318         int eff_ds = o_ptr->ds + p_ptr->to_ds[0];
3319         
3320         int mindice = eff_dd;
3321         int maxdice = eff_ds * eff_dd;
3322         int mindam = 0;
3323         int maxdam = 0;
3324         int vorpal_mult = 1;
3325         int vorpal_div = 1;
3326         int dmg_bonus = o_ptr->to_d + p_ptr->to_d[0];
3327         
3328
3329         /* Get the flags of the weapon */
3330         object_flags(o_ptr, flgs);
3331         
3332         if((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DOKUBARI)) dokubari = TRUE;
3333         
3334         
3335         /* Show Critical Damage*/
3336         mindam = calc_expect_crit(o_ptr->weight, o_ptr->to_h, mindice, p_ptr->to_h[0], dokubari);
3337         maxdam = calc_expect_crit(o_ptr->weight, o_ptr->to_h, maxdice, p_ptr->to_h[0], dokubari);
3338         
3339         show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus, _("²ñ¿´:", "Critical:"), TERM_L_RED);
3340
3341         
3342         /* Vorpal Hit*/
3343         if ((have_flag(flgs, TR_VORPAL) || hex_spelling(HEX_RUNESWORD)))
3344         {
3345                 if((o_ptr->name1 == ART_VORPAL_BLADE) || (o_ptr->name1 == ART_CHAINSWORD))
3346                 {
3347                         vorpal_mult = 5;
3348                         vorpal_div = 3;
3349                 }
3350                 else
3351                 {
3352                         vorpal_mult = 11;
3353                         vorpal_div = 9;
3354                 }
3355                 
3356                 mindam = calc_expect_dice(mindice, 1, 1, FALSE, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3357                 maxdam = calc_expect_dice(maxdice, 1, 1, FALSE, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);         
3358                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus, _("ÀÚ¤ìÌ£:", "Vorpal:") , TERM_L_RED);
3359         }       
3360         
3361         if ((p_ptr->pclass != CLASS_SAMURAI) && have_flag(flgs, TR_FORCE_WEAPON) && (p_ptr->csp > (o_ptr->dd * o_ptr->ds / 5)))
3362         {
3363                 force = TRUE;
3364                 
3365                 mindam = calc_expect_dice(mindice, 1, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3366                 maxdam = calc_expect_dice(maxdice, 1, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3367                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus, _("ÍýÎÏ:", "Force  :"), TERM_L_BLUE);
3368         }
3369                 
3370         /* Print the relevant lines */
3371         if (have_flag(flgs, TR_KILL_ANIMAL))
3372         {
3373                 mindam = calc_expect_dice(mindice, 4, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3374                 maxdam = calc_expect_dice(maxdice, 4, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);         
3375                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("ưʪ:", "Animals:"), TERM_YELLOW);
3376         }
3377         else if (have_flag(flgs, TR_SLAY_ANIMAL)) 
3378         {
3379                 mindam = calc_expect_dice(mindice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3380                 maxdam = calc_expect_dice(maxdice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3381                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("ưʪ:", "Animals:"), TERM_YELLOW);
3382         }
3383         if (have_flag(flgs, TR_KILL_EVIL))
3384         {       
3385                 mindam = calc_expect_dice(mindice, 7, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3386                 maxdam = calc_expect_dice(maxdice, 7, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3387                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("¼Ù°­:", "Evil:"), TERM_YELLOW);
3388         }
3389         else if (have_flag(flgs, TR_SLAY_EVIL))
3390         {       
3391                 mindam = calc_expect_dice(mindice, 2, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3392                 maxdam = calc_expect_dice(maxdice, 2, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);         
3393                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("¼Ù°­:", "Evil:"), TERM_YELLOW);
3394         }
3395         if (have_flag(flgs, TR_KILL_HUMAN))
3396         {       
3397                 mindam = calc_expect_dice(mindice, 4, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3398                 maxdam = calc_expect_dice(maxdice, 4, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3399                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("¿Í´Ö:", "Human:"), TERM_YELLOW);
3400         }
3401         else if (have_flag(flgs, TR_SLAY_HUMAN))
3402         {       
3403                 mindam = calc_expect_dice(mindice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3404                 maxdam = calc_expect_dice(maxdice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3405                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("¿Í´Ö:", "Human:"), TERM_YELLOW);
3406         }
3407         if (have_flag(flgs, TR_KILL_UNDEAD))
3408         {
3409                 mindam = calc_expect_dice(mindice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3410                 maxdam = calc_expect_dice(maxdice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3411                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("ÉÔ»à:", "Undead:"), TERM_YELLOW);
3412         }
3413         else if (have_flag(flgs, TR_SLAY_UNDEAD)) 
3414         {
3415                 mindam = calc_expect_dice(mindice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3416                 maxdam = calc_expect_dice(maxdice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3417                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("ÉÔ»à:", "Undead:"), TERM_YELLOW);
3418         }
3419         if (have_flag(flgs, TR_KILL_DEMON))
3420         {       
3421                 mindam = calc_expect_dice(mindice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3422                 maxdam = calc_expect_dice(maxdice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3423                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("°­Ëâ:", "Demons:") , TERM_YELLOW);
3424         }
3425         else if (have_flag(flgs, TR_SLAY_DEMON))
3426         {       
3427                 mindam = calc_expect_dice(mindice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3428                 maxdam = calc_expect_dice(maxdice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3429                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus, _("°­Ëâ:", "Demons:") , TERM_YELLOW);
3430         }
3431         if (have_flag(flgs, TR_KILL_ORC))
3432         {
3433                 mindam = calc_expect_dice(mindice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3434                 maxdam = calc_expect_dice(maxdice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3435                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("¥ª¡¼¥¯:", "Orcs:"), TERM_YELLOW);
3436         }
3437         else if (have_flag(flgs, TR_SLAY_ORC))
3438         {
3439                 mindam = calc_expect_dice(mindice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3440                 maxdam = calc_expect_dice(maxdice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3441                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("¥ª¡¼¥¯:", "Orcs:"), TERM_YELLOW);
3442         }
3443         if (have_flag(flgs, TR_KILL_TROLL))
3444         {
3445                 mindam = calc_expect_dice(mindice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3446                 maxdam = calc_expect_dice(maxdice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3447                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("¥È¥í¥ë:", "Trolls:") , TERM_YELLOW);
3448         }
3449         else if (have_flag(flgs, TR_SLAY_TROLL))
3450         {
3451                 mindam = calc_expect_dice(mindice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3452                 maxdam = calc_expect_dice(maxdice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3453                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,   _("¥È¥í¥ë:", "Trolls:") , TERM_YELLOW);
3454         }
3455         if (have_flag(flgs, TR_KILL_GIANT))
3456         {
3457                 mindam = calc_expect_dice(mindice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3458                 maxdam = calc_expect_dice(maxdice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3459                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("µð¿Í:", "Giants:"), TERM_YELLOW);
3460         }
3461         else if (have_flag(flgs, TR_SLAY_GIANT))
3462         {
3463                 mindam = calc_expect_dice(mindice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3464                 maxdam = calc_expect_dice(maxdice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3465                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("µð¿Í:", "Giants:"), TERM_YELLOW);
3466         }
3467         if (have_flag(flgs, TR_KILL_DRAGON))
3468         {
3469                 mindam = calc_expect_dice(mindice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3470                 maxdam = calc_expect_dice(maxdice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3471                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("ε:", "Dragons:"), TERM_YELLOW);
3472         }
3473         else if (have_flag(flgs, TR_SLAY_DRAGON))
3474         {               
3475                 mindam = calc_expect_dice(mindice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3476                 maxdam = calc_expect_dice(maxdice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3477                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,   _("ε:", "Dragons:"), TERM_YELLOW);
3478         }
3479         if (have_flag(flgs, TR_BRAND_ACID))
3480         {
3481                 mindam = calc_expect_dice(mindice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3482                 maxdam = calc_expect_dice(maxdice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3483                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("»À°À­:", "Acid:"), TERM_RED);
3484         }
3485         if (have_flag(flgs, TR_BRAND_ELEC))
3486         {
3487                 mindam = calc_expect_dice(mindice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3488                 maxdam = calc_expect_dice(maxdice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3489                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("ÅÅ°À­:", "Elec:"), TERM_RED);
3490         }
3491         if (have_flag(flgs, TR_BRAND_FIRE))
3492         {
3493                 mindam = calc_expect_dice(mindice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3494                 maxdam = calc_expect_dice(maxdice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3495                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("±ê°À­:", "Fire:"), TERM_RED);
3496         }
3497         if (have_flag(flgs, TR_BRAND_COLD))
3498         {
3499                 mindam = calc_expect_dice(mindice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3500                 maxdam = calc_expect_dice(maxdice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3501                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("Îä°À­:", "Cold:"), TERM_RED);
3502         }
3503         if (have_flag(flgs, TR_BRAND_POIS))
3504         {
3505                 mindam = calc_expect_dice(mindice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3506                 maxdam = calc_expect_dice(maxdice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
3507                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus, _("ÆÇ°À­:", "Poison:"), TERM_RED);
3508         }
3509 }
3510
3511 static int hit_chance(int to_h, int ac)
3512 {
3513         int chance = 0;
3514         int meichuu = p_ptr->skill_thn + (p_ptr->to_h[0] + to_h) * BTH_PLUS_ADJ;
3515
3516         if (meichuu <= 0) return 5;
3517
3518         chance = 100 - ((ac * 75) / meichuu);
3519
3520         if (chance > 95) chance = 95;
3521         if (chance < 5) chance = 5;
3522         if (p_ptr->pseikaku == SEIKAKU_NAMAKE)
3523                 chance = (chance*19+9)/20;
3524         return chance;
3525 }
3526
3527 /*
3528  * Displays all info about a weapon
3529  *
3530  * Only accurate for the current weapon, because it includes
3531  * various info about the player's +to_dam and number of blows.
3532  */
3533 static void list_weapon(object_type *o_ptr, int row, int col)
3534 {
3535         char o_name[MAX_NLEN];
3536         char tmp_str[80];
3537
3538         /* Effective dices */
3539         int eff_dd = o_ptr->dd + p_ptr->to_dd[0];
3540         int eff_ds = o_ptr->ds + p_ptr->to_ds[0];
3541
3542         /* Print the weapon name */
3543         object_desc(o_name, o_ptr, OD_NAME_ONLY);
3544         c_put_str(TERM_YELLOW, o_name, row, col);
3545
3546         /* Print the player's number of blows */
3547 #ifdef JP
3548 sprintf(tmp_str, "¹¶·â²ó¿ô: %d", p_ptr->num_blow[0]);
3549 #else
3550         sprintf(tmp_str, "Number of Blows: %d", p_ptr->num_blow[0]);
3551 #endif
3552
3553         put_str(tmp_str, row+1, col);
3554
3555         /* Print to_hit and to_dam of the weapon */
3556 #ifdef JP
3557 sprintf(tmp_str, "Ì¿ÃæΨ:  0  50 100 150 200 (Ũ¤ÎAC)");
3558 #else
3559 sprintf(tmp_str, "To Hit:  0  50 100 150 200 (AC)");
3560 #endif
3561
3562         put_str(tmp_str, row+2, col);
3563
3564         /* Print the weapons base damage dice */
3565 #ifdef JP
3566 sprintf(tmp_str, "        %2d  %2d  %2d  %2d  %2d (%%)", hit_chance(o_ptr->to_h, 0), hit_chance(o_ptr->to_h, 50), hit_chance(o_ptr->to_h, 100), hit_chance(o_ptr->to_h, 150), hit_chance(o_ptr->to_h, 200));
3567 #else
3568 sprintf(tmp_str, "        %2d  %2d  %2d  %2d  %2d (%%)", hit_chance(o_ptr->to_h, 0), hit_chance(o_ptr->to_h, 50), hit_chance(o_ptr->to_h, 100), hit_chance(o_ptr->to_h, 150), hit_chance(o_ptr->to_h, 200));
3569 #endif
3570
3571         put_str(tmp_str, row+3, col);
3572
3573 #ifdef JP
3574 c_put_str(TERM_YELLOW, "²Äǽ¤Ê¥À¥á¡¼¥¸:", row+5, col);
3575 #else
3576         c_put_str(TERM_YELLOW, "Possible Damage:", row+5, col);
3577 #endif
3578
3579
3580         /* Damage for one blow (if it hits) */
3581 #ifdef JP
3582 sprintf(tmp_str, "¹¶·â°ì²ó¤Ë¤Ä¤­ %d-%d",
3583 #else
3584         sprintf(tmp_str, "One Strike: %d-%d damage",
3585 #endif
3586
3587             eff_dd + o_ptr->to_d + p_ptr->to_d[0],
3588             eff_ds * eff_dd + o_ptr->to_d + p_ptr->to_d[0]);
3589         put_str(tmp_str, row+6, col+1);
3590
3591         /* Damage for the complete attack (if all blows hit) */
3592 #ifdef JP
3593 sprintf(tmp_str, "£±¥¿¡¼¥ó¤Ë¤Ä¤­ %d-%d",
3594 #else
3595         sprintf(tmp_str, "One Attack: %d-%d damage",
3596 #endif
3597
3598             p_ptr->num_blow[0] * (eff_dd + o_ptr->to_d + p_ptr->to_d[0]),
3599             p_ptr->num_blow[0] * (eff_ds * eff_dd + o_ptr->to_d + p_ptr->to_d[0]));
3600         put_str(tmp_str, row+7, col+1);
3601 }
3602
3603
3604 /*
3605  * Hook to specify "weapon"
3606  */
3607 static bool item_tester_hook_melee_weapon(object_type *o_ptr)
3608 {
3609         switch (o_ptr->tval)
3610         {
3611                 case TV_HAFTED:
3612                 case TV_POLEARM:
3613                 case TV_DIGGING:
3614                 {
3615                         return (TRUE);
3616                 }
3617                 case TV_SWORD:
3618                 {
3619                         if (o_ptr->sval != SV_DOKUBARI) return (TRUE);
3620                 }
3621         }
3622
3623         return (FALSE);
3624 }
3625
3626
3627 /*
3628  * Hook to specify "ammo"
3629  */
3630 static bool item_tester_hook_ammo(object_type *o_ptr)
3631 {
3632         switch (o_ptr->tval)
3633         {
3634                 case TV_SHOT:
3635                 case TV_ARROW:
3636                 case TV_BOLT:
3637                 {
3638                         return (TRUE);
3639                 }
3640         }
3641
3642         return (FALSE);
3643 }
3644
3645
3646 /*
3647  * Compare weapons
3648  *
3649  * Copies the weapons to compare into the weapon-slot and
3650  * compares the values for both weapons.
3651  */
3652 static int compare_weapons(int bcost)
3653 {
3654         int i, n;
3655         int item, item2;
3656         object_type *o_ptr[2];
3657         object_type orig_weapon;
3658         object_type *i_ptr;
3659         cptr q, s;
3660         int row = 2;
3661         int wid = 38, mgn = 2;
3662         bool old_character_xtra = character_xtra;
3663         char ch;
3664         int total = 0;
3665         int cost = 0; /* First time no price */
3666
3667         /* Save the screen */
3668         screen_save();
3669
3670         /* Clear the screen */
3671         clear_bldg(0, 22);
3672
3673         /* Store copy of original wielded weapon */
3674         i_ptr = &inventory[INVEN_RARM];
3675         object_copy(&orig_weapon, i_ptr);
3676
3677         /* Only compare melee weapons */
3678         item_tester_no_ryoute = TRUE;
3679         item_tester_hook = item_tester_hook_melee_weapon;
3680
3681         /* Get the first weapon */
3682         q = _("Âè°ì¤ÎÉð´ï¤Ï¡©", "What is your first weapon? ");
3683         s = _("Èæ¤Ù¤ë¤â¤Î¤¬¤¢¤ê¤Þ¤»¤ó¡£", "You have nothing to compare.");
3684
3685         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN)))
3686         {
3687                 screen_load();
3688                 return (0);
3689         }
3690
3691         /* Get the item (in the pack) */
3692         o_ptr[0] = &inventory[item];
3693         n = 1;
3694         total = bcost;
3695
3696         while (TRUE)
3697         {
3698                 /* Clear the screen */
3699                 clear_bldg(0, 22);
3700
3701                 /* Only compare melee weapons */
3702                 item_tester_no_ryoute = TRUE;
3703                 item_tester_hook = item_tester_hook_melee_weapon;
3704
3705                 /* Hack -- prevent "icky" message */
3706                 character_xtra = TRUE;
3707
3708                 /* Diaplay selected weapon's infomation */
3709                 for (i = 0; i < n; i++)
3710                 {
3711                         int col = (wid * i + mgn);
3712
3713                         /* Copy i-th weapon into the weapon slot (if it's not already there) */
3714                         if (o_ptr[i] != i_ptr) object_copy(i_ptr, o_ptr[i]);
3715
3716                         /* Get the new values */
3717                         calc_bonuses();
3718
3719                         /* List the new values */
3720                         list_weapon(o_ptr[i], row, col);
3721                         compare_weapon_aux(o_ptr[i], col, row + 8);
3722
3723                         /* Copy back the original weapon into the weapon slot */
3724                         object_copy(i_ptr, &orig_weapon);
3725                 }
3726
3727                 /* Reset the values for the old weapon */
3728                 calc_bonuses();
3729
3730                 character_xtra = old_character_xtra;
3731
3732 #ifdef JP
3733                 put_str(format("[ Èæ³ÓÂоÝ: 's'¤ÇÊѹ¹ ($%d) ]", cost), 1, (wid + mgn));
3734                 put_str("(°ìÈֹ⤤¥À¥á¡¼¥¸¤¬Å¬ÍѤµ¤ì¤Þ¤¹¡£Ê£¿ô¤ÎÇÜÂǸú²Ì¤Ï­¤·»»¤µ¤ì¤Þ¤»¤ó¡£)", row + 4, 0);
3735                 prt("¸½ºß¤Îµ»Î̤«¤éȽÃǤ¹¤ë¤È¡¢¤¢¤Ê¤¿¤ÎÉð´ï¤Ï°Ê²¼¤Î¤è¤¦¤Ê°ÒÎϤòȯ´ø¤·¤Þ¤¹:", 0, 0);
3736 #else
3737                 put_str(format("[ 's' Select secondary weapon($%d) ]", cost), row + 1, (wid * i + mgn));
3738                 put_str("(Only highest damage applies per monster. Special damage not cumulative.)", row + 4, 0);
3739                 prt("Based on your current abilities, here is what your weapons will do", 0, 0);
3740 #endif
3741
3742                 flush();
3743                 ch = inkey();
3744
3745                 if (ch == 's')
3746                 {
3747                         if (total + cost > p_ptr->au)
3748                         {
3749                                 msg_print(_("¤ª¶â¤¬Â­¤ê¤Þ¤»¤ó¡ª", "You don't have enough money!"));
3750                                 msg_print(NULL);
3751                                 continue;
3752                         }
3753
3754                         q = _("ÂèÆó¤ÎÉð´ï¤Ï¡©", "What is your second weapon? ");
3755                         s = _("Èæ¤Ù¤ë¤â¤Î¤¬¤¢¤ê¤Þ¤»¤ó¡£", "You have nothing to compare.");
3756
3757                         /* Get the second weapon */
3758                         if (!get_item(&item2, q, s, (USE_EQUIP | USE_INVEN))) continue;
3759
3760                         total += cost;
3761                         cost = bcost / 2;
3762
3763                         /* Get the item (in the pack) */
3764                         o_ptr[1] = &inventory[item2];
3765                         n = 2;
3766                 }
3767                 else
3768                 {
3769                         break;
3770                 }
3771         }
3772
3773         /* Restore the screen */
3774         screen_load();
3775
3776         /* Done */
3777         return (total);
3778 }
3779
3780
3781 /*
3782  * Evaluate AC
3783  *
3784  * AC¤«¤é²óÈòΨ¡¢¥À¥á¡¼¥¸¸º¾¯Î¨¤ò·×»»¤·É½¼¨¤¹¤ë
3785  * Calculate and display the dodge-rate and the protection-rate
3786  * based on AC
3787  */
3788 static bool eval_ac(int iAC)
3789 {
3790 #ifdef JP
3791         const char memo[] =
3792                 "¥À¥á¡¼¥¸·Ú¸ºÎ¨¤È¤Ï¡¢Å¨¤Î¹¶·â¤¬Åö¤¿¤Ã¤¿»þ¤½¤Î¥À¥á¡¼¥¸¤ò\n"
3793                 "²¿¥Ñ¡¼¥»¥ó¥È·Ú¸º¤¹¤ë¤«¤ò¼¨¤·¤Þ¤¹¡£\n"
3794                 "¥À¥á¡¼¥¸·Ú¸º¤ÏÄ̾ï¤ÎľÀܹ¶·â(¼ïÎब¡Ö¹¶·â¤¹¤ë¡×¤È¡ÖÊ´ºÕ¤¹¤ë¡×¤Îʪ)\n"
3795                 "¤ËÂФ·¤Æ¤Î¤ß¸ú²Ì¤¬¤¢¤ê¤Þ¤¹¡£\n \n"
3796                 "Ũ¤Î¥ì¥Ù¥ë¤È¤Ï¡¢¤½¤ÎŨ¤¬Ä̾ﲿ³¬¤Ë¸½¤ì¤ë¤«¤ò¼¨¤·¤Þ¤¹¡£\n \n"
3797                 "²óÈòΨ¤ÏŨ¤ÎľÀܹ¶·â¤ò²¿¥Ñ¡¼¥»¥ó¥È¤Î³ÎΨ¤ÇÈò¤±¤ë¤«¤ò¼¨¤·¡¢\n"
3798                 "Ũ¤Î¥ì¥Ù¥ë¤È¤¢¤Ê¤¿¤ÎAC¤Ë¤è¤Ã¤Æ·èÄꤵ¤ì¤Þ¤¹¡£\n \n"
3799                 "¥À¥á¡¼¥¸´üÂÔÃͤȤϡ¢Å¨¤Î£±£°£°¥Ý¥¤¥ó¥È¤ÎÄ̾ﹶ·â¤ËÂФ·¡¢\n"
3800                 "²óÈòΨ¤È¥À¥á¡¼¥¸·Ú¸ºÎ¨¤ò¹Íθ¤·¤¿¥À¥á¡¼¥¸¤Î´üÂÔÃͤò¼¨¤·¤Þ¤¹¡£\n";
3801 #else
3802         const char memo[] =
3803                 "'Protection Rate' means how much damage is reduced by your armor.\n"
3804                 "Note that the Protection rate is effective only against normal "
3805                 "'attack' and 'shatter' type melee attacks, "
3806                 "and has no effect against any other types such as 'poison'.\n \n"
3807                 "'Dodge Rate' indicates the success rate on dodging the "
3808                 "monster's melee attacks.  "
3809                 "It is depend on the level of the monster and your AC.\n \n"
3810                 "'Average Damage' indicates the expected amount of damage "
3811                 "when you are attacked by normal melee attacks with power=100.";
3812 #endif
3813
3814         int protection;
3815         int col, row = 2;
3816         int lvl;
3817         char buf[80*20], *t;
3818
3819         /* AC lower than zero has no effect */
3820         if (iAC < 0) iAC = 0;
3821
3822         /* ¥À¥á¡¼¥¸·Ú¸ºÎ¨¤ò·×»» */
3823         protection = 100 * MIN(iAC, 150) / 250;
3824
3825         screen_save();
3826         clear_bldg(0, 22);
3827
3828 #ifdef JP
3829         put_str(format("¤¢¤Ê¤¿¤Î¸½ºß¤ÎAC: %3d", iAC), row++, 0);
3830         put_str(format("¥À¥á¡¼¥¸·Ú¸ºÎ¨  : %3d%%", protection), row++, 0);
3831         row++;
3832
3833         put_str("Ũ¤Î¥ì¥Ù¥ë      :", row + 0, 0);
3834         put_str("²óÈòΨ          :", row + 1, 0);
3835         put_str("¥À¥á¡¼¥¸´üÂÔÃÍ  :", row + 2, 0);
3836 #else
3837         put_str(format("Your current AC : %3d", iAC), row++, 0);
3838         put_str(format("Protection rate : %3d%%", protection), row++, 0);
3839         row++;
3840
3841         put_str("Level of Monster:", row + 0, 0);
3842         put_str("Dodge Rate      :", row + 1, 0);
3843         put_str("Average Damage  :", row + 2, 0);
3844 #endif
3845     
3846         for (col = 17 + 1, lvl = 0; lvl <= 100; lvl += 10, col += 5)
3847         {
3848                 int quality = 60 + lvl * 3; /* attack quality with power 60 */
3849                 int dodge;   /* ²óÈòΨ(%) */
3850                 int average; /* ¥À¥á¡¼¥¸´üÂÔÃÍ */
3851
3852                 put_str(format("%3d", lvl), row + 0, col);
3853
3854                 /* ²óÈòΨ¤ò·×»» */
3855                 dodge = 5 + (MIN(100, 100 * (iAC * 3 / 4) / quality) * 9 + 5) / 10;
3856                 put_str(format("%3d%%", dodge), row + 1, col);
3857
3858                 /* 100ÅÀ¤Î¹¶·â¤ËÂФ·¤Æ¤Î¥À¥á¡¼¥¸´üÂÔÃͤò·×»» */
3859                 average = (100 - dodge) * (100 - protection) / 100;
3860                 put_str(format("%3d", average), row + 2, col);
3861         }
3862
3863         /* Display note */
3864         roff_to_buf(memo, 70, buf, sizeof(buf));
3865         for (t = buf; t[0]; t += strlen(t) + 1)
3866                 put_str(t, (row++) + 4, 4);
3867
3868 #ifdef JP
3869         prt("¸½ºß¤Î¤¢¤Ê¤¿¤ÎÁõÈ÷¤«¤é¤¹¤ë¤È¡¢¤¢¤Ê¤¿¤ÎËɸæÎϤÏ"
3870                    "¤³¤ì¤¯¤é¤¤¤Ç¤¹:", 0, 0);
3871 #else
3872         prt("Defense abilities from your current Armor Class are evaluated below.", 0, 0);
3873 #endif
3874   
3875         flush();
3876         (void)inkey();
3877         screen_load();
3878
3879         /* Done */
3880         return (TRUE);
3881 }
3882
3883
3884 /*
3885  * Hook to specify "broken weapon"
3886  */
3887 static bool item_tester_hook_broken_weapon(object_type *o_ptr)
3888 {
3889         if (o_ptr->tval != TV_SWORD) return FALSE;
3890
3891         switch (o_ptr->sval)
3892         {
3893         case SV_BROKEN_DAGGER:
3894         case SV_BROKEN_SWORD:
3895                 return TRUE;
3896         }
3897
3898         return FALSE;
3899 }
3900
3901 static void give_one_ability_of_object(object_type *to_ptr, object_type *from_ptr)
3902 {
3903         int i, n = 0;
3904         int cand[TR_FLAG_MAX];
3905         u32b to_flgs[TR_FLAG_SIZE];
3906         u32b from_flgs[TR_FLAG_SIZE];
3907
3908         object_flags(to_ptr, to_flgs);
3909         object_flags(from_ptr, from_flgs);
3910
3911         for (i = 0; i < TR_FLAG_MAX; i++)
3912         {
3913                 switch (i)
3914                 {
3915                 case TR_IGNORE_ACID:
3916                 case TR_IGNORE_ELEC:
3917                 case TR_IGNORE_FIRE:
3918                 case TR_IGNORE_COLD:
3919                 case TR_ACTIVATE:
3920                 case TR_RIDING:
3921                 case TR_THROW:
3922                 case TR_SHOW_MODS:
3923                 case TR_HIDE_TYPE:
3924                 case TR_ES_ATTACK:
3925                 case TR_ES_AC:
3926                 case TR_FULL_NAME:
3927                 case TR_FIXED_FLAVOR:
3928                         break;
3929                 default:
3930                         if (have_flag(from_flgs, i) && !have_flag(to_flgs, i))
3931                         {
3932                                 if (!(is_pval_flag(i) && (from_ptr->pval < 1))) cand[n++] = i;
3933                         }
3934                 }
3935         }
3936
3937         if (n > 0)
3938         {
3939                 int bmax;
3940                 int tr_idx = cand[randint0(n)];
3941                 add_flag(to_ptr->art_flags, tr_idx);
3942                 if (is_pval_flag(tr_idx)) to_ptr->pval = MAX(to_ptr->pval, 1);
3943                 bmax = MIN(3, MAX(1, 40 / (to_ptr->dd * to_ptr->ds)));
3944                 if (tr_idx == TR_BLOWS) to_ptr->pval = MIN(to_ptr->pval, bmax);
3945                 if (tr_idx == TR_SPEED) to_ptr->pval = MIN(to_ptr->pval, 4);
3946         }
3947
3948         return;
3949 }
3950
3951 /*
3952  * Repair broken weapon
3953  */
3954 static int repair_broken_weapon_aux(int bcost)
3955 {
3956         s32b cost;
3957         int item, mater;
3958         object_type *o_ptr, *mo_ptr; /* broken weapon and material weapon */
3959         object_kind *k_ptr;
3960         int i, k_idx, dd_bonus, ds_bonus;
3961         char basenm[MAX_NLEN];
3962         cptr q, s; /* For get_item prompt */
3963         int row = 7;
3964
3965         /* Clear screen */
3966         clear_bldg(0, 22);
3967
3968         /* Notice */
3969         prt(_("½¤Éü¤Ë¤ÏºàÎÁ¤È¤Ê¤ë¤â¤¦1¤Ä¤ÎÉð´ï¤¬É¬ÍפǤ¹¡£", "Hand one material weapon to repair a broken weapon."), row, 2);
3970         prt(_("ºàÎÁ¤Ë»ÈÍѤ·¤¿Éð´ï¤Ï¤Ê¤¯¤Ê¤ê¤Þ¤¹¡ª", "The material weapon will disappear after repairing!!"), row+1, 2);
3971
3972         /* Get an item */
3973         q = _("¤É¤ÎÀޤ줿Éð´ï¤ò½¤Éü¤·¤Þ¤¹¤«¡©", "Repair which broken weapon? ");
3974         s = _("½¤Éü¤Ç¤­¤ëÀޤ줿Éð´ï¤¬¤¢¤ê¤Þ¤»¤ó¡£", "You have no broken weapon to repair.");
3975
3976         /* Only forge broken weapons */
3977         item_tester_hook = item_tester_hook_broken_weapon;
3978
3979         if (!get_item(&item, q, s, (USE_INVEN | USE_EQUIP))) return (0);
3980
3981         /* Get the item (in the pack) */
3982         o_ptr = &inventory[item];
3983
3984         /* It is worthless */
3985         if (!object_is_ego(o_ptr) && !object_is_artifact(o_ptr))
3986         {
3987                 msg_format(_("¤½¤ì¤Ïľ¤·¤Æ¤â¤·¤ç¤¦¤¬¤Ê¤¤¤¼¡£", "It is worthless to repair."));
3988                 return (0);
3989         }
3990
3991         /* They are too many */
3992         if (o_ptr->number > 1)
3993         {
3994                 msg_format(_("°ìÅÙ¤ËÊ£¿ô¤ò½¤Éü¤¹¤ë¤³¤È¤Ï¤Ç¤­¤Þ¤»¤ó¡ª", "They are too many to repair at once!"));
3995                 return (0);
3996         }
3997
3998         /* Display item name */
3999         object_desc(basenm, o_ptr, OD_NAME_ONLY);
4000         prt(format(_("½¤Éü¤¹¤ëÉð´ï¡¡¡§ %s", "Repairing: %s"), basenm), row+3, 2);
4001
4002         /* Get an item */
4003         q = _("ºàÎÁ¤È¤Ê¤ëÉð´ï¤Ï¡©", "Which weapon for material? ");
4004         s = _("ºàÎÁ¤È¤Ê¤ëÉð´ï¤¬¤¢¤ê¤Þ¤»¤ó¡£", "You have no material to repair.");
4005
4006         /* Only forge broken weapons */
4007         item_tester_hook = item_tester_hook_melee_weapon;
4008
4009         if (!get_item(&mater, q, s, (USE_INVEN | USE_EQUIP))) return (0);
4010         if (mater == item)
4011         {
4012                 msg_print(_("¥¯¥é¥¤¥ó¤ÎÄÛ¤¸¤ã¤Ê¤¤¡ª", "This is not a klein bottle!"));
4013                 return (0);
4014         }
4015
4016         /* Get the item (in the pack) */
4017         mo_ptr = &inventory[mater];
4018
4019         /* Display item name */
4020         object_desc(basenm, mo_ptr, OD_NAME_ONLY);
4021         prt(format(_("ºàÎÁ¤È¤¹¤ëÉð´ï¡§ %s", "Material : %s"), basenm), row+4, 2);
4022
4023         /* Get the value of one of the items (except curses) */
4024         cost = bcost + object_value_real(o_ptr) * 2;
4025
4026 #ifdef JP
4027         if (!get_check(format("¡ð%d¤«¤«¤ê¤Þ¤¹¤¬¤è¤í¤·¤¤¤Ç¤¹¤«¡© ", cost))) return (0);
4028 #else
4029         if (!get_check(format("Costs %d gold, okay? ", cost))) return (0);
4030 #endif
4031
4032         /* Check if the player has enough money */
4033         if (p_ptr->au < cost)
4034         {
4035                 object_desc(basenm, o_ptr, OD_NAME_ONLY);
4036                 msg_format(_("%s¤ò½¤Éü¤¹¤ë¤À¤±¤Î¥´¡¼¥ë¥É¤¬¤¢¤ê¤Þ¤»¤ó¡ª",
4037                         "You do not have the gold to repair %s!"), basenm);
4038                 msg_print(NULL);
4039                 return (0);
4040         }
4041
4042         if (o_ptr->sval == SV_BROKEN_DAGGER)
4043         {
4044                 int i, n = 1;
4045
4046                 /* Suppress compiler warning */
4047                 k_idx = 0;
4048
4049                 for (i = 1; i < max_k_idx; i++)
4050                 {
4051                         object_kind *k_ptr = &k_info[i];
4052
4053                         if (k_ptr->tval != TV_SWORD) continue;
4054                         if ((k_ptr->sval == SV_BROKEN_DAGGER) ||
4055                                 (k_ptr->sval == SV_BROKEN_SWORD) ||
4056                                 (k_ptr->sval == SV_DOKUBARI)) continue;
4057                         if (k_ptr->weight > 99) continue;
4058
4059                         if (one_in_(n)) 
4060                         {
4061                                 k_idx = i;
4062                                 n++;
4063                         }
4064                 }
4065         }
4066         else /* TV_BROKEN_SWORD */
4067         {
4068                 /* Repair to a sword or sometimes material's type weapon */
4069                 int tval = (one_in_(5) ? mo_ptr->tval : TV_SWORD);
4070
4071                 while(1)
4072                 {
4073                         object_kind *ck_ptr;
4074
4075                         k_idx = lookup_kind(tval, SV_ANY);
4076                         ck_ptr = &k_info[k_idx];
4077
4078                         if (tval == TV_SWORD)
4079                         {
4080                                 if ((ck_ptr->sval == SV_BROKEN_DAGGER) ||
4081                                         (ck_ptr->sval == SV_BROKEN_SWORD) ||
4082                                         (ck_ptr->sval == SV_DIAMOND_EDGE) ||
4083                                         (ck_ptr->sval == SV_DOKUBARI)) continue;
4084                         }
4085                         if (tval == TV_POLEARM)
4086                         {
4087                                 if ((ck_ptr->sval == SV_DEATH_SCYTHE) ||
4088                                         (ck_ptr->sval == SV_TSURIZAO)) continue;
4089                         }
4090                         if (tval == TV_HAFTED)
4091                         {
4092                                 if ((ck_ptr->sval == SV_GROND) ||
4093                                         (ck_ptr->sval == SV_WIZSTAFF) ||
4094                                         (ck_ptr->sval == SV_NAMAKE_HAMMER)) continue;
4095                         }
4096
4097                         break;
4098                 }
4099         }
4100
4101         /* Calculate dice bonuses */
4102         dd_bonus = o_ptr->dd - k_info[o_ptr->k_idx].dd;
4103         ds_bonus = o_ptr->ds - k_info[o_ptr->k_idx].ds;
4104         dd_bonus += mo_ptr->dd - k_info[mo_ptr->k_idx].dd;
4105         ds_bonus += mo_ptr->ds - k_info[mo_ptr->k_idx].ds;
4106
4107         /* Change base object */
4108         k_ptr = &k_info[k_idx];
4109         o_ptr->k_idx = k_idx;
4110         o_ptr->weight = k_ptr->weight;
4111         o_ptr->tval = k_ptr->tval;
4112         o_ptr->sval = k_ptr->sval;
4113         o_ptr->dd = k_ptr->dd;
4114         o_ptr->ds = k_ptr->ds;
4115
4116         /* Copy base object's ability */
4117         for (i = 0; i < TR_FLAG_SIZE; i++) o_ptr->art_flags[i] |= k_ptr->flags[i];
4118         if (k_ptr->pval) o_ptr->pval = MAX(o_ptr->pval, randint1(k_ptr->pval));
4119         if (have_flag(k_ptr->flags, TR_ACTIVATE)) o_ptr->xtra2 = k_ptr->act_idx;
4120
4121         /* Dice up */
4122         if (dd_bonus > 0)
4123         {
4124                 o_ptr->dd++;
4125                 for (i = 0; i < dd_bonus; i++)
4126                 {
4127                         if (one_in_(o_ptr->dd + i)) o_ptr->dd++;
4128                 }
4129         }
4130         if (ds_bonus > 0)
4131         {
4132                 o_ptr->ds++;
4133                 for (i = 0; i < ds_bonus; i++)
4134                 {
4135                         if (one_in_(o_ptr->ds + i)) o_ptr->ds++;
4136                 }
4137         }
4138
4139         /* */
4140         if (have_flag(k_ptr->flags, TR_BLOWS))
4141         {
4142                 int bmax = MIN(3, MAX(1, 40 / (o_ptr->dd * o_ptr->ds)));
4143                 o_ptr->pval = MIN(o_ptr->pval, bmax);
4144         }
4145
4146         /* Add one random ability from material weapon */
4147         give_one_ability_of_object(o_ptr, mo_ptr);
4148
4149         /* Add to-dam, to-hit and to-ac from material weapon */
4150         o_ptr->to_d += MAX(0, (mo_ptr->to_d / 3));
4151         o_ptr->to_h += MAX(0, (mo_ptr->to_h / 3));
4152         o_ptr->to_a += MAX(0, (mo_ptr->to_a));
4153
4154         if ((o_ptr->name1 == ART_NARSIL) ||
4155                 (object_is_random_artifact(o_ptr) && one_in_(1)) ||
4156                 (object_is_ego(o_ptr) && one_in_(7)))
4157         {
4158                 /* Forge it */
4159                 if (object_is_ego(o_ptr))
4160                 {
4161                         add_flag(o_ptr->art_flags, TR_IGNORE_FIRE);
4162                         add_flag(o_ptr->art_flags, TR_IGNORE_ACID);
4163                 }
4164
4165                 /* Add one random ability from material weapon */
4166                 give_one_ability_of_object(o_ptr, mo_ptr);
4167
4168                 /* Add one random activation */
4169                 if (!activation_index(o_ptr)) one_activation(o_ptr);
4170
4171                 /* Narsil */
4172                 if (o_ptr->name1 == ART_NARSIL)
4173                 {
4174                         one_high_resistance(o_ptr);
4175                         one_ability(o_ptr);
4176                 }
4177
4178                 msg_print(_("¤³¤ì¤Ï¤«¤Ê¤ê¤Î¶Èʪ¤À¤Ã¤¿¤è¤¦¤À¡£", "This blade seems to be exceptionally."));
4179         }
4180
4181         object_desc(basenm, o_ptr, OD_NAME_ONLY);
4182 #ifdef JP
4183         msg_format("¡ð%d¤Ç%s¤Ë½¤Éü¤·¤Þ¤·¤¿¡£", cost, basenm);
4184 #else
4185         msg_format("Repaired into %s for %d gold.", basenm, cost);
4186 #endif
4187         msg_print(NULL);
4188
4189         /* Remove BROKEN flag */
4190         o_ptr->ident &= ~(IDENT_BROKEN);
4191
4192         /* Add repaired flag */
4193         o_ptr->discount = 99;
4194
4195         /* Decrease material object */
4196         inven_item_increase(mater, -1);
4197         inven_item_optimize(mater);
4198
4199         /* Copyback */
4200         p_ptr->update |= PU_BONUS;
4201         handle_stuff();
4202
4203         /* Something happened */
4204         return (cost);
4205 }
4206
4207 static int repair_broken_weapon(int bcost)
4208 {
4209         int cost;
4210
4211         screen_save();
4212         cost = repair_broken_weapon_aux(bcost);
4213         screen_load();
4214         return cost;
4215 }
4216
4217
4218 /*
4219  * Enchant item
4220  */
4221 static bool enchant_item(int cost, int to_hit, int to_dam, int to_ac)
4222 {
4223         int         i, item;
4224         bool        okay = FALSE;
4225         object_type *o_ptr;
4226         cptr        q, s;
4227         int         maxenchant = (p_ptr->lev / 5);
4228         char        tmp_str[MAX_NLEN];
4229
4230         clear_bldg(4, 18);
4231 #ifdef JP
4232         prt(format("¸½ºß¤Î¤¢¤Ê¤¿¤Îµ»Î̤À¤È¡¢+%d ¤Þ¤Ç²þÎɤǤ­¤Þ¤¹¡£", maxenchant), 5, 0);
4233         prt(format(" ²þÎɤÎÎÁ¶â¤Ï°ì¸Ä¤Ë¤Ä¤­¡ð%d ¤Ç¤¹¡£", cost), 7, 0);
4234 #else
4235         prt(format("  Based on your skill, we can improve up to +%d.", maxenchant), 5, 0);
4236         prt(format("  The price for the service is %d gold per item.", cost), 7, 0);
4237 #endif
4238
4239         item_tester_no_ryoute = TRUE;
4240
4241         /* Get an item */
4242 #ifdef JP
4243         q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò²þÎɤ·¤Þ¤¹¤«¡©";
4244         s = "²þÎɤǤ­¤ë¤â¤Î¤¬¤¢¤ê¤Þ¤»¤ó¡£";
4245 #else
4246         q = "Improve which item? ";
4247         s = "You have nothing to improve.";
4248 #endif
4249
4250         if (!get_item(&item, q, s, (USE_INVEN | USE_EQUIP))) return (FALSE);
4251
4252         /* Get the item (in the pack) */
4253         o_ptr = &inventory[item];
4254
4255         /* Check if the player has enough money */
4256         if (p_ptr->au < (cost * o_ptr->number))
4257         {
4258                 object_desc(tmp_str, o_ptr, OD_NAME_ONLY);
4259 #ifdef JP
4260                 msg_format("%s¤ò²þÎɤ¹¤ë¤À¤±¤Î¥´¡¼¥ë¥É¤¬¤¢¤ê¤Þ¤»¤ó¡ª", tmp_str);
4261 #else
4262                 msg_format("You do not have the gold to improve %s!", tmp_str);
4263 #endif
4264
4265                 return (FALSE);
4266         }
4267
4268         /* Enchant to hit */
4269         for (i = 0; i < to_hit; i++)
4270         {
4271                 if (o_ptr->to_h < maxenchant)
4272                 {
4273                         if (enchant(o_ptr, 1, (ENCH_TOHIT | ENCH_FORCE)))
4274                         {
4275                                 okay = TRUE;
4276                                 break;
4277                         }
4278                 }
4279         }
4280
4281         /* Enchant to damage */
4282         for (i = 0; i < to_dam; i++)
4283         {
4284                 if (o_ptr->to_d < maxenchant)
4285                 {
4286                         if (enchant(o_ptr, 1, (ENCH_TODAM | ENCH_FORCE)))
4287                         {
4288                                 okay = TRUE;
4289                                 break;
4290                         }
4291                 }
4292         }
4293
4294         /* Enchant to AC */
4295         for (i = 0; i < to_ac; i++)
4296         {
4297                 if (o_ptr->to_a < maxenchant)
4298                 {
4299                         if (enchant(o_ptr, 1, (ENCH_TOAC | ENCH_FORCE)))
4300                         {
4301                                 okay = TRUE;
4302                                 break;
4303                         }
4304                 }
4305         }
4306
4307         /* Failure */
4308         if (!okay)
4309         {
4310                 /* Flush */
4311                 if (flush_failure) flush();
4312
4313                 /* Message */
4314 #ifdef JP
4315                 msg_print("²þÎɤ˼ºÇÔ¤·¤¿¡£");
4316 #else
4317                 msg_print("The improvement failed.");
4318 #endif
4319
4320                 return (FALSE);
4321         }
4322         else
4323         {
4324                 object_desc(tmp_str, o_ptr, OD_NAME_AND_ENCHANT);
4325 #ifdef JP
4326                 msg_format("¡ð%d¤Ç%s¤Ë²þÎɤ·¤Þ¤·¤¿¡£", cost * o_ptr->number, tmp_str);
4327 #else
4328                 msg_format("Improved into %s for %d gold.", tmp_str, cost * o_ptr->number);
4329 #endif
4330
4331                 /* Charge the money */
4332                 p_ptr->au -= (cost * o_ptr->number);
4333
4334                 if (item >= INVEN_RARM) calc_android_exp();
4335
4336                 /* Something happened */
4337                 return (TRUE);
4338         }
4339 }
4340
4341
4342 /*
4343  * Recharge rods, wands and staves
4344  *
4345  * The player can select the number of charges to add
4346  * (up to a limit), and the recharge never fails.
4347  *
4348  * The cost for rods depends on the level of the rod. The prices
4349  * for recharging wands and staves are dependent on the cost of
4350  * the base-item.
4351  */
4352 static void building_recharge(void)
4353 {
4354         int         item, lev;
4355         object_type *o_ptr;
4356         object_kind *k_ptr;
4357         cptr        q, s;
4358         int         price;
4359         int         charges;
4360         int         max_charges;
4361         char        tmp_str[MAX_NLEN];
4362
4363         msg_flag = FALSE;
4364
4365         /* Display some info */
4366         clear_bldg(4, 18);
4367 #ifdef JP
4368 prt("  ºÆ½¼Å¶¤ÎÈñÍѤϥ¢¥¤¥Æ¥à¤Î¼ïÎà¤Ë¤è¤ê¤Þ¤¹¡£", 6, 0);
4369 #else
4370         prt("  The prices of recharge depend on the type.", 6, 0);
4371 #endif
4372
4373
4374         /* Only accept legal items */
4375         item_tester_hook = item_tester_hook_recharge;
4376
4377         /* Get an item */
4378 #ifdef JP
4379 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ËËâÎϤò½¼Å¶¤·¤Þ¤¹¤«? ";
4380 s = "ËâÎϤò½¼Å¶¤¹¤Ù¤­¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
4381 #else
4382         q = "Recharge which item? ";
4383         s = "You have nothing to recharge.";
4384 #endif
4385
4386         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
4387
4388         /* Get the item (in the pack) */
4389         if (item >= 0)
4390         {
4391                 o_ptr = &inventory[item];
4392         }
4393
4394         /* Get the item (on the floor) */
4395         else
4396         {
4397                 o_ptr = &o_list[0 - item];
4398         }
4399
4400         k_ptr = &k_info[o_ptr->k_idx];
4401
4402         /*
4403          * We don't want to give the player free info about
4404          * the level of the item or the number of charges.
4405          */
4406         /* The item must be "known" */
4407         if (!object_is_known(o_ptr))
4408         {
4409 #ifdef JP
4410 msg_format("½¼Å¶¤¹¤ëÁ°¤Ë´ÕÄꤵ¤ì¤Æ¤¤¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡ª");
4411 #else
4412                 msg_format("The item must be identified first!");
4413 #endif
4414
4415                 msg_print(NULL);
4416
4417                 if ((p_ptr->au >= 50) &&
4418 #ifdef JP
4419 get_check("¡ð50¤Ç´ÕÄꤷ¤Þ¤¹¤«¡© "))
4420 #else
4421                         get_check("Identify for 50 gold? "))
4422 #endif
4423
4424                 {
4425                         /* Pay the price */
4426                         p_ptr->au -= 50;
4427
4428                         /* Identify it */
4429                         identify_item(o_ptr);
4430
4431                         /* Description */
4432                         object_desc(tmp_str, o_ptr, 0);
4433
4434 #ifdef JP
4435 msg_format("%s ¤Ç¤¹¡£", tmp_str);
4436 #else
4437                         msg_format("You have: %s.", tmp_str);
4438 #endif
4439
4440                         /* Auto-inscription */
4441                         autopick_alter_item(item, FALSE);
4442
4443                         /* Update the gold display */
4444                         building_prt_gold();
4445                 }
4446                 else
4447                 {
4448                         return;
4449                 }
4450         }
4451
4452         /* Extract the object "level" */
4453         lev = k_info[o_ptr->k_idx].level;
4454
4455         /* Price for a rod */
4456         if (o_ptr->tval == TV_ROD)
4457         {
4458                 if (o_ptr->timeout > 0)
4459                 {
4460                         /* Fully recharge */
4461                         price = (lev * 50 * o_ptr->timeout) / k_ptr->pval;
4462                 }
4463                 else
4464                 {
4465                         /* No recharge necessary */
4466                         price = 0;
4467 #ifdef JP
4468 msg_format("¤½¤ì¤ÏºÆ½¼Å¶¤¹¤ëɬÍפϤ¢¤ê¤Þ¤»¤ó¡£");
4469 #else
4470                         msg_format("That doesn't need to be recharged.");
4471 #endif
4472
4473                         return;
4474                 }
4475         }
4476         else if (o_ptr->tval == TV_STAFF)
4477         {
4478                 /* Price per charge ( = double the price paid by shopkeepers for the charge) */
4479                 price = (k_info[o_ptr->k_idx].cost / 10) * o_ptr->number;
4480
4481                 /* Pay at least 10 gold per charge */
4482                 price = MAX(10, price);
4483         }
4484         else
4485         {
4486                 /* Price per charge ( = double the price paid by shopkeepers for the charge) */
4487                 price = (k_info[o_ptr->k_idx].cost / 10);
4488
4489                 /* Pay at least 10 gold per charge */
4490                 price = MAX(10, price);
4491         }
4492
4493         /* Limit the number of charges for wands and staffs */
4494         if (o_ptr->tval == TV_WAND
4495                 && (o_ptr->pval / o_ptr->number >= k_ptr->pval))
4496         {
4497                 if (o_ptr->number > 1)
4498                 {
4499 #ifdef JP
4500 msg_print("¤³¤ÎËâË¡ËÀ¤Ï¤â¤¦½¼Ê¬¤Ë½¼Å¶¤µ¤ì¤Æ¤¤¤Þ¤¹¡£");
4501 #else
4502                         msg_print("These wands are already fully charged.");
4503 #endif
4504                 }
4505                 else
4506                 {
4507 #ifdef JP
4508 msg_print("¤³¤ÎËâË¡ËÀ¤Ï¤â¤¦½¼Ê¬¤Ë½¼Å¶¤µ¤ì¤Æ¤¤¤Þ¤¹¡£");
4509 #else
4510                         msg_print("This wand is already fully charged.");
4511 #endif
4512                 }
4513                 return;
4514         }
4515         else if (o_ptr->tval == TV_STAFF && o_ptr->pval >= k_ptr->pval)
4516         {
4517                 if (o_ptr->number > 1)
4518                 {
4519 #ifdef JP
4520 msg_print("¤³¤Î¾ó¤Ï¤â¤¦½¼Ê¬¤Ë½¼Å¶¤µ¤ì¤Æ¤¤¤Þ¤¹¡£");
4521 #else
4522                         msg_print("These staffs are already fully charged.");
4523 #endif
4524                 }
4525                 else
4526                 {
4527 #ifdef JP
4528 msg_print("¤³¤Î¾ó¤Ï¤â¤¦½¼Ê¬¤Ë½¼Å¶¤µ¤ì¤Æ¤¤¤Þ¤¹¡£");
4529 #else
4530                         msg_print("This staff is already fully charged.");
4531 #endif
4532                 }
4533                 return;
4534         }
4535
4536         /* Check if the player has enough money */
4537         if (p_ptr->au < price)
4538         {
4539                 object_desc(tmp_str, o_ptr, OD_NAME_ONLY);
4540 #ifdef JP
4541 msg_format("%s¤òºÆ½¼Å¶¤¹¤ë¤Ë¤Ï¡ð%d É¬ÍפǤ¹¡ª", tmp_str,price );
4542 #else
4543                 msg_format("You need %d gold to recharge %s!", price, tmp_str);
4544 #endif
4545
4546                 return;
4547         }
4548
4549         if (o_ptr->tval == TV_ROD)
4550         {
4551 #ifdef JP
4552 if (get_check(format("¤½¤Î¥í¥Ã¥É¤ò¡ð%d ¤ÇºÆ½¼Å¶¤·¤Þ¤¹¤«¡©",
4553  price)))
4554 #else
4555                 if (get_check(format("Recharge the %s for %d gold? ",
4556                         ((o_ptr->number > 1) ? "rods" : "rod"), price)))
4557 #endif
4558
4559                 {
4560                         /* Recharge fully */
4561                         o_ptr->timeout = 0;
4562                 }
4563                 else
4564                 {
4565                         return;
4566                 }
4567         }
4568         else
4569         {
4570                 if (o_ptr->tval == TV_STAFF)
4571                         max_charges = k_ptr->pval - o_ptr->pval;
4572                 else
4573                         max_charges = o_ptr->number * k_ptr->pval - o_ptr->pval;
4574
4575                 /* Get the quantity for staves and wands */
4576 #ifdef JP
4577 charges = get_quantity(format("°ì²óʬ¡ð%d ¤Ç²¿²óʬ½¼Å¶¤·¤Þ¤¹¤«¡©",
4578 #else
4579                 charges = get_quantity(format("Add how many charges for %d gold? ",
4580 #endif
4581
4582                               price), MIN(p_ptr->au / price, max_charges));
4583
4584                 /* Do nothing */
4585                 if (charges < 1) return;
4586
4587                 /* Get the new price */
4588                 price *= charges;
4589
4590                 /* Recharge */
4591                 o_ptr->pval += charges;
4592
4593                 /* We no longer think the item is empty */
4594                 o_ptr->ident &= ~(IDENT_EMPTY);
4595         }
4596
4597         /* Give feedback */
4598         object_desc(tmp_str, o_ptr, 0);
4599 #ifdef JP
4600 msg_format("%s¤ò¡ð%d ¤ÇºÆ½¼Å¶¤·¤Þ¤·¤¿¡£", tmp_str, price);
4601 #else
4602         msg_format("%^s %s recharged for %d gold.", tmp_str, ((o_ptr->number > 1) ? "were" : "was"), price);
4603 #endif
4604
4605         /* Combine / Reorder the pack (later) */
4606         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
4607
4608         /* Window stuff */
4609         p_ptr->window |= (PW_INVEN);
4610
4611         /* Pay the price */
4612         p_ptr->au -= price;
4613
4614         /* Finished */
4615         return;
4616 }
4617
4618
4619 /*
4620  * Recharge rods, wands and staves
4621  *
4622  * The player can select the number of charges to add
4623  * (up to a limit), and the recharge never fails.
4624  *
4625  * The cost for rods depends on the level of the rod. The prices
4626  * for recharging wands and staves are dependent on the cost of
4627  * the base-item.
4628  */
4629 static void building_recharge_all(void)
4630 {
4631         int         i;
4632         int         lev;
4633         object_type *o_ptr;
4634         object_kind *k_ptr;
4635         int         price = 0;
4636         int         total_cost = 0;
4637
4638
4639         /* Display some info */
4640         msg_flag = FALSE;
4641         clear_bldg(4, 18);
4642 #ifdef JP
4643         prt("  ºÆ½¼Å¶¤ÎÈñÍѤϥ¢¥¤¥Æ¥à¤Î¼ïÎà¤Ë¤è¤ê¤Þ¤¹¡£", 6, 0);
4644 #else
4645         prt("  The prices of recharge depend on the type.", 6, 0);
4646 #endif
4647
4648         /* Calculate cost */
4649         for ( i = 0; i < INVEN_PACK; i++)
4650         {
4651                 o_ptr = &inventory[i];
4652                                 
4653                 /* skip non magic device */
4654                 if (o_ptr->tval < TV_STAFF || o_ptr->tval > TV_ROD) continue;
4655
4656                 /* need identified */
4657                 if (!object_is_known(o_ptr)) total_cost += 50;
4658
4659                 /* Extract the object "level" */
4660                 lev = k_info[o_ptr->k_idx].level;
4661
4662                 k_ptr = &k_info[o_ptr->k_idx];
4663
4664                 switch (o_ptr->tval)
4665                 {
4666                 case TV_ROD:
4667                         price = (lev * 50 * o_ptr->timeout) / k_ptr->pval;
4668                         break;
4669
4670                 case TV_STAFF:
4671                         /* Price per charge ( = double the price paid by shopkeepers for the charge) */
4672                         price = (k_info[o_ptr->k_idx].cost / 10) * o_ptr->number;
4673
4674                         /* Pay at least 10 gold per charge */
4675                         price = MAX(10, price);
4676
4677                         /* Fully charge */
4678                         price = (k_ptr->pval - o_ptr->pval) * price;
4679                         break;
4680
4681                 case TV_WAND:
4682                         /* Price per charge ( = double the price paid by shopkeepers for the charge) */
4683                         price = (k_info[o_ptr->k_idx].cost / 10);
4684
4685                         /* Pay at least 10 gold per charge */
4686                         price = MAX(10, price);
4687
4688                         /* Fully charge */
4689                         price = (o_ptr->number * k_ptr->pval - o_ptr->pval) * price;
4690                         break;
4691                 }
4692
4693                 /* if price <= 0 then item have enough charge */
4694                 if (price > 0) total_cost += price;
4695         }
4696
4697         if (!total_cost)
4698         {
4699 #ifdef JP
4700                 msg_print("½¼Å¶¤¹¤ëɬÍפϤ¢¤ê¤Þ¤»¤ó¡£");
4701 #else
4702                 msg_print("No need to recharge.");
4703 #endif
4704
4705                 msg_print(NULL);
4706                 return;
4707         }
4708
4709         /* Check if the player has enough money */
4710         if (p_ptr->au < total_cost)
4711         {
4712 #ifdef JP
4713                 msg_format("¤¹¤Ù¤Æ¤Î¥¢¥¤¥Æ¥à¤òºÆ½¼Å¶¤¹¤ë¤Ë¤Ï¡ð%d É¬ÍפǤ¹¡ª", total_cost );
4714 #else
4715                 msg_format("You need %d gold to recharge all items!",total_cost);
4716 #endif
4717
4718                 msg_print(NULL);
4719                 return;
4720         }
4721
4722 #ifdef JP
4723         if (!get_check(format("¤¹¤Ù¤Æ¤Î¥¢¥¤¥Æ¥à¤ò ¡ð%d ¤ÇºÆ½¼Å¶¤·¤Þ¤¹¤«¡©",  total_cost))) return;
4724 #else
4725         if (!get_check(format("Recharge all items for %d gold? ", total_cost))) return;
4726 #endif
4727
4728         for (i = 0; i < INVEN_PACK; i++)
4729         {
4730                 o_ptr = &inventory[i];
4731                 k_ptr = &k_info[o_ptr->k_idx];
4732
4733                 /* skip non magic device */
4734                 if (o_ptr->tval < TV_STAFF || o_ptr->tval > TV_ROD) continue;
4735
4736                 /* Identify it */
4737                 if (!object_is_known(o_ptr))
4738                 {
4739                         identify_item(o_ptr);
4740
4741                         /* Auto-inscription */
4742                         autopick_alter_item(i, FALSE);
4743                 }
4744
4745                 /* Recharge */
4746                 switch (o_ptr->tval)
4747                 {
4748                 case TV_ROD:
4749                         o_ptr->timeout = 0;
4750                         break;
4751                 case TV_STAFF:
4752                         if (o_ptr->pval < k_ptr->pval) o_ptr->pval = k_ptr->pval;
4753                         /* We no longer think the item is empty */
4754                         o_ptr->ident &= ~(IDENT_EMPTY);
4755                         break;
4756                 case TV_WAND:
4757                         if (o_ptr->pval < o_ptr->number * k_ptr->pval)
4758                                 o_ptr->pval = o_ptr->number * k_ptr->pval;
4759                         /* We no longer think the item is empty */
4760                         o_ptr->ident &= ~(IDENT_EMPTY);
4761                         break;
4762                 }
4763         }
4764
4765         /* Give feedback */
4766 #ifdef JP
4767         msg_format("¡ð%d ¤ÇºÆ½¼Å¶¤·¤Þ¤·¤¿¡£", total_cost);
4768 #else
4769         msg_format("You pay %d gold.", total_cost);
4770 #endif
4771
4772         msg_print(NULL);
4773
4774         /* Combine / Reorder the pack (later) */
4775         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
4776
4777         /* Window stuff */
4778         p_ptr->window |= (PW_INVEN);
4779
4780         /* Pay the price */
4781         p_ptr->au -= total_cost;
4782
4783         /* Finished */
4784         return;
4785 }
4786
4787
4788 bool tele_town(void)
4789 {
4790         int i, x, y;
4791         int num = 0;
4792
4793         if (dun_level)
4794         {
4795 #ifdef JP
4796                 msg_print("¤³¤ÎËâË¡¤ÏÃϾå¤Ç¤·¤«»È¤¨¤Ê¤¤¡ª");
4797 #else
4798                 msg_print("This spell can only be used on the surface!");
4799 #endif
4800                 return FALSE;
4801         }
4802
4803         if (p_ptr->inside_arena || p_ptr->inside_battle)
4804         {
4805 #ifdef JP
4806                 msg_print("¤³¤ÎËâË¡¤Ï³°¤Ç¤·¤«»È¤¨¤Ê¤¤¡ª");
4807 #else
4808                 msg_print("This spell can only be used outside!");
4809 #endif
4810                 return FALSE;
4811         }
4812
4813         screen_save();
4814         clear_bldg(4, 10);
4815
4816         for (i=1;i<max_towns;i++)
4817         {
4818                 char buf[80];
4819
4820                 if ((i == NO_TOWN) || (i == SECRET_TOWN) || (i == p_ptr->town_num) || !(p_ptr->visit & (1L << (i-1)))) continue;
4821
4822                 sprintf(buf,"%c) %-20s", I2A(i-1), town[i].name);
4823                 prt(buf, 5+i, 5);
4824                 num++;
4825         }
4826
4827         if (!num)
4828         {
4829 #ifdef JP
4830                 msg_print("¤Þ¤À¹Ô¤±¤ë¤È¤³¤í¤¬¤Ê¤¤¡£");
4831 #else
4832                 msg_print("You have not yet visited any town.");
4833 #endif
4834
4835                 msg_print(NULL);
4836                 screen_load();
4837                 return FALSE;
4838         }
4839
4840 #ifdef JP
4841         prt("¤É¤³¤Ë¹Ô¤­¤Þ¤¹¤«:", 0, 0);
4842 #else
4843         prt("Which town you go: ", 0, 0);
4844 #endif
4845         while(1)
4846         {
4847                 i = inkey();
4848
4849                 if (i == ESCAPE)
4850                 {
4851                         screen_load();
4852                         return FALSE;
4853                 }
4854                 else if ((i < 'a') || (i > ('a'+max_towns-2))) continue;
4855                 else if (((i-'a'+1) == p_ptr->town_num) || ((i-'a'+1) == NO_TOWN) || ((i-'a'+1) == SECRET_TOWN) || !(p_ptr->visit & (1L << (i-'a')))) continue;
4856                 break;
4857         }
4858
4859         for (y = 0; y < max_wild_y; y++)
4860         {
4861                 for (x = 0; x < max_wild_x; x++)
4862                 {
4863                         if(wilderness[y][x].town == (i-'a'+1))
4864                         {
4865                                 p_ptr->wilderness_y = y;
4866                                 p_ptr->wilderness_x = x;
4867                         }
4868                 }
4869         }
4870
4871         p_ptr->leaving = TRUE;
4872         leave_bldg = TRUE;
4873         p_ptr->teleport_town = TRUE;
4874         screen_load();
4875         return TRUE;
4876 }
4877
4878
4879 /*
4880  *  research_mon
4881  *  -KMW-
4882  */
4883 static bool research_mon(void)
4884 {
4885         int i, n, r_idx;
4886         char sym, query;
4887         char buf[128];
4888
4889         bool notpicked;
4890
4891         bool recall = FALSE;
4892
4893         u16b why = 0;
4894
4895         u16b    *who;
4896
4897         /* XTRA HACK WHATSEARCH */
4898         bool    all = FALSE;
4899         bool    uniq = FALSE;
4900         bool    norm = FALSE;
4901         char temp[80] = "";
4902
4903         /* XTRA HACK REMEMBER_IDX */
4904         static int old_sym = '\0';
4905         static int old_i = 0;
4906
4907
4908         /* Save the screen */
4909         screen_save();
4910
4911         /* Get a character, or abort */
4912 #ifdef JP
4913 if (!get_com("¥â¥ó¥¹¥¿¡¼¤Îʸ»ú¤òÆþÎϤ·¤Æ²¼¤µ¤¤(µ­¹æ or ^AÁ´,^U¥æ,^NÈó¥æ,^M̾Á°):", &sym, FALSE)) 
4914 #else
4915         if (!get_com("Enter character to be identified(^A:All,^U:Uniqs,^N:Non uniqs,^M:Name): ", &sym, FALSE))
4916 #endif
4917
4918         {
4919                 /* Restore */
4920                 screen_load();
4921
4922                 return (FALSE);
4923         }
4924
4925         /* Find that character info, and describe it */
4926         for (i = 0; ident_info[i]; ++i)
4927         {
4928                 if (sym == ident_info[i][0]) break;
4929         }
4930
4931                 /* XTRA HACK WHATSEARCH */
4932         if (sym == KTRL('A'))
4933         {
4934                 all = TRUE;
4935 #ifdef JP
4936                 strcpy(buf, "Á´¥â¥ó¥¹¥¿¡¼¤Î¥ê¥¹¥È");
4937 #else
4938                 strcpy(buf, "Full monster list.");
4939 #endif
4940         }
4941         else if (sym == KTRL('U'))
4942         {
4943                 all = uniq = TRUE;
4944 #ifdef JP
4945                 strcpy(buf, "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î¥ê¥¹¥È");
4946 #else
4947                 strcpy(buf, "Unique monster list.");
4948 #endif
4949         }
4950         else if (sym == KTRL('N'))
4951         {
4952                 all = norm = TRUE;
4953 #ifdef JP
4954                 strcpy(buf, "¥æ¥Ë¡¼¥¯³°¥â¥ó¥¹¥¿¡¼¤Î¥ê¥¹¥È");
4955 #else
4956                 strcpy(buf, "Non-unique monster list.");
4957 #endif
4958         }
4959         else if (sym == KTRL('M'))
4960         {
4961                 all = TRUE;
4962 #ifdef JP
4963                 if (!get_string("̾Á°(±Ñ¸ì¤Î¾ì¹ç¾®Ê¸»ú¤Ç²Ä)",temp, 70))
4964 #else
4965                 if (!get_string("Enter name:",temp, 70))
4966 #endif
4967                 {
4968                         temp[0]=0;
4969
4970                         /* Restore */
4971                         screen_load();
4972
4973                         return FALSE;
4974                 }
4975 #ifdef JP
4976                 sprintf(buf, "̾Á°:%s¤Ë¥Þ¥Ã¥Á",temp);
4977 #else
4978                 sprintf(buf, "Monsters with a name \"%s\"",temp);
4979 #endif
4980         }
4981         else if (ident_info[i])
4982         {
4983                 sprintf(buf, "%c - %s.", sym, ident_info[i] + 2);
4984         }
4985         else
4986         {
4987 #ifdef JP
4988 sprintf(buf, "%c - %s", sym, "̵¸ú¤Êʸ»ú");
4989 #else
4990                 sprintf(buf, "%c - %s.", sym, "Unknown Symbol");
4991 #endif
4992
4993         }
4994
4995         /* Display the result */
4996         prt(buf, 16, 10);
4997
4998
4999         /* Allocate the "who" array */
5000         C_MAKE(who, max_r_idx, u16b);
5001
5002         /* Collect matching monsters */
5003         for (n = 0, i = 1; i < max_r_idx; i++)
5004         {
5005                 monster_race *r_ptr = &r_info[i];
5006
5007                 /* Empty monster */
5008                 if (!r_ptr->name) continue;
5009
5010                 /* XTRA HACK WHATSEARCH */
5011                 /* Require non-unique monsters if needed */
5012                 if (norm && (r_ptr->flags1 & (RF1_UNIQUE))) continue;
5013
5014                 /* Require unique monsters if needed */
5015                 if (uniq && !(r_ptr->flags1 & (RF1_UNIQUE))) continue;
5016
5017                 /* Ì¾Á°¸¡º÷ */
5018                 if (temp[0])
5019                 {
5020                         int xx;
5021                         char temp2[80];
5022
5023                         for (xx = 0; temp[xx] && xx < 80; xx++)
5024                         {
5025 #ifdef JP
5026                                 if (iskanji(temp[xx]))
5027                                 {
5028                                         xx++;
5029                                         continue;
5030                                 }
5031 #endif
5032                                 if (isupper(temp[xx])) temp[xx] = tolower(temp[xx]);
5033                         }
5034   
5035 #ifdef JP
5036                         strcpy(temp2, r_name + r_ptr->E_name);
5037 #else
5038                         strcpy(temp2, r_name + r_ptr->name);
5039 #endif
5040                         for (xx = 0; temp2[xx] && xx < 80; xx++)
5041                                 if (isupper(temp2[xx])) temp2[xx] = tolower(temp2[xx]);
5042
5043 #ifdef JP
5044                         if (my_strstr(temp2, temp) || my_strstr(r_name + r_ptr->name, temp))
5045 #else
5046                         if (my_strstr(temp2, temp))
5047 #endif
5048                                 who[n++] = i;
5049                 }
5050                 else if (all || (r_ptr->d_char == sym)) who[n++] = i;
5051         }
5052
5053         /* Nothing to recall */
5054         if (!n)
5055         {
5056                 /* Free the "who" array */
5057                 C_KILL(who, max_r_idx, u16b);
5058
5059                 /* Restore */
5060                 screen_load();
5061
5062                 return (FALSE);
5063         }
5064
5065         /* Sort by level */
5066         why = 2;
5067         query = 'y';
5068
5069         /* Sort if needed */
5070         if (why)
5071         {
5072                 /* Select the sort method */
5073                 ang_sort_comp = ang_sort_comp_hook;
5074                 ang_sort_swap = ang_sort_swap_hook;
5075
5076                 /* Sort the array */
5077                 ang_sort(who, &why, n);
5078         }
5079
5080
5081         /* Start at the end */
5082         /* XTRA HACK REMEMBER_IDX */
5083         if (old_sym == sym && old_i < n) i = old_i;
5084         else i = n - 1;
5085
5086         notpicked = TRUE;
5087
5088         /* Scan the monster memory */
5089         while (notpicked)
5090         {
5091                 /* Extract a race */
5092                 r_idx = who[i];
5093
5094                 /* Hack -- Begin the prompt */
5095                 roff_top(r_idx);
5096
5097                 /* Hack -- Complete the prompt */
5098 #ifdef JP
5099 Term_addstr(-1, TERM_WHITE, " ['r'»×¤¤½Ð, ' '¤Ç³¹Ô, ESC]");
5100 #else
5101                 Term_addstr(-1, TERM_WHITE, " [(r)ecall, ESC, space to continue]");
5102 #endif
5103
5104
5105                 /* Interact */
5106                 while (1)
5107                 {
5108                         /* Recall */
5109                         if (recall)
5110                         {
5111                                 /*** Recall on screen ***/
5112
5113                                 /* Get maximal info about this monster */
5114                                 lore_do_probe(r_idx);
5115
5116                                 /* Save this monster ID */
5117                                 monster_race_track(r_idx);
5118
5119                                 /* Hack -- Handle stuff */
5120                                 handle_stuff();
5121
5122                                 /* know every thing mode */
5123                                 screen_roff(r_idx, 0x01);
5124                                 notpicked = FALSE;
5125
5126                                 /* XTRA HACK REMEMBER_IDX */
5127                                 old_sym = sym;
5128                                 old_i = i;
5129                         }
5130
5131                         /* Command */
5132                         query = inkey();
5133
5134                         /* Normal commands */
5135                         if (query != 'r') break;
5136
5137                         /* Toggle recall */
5138                         recall = !recall;
5139                 }
5140
5141                 /* Stop scanning */
5142                 if (query == ESCAPE) break;
5143
5144                 /* Move to "prev" monster */
5145                 if (query == '-')
5146                 {
5147                         if (++i == n)
5148                         {
5149                                 i = 0;
5150                                 if (!expand_list) break;
5151                         }
5152                 }
5153
5154                 /* Move to "next" monster */
5155                 else
5156                 {
5157                         if (i-- == 0)
5158                         {
5159                                 i = n - 1;
5160                                 if (!expand_list) break;
5161                         }
5162                 }
5163         }
5164
5165
5166         /* Re-display the identity */
5167         /* prt(buf, 5, 5);*/
5168
5169         /* Free the "who" array */
5170         C_KILL(who, max_r_idx, u16b);
5171
5172         /* Restore */
5173         screen_load();
5174
5175         return (!notpicked);
5176 }
5177
5178
5179 /*
5180  * Execute a building command
5181  */
5182 static void bldg_process_command(building_type *bldg, int i)
5183 {
5184         int bact = bldg->actions[i];
5185         int bcost;
5186         bool paid = FALSE;
5187         int amt;
5188
5189         /* Flush messages XXX XXX XXX */
5190         msg_flag = FALSE;
5191         msg_print(NULL);
5192
5193         if (is_owner(bldg))
5194                 bcost = bldg->member_costs[i];
5195         else
5196                 bcost = bldg->other_costs[i];
5197
5198         /* action restrictions */
5199         if (((bldg->action_restr[i] == 1) && !is_member(bldg)) ||
5200             ((bldg->action_restr[i] == 2) && !is_owner(bldg)))
5201         {
5202 #ifdef JP
5203 msg_print("¤½¤ì¤òÁªÂò¤¹¤ë¸¢Íø¤Ï¤¢¤ê¤Þ¤»¤ó¡ª");
5204 #else
5205                 msg_print("You have no right to choose that!");
5206 #endif
5207                 return;
5208         }
5209
5210         /* check gold (HACK - Recharge uses variable costs) */
5211         if ((bact != BACT_RECHARGE) &&
5212             (((bldg->member_costs[i] > p_ptr->au) && is_owner(bldg)) ||
5213              ((bldg->other_costs[i] > p_ptr->au) && !is_owner(bldg))))
5214         {
5215 #ifdef JP
5216 msg_print("¤ª¶â¤¬Â­¤ê¤Þ¤»¤ó¡ª");
5217 #else
5218                 msg_print("You do not have the gold!");
5219 #endif
5220                 return;
5221         }
5222
5223         switch (bact)
5224         {
5225         case BACT_NOTHING:
5226                 /* Do nothing */
5227                 break;
5228         case BACT_RESEARCH_ITEM:
5229                 paid = identify_fully(FALSE);
5230                 break;
5231         case BACT_TOWN_HISTORY:
5232                 town_history();
5233                 break;
5234         case BACT_RACE_LEGENDS:
5235                 race_legends();
5236                 break;
5237         case BACT_QUEST:
5238                 castle_quest();
5239                 break;
5240         case BACT_KING_LEGENDS:
5241         case BACT_ARENA_LEGENDS:
5242         case BACT_LEGENDS:
5243                 show_highclass();
5244                 break;
5245         case BACT_POSTER:
5246         case BACT_ARENA_RULES:
5247         case BACT_ARENA:
5248                 arena_comm(bact);
5249                 break;
5250         case BACT_IN_BETWEEN:
5251         case BACT_CRAPS:
5252         case BACT_SPIN_WHEEL:
5253         case BACT_DICE_SLOTS:
5254         case BACT_GAMBLE_RULES:
5255         case BACT_POKER:
5256                 gamble_comm(bact);
5257                 break;
5258         case BACT_REST:
5259         case BACT_RUMORS:
5260         case BACT_FOOD:
5261                 paid = inn_comm(bact);
5262                 break;
5263         case BACT_RESEARCH_MONSTER:
5264                 paid = research_mon();
5265                 break;
5266         case BACT_COMPARE_WEAPONS:
5267                 paid = TRUE;
5268                 bcost = compare_weapons(bcost);
5269                 break;
5270         case BACT_ENCHANT_WEAPON:
5271                 item_tester_hook = object_allow_enchant_melee_weapon;
5272                 enchant_item(bcost, 1, 1, 0);
5273                 break;
5274         case BACT_ENCHANT_ARMOR:
5275                 item_tester_hook = object_is_armour;
5276                 enchant_item(bcost, 0, 0, 1);
5277                 break;
5278         case BACT_RECHARGE:
5279                 building_recharge();
5280                 break;
5281         case BACT_RECHARGE_ALL:
5282                 building_recharge_all();
5283                 break;
5284         case BACT_IDENTS: /* needs work */
5285 #ifdef JP
5286                 if (!get_check("»ý¤Áʪ¤òÁ´¤Æ´ÕÄꤷ¤Æ¤è¤í¤·¤¤¤Ç¤¹¤«¡©")) break;
5287                 identify_pack();
5288                 msg_print(" »ý¤ÁʪÁ´¤Æ¤¬´ÕÄꤵ¤ì¤Þ¤·¤¿¡£");
5289 #else
5290                 if (!get_check("Do you pay for identify all your possession? ")) break;
5291                 identify_pack();
5292                 msg_print("Your possessions have been identified.");
5293 #endif
5294
5295                 paid = TRUE;
5296                 break;
5297         case BACT_IDENT_ONE: /* needs work */
5298                 paid = ident_spell(FALSE);
5299                 break;
5300         case BACT_LEARN:
5301                 do_cmd_study();
5302                 break;
5303         case BACT_HEALING: /* needs work */
5304                 hp_player(200);
5305                 set_poisoned(0);
5306                 set_blind(0);
5307                 set_confused(0);
5308                 set_cut(0);
5309                 set_stun(0);
5310                 paid = TRUE;
5311                 break;
5312         case BACT_RESTORE: /* needs work */
5313                 if (do_res_stat(A_STR)) paid = TRUE;
5314                 if (do_res_stat(A_INT)) paid = TRUE;
5315                 if (do_res_stat(A_WIS)) paid = TRUE;
5316                 if (do_res_stat(A_DEX)) paid = TRUE;
5317                 if (do_res_stat(A_CON)) paid = TRUE;
5318                 if (do_res_stat(A_CHR)) paid = TRUE;
5319                 break;
5320         case BACT_ENCHANT_ARROWS:
5321                 item_tester_hook = item_tester_hook_ammo;
5322                 enchant_item(bcost, 1, 1, 0);
5323                 break;
5324         case BACT_ENCHANT_BOW:
5325                 item_tester_tval = TV_BOW;
5326                 enchant_item(bcost, 1, 1, 0);
5327                 break;
5328         case BACT_RECALL:
5329                 if (recall_player(1)) paid = TRUE;
5330                 break;
5331         case BACT_TELEPORT_LEVEL:
5332         {
5333                 int select_dungeon;
5334                 int max_depth;
5335
5336                 clear_bldg(4, 20);
5337 #ifdef JP
5338                 select_dungeon = choose_dungeon("¤Ë¥Æ¥ì¥Ý¡¼¥È", 4, 0);
5339 #else
5340                 select_dungeon = choose_dungeon("teleport", 4, 0);
5341 #endif
5342                 show_building(bldg);
5343                 if (!select_dungeon) return;
5344
5345                 max_depth = d_info[select_dungeon].maxdepth;
5346
5347                 /* Limit depth in Angband */
5348                 if (select_dungeon == DUNGEON_ANGBAND)
5349                 {
5350                         if (quest[QUEST_OBERON].status != QUEST_STATUS_FINISHED) max_depth = 98;
5351                         else if(quest[QUEST_SERPENT].status != QUEST_STATUS_FINISHED) max_depth = 99;
5352                 }
5353
5354 #ifdef JP
5355                 amt = get_quantity(format("%s¤Î²¿³¬¤Ë¥Æ¥ì¥Ý¡¼¥È¤·¤Þ¤¹¤«¡©", d_name + d_info[select_dungeon].name), max_depth);
5356 #else
5357                 amt = get_quantity(format("Teleport to which level of %s? ", d_name + d_info[select_dungeon].name), max_depth);
5358 #endif
5359
5360                 if (amt > 0)
5361                 {
5362                         p_ptr->word_recall = 1;
5363                         p_ptr->recall_dungeon = select_dungeon;
5364                         max_dlv[p_ptr->recall_dungeon] = ((amt > d_info[select_dungeon].maxdepth) ? d_info[select_dungeon].maxdepth : ((amt < d_info[select_dungeon].mindepth) ? d_info[select_dungeon].mindepth : amt));
5365                         if (record_maxdepth)
5366 #ifdef JP
5367                                 do_cmd_write_nikki(NIKKI_TRUMP, select_dungeon, "¥È¥é¥ó¥×¥¿¥ï¡¼¤Ç");
5368 #else
5369                         do_cmd_write_nikki(NIKKI_TRUMP, select_dungeon, "at Trump Tower");
5370 #endif
5371 #ifdef JP
5372                         msg_print("²ó¤ê¤ÎÂ絤¤¬Ä¥¤ê¤Ä¤á¤Æ¤­¤¿...");
5373 #else
5374                         msg_print("The air about you becomes charged...");
5375 #endif
5376
5377                         paid = TRUE;
5378                         p_ptr->redraw |= (PR_STATUS);
5379                 }
5380                 break;
5381         }
5382         case BACT_LOSE_MUTATION:
5383                 if (p_ptr->muta1 || p_ptr->muta2 ||
5384                     (p_ptr->muta3 & ~MUT3_GOOD_LUCK) ||
5385                     (p_ptr->pseikaku != SEIKAKU_LUCKY &&
5386                      (p_ptr->muta3 & MUT3_GOOD_LUCK)))
5387                 {
5388                         while(!lose_mutation(0));
5389                         paid = TRUE;
5390                 }
5391                 else
5392                 {
5393 #ifdef JP
5394                         msg_print("¼£¤¹¤Ù¤­ÆÍÁ³ÊÑ°Û¤¬Ìµ¤¤¡£");
5395 #else
5396                         msg_print("You have no mutations.");
5397 #endif
5398                         msg_print(NULL);
5399                 }
5400                 break;
5401         case BACT_BATTLE:
5402                 kakutoujou();
5403                 break;
5404         case BACT_TSUCHINOKO:
5405                 tsuchinoko();
5406                 break;
5407         case BACT_KUBI:
5408                 shoukinkubi();
5409                 break;
5410         case BACT_TARGET:
5411                 today_target();
5412                 break;
5413         case BACT_KANKIN:
5414                 kankin();
5415                 break;
5416         case BACT_HEIKOUKA:
5417 #ifdef JP
5418                 msg_print("Ê¿¹Õ²½¤Îµ·¼°¤ò¹Ô¤Ê¤Ã¤¿¡£");
5419 #else
5420                 msg_print("You received an equalization ritual.");
5421 #endif
5422                 set_virtue(V_COMPASSION, 0);
5423                 set_virtue(V_HONOUR, 0);
5424                 set_virtue(V_JUSTICE, 0);
5425                 set_virtue(V_SACRIFICE, 0);
5426                 set_virtue(V_KNOWLEDGE, 0);
5427                 set_virtue(V_FAITH, 0);
5428                 set_virtue(V_ENLIGHTEN, 0);
5429                 set_virtue(V_ENCHANT, 0);
5430                 set_virtue(V_CHANCE, 0);
5431                 set_virtue(V_NATURE, 0);
5432                 set_virtue(V_HARMONY, 0);
5433                 set_virtue(V_VITALITY, 0);
5434                 set_virtue(V_UNLIFE, 0);
5435                 set_virtue(V_PATIENCE, 0);
5436                 set_virtue(V_TEMPERANCE, 0);
5437                 set_virtue(V_DILIGENCE, 0);
5438                 set_virtue(V_VALOUR, 0);
5439                 set_virtue(V_INDIVIDUALISM, 0);
5440                 get_virtues();
5441                 paid = TRUE;
5442                 break;
5443         case BACT_TELE_TOWN:
5444                 paid = tele_town();
5445                 break;
5446         case BACT_EVAL_AC:
5447                 paid = eval_ac(p_ptr->dis_ac + p_ptr->dis_to_a);
5448                 break;
5449         case BACT_BROKEN_WEAPON:
5450                 paid = TRUE;
5451                 bcost = repair_broken_weapon(bcost);
5452                 break;
5453         }
5454
5455         if (paid)
5456         {
5457                 p_ptr->au -= bcost;
5458         }
5459 }
5460
5461
5462 /*
5463  * Enter quest level
5464  */
5465 void do_cmd_quest(void)
5466 {
5467         energy_use = 100;
5468
5469         if (!cave_have_flag_bold(py, px, FF_QUEST_ENTER))
5470         {
5471 #ifdef JP
5472 msg_print("¤³¤³¤Ë¤Ï¥¯¥¨¥¹¥È¤ÎÆþ¸ý¤Ï¤Ê¤¤¡£");
5473 #else
5474                 msg_print("You see no quest level here.");
5475 #endif
5476
5477                 return;
5478         }
5479         else
5480         {
5481 #ifdef JP
5482                 msg_print("¤³¤³¤Ë¤Ï¥¯¥¨¥¹¥È¤Ø¤ÎÆþ¸ý¤¬¤¢¤ê¤Þ¤¹¡£");
5483                 if (!get_check("¥¯¥¨¥¹¥È¤ËÆþ¤ê¤Þ¤¹¤«¡©")) return;
5484                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
5485                         msg_print("¡Ø¤È¤Ë¤«¤¯Æþ¤Ã¤Æ¤ß¤è¤¦¤¼¤§¡£¡Ù");
5486 #else
5487                 msg_print("There is an entry of a quest.");
5488                 if (!get_check("Do you enter? ")) return;
5489 #endif
5490
5491                 /* Player enters a new quest */
5492                 p_ptr->oldpy = 0;
5493                 p_ptr->oldpx = 0;
5494
5495                 leave_quest_check();
5496
5497                 if (quest[p_ptr->inside_quest].type != QUEST_TYPE_RANDOM) dun_level = 1;
5498                 p_ptr->inside_quest = cave[py][px].special;
5499
5500                 p_ptr->leaving = TRUE;
5501         }
5502 }
5503
5504
5505 /*
5506  * Do building commands
5507  */
5508 void do_cmd_bldg(void)
5509 {
5510         int             i, which;
5511         char            command;
5512         bool            validcmd;
5513         building_type   *bldg;
5514
5515
5516         energy_use = 100;
5517
5518         if (!cave_have_flag_bold(py, px, FF_BLDG))
5519         {
5520 #ifdef JP
5521                 msg_print("¤³¤³¤Ë¤Ï·úʪ¤Ï¤Ê¤¤¡£");
5522 #else
5523                 msg_print("You see no building here.");
5524 #endif
5525
5526                 return;
5527         }
5528
5529         which = f_info[cave[py][px].feat].subtype;
5530
5531         bldg = &building[which];
5532
5533         /* Don't re-init the wilderness */
5534         reinit_wilderness = FALSE;
5535
5536         if ((which == 2) && (p_ptr->arena_number < 0))
5537         {
5538 #ifdef JP
5539                 msg_print("¡ÖÇÔ¼Ô¤ËÍѤϤʤ¤¡£¡×");
5540 #else
5541                 msg_print("'There's no place here for a LOSER like you!'");
5542 #endif
5543                 return;
5544         }
5545         else if ((which == 2) && p_ptr->inside_arena)
5546         {
5547                 if (!p_ptr->exit_bldg && m_cnt > 0)
5548                 {
5549 #ifdef JP
5550                         prt("¥²¡¼¥È¤ÏÊĤޤäƤ¤¤ë¡£¥â¥ó¥¹¥¿¡¼¤¬¤¢¤Ê¤¿¤òÂԤäƤ¤¤ë¡ª", 0, 0);
5551 #else
5552                         prt("The gates are closed.  The monster awaits!", 0, 0);
5553 #endif
5554                 }
5555                 else
5556                 {
5557                         /* Don't save the arena as saved floor */
5558                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_NO_RETURN);
5559
5560                         p_ptr->inside_arena = FALSE;
5561                         p_ptr->leaving = TRUE;
5562
5563                         /* Re-enter the arena */
5564                         command_new = SPECIAL_KEY_BUILDING;
5565
5566                         /* No energy needed to re-enter the arena */
5567                         energy_use = 0;
5568                 }
5569
5570                 return;
5571         }
5572         else if (p_ptr->inside_battle)
5573         {
5574                 /* Don't save the arena as saved floor */
5575                 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_NO_RETURN);
5576
5577                 p_ptr->leaving = TRUE;
5578                 p_ptr->inside_battle = FALSE;
5579
5580                 /* Re-enter the monster arena */
5581                 command_new = SPECIAL_KEY_BUILDING;
5582
5583                 /* No energy needed to re-enter the arena */
5584                 energy_use = 0;
5585
5586                 return;
5587         }
5588         else
5589         {
5590                 p_ptr->oldpy = py;
5591                 p_ptr->oldpx = px;
5592         }
5593
5594         /* Forget the lite */
5595         forget_lite();
5596
5597         /* Forget the view */
5598         forget_view();
5599
5600         /* Hack -- Increase "icky" depth */
5601         character_icky++;
5602
5603         command_arg = 0;
5604         command_rep = 0;
5605         command_new = 0;
5606
5607         show_building(bldg);
5608         leave_bldg = FALSE;
5609
5610         while (!leave_bldg)
5611         {
5612                 validcmd = FALSE;
5613                 prt("", 1, 0);
5614
5615                 building_prt_gold();
5616
5617                 command = inkey();
5618
5619                 if (command == ESCAPE)
5620                 {
5621                         leave_bldg = TRUE;
5622                         p_ptr->inside_arena = FALSE;
5623                         p_ptr->inside_battle = FALSE;
5624                         break;
5625                 }
5626
5627                 for (i = 0; i < 8; i++)
5628                 {
5629                         if (bldg->letters[i])
5630                         {
5631                                 if (bldg->letters[i] == command)
5632                                 {
5633                                         validcmd = TRUE;
5634                                         break;
5635                                 }
5636                         }
5637                 }
5638
5639                 if (validcmd)
5640                         bldg_process_command(bldg, i);
5641
5642                 /* Notice stuff */
5643                 notice_stuff();
5644
5645                 /* Handle stuff */
5646                 handle_stuff();
5647         }
5648
5649         /* Flush messages XXX XXX XXX */
5650         msg_flag = FALSE;
5651         msg_print(NULL);
5652
5653         /* Reinit wilderness to activate quests ... */
5654         if (reinit_wilderness)
5655         {
5656                 p_ptr->leaving = TRUE;
5657         }
5658
5659         /* Hack -- Decrease "icky" depth */
5660         character_icky--;
5661
5662         /* Clear the screen */
5663         Term_clear();
5664
5665         /* Update the visuals */
5666         p_ptr->update |= (PU_VIEW | PU_MONSTERS | PU_BONUS | PU_LITE | PU_MON_LITE);
5667
5668         /* Redraw entire screen */
5669         p_ptr->redraw |= (PR_BASIC | PR_EXTRA | PR_EQUIPPY | PR_MAP);
5670
5671         /* Window stuff */
5672         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
5673 }
5674
5675
5676 /* Array of places to find an inscription */
5677 static cptr find_quest[] =
5678 {
5679 #ifdef JP
5680 "¾²¤Ë¥á¥Ã¥»¡¼¥¸¤¬¹ï¤Þ¤ì¤Æ¤¤¤ë:",
5681 #else
5682         "You find the following inscription in the floor",
5683 #endif
5684
5685 #ifdef JP
5686 "Êɤ˥á¥Ã¥»¡¼¥¸¤¬¹ï¤Þ¤ì¤Æ¤¤¤ë:",
5687 #else
5688         "You see a message inscribed in the wall",
5689 #endif
5690
5691 #ifdef JP
5692 "¥á¥Ã¥»¡¼¥¸¤ò¸«¤Ä¤±¤¿:",
5693 #else
5694         "There is a sign saying",
5695 #endif
5696
5697 #ifdef JP
5698 "²¿¤«¤¬³¬Ãʤξå¤Ë½ñ¤¤¤Æ¤¢¤ë:",
5699 #else
5700         "Something is written on the staircase",
5701 #endif
5702
5703 #ifdef JP
5704 "´¬Êª¤ò¸«¤Ä¤±¤¿¡£¥á¥Ã¥»¡¼¥¸¤¬½ñ¤¤¤Æ¤¢¤ë:",
5705 #else
5706         "You find a scroll with the following message",
5707 #endif
5708
5709 };
5710
5711
5712 /*
5713  * Discover quest
5714  */
5715 void quest_discovery(int q_idx)
5716 {
5717         quest_type      *q_ptr = &quest[q_idx];
5718         monster_race    *r_ptr = &r_info[q_ptr->r_idx];
5719         int             q_num = q_ptr->max_num;
5720         char            name[80];
5721
5722         /* No quest index */
5723         if (!q_idx) return;
5724
5725         strcpy(name, (r_name + r_ptr->name));
5726
5727         msg_print(find_quest[rand_range(0, 4)]);
5728         msg_print(NULL);
5729
5730         if (q_num == 1)
5731         {
5732                 /* Unique */
5733
5734                 /* Hack -- "unique" monsters must be "unique" */
5735                 if ((r_ptr->flags1 & RF1_UNIQUE) &&
5736                     (0 == r_ptr->max_num))
5737                 {
5738 #ifdef JP
5739                         msg_print("¤³¤Î³¬¤Ï°ÊÁ°¤Ï狼¤Ë¤è¤Ã¤Æ¼é¤é¤ì¤Æ¤¤¤¿¤è¤¦¤À¡Ä¡£");
5740 #else
5741                         msg_print("It seems that this level was protected by someone before...");
5742 #endif
5743                         /* The unique is already dead */
5744                         quest[q_idx].status = QUEST_STATUS_FINISHED;
5745                         q_ptr->complev = 0;
5746                         update_playtime();
5747                         q_ptr->comptime = playtime;
5748                 }
5749                 else
5750                 {
5751 #ifdef JP
5752                         msg_format("Ãí°Õ¤»¤è¡ª¤³¤Î³¬¤Ï%s¤Ë¤è¤Ã¤Æ¼é¤é¤ì¤Æ¤¤¤ë¡ª", name);
5753 #else
5754                         msg_format("Beware, this level is protected by %s!", name);
5755 #endif
5756                 }
5757         }
5758         else
5759         {
5760                 /* Normal monsters */
5761 #ifdef JP
5762                 msg_format("Ãí°Õ¤·¤í¡ª¤³¤Î³¬¤Ï%dÂΤÎ%s¤Ë¤è¤Ã¤Æ¼é¤é¤ì¤Æ¤¤¤ë¡ª", q_num, name);
5763 #else
5764                 plural_aux(name);
5765                 msg_format("Be warned, this level is guarded by %d %s!", q_num, name);
5766 #endif
5767
5768         }
5769 }
5770
5771
5772 /*
5773  * Hack -- Check if a level is a "quest" level
5774  */
5775 int quest_number(int level)
5776 {
5777         int i;
5778
5779         /* Check quests */
5780         if (p_ptr->inside_quest)
5781                 return (p_ptr->inside_quest);
5782
5783         for (i = 0; i < max_quests; i++)
5784         {
5785                 if (quest[i].status != QUEST_STATUS_TAKEN) continue;
5786
5787                 if ((quest[i].type == QUEST_TYPE_KILL_LEVEL) &&
5788                         !(quest[i].flags & QUEST_FLAG_PRESET) &&
5789                     (quest[i].level == level) &&
5790                     (quest[i].dungeon == dungeon_type))
5791                         return (i);
5792         }
5793
5794         /* Check for random quest */
5795         return (random_quest_number(level));
5796 }
5797
5798
5799 /*
5800  * Return the index of the random quest on this level
5801  * (or zero)
5802  */
5803 int random_quest_number(int level)
5804 {
5805         int i;
5806
5807         if (dungeon_type != DUNGEON_ANGBAND) return 0;
5808
5809         for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
5810         {
5811                 if ((quest[i].type == QUEST_TYPE_RANDOM) &&
5812                     (quest[i].status == QUEST_STATUS_TAKEN) &&
5813                     (quest[i].level == level) &&
5814                     (quest[i].dungeon == DUNGEON_ANGBAND))
5815                 {
5816                         return i;
5817                 }
5818         }
5819
5820         /* Nope */
5821         return 0;
5822 }