OSDN Git Service

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