OSDN Git Service

[Refactor] #3484 get_com() をinput_command() に改名した
[hengbandforosx/hengbandosx.git] / src / wizard / wizard-special-process.cpp
1 /*!
2  * @brief ウィザードモードの処理(特別処理中心) / Wizard commands
3  * @date 2014/09/07
4  * @author
5  * Copyright (c) 1997 Ben Harrison, and others<br>
6  * This software may be copied and distributed for educational, research,
7  * and not for profit purposes provided that this copyright and statement
8  * are included in all such copies.  Other copyrights may also apply.<br>
9  * 2014 Deskull rearranged comment for Doxygen.<br>
10  */
11
12 #include "wizard/wizard-special-process.h"
13 #include "artifact/fixed-art-generator.h"
14 #include "artifact/fixed-art-types.h"
15 #include "birth/inventory-initializer.h"
16 #include "cmd-io/cmd-dump.h"
17 #include "cmd-io/cmd-help.h"
18 #include "cmd-io/cmd-save.h"
19 #include "cmd-visual/cmd-draw.h"
20 #include "core/asking-player.h"
21 #include "core/stuff-handler.h"
22 #include "core/window-redrawer.h"
23 #include "dungeon/quest.h"
24 #include "flavor/flavor-describer.h"
25 #include "flavor/object-flavor-types.h"
26 #include "flavor/object-flavor.h"
27 #include "floor/floor-leaver.h"
28 #include "floor/floor-mode-changer.h"
29 #include "floor/floor-object.h"
30 #include "game-option/birth-options.h"
31 #include "game-option/option-types-table.h"
32 #include "game-option/play-record-options.h"
33 #include "game-option/special-options.h"
34 #include "grid/feature.h"
35 #include "grid/grid.h"
36 #include "info-reader/fixed-map-parser.h"
37 #include "inventory/inventory-object.h"
38 #include "inventory/inventory-slot-types.h"
39 #include "io/files-util.h"
40 #include "io/input-key-requester.h"
41 #include "io/write-diary.h"
42 #include "market/arena.h"
43 #include "monster-floor/monster-remover.h"
44 #include "monster-floor/monster-summon.h"
45 #include "monster/monster-describer.h"
46 #include "monster/monster-description-types.h"
47 #include "monster/monster-info.h"
48 #include "monster/monster-status.h"
49 #include "monster/smart-learn-types.h"
50 #include "mutation/mutation-investor-remover.h"
51 #include "object-enchant/item-apply-magic.h"
52 #include "object-enchant/item-magic-applier.h"
53 #include "object-enchant/trc-types.h"
54 #include "object-enchant/trg-types.h"
55 #include "object/object-kind-hook.h"
56 #include "perception/object-perception.h"
57 #include "player-base/player-class.h"
58 #include "player-base/player-race.h"
59 #include "player-info/class-info.h"
60 #include "player-info/race-info.h"
61 #include "player-info/race-types.h"
62 #include "player-info/self-info.h"
63 #include "player-status/player-energy.h"
64 #include "player/digestion-processor.h"
65 #include "player/patron.h"
66 #include "player/player-skill.h"
67 #include "player/player-status-table.h"
68 #include "player/player-status.h"
69 #include "player/race-info-table.h"
70 #include "spell-kind/spells-detection.h"
71 #include "spell-kind/spells-sight.h"
72 #include "spell-kind/spells-teleport.h"
73 #include "spell-kind/spells-world.h"
74 #include "spell/spells-object.h"
75 #include "spell/spells-status.h"
76 #include "spell/spells-summon.h"
77 #include "status/bad-status-setter.h"
78 #include "status/experience.h"
79 #include "system/angband-version.h"
80 #include "system/artifact-type-definition.h"
81 #include "system/baseitem-info.h"
82 #include "system/dungeon-info.h"
83 #include "system/floor-type-definition.h"
84 #include "system/grid-type-definition.h"
85 #include "system/item-entity.h"
86 #include "system/monster-entity.h"
87 #include "system/player-type-definition.h"
88 #include "system/redrawing-flags-updater.h"
89 #include "system/terrain-type-definition.h"
90 #include "target/grid-selector.h"
91 #include "term/screen-processor.h"
92 #include "term/z-form.h"
93 #include "util/angband-files.h"
94 #include "util/bit-flags-calculator.h"
95 #include "util/enum-converter.h"
96 #include "util/finalizer.h"
97 #include "util/int-char-converter.h"
98 #include "view/display-messages.h"
99 #include "wizard/spoiler-table.h"
100 #include "wizard/tval-descriptions-table.h"
101 #include "wizard/wizard-messages.h"
102 #include "wizard/wizard-spells.h"
103 #include "wizard/wizard-spoiler.h"
104 #include "world/world.h"
105 #include <algorithm>
106 #include <optional>
107 #include <span>
108 #include <sstream>
109 #include <tuple>
110 #include <vector>
111
112 #define NUM_O_SET 8
113 #define NUM_O_BIT 32
114
115 /*!
116  * @brief プレイヤーを完全回復する
117  */
118 void wiz_cure_all(PlayerType *player_ptr)
119 {
120     (void)life_stream(player_ptr, false, false);
121     (void)restore_mana(player_ptr, true);
122     (void)set_food(player_ptr, PY_FOOD_MAX - 1);
123     BadStatusSetter bss(player_ptr);
124     (void)bss.set_fear(0);
125     (void)bss.set_deceleration(0, false);
126     msg_print("You're fully cured by wizard command.");
127 }
128
129 static std::optional<short> wiz_select_tval()
130 {
131     short list;
132     char ch;
133     for (list = 0; (list < 80) && (tvals[list].tval > ItemKindType::NONE); list++) {
134         auto row = 2 + (list % 20);
135         auto col = _(32, 24) * (list / 20);
136         ch = listsym[list];
137         prt(format("[%c] %s", ch, tvals[list].desc), row, col);
138     }
139
140     auto max_num = list;
141     if (!input_command(_("アイテム種別を選んで下さい", "Get what type of object? "), &ch, false)) {
142         return std::nullopt;
143     }
144
145     short selection;
146     for (selection = 0; selection < max_num; selection++) {
147         if (listsym[selection] == ch) {
148             break;
149         }
150     }
151
152     if ((selection < 0) || (selection >= max_num)) {
153         return std::nullopt;
154     }
155
156     return selection;
157 }
158
159 static short wiz_select_sval(const ItemKindType tval, concptr tval_description)
160 {
161     auto num = 0;
162     short choice[80]{};
163     char ch;
164     for (const auto &baseitem : baseitems_info) {
165         if (num >= 80) {
166             break;
167         }
168
169         if ((baseitem.idx == 0) || baseitem.bi_key.tval() != tval) {
170             continue;
171         }
172
173         auto row = 2 + (num % 20);
174         auto col = _(30, 32) * (num / 20);
175         ch = listsym[num];
176         const auto buf = strip_name(baseitem.idx);
177         prt(format("[%c] %s", ch, buf.data()), row, col);
178         choice[num++] = baseitem.idx;
179     }
180
181     auto max_num = num;
182     if (!input_command(format(_("%s群の具体的なアイテムを選んで下さい", "What Kind of %s? "), tval_description), &ch, false)) {
183         return 0;
184     }
185
186     short selection;
187     for (selection = 0; selection < max_num; selection++) {
188         if (listsym[selection] == ch) {
189             break;
190         }
191     }
192
193     if ((selection < 0) || (selection >= max_num)) {
194         return 0;
195     }
196
197     return choice[selection];
198 }
199
200 /*!
201  * @brief ベースアイテムのウィザード生成のために大項目IDと小項目IDを取得する /
202  * Specify tval and sval (type and subtype of object) originally
203  * @return ベースアイテムID
204  * @details
205  * by RAK, heavily modified by -Bernd-
206  * This function returns the bi_id of an object type, or zero if failed
207  * List up to 50 choices in three columns
208  */
209 static short wiz_create_itemtype()
210 {
211     term_clear();
212     auto selection = wiz_select_tval();
213     if (!selection.has_value()) {
214         return 0;
215     }
216
217     auto tval = tvals[selection.value()].tval;
218     auto tval_description = tvals[selection.value()].desc;
219     term_clear();
220     return wiz_select_sval(tval, tval_description);
221 }
222
223 /*!
224  * @brief 任意のベースアイテム生成のメインルーチン /
225  * Wizard routine for creating objects          -RAK-
226  * @details
227  * Heavily modified to allow magification and artifactification  -Bernd-
228  *
229  * Note that wizards cannot create objects on top of other objects.
230  *
231  * Hack -- this routine always makes a "dungeon object", and applies
232  * magic to it, and attempts to decline cursed items.
233  */
234 void wiz_create_item(PlayerType *player_ptr)
235 {
236     screen_save();
237     const auto bi_id = wiz_create_itemtype();
238     screen_load();
239     if (bi_id == 0) {
240         return;
241     }
242
243     const auto &baseitem = baseitems_info[bi_id];
244     if (baseitem.gen_flags.has(ItemGenerationTraitType::INSTA_ART)) {
245         for (const auto &[a_idx, artifact] : artifacts_info) {
246             if ((a_idx == FixedArtifactId::NONE) || (artifact.bi_key != baseitem.bi_key)) {
247                 continue;
248             }
249
250             (void)create_named_art(player_ptr, a_idx, player_ptr->y, player_ptr->x);
251             msg_print("Allocated(INSTA_ART).");
252             return;
253         }
254     }
255
256     ItemEntity item;
257     item.prep(bi_id);
258     ItemMagicApplier(player_ptr, &item, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART).execute();
259     (void)drop_near(player_ptr, &item, -1, player_ptr->y, player_ptr->x);
260     msg_print("Allocated.");
261 }
262
263 /*!
264  * @brief 指定したIDの固定アーティファクトの名称を取得する
265  *
266  * @param a_idx 固定アーティファクトのID
267  * @return 固定アーティファクトの名称(Ex. ★ロング・ソード『リンギル』)を保持する std::string オブジェクト
268  */
269 static std::string wiz_make_named_artifact_desc(PlayerType *player_ptr, FixedArtifactId a_idx)
270 {
271     const auto &artifact = ArtifactsInfo::get_instance().get_artifact(a_idx);
272     ItemEntity item;
273     item.prep(lookup_baseitem_id(artifact.bi_key));
274     item.fixed_artifact_idx = a_idx;
275     object_known(&item);
276     return describe_flavor(player_ptr, &item, OD_NAME_ONLY);
277 }
278
279 /**
280  * @brief 固定アーティファクトをリストから選択する
281  *
282  * @param a_idx_list 選択する候補となる固定アーティファクトのIDのリスト
283  * @return 選択した固定アーティファクトのIDを返す。但しキャンセルした場合は std::nullopt を返す。
284  */
285 static std::optional<FixedArtifactId> wiz_select_named_artifact(PlayerType *player_ptr, const std::vector<FixedArtifactId> &a_idx_list)
286 {
287     constexpr auto MAX_PER_PAGE = 20UL;
288     const auto page_max = (a_idx_list.size() - 1) / MAX_PER_PAGE + 1;
289     auto current_page = 0UL;
290
291     screen_save();
292
293     std::optional<FixedArtifactId> selected_a_idx;
294
295     while (!selected_a_idx.has_value()) {
296         const auto page_base_idx = current_page * MAX_PER_PAGE;
297         for (auto i = 0U; i < MAX_PER_PAGE + 1; ++i) {
298             term_erase(14, i + 1, 255);
299         }
300         const auto page_item_count = std::min(MAX_PER_PAGE, a_idx_list.size() - page_base_idx);
301         for (auto i = 0U; i < page_item_count; ++i) {
302             std::stringstream ss;
303             ss << I2A(i) << ") " << wiz_make_named_artifact_desc(player_ptr, a_idx_list[page_base_idx + i]);
304             put_str(ss.str(), i + 1, 15);
305         }
306         if (page_max > 1) {
307             put_str(format("-- more (%lu/%lu) --", current_page + 1, page_max), page_item_count + 1, 15);
308         }
309
310         char cmd = ESCAPE;
311         input_command("Which artifact: ", &cmd, false);
312         switch (cmd) {
313         case ESCAPE:
314             screen_load();
315             return selected_a_idx;
316         case ' ':
317             current_page++;
318             if (current_page >= page_max) {
319                 current_page = 0;
320             }
321             break;
322         default:
323             const auto select_idx = A2I(cmd) + page_base_idx;
324             if (select_idx < a_idx_list.size()) {
325                 selected_a_idx = a_idx_list[select_idx];
326             }
327             break;
328         }
329     }
330
331     screen_load();
332
333     return selected_a_idx;
334 }
335
336 /**
337  * @brief 指定したカテゴリの固定アーティファクトのIDのリストを得る
338  *
339  * @param group_artifact 固定アーティファクトのカテゴリ
340  * @return 該当のカテゴリの固定アーティファクトのIDのリスト
341  */
342 static std::vector<FixedArtifactId> wiz_collect_group_a_idx(const grouper &group_artifact)
343 {
344     const auto &[tval_list, name] = group_artifact;
345     std::vector<FixedArtifactId> a_idx_list;
346     for (auto tval : tval_list) {
347         for (const auto &[a_idx, artifact] : artifacts_info) {
348             if (artifact.bi_key.tval() == tval) {
349                 a_idx_list.push_back(a_idx);
350             }
351         }
352     }
353
354     return a_idx_list;
355 }
356
357 /*!
358  * @brief 固定アーティファクトを生成する / Create the artifact
359  */
360 void wiz_create_named_art(PlayerType *player_ptr)
361 {
362     screen_save();
363     for (auto i = 0U; i < group_artifact_list.size(); ++i) {
364         const auto &[tval_lit, name] = group_artifact_list[i];
365         std::stringstream ss;
366         ss << I2A(i) << ") " << name;
367         term_erase(14, i + 1, 255);
368         put_str(ss.str(), i + 1, 15);
369     }
370
371     std::optional<FixedArtifactId> create_a_idx;
372     while (!create_a_idx.has_value()) {
373         char cmd = ESCAPE;
374         input_command("Kind of artifact: ", &cmd, false);
375         switch (cmd) {
376         case ESCAPE:
377             screen_load();
378             return;
379         default:
380             if (auto idx = A2I(cmd); idx < group_artifact_list.size()) {
381                 const auto &a_idx_list = wiz_collect_group_a_idx(group_artifact_list[idx]);
382                 create_a_idx = wiz_select_named_artifact(player_ptr, a_idx_list);
383             }
384
385             break;
386         }
387     }
388
389     screen_load();
390     const auto a_idx = create_a_idx.value();
391     const auto &artifact = ArtifactsInfo::get_instance().get_artifact(a_idx);
392     if (artifact.is_generated) {
393         msg_print("It's already allocated.");
394         return;
395     }
396
397     (void)create_named_art(player_ptr, a_idx, player_ptr->y, player_ptr->x);
398     msg_print("Allocated.");
399 }
400
401 static void wiz_change_status_max(PlayerType *player_ptr)
402 {
403     for (auto i = 0; i < A_MAX; ++i) {
404         player_ptr->stat_cur[i] = player_ptr->stat_max_max[i];
405         player_ptr->stat_max[i] = player_ptr->stat_max_max[i];
406     }
407
408     for (auto tval : TV_WEAPON_RANGE) {
409         for (auto &exp : player_ptr->weapon_exp[tval]) {
410             exp = PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER);
411         }
412     }
413     PlayerSkill(player_ptr).limit_weapon_skills_by_max_value();
414
415     for (auto &[type, exp] : player_ptr->skill_exp) {
416         exp = class_skills_info[enum2i(player_ptr->pclass)].s_max[type];
417     }
418
419     const std::span spells_exp_span(player_ptr->spell_exp);
420     for (auto &exp : spells_exp_span.first(32)) {
421         exp = PlayerSkill::spell_exp_at(PlayerSkillRank::MASTER);
422     }
423     for (auto &exp : spells_exp_span.last(32)) {
424         exp = PlayerSkill::spell_exp_at(PlayerSkillRank::EXPERT);
425     }
426
427     player_ptr->au = 999999999;
428
429     if (PlayerRace(player_ptr).equals(PlayerRaceType::ANDROID)) {
430         return;
431     }
432
433     player_ptr->max_exp = 99999999;
434     player_ptr->exp = 99999999;
435     player_ptr->exp_frac = 0;
436 }
437
438 /*!
439  * @brief プレイヤーの現能力値を調整する / Change various "permanent" player variables.
440  * @param player_ptr プレイヤーへの参照ポインタ
441  */
442 void wiz_change_status(PlayerType *player_ptr)
443 {
444     const auto finalizer = util::make_finalizer([player_ptr]() {
445         check_experience(player_ptr);
446         do_cmd_redraw(player_ptr);
447     });
448
449     constexpr auto msg = _("全てのステータスを最大にしますか?", "Maximize all statuses? ");
450     if (get_check_strict(player_ptr, msg, (CHECK_NO_ESCAPE | CHECK_NO_HISTORY))) {
451         wiz_change_status_max(player_ptr);
452         return;
453     }
454
455     for (int i = 0; i < A_MAX; i++) {
456         const auto max_max_ability_score = player_ptr->stat_max_max[i];
457         const auto max_ability_score = player_ptr->stat_max[i];
458         const auto new_ability_score = input_numerics(stat_names[i], 3, max_max_ability_score, max_ability_score);
459         if (!new_ability_score.has_value()) {
460             return;
461         }
462
463         auto stat = new_ability_score.value();
464         player_ptr->stat_cur[i] = stat;
465         player_ptr->stat_max[i] = stat;
466     }
467
468     const auto unskilled = PlayerSkill::weapon_exp_at(PlayerSkillRank::UNSKILLED);
469     const auto master = PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER);
470     const auto proficiency_opt = input_numerics(_("熟練度", "Proficiency"), unskilled, master, static_cast<short>(master));
471     if (!proficiency_opt.has_value()) {
472         return;
473     }
474
475     const auto proficiency = proficiency_opt.value();
476     for (auto tval : TV_WEAPON_RANGE) {
477         for (int i = 0; i < 64; i++) {
478             player_ptr->weapon_exp[tval][i] = proficiency;
479         }
480     }
481
482     PlayerSkill(player_ptr).limit_weapon_skills_by_max_value();
483     for (auto j : PLAYER_SKILL_KIND_TYPE_RANGE) {
484         player_ptr->skill_exp[j] = proficiency;
485         auto short_pclass = enum2i(player_ptr->pclass);
486         if (player_ptr->skill_exp[j] > class_skills_info[short_pclass].s_max[j]) {
487             player_ptr->skill_exp[j] = class_skills_info[short_pclass].s_max[j];
488         }
489     }
490
491     int k;
492     for (k = 0; k < 32; k++) {
493         player_ptr->spell_exp[k] = std::min(PlayerSkill::spell_exp_at(PlayerSkillRank::MASTER), proficiency);
494     }
495
496     for (; k < 64; k++) {
497         player_ptr->spell_exp[k] = std::min(PlayerSkill::spell_exp_at(PlayerSkillRank::EXPERT), proficiency);
498     }
499
500     const auto gold = input_numerics("Gold: ", 0, MAX_INT, player_ptr->au);
501     if (!gold.has_value()) {
502         return;
503     }
504
505     player_ptr->au = gold.value();
506     if (PlayerRace(player_ptr).equals(PlayerRaceType::ANDROID)) {
507         return;
508     }
509
510     const auto experience_opt = input_numerics("Experience: ", 0, MAX_INT, player_ptr->max_exp);
511     if (!experience_opt.has_value()) {
512         return;
513     }
514
515     const auto experience = experience_opt.value();
516     player_ptr->max_exp = experience;
517     player_ptr->exp = experience;
518     player_ptr->exp_frac = 0;
519 }
520
521 /*!
522  * @brief 指定された地点の地形IDを変更する /
523  * Create desired feature
524  * @param creaturer_ptr プレイヤーへの参照ポインタ
525  */
526 void wiz_create_feature(PlayerType *player_ptr)
527 {
528     POSITION y, x;
529     if (!tgt_pt(player_ptr, &x, &y)) {
530         return;
531     }
532
533     auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
534     const int max = terrains_info.size() - 1;
535     const auto f_val1 = input_numerics(_("実地形ID", "FeatureID"), 0, max, g_ptr->feat);
536     if (!f_val1.has_value()) {
537         return;
538     }
539
540     const auto f_val2 = input_numerics(_("偽装地形ID", "FeatureID"), 0, max, f_val1.value());
541     if (!f_val2.has_value()) {
542         return;
543     }
544
545     cave_set_feat(player_ptr, y, x, f_val1.value());
546     g_ptr->mimic = f_val2.value();
547     auto *f_ptr = &terrains_info[g_ptr->get_feat_mimic()];
548     if (f_ptr->flags.has(TerrainCharacteristics::RUNE_PROTECTION) || f_ptr->flags.has(TerrainCharacteristics::RUNE_EXPLOSION)) {
549         g_ptr->info |= CAVE_OBJECT;
550     } else if (f_ptr->flags.has(TerrainCharacteristics::MIRROR)) {
551         g_ptr->info |= CAVE_GLOW | CAVE_OBJECT;
552     }
553
554     note_spot(player_ptr, y, x);
555     lite_spot(player_ptr, y, x);
556     RedrawingFlagsUpdater::get_instance().set_flag(StatusRecalculatingFlag::FLOW);
557 }
558
559 /*!
560  * @brief デバッグ帰還のダンジョンを選ぶ
561  * @param player_ptr プレイヤーへの参照ポインタ
562  * @details 範囲外の値が選択されたら再入力を促す
563  */
564 static std::optional<short> select_debugging_dungeon(short initial_dungeon_id)
565 {
566     if (command_arg > 0) {
567         return static_cast<short>(std::clamp(static_cast<int>(command_arg), DUNGEON_ANGBAND, DUNGEON_DARKNESS));
568     }
569
570     while (true) {
571         const auto dungeon_id = input_numerics("Jump which dungeon", DUNGEON_ANGBAND, DUNGEON_DARKNESS, initial_dungeon_id);
572         if (!dungeon_id.has_value()) {
573             return std::nullopt;
574         }
575
576         return dungeon_id.value();
577     }
578 }
579
580 /*
581  * @brief 選択したダンジョンの任意レベルを選択する
582  * @param player_ptr プレイヤーへの参照ポインタ
583  * @param dungeon_id ダンジョン番号
584  * @return レベルを選択したらその値、キャンセルならnullopt
585  */
586 static std::optional<int> select_debugging_floor(const FloorType &floor, int dungeon_id)
587 {
588     const auto &dungeon = dungeons_info[dungeon_id];
589     const auto max_depth = dungeon.maxdepth;
590     const auto min_depth = dungeon.mindepth;
591     const auto is_current_dungeon = floor.dungeon_idx == dungeon_id;
592     auto initial_depth = floor.dun_level;
593     if (!is_current_dungeon) {
594         initial_depth = min_depth;
595     }
596
597     return input_numerics("Jump to level", min_depth, max_depth, initial_depth);
598 }
599
600 /*!
601  * @brief 任意のダンジョン及び階層に飛ぶ
602  * Go to any level
603  */
604 static void wiz_jump_floor(PlayerType *player_ptr, DUNGEON_IDX dun_idx, DEPTH depth)
605 {
606     auto &floor = *player_ptr->current_floor_ptr;
607     floor.set_dungeon_index(dun_idx);
608     floor.dun_level = depth;
609     prepare_change_floor_mode(player_ptr, CFM_RAND_PLACE);
610     if (!floor.is_in_dungeon()) {
611         floor.reset_dungeon_index();
612     }
613
614     floor.inside_arena = false;
615     player_ptr->wild_mode = false;
616     leave_quest_check(player_ptr);
617     auto to = !floor.is_in_dungeon()
618                   ? _("地上", "the surface")
619                   : format(_("%d階(%s)", "level %d of %s"), floor.dun_level, floor.get_dungeon_definition().name.data());
620     constexpr auto mes = _("%sへとウィザード・テレポートで移動した。\n", "You wizard-teleported to %s.\n");
621     msg_print_wizard(player_ptr, 2, format(mes, to.data()));
622     floor.quest_number = QuestId::NONE;
623     PlayerEnergy(player_ptr).reset_player_turn();
624     player_ptr->energy_need = 0;
625     prepare_change_floor_mode(player_ptr, CFM_FIRST_FLOOR);
626     player_ptr->leaving = true;
627 }
628
629 /*!
630  * @brief 任意のダンジョン及び階層に飛ぶtための選択処理
631  * Go to any level
632  */
633 void wiz_jump_to_dungeon(PlayerType *player_ptr)
634 {
635     const auto &floor = *player_ptr->current_floor_ptr;
636     const auto is_in_dungeon = floor.is_in_dungeon();
637     const auto dungeon_idx = is_in_dungeon ? floor.dungeon_idx : static_cast<short>(DUNGEON_ANGBAND);
638     const auto dungeon_id_opt = select_debugging_dungeon(dungeon_idx);
639     if (!dungeon_id_opt.has_value()) {
640         if (!is_in_dungeon) {
641             return;
642         }
643
644         if (get_check(("Jump to the ground?"))) {
645             wiz_jump_floor(player_ptr, 0, 0);
646         }
647
648         return;
649     }
650
651     const auto dungeon_id = dungeon_id_opt.value();
652     const auto level_opt = select_debugging_floor(floor, dungeon_id);
653     if (!level_opt.has_value()) {
654         return;
655     }
656
657     const auto level = level_opt.value();
658     msg_format("You jump to dungeon level %d.", level);
659     if (autosave_l) {
660         do_cmd_save_game(player_ptr, true);
661     }
662
663     wiz_jump_floor(player_ptr, dungeon_id, level);
664 }
665
666 /*!
667  * @brief 全ベースアイテムを鑑定済みにする
668  * @param player_ptr プレイヤーへの参照ポインタ
669  */
670 void wiz_learn_items_all(PlayerType *player_ptr)
671 {
672     ItemEntity forge;
673     ItemEntity *q_ptr;
674     for (const auto &baseitem : baseitems_info) {
675         if (baseitem.idx > 0 && baseitem.level <= command_arg) {
676             q_ptr = &forge;
677             q_ptr->prep(baseitem.idx);
678             object_aware(player_ptr, q_ptr);
679         }
680     }
681 }
682
683 static void change_birth_flags()
684 {
685     auto &rfu = RedrawingFlagsUpdater::get_instance();
686     static constexpr auto flags_srf = {
687         StatusRecalculatingFlag::BONUS,
688         StatusRecalculatingFlag::HP,
689         StatusRecalculatingFlag::MP,
690         StatusRecalculatingFlag::SPELLS,
691     };
692     rfu.set_flag(SubWindowRedrawingFlag::PLAYER);
693     rfu.set_flags(flags_srf);
694     static constexpr auto flags_mwrf = {
695         MainWindowRedrawingFlag::BASIC,
696         MainWindowRedrawingFlag::HP,
697         MainWindowRedrawingFlag::MP,
698         MainWindowRedrawingFlag::ABILITY_SCORE,
699     };
700     rfu.set_flags(flags_mwrf);
701 }
702
703 /*!
704  * @brief プレイヤーの種族を変更する
705  */
706 void wiz_reset_race(PlayerType *player_ptr)
707 {
708     const auto new_race = input_numerics("RaceID", 0, MAX_RACES - 1, player_ptr->prace);
709     if (!new_race.has_value()) {
710         return;
711     }
712
713     player_ptr->prace = new_race.value();
714     rp_ptr = &race_info[enum2i(player_ptr->prace)];
715     change_birth_flags();
716     handle_stuff(player_ptr);
717 }
718
719 /*!
720  * @brief プレイヤーの職業を変更する
721  * @todo 魔法領域の再選択などがまだ不完全、要実装。
722  */
723 void wiz_reset_class(PlayerType *player_ptr)
724 {
725     const auto new_class_opt = input_numerics("ClassID", 0, PLAYER_CLASS_TYPE_MAX - 1, player_ptr->pclass);
726     if (!new_class_opt.has_value()) {
727         return;
728     }
729
730     const auto new_class_enum = new_class_opt.value();
731     const auto new_class = enum2i(new_class_enum);
732     player_ptr->pclass = new_class_enum;
733     cp_ptr = &class_info[new_class];
734     mp_ptr = &class_magics_info[new_class];
735     PlayerClass(player_ptr).init_specific_data();
736     change_birth_flags();
737     handle_stuff(player_ptr);
738 }
739
740 /*!
741  * @brief プレイヤーの領域を変更する
742  * @todo 存在有無などは未判定。そのうちすべき。
743  */
744 void wiz_reset_realms(PlayerType *player_ptr)
745 {
746     const auto new_realm1 = input_numerics("1st Realm (None=0)", 0, MAX_REALM - 1, player_ptr->realm1);
747     if (!new_realm1.has_value()) {
748         return;
749     }
750
751     const auto new_realm2 = input_numerics("2nd Realm (None=0)", 0, MAX_REALM - 1, player_ptr->realm2);
752     if (!new_realm2.has_value()) {
753         return;
754     }
755
756     player_ptr->realm1 = new_realm1.value();
757     player_ptr->realm2 = new_realm2.value();
758     change_birth_flags();
759     handle_stuff(player_ptr);
760 }
761
762 /*!
763  * @brief 現在のオプション設定をダンプ出力する /
764  * @param player_ptr プレイヤーへの参照ポインタ
765  * Hack -- Dump option bits usage
766  */
767 void wiz_dump_options(void)
768 {
769     const auto &path = path_build(ANGBAND_DIR_USER, "opt_info.txt");
770     const auto &filename = path.string();
771     auto *fff = angband_fopen(path, FileOpenMode::APPEND);
772     if (fff == nullptr) {
773         msg_format(_("ファイル %s を開けませんでした。", "Failed to open file %s."), filename.data());
774         msg_print(nullptr);
775         return;
776     }
777
778     std::vector<std::vector<int>> exist(NUM_O_SET, std::vector<int>(NUM_O_BIT));
779
780     for (int i = 0; option_info[i].o_desc; i++) {
781         const option_type *ot_ptr = &option_info[i];
782         if (ot_ptr->o_var) {
783             exist[ot_ptr->o_set][ot_ptr->o_bit] = i + 1;
784         }
785     }
786
787     fprintf(fff, "[Option bits usage on %s\n]", get_version().data());
788     fputs("Set - Bit (Page) Option Name\n", fff);
789     fputs("------------------------------------------------\n", fff);
790     for (int i = 0; i < NUM_O_SET; i++) {
791         for (int j = 0; j < NUM_O_BIT; j++) {
792             if (exist[i][j]) {
793                 const option_type *ot_ptr = &option_info[exist[i][j] - 1];
794                 fprintf(fff, "  %d -  %02d (%4d) %s\n", i, j, ot_ptr->o_page, ot_ptr->o_text);
795             } else {
796                 fprintf(fff, "  %d -  %02d\n", i, j);
797             }
798         }
799
800         fputc('\n', fff);
801     }
802
803     angband_fclose(fff);
804     msg_format(_("オプションbit使用状況をファイル %s に書き出しました。", "Option bits usage dump saved to file %s."), filename.data());
805 }
806
807 /*!
808  * @brief プレイ日数を変更する / Set gametime.
809  * @return 実際に変更を行ったらTRUEを返す
810  */
811 void set_gametime(void)
812 {
813     const auto game_time = input_integer("Dungeon Turn", 0, w_ptr->dungeon_turn_limit - 1);
814     if (!game_time.has_value()) {
815         return;
816     }
817
818     w_ptr->dungeon_turn = w_ptr->game_turn = game_time.value();
819 }
820
821 /*!
822  * @brief プレイヤー近辺の全モンスターを消去する / Delete all nearby monsters
823  */
824 void wiz_zap_surrounding_monsters(PlayerType *player_ptr)
825 {
826     for (MONSTER_IDX i = 1; i < player_ptr->current_floor_ptr->m_max; i++) {
827         auto *m_ptr = &player_ptr->current_floor_ptr->m_list[i];
828         if (!m_ptr->is_valid() || (i == player_ptr->riding) || (m_ptr->cdis > MAX_PLAYER_SIGHT)) {
829             continue;
830         }
831
832         if (record_named_pet && m_ptr->is_named_pet()) {
833             const auto m_name = monster_desc(player_ptr, m_ptr, MD_INDEF_VISIBLE);
834             exe_write_diary(player_ptr, DiaryKind::NAMED_PET, RECORD_NAMED_PET_WIZ_ZAP, m_name);
835         }
836
837         delete_monster_idx(player_ptr, i);
838     }
839 }
840
841 /*!
842  * @brief フロアに存在する全モンスターを消去する / Delete all monsters
843  * @param player_ptr 術者の参照ポインタ
844  */
845 void wiz_zap_floor_monsters(PlayerType *player_ptr)
846 {
847     for (MONSTER_IDX i = 1; i < player_ptr->current_floor_ptr->m_max; i++) {
848         auto *m_ptr = &player_ptr->current_floor_ptr->m_list[i];
849         if (!m_ptr->is_valid() || (i == player_ptr->riding)) {
850             continue;
851         }
852
853         if (record_named_pet && m_ptr->is_named_pet()) {
854             const auto m_name = monster_desc(player_ptr, m_ptr, MD_INDEF_VISIBLE);
855             exe_write_diary(player_ptr, DiaryKind::NAMED_PET, RECORD_NAMED_PET_WIZ_ZAP, m_name);
856         }
857
858         delete_monster_idx(player_ptr, i);
859     }
860 }
861
862 void cheat_death(PlayerType *player_ptr)
863 {
864     if (player_ptr->sc) {
865         player_ptr->sc = player_ptr->age = 0;
866     }
867     player_ptr->age++;
868
869     w_ptr->noscore |= 0x0001;
870     msg_print(_("ウィザードモードに念を送り、死を欺いた。", "You invoke wizard mode and cheat death."));
871     msg_print(nullptr);
872
873     player_ptr->is_dead = false;
874     (void)life_stream(player_ptr, false, false);
875     (void)restore_mana(player_ptr, true);
876     (void)recall_player(player_ptr, 0);
877     reserve_alter_reality(player_ptr, 0);
878
879     player_ptr->died_from = _("死の欺き", "Cheating death");
880     (void)set_food(player_ptr, PY_FOOD_MAX - 1);
881
882     auto *floor_ptr = player_ptr->current_floor_ptr;
883     floor_ptr->dun_level = 0;
884     floor_ptr->inside_arena = false;
885     player_ptr->phase_out = false;
886     leaving_quest = QuestId::NONE;
887     floor_ptr->quest_number = QuestId::NONE;
888     if (floor_ptr->dungeon_idx) {
889         player_ptr->recall_dungeon = floor_ptr->dungeon_idx;
890     }
891
892     floor_ptr->reset_dungeon_index();
893     if (lite_town || vanilla_town) {
894         player_ptr->wilderness_y = 1;
895         player_ptr->wilderness_x = 1;
896         if (vanilla_town) {
897             player_ptr->oldpy = 10;
898             player_ptr->oldpx = 34;
899         } else {
900             player_ptr->oldpy = 33;
901             player_ptr->oldpx = 131;
902         }
903     } else {
904         player_ptr->wilderness_y = 48;
905         player_ptr->wilderness_x = 5;
906         player_ptr->oldpy = 33;
907         player_ptr->oldpx = 131;
908     }
909
910     player_ptr->wild_mode = false;
911     player_ptr->leaving = true;
912     constexpr auto note = _("                            しかし、生き返った。", "                            but revived.");
913     exe_write_diary(player_ptr, DiaryKind::DESCRIPTION, 1, note);
914     leave_floor(player_ptr);
915 }