OSDN Git Service

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