2 * @brief 町の施設処理 / Building commands
5 * Created by Ken Wigle for Kangband - a variant of Angband 2.8.3
8 * Rewritten for Kangband 2.8.3i using Kamband's version of
9 * building.c as written by Ivan Tkatchev
11 * Changed for ZAngband by Robert Ruehlmann
14 #include "cmd-building/cmd-building.h"
15 #include "avatar/avatar.h"
16 #include "cmd-action/cmd-spell.h"
17 #include "cmd-building/cmd-inn.h"
18 #include "cmd-io/cmd-dump.h"
19 #include "core/asking-player.h"
20 #include "core/scores.h"
21 #include "core/show-file.h"
22 #include "core/special-internal-keys.h"
23 #include "core/stuff-handler.h"
24 #include "core/window-redrawer.h"
25 #include "floor/cave.h"
26 #include "floor/floor-events.h"
27 #include "floor/floor-mode-changer.h"
28 #include "floor/wild.h"
29 #include "io/input-key-acceptor.h"
30 #include "io/input-key-requester.h"
31 #include "main/music-definitions-table.h"
32 #include "main/sound-of-music.h"
33 #include "market/arena.h"
34 #include "market/bounty.h"
35 #include "market/building-actions-table.h"
36 #include "market/building-craft-armor.h"
37 #include "market/building-craft-fix.h"
38 #include "market/building-craft-weapon.h"
39 #include "market/building-enchanter.h"
40 #include "market/building-monster.h"
41 #include "market/building-quest.h"
42 #include "market/building-recharger.h"
43 #include "market/building-service.h"
44 #include "market/building-util.h"
45 #include "market/play-gamble.h"
46 #include "market/poker.h"
47 #include "monster-race/monster-race.h"
48 #include "mutation/mutation-flag-types.h"
49 #include "mutation/mutation-investor-remover.h"
50 #include "object-hook/hook-armor.h"
51 #include "object-hook/hook-weapon.h"
52 #include "object/item-tester-hooker.h"
53 #include "player-status/player-energy.h"
54 #include "player/player-personality-types.h"
55 #include "spell-kind/spells-perception.h"
56 #include "spell-kind/spells-world.h"
57 #include "spell/spells-status.h"
58 #include "system/angband-exceptions.h"
59 #include "system/angband-system.h"
60 #include "system/building-type-definition.h"
61 #include "system/floor-type-definition.h"
62 #include "system/grid-type-definition.h"
63 #include "system/item-entity.h"
64 #include "system/player-type-definition.h"
65 #include "system/redrawing-flags-updater.h"
66 #include "system/terrain-type-definition.h"
67 #include "term/gameterm.h"
68 #include "term/screen-processor.h"
69 #include "util/bit-flags-calculator.h"
70 #include "util/int-char-converter.h"
71 #include "view/display-messages.h"
72 #include "world/world.h"
79 bool reinit_wilderness = false;
82 * @brief 町に関するヘルプを表示する / Display town history
83 * @param player_ptr プレイヤーへの参照ポインタ
85 static void town_history(PlayerType *player_ptr)
88 (void)show_file(player_ptr, true, _("jbldg.txt", "bldg.txt"), 0, 0);
93 * @brief 施設の処理実行メインルーチン
94 * @param player_ptr プレイヤーへの参照ポインタ
95 * @param bldg 施設構造体の参照ポインタ
96 * @param i 実行したい施設のサービステーブルの添字
97 * @return 施設から別フロアへ移動するか否か (アリーナ/モンスター闘技場のみtrue)
99 static bool bldg_process_command(PlayerType *player_ptr, building_type *bldg, int i)
103 const auto can_be_owner = is_owner(player_ptr, bldg);
104 const auto building_cost = can_be_owner ? bldg->member_costs[i] : bldg->other_costs[i];
105 if (((bldg->action_restr[i] == 1) && !is_member(player_ptr, bldg)) || ((bldg->action_restr[i] == 2) && !can_be_owner)) {
106 msg_print(_("それを選択する権利はありません!", "You have no right to choose that!"));
110 const auto building_action = bldg->actions[i];
111 if ((building_action != BACT_RECHARGE) && (((bldg->member_costs[i] > player_ptr->au) && can_be_owner) || ((bldg->other_costs[i] > player_ptr->au) && !can_be_owner))) {
112 msg_print(_("お金が足りません!", "You do not have the gold!"));
116 switch (building_action) {
120 case BACT_RESEARCH_ITEM:
121 if (identify_fully(player_ptr, false)) {
122 player_ptr->au -= building_cost;
126 case BACT_TOWN_HISTORY:
127 town_history(player_ptr);
129 case BACT_RACE_LEGENDS:
130 race_legends(player_ptr);
133 castle_quest(player_ptr);
135 case BACT_KING_LEGENDS:
136 case BACT_ARENA_LEGENDS:
138 show_highclass(player_ptr);
141 case BACT_ARENA_RULES:
143 return arena_comm(player_ptr, building_action);
144 case BACT_IN_BETWEEN:
146 case BACT_SPIN_WHEEL:
147 case BACT_DICE_SLOTS:
148 case BACT_GAMBLE_RULES:
150 gamble_comm(player_ptr, building_action);
155 if (inn_comm(player_ptr, building_action)) {
156 player_ptr->au -= building_cost;
160 case BACT_RESEARCH_MONSTER:
161 if (research_mon(player_ptr)) {
162 player_ptr->au -= building_cost;
166 case BACT_COMPARE_WEAPONS:
167 player_ptr->au -= compare_weapons(player_ptr, building_cost);
169 case BACT_ENCHANT_WEAPON:
170 enchant_item(player_ptr, building_cost, 1, 1, 0, FuncItemTester(&ItemEntity::allow_enchant_melee_weapon));
172 case BACT_ENCHANT_ARMOR:
173 enchant_item(player_ptr, building_cost, 0, 0, 1, FuncItemTester(&ItemEntity::is_protector));
176 building_recharge(player_ptr);
178 case BACT_RECHARGE_ALL:
179 building_recharge_all(player_ptr);
182 if (!input_check(_("持ち物を全て鑑定してよろしいですか?", "Do you pay to identify all your possession? "))) {
186 identify_pack(player_ptr);
187 msg_print(_(" 持ち物全てが鑑定されました。", "Your possessions have been identified."));
188 player_ptr->au -= building_cost;
191 if (ident_spell(player_ptr, false)) {
192 player_ptr->au -= building_cost;
197 do_cmd_study(player_ptr);
200 if (cure_critical_wounds(player_ptr, 200)) {
201 player_ptr->au -= building_cost;
206 if (restore_all_status(player_ptr)) {
207 player_ptr->au -= building_cost;
211 case BACT_ENCHANT_ARROWS:
212 enchant_item(player_ptr, building_cost, 1, 1, 0, FuncItemTester(&ItemEntity::is_ammo));
214 case BACT_ENCHANT_BOW:
215 enchant_item(player_ptr, building_cost, 1, 1, 0, TvalItemTester(ItemKindType::BOW));
218 if (recall_player(player_ptr, 1)) {
219 player_ptr->au -= building_cost;
223 case BACT_TELEPORT_LEVEL:
226 if (free_level_recall(player_ptr)) {
227 player_ptr->au -= building_cost;
232 case BACT_LOSE_MUTATION: {
233 auto muta = player_ptr->muta;
234 if (player_ptr->ppersonality == PERSONALITY_LUCKY) {
235 // ラッキーマンの白オーラは突然変異治療の対象外
236 muta.reset(PlayerMutationType::GOOD_LUCK);
240 while (!lose_mutation(player_ptr, 0)) {
244 player_ptr->au -= building_cost;
248 msg_print(_("治すべき突然変異が無い。", "You have no mutations."));
253 return monster_arena_comm(player_ptr);
254 case BACT_TSUCHINOKO:
261 today_target(player_ptr);
264 exchange_cash(player_ptr);
267 msg_print(_("平衡化の儀式を行なった。", "You received an equalization ritual."));
268 set_virtue(player_ptr, Virtue::COMPASSION, 0);
269 set_virtue(player_ptr, Virtue::HONOUR, 0);
270 set_virtue(player_ptr, Virtue::JUSTICE, 0);
271 set_virtue(player_ptr, Virtue::SACRIFICE, 0);
272 set_virtue(player_ptr, Virtue::KNOWLEDGE, 0);
273 set_virtue(player_ptr, Virtue::FAITH, 0);
274 set_virtue(player_ptr, Virtue::ENLIGHTEN, 0);
275 set_virtue(player_ptr, Virtue::ENCHANT, 0);
276 set_virtue(player_ptr, Virtue::CHANCE, 0);
277 set_virtue(player_ptr, Virtue::NATURE, 0);
278 set_virtue(player_ptr, Virtue::HARMONY, 0);
279 set_virtue(player_ptr, Virtue::VITALITY, 0);
280 set_virtue(player_ptr, Virtue::UNLIFE, 0);
281 set_virtue(player_ptr, Virtue::PATIENCE, 0);
282 set_virtue(player_ptr, Virtue::TEMPERANCE, 0);
283 set_virtue(player_ptr, Virtue::DILIGENCE, 0);
284 set_virtue(player_ptr, Virtue::VALOUR, 0);
285 set_virtue(player_ptr, Virtue::INDIVIDUALISM, 0);
286 initialize_virtues(player_ptr);
287 player_ptr->au -= building_cost;
290 if (!tele_town(player_ptr)) {
294 player_ptr->au -= building_cost;
297 if (eval_ac(player_ptr->dis_ac + player_ptr->dis_to_a)) {
298 player_ptr->au -= building_cost;
302 case BACT_BROKEN_WEAPON:
303 player_ptr->au -= repair_broken_weapon(player_ptr, building_cost);
306 THROW_EXCEPTION(std::logic_error, "Invalid building action is specified!");
311 * @brief 施設入り口にプレイヤーが乗った際の処理 / Do building commands
312 * @param プレイヤーへの参照ポインタ
314 void do_cmd_building(PlayerType *player_ptr)
316 if (player_ptr->wild_mode) {
320 PlayerEnergy energy(player_ptr);
321 energy.set_player_turn_energy(100);
322 const auto p_pos = player_ptr->get_position();
323 if (!cave_has_flag_bold(player_ptr->current_floor_ptr, p_pos.y, p_pos.x, TerrainCharacteristics::BLDG)) {
324 msg_print(_("ここには建物はない。", "You see no building here."));
328 int which = player_ptr->current_floor_ptr->get_grid(p_pos).get_terrain().subtype;
331 bldg = &buildings[which];
333 reinit_wilderness = false;
335 if ((which == 2) && (player_ptr->arena_number < 0)) {
336 msg_print(_("「敗者に用はない。」", "'There's no place here for a LOSER like you!'"));
340 if ((which == 2) && player_ptr->current_floor_ptr->inside_arena) {
341 if (!player_ptr->exit_bldg && player_ptr->current_floor_ptr->m_cnt > 0) {
342 prt(_("ゲートは閉まっている。モンスターがあなたを待っている!", "The gates are closed. The monster awaits!"), 0, 0);
344 prepare_change_floor_mode(player_ptr, CFM_SAVE_FLOORS | CFM_NO_RETURN);
345 player_ptr->current_floor_ptr->inside_arena = false;
346 player_ptr->leaving = true;
347 command_new = SPECIAL_KEY_BUILDING;
348 energy.reset_player_turn();
354 TermCenteredOffsetSetter tcos(MAIN_TERM_MIN_COLS, MAIN_TERM_MIN_ROWS);
356 auto &system = AngbandSystem::get_instance();
357 if (system.is_phase_out()) {
358 prepare_change_floor_mode(player_ptr, CFM_SAVE_FLOORS | CFM_NO_RETURN);
359 player_ptr->leaving = true;
360 system.set_phase_out(false);
361 command_new = SPECIAL_KEY_BUILDING;
362 energy.reset_player_turn();
366 player_ptr->oldpy = player_ptr->y;
367 player_ptr->oldpx = player_ptr->x;
368 forget_lite(player_ptr->current_floor_ptr);
369 forget_view(player_ptr->current_floor_ptr);
370 w_ptr->character_icky_depth++;
376 display_buikding_service(player_ptr, bldg);
377 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_BUILD);
381 building_prt_gold(player_ptr);
382 const auto command = inkey();
383 if (command == ESCAPE) {
384 player_ptr->current_floor_ptr->inside_arena = false;
385 system.set_phase_out(false);
389 auto is_valid_command = false;
391 for (i = 0; i < 8; i++) {
392 if (bldg->letters[i] && (bldg->letters[i] == command)) {
393 is_valid_command = true;
398 const auto should_leave = is_valid_command ? bldg_process_command(player_ptr, bldg, i) : false;
399 handle_stuff(player_ptr);
405 select_floor_music(player_ptr);
410 if (reinit_wilderness) {
411 player_ptr->leaving = true;
414 w_ptr->character_icky_depth--;
417 auto &rfu = RedrawingFlagsUpdater::get_instance();
418 static constexpr auto flags_srf = {
419 StatusRecalculatingFlag::VIEW,
420 StatusRecalculatingFlag::MONSTER_STATUSES,
421 StatusRecalculatingFlag::BONUS,
422 StatusRecalculatingFlag::LITE,
423 StatusRecalculatingFlag::MONSTER_LITE,
425 rfu.set_flags(flags_srf);
426 static constexpr auto flags_mwrf = {
427 MainWindowRedrawingFlag::BASIC,
428 MainWindowRedrawingFlag::EXTRA,
429 MainWindowRedrawingFlag::EQUIPPY,
430 MainWindowRedrawingFlag::MAP,
432 rfu.set_flags(flags_mwrf);
433 static constexpr auto flags_swrf = {
434 SubWindowRedrawingFlag::OVERHEAD,
435 SubWindowRedrawingFlag::DUNGEON,
437 rfu.set_flags(flags_swrf);