OSDN Git Service

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