OSDN Git Service

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