OSDN Git Service

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