OSDN Git Service

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