OSDN Git Service

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