OSDN Git Service

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