OSDN Git Service

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