OSDN Git Service

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