OSDN Git Service

[Refactor] #37353 職業ID定義を player-class.h へ移動.
[hengband/hengband.git] / src / bldg.c
1 /*!
2     @file bldg.c
3     @brief 町の施設処理 / Building commands
4     @date 2013/12/23
5     @author
6     Created by Ken Wigle for Kangband - a variant of Angband 2.8.3\n
7     -KMW-\n
8     \n
9     Rewritten for Kangband 2.8.3i using Kamband's version of\n
10     bldg.c as written by Ivan Tkatchev\n
11     \n
12     Changed for ZAngband by Robert Ruehlmann\n
13 */
14
15 #include "angband.h"
16 #include "util.h"
17 #include "term.h"
18
19 #include "core.h"
20 #include "cmd-dump.h"
21 #include "floor.h"
22 #include "floor-events.h"
23 #include "floor-save.h"
24 #include "autopick.h"
25 #include "objectkind.h"
26 #include "object-boost.h"
27 #include "object-flavor.h"
28 #include "object-hook.h"
29 #include "monster.h"
30 #include "monsterrace-hook.h"
31 #include "melee.h"
32 #include "wild.h"
33 #include "world.h"
34 #include "sort.h"
35
36 #include "avatar.h"
37 #include "bldg.h"
38 #include "dungeon.h"
39 #include "mutation.h"
40 #include "quest.h"
41 #include "artifact.h"
42 #include "cmd-spell.h"
43 #include "rumor.h"
44 #include "spells.h"
45 #include "spells-status.h"
46 #include "realm-hex.h"
47 #include "dungeon-file.h"
48
49 #include "files.h"
50 #include "player-status.h"
51 #include "player-effects.h"
52 #include "player-class.h"
53 #include "scores.h"
54 #include "shoot.h"
55 #include "view-mainwindow.h"
56 #include "monsterrace.h"
57 #include "autopick.h"
58
59
60 /*
61  * Buildings
62  */
63 building_type building[MAX_BLDG];
64
65 MONRACE_IDX battle_mon[4];
66 u32b mon_odds[4];
67 int battle_odds;
68 PRICE kakekin;
69 int sel_monster;
70
71 bool reinit_wilderness = FALSE;
72
73 /*!
74  * @brief 闘技場のモンスターID及び報酬アイテムテーブル
75  */
76 const arena_type arena_info[MAX_ARENA_MONS + 2] =
77 {
78         { MON_NOBORTA,       TV_AMULET, SV_AMULET_ADORNMENT           },
79         { MON_MORI_TROLL,    TV_FOOD,   SV_FOOD_PINT_OF_WINE          },
80         { MON_IMP,           TV_POTION, SV_POTION_SPEED               },
81         { MON_LION_HEART,    0,         0                             },
82         { MON_MASTER_YEEK,   TV_POTION, SV_POTION_CURING              },
83         { MON_SABRE_TIGER,   TV_WAND,   SV_WAND_STONE_TO_MUD          },
84         { MON_LIZARD_KING,   TV_WAND,   SV_WAND_TELEPORT_AWAY         },
85         { MON_WYVERN,        TV_POTION, SV_POTION_HEALING             },
86         { MON_ARCH_VILE,     TV_POTION, SV_POTION_RESISTANCE          },
87         { MON_ELF_LORD   ,   TV_POTION, SV_POTION_ENLIGHTENMENT       },
88         { MON_GHOUL_KING,    TV_FOOD,   SV_FOOD_RESTORING             },
89         { MON_COLBRAN,       TV_RING,   SV_RING_ELEC                  },
90         { MON_BICLOPS,       TV_WAND,   SV_WAND_ACID_BALL             },
91         { MON_M_MINDCRAFTER, TV_POTION, SV_POTION_SELF_KNOWLEDGE      },
92         { MON_GROO,          TV_SCROLL, SV_SCROLL_ACQUIREMENT         },
93         { MON_RAAL,          TV_SCROLL, SV_SCROLL_STAR_DESTRUCTION    },
94         { MON_DREADMASTER,   TV_WAND,   SV_WAND_HYPODYNAMIA            },
95         { MON_ULTRA_PALADIN, TV_STAFF,  SV_STAFF_DISPEL_EVIL          },
96         { MON_BARNEY,        TV_RING,   SV_RING_RES_CHAOS             },
97         { MON_TROLL_KING,    TV_SCROLL, SV_SCROLL_MASS_GENOCIDE       },
98         { MON_BARON_HELL,    TV_POTION, SV_POTION_AUGMENTATION        },
99         { MON_F_ANGEL,       TV_SCROLL, SV_SCROLL_RUNE_OF_PROTECTION  },
100         { MON_G_C_DRAKE,     TV_WAND,   SV_WAND_DRAGON_FIRE           },
101         { MON_IRON_LICH,     TV_STAFF,  SV_STAFF_DESTRUCTION          },
102         { MON_DROLEM,        TV_POTION, SV_POTION_STAR_HEALING        },
103         { MON_G_TITAN,       TV_WAND,   SV_WAND_GENOCIDE              },
104         { MON_G_BALROG,      TV_POTION, SV_POTION_EXPERIENCE          },
105         { MON_ELDER_VAMPIRE, TV_RING,   SV_RING_SUSTAIN               },
106         { MON_NIGHTWALKER,   TV_WAND,   SV_WAND_STRIKING              },
107         { MON_S_TYRANNO,     TV_SCROLL, SV_SCROLL_STAR_ACQUIREMENT    },
108         { MON_G_MASTER_MYS,  TV_ROD,    SV_ROD_IDENTIFY               },
109         { MON_LORD_CHAOS,    TV_POTION, SV_POTION_LIFE                },
110         { MON_SHADOWLORD,    TV_POTION, SV_POTION_STAR_ENLIGHTENMENT  },
111         { MON_ULT_BEHOLDER,  TV_AMULET, SV_AMULET_REFLECTION          },
112         { MON_JABBERWOCK,    TV_ROD,    SV_ROD_HEALING                },
113         { MON_LOCKE_CLONE,   TV_WAND,   SV_WAND_DISINTEGRATE          },
114         { MON_WYRM_SPACE,    TV_ROD,    SV_ROD_RESTORATION            },
115         { MON_SHAMBLER,      TV_SCROLL, SV_SCROLL_STAR_ACQUIREMENT    },
116         { MON_BLACK_REAVER,  TV_RING,   SV_RING_LORDLY                },
117         { MON_FENGHUANG,     TV_STAFF,  SV_STAFF_THE_MAGI             },
118         { MON_WYRM_POWER,    TV_SCROLL, SV_SCROLL_ARTIFACT            },
119         { 0,                 0,         0                             }, /* Victory prizing */
120         { MON_HAGURE,        TV_SCROLL, SV_SCROLL_ARTIFACT            },
121 };
122
123 /*!
124  * @brief 施設毎に設定された種族、職業、魔法領域フラグがプレイヤーと一致するかを判定する。
125  * @details 各種ギルドや寺院など、特定の職業ならば優遇措置を得られる施設、
126  * あるいは食堂など特定の種族では利用できない施設の判定処理を行う。
127  * @param bldg 施設構造体の参照ポインタ
128  * @return 種族、職業、魔法領域のいずれかが一致しているかの是非。
129  */
130 static bool is_owner(building_type *bldg)
131 {
132         if (bldg->member_class[p_ptr->pclass] == BUILDING_OWNER)
133         {
134                 return (TRUE);
135         }
136
137         if (bldg->member_race[p_ptr->prace] == BUILDING_OWNER)
138         {
139                 return (TRUE);
140         }
141
142         if ((is_magic(p_ptr->realm1) && (bldg->member_realm[p_ptr->realm1] == BUILDING_OWNER)) ||
143                 (is_magic(p_ptr->realm2) && (bldg->member_realm[p_ptr->realm2] == BUILDING_OWNER)))
144         {
145                 return (TRUE);
146         }
147
148         return (FALSE);
149 }
150
151 /*!
152  * @brief 施設毎に設定された種族、職業、魔法領域フラグがプレイヤーと一致するかを判定する。
153  (スペルマスターの特別判定つき)
154  * @details 各種ギルドや寺院など、特定の職業ならば優遇措置を得られる施設、
155  * あるいは食堂など特定の種族では利用できない施設の判定処理を行う。
156  * @param bldg 施設構造体の参照ポインタ
157  * @return 種族、職業、魔法領域のいずれかが一致しているかの是非。
158  * @todo is_owner()との実質的な多重実装なので、リファクタリングを行うべきである。
159  */
160 static bool is_member(building_type *bldg)
161 {
162         if (bldg->member_class[p_ptr->pclass])
163         {
164                 return (TRUE);
165         }
166
167         if (bldg->member_race[p_ptr->prace])
168         {
169                 return (TRUE);
170         }
171
172         if ((is_magic(p_ptr->realm1) && bldg->member_realm[p_ptr->realm1]) ||
173             (is_magic(p_ptr->realm2) && bldg->member_realm[p_ptr->realm2]))
174         {
175                 return (TRUE);
176         }
177
178
179         if (p_ptr->pclass == CLASS_SORCERER)
180         {
181                 int i;
182                 bool OK = FALSE;
183                 for (i = 0; i < MAX_MAGIC; i++)
184                 {
185                         if (bldg->member_realm[i+1]) OK = TRUE;
186                 }
187                 return OK;
188         }
189         return (FALSE);
190 }
191
192 /*!
193  * @brief コンソールに表示された施設に関する情報を消去する / Clear the building information
194  * @details 消去は行毎にヌル文字列で行われる。
195  * @param min_row 開始行番号
196  * @param max_row 末尾行番号
197  * @return なし
198  */
199 void clear_bldg(int min_row, int max_row)
200 {
201         int   i;
202
203         for (i = min_row; i <= max_row; i++)
204                 prt("", i, 0);
205 }
206
207 /*!
208  * @brief 所持金を表示する。
209  * @return なし
210  */
211 static void building_prt_gold(void)
212 {
213         char tmp_str[80];
214         prt(_("手持ちのお金: ", "Gold Remaining: "), 23,53);
215         sprintf(tmp_str, "%9ld", (long)p_ptr->au);
216         prt(tmp_str, 23, 68);
217 }
218
219 /*!
220  * @brief 施設のサービス一覧を表示する / Display a building.
221  * @param bldg 施設構造体の参照ポインタ
222  * @return なし
223  */
224 static void show_building(building_type* bldg)
225 {
226         char buff[20];
227         int i;
228         byte action_color;
229         char tmp_str[80];
230
231         Term_clear();
232         sprintf(tmp_str, "%s (%s) %35s", bldg->owner_name, bldg->owner_race, bldg->name);
233         prt(tmp_str, 2, 1);
234
235
236         for (i = 0; i < 8; i++)
237         {
238                 if (bldg->letters[i])
239                 {
240                         if (bldg->action_restr[i] == 0)
241                         {
242                                 if ((is_owner(bldg) && (bldg->member_costs[i] == 0)) ||
243                                         (!is_owner(bldg) && (bldg->other_costs[i] == 0)))
244                                 {
245                                         action_color = TERM_WHITE;
246                                         buff[0] = '\0';
247                                 }
248                                 else if (is_owner(bldg))
249                                 {
250                                         action_color = TERM_YELLOW;
251                                         sprintf(buff, _("($%ld)", "(%ldgp)"), (long int)bldg->member_costs[i]);
252                                 }
253                                 else
254                                 {
255                                         action_color = TERM_YELLOW;
256                                         sprintf(buff, _("($%ld)", "(%ldgp)"), (long int)bldg->other_costs[i]);                          }
257                         }
258                         else if (bldg->action_restr[i] == 1)
259                         {
260                                 if (!is_member(bldg))
261                                 {
262                                         action_color = TERM_L_DARK;
263                                         strcpy(buff, _("(閉店)", "(closed)"));
264                                 }
265                                 else if ((is_owner(bldg) && (bldg->member_costs[i] == 0)) ||
266                                         (is_member(bldg) && (bldg->other_costs[i] == 0)))
267                                 {
268                                         action_color = TERM_WHITE;
269                                         buff[0] = '\0';
270                                 }
271                                 else if (is_owner(bldg))
272                                 {
273                                         action_color = TERM_YELLOW;
274                                         sprintf(buff, _("($%ld)", "(%ldgp)"), (long int)bldg->member_costs[i]);
275                                 }
276                                 else
277                                 {
278                                         action_color = TERM_YELLOW;
279                                         sprintf(buff, _("($%ld)", "(%ldgp)"), (long int)bldg->other_costs[i]);
280                                 }
281                         }
282                         else
283                         {
284                                 if (!is_owner(bldg))
285                                 {
286                                         action_color = TERM_L_DARK;
287                                         strcpy(buff, _("(閉店)", "(closed)"));
288                                 }
289                                 else if (bldg->member_costs[i] != 0)
290                                 {
291                                         action_color = TERM_YELLOW;
292                                         sprintf(buff, _("($%ld)", "(%ldgp)"), (long int)bldg->member_costs[i]);
293                                 }
294                                 else
295                                 {
296                                         action_color = TERM_WHITE;
297                                         buff[0] = '\0';
298                                 }
299                         }
300
301                         sprintf(tmp_str," %c) %s %s", bldg->letters[i], bldg->act_names[i], buff);
302                         c_put_str(action_color, tmp_str, 19+(i/2), 35*(i%2));
303                 }
304         }
305         prt(_(" ESC) 建物を出る", " ESC) Exit building"), 23, 0);
306 }
307
308 /*!
309  * @brief 闘技場に入るコマンドの処理 / arena commands
310  * @param cmd 闘技場処理のID
311  * @return なし
312  */
313 static void arena_comm(int cmd)
314 {
315         monster_race    *r_ptr;
316         concptr            name;
317
318
319         switch (cmd)
320         {
321                 case BACT_ARENA:
322                         if (p_ptr->arena_number == MAX_ARENA_MONS)
323                         {
324                                 clear_bldg(5, 19);
325                                 prt(_("アリーナの優勝者!", "               Arena Victor!"), 5, 0);
326                                 prt(_("おめでとう!あなたは全ての敵を倒しました。", "Congratulations!  You have defeated all before you."), 7, 0);
327                                 prt(_("賞金として $1,000,000 が与えられます。", "For that, receive the prize: 1,000,000 gold pieces"), 8, 0);
328
329                                 prt("", 10, 0);
330                                 prt("", 11, 0);
331                                 p_ptr->au += 1000000L;
332                                 msg_print(_("スペースキーで続行", "Press the space bar to continue"));
333                                 msg_print(NULL);
334                                 p_ptr->arena_number++;
335                         }
336                         else if (p_ptr->arena_number > MAX_ARENA_MONS)
337                         {
338                                 if (p_ptr->arena_number < MAX_ARENA_MONS+2)
339                                 {
340                                         msg_print(_("君のために最強の挑戦者を用意しておいた。", "The strongest challenger is waiting for you."));
341                                         msg_print(NULL);
342                                         if (get_check(_("挑戦するかね?", "Do you fight? ")))
343                                         {       
344                                                 msg_print(_("死ぬがよい。", "Die, maggots."));
345                                                 msg_print(NULL);
346                                         
347                                                 p_ptr->exit_bldg = FALSE;
348                                                 reset_tim_flags();
349
350                                                 /* Save the surface floor as saved floor */
351                                                 prepare_change_floor_mode(CFM_SAVE_FLOORS);
352
353                                                 p_ptr->inside_arena = TRUE;
354                                                 p_ptr->leaving = TRUE;
355                                                 p_ptr->leave_bldg = TRUE;
356                                         }
357                                         else
358                                         {
359                                                 msg_print(_("残念だ。", "We are disappointed."));
360                                         }
361                                 }
362                                 else
363                                 {
364                                         msg_print(_("あなたはアリーナに入り、しばらくの間栄光にひたった。",
365                                                                 "You enter the arena briefly and bask in your glory."));
366                                         msg_print(NULL);
367                                 }
368                         }
369                         else if (p_ptr->riding && (p_ptr->pclass != CLASS_BEASTMASTER) && (p_ptr->pclass != CLASS_CAVALRY))
370                         {
371                                 msg_print(_("ペットに乗ったままではアリーナへ入れさせてもらえなかった。",
372                                                         "You don't have permission to enter with pet."));
373                                 msg_print(NULL);
374                         }
375                         else
376                         {
377                                 p_ptr->exit_bldg = FALSE;
378                                 reset_tim_flags();
379
380                                 /* Save the surface floor as saved floor */
381                                 prepare_change_floor_mode(CFM_SAVE_FLOORS);
382
383                                 p_ptr->inside_arena = TRUE;
384                                 p_ptr->leaving = TRUE;
385                                 p_ptr->leave_bldg = TRUE;
386                         }
387                         break;
388                 case BACT_POSTER:
389                         if (p_ptr->arena_number == MAX_ARENA_MONS)
390                                 msg_print(_("あなたは勝利者だ。 アリーナでのセレモニーに参加しなさい。",
391                                                         "You are victorious. Enter the arena for the ceremony."));
392
393                         else if (p_ptr->arena_number > MAX_ARENA_MONS)
394                         {
395                                 msg_print(_("あなたはすべての敵に勝利した。", "You have won against all foes."));
396                         }
397                         else
398                         {
399                                 r_ptr = &r_info[arena_info[p_ptr->arena_number].r_idx];
400                                 name = (r_name + r_ptr->name);
401                                 msg_format(_("%s に挑戦するものはいないか?", "Do I hear any challenges against: %s"), name);
402
403                                 p_ptr->monster_race_idx = arena_info[p_ptr->arena_number].r_idx;
404                                 p_ptr->window |= (PW_MONSTER);
405                                 handle_stuff();
406
407                         }
408                         break;
409                 case BACT_ARENA_RULES:
410                         screen_save();
411
412                         /* Peruse the arena help file */
413                         (void)show_file(TRUE, _("arena_j.txt", "arena.txt"), NULL, 0, 0);
414                         screen_load();
415
416                         break;
417         }
418 }
419
420 /*!
421  * @brief カジノのスロットシンボルを表示する / display fruit for dice slots
422  * @param row シンボルを表示する行の上端
423  * @param col シンボルを表示する行の左端
424  * @param fruit 表示するシンボルID
425  * @return なし
426  */
427 static void display_fruit(int row, int col, int fruit)
428 {
429         switch (fruit)
430         {
431                 case 0: /* lemon */
432                         c_put_str(TERM_YELLOW, "   ####.", row, col);
433                         c_put_str(TERM_YELLOW, "  #    #", row + 1, col);
434                         c_put_str(TERM_YELLOW, " #     #", row + 2, col);
435                         c_put_str(TERM_YELLOW, "#      #", row + 3, col);
436                         c_put_str(TERM_YELLOW, "#      #", row + 4, col);
437                         c_put_str(TERM_YELLOW, "#     # ", row + 5, col);
438                         c_put_str(TERM_YELLOW, "#    #  ", row + 6, col);
439                         c_put_str(TERM_YELLOW, ".####   ", row + 7, col);
440                         prt(                 _(" レモン ",
441                                                            " Lemon  "), row + 8, col);
442                         break;
443                 case 1: /* orange */
444                         c_put_str(TERM_ORANGE, "   ##   ", row, col);
445                         c_put_str(TERM_ORANGE, "  #..#  ", row + 1, col);
446                         c_put_str(TERM_ORANGE, " #....# ", row + 2, col);
447                         c_put_str(TERM_ORANGE, "#......#", row + 3, col);
448                         c_put_str(TERM_ORANGE, "#......#", row + 4, col);
449                         c_put_str(TERM_ORANGE, " #....# ", row + 5, col);
450                         c_put_str(TERM_ORANGE, "  #..#  ", row + 6, col);
451                         c_put_str(TERM_ORANGE, "   ##   ", row + 7, col);
452                         prt(                 _("オレンジ",
453                                                                    " Orange "), row + 8, col);
454                         break;
455                 case 2: /* sword */
456                         c_put_str(TERM_SLATE, _("   Λ   ",  "   /\\   ") , row, col);
457                         c_put_str(TERM_SLATE, _("   ||   ", "   ##   ") , row + 1, col);
458                         c_put_str(TERM_SLATE, _("   ||   ", "   ##   ") , row + 2, col);
459                         c_put_str(TERM_SLATE, _("   ||   ", "   ##   ") , row + 3, col);
460                         c_put_str(TERM_SLATE, _("   ||   ", "   ##   ") , row + 4, col);
461                         c_put_str(TERM_SLATE, _("   ||   ", "   ##   ") , row + 5, col);
462                         c_put_str(TERM_UMBER, _(" |=亜=| ", " ###### ") , row + 6, col);
463                         c_put_str(TERM_UMBER, _("   目   ", "   ##   ") , row + 7, col);
464                         prt(                  _("   剣   ", " Sword  ") , row + 8, col);
465                         break;
466                 case 3: /* shield */
467                         c_put_str(TERM_SLATE, " ###### ", row, col);
468                         c_put_str(TERM_SLATE, "#      #", row + 1, col);
469                         c_put_str(TERM_SLATE, "# ++++ #", row + 2, col);
470                         c_put_str(TERM_SLATE, "# +==+ #", row + 3, col);
471                         c_put_str(TERM_SLATE, "#  ++  #", row + 4, col);
472                         c_put_str(TERM_SLATE, " #    # ", row + 5, col);
473                         c_put_str(TERM_SLATE, "  #  #  ", row + 6, col);
474                         c_put_str(TERM_SLATE, "   ##   ", row + 7, col);
475                         prt(                _("   盾   ",
476                                                                   " Shield "), row + 8, col);
477                         break;
478                 case 4: /* plum */
479                         c_put_str(TERM_VIOLET, "   ##   ", row, col);
480                         c_put_str(TERM_VIOLET, " ###### ", row + 1, col);
481                         c_put_str(TERM_VIOLET, "########", row + 2, col);
482                         c_put_str(TERM_VIOLET, "########", row + 3, col);
483                         c_put_str(TERM_VIOLET, "########", row + 4, col);
484                         c_put_str(TERM_VIOLET, " ###### ", row + 5, col);
485                         c_put_str(TERM_VIOLET, "  ####  ", row + 6, col);
486                         c_put_str(TERM_VIOLET, "   ##   ", row + 7, col);
487                         prt(                 _(" プラム ",
488                                                                    "  Plum  "), row + 8, col);
489                         break;
490                 case 5: /* cherry */
491                         c_put_str(TERM_RED, "      ##", row, col);
492                         c_put_str(TERM_RED, "   ###  ", row + 1, col);
493                         c_put_str(TERM_RED, "  #..#  ", row + 2, col);
494                         c_put_str(TERM_RED, "  #..#  ", row + 3, col);
495                         c_put_str(TERM_RED, " ###### ", row + 4, col);
496                         c_put_str(TERM_RED, "#..##..#", row + 5, col);
497                         c_put_str(TERM_RED, "#..##..#", row + 6, col);
498                         c_put_str(TERM_RED, " ##  ## ", row + 7, col);
499                         prt(              _("チェリー",
500                                                                 " Cherry "), row + 8, col);
501                         break;
502         }
503 }
504
505 /*! @note
506  * kpoker no (tyuto-hannpa na)pakuri desu...
507  * joker ha shineru node haitte masen.
508  *
509  * TODO: donataka! tsukutte!
510  *  - agatta yaku no kiroku (like DQ).
511  *  - kakkoii card no e.
512  *  - sousa-sei no koujyo.
513  *  - code wo wakariyasuku.
514  *  - double up.
515  *  - Joker... -- done.
516  *
517  * 9/13/2000 --Koka
518  * 9/15/2000 joker wo jissou. soreto, code wo sukosi kakikae. --Habu
519  */
520
521 #define SUIT_OF(card)  ((card) / 13) /*!< トランプカードのスートを返す */
522 #define NUM_OF(card)   ((card) % 13) /*!< トランプカードの番号を返す */
523 #define IS_JOKER(card) ((card) == 52) /*!< トランプカードがジョーカーかどうかを返す */
524
525 static int cards[5]; /*!< ポーカーの現在の手札ID */
526
527 /*!
528  * @brief ポーカーの山札を切る。
529  * @param deck デッキの配列
530  * @return なし
531  */
532 static void reset_deck(int deck[])
533 {
534         int i;
535         for (i = 0; i < 53; i++) deck[i] = i;
536
537         /* shuffle cards */
538         for (i = 0; i < 53; i++){
539                 int tmp1 = randint0(53 - i) + i;
540                 int tmp2 = deck[i];
541                 deck[i] = deck[tmp1];
542                 deck[tmp1] = tmp2;
543         }
544 }
545
546 /*!
547  * @brief ポーカープレイ中にジョーカーを持っているかの判定を返す。
548  * @return ジョーカーを持っているか。
549  */
550 static bool have_joker(void)
551 {
552         int i;
553
554         for (i = 0; i < 5; i++){
555           if(IS_JOKER(cards[i])) return TRUE;
556         }
557         return FALSE;
558 }
559
560 /*!
561  * @brief ポーカーの手札に該当の番号の札があるかを返す。
562  * @param num 探したいカードの番号。
563  * @return 該当の番号が手札にあるか。
564  */
565 static bool find_card_num(int num)
566 {
567         int i;
568         for (i = 0; i < 5; i++)
569                 if (NUM_OF(cards[i]) == num && !IS_JOKER(cards[i])) return TRUE;
570         return FALSE;
571 }
572
573 /*!
574  * @brief ポーカーの手札がフラッシュ役を得ているかを帰す。
575  * @return 役の判定結果
576  */
577 static bool yaku_check_flush(void)
578 {
579         int i, suit;
580         bool joker_is_used = FALSE;
581
582         suit = IS_JOKER(cards[0]) ? SUIT_OF(cards[1]) : SUIT_OF(cards[0]);
583         for (i = 0; i < 5; i++){
584                 if (SUIT_OF(cards[i]) != suit){
585                   if(have_joker() && !joker_is_used)
586                     joker_is_used = TRUE;
587                   else
588                     return FALSE;
589                 }
590         }
591
592         return TRUE;
593 }
594
595 /*!
596  * @brief ポーカーの手札がストレートを含んだ高位の役を得ているかを帰す。
597  * @return 役の判定結果 0…ストレート、フラッシュいずれもなし/1…ストレートのみ/2…ストレートフラッシュ/3…ロイヤルストレートフラッシュ
598  */
599 static int yaku_check_straight(void)
600 {
601         int i, lowest = 99;
602         bool joker_is_used = FALSE;
603         bool straight = FALSE;
604
605         /* get lowest */
606         for (i = 0; i < 5; i++)
607         {
608                 if (NUM_OF(cards[i]) < lowest && !IS_JOKER(cards[i]))
609                         lowest = NUM_OF(cards[i]);
610         }
611         
612         /* Check Royal Straight Flush */
613         if (yaku_check_flush())
614         {
615           if( lowest == 0 ){
616                 for (i = 0; i < 4; i++)
617                 {
618                         if (!find_card_num(9 + i)){
619                                 if( have_joker() && !joker_is_used )
620                                   joker_is_used = TRUE;
621                                 else
622                                   break;
623                         }
624                 }
625                 if (i == 4) return 3; /* Wow! Royal Straight Flush!!! */
626           }
627           if(lowest == 9){
628                 for (i = 0; i < 3; i++)
629                 {
630                         if (!find_card_num(10 + i))
631                                 break;
632                 }
633                 if (i == 3 && have_joker()) return 3; /* Wow! Royal Straight Flush!!! */
634           }
635         }
636
637         joker_is_used = FALSE;
638
639         /* Straight Only Check */
640
641         if (lowest == 0) { /* (10 - J - Q - K)[JOKER] - A */
642                 for (i = 0; i < 4; i++)
643                 {
644                         if (!find_card_num(9 + i)) {
645                                 if (have_joker() && !joker_is_used)
646                                         joker_is_used = TRUE;
647                                 else
648                                         break; /* None */
649                         }
650                 }
651                 if(i == 4) straight = TRUE;
652         }
653
654         joker_is_used = FALSE;
655
656         for (i = 0; i < 5; i++)
657         {
658                 if(!find_card_num(lowest + i)){
659                         if( have_joker() && !joker_is_used )
660                                 joker_is_used = TRUE;
661                         else
662                                 break; /* None */
663                 }
664         }
665         if(i == 5) straight = TRUE;
666         
667         if (straight && yaku_check_flush()) return 2; /* Straight Flush */
668         else if(straight) return 1; /* Only Straight */
669         else return 0;
670 }
671
672 /*!
673  * @brief ポーカーのペア役の状態を返す。
674  * @return 0:nopair 1:1 pair 2:2 pair 3:3 cards 4:full house 6:4cards
675  */
676 static int yaku_check_pair(void)
677 {
678         int i, i2, matching = 0;
679
680         for (i = 0; i < 5; i++)
681         {
682                 for (i2 = i+1; i2 < 5; i2++)
683                 {
684                         if (IS_JOKER(cards[i]) || IS_JOKER(cards[i2])) continue;
685                         if (NUM_OF(cards[i]) == NUM_OF(cards[i2]))
686                                 matching++;
687                 }
688         }
689
690         if(have_joker()){
691           switch(matching){
692           case 0:
693             matching = 1;
694             break;
695           case 1:
696             matching = 3;
697             break;
698           case 2:
699             matching = 4;
700             break;
701           case 3:
702             matching = 6;
703             break;
704           case 6:
705             matching = 7;
706             break;
707           default:
708             /* don't reach */
709             break;
710           }
711         }
712
713         return matching;
714 }
715
716 #define ODDS_5A 3000 /*!< ファイブエースの役倍率 */
717 #define ODDS_5C 400 /*!< ファイブカードの役倍率 */
718 #define ODDS_RF 200 /*!< ロイヤルストレートフラッシュの役倍率 */
719 #define ODDS_SF 80 /*!< ストレートフラッシュの役倍率 */
720 #define ODDS_4C 16 /*!< フォアカードの役倍率 */
721 #define ODDS_FH 12 /*!< フルハウスの役倍率 */
722 #define ODDS_FL 8 /*!< フラッシュの役倍率 */
723 #define ODDS_ST 4 /*!< ストレートの役倍率 */
724 #define ODDS_3C 1 /*!< スリーカードの役倍率 */
725 #define ODDS_2P 1 /*!< ツーペアの役倍率 */
726
727 /*!
728  * @brief ポーカーの役をチェックし、その結果を画面に表示しつつ結果を返す。
729  * @return 役のID
730  */
731 static int yaku_check(void)
732 {
733         prt("                            ", 4, 3);
734
735         switch(yaku_check_straight()){
736         case 3: /* RF! */
737                 c_put_str(TERM_YELLOW, _("ロイヤルストレートフラッシュ", "Royal Flush"),  4,  3);
738                 return ODDS_RF;
739         case 2: /* SF! */
740                 c_put_str(TERM_YELLOW, _("ストレートフラッシュ", "Straight Flush"),  4,  3);
741                 return ODDS_SF;
742         case 1:
743                 c_put_str(TERM_YELLOW, _("ストレート", "Straight"),  4,  3);
744                 return ODDS_ST;
745         default:
746                 /* Not straight -- fall through */
747                 break;
748         }
749
750         if (yaku_check_flush())
751         {
752                 c_put_str(TERM_YELLOW, _("フラッシュ", "Flush"),  4,  3);
753                 return ODDS_FL;
754         }
755
756         switch (yaku_check_pair())
757         {
758         case 1:
759                 c_put_str(TERM_YELLOW, _("ワンペア", "One pair"),  4,  3);
760                 return 0;
761         case 2:
762                 c_put_str(TERM_YELLOW, _("ツーペア", "Two pair"),  4,  3);
763                 return ODDS_2P;
764         case 3:
765                 c_put_str(TERM_YELLOW, _("スリーカード", "Three of a kind"),  4,  3);
766                 return ODDS_3C;
767         case 4:
768                 c_put_str(TERM_YELLOW, _("フルハウス", "Full house"),  4,  3);
769                 return ODDS_FH;
770         case 6:
771                 c_put_str(TERM_YELLOW, _("フォーカード", "Four of a kind"),  4,  3);
772                 return ODDS_4C;
773         case 7:
774                 if (!NUM_OF(cards[0]) && !NUM_OF(cards[1]))
775                 {
776                         c_put_str(TERM_YELLOW, _("ファイブエース", "Five ace"),  4,  3);
777                         return ODDS_5A;
778                 }
779                 else
780                 {
781                         c_put_str(TERM_YELLOW, _("ファイブカード", "Five of a kind"),  4,  3);
782                         return ODDS_5C;
783                 }
784         default:
785                 break;
786         }
787         return 0;
788 }
789
790 /*!
791  * @brief ポーカーの捨てる/残すインターフェイスの表示を更新する。
792  * @param hoge カーソルの現在位置
793  * @param kaeruka カードの捨てる/残すフラグ配列
794  * @return なし
795  */
796 static void display_kaeruka(int hoge, int kaeruka[])
797 {
798         int i;
799         char col = TERM_WHITE;
800         for (i = 0; i < 5; i++)
801         {
802                 if (i == hoge) col = TERM_YELLOW;
803                 else if(kaeruka[i]) col = TERM_WHITE;
804                 else col = TERM_L_BLUE;
805                 
806                 if(kaeruka[i])
807                         c_put_str(col, _("かえる", "Change"), 14,  5+i*16);
808                 else
809                         c_put_str(col, _("のこす", " Stay "), 14,  5+i*16);
810         }
811         if (hoge > 4) col = TERM_YELLOW;
812         else col = TERM_WHITE;
813         c_put_str(col, _("決定", "Sure"), 16,  38);
814
815         /* Hilite current option */
816         if (hoge < 5) move_cursor(14, 5+hoge*16);
817         else move_cursor(16, 38);
818 }
819
820 /*!
821  * @brief ポーカーの手札を表示する。
822  * @return なし
823  */
824 static void display_cards(void)
825 {
826         int i, j;
827         char suitcolor[4] = {TERM_YELLOW, TERM_L_RED, TERM_L_BLUE, TERM_L_GREEN};
828 #ifdef JP
829         concptr suit[4] = {"★", "●", "¶", "†"};
830         concptr card_grph[13][7] = {{"A   %s     ",
831                                   "     変     ",
832                                   "     愚     ",
833                                   "     蛮     ",
834                                   "     怒     ",
835                                   "     %s     ",
836                                   "          A"},
837                                  {"2          ",
838                                   "     %s     ",
839                                   "            ",
840                                   "            ",
841                                   "            ",
842                                   "     %s     ",
843                                   "          2"},
844                                  {"3          ",
845                                   "     %s     ",
846                                   "            ",
847                                   "     %s     ",
848                                   "            ",
849                                   "     %s     ",
850                                   "          3"},
851                                  {"4          ",
852                                   "   %s  %s   ",
853                                   "            ",
854                                   "            ",
855                                   "            ",
856                                   "   %s  %s   ",
857                                   "          4"},
858                                  {"5          ",
859                                   "   %s  %s   ",
860                                   "            ",
861                                   "     %s     ",
862                                   "            ",
863                                   "   %s  %s   ",
864                                   "          5"},
865                                  {"6          ",
866                                   "   %s  %s   ",
867                                   "            ",
868                                   "   %s  %s   ",
869                                   "            ",
870                                   "   %s  %s   ",
871                                   "          6"},
872                                  {"7          ",
873                                   "   %s  %s   ",
874                                   "     %s     ",
875                                   "   %s  %s   ",
876                                   "            ",
877                                   "   %s  %s   ",
878                                   "          7"},
879                                  {"8          ",
880                                   "   %s  %s   ",
881                                   "     %s     ",
882                                   "   %s  %s   ",
883                                   "     %s     ",
884                                   "   %s  %s   ",
885                                   "          8"},
886                                  {"9 %s  %s   ",
887                                   "            ",
888                                   "   %s  %s   ",
889                                   "     %s     ",
890                                   "   %s  %s   ",
891                                   "            ",
892                                   "   %s  %s 9"},
893                                  {"10 %s  %s   ",
894                                   "     %s     ",
895                                   "   %s  %s   ",
896                                   "            ",
897                                   "   %s  %s   ",
898                                   "     %s     ",
899                                   "   %s  %s 10"},
900                                  {"J   Λ     ",
901                                   "%s   ||     ",
902                                   "     ||     ",
903                                   "     ||     ",
904                                   "     ||     ",
905                                   "   |=亜=| %s",
906                                   "     目   J"},
907                                  {"Q ######   ",
908                                   "%s#      #  ",
909                                   "  # ++++ #  ",
910                                   "  # +==+ #  ",
911                                   "   # ++ #   ",
912                                   "    #  #  %s",
913                                   "     ##   Q"},
914                                  {"K          ",
915                                   "%s `⌒´   ",
916                                   "  γγγλ  ",
917                                   "  ο ο ι  ",
918                                   "   υ    ∂ ",
919                                   "    σ ノ %s",
920                                   "          K"}};
921         concptr joker_grph[7] = {    "            ",
922                                   "     J     ",
923                                   "     O     ",
924                                   "     K     ",
925                                   "     E     ",
926                                   "     R     ",
927                                   "            "};
928
929 #else
930
931         concptr suit[4] = {"[]", "qp", "<>", "db"};
932         concptr card_grph[13][7] = {{"A    %s     ",
933                                   "     He     ",
934                                   "     ng     ",
935                                   "     ba     ",
936                                   "     nd     ",
937                                   "     %s     ",
938                                   "           A"},
939                                  {"2           ",
940                                   "     %s     ",
941                                   "            ",
942                                   "            ",
943                                   "            ",
944                                   "     %s     ",
945                                   "           2"},
946                                  {"3           ",
947                                   "     %s     ",
948                                   "            ",
949                                   "     %s     ",
950                                   "            ",
951                                   "     %s     ",
952                                   "           3"},
953                                  {"4           ",
954                                   "   %s  %s   ",
955                                   "            ",
956                                   "            ",
957                                   "            ",
958                                   "   %s  %s   ",
959                                   "           4"},
960                                  {"5           ",
961                                   "   %s  %s   ",
962                                   "            ",
963                                   "     %s     ",
964                                   "            ",
965                                   "   %s  %s   ",
966                                   "           5"},
967                                  {"6           ",
968                                   "   %s  %s   ",
969                                   "            ",
970                                   "   %s  %s   ",
971                                   "            ",
972                                   "   %s  %s   ",
973                                   "           6"},
974                                  {"7           ",
975                                   "   %s  %s   ",
976                                   "     %s     ",
977                                   "   %s  %s   ",
978                                   "            ",
979                                   "   %s  %s   ",
980                                   "           7"},
981                                  {"8           ",
982                                   "   %s  %s   ",
983                                   "     %s     ",
984                                   "   %s  %s   ",
985                                   "     %s     ",
986                                   "   %s  %s   ",
987                                   "           8"},
988                                  {"9  %s  %s   ",
989                                   "            ",
990                                   "   %s  %s   ",
991                                   "     %s     ",
992                                   "   %s  %s   ",
993                                   "            ",
994                                   "   %s  %s  9"},
995                                  {"10 %s  %s   ",
996                                   "     %s     ",
997                                   "   %s  %s   ",
998                                   "            ",
999                                   "   %s  %s   ",
1000                                   "     %s     ",
1001                                   "   %s  %s 10"},
1002                                  {"J    /\\     ",
1003                                   "%s   ||     ",
1004                                   "     ||     ",
1005                                   "     ||     ",
1006                                   "     ||     ",
1007                                   "   |=HH=| %s",
1008                                   "     ][    J"},
1009                                  {"Q  ######   ",
1010                                   "%s#      #  ",
1011                                   "  # ++++ #  ",
1012                                   "  # +==+ #  ",
1013                                   "   # ++ #   ",
1014                                   "    #  #  %s",
1015                                   "     ##    Q"},
1016                                  {"K           ",
1017                                   "%s _'~~`_   ",
1018                                   "   jjjjj$&  ",
1019                                   "   q q uu   ",
1020                                   "   c    &   ",
1021                                   "    v__/  %s",
1022                                   "           K"}};
1023         concptr joker_grph[7] = {    "            ",
1024                                   "     J      ",
1025                                   "     O      ",
1026                                   "     K      ",
1027                                   "     E      ",
1028                                   "     R      ",
1029                                   "            "};
1030 #endif
1031
1032         for (i = 0; i < 5; i++)
1033         {
1034                 prt(_("┏━━━━━━┓", " +------------+ "),  5,  i*16);
1035         }
1036
1037         for (i = 0; i < 5; i++)
1038         {
1039                 for (j = 0; j < 7; j++)
1040                 {
1041                         prt(_("┃", " |"),  j+6,  i*16);
1042                         if(IS_JOKER(cards[i]))
1043                                 c_put_str(TERM_VIOLET, joker_grph[j],  j+6,  2+i*16);
1044                         else
1045                                 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);
1046                         prt(_("┃", "| "),  j+6,  i*16+14);
1047                 }
1048         }
1049         for (i = 0; i < 5; i++)
1050         {
1051                 prt(_("┗━━━━━━┛", " +------------+ "), 13,  i*16);
1052         }
1053 }
1054
1055 /*!
1056  * @brief ポーカーの1プレイルーチン。
1057  * @return 1プレイの役の結果
1058  */
1059 static int do_poker(void)
1060 {
1061         int i, k = 2;
1062         char cmd;
1063         int deck[53]; /* yamafuda : 0...52 */
1064         int deck_ptr = 0;
1065         int kaeruka[5]; /* 0:kaenai 1:kaeru */
1066
1067         bool done = FALSE;
1068         bool kettei = TRUE;
1069         bool kakikae = TRUE;
1070
1071         reset_deck(deck);
1072
1073         for (i = 0; i < 5; i++)
1074         {
1075                 cards[i] = deck[deck_ptr++];
1076                 kaeruka[i] = 0; /* default:nokosu */
1077         }
1078
1079         /* suteruno wo kimeru */
1080         prt(_("残すカードを決めて下さい(方向で移動, スペースで選択)。", "Stay witch? "), 0, 0);
1081
1082         display_cards();
1083         yaku_check();
1084
1085         while (!done)
1086         {
1087                 if (kakikae) display_kaeruka(k+kettei*5, kaeruka);
1088                 kakikae = FALSE;
1089                 cmd = inkey();
1090                 switch (cmd)
1091                 {
1092                 case '6': case 'l': case 'L': case KTRL('F'):
1093                         if (!kettei) k = (k+1)%5;
1094                         else {k = 0;kettei = FALSE;}
1095                         kakikae = TRUE;
1096                         break;
1097                 case '4': case 'h': case 'H': case KTRL('B'):
1098                         if (!kettei) k = (k+4)%5;
1099                         else {k = 4;kettei = FALSE;}
1100                         kakikae = TRUE;
1101                         break;
1102                 case '2': case 'j': case 'J': case KTRL('N'):
1103                         if (!kettei) {kettei = TRUE;kakikae = TRUE;}
1104                         break;
1105                 case '8': case 'k': case 'K': case KTRL('P'):
1106                         if (kettei) {kettei = FALSE;kakikae = TRUE;}
1107                         break;
1108                 case ' ': case '\r':
1109                         if (kettei) done = TRUE;
1110                         else {kaeruka[k] = !kaeruka[k];kakikae = TRUE;}
1111                         break;
1112                 default:
1113                         break;
1114                 }
1115         }
1116         
1117         prt("",0,0);
1118
1119         for (i = 0; i < 5; i++)
1120                 if (kaeruka[i] == 1) cards[i] = deck[deck_ptr++]; /* soshite toru */
1121
1122         display_cards();
1123         
1124         return yaku_check();
1125 }
1126 #undef SUIT_OF
1127 #undef NUM_OF
1128 #undef IS_JOKER
1129 /* end of poker codes --Koka */
1130
1131 /*!
1132  * @brief カジノ1プレイごとのメインルーチン / gamble_comm
1133  * @param cmd プレイするゲームID
1134  * @return なし
1135  */
1136 static bool gamble_comm(int cmd)
1137 {
1138         int i;
1139         int roll1, roll2, roll3, choice, odds, win;
1140         s32b wager;
1141         s32b maxbet;
1142         s32b oldgold;
1143
1144         char out_val[160], tmp_str[80], again;
1145         concptr p;
1146
1147         screen_save();
1148
1149         if (cmd == BACT_GAMBLE_RULES)
1150         {
1151                 /* Peruse the gambling help file */
1152                 (void)show_file(TRUE, _("jgambling.txt", "gambling.txt"), NULL, 0, 0);
1153         }
1154         else
1155         {
1156                 /* No money */
1157                 if (p_ptr->au < 1)
1158                 {
1159                         msg_print(_("おい!おまえ一文なしじゃないか!こっから出ていけ!", 
1160                                                 "Hey! You don't have gold - get out of here!"));
1161                         msg_print(NULL);
1162                         screen_load();
1163                         return FALSE;
1164                 }
1165
1166                 clear_bldg(5, 23);
1167
1168                 maxbet = p_ptr->lev * 200;
1169
1170                 /* We can't bet more than we have */
1171                 maxbet = MIN(maxbet, p_ptr->au);
1172
1173                 /* Get the wager */
1174                 strcpy(out_val, "");
1175                 sprintf(tmp_str,_("賭け金 (1-%ld)?", "Your wager (1-%ld) ? "), (long int)maxbet);
1176
1177
1178                 /*
1179                  * Use get_string() because we may need more than
1180                  * the s16b value returned by get_quantity().
1181                  */
1182                 if (get_string(tmp_str, out_val, 32))
1183                 {
1184                         /* Strip spaces */
1185                         for (p = out_val; *p == ' '; p++);
1186
1187                         /* Get the wager */
1188                         wager = atol(p);
1189
1190                         if (wager > p_ptr->au)
1191                         {
1192                                 msg_print(_("おい!金が足りないじゃないか!出ていけ!", "Hey! You don't have the gold - get out of here!"));
1193                                 msg_print(NULL);
1194                                 screen_load();
1195                                 return (FALSE);
1196                         }
1197                         else if (wager > maxbet)
1198                         {
1199                                 msg_format(_("%ldゴールドだけ受けよう。残りは取っときな。",
1200                                                          "I'll take %ld gold of that. Keep the rest."), (long int)maxbet);
1201                                 wager = maxbet;
1202                         }
1203                         else if (wager < 1)
1204                         {
1205                                 msg_print(_("OK、1ゴールドからはじめよう。", "Ok, we'll start with 1 gold."));
1206                                 wager = 1;
1207                         }
1208                         msg_print(NULL);
1209                         win = FALSE;
1210                         odds = 0;
1211                         oldgold = p_ptr->au;
1212
1213                         sprintf(tmp_str, _("ゲーム前の所持金: %9ld", "Gold before game: %9ld"), (long int)oldgold);
1214                         prt(tmp_str, 20, 2);
1215                         sprintf(tmp_str, _("現在の掛け金:     %9ld", "Current Wager:    %9ld"), (long int)wager);
1216                         prt(tmp_str, 21, 2);
1217
1218                         do
1219                         {
1220                                 p_ptr->au -= wager;
1221                                 switch (cmd)
1222                                 {
1223                                  case BACT_IN_BETWEEN: /* Game of In-Between */
1224                                         c_put_str(TERM_GREEN, _("イン・ビトイーン", "In Between"),5,2);
1225
1226                                         odds = 4;
1227                                         win = FALSE;
1228                                         roll1 = randint1(10);
1229                                         roll2 = randint1(10);
1230                                         choice = randint1(10);
1231                                         sprintf(tmp_str, _("黒ダイス: %d        黒ダイス: %d", "Black die: %d       Black Die: %d"), roll1, roll2);
1232
1233                                         prt(tmp_str, 8, 3);
1234                                         sprintf(tmp_str, _("赤ダイス: %d", "Red die: %d"), choice);
1235
1236                                         prt(tmp_str, 11, 14);
1237                                         if (((choice > roll1) && (choice < roll2)) ||
1238                                                 ((choice < roll1) && (choice > roll2)))
1239                                                 win = TRUE;
1240                                         break;
1241                                 case BACT_CRAPS:  /* Game of Craps */
1242                                         c_put_str(TERM_GREEN, _("クラップス", "Craps"), 5, 2);
1243
1244                                         win = 3;
1245                                         odds = 2;
1246                                         roll1 = randint1(6);
1247                                         roll2 = randint1(6);
1248                                         roll3 = roll1 +  roll2;
1249                                         choice = roll3;
1250                                         sprintf(tmp_str, _("1振りめ: %d %d      Total: %d", 
1251                                                                            "First roll: %d %d    Total: %d"), roll1, roll2, roll3);
1252                                         prt(tmp_str, 7, 5);
1253                                         if ((roll3 == 7) || (roll3 == 11))
1254                                                 win = TRUE;
1255                                         else if ((roll3 == 2) || (roll3 == 3) || (roll3 == 12))
1256                                                 win = FALSE;
1257                                         else
1258                                                 do
1259                                                 {
1260                                                         msg_print(_("なにかキーを押すともう一回振ります。", "Hit any key to roll again"));
1261
1262                                                         msg_print(NULL);
1263                                                         roll1 = randint1(6);
1264                                                         roll2 = randint1(6);
1265                                                         roll3 = roll1 +  roll2;
1266                                                         sprintf(tmp_str, _("出目: %d %d          合計:      %d", 
1267                                                                                    "Roll result: %d %d   Total:     %d"), roll1, roll2, roll3);
1268                                                         prt(tmp_str, 8, 5);
1269                                                         if (roll3 == choice)
1270                                                                 win = TRUE;
1271                                                         else if (roll3 == 7)
1272                                                                 win = FALSE;
1273                                                 } while ((win != TRUE) && (win != FALSE));
1274                                         break;
1275
1276                                 case BACT_SPIN_WHEEL:  /* Spin the Wheel Game */
1277                                         win = FALSE;
1278                                         odds = 9;
1279                                         c_put_str(TERM_GREEN, _("ルーレット", "Wheel"), 5, 2);
1280
1281                                         prt("0  1  2  3  4  5  6  7  8  9", 7, 5);
1282                                         prt("--------------------------------", 8, 3);
1283                                         strcpy(out_val, "");
1284                                         get_string(_("何番? (0-9): ", "Pick a number (0-9): "), out_val, 32);
1285
1286                                         for (p = out_val; iswspace(*p); p++);
1287                                         choice = atol(p);
1288                                         if (choice < 0)
1289                                         {
1290                                                 msg_print(_("0番にしとくぜ。", "I'll put you down for 0."));
1291                                                 choice = 0;
1292                                         }
1293                                         else if (choice > 9)
1294                                         {
1295                                                 msg_print(_("OK、9番にしとくぜ。", "Ok, I'll put you down for 9."));
1296                                                 choice = 9;
1297                                         }
1298                                         msg_print(NULL);
1299                                         roll1 = randint0(10);
1300                                         sprintf(tmp_str, _("ルーレットは回り、止まった。勝者は %d番だ。", 
1301                                                                            "The wheel spins to a stop and the winner is %d"), roll1);
1302                                         prt(tmp_str, 13, 3);
1303                                         prt("", 9, 0);
1304                                         prt("*", 9, (3 * roll1 + 5));
1305                                         if (roll1 == choice)
1306                                                 win = TRUE;
1307                                         break;
1308
1309                                 case BACT_DICE_SLOTS: /* The Dice Slots */
1310                                         c_put_str(TERM_GREEN,  _("ダイス・スロット", "Dice Slots"), 5, 2);
1311                                         c_put_str(TERM_YELLOW, _("レモン   レモン            2", ""), 6, 37);
1312                                         c_put_str(TERM_YELLOW, _("レモン   レモン   レモン   5", ""), 7, 37);
1313                                         c_put_str(TERM_ORANGE, _("オレンジ オレンジ オレンジ 10", ""), 8, 37);
1314                                         c_put_str(TERM_UMBER, _("剣       剣       剣       20", ""), 9, 37);
1315                                         c_put_str(TERM_SLATE, _("盾       盾       盾       50", ""), 10, 37);
1316                                         c_put_str(TERM_VIOLET, _("プラム   プラム   プラム   200", ""), 11, 37);
1317                                         c_put_str(TERM_RED, _("チェリー チェリー チェリー 1000", ""), 12, 37);
1318                                         
1319                                         win = FALSE;
1320                                         roll1 = randint1(21);
1321                                         for (i=6;i>0;i--)
1322                                         {
1323                                                 if ((roll1-i) < 1)
1324                                                 {
1325                                                         roll1 = 7-i;
1326                                                         break;
1327                                                 }
1328                                                 roll1 -= i;
1329                                         }
1330                                         roll2 = randint1(21);
1331                                         for (i=6;i>0;i--)
1332                                         {
1333                                                 if ((roll2-i) < 1)
1334                                                 {
1335                                                         roll2 = 7-i;
1336                                                         break;
1337                                                 }
1338                                                 roll2 -= i;
1339                                         }
1340                                         choice = randint1(21);
1341                                         for (i=6;i>0;i--)
1342                                         {
1343                                                 if ((choice-i) < 1)
1344                                                 {
1345                                                         choice = 7-i;
1346                                                         break;
1347                                                 }
1348                                                 choice -= i;
1349                                         }
1350                                         put_str("/--------------------------\\", 7, 2);
1351                                         prt("\\--------------------------/", 17, 2);
1352                                         display_fruit(8,  3, roll1 - 1);
1353                                         display_fruit(8, 12, roll2 - 1);
1354                                         display_fruit(8, 21, choice - 1);
1355                                         if ((roll1 == roll2) && (roll2 == choice))
1356                                         {
1357                                                 win = TRUE;
1358                                                 switch(roll1)
1359                                                 {
1360                                                 case 1:
1361                                                         odds = 5;break;
1362                                                 case 2:
1363                                                         odds = 10;break;
1364                                                 case 3:
1365                                                         odds = 20;break;
1366                                                 case 4:
1367                                                         odds = 50;break;
1368                                                 case 5:
1369                                                         odds = 200;break;
1370                                                 case 6:
1371                                                         odds = 1000;break;
1372                                                 }
1373                                         }
1374                                         else if ((roll1 == 1) && (roll2 == 1))
1375                                         {
1376                                                 win = TRUE;
1377                                                 odds = 2;
1378                                         }
1379                                         break;
1380                                 case BACT_POKER:
1381                                         win = FALSE;
1382                                         odds = do_poker();
1383                                         if (odds) win = TRUE;
1384                                         break;
1385                                 }
1386
1387                                 if (win)
1388                                 {
1389                                         prt(_("あなたの勝ち", "YOU WON"), 16, 37);
1390
1391                                         p_ptr->au += odds * wager;
1392                                         sprintf(tmp_str, _("倍率: %d", "Payoff: %d"), odds);
1393
1394                                         prt(tmp_str, 17, 37);
1395                                 }
1396                                 else
1397                                 {
1398                                         prt(_("あなたの負け", "You Lost"), 16, 37);
1399                                         prt("", 17, 37);
1400                                 }
1401                                 sprintf(tmp_str, _("現在の所持金:     %9ld", "Current Gold:     %9ld"), (long int)p_ptr->au);
1402
1403                                 prt(tmp_str, 22, 2);
1404                                 prt(_("もう一度(Y/N)?", "Again(Y/N)?"), 18, 37);
1405
1406                                 move_cursor(18, 52);
1407                                 again = inkey();
1408                                 prt("", 16, 37);
1409                                 prt("", 17, 37);
1410                                 prt("", 18, 37);
1411                                 if (wager > p_ptr->au)
1412                                 {
1413                                         msg_print(_("おい!金が足りないじゃないか!ここから出て行け!", 
1414                                                                 "Hey! You don't have the gold - get out of here!"));
1415                                         msg_print(NULL);
1416
1417                                         /* Get out here */
1418                                         break;
1419                                 }
1420                         } while ((again == 'y') || (again == 'Y'));
1421
1422                         prt("", 18, 37);
1423                         if (p_ptr->au >= oldgold)
1424                         {
1425                                 msg_print(_("「今回は儲けたな!でも次はこっちが勝ってやるからな、絶対に!」",
1426                                                         "You came out a winner! We'll win next time, I'm sure."));
1427                                 chg_virtue(V_CHANCE, 3);
1428                         }
1429                         else
1430                         {
1431                                 msg_print(_("「金をスッてしまったな、わはは!うちに帰った方がいいぜ。」", "You lost gold! Haha, better head home."));
1432                                 chg_virtue(V_CHANCE, -3);
1433                         }
1434                 }
1435                 msg_print(NULL);
1436         }
1437         screen_load();
1438         return (TRUE);
1439 }
1440
1441 /*!
1442  * @brief モンスター闘技場に参加するモンスターを更新する。
1443  * @return なし
1444  */
1445 void update_gambling_monsters(void)
1446 {
1447         int total, i;
1448         int max_dl = 0;
1449         int mon_level;
1450         int power[4];
1451         bool tekitou;
1452         bool old_inside_battle = p_ptr->inside_battle;
1453
1454         for (i = 0; i < max_d_idx; i++)
1455                 if (max_dl < max_dlv[i]) max_dl = max_dlv[i];
1456
1457         mon_level = randint1(MIN(max_dl, 122)) + 5;
1458         if (randint0(100) < 60)
1459         {
1460                 i = randint1(MIN(max_dl, 122)) + 5;
1461                 mon_level = MAX(i, mon_level);
1462         }
1463         if (randint0(100) < 30)
1464         {
1465                 i = randint1(MIN(max_dl, 122)) + 5;
1466                 mon_level = MAX(i, mon_level);
1467         }
1468
1469         while (1)
1470         {
1471                 total = 0;
1472                 tekitou = FALSE;
1473                 for (i = 0; i < 4; i++)
1474                 {
1475                         MONRACE_IDX r_idx;
1476                         int j;
1477                         while (1)
1478                         {
1479                                 get_mon_num_prep(monster_can_entry_arena, NULL);
1480                                 p_ptr->inside_battle = TRUE;
1481                                 r_idx = get_mon_num(mon_level);
1482                                 p_ptr->inside_battle = old_inside_battle;
1483                                 if (!r_idx) continue;
1484
1485                                 if ((r_info[r_idx].flags1 & RF1_UNIQUE) || (r_info[r_idx].flags7 & RF7_UNIQUE2))
1486                                 {
1487                                         if ((r_info[r_idx].level + 10) > mon_level) continue;
1488                                 }
1489
1490                                 for (j = 0; j < i; j++)
1491                                         if (r_idx == battle_mon[j]) break;
1492                                 if (j < i) continue;
1493
1494                                 break;
1495                         }
1496                         battle_mon[i] = r_idx;
1497                         if (r_info[r_idx].level < 45) tekitou = TRUE;
1498                 }
1499
1500                 for (i = 0; i < 4; i++)
1501                 {
1502                         monster_race *r_ptr = &r_info[battle_mon[i]];
1503                         int num_taisei = count_bits(r_ptr->flagsr & (RFR_IM_ACID | RFR_IM_ELEC | RFR_IM_FIRE | RFR_IM_COLD | RFR_IM_POIS));
1504
1505                         if (r_ptr->flags1 & RF1_FORCE_MAXHP)
1506                                 power[i] = r_ptr->hdice * r_ptr->hside * 2;
1507                         else
1508                                 power[i] = r_ptr->hdice * (r_ptr->hside + 1);
1509                         power[i] = power[i] * (100 + r_ptr->level) / 100;
1510                         if (r_ptr->speed > 110)
1511                                 power[i] = power[i] * (r_ptr->speed * 2 - 110) / 100;
1512                         if (r_ptr->speed < 110)
1513                                 power[i] = power[i] * (r_ptr->speed - 20) / 100;
1514                         if (num_taisei > 2)
1515                                 power[i] = power[i] * (num_taisei * 2 + 5) / 10;
1516                         else if (r_ptr->a_ability_flags2 & RF6_INVULNER)
1517                                 power[i] = power[i] * 4 / 3;
1518                         else if (r_ptr->a_ability_flags2 & RF6_HEAL)
1519                                 power[i] = power[i] * 4 / 3;
1520                         else if (r_ptr->a_ability_flags1 & RF5_DRAIN_MANA)
1521                                 power[i] = power[i] * 11 / 10;
1522                         if (r_ptr->flags1 & RF1_RAND_25)
1523                                 power[i] = power[i] * 9 / 10;
1524                         if (r_ptr->flags1 & RF1_RAND_50)
1525                                 power[i] = power[i] * 9 / 10;
1526                         if (r_ptr->flagsr & RFR_RES_ALL) power[i] *= 100000;
1527                         if (r_ptr->arena_ratio) power[i] = power[i] * r_ptr->arena_ratio / 100;
1528
1529
1530                         total += power[i];
1531                 }
1532                 for (i = 0; i < 4; i++)
1533                 {
1534                         power[i] = total * 60 / power[i];
1535                         if (tekitou && ((power[i] < 160) || power[i] > 1500)) break;
1536                         if ((power[i] < 160) && randint0(20)) break;
1537                         if (power[i] < 101) power[i] = 100 + randint1(5);
1538                         mon_odds[i] = power[i];
1539                 }
1540                 if (i == 4) break;
1541         }
1542 }
1543
1544 /*!
1545  * @brief モンスター闘技場のメインルーチン
1546  * @return 賭けを開始したか否か
1547  */
1548 static bool kakutoujou(void)
1549 {
1550         PRICE maxbet;
1551         PRICE wager;
1552         char out_val[160], tmp_str[80];
1553         concptr p;
1554
1555         if ((current_world_ptr->game_turn - current_world_ptr->arena_start_turn) > TURNS_PER_TICK * 250)
1556         {
1557                 update_gambling_monsters();
1558                 current_world_ptr->arena_start_turn = current_world_ptr->game_turn;
1559         }
1560
1561         screen_save();
1562
1563         /* No money */
1564         if (p_ptr->au < 1)
1565         {
1566                 msg_print(_("おい!おまえ一文なしじゃないか!こっから出ていけ!", "Hey! You don't have gold - get out of here!"));
1567                 msg_print(NULL);
1568                 screen_load();
1569                 return FALSE;
1570         }
1571         else
1572         {
1573                 int i;
1574
1575                 clear_bldg(4, 10);
1576
1577                 prt(_("モンスター                                                     倍率",
1578                           "Monsters                                                       Odds"), 4, 4);
1579                 for (i=0;i<4;i++)
1580                 {
1581                         char buf[80];
1582                         monster_race *r_ptr = &r_info[battle_mon[i]];
1583
1584                         sprintf(buf, _("%d) %-58s  %4ld.%02ld倍", "%d) %-58s  %4ld.%02ld"), i+1, 
1585                                                  _(format("%s%s",r_name + r_ptr->name, (r_ptr->flags1 & RF1_UNIQUE) ? "もどき" : "      "),
1586                                                    format("%s%s", (r_ptr->flags1 & RF1_UNIQUE) ? "Fake " : "", r_name + r_ptr->name)),
1587                                                 (long int)mon_odds[i]/100, (long int)mon_odds[i]%100);
1588                         prt(buf, 5+i, 1);
1589                 }
1590                 prt(_("どれに賭けますか:", "Which monster: "), 0, 0);
1591                 while(1)
1592                 {
1593                         i = inkey();
1594
1595                         if (i == ESCAPE)
1596                         {
1597                                 screen_load();
1598                                 return FALSE;
1599                         }
1600                         if (i >= '1' && i <= '4')
1601                         {
1602                                 sel_monster = i-'1';
1603                                 battle_odds = mon_odds[sel_monster];
1604                                 break;
1605                         }
1606                         else bell();
1607                 }
1608
1609                 clear_bldg(4, 4);
1610                 for (i = 0; i < 4; i++)
1611                         if (i != sel_monster) clear_bldg(i + 5, i + 5);
1612
1613                 maxbet = p_ptr->lev * 200;
1614
1615                 /* We can't bet more than we have */
1616                 maxbet = MIN(maxbet, p_ptr->au);
1617
1618                 /* Get the wager */
1619                 strcpy(out_val, "");
1620                 sprintf(tmp_str,_("賭け金 (1-%ld)?", "Your wager (1-%ld) ? "), (long int)maxbet);
1621                 /*
1622                  * Use get_string() because we may need more than
1623                  * the s16b value returned by get_quantity().
1624                  */
1625                 if (get_string(tmp_str, out_val, 32))
1626                 {
1627                         /* Strip spaces */
1628                         for (p = out_val; *p == ' '; p++);
1629
1630                         /* Get the wager */
1631                         wager = atol(p);
1632
1633                         if (wager > p_ptr->au)
1634                         {
1635                                 msg_print(_("おい!金が足りないじゃないか!出ていけ!", "Hey! You don't have the gold - get out of here!"));
1636
1637                                 msg_print(NULL);
1638                                 screen_load();
1639                                 return (FALSE);
1640                         }
1641                         else if (wager > maxbet)
1642                         {
1643                                 msg_format(_("%ldゴールドだけ受けよう。残りは取っときな。", "I'll take %ld gold of that. Keep the rest."), (long int)maxbet);
1644
1645                                 wager = maxbet;
1646                         }
1647                         else if (wager < 1)
1648                         {
1649                                 msg_print(_("OK、1ゴールドでいこう。", "Ok, we'll start with 1 gold."));
1650                                 wager = 1;
1651                         }
1652                         msg_print(NULL);
1653                         battle_odds = MAX(wager+1, wager * battle_odds / 100);
1654                         kakekin = wager;
1655                         p_ptr->au -= wager;
1656                         reset_tim_flags();
1657
1658                         /* Save the surface floor as saved floor */
1659                         prepare_change_floor_mode(CFM_SAVE_FLOORS);
1660
1661                         p_ptr->inside_battle = TRUE;
1662                         p_ptr->leaving = TRUE;
1663
1664                         p_ptr->leave_bldg = TRUE;
1665                         screen_load();
1666
1667                         return (TRUE);
1668                 }
1669         }
1670         screen_load();
1671
1672         return (FALSE);
1673 }
1674
1675 /*!
1676  * @brief 本日の賞金首情報を表示する。
1677  * @return なし
1678  */
1679 static void today_target(void)
1680 {
1681         char buf[160];
1682         monster_race *r_ptr = &r_info[today_mon];
1683
1684         clear_bldg(4,18);
1685         c_put_str(TERM_YELLOW, _("本日の賞金首", "Wanted monster that changes from day to day"), 5, 10);
1686         sprintf(buf,_("ターゲット: %s", "target: %s"),r_name + r_ptr->name);
1687         c_put_str(TERM_YELLOW, buf, 6, 10);
1688         sprintf(buf,_("死体 ---- $%d", "corpse   ---- $%d"), (int)r_ptr->level * 50 + 100);
1689         prt(buf, 8, 10);
1690         sprintf(buf,_("骨   ---- $%d", "skeleton ---- $%d"), (int)r_ptr->level * 30 + 60);
1691         prt(buf, 9, 10);
1692         p_ptr->today_mon = today_mon;
1693 }
1694
1695 /*!
1696  * @brief ツチノコの賞金首情報を表示する。
1697  * @return なし
1698  */
1699 static void tsuchinoko(void)
1700 {
1701         clear_bldg(4,18);
1702         c_put_str(TERM_YELLOW, _("一獲千金の大チャンス!!!", "Big chance to quick money!!!"), 5, 10);
1703         c_put_str(TERM_YELLOW, _("ターゲット:幻の珍獣「ツチノコ」", "target: the rarest animal 'Tsuchinoko'"), 6, 10);
1704         c_put_str(TERM_WHITE, _("生け捕り ---- $1,000,000", "catch alive ---- $1,000,000"), 8, 10);
1705         c_put_str(TERM_WHITE, _("死体     ----   $200,000", "corpse      ----   $200,000"), 9, 10);
1706         c_put_str(TERM_WHITE, _("骨       ----   $100,000", "bones       ----   $100,000"), 10, 10);
1707 }
1708
1709 /*!
1710  * @brief 通常の賞金首情報を表示する。
1711  * @return なし
1712  */
1713 static void shoukinkubi(void)
1714 {
1715         int i;
1716         TERM_LEN y = 0;
1717
1718         clear_bldg(4,18);
1719         prt(_("死体を持ち帰れば報酬を差し上げます。", "Offer a prize when you bring a wanted monster's corpse"),4 ,10);
1720         c_put_str(TERM_YELLOW, _("現在の賞金首", "Wanted monsters"), 6, 10);
1721
1722         for (i = 0; i < MAX_KUBI; i++)
1723         {
1724                 byte color;
1725                 concptr done_mark;
1726                 monster_race *r_ptr = &r_info[(current_world_ptr->bounty_r_idx[i] > 10000 ? current_world_ptr->bounty_r_idx[i] - 10000 : current_world_ptr->bounty_r_idx[i])];
1727
1728                 if (current_world_ptr->bounty_r_idx[i] > 10000)
1729                 {
1730                         color = TERM_RED;
1731                         done_mark = _("(済)", "(done)");
1732                 }
1733                 else
1734                 {
1735                         color = TERM_WHITE;
1736                         done_mark = "";
1737                 }
1738
1739                 c_prt(color, format("%s %s", r_name + r_ptr->name, done_mark), y+7, 10);
1740
1741                 y = (y+1) % 10;
1742                 if (!y && (i < MAX_KUBI -1))
1743                 {
1744                         prt(_("何かキーを押してください", "Hit any key."), 0, 0);
1745                         (void)inkey();
1746                         prt("", 0, 0);
1747                         clear_bldg(7,18);
1748                 }
1749         }
1750 }
1751
1752
1753
1754 /*!
1755  * 賞金首の報酬テーブル / List of prize object
1756  */
1757 static struct {
1758         OBJECT_TYPE_VALUE tval; /*!< ベースアイテムのメイン種別ID */
1759         OBJECT_SUBTYPE_VALUE sval; /*!< ベースアイテムのサブ種別ID */
1760 } prize_list[MAX_KUBI] = 
1761 {
1762         {TV_POTION, SV_POTION_CURING},
1763         {TV_POTION, SV_POTION_SPEED},
1764         {TV_POTION, SV_POTION_SPEED},
1765         {TV_POTION, SV_POTION_RESISTANCE},
1766         {TV_POTION, SV_POTION_ENLIGHTENMENT},
1767
1768         {TV_POTION, SV_POTION_HEALING},
1769         {TV_POTION, SV_POTION_RESTORE_MANA},
1770         {TV_SCROLL, SV_SCROLL_STAR_DESTRUCTION},
1771         {TV_POTION, SV_POTION_STAR_ENLIGHTENMENT},
1772         {TV_SCROLL, SV_SCROLL_SUMMON_PET},
1773
1774         {TV_SCROLL, SV_SCROLL_GENOCIDE},
1775         {TV_POTION, SV_POTION_STAR_HEALING},
1776         {TV_POTION, SV_POTION_STAR_HEALING},
1777         {TV_POTION, SV_POTION_NEW_LIFE},
1778         {TV_SCROLL, SV_SCROLL_MASS_GENOCIDE},
1779
1780         {TV_POTION, SV_POTION_LIFE},
1781         {TV_POTION, SV_POTION_LIFE},
1782         {TV_POTION, SV_POTION_AUGMENTATION},
1783         {TV_POTION, SV_POTION_INVULNERABILITY},
1784         {TV_SCROLL, SV_SCROLL_ARTIFACT},
1785 };
1786
1787 /*!
1788  * @brief 賞金首の引き換え処理 / Get prize
1789  * @return 各種賞金首のいずれかでも換金が行われたか否か。
1790  */
1791 static bool kankin(void)
1792 {
1793         INVENTORY_IDX i;
1794         int j;
1795         bool change = FALSE;
1796         GAME_TEXT o_name[MAX_NLEN];
1797         object_type *o_ptr;
1798
1799         /* Loop for p_ptr->inventory_list and right/left arm */
1800         for (i = 0; i <= INVEN_LARM; i++)
1801         {
1802                 o_ptr = &p_ptr->inventory_list[i];
1803
1804                 /* Living Tsuchinoko worthes $1000000 */
1805                 if ((o_ptr->tval == TV_CAPTURE) && (o_ptr->pval == MON_TSUCHINOKO))
1806                 {
1807                         char buf[MAX_NLEN+20];
1808                         object_desc(o_name, o_ptr, 0);
1809                         sprintf(buf, _("%s を換金しますか?", "Convert %s into money? "),o_name);
1810                         if (get_check(buf))
1811                         {
1812                                 msg_format(_("賞金 %ld$を手に入れた。", "You get %ldgp."), (long int)(1000000L * o_ptr->number));
1813                                 p_ptr->au += 1000000L * o_ptr->number;
1814                                 p_ptr->redraw |= (PR_GOLD);
1815                                 inven_item_increase(i, -o_ptr->number);
1816                                 inven_item_describe(i);
1817                                 inven_item_optimize(i);
1818                         }
1819                         change = TRUE;
1820                 }
1821         }
1822
1823         for (i = 0; i < INVEN_PACK; i++)
1824         {
1825                 o_ptr = &p_ptr->inventory_list[i];
1826
1827                 /* Corpse of Tsuchinoko worthes $200000 */
1828                 if ((o_ptr->tval == TV_CORPSE) && (o_ptr->sval == SV_CORPSE) && (o_ptr->pval == MON_TSUCHINOKO))
1829                 {
1830                         char buf[MAX_NLEN+20];
1831                         object_desc(o_name, o_ptr, 0);
1832                         sprintf(buf, _("%s を換金しますか?", "Convert %s into money? "),o_name);
1833                         if (get_check(buf))
1834                         {
1835                                 msg_format(_("賞金 %ld$を手に入れた。", "You get %ldgp."), (long int)(200000L * o_ptr->number));
1836                                 p_ptr->au += 200000L * o_ptr->number;
1837                                 p_ptr->redraw |= (PR_GOLD);
1838                                 inven_item_increase(i, -o_ptr->number);
1839                                 inven_item_describe(i);
1840                                 inven_item_optimize(i);
1841                         }
1842                         change = TRUE;
1843                 }
1844         }
1845
1846         for (i = 0; i < INVEN_PACK; i++)
1847         {
1848                 o_ptr = &p_ptr->inventory_list[i];
1849
1850                 /* Bones of Tsuchinoko worthes $100000 */
1851                 if ((o_ptr->tval == TV_CORPSE) && (o_ptr->sval == SV_SKELETON) && (o_ptr->pval == MON_TSUCHINOKO))
1852                 {
1853                         char buf[MAX_NLEN+20];
1854                         object_desc(o_name, o_ptr, 0);
1855                         sprintf(buf, _("%s を換金しますか?", "Convert %s into money? "),o_name);
1856                         if (get_check(buf))
1857                         {
1858                                 msg_format(_("賞金 %ld$を手に入れた。", "You get %ldgp."), (long int)(100000L * o_ptr->number));
1859                                 p_ptr->au += 100000L * o_ptr->number;
1860                                 p_ptr->redraw |= (PR_GOLD);
1861                                 inven_item_increase(i, -o_ptr->number);
1862                                 inven_item_describe(i);
1863                                 inven_item_optimize(i);
1864                         }
1865                         change = TRUE;
1866                 }
1867         }
1868
1869         for (i = 0; i < INVEN_PACK; i++)
1870         {
1871                 o_ptr = &p_ptr->inventory_list[i];
1872                 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)))
1873                 {
1874                         char buf[MAX_NLEN+20];
1875                         object_desc(o_name, o_ptr, 0);
1876                         sprintf(buf, _("%s を換金しますか?", "Convert %s into money? "),o_name);
1877                         if (get_check(buf))
1878                         {
1879                                 msg_format(_("賞金 %ld$を手に入れた。", "You get %ldgp."), (long int)((r_info[today_mon].level * 50 + 100) * o_ptr->number));
1880                                 p_ptr->au += (r_info[today_mon].level * 50 + 100) * o_ptr->number;
1881                                 p_ptr->redraw |= (PR_GOLD);
1882                                 inven_item_increase(i, -o_ptr->number);
1883                                 inven_item_describe(i);
1884                                 inven_item_optimize(i);
1885                         }
1886                         change = TRUE;
1887                 }
1888         }
1889
1890         for (i = 0; i < INVEN_PACK; i++)
1891         {
1892                 o_ptr = &p_ptr->inventory_list[i];
1893
1894                 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)))
1895                 {
1896                         char buf[MAX_NLEN+20];
1897                         object_desc(o_name, o_ptr, 0);
1898                         sprintf(buf, _("%s を換金しますか?", "Convert %s into money? "),o_name);
1899                         if (get_check(buf))
1900                         {
1901                                 msg_format(_("賞金 %ld$を手に入れた。", "You get %ldgp."), (long int)((r_info[today_mon].level * 30 + 60) * o_ptr->number));
1902                                 p_ptr->au += (r_info[today_mon].level * 30 + 60) * o_ptr->number;
1903                                 p_ptr->redraw |= (PR_GOLD);
1904                                 inven_item_increase(i, -o_ptr->number);
1905                                 inven_item_describe(i);
1906                                 inven_item_optimize(i);
1907                         }
1908                         change = TRUE;
1909                 }
1910         }
1911
1912         for (j = 0; j < MAX_KUBI; j++)
1913         {
1914                 /* Need reverse order --- Positions will be changed in the loop */
1915                 for (i = INVEN_PACK-1; i >= 0; i--)
1916                 {
1917                         o_ptr = &p_ptr->inventory_list[i];
1918                         if ((o_ptr->tval == TV_CORPSE) && (o_ptr->pval == current_world_ptr->bounty_r_idx[j]))
1919                         {
1920                                 char buf[MAX_NLEN+20];
1921                                 int num, k;
1922                                 INVENTORY_IDX item_new;
1923                                 object_type forge;
1924
1925                                 object_desc(o_name, o_ptr, 0);
1926                                 sprintf(buf, _("%sを渡しますか?", "Hand %s over? "),o_name);
1927                                 if (!get_check(buf)) continue;
1928
1929 #if 0 /* Obsoleted */
1930                                 msg_format(_("賞金 %ld$を手に入れた。", "You get %ldgp."), (r_info[current_world_ptr->bounty_r_idx[j]].level + 1) * 300 * o_ptr->number);
1931                                 p_ptr->au += (r_info[current_world_ptr->bounty_r_idx[j]].level+1) * 300 * o_ptr->number;
1932                                 p_ptr->redraw |= (PR_GOLD);
1933                                 inven_item_increase(i, -o_ptr->number);
1934                                 inven_item_describe(i);
1935                                 inven_item_optimize(i);
1936                                 chg_virtue(V_JUSTICE, 5);
1937                                 current_world_ptr->bounty_r_idx[j] += 10000;
1938
1939                                 change = TRUE;
1940 #endif /* Obsoleted */
1941
1942                                 /* Hand it first */
1943                                 inven_item_increase(i, -o_ptr->number);
1944                                 inven_item_describe(i);
1945                                 inven_item_optimize(i);
1946
1947                                 chg_virtue(V_JUSTICE, 5);
1948                                 current_world_ptr->bounty_r_idx[j] += 10000;
1949
1950                                 /* Count number of unique corpses already handed */
1951                                 for (num = 0, k = 0; k < MAX_KUBI; k++)
1952                                 {
1953                                         if (current_world_ptr->bounty_r_idx[k] >= 10000) num++;
1954                                 }
1955                                 msg_format(_("これで合計 %d ポイント獲得しました。" ,"You earned %d point%s total."), num, (num > 1 ? "s" : ""));
1956
1957                                 /* Prepare to make a prize */
1958                                 object_prep(&forge, lookup_kind(prize_list[num-1].tval, prize_list[num-1].sval));
1959                                 apply_magic(&forge, current_floor_ptr->object_level, AM_NO_FIXED_ART);
1960
1961                                 object_aware(&forge);
1962                                 object_known(&forge);
1963
1964                                 /*
1965                                  * Hand it --- Assume there is an empty slot.
1966                                  * Since a corpse is handed at first,
1967                                  * there is at least one empty slot.
1968                                  */
1969                                 item_new = inven_carry(&forge);
1970
1971                                 object_desc(o_name, &forge, 0);
1972                                 msg_format(_("%s(%c)を貰った。", "You get %s (%c). "), o_name, index_to_label(item_new));
1973
1974                                 /* Auto-inscription */
1975                                 autopick_alter_item(item_new, FALSE);
1976                                 handle_stuff();
1977
1978                                 change = TRUE;
1979                         }
1980                 }
1981         }
1982
1983         if (!change)
1984         {
1985                 msg_print(_("賞金を得られそうなものは持っていなかった。", "You have nothing."));
1986                 msg_print(NULL);
1987                 return FALSE;
1988         }
1989         return TRUE;
1990 }
1991
1992 /*!
1993  * @brief 宿屋の利用サブルーチン
1994  * @details inn commands\n
1995  * Note that resting for the night was a perfect way to avoid player\n
1996  * ghosts in the town *if* you could only make it to the inn in time (-:\n
1997  * Now that the ghosts are temporarily disabled in 2.8.X, this function\n
1998  * will not be that useful.  I will keep it in the hopes the player\n
1999  * ghost code does become a reality again. Does help to avoid filthy urchins.\n
2000  * Resting at night is also a quick way to restock stores -KMW-\n
2001  * @param cmd 宿屋の利用施設ID
2002  * @return 施設の利用が実際に行われたか否か。
2003  */
2004 static bool inn_comm(int cmd)
2005 {
2006         switch (cmd)
2007         {
2008                 case BACT_FOOD: /* Buy food & drink */
2009                         if (p_ptr->food >= PY_FOOD_FULL)
2010                         {
2011                                 msg_print(_("今は満腹だ。", "You are full now."));
2012                                 return FALSE;
2013                         }
2014                         msg_print(_("バーテンはいくらかの食べ物とビールをくれた。", "The barkeep gives you some gruel and a beer."));
2015                         (void)set_food(PY_FOOD_MAX - 1);
2016                         break;
2017
2018                 case BACT_REST: /* Rest for the night */
2019                         if ((p_ptr->poisoned) || (p_ptr->cut))
2020                         {
2021                                 msg_print(_("あなたに必要なのは部屋ではなく、治療者です。", "You need a healer, not a room."));
2022                                 msg_print(NULL);
2023                                 msg_print(_("すみません、でもうちで誰かに死なれちゃ困りますんで。", "Sorry, but don't want anyone dying in here."));
2024                         }
2025                         else
2026                         {
2027                                 s32b oldturn = current_world_ptr->game_turn;
2028                                 int prev_day, prev_hour, prev_min;
2029
2030                                 extract_day_hour_min(&prev_day, &prev_hour, &prev_min);
2031                                 if ((prev_hour >= 6) && (prev_hour <= 17)) 
2032                                         do_cmd_write_nikki(NIKKI_BUNSHOU, 0, _("宿屋に泊まった。", "stay over daytime at the inn."));
2033                                 else
2034                                         do_cmd_write_nikki(NIKKI_BUNSHOU, 0, _("宿屋に泊まった。", "stay over night at the inn."));
2035                                 
2036                                 current_world_ptr->game_turn = (current_world_ptr->game_turn / (TURNS_PER_TICK * TOWN_DAWN / 2) + 1) * (TURNS_PER_TICK * TOWN_DAWN / 2);
2037                                 if (current_world_ptr->dungeon_turn < current_world_ptr->dungeon_turn_limit)
2038                                 {
2039                                         current_world_ptr->dungeon_turn += MIN((current_world_ptr->game_turn - oldturn), TURNS_PER_TICK * 250) * INN_DUNGEON_TURN_ADJ;
2040                                         if (current_world_ptr->dungeon_turn > current_world_ptr->dungeon_turn_limit) current_world_ptr->dungeon_turn = current_world_ptr->dungeon_turn_limit;
2041                                 }
2042
2043                                 prevent_turn_overflow();
2044
2045                                 if ((prev_hour >= 18) && (prev_hour <= 23)) do_cmd_write_nikki(NIKKI_HIGAWARI, 0, NULL);
2046                                 p_ptr->chp = p_ptr->mhp;
2047
2048                                 if (ironman_nightmare)
2049                                 {
2050                                         msg_print(_("眠りに就くと恐ろしい光景が心をよぎった。", "Horrible visions flit through your mind as you sleep."));
2051
2052                                         /* Have some nightmares */
2053                                         while(1)
2054                                         {
2055                                                 sanity_blast(NULL, FALSE);
2056                                                 if (!one_in_(3)) break;
2057                                         }
2058
2059                                         msg_print(_("あなたは絶叫して目を覚ました。", "You awake screaming."));
2060                                         do_cmd_write_nikki(NIKKI_BUNSHOU, 0, _("悪夢にうなされてよく眠れなかった。", "be troubled by a nightmare."));
2061                                 }
2062                                 else
2063                                 {
2064                                         set_blind(0);
2065                                         set_confused(0);
2066                                         p_ptr->stun = 0;
2067                                         p_ptr->chp = p_ptr->mhp;
2068                                         p_ptr->csp = p_ptr->msp;
2069                                         if (p_ptr->pclass == CLASS_MAGIC_EATER)
2070                                         {
2071                                                 int i;
2072                                                 for (i = 0; i < 72; i++)
2073                                                 {
2074                                                         p_ptr->magic_num1[i] = p_ptr->magic_num2[i] * EATER_CHARGE;
2075                                                 }
2076                                                 for (; i < 108; i++)
2077                                                 {
2078                                                         p_ptr->magic_num1[i] = 0;
2079                                                 }
2080                                         }
2081
2082                                         if ((prev_hour >= 6) && (prev_hour <= 17))
2083                                         {
2084                                                 msg_print(_("あなたはリフレッシュして目覚め、夕方を迎えた。", "You awake refreshed for the evening."));
2085                                                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, _("夕方を迎えた。", "awake refreshed."));
2086                                         }
2087                                         else
2088                                         {
2089                                                 msg_print(_("あなたはリフレッシュして目覚め、新たな日を迎えた。", "You awake refreshed for the new day."));
2090                                                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, _("すがすがしい朝を迎えた。", "awake refreshed."));
2091                                         }
2092                                 }
2093                         }
2094                         break;
2095
2096                 case BACT_RUMORS: /* Listen for rumors */
2097                         {
2098                                 display_rumor(TRUE);
2099                                 break;
2100                         }
2101         }
2102
2103         return (TRUE);
2104 }
2105
2106
2107 /*!
2108  * @brief クエスト情報を表示しつつ処理する。/ Display quest information
2109  * @param questnum クエストのID
2110  * @param do_init クエストの開始処理(TRUE)、結果処理か(FALSE)
2111  * @return なし
2112  */
2113 static void get_questinfo(IDX questnum, bool do_init)
2114 {
2115         int i;
2116         QUEST_IDX old_quest;
2117         GAME_TEXT tmp_str[80];
2118
2119         /* Clear the text */
2120         for (i = 0; i < 10; i++)
2121         {
2122                 quest_text[i][0] = '\0';
2123         }
2124
2125         quest_text_line = 0;
2126
2127         /* Set the quest number temporary */
2128         old_quest = p_ptr->inside_quest;
2129         p_ptr->inside_quest = questnum;
2130
2131         /* Get the quest text */
2132         init_flags = INIT_SHOW_TEXT;
2133         if (do_init) init_flags |= INIT_ASSIGN;
2134
2135         process_dungeon_file("q_info.txt", 0, 0, 0, 0);
2136
2137         /* Reset the old quest number */
2138         p_ptr->inside_quest = old_quest;
2139
2140         /* Print the quest info */
2141         sprintf(tmp_str, _("クエスト情報 (危険度: %d 階相当)", "Quest Information (Danger level: %d)"), (int)quest[questnum].level);
2142
2143         prt(tmp_str, 5, 0);
2144
2145         prt(quest[questnum].name, 7, 0);
2146
2147         for (i = 0; i < 10; i++)
2148         {
2149                 c_put_str(TERM_YELLOW, quest_text[i], i + 8, 0);
2150         }
2151 }
2152
2153 /*!
2154  * @brief クエスト処理のメインルーチン / Request a quest from the Lord.
2155  * @return なし
2156  */
2157 static void castle_quest(void)
2158 {
2159         QUEST_IDX q_index = 0;
2160         monster_race *r_ptr;
2161         quest_type *q_ptr;
2162         concptr name;
2163
2164
2165         clear_bldg(4, 18);
2166
2167         /* Current quest of the building */
2168         q_index = current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].special;
2169
2170         /* Is there a quest available at the building? */
2171         if (!q_index)
2172         {
2173                 put_str(_("今のところクエストはありません。", "I don't have a quest for you at the moment."), 8, 0);
2174                 return;
2175         }
2176
2177         q_ptr = &quest[q_index];
2178
2179         /* Quest is completed */
2180         if (q_ptr->status == QUEST_STATUS_COMPLETED)
2181         {
2182                 /* Rewarded quest */
2183                 q_ptr->status = QUEST_STATUS_REWARDED;
2184
2185                 get_questinfo(q_index, FALSE);
2186
2187                 reinit_wilderness = TRUE;
2188         }
2189         /* Failed quest */
2190         else if (q_ptr->status == QUEST_STATUS_FAILED)
2191         {
2192                 get_questinfo(q_index, FALSE);
2193
2194                 /* Mark quest as done (but failed) */
2195                 q_ptr->status = QUEST_STATUS_FAILED_DONE;
2196
2197                 reinit_wilderness = TRUE;
2198         }
2199         /* Quest is still unfinished */
2200         else if (q_ptr->status == QUEST_STATUS_TAKEN)
2201         {
2202                 put_str(_("あなたは現在のクエストを終了させていません!", "You have not completed your current quest yet!"), 8, 0);
2203                 put_str(_("CTRL-Qを使えばクエストの状態がチェックできます。", "Use CTRL-Q to check the status of your quest."), 9, 0);
2204                 put_str(_("クエストを終わらせたら戻って来て下さい。", "Return when you have completed your quest."), 12, 0);
2205         }
2206         /* No quest yet */
2207         else if (q_ptr->status == QUEST_STATUS_UNTAKEN)
2208         {
2209                 q_ptr->status = QUEST_STATUS_TAKEN;
2210
2211                 reinit_wilderness = TRUE;
2212
2213                 /* Assign a new quest */
2214                 if (q_ptr->type == QUEST_TYPE_KILL_ANY_LEVEL)
2215                 {
2216                         if (q_ptr->r_idx == 0)
2217                         {
2218                                 /* Random monster at least 5 - 10 levels out of deep */
2219                                 q_ptr->r_idx = get_mon_num(q_ptr->level + 4 + randint1(6));
2220                         }
2221
2222                         r_ptr = &r_info[q_ptr->r_idx];
2223
2224                         while ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->rarity != 1))
2225                         {
2226                                 q_ptr->r_idx = get_mon_num(q_ptr->level) + 4 + randint1(6);
2227                                 r_ptr = &r_info[q_ptr->r_idx];
2228                         }
2229
2230                         if (q_ptr->max_num == 0)
2231                         {
2232                                 /* Random monster number */
2233                                 if (randint1(10) > 7)
2234                                         q_ptr->max_num = 1;
2235                                 else
2236                                         q_ptr->max_num = randint1(3) + 1;
2237                         }
2238
2239                         q_ptr->cur_num = 0;
2240                         name = (r_name + r_ptr->name);
2241                         msg_format(_("クエスト: %sを %d体倒す", "Your quest: kill %d %s"), name,q_ptr->max_num);
2242                 }
2243                 else
2244                 {
2245                         get_questinfo(q_index, TRUE);
2246                 }
2247         }
2248 }
2249
2250
2251 /*!
2252  * @brief 町に関するヘルプを表示する / Display town history
2253  * @return なし
2254  */
2255 static void town_history(void)
2256 {
2257         screen_save();
2258
2259         /* Peruse the building help file */
2260         (void)show_file(TRUE, _("jbldg.txt", "bldg.txt"), NULL, 0, 0);
2261         screen_load();
2262 }
2263
2264 /*!
2265  * @brief 攻撃時スレイによるダメージ期待値修正計算 / critical happens at i / 10000
2266  * @param dam 基本ダメージ
2267  * @param mult スレイ倍率(掛け算部分)
2268  * @param div スレイ倍率(割り算部分)
2269  * @param force 理力特別計算フラグ
2270  * @return ダメージ期待値
2271  */
2272 static HIT_POINT calc_slaydam(HIT_POINT dam, int mult, int div, bool force)
2273 {
2274         int tmp;
2275         if(force)
2276         {
2277                 tmp = dam * 60;
2278                 tmp *= mult * 3;
2279                 tmp /= div * 2;
2280                 tmp += dam * 60 * 2;
2281                 tmp /= 60;
2282         }
2283         else
2284         {
2285                 tmp = dam * 60;
2286                 tmp *= mult; 
2287                 tmp /= div;
2288                 tmp /= 60;
2289         }
2290         return tmp;
2291 }
2292
2293 /*!
2294  * @brief 攻撃時の期待値計算(スレイ→重量クリティカル→切れ味効果)
2295  * @param dam 基本ダメージ
2296  * @param mult スレイ倍率(掛け算部分)
2297  * @param div スレイ倍率(割り算部分)
2298  * @param force 理力特別計算フラグ
2299  * @param weight 重量
2300  * @param plus 武器ダメージ修正
2301  * @param meichuu 命中値
2302  * @param dokubari 毒針処理か否か
2303  * @param vorpal_mult 切れ味倍率(掛け算部分)
2304  * @param vorpal_div 切れ味倍率(割り算部分)
2305  * @return ダメージ期待値
2306  */
2307 static u32b calc_expect_dice(u32b dam, int mult, int div, bool force, WEIGHT weight, int plus, s16b meichuu, bool dokubari, int vorpal_mult, int vorpal_div)
2308 {
2309         dam = calc_slaydam(dam, mult, div, force);
2310         dam = calc_expect_crit(weight, plus, dam, meichuu, dokubari);
2311         dam = calc_slaydam(dam, vorpal_mult, vorpal_div, FALSE);
2312         return dam;
2313 }
2314
2315
2316 /*!
2317  * @brief 武器の各条件毎のダメージ期待値を表示する。
2318  * @param r 表示行
2319  * @param c 表示列
2320  * @param mindice ダイス部分最小値
2321  * @param maxdice ダイス部分最大値
2322  * @param blows 攻撃回数
2323  * @param dam_bonus ダメージ修正値
2324  * @param attr 条件内容
2325  * @param color 条件内容の表示色
2326  * @details
2327  * Display the damage figure of an object\n
2328  * (used by compare_weapon_aux)\n
2329  * \n
2330  * Only accurate for the current weapon, because it includes\n
2331  * the current +dam of the player.\n
2332  * @return なし
2333  */
2334 static void show_weapon_dmg(int r, int c, int mindice, int maxdice, int blows, int dam_bonus, concptr attr, byte color)
2335 {
2336         GAME_TEXT tmp_str[80];
2337         int mindam, maxdam;
2338         
2339         mindam = blows * (mindice + dam_bonus);
2340         maxdam = blows * (maxdice + dam_bonus);
2341
2342         /* Print the intro text */
2343         c_put_str(color, attr, r, c);
2344
2345         /* Calculate the min and max damage figures */
2346         sprintf(tmp_str, _("1ターン: %d-%d ダメージ", "Attack: %d-%d damage"), mindam, maxdam);
2347         
2348         /* Print the damage */
2349         put_str(tmp_str, r, c + 8);
2350 }
2351
2352
2353 /*!
2354  * @brief 武器一つ毎のダメージ情報を表示する。
2355  * @param o_ptr オブジェクトの構造体の参照ポインタ。
2356  * @param col 表示する行の上端
2357  * @param r 表示する列の左端
2358  * @details
2359  * Show the damage figures for the various monster types\n
2360  * \n
2361  * Only accurate for the current weapon, because it includes\n
2362  * the current number of blows for the player.\n
2363  * @return なし
2364  */
2365 static void compare_weapon_aux(object_type *o_ptr, int col, int r)
2366 {
2367         BIT_FLAGS flgs[TR_FLAG_SIZE];
2368         int blow = p_ptr->num_blow[0];
2369         bool force = FALSE;
2370         bool dokubari = FALSE;
2371         
2372         /* Effective dices */
2373         int eff_dd = o_ptr->dd + p_ptr->to_dd[0];
2374         int eff_ds = o_ptr->ds + p_ptr->to_ds[0];
2375         
2376         int mindice = eff_dd;
2377         int maxdice = eff_ds * eff_dd;
2378         int mindam = 0;
2379         int maxdam = 0;
2380         int vorpal_mult = 1;
2381         int vorpal_div = 1;
2382         int dmg_bonus = o_ptr->to_d + p_ptr->to_d[0];
2383         
2384
2385         /* Get the flags of the weapon */
2386         object_flags(o_ptr, flgs);
2387         
2388         if((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DOKUBARI)) dokubari = TRUE;
2389         
2390         
2391         /* Show Critical Damage*/
2392         mindam = calc_expect_crit(o_ptr->weight, o_ptr->to_h, mindice, p_ptr->to_h[0], dokubari);
2393         maxdam = calc_expect_crit(o_ptr->weight, o_ptr->to_h, maxdice, p_ptr->to_h[0], dokubari);
2394         
2395         show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus, _("会心:", "Critical:"), TERM_L_RED);
2396
2397         
2398         /* Vorpal Hit*/
2399         if ((have_flag(flgs, TR_VORPAL) || hex_spelling(HEX_RUNESWORD)))
2400         {
2401                 if((o_ptr->name1 == ART_VORPAL_BLADE) || (o_ptr->name1 == ART_CHAINSWORD))
2402                 {
2403                         vorpal_mult = 5;
2404                         vorpal_div = 3;
2405                 }
2406                 else
2407                 {
2408                         vorpal_mult = 11;
2409                         vorpal_div = 9;
2410                 }
2411                 
2412                 mindam = calc_expect_dice(mindice, 1, 1, FALSE, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2413                 maxdam = calc_expect_dice(maxdice, 1, 1, FALSE, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);         
2414                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus, _("切れ味:", "Vorpal:") , TERM_L_RED);
2415         }       
2416         
2417         if ((p_ptr->pclass != CLASS_SAMURAI) && have_flag(flgs, TR_FORCE_WEAPON) && (p_ptr->csp > (o_ptr->dd * o_ptr->ds / 5)))
2418         {
2419                 force = TRUE;
2420                 
2421                 mindam = calc_expect_dice(mindice, 1, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2422                 maxdam = calc_expect_dice(maxdice, 1, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2423                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus, _("理力:", "Force  :"), TERM_L_BLUE);
2424         }
2425                 
2426         /* Print the relevant lines */
2427         if (have_flag(flgs, TR_KILL_ANIMAL))
2428         {
2429                 mindam = calc_expect_dice(mindice, 4, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2430                 maxdam = calc_expect_dice(maxdice, 4, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);         
2431                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("動物:", "Animals:"), TERM_YELLOW);
2432         }
2433         else if (have_flag(flgs, TR_SLAY_ANIMAL)) 
2434         {
2435                 mindam = calc_expect_dice(mindice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2436                 maxdam = calc_expect_dice(maxdice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2437                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("動物:", "Animals:"), TERM_YELLOW);
2438         }
2439         if (have_flag(flgs, TR_KILL_EVIL))
2440         {       
2441                 mindam = calc_expect_dice(mindice, 7, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2442                 maxdam = calc_expect_dice(maxdice, 7, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2443                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("邪悪:", "Evil:"), TERM_YELLOW);
2444         }
2445         else if (have_flag(flgs, TR_SLAY_EVIL))
2446         {       
2447                 mindam = calc_expect_dice(mindice, 2, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2448                 maxdam = calc_expect_dice(maxdice, 2, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);         
2449                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("邪悪:", "Evil:"), TERM_YELLOW);
2450         }
2451         if (have_flag(flgs, TR_KILL_HUMAN))
2452         {       
2453                 mindam = calc_expect_dice(mindice, 4, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2454                 maxdam = calc_expect_dice(maxdice, 4, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2455                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("人間:", "Human:"), TERM_YELLOW);
2456         }
2457         else if (have_flag(flgs, TR_SLAY_HUMAN))
2458         {       
2459                 mindam = calc_expect_dice(mindice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2460                 maxdam = calc_expect_dice(maxdice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2461                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("人間:", "Human:"), TERM_YELLOW);
2462         }
2463         if (have_flag(flgs, TR_KILL_UNDEAD))
2464         {
2465                 mindam = calc_expect_dice(mindice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2466                 maxdam = calc_expect_dice(maxdice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2467                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("不死:", "Undead:"), TERM_YELLOW);
2468         }
2469         else if (have_flag(flgs, TR_SLAY_UNDEAD)) 
2470         {
2471                 mindam = calc_expect_dice(mindice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2472                 maxdam = calc_expect_dice(maxdice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2473                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("不死:", "Undead:"), TERM_YELLOW);
2474         }
2475         if (have_flag(flgs, TR_KILL_DEMON))
2476         {       
2477                 mindam = calc_expect_dice(mindice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2478                 maxdam = calc_expect_dice(maxdice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2479                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("悪魔:", "Demons:") , TERM_YELLOW);
2480         }
2481         else if (have_flag(flgs, TR_SLAY_DEMON))
2482         {       
2483                 mindam = calc_expect_dice(mindice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2484                 maxdam = calc_expect_dice(maxdice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2485                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus, _("悪魔:", "Demons:") , TERM_YELLOW);
2486         }
2487         if (have_flag(flgs, TR_KILL_ORC))
2488         {
2489                 mindam = calc_expect_dice(mindice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2490                 maxdam = calc_expect_dice(maxdice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2491                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("オーク:", "Orcs:"), TERM_YELLOW);
2492         }
2493         else if (have_flag(flgs, TR_SLAY_ORC))
2494         {
2495                 mindam = calc_expect_dice(mindice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2496                 maxdam = calc_expect_dice(maxdice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2497                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("オーク:", "Orcs:"), TERM_YELLOW);
2498         }
2499         if (have_flag(flgs, TR_KILL_TROLL))
2500         {
2501                 mindam = calc_expect_dice(mindice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2502                 maxdam = calc_expect_dice(maxdice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2503                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("トロル:", "Trolls:") , TERM_YELLOW);
2504         }
2505         else if (have_flag(flgs, TR_SLAY_TROLL))
2506         {
2507                 mindam = calc_expect_dice(mindice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2508                 maxdam = calc_expect_dice(maxdice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2509                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,   _("トロル:", "Trolls:") , TERM_YELLOW);
2510         }
2511         if (have_flag(flgs, TR_KILL_GIANT))
2512         {
2513                 mindam = calc_expect_dice(mindice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2514                 maxdam = calc_expect_dice(maxdice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2515                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("巨人:", "Giants:"), TERM_YELLOW);
2516         }
2517         else if (have_flag(flgs, TR_SLAY_GIANT))
2518         {
2519                 mindam = calc_expect_dice(mindice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2520                 maxdam = calc_expect_dice(maxdice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2521                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("巨人:", "Giants:"), TERM_YELLOW);
2522         }
2523         if (have_flag(flgs, TR_KILL_DRAGON))
2524         {
2525                 mindam = calc_expect_dice(mindice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2526                 maxdam = calc_expect_dice(maxdice, 5, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2527                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("竜:", "Dragons:"), TERM_YELLOW);
2528         }
2529         else if (have_flag(flgs, TR_SLAY_DRAGON))
2530         {               
2531                 mindam = calc_expect_dice(mindice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2532                 maxdam = calc_expect_dice(maxdice, 3, 1, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2533                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,   _("竜:", "Dragons:"), TERM_YELLOW);
2534         }
2535         if (have_flag(flgs, TR_BRAND_ACID))
2536         {
2537                 mindam = calc_expect_dice(mindice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2538                 maxdam = calc_expect_dice(maxdice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2539                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("酸属性:", "Acid:"), TERM_RED);
2540         }
2541         if (have_flag(flgs, TR_BRAND_ELEC))
2542         {
2543                 mindam = calc_expect_dice(mindice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2544                 maxdam = calc_expect_dice(maxdice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2545                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("電属性:", "Elec:"), TERM_RED);
2546         }
2547         if (have_flag(flgs, TR_BRAND_FIRE))
2548         {
2549                 mindam = calc_expect_dice(mindice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2550                 maxdam = calc_expect_dice(maxdice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2551                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("炎属性:", "Fire:"), TERM_RED);
2552         }
2553         if (have_flag(flgs, TR_BRAND_COLD))
2554         {
2555                 mindam = calc_expect_dice(mindice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2556                 maxdam = calc_expect_dice(maxdice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2557                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus,  _("冷属性:", "Cold:"), TERM_RED);
2558         }
2559         if (have_flag(flgs, TR_BRAND_POIS))
2560         {
2561                 mindam = calc_expect_dice(mindice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2562                 maxdam = calc_expect_dice(maxdice, 5, 2, force, o_ptr->weight, o_ptr->to_h, p_ptr->to_h[0], dokubari, vorpal_mult, vorpal_div);
2563                 show_weapon_dmg(r++, col, mindam, maxdam, blow, dmg_bonus, _("毒属性:", "Poison:"), TERM_RED);
2564         }
2565 }
2566
2567 /*!
2568  * @brief 武器匠における武器一つ毎の完全情報を表示する。
2569  * @param o_ptr オブジェクトの構造体の参照ポインタ。
2570  * @param row 表示する列の左端
2571  * @param col 表示する行の上端
2572  * @details
2573  * Displays all info about a weapon
2574  *
2575  * Only accurate for the current weapon, because it includes
2576  * various info about the player's +to_dam and number of blows.
2577  * @return なし
2578  */
2579 static void list_weapon(object_type *o_ptr, TERM_LEN row, TERM_LEN col)
2580 {
2581         GAME_TEXT o_name[MAX_NLEN];
2582         GAME_TEXT tmp_str[80];
2583
2584         DICE_NUMBER eff_dd = o_ptr->dd + p_ptr->to_dd[0];
2585         DICE_SID eff_ds = o_ptr->ds + p_ptr->to_ds[0];
2586         HIT_RELIABILITY reli = p_ptr->skill_thn + (p_ptr->to_h[0] + o_ptr->to_h) * BTH_PLUS_ADJ;
2587
2588         /* Print the weapon name */
2589         object_desc(o_name, o_ptr, OD_NAME_ONLY);
2590         c_put_str(TERM_YELLOW, o_name, row, col);
2591
2592         /* Print the player's number of blows */
2593         sprintf(tmp_str, _("攻撃回数: %d", "Number of Blows: %d"), p_ptr->num_blow[0]);
2594         put_str(tmp_str, row+1, col);
2595
2596         /* Print to_hit and to_dam of the weapon */
2597         sprintf(tmp_str, _("命中率:  0  50 100 150 200 (敵のAC)", "To Hit:  0  50 100 150 200 (AC)"));
2598         put_str(tmp_str, row+2, col);
2599
2600         /* Print the weapons base damage dice */
2601         sprintf(tmp_str, "        %2d  %2d  %2d  %2d  %2d (%%)",
2602                 (int)hit_chance(reli, 0),
2603                 (int)hit_chance(reli, 50),
2604                 (int)hit_chance(reli, 100),
2605                 (int)hit_chance(reli, 150),
2606                 (int)hit_chance(reli, 200));
2607         put_str(tmp_str, row+3, col);
2608         c_put_str(TERM_YELLOW, _("可能なダメージ:", "Possible Damage:"), row+5, col);
2609
2610         /* Damage for one blow (if it hits) */
2611         sprintf(tmp_str, _("攻撃一回につき %d-%d", "One Strike: %d-%d damage"),
2612             (int)(eff_dd + o_ptr->to_d + p_ptr->to_d[0]),
2613                 (int)(eff_ds * eff_dd + o_ptr->to_d + p_ptr->to_d[0]));
2614         put_str(tmp_str, row+6, col+1);
2615
2616         /* Damage for the complete attack (if all blows hit) */
2617         sprintf(tmp_str, _("1ターンにつき %d-%d", "One Attack: %d-%d damage"),
2618                 (int)(p_ptr->num_blow[0] * (eff_dd + o_ptr->to_d + p_ptr->to_d[0])),
2619                         (int)(p_ptr->num_blow[0] * (eff_ds * eff_dd + o_ptr->to_d + p_ptr->to_d[0])));
2620         put_str(tmp_str, row+7, col+1);
2621 }
2622
2623 /*!
2624  * @brief 武器匠鑑定1回分(オブジェクト2種)の処理。/ Compare weapons
2625  * @details 
2626  * Copies the weapons to compare into the weapon-slot and\n
2627  * compares the values for both weapons.\n
2628  * 武器1つだけで比較をしないなら費用は半額になる。
2629  * @param bcost 基本鑑定費用
2630  * @return 最終的にかかった費用
2631  */
2632 static PRICE compare_weapons(PRICE bcost)
2633 {
2634         int i, n;
2635         OBJECT_IDX item, item2;
2636         object_type *o_ptr[2];
2637         object_type orig_weapon;
2638         object_type *i_ptr;
2639         concptr q, s;
2640         TERM_LEN row = 2;
2641         TERM_LEN wid = 38, mgn = 2;
2642         bool old_character_xtra = current_world_ptr->character_xtra;
2643         char ch;
2644         PRICE total = 0;
2645         PRICE cost = 0; /* First time no price */
2646
2647         screen_save();
2648         clear_bldg(0, 22);
2649
2650         /* Store copy of original wielded weapon */
2651         i_ptr = &p_ptr->inventory_list[INVEN_RARM];
2652         object_copy(&orig_weapon, i_ptr);
2653
2654         item_tester_hook = item_tester_hook_orthodox_melee_weapons;
2655
2656         /* Get the first weapon */
2657         q = _("第一の武器は?", "What is your first weapon? ");
2658         s = _("比べるものがありません。", "You have nothing to compare.");
2659
2660         o_ptr[0] = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | IGNORE_BOTHHAND_SLOT));
2661         if (!o_ptr[0])
2662         {
2663                 screen_load();
2664                 return (0);
2665         }
2666
2667         n = 1;
2668         total = bcost;
2669
2670         while (TRUE)
2671         {
2672                 clear_bldg(0, 22);
2673
2674                 /* Only compare melee weapons */
2675                 item_tester_hook = item_tester_hook_orthodox_melee_weapons;
2676
2677                 /* Hack -- prevent "icky" message */
2678                 current_world_ptr->character_xtra = TRUE;
2679
2680                 /* Diaplay selected weapon's infomation */
2681                 for (i = 0; i < n; i++)
2682                 {
2683                         int col = (wid * i + mgn);
2684
2685                         /* Copy i-th weapon into the weapon slot (if it's not already there) */
2686                         if (o_ptr[i] != i_ptr) object_copy(i_ptr, o_ptr[i]);
2687
2688                         p_ptr->update |= PU_BONUS;
2689                         handle_stuff();
2690
2691                         /* List the new values */
2692                         list_weapon(o_ptr[i], row, col);
2693                         compare_weapon_aux(o_ptr[i], col, row + 8);
2694
2695                         /* Copy back the original weapon into the weapon slot */
2696                         object_copy(i_ptr, &orig_weapon);
2697                 }
2698
2699                 /* Reset the values for the old weapon */
2700                 p_ptr->update |= PU_BONUS;
2701                 handle_stuff();
2702
2703                 current_world_ptr->character_xtra = old_character_xtra;
2704
2705 #ifdef JP
2706                 put_str(format("[ 比較対象: 's'で変更 ($%d) ]", cost), 1, (wid + mgn));
2707                 put_str("(一番高いダメージが適用されます。複数の倍打効果は足し算されません。)", row + 4, 0);
2708                 prt("現在の技量から判断すると、あなたの武器は以下のような威力を発揮します:", 0, 0);
2709 #else
2710                 put_str(format("[ 's' Select secondary weapon($%d) ]", cost), row + 1, (wid * i + mgn));
2711                 put_str("(Only highest damage applies per monster. Special damage not cumulative.)", row + 4, 0);
2712                 prt("Based on your current abilities, here is what your weapons will do", 0, 0);
2713 #endif
2714
2715                 flush();
2716                 ch = inkey();
2717
2718                 if (ch == 's')
2719                 {
2720                         if (total + cost > p_ptr->au)
2721                         {
2722                                 msg_print(_("お金が足りません!", "You don't have enough money!"));
2723                                 msg_print(NULL);
2724                                 continue;
2725                         }
2726
2727                         q = _("第二の武器は?", "What is your second weapon? ");
2728                         s = _("比べるものがありません。", "You have nothing to compare.");
2729
2730                         /* Get the second weapon */
2731                         o_ptr[1] = choose_object(&item2, q, s, (USE_EQUIP | USE_INVEN | IGNORE_BOTHHAND_SLOT));
2732                         if (!o_ptr[1]) continue;
2733
2734                         total += cost;
2735                         cost = bcost / 2;
2736                         n = 2;
2737                 }
2738                 else
2739                 {
2740                         break;
2741                 }
2742         }
2743         screen_load();
2744
2745         return (total);
2746 }
2747
2748
2749 /*!
2750  * @brief ACから回避率、ダメージ減少率を計算し表示する。 / Evaluate AC
2751  * @details 
2752  * Calculate and display the dodge-rate and the protection-rate
2753  * based on AC
2754  * @param iAC プレイヤーのAC。
2755  * @return 常にTRUEを返す。
2756  */
2757 static bool eval_ac(ARMOUR_CLASS iAC)
2758 {
2759 #ifdef JP
2760         const char memo[] =
2761                 "ダメージ軽減率とは、敵の攻撃が当たった時そのダメージを\n"
2762                 "何パーセント軽減するかを示します。\n"
2763                 "ダメージ軽減は通常の直接攻撃(種類が「攻撃する」と「粉砕する」の物)\n"
2764                 "に対してのみ効果があります。\n \n"
2765                 "敵のレベルとは、その敵が通常何階に現れるかを示します。\n \n"
2766                 "回避率は敵の直接攻撃を何パーセントの確率で避けるかを示し、\n"
2767                 "敵のレベルとあなたのACによって決定されます。\n \n"
2768                 "ダメージ期待値とは、敵の100ポイントの通常攻撃に対し、\n"
2769                 "回避率とダメージ軽減率を考慮したダメージの期待値を示します。\n";
2770 #else
2771         const char memo[] =
2772                 "'Protection Rate' means how much damage is reduced by your armor.\n"
2773                 "Note that the Protection rate is effective only against normal "
2774                 "'attack' and 'shatter' type melee attacks, "
2775                 "and has no effect against any other types such as 'poison'.\n \n"
2776                 "'Dodge Rate' indicates the success rate on dodging the "
2777                 "monster's melee attacks.  "
2778                 "It is depend on the level of the monster and your AC.\n \n"
2779                 "'Average Damage' indicates the expected amount of damage "
2780                 "when you are attacked by normal melee attacks with power=100.";
2781 #endif
2782
2783         int protection;
2784         TERM_LEN col, row = 2;
2785         DEPTH lvl;
2786         char buf[80*20], *t;
2787
2788         /* AC lower than zero has no effect */
2789         if (iAC < 0) iAC = 0;
2790
2791         /* ダメージ軽減率を計算 */
2792         protection = 100 * MIN(iAC, 150) / 250;
2793
2794         screen_save();
2795         clear_bldg(0, 22);
2796
2797         put_str(format(_("あなたの現在のAC: %3d", "Your current AC : %3d"), iAC), row++, 0);
2798         put_str(format(_("ダメージ軽減率  : %3d%%", "Protection rate : %3d%%"), protection), row++, 0);
2799         row++;
2800
2801         put_str(_("敵のレベル      :", "Level of Monster:"), row + 0, 0);
2802         put_str(_("回避率          :", "Dodge Rate      :"), row + 1, 0);
2803         put_str(_("ダメージ期待値  :", "Average Damage  :"), row + 2, 0);
2804     
2805         for (col = 17 + 1, lvl = 0; lvl <= 100; lvl += 10, col += 5)
2806         {
2807                 int quality = 60 + lvl * 3; /* attack quality with power 60 */
2808                 int dodge;   /* 回避率(%) */
2809                 int average; /* ダメージ期待値 */
2810
2811                 put_str(format("%3d", lvl), row + 0, col);
2812
2813                 /* 回避率を計算 */
2814                 dodge = 5 + (MIN(100, 100 * (iAC * 3 / 4) / quality) * 9 + 5) / 10;
2815                 put_str(format("%3d%%", dodge), row + 1, col);
2816
2817                 /* 100点の攻撃に対してのダメージ期待値を計算 */
2818                 average = (100 - dodge) * (100 - protection) / 100;
2819                 put_str(format("%3d", average), row + 2, col);
2820         }
2821
2822         /* Display note */
2823         roff_to_buf(memo, 70, buf, sizeof(buf));
2824         for (t = buf; t[0]; t += strlen(t) + 1)
2825                 put_str(t, (row++) + 4, 4);
2826
2827         prt(_("現在のあなたの装備からすると、あなたの防御力はこれくらいです:", "Defense abilities from your current Armor Class are evaluated below."), 0, 0);
2828   
2829         flush();
2830         (void)inkey();
2831         screen_load();
2832
2833         return (TRUE);
2834 }
2835
2836
2837
2838 /*!
2839  * @brief 修復材料のオブジェクトから修復対象に特性を移植する。
2840  * @param to_ptr 修復対象オブジェクトの構造体の参照ポインタ。
2841  * @param from_ptr 修復材料オブジェクトの構造体の参照ポインタ。
2842  * @return 修復対象になるならTRUEを返す。
2843  */
2844 static void give_one_ability_of_object(object_type *to_ptr, object_type *from_ptr)
2845 {
2846         int i, n = 0;
2847         int cand[TR_FLAG_MAX];
2848         BIT_FLAGS to_flgs[TR_FLAG_SIZE];
2849         BIT_FLAGS from_flgs[TR_FLAG_SIZE];
2850
2851         object_flags(to_ptr, to_flgs);
2852         object_flags(from_ptr, from_flgs);
2853
2854         for (i = 0; i < TR_FLAG_MAX; i++)
2855         {
2856                 switch (i)
2857                 {
2858                 case TR_IGNORE_ACID:
2859                 case TR_IGNORE_ELEC:
2860                 case TR_IGNORE_FIRE:
2861                 case TR_IGNORE_COLD:
2862                 case TR_ACTIVATE:
2863                 case TR_RIDING:
2864                 case TR_THROW:
2865                 case TR_SHOW_MODS:
2866                 case TR_HIDE_TYPE:
2867                 case TR_ES_ATTACK:
2868                 case TR_ES_AC:
2869                 case TR_FULL_NAME:
2870                 case TR_FIXED_FLAVOR:
2871                         break;
2872                 default:
2873                         if (have_flag(from_flgs, i) && !have_flag(to_flgs, i))
2874                         {
2875                                 if (!(is_pval_flag(i) && (from_ptr->pval < 1))) cand[n++] = i;
2876                         }
2877                 }
2878         }
2879
2880         if (n > 0)
2881         {
2882                 int bmax;
2883                 int tr_idx = cand[randint0(n)];
2884                 add_flag(to_ptr->art_flags, tr_idx);
2885                 if (is_pval_flag(tr_idx)) to_ptr->pval = MAX(to_ptr->pval, 1);
2886                 bmax = MIN(3, MAX(1, 40 / (to_ptr->dd * to_ptr->ds)));
2887                 if (tr_idx == TR_BLOWS) to_ptr->pval = MIN(to_ptr->pval, bmax);
2888                 if (tr_idx == TR_SPEED) to_ptr->pval = MIN(to_ptr->pval, 4);
2889         }
2890
2891         return;
2892 }
2893
2894 /*!
2895  * @brief アイテム修復処理のメインルーチン / Repair broken weapon
2896  * @param bcost 基本修復費用
2897  * @return 実際にかかった費用
2898  */
2899 static PRICE repair_broken_weapon_aux(PRICE bcost)
2900 {
2901         PRICE cost;
2902         OBJECT_IDX item, mater;
2903         object_type *o_ptr, *mo_ptr; /* broken weapon and material weapon */
2904         object_kind *k_ptr;
2905         int i, dd_bonus, ds_bonus;
2906         KIND_OBJECT_IDX k_idx;
2907         char basenm[MAX_NLEN];
2908         concptr q, s;
2909         int row = 7;
2910         clear_bldg(0, 22);
2911
2912         prt(_("修復には材料となるもう1つの武器が必要です。", "Hand one material weapon to repair a broken weapon."), row, 2);
2913         prt(_("材料に使用した武器はなくなります!", "The material weapon will disappear after repairing!!"), row+1, 2);
2914
2915         q = _("どの折れた武器を修復しますか?", "Repair which broken weapon? ");
2916         s = _("修復できる折れた武器がありません。", "You have no broken weapon to repair.");
2917
2918         /* Only forge broken weapons */
2919         item_tester_hook = item_tester_hook_broken_weapon;
2920
2921         o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_EQUIP));
2922         if (!o_ptr) return (0);
2923
2924         /* It is worthless */
2925         if (!object_is_ego(o_ptr) && !object_is_artifact(o_ptr))
2926         {
2927                 msg_format(_("それは直してもしょうがないぜ。", "It is worthless to repair."));
2928                 return (0);
2929         }
2930
2931         /* They are too many */
2932         if (o_ptr->number > 1)
2933         {
2934                 msg_format(_("一度に複数を修復することはできません!", "They are too many to repair at once!"));
2935                 return (0);
2936         }
2937
2938         /* Display item name */
2939         object_desc(basenm, o_ptr, OD_NAME_ONLY);
2940         prt(format(_("修復する武器 : %s", "Repairing: %s"), basenm), row+3, 2);
2941
2942         q = _("材料となる武器は?", "Which weapon for material? ");
2943         s = _("材料となる武器がありません。", "You have no material to repair.");
2944
2945         /* Only forge broken weapons */
2946         item_tester_hook = item_tester_hook_orthodox_melee_weapons;
2947
2948         mo_ptr = choose_object(&mater, q, s, (USE_INVEN | USE_EQUIP));
2949         if (!mo_ptr) return (0);
2950         if (mater == item)
2951         {
2952                 msg_print(_("クラインの壷じゃない!", "This is not a klein bottle!"));
2953                 return (0);
2954         }
2955
2956         /* Display item name */
2957         object_desc(basenm, mo_ptr, OD_NAME_ONLY);
2958         prt(format(_("材料とする武器: %s", "Material : %s"), basenm), row+4, 2);
2959
2960         /* Get the value of one of the items (except curses) */
2961         cost = bcost + object_value_real(o_ptr) * 2;
2962
2963         if (!get_check(format(_("$%dかかりますがよろしいですか? ", "Costs %d gold, okay? "), cost))) return (0);
2964
2965         /* Check if the player has enough money */
2966         if (p_ptr->au < cost)
2967         {
2968                 object_desc(basenm, o_ptr, OD_NAME_ONLY);
2969                 msg_format(_("%sを修復するだけのゴールドがありません!", "You do not have the gold to repair %s!"), basenm);
2970                 msg_print(NULL);
2971                 return (0);
2972         }
2973
2974         p_ptr->total_weight -= o_ptr->weight;
2975
2976         if (o_ptr->sval == SV_BROKEN_DAGGER)
2977         {
2978                 KIND_OBJECT_IDX j;
2979                 int n = 1;
2980
2981                 /* Suppress compiler warning */
2982                 k_idx = 0;
2983
2984                 for (j = 1; j < max_k_idx; j++)
2985                 {
2986                         object_kind *k_aux_ptr = &k_info[j];
2987
2988                         if (k_aux_ptr->tval != TV_SWORD) continue;
2989                         if ((k_aux_ptr->sval == SV_BROKEN_DAGGER) ||
2990                                 (k_aux_ptr->sval == SV_BROKEN_SWORD) ||
2991                                 (k_aux_ptr->sval == SV_DOKUBARI)) continue;
2992                         if (k_aux_ptr->weight > 99) continue;
2993
2994                         if (one_in_(n)) 
2995                         {
2996                                 k_idx = j;
2997                                 n++;
2998                         }
2999                 }
3000         }
3001         else /* TV_BROKEN_SWORD */
3002         {
3003                 /* Repair to a sword or sometimes material's type weapon */
3004                 OBJECT_TYPE_VALUE tval = (one_in_(5) ? mo_ptr->tval : TV_SWORD);
3005
3006                 while(1)
3007                 {
3008                         object_kind *ck_ptr;
3009
3010                         k_idx = lookup_kind(tval, SV_ANY);
3011                         ck_ptr = &k_info[k_idx];
3012
3013                         if (tval == TV_SWORD)
3014                         {
3015                                 if ((ck_ptr->sval == SV_BROKEN_DAGGER) ||
3016                                         (ck_ptr->sval == SV_BROKEN_SWORD) ||
3017                                         (ck_ptr->sval == SV_DIAMOND_EDGE) ||
3018                                         (ck_ptr->sval == SV_DOKUBARI)) continue;
3019                         }
3020                         if (tval == TV_POLEARM)
3021                         {
3022                                 if ((ck_ptr->sval == SV_DEATH_SCYTHE) ||
3023                                         (ck_ptr->sval == SV_TSURIZAO)) continue;
3024                         }
3025                         if (tval == TV_HAFTED)
3026                         {
3027                                 if ((ck_ptr->sval == SV_GROND) ||
3028                                         (ck_ptr->sval == SV_WIZSTAFF) ||
3029                                         (ck_ptr->sval == SV_NAMAKE_HAMMER)) continue;
3030                         }
3031
3032                         break;
3033                 }
3034         }
3035
3036         /* Calculate dice bonuses */
3037         dd_bonus = o_ptr->dd - k_info[o_ptr->k_idx].dd;
3038         ds_bonus = o_ptr->ds - k_info[o_ptr->k_idx].ds;
3039         dd_bonus += mo_ptr->dd - k_info[mo_ptr->k_idx].dd;
3040         ds_bonus += mo_ptr->ds - k_info[mo_ptr->k_idx].ds;
3041
3042         /* Change base object */
3043         k_ptr = &k_info[k_idx];
3044         o_ptr->k_idx = k_idx;
3045         o_ptr->weight = k_ptr->weight;
3046         o_ptr->tval = k_ptr->tval;
3047         o_ptr->sval = k_ptr->sval;
3048         o_ptr->dd = k_ptr->dd;
3049         o_ptr->ds = k_ptr->ds;
3050
3051         /* Copy base object's ability */
3052         for (i = 0; i < TR_FLAG_SIZE; i++) o_ptr->art_flags[i] |= k_ptr->flags[i];
3053         if (k_ptr->pval) o_ptr->pval = MAX(o_ptr->pval, randint1(k_ptr->pval));
3054         if (have_flag(k_ptr->flags, TR_ACTIVATE)) o_ptr->xtra2 = (byte_hack)k_ptr->act_idx;
3055
3056         /* Dice up */
3057         if (dd_bonus > 0)
3058         {
3059                 o_ptr->dd++;
3060                 for (i = 1; i < dd_bonus; i++)
3061                 {
3062                         if (one_in_(o_ptr->dd + i)) o_ptr->dd++;
3063                 }
3064         }
3065         if (ds_bonus > 0)
3066         {
3067                 o_ptr->ds++;
3068                 for (i = 1; i < ds_bonus; i++)
3069                 {
3070                         if (one_in_(o_ptr->ds + i)) o_ptr->ds++;
3071                 }
3072         }
3073
3074         if (have_flag(k_ptr->flags, TR_BLOWS))
3075         {
3076                 int bmax = MIN(3, MAX(1, 40 / (o_ptr->dd * o_ptr->ds)));
3077                 o_ptr->pval = MIN(o_ptr->pval, bmax);
3078         }
3079
3080         /* Add one random ability from material weapon */
3081         give_one_ability_of_object(o_ptr, mo_ptr);
3082
3083         /* Add to-dam, to-hit and to-ac from material weapon */
3084         o_ptr->to_d += MAX(0, (mo_ptr->to_d / 3));
3085         o_ptr->to_h += MAX(0, (mo_ptr->to_h / 3));
3086         o_ptr->to_a += MAX(0, (mo_ptr->to_a));
3087
3088         if ((o_ptr->name1 == ART_NARSIL) ||
3089                 (object_is_random_artifact(o_ptr) && one_in_(1)) ||
3090                 (object_is_ego(o_ptr) && one_in_(7)))
3091         {
3092                 /* Forge it */
3093                 if (object_is_ego(o_ptr))
3094                 {
3095                         add_flag(o_ptr->art_flags, TR_IGNORE_FIRE);
3096                         add_flag(o_ptr->art_flags, TR_IGNORE_ACID);
3097                 }
3098
3099                 /* Add one random ability from material weapon */
3100                 give_one_ability_of_object(o_ptr, mo_ptr);
3101
3102                 /* Add one random activation */
3103                 if (!activation_index(o_ptr)) one_activation(o_ptr);
3104
3105                 /* Narsil */
3106                 if (o_ptr->name1 == ART_NARSIL)
3107                 {
3108                         one_high_resistance(o_ptr);
3109                         one_ability(o_ptr);
3110                 }
3111
3112                 msg_print(_("これはかなりの業物だったようだ。", "This blade seems to be exceptionally."));
3113         }
3114
3115         object_desc(basenm, o_ptr, OD_NAME_ONLY);
3116 #ifdef JP
3117         msg_format("$%dで%sに修復しました。", cost, basenm);
3118 #else
3119         msg_format("Repaired into %s for %d gold.", basenm, cost);
3120 #endif
3121         msg_print(NULL);
3122
3123         /* Remove BROKEN flag */
3124         o_ptr->ident &= ~(IDENT_BROKEN);
3125
3126         /* Add repaired flag */
3127         o_ptr->discount = 99;
3128
3129         p_ptr->total_weight += o_ptr->weight;
3130         calc_android_exp();
3131
3132         /* Decrease material object */
3133         inven_item_increase(mater, -1);
3134         inven_item_optimize(mater);
3135
3136         /* Copyback */
3137         p_ptr->update |= PU_BONUS;
3138         handle_stuff();
3139
3140         /* Something happened */
3141         return (cost);
3142 }
3143
3144 /*!
3145  * @brief アイテム修復処理の過渡ルーチン / Repair broken weapon
3146  * @param bcost 基本鑑定費用
3147  * @return 実際にかかった費用
3148  */
3149 static int repair_broken_weapon(PRICE bcost)
3150 {
3151         PRICE cost;
3152         screen_save();
3153         cost = repair_broken_weapon_aux(bcost);
3154         screen_load();
3155         return cost;
3156 }
3157
3158
3159 /*!
3160  * @brief アイテムの強化を行う。 / Enchant item
3161  * @param cost 1回毎の費用
3162  * @param to_hit 命中をアップさせる量
3163  * @param to_dam ダメージをアップさせる量
3164  * @param to_ac ACをアップさせる量
3165  * @return 実際に行ったらTRUE
3166  */
3167 static bool enchant_item(PRICE cost, HIT_PROB to_hit, HIT_POINT to_dam, ARMOUR_CLASS to_ac)
3168 {
3169         int i;
3170         OBJECT_IDX item;
3171         bool okay = FALSE;
3172         object_type *o_ptr;
3173         concptr q, s;
3174         int maxenchant = (p_ptr->lev / 5);
3175         char tmp_str[MAX_NLEN];
3176
3177         clear_bldg(4, 18);
3178         prt(format(_("現在のあなたの技量だと、+%d まで改良できます。", "  Based on your skill, we can improve up to +%d."), maxenchant), 5, 0);
3179         prt(format(_(" 改良の料金は一個につき$%d です。", "  The price for the service is %d gold per item."), cost), 7, 0);
3180
3181         q = _("どのアイテムを改良しますか?", "Improve which item? ");
3182         s = _("改良できるものがありません。", "You have nothing to improve.");
3183
3184         o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_EQUIP | IGNORE_BOTHHAND_SLOT));
3185         if (!o_ptr) return (FALSE);
3186
3187         /* Check if the player has enough money */
3188         if (p_ptr->au < (cost * o_ptr->number))
3189         {
3190                 object_desc(tmp_str, o_ptr, OD_NAME_ONLY);
3191                 msg_format(_("%sを改良するだけのゴールドがありません!", "You do not have the gold to improve %s!"), tmp_str);
3192                 return (FALSE);
3193         }
3194
3195         /* Enchant to hit */
3196         for (i = 0; i < to_hit; i++)
3197         {
3198                 if (o_ptr->to_h < maxenchant)
3199                 {
3200                         if (enchant(o_ptr, 1, (ENCH_TOHIT | ENCH_FORCE)))
3201                         {
3202                                 okay = TRUE;
3203                                 break;
3204                         }
3205                 }
3206         }
3207
3208         /* Enchant to damage */
3209         for (i = 0; i < to_dam; i++)
3210         {
3211                 if (o_ptr->to_d < maxenchant)
3212                 {
3213                         if (enchant(o_ptr, 1, (ENCH_TODAM | ENCH_FORCE)))
3214                         {
3215                                 okay = TRUE;
3216                                 break;
3217                         }
3218                 }
3219         }
3220
3221         /* Enchant to AC */
3222         for (i = 0; i < to_ac; i++)
3223         {
3224                 if (o_ptr->to_a < maxenchant)
3225                 {
3226                         if (enchant(o_ptr, 1, (ENCH_TOAC | ENCH_FORCE)))
3227                         {
3228                                 okay = TRUE;
3229                                 break;
3230                         }
3231                 }
3232         }
3233
3234         /* Failure */
3235         if (!okay)
3236         {
3237                 if (flush_failure) flush();
3238                 msg_print(_("改良に失敗した。", "The improvement failed."));
3239                 return (FALSE);
3240         }
3241         else
3242         {
3243                 object_desc(tmp_str, o_ptr, OD_NAME_AND_ENCHANT);
3244 #ifdef JP
3245                 msg_format("$%dで%sに改良しました。", cost * o_ptr->number, tmp_str);
3246 #else
3247                 msg_format("Improved into %s for %d gold.", tmp_str, cost * o_ptr->number);
3248 #endif
3249
3250                 /* Charge the money */
3251                 p_ptr->au -= (cost * o_ptr->number);
3252
3253                 if (item >= INVEN_RARM) calc_android_exp();
3254
3255                 /* Something happened */
3256                 return (TRUE);
3257         }
3258 }
3259
3260
3261 /*!
3262  * @brief 魔道具の使用回数を回復させる施設のメインルーチン / Recharge rods, wands and staves
3263  * @details
3264  * The player can select the number of charges to add\n
3265  * (up to a limit), and the recharge never fails.\n
3266  *\n
3267  * The cost for rods depends on the level of the rod. The prices\n
3268  * for recharging wands and staves are dependent on the cost of\n
3269  * the base-item.\n
3270  * @return なし
3271  */
3272 static void building_recharge(void)
3273 {
3274         OBJECT_IDX  item;
3275         DEPTH       lev;
3276         object_type *o_ptr;
3277         object_kind *k_ptr;
3278         concptr        q, s;
3279         PRICE       price;
3280         PARAMETER_VALUE charges;
3281         int         max_charges;
3282         char        tmp_str[MAX_NLEN];
3283
3284         msg_flag = FALSE;
3285
3286         /* Display some info */
3287         clear_bldg(4, 18);
3288         prt(_("  再充填の費用はアイテムの種類によります。", "  The prices of recharge depend on the type."), 6, 0);
3289
3290
3291         /* Only accept legal items */
3292         item_tester_hook = item_tester_hook_recharge;
3293
3294         q = _("どのアイテムに魔力を充填しますか? ", "Recharge which item? ");
3295         s = _("魔力を充填すべきアイテムがない。", "You have nothing to recharge.");
3296
3297         o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
3298         if (!o_ptr) return;
3299
3300         k_ptr = &k_info[o_ptr->k_idx];
3301
3302         /*
3303          * We don't want to give the player free info about
3304          * the level of the item or the number of charges.
3305          */
3306         /* The item must be "known" */
3307         if (!object_is_known(o_ptr))
3308         {
3309                 msg_format(_("充填する前に鑑定されている必要があります!", "The item must be identified first!"));
3310                 msg_print(NULL);
3311
3312                 if ((p_ptr->au >= 50) &&
3313                         get_check(_("$50で鑑定しますか? ", "Identify for 50 gold? ")))
3314
3315                 {
3316                         p_ptr->au -= 50;
3317                         identify_item(o_ptr);
3318                         object_desc(tmp_str, o_ptr, 0);
3319                         msg_format(_("%s です。", "You have: %s."), tmp_str);
3320
3321                         /* Auto-inscription */
3322                         autopick_alter_item(item, FALSE);
3323
3324                         /* Update the gold display */
3325                         building_prt_gold();
3326                 }
3327                 else
3328                 {
3329                         return;
3330                 }
3331         }
3332
3333         /* Extract the object "level" */
3334         lev = k_info[o_ptr->k_idx].level;
3335
3336         /* Price for a rod */
3337         if (o_ptr->tval == TV_ROD)
3338         {
3339                 if (o_ptr->timeout > 0)
3340                 {
3341                         /* Fully recharge */
3342                         price = (lev * 50 * o_ptr->timeout) / k_ptr->pval;
3343                 }
3344                 else
3345                 {
3346                         /* No recharge necessary */
3347                         price = 0;
3348                         msg_format(_("それは再充填する必要はありません。", "That doesn't need to be recharged."));
3349                         return;
3350                 }
3351         }
3352         else if (o_ptr->tval == TV_STAFF)
3353         {
3354                 /* Price per charge ( = double the price paid by shopkeepers for the charge) */
3355                 price = (k_info[o_ptr->k_idx].cost / 10) * o_ptr->number;
3356
3357                 /* Pay at least 10 gold per charge */
3358                 price = MAX(10, price);
3359         }
3360         else
3361         {
3362                 /* Price per charge ( = double the price paid by shopkeepers for the charge) */
3363                 price = (k_info[o_ptr->k_idx].cost / 10);
3364
3365                 /* Pay at least 10 gold per charge */
3366                 price = MAX(10, price);
3367         }
3368
3369         /* Limit the number of charges for wands and staffs */
3370         if (o_ptr->tval == TV_WAND
3371                 && (o_ptr->pval / o_ptr->number >= k_ptr->pval))
3372         {
3373                 if (o_ptr->number > 1)
3374                 {
3375                         msg_print(_("この魔法棒はもう充分に充填されています。", "These wands are already fully charged."));
3376                 }
3377                 else
3378                 {
3379                         msg_print(_("この魔法棒はもう充分に充填されています。", "This wand is already fully charged."));
3380                 }
3381                 return;
3382         }
3383         else if (o_ptr->tval == TV_STAFF && o_ptr->pval >= k_ptr->pval)
3384         {
3385                 if (o_ptr->number > 1)
3386                 {
3387                         msg_print(_("この杖はもう充分に充填されています。", "These staffs are already fully charged."));
3388                 }
3389                 else
3390                 {
3391                         msg_print(_("この杖はもう充分に充填されています。", "This staff is already fully charged."));
3392                 }
3393                 return;
3394         }
3395
3396         /* Check if the player has enough money */
3397         if (p_ptr->au < price)
3398         {
3399                 object_desc(tmp_str, o_ptr, OD_NAME_ONLY);
3400 #ifdef JP
3401                 msg_format("%sを再充填するには$%d 必要です!", tmp_str,price );
3402 #else
3403                 msg_format("You need %d gold to recharge %s!", price, tmp_str);
3404 #endif
3405
3406                 return;
3407         }
3408
3409         if (o_ptr->tval == TV_ROD)
3410         {
3411 #ifdef JP
3412                 if (get_check(format("そのロッドを$%d で再充填しますか?", price)))
3413 #else
3414                 if (get_check(format("Recharge the %s for %d gold? ",
3415                         ((o_ptr->number > 1) ? "rods" : "rod"), price)))
3416 #endif
3417
3418                 {
3419                         /* Recharge fully */
3420                         o_ptr->timeout = 0;
3421                 }
3422                 else
3423                 {
3424                         return;
3425                 }
3426         }
3427         else
3428         {
3429                 if (o_ptr->tval == TV_STAFF)
3430                         max_charges = k_ptr->pval - o_ptr->pval;
3431                 else
3432                         max_charges = o_ptr->number * k_ptr->pval - o_ptr->pval;
3433
3434                 /* Get the quantity for staves and wands */
3435                 charges = (PARAMETER_VALUE)get_quantity(format(_("一回分$%d で何回分充填しますか?", "Add how many charges for %d gold? "), price), 
3436                                         MIN(p_ptr->au / price, max_charges));
3437
3438                 /* Do nothing */
3439                 if (charges < 1) return;
3440
3441                 /* Get the new price */
3442                 price *= charges;
3443
3444                 /* Recharge */
3445                 o_ptr->pval += charges;
3446
3447                 /* We no longer think the item is empty */
3448                 o_ptr->ident &= ~(IDENT_EMPTY);
3449         }
3450
3451         /* Give feedback */
3452         object_desc(tmp_str, o_ptr, 0);
3453 #ifdef JP
3454         msg_format("%sを$%d で再充填しました。", tmp_str, price);
3455 #else
3456         msg_format("%^s %s recharged for %d gold.", tmp_str, ((o_ptr->number > 1) ? "were" : "was"), price);
3457 #endif
3458         p_ptr->update |= (PU_COMBINE | PU_REORDER);
3459
3460         p_ptr->window |= (PW_INVEN);
3461
3462         /* Pay the price */
3463         p_ptr->au -= price;
3464
3465         /* Finished */
3466         return;
3467 }
3468
3469
3470 /*!
3471  * @brief 魔道具の使用回数を回復させる施設の一括処理向けサブルーチン / Recharge rods, wands and staves
3472  * @details
3473  * The player can select the number of charges to add\n
3474  * (up to a limit), and the recharge never fails.\n
3475  *\n
3476  * The cost for rods depends on the level of the rod. The prices\n
3477  * for recharging wands and staves are dependent on the cost of\n
3478  * the base-item.\n
3479  * @return なし
3480  */
3481 static void building_recharge_all(void)
3482 {
3483         INVENTORY_IDX i;
3484         DEPTH lev;
3485         object_type *o_ptr;
3486         object_kind *k_ptr;
3487         PRICE price = 0;
3488         PRICE total_cost = 0;
3489
3490
3491         /* Display some info */
3492         msg_flag = FALSE;
3493         clear_bldg(4, 18);
3494         prt(_("  再充填の費用はアイテムの種類によります。", "  The prices of recharge depend on the type."), 6, 0);
3495
3496         /* Calculate cost */
3497         for ( i = 0; i < INVEN_PACK; i++)
3498         {
3499                 o_ptr = &p_ptr->inventory_list[i];
3500                                 
3501                 /* skip non magic device */
3502                 if (o_ptr->tval < TV_STAFF || o_ptr->tval > TV_ROD) continue;
3503
3504                 /* need identified */
3505                 if (!object_is_known(o_ptr)) total_cost += 50;
3506
3507                 /* Extract the object "level" */
3508                 lev = k_info[o_ptr->k_idx].level;
3509
3510                 k_ptr = &k_info[o_ptr->k_idx];
3511
3512                 switch (o_ptr->tval)
3513                 {
3514                 case TV_ROD:
3515                         price = (lev * 50 * o_ptr->timeout) / k_ptr->pval;
3516                         break;
3517
3518                 case TV_STAFF:
3519                         /* Price per charge ( = double the price paid by shopkeepers for the charge) */
3520                         price = (k_info[o_ptr->k_idx].cost / 10) * o_ptr->number;
3521
3522                         /* Pay at least 10 gold per charge */
3523                         price = MAX(10, price);
3524
3525                         /* Fully charge */
3526                         price = (k_ptr->pval - o_ptr->pval) * price;
3527                         break;
3528
3529                 case TV_WAND:
3530                         /* Price per charge ( = double the price paid by shopkeepers for the charge) */
3531                         price = (k_info[o_ptr->k_idx].cost / 10);
3532
3533                         /* Pay at least 10 gold per charge */
3534                         price = MAX(10, price);
3535
3536                         /* Fully charge */
3537                         price = (o_ptr->number * k_ptr->pval - o_ptr->pval) * price;
3538                         break;
3539                 }
3540
3541                 /* if price <= 0 then item have enough charge */
3542                 if (price > 0) total_cost += price;
3543         }
3544
3545         if (!total_cost)
3546         {
3547                 msg_print(_("充填する必要はありません。", "No need to recharge."));
3548                 msg_print(NULL);
3549                 return;
3550         }
3551
3552         /* Check if the player has enough money */
3553         if (p_ptr->au < total_cost)
3554         {
3555                 msg_format(_("すべてのアイテムを再充填するには$%d 必要です!", "You need %d gold to recharge all items!"), total_cost );
3556                 msg_print(NULL);
3557                 return;
3558         }
3559         if (!get_check(format(_("すべてのアイテムを $%d で再充填しますか?", "Recharge all items for %d gold? "),  total_cost))) return;
3560         
3561         for (i = 0; i < INVEN_PACK; i++)
3562         {
3563                 o_ptr = &p_ptr->inventory_list[i];
3564                 k_ptr = &k_info[o_ptr->k_idx];
3565
3566                 /* skip non magic device */
3567                 if (o_ptr->tval < TV_STAFF || o_ptr->tval > TV_ROD) continue;
3568
3569                 if (!object_is_known(o_ptr))
3570                 {
3571                         identify_item(o_ptr);
3572
3573                         /* Auto-inscription */
3574                         autopick_alter_item(i, FALSE);
3575                 }
3576
3577                 /* Recharge */
3578                 switch (o_ptr->tval)
3579                 {
3580                 case TV_ROD:
3581                         o_ptr->timeout = 0;
3582                         break;
3583                 case TV_STAFF:
3584                         if (o_ptr->pval < k_ptr->pval) o_ptr->pval = k_ptr->pval;
3585                         /* We no longer think the item is empty */
3586                         o_ptr->ident &= ~(IDENT_EMPTY);
3587                         break;
3588                 case TV_WAND:
3589                         if (o_ptr->pval < o_ptr->number * k_ptr->pval)
3590                                 o_ptr->pval = o_ptr->number * k_ptr->pval;
3591                         /* We no longer think the item is empty */
3592                         o_ptr->ident &= ~(IDENT_EMPTY);
3593                         break;
3594                 }
3595         }
3596
3597         /* Give feedback */
3598         msg_format(_("$%d で再充填しました。", "You pay %d gold."), total_cost);
3599         msg_print(NULL);
3600         p_ptr->update |= (PU_COMBINE | PU_REORDER);
3601
3602         p_ptr->window |= (PW_INVEN);
3603
3604         /* Pay the price */
3605         p_ptr->au -= total_cost;
3606
3607         /* Finished */
3608         return;
3609 }
3610
3611 /*!
3612  * @brief 施設でモンスターの情報を知るメインルーチン / research_mon -KMW-
3613  * @return 常にTRUEを返す。
3614  * @todo 返り値が意味不明なので直した方が良いかもしれない。
3615  */
3616 static bool research_mon(void)
3617 {
3618         IDX i;
3619         int n;
3620         MONRACE_IDX r_idx;
3621         char sym, query;
3622         char buf[128];
3623         bool notpicked;
3624         bool recall = FALSE;
3625         u16b why = 0;
3626         MONSTER_IDX *who;
3627
3628         /* XTRA HACK WHATSEARCH */
3629         bool all = FALSE;
3630         bool uniq = FALSE;
3631         bool norm = FALSE;
3632         char temp[80] = "";
3633
3634         /* XTRA HACK REMEMBER_IDX */
3635         static int old_sym = '\0';
3636         static IDX old_i = 0;
3637
3638         screen_save();
3639
3640         /* Get a character, or abort */
3641         if (!get_com(_("モンスターの文字を入力して下さい(記号 or ^A全,^Uユ,^N非ユ,^M名前):",
3642                                    "Enter character to be identified(^A:All,^U:Uniqs,^N:Non uniqs,^M:Name): "), &sym, FALSE)) 
3643
3644         {
3645                 screen_load();
3646
3647                 return (FALSE);
3648         }
3649
3650         /* Find that character info, and describe it */
3651         for (i = 0; ident_info[i]; ++i)
3652         {
3653                 if (sym == ident_info[i][0]) break;
3654         }
3655
3656                 /* XTRA HACK WHATSEARCH */
3657         if (sym == KTRL('A'))
3658         {
3659                 all = TRUE;
3660                 strcpy(buf, _("全モンスターのリスト", "Full monster list."));
3661         }
3662         else if (sym == KTRL('U'))
3663         {
3664                 all = uniq = TRUE;
3665                 strcpy(buf, _("ユニーク・モンスターのリスト", "Unique monster list."));
3666         }
3667         else if (sym == KTRL('N'))
3668         {
3669                 all = norm = TRUE;
3670                 strcpy(buf, _("ユニーク外モンスターのリスト", "Non-unique monster list."));
3671         }
3672         else if (sym == KTRL('M'))
3673         {
3674                 all = TRUE;
3675                 if (!get_string(_("名前(英語の場合小文字で可)", "Enter name:"),temp, 70))
3676                 {
3677                         temp[0]=0;
3678                         screen_load();
3679
3680                         return FALSE;
3681                 }
3682                 sprintf(buf, _("名前:%sにマッチ", "Monsters with a name \"%s\""),temp);
3683         }
3684         else if (ident_info[i])
3685         {
3686                 sprintf(buf, "%c - %s.", sym, ident_info[i] + 2);
3687         }
3688         else
3689         {
3690                 sprintf(buf, "%c - %s", sym, _("無効な文字", "Unknown Symbol"));
3691         }
3692
3693         /* Display the result */
3694         prt(buf, 16, 10);
3695
3696         /* Allocate the "who" array */
3697         C_MAKE(who, max_r_idx, MONRACE_IDX);
3698
3699         /* Collect matching monsters */
3700         for (n = 0, i = 1; i < max_r_idx; i++)
3701         {
3702                 monster_race *r_ptr = &r_info[i];
3703
3704                 /* Empty monster */
3705                 if (!r_ptr->name) continue;
3706
3707                 /* XTRA HACK WHATSEARCH */
3708                 /* Require non-unique monsters if needed */
3709                 if (norm && (r_ptr->flags1 & (RF1_UNIQUE))) continue;
3710
3711                 /* Require unique monsters if needed */
3712                 if (uniq && !(r_ptr->flags1 & (RF1_UNIQUE))) continue;
3713
3714                 /* 名前検索 */
3715                 if (temp[0])
3716                 {
3717                         int xx;
3718                         char temp2[80];
3719
3720                         for (xx = 0; temp[xx] && xx < 80; xx++)
3721                         {
3722 #ifdef JP
3723                                 if (iskanji(temp[xx]))
3724                                 {
3725                                         xx++;
3726                                         continue;
3727                                 }
3728 #endif
3729                                 if (isupper(temp[xx])) temp[xx] = (char)tolower(temp[xx]);
3730                         }
3731   
3732 #ifdef JP
3733                         strcpy(temp2, r_name + r_ptr->E_name);
3734 #else
3735                         strcpy(temp2, r_name + r_ptr->name);
3736 #endif
3737                         for (xx = 0; temp2[xx] && xx < 80; xx++)
3738                                 if (isupper(temp2[xx])) temp2[xx] = (char)tolower(temp2[xx]);
3739
3740 #ifdef JP
3741                         if (my_strstr(temp2, temp) || my_strstr(r_name + r_ptr->name, temp))
3742 #else
3743                         if (my_strstr(temp2, temp))
3744 #endif
3745                                 who[n++] = i;
3746                 }
3747                 else if (all || (r_ptr->d_char == sym)) who[n++] = i;
3748         }
3749
3750         /* Nothing to recall */
3751         if (!n)
3752         {
3753                 /* Free the "who" array */
3754                 C_KILL(who, max_r_idx, MONRACE_IDX);
3755                 screen_load();
3756
3757                 return (FALSE);
3758         }
3759
3760         /* Sort by level */
3761         why = 2;
3762         query = 'y';
3763
3764         /* Sort if needed */
3765         if (why)
3766         {
3767                 ang_sort(who, &why, n, ang_sort_comp_hook, ang_sort_swap_hook);
3768         }
3769
3770
3771         /* Start at the end */
3772         /* XTRA HACK REMEMBER_IDX */
3773         if (old_sym == sym && old_i < n) i = old_i;
3774         else i = n - 1;
3775
3776         notpicked = TRUE;
3777
3778         /* Scan the monster memory */
3779         while (notpicked)
3780         {
3781                 /* Extract a race */
3782                 r_idx = who[i];
3783
3784                 /* Hack -- Begin the prompt */
3785                 roff_top(r_idx);
3786
3787                 /* Hack -- Complete the prompt */
3788                 Term_addstr(-1, TERM_WHITE, _(" ['r'思い出, ' 'で続行, ESC]", " [(r)ecall, ESC, space to continue]"));
3789
3790                 /* Interact */
3791                 while (1)
3792                 {
3793                         /* Recall */
3794                         if (recall)
3795                         {
3796                                 /*** Recall on screen ***/
3797
3798                                 /* Get maximal info about this monster */
3799                                 lore_do_probe(r_idx);
3800
3801                                 /* Save this monster ID */
3802                                 monster_race_track(r_idx);
3803                                 handle_stuff();
3804
3805                                 /* know every thing mode */
3806                                 screen_roff(r_idx, 0x01);
3807                                 notpicked = FALSE;
3808
3809                                 /* XTRA HACK REMEMBER_IDX */
3810                                 old_sym = sym;
3811                                 old_i = i;
3812                         }
3813
3814                         query = inkey();
3815
3816                         /* Normal commands */
3817                         if (query != 'r') break;
3818
3819                         /* Toggle recall */
3820                         recall = !recall;
3821                 }
3822
3823                 /* Stop scanning */
3824                 if (query == ESCAPE) break;
3825
3826                 /* Move to "prev" monster */
3827                 if (query == '-')
3828                 {
3829                         if (++i == n)
3830                         {
3831                                 i = 0;
3832                                 if (!expand_list) break;
3833                         }
3834                 }
3835
3836                 /* Move to "next" monster */
3837                 else
3838                 {
3839                         if (i-- == 0)
3840                         {
3841                                 i = n - 1;
3842                                 if (!expand_list) break;
3843                         }
3844                 }
3845         }
3846
3847
3848         /* Re-display the identity */
3849         /* prt(buf, 5, 5);*/
3850
3851         /* Free the "who" array */
3852         C_KILL(who, max_r_idx, MONRACE_IDX);
3853         screen_load();
3854
3855         return (!notpicked);
3856 }
3857
3858
3859 /*!
3860  * @brief 施設の処理実行メインルーチン / Execute a building command
3861  * @param bldg 施設構造体の参照ポインタ
3862  * @param i 実行したい施設のサービステーブルの添字
3863  * @return なし
3864  */
3865 static void bldg_process_command(building_type *bldg, int i)
3866 {
3867         BACT_IDX bact = bldg->actions[i];
3868         PRICE bcost;
3869         bool paid = FALSE;
3870
3871         msg_flag = FALSE;
3872         msg_erase();
3873
3874         if (is_owner(bldg))
3875                 bcost = bldg->member_costs[i];
3876         else
3877                 bcost = bldg->other_costs[i];
3878
3879         /* action restrictions */
3880         if (((bldg->action_restr[i] == 1) && !is_member(bldg)) ||
3881             ((bldg->action_restr[i] == 2) && !is_owner(bldg)))
3882         {
3883                 msg_print(_("それを選択する権利はありません!", "You have no right to choose that!"));
3884                 return;
3885         }
3886
3887         /* check gold (HACK - Recharge uses variable costs) */
3888         if ((bact != BACT_RECHARGE) &&
3889             (((bldg->member_costs[i] > p_ptr->au) && is_owner(bldg)) ||
3890              ((bldg->other_costs[i] > p_ptr->au) && !is_owner(bldg))))
3891         {
3892                 msg_print(_("お金が足りません!", "You do not have the gold!"));
3893                 return;
3894         }
3895
3896         switch (bact)
3897         {
3898         case BACT_NOTHING:
3899                 /* Do nothing */
3900                 break;
3901         case BACT_RESEARCH_ITEM:
3902                 paid = identify_fully(FALSE);
3903                 break;
3904         case BACT_TOWN_HISTORY:
3905                 town_history();
3906                 break;
3907         case BACT_RACE_LEGENDS:
3908                 race_legends();
3909                 break;
3910         case BACT_QUEST:
3911                 castle_quest();
3912                 break;
3913         case BACT_KING_LEGENDS:
3914         case BACT_ARENA_LEGENDS:
3915         case BACT_LEGENDS:
3916                 show_highclass();
3917                 break;
3918         case BACT_POSTER:
3919         case BACT_ARENA_RULES:
3920         case BACT_ARENA:
3921                 arena_comm(bact);
3922                 break;
3923         case BACT_IN_BETWEEN:
3924         case BACT_CRAPS:
3925         case BACT_SPIN_WHEEL:
3926         case BACT_DICE_SLOTS:
3927         case BACT_GAMBLE_RULES:
3928         case BACT_POKER:
3929                 gamble_comm(bact);
3930                 break;
3931         case BACT_REST:
3932         case BACT_RUMORS:
3933         case BACT_FOOD:
3934                 paid = inn_comm(bact);
3935                 break;
3936         case BACT_RESEARCH_MONSTER:
3937                 paid = research_mon();
3938                 break;
3939         case BACT_COMPARE_WEAPONS:
3940                 paid = TRUE;
3941                 bcost = compare_weapons(bcost);
3942                 break;
3943         case BACT_ENCHANT_WEAPON:
3944                 item_tester_hook = object_allow_enchant_melee_weapon;
3945                 enchant_item(bcost, 1, 1, 0);
3946                 break;
3947         case BACT_ENCHANT_ARMOR:
3948                 item_tester_hook = object_is_armour;
3949                 enchant_item(bcost, 0, 0, 1);
3950                 break;
3951         case BACT_RECHARGE:
3952                 building_recharge();
3953                 break;
3954         case BACT_RECHARGE_ALL:
3955                 building_recharge_all();
3956                 break;
3957         case BACT_IDENTS: /* needs work */
3958                 if (!get_check(_("持ち物を全て鑑定してよろしいですか?", "Do you pay for identify all your possession? "))) break;
3959                 identify_pack();
3960                 msg_print(_(" 持ち物全てが鑑定されました。", "Your possessions have been identified."));
3961                 paid = TRUE;
3962                 break;
3963         case BACT_IDENT_ONE: /* needs work */
3964                 paid = ident_spell(FALSE);
3965                 break;
3966         case BACT_LEARN:
3967                 do_cmd_study();
3968                 break;
3969         case BACT_HEALING: /* needs work */
3970                 paid = cure_critical_wounds(200);
3971                 break;
3972         case BACT_RESTORE: /* needs work */
3973                 paid = restore_all_status();
3974                 break;
3975         case BACT_ENCHANT_ARROWS:
3976                 item_tester_hook = item_tester_hook_ammo;
3977                 enchant_item(bcost, 1, 1, 0);
3978                 break;
3979         case BACT_ENCHANT_BOW:
3980                 item_tester_tval = TV_BOW;
3981                 enchant_item(bcost, 1, 1, 0);
3982                 break;
3983
3984         case BACT_RECALL:
3985                 if (recall_player(p_ptr, 1)) paid = TRUE;
3986                 break;
3987
3988         case BACT_TELEPORT_LEVEL:
3989                 clear_bldg(4, 20);
3990                 paid = free_level_recall(p_ptr);
3991                 break;
3992
3993         case BACT_LOSE_MUTATION:
3994                 if (p_ptr->muta1 || p_ptr->muta2 || (p_ptr->muta3 & ~MUT3_GOOD_LUCK) ||
3995                         (p_ptr->pseikaku != SEIKAKU_LUCKY && (p_ptr->muta3 & MUT3_GOOD_LUCK)))
3996                 {
3997                         while(!lose_mutation(0));
3998                         paid = TRUE;
3999                 }
4000                 else
4001                 {
4002                         msg_print(_("治すべき突然変異が無い。", "You have no mutations."));
4003                         msg_print(NULL);
4004                 }
4005                 break;
4006
4007         case BACT_BATTLE:
4008                 kakutoujou();
4009                 break;
4010
4011         case BACT_TSUCHINOKO:
4012                 tsuchinoko();
4013                 break;
4014
4015         case BACT_KUBI:
4016                 shoukinkubi();
4017                 break;
4018
4019         case BACT_TARGET:
4020                 today_target();
4021                 break;
4022
4023         case BACT_KANKIN:
4024                 kankin();
4025                 break;
4026
4027         case BACT_HEIKOUKA:
4028                 msg_print(_("平衡化の儀式を行なった。", "You received an equalization ritual."));
4029                 set_virtue(V_COMPASSION, 0);
4030                 set_virtue(V_HONOUR, 0);
4031                 set_virtue(V_JUSTICE, 0);
4032                 set_virtue(V_SACRIFICE, 0);
4033                 set_virtue(V_KNOWLEDGE, 0);
4034                 set_virtue(V_FAITH, 0);
4035                 set_virtue(V_ENLIGHTEN, 0);
4036                 set_virtue(V_ENCHANT, 0);
4037                 set_virtue(V_CHANCE, 0);
4038                 set_virtue(V_NATURE, 0);
4039                 set_virtue(V_HARMONY, 0);
4040                 set_virtue(V_VITALITY, 0);
4041                 set_virtue(V_UNLIFE, 0);
4042                 set_virtue(V_PATIENCE, 0);
4043                 set_virtue(V_TEMPERANCE, 0);
4044                 set_virtue(V_DILIGENCE, 0);
4045                 set_virtue(V_VALOUR, 0);
4046                 set_virtue(V_INDIVIDUALISM, 0);
4047                 get_virtues();
4048                 paid = TRUE;
4049                 break;
4050
4051         case BACT_TELE_TOWN:
4052                 paid = tele_town();
4053                 break;
4054
4055         case BACT_EVAL_AC:
4056                 paid = eval_ac(p_ptr->dis_ac + p_ptr->dis_to_a);
4057                 break;
4058
4059         case BACT_BROKEN_WEAPON:
4060                 paid = TRUE;
4061                 bcost = repair_broken_weapon(bcost);
4062                 break;
4063         }
4064
4065         if (paid)
4066         {
4067                 p_ptr->au -= bcost;
4068         }
4069 }
4070
4071 /*!
4072  * @brief 施設入り口にプレイヤーが乗った際の処理 / Do building commands
4073  * @return なし
4074  */
4075 void do_cmd_bldg(void)
4076 {
4077         int             i, which;
4078         char            command;
4079         bool            validcmd;
4080         building_type   *bldg;
4081
4082         if(p_ptr->wild_mode) return;
4083
4084         take_turn(p_ptr, 100);
4085
4086         if (!cave_have_flag_bold(p_ptr->y, p_ptr->x, FF_BLDG))
4087         {
4088                 msg_print(_("ここには建物はない。", "You see no building here."));
4089                 return;
4090         }
4091
4092         which = f_info[current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].feat].subtype;
4093
4094         bldg = &building[which];
4095
4096         /* Don't re-init the wilderness */
4097         reinit_wilderness = FALSE;
4098
4099         if ((which == 2) && (p_ptr->arena_number < 0))
4100         {
4101                 msg_print(_("「敗者に用はない。」", "'There's no place here for a LOSER like you!'"));
4102                 return;
4103         }
4104         else if ((which == 2) && p_ptr->inside_arena)
4105         {
4106                 if (!p_ptr->exit_bldg && current_floor_ptr->m_cnt > 0)
4107                 {
4108                         prt(_("ゲートは閉まっている。モンスターがあなたを待っている!", "The gates are closed.  The monster awaits!"), 0, 0);
4109                 }
4110                 else
4111                 {
4112                         /* Don't save the arena as saved floor */
4113                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_NO_RETURN);
4114
4115                         p_ptr->inside_arena = FALSE;
4116                         p_ptr->leaving = TRUE;
4117
4118                         /* Re-enter the arena */
4119                         command_new = SPECIAL_KEY_BUILDING;
4120
4121                         /* No energy needed to re-enter the arena */
4122                         free_turn(p_ptr);
4123                 }
4124
4125                 return;
4126         }
4127         else if (p_ptr->inside_battle)
4128         {
4129                 /* Don't save the arena as saved floor */
4130                 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_NO_RETURN);
4131
4132                 p_ptr->leaving = TRUE;
4133                 p_ptr->inside_battle = FALSE;
4134
4135                 /* Re-enter the monster arena */
4136                 command_new = SPECIAL_KEY_BUILDING;
4137
4138                 /* No energy needed to re-enter the arena */
4139                 free_turn(p_ptr);
4140
4141                 return;
4142         }
4143         else
4144         {
4145                 p_ptr->oldpy = p_ptr->y;
4146                 p_ptr->oldpx = p_ptr->x;
4147         }
4148
4149         forget_lite();
4150         forget_view();
4151
4152         /* Hack -- Increase "icky" depth */
4153         current_world_ptr->character_icky++;
4154
4155         command_arg = 0;
4156         command_rep = 0;
4157         command_new = 0;
4158
4159         show_building(bldg);
4160         p_ptr->leave_bldg = FALSE;
4161
4162         play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_BUILD);
4163
4164         while (!p_ptr->leave_bldg)
4165         {
4166                 validcmd = FALSE;
4167                 prt("", 1, 0);
4168
4169                 building_prt_gold();
4170
4171                 command = inkey();
4172
4173                 if (command == ESCAPE)
4174                 {
4175                         p_ptr->leave_bldg = TRUE;
4176                         p_ptr->inside_arena = FALSE;
4177                         p_ptr->inside_battle = FALSE;
4178                         break;
4179                 }
4180
4181                 for (i = 0; i < 8; i++)
4182                 {
4183                         if (bldg->letters[i])
4184                         {
4185                                 if (bldg->letters[i] == command)
4186                                 {
4187                                         validcmd = TRUE;
4188                                         break;
4189                                 }
4190                         }
4191                 }
4192
4193                 if(validcmd) bldg_process_command(bldg, i);
4194
4195                 handle_stuff();
4196         }
4197
4198         select_floor_music();
4199
4200         msg_flag = FALSE;
4201         msg_erase();
4202
4203         /* Reinit wilderness to activate quests ... */
4204         if (reinit_wilderness)
4205         {
4206                 p_ptr->leaving = TRUE;
4207         }
4208
4209         /* Hack -- Decrease "icky" depth */
4210         current_world_ptr->character_icky--;
4211
4212         Term_clear();
4213
4214         p_ptr->update |= (PU_VIEW | PU_MONSTERS | PU_BONUS | PU_LITE | PU_MON_LITE);
4215         p_ptr->redraw |= (PR_BASIC | PR_EXTRA | PR_EQUIPPY | PR_MAP);
4216         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4217 }
4218
4219
4220 /*!
4221  * @brief 今日の賞金首を確定する / Determine today's bounty monster
4222  * @return なし
4223  * @note conv_old is used if loaded 0.0.3 or older save file
4224  */
4225 void determine_today_mon(bool conv_old)
4226 {
4227         int max_dl = 3, i;
4228         bool old_inside_battle = p_ptr->inside_battle;
4229         monster_race *r_ptr;
4230
4231         if (!conv_old)
4232         {
4233                 for (i = 0; i < max_d_idx; i++)
4234                 {
4235                         if (max_dlv[i] < d_info[i].mindepth) continue;
4236                         if (max_dl < max_dlv[i]) max_dl = max_dlv[i];
4237                 }
4238         }
4239         else max_dl = MAX(max_dlv[DUNGEON_ANGBAND], 3);
4240
4241         p_ptr->inside_battle = TRUE;
4242         get_mon_num_prep(NULL, NULL);
4243
4244         while (1)
4245         {
4246                 today_mon = get_mon_num(max_dl);
4247                 r_ptr = &r_info[today_mon];
4248
4249                 if (r_ptr->flags1 & RF1_UNIQUE) continue;
4250                 if (r_ptr->flags7 & (RF7_NAZGUL | RF7_UNIQUE2)) continue;
4251                 if (r_ptr->flags2 & RF2_MULTIPLY) continue;
4252                 if ((r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) != (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) continue;
4253                 if (r_ptr->level < MIN(max_dl / 2, 40)) continue;
4254                 if (r_ptr->rarity > 10) continue;
4255                 break;
4256         }
4257
4258         p_ptr->today_mon = 0;
4259         p_ptr->inside_battle = old_inside_battle;
4260 }
4261
4262
4263
4264 /*!
4265  * @brief 賞金首となるユニークを確定する / Determine bounty uniques
4266  * @return なし
4267  */
4268 void determine_bounty_uniques(void)
4269 {
4270         int i, j;
4271         MONRACE_IDX tmp;
4272         monster_race *r_ptr;
4273
4274         get_mon_num_prep(NULL, NULL);
4275         for (i = 0; i < MAX_KUBI; i++)
4276         {
4277                 while (1)
4278                 {
4279                         current_world_ptr->bounty_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
4280                         r_ptr = &r_info[current_world_ptr->bounty_r_idx[i]];
4281
4282                         if (!(r_ptr->flags1 & RF1_UNIQUE)) continue;
4283
4284                         if (!(r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON))) continue;
4285
4286                         if (r_ptr->rarity > 100) continue;
4287
4288                         if (no_questor_or_bounty_uniques(current_world_ptr->bounty_r_idx[i])) continue;
4289
4290                         for (j = 0; j < i; j++)
4291                                 if (current_world_ptr->bounty_r_idx[i] == current_world_ptr->bounty_r_idx[j]) break;
4292
4293                         if (j == i) break;
4294                 }
4295         }
4296
4297         /* Sort them */
4298         for (i = 0; i < MAX_KUBI - 1; i++)
4299         {
4300                 for (j = i; j < MAX_KUBI; j++)
4301                 {
4302                         if (r_info[current_world_ptr->bounty_r_idx[i]].level > r_info[current_world_ptr->bounty_r_idx[j]].level)
4303                         {
4304                                 tmp = current_world_ptr->bounty_r_idx[i];
4305                                 current_world_ptr->bounty_r_idx[i] = current_world_ptr->bounty_r_idx[j];
4306                                 current_world_ptr->bounty_r_idx[j] = tmp;
4307                         }
4308                 }
4309         }
4310 }