OSDN Git Service

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