OSDN Git Service

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