OSDN Git Service

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