2 * @brief ウィザードモードの処理(特別処理中心) / Wizard commands
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>
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/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/apply-magic.h"
52 #include "object-enchant/item-apply-magic.h"
53 #include "object-enchant/trc-types.h"
54 #include "object-enchant/trg-types.h"
55 #include "object/object-kind.h"
56 #include "perception/object-perception.h"
57 #include "player-info/class-info.h"
58 #include "player-info/race-info.h"
59 #include "player-info/race-types.h"
60 #include "player-info/self-info.h"
61 #include "player-status/player-energy.h"
62 #include "player/digestion-processor.h"
63 #include "player/patron.h"
64 #include "player/player-skill.h"
65 #include "player/player-status-table.h"
66 #include "player/player-status.h"
67 #include "player/race-info-table.h"
68 #include "spell-kind/spells-detection.h"
69 #include "spell-kind/spells-sight.h"
70 #include "spell-kind/spells-teleport.h"
71 #include "spell-kind/spells-world.h"
72 #include "spell/spells-object.h"
73 #include "spell/spells-status.h"
74 #include "spell/spells-summon.h"
75 #include "status/experience.h"
76 #include "system/angband-version.h"
77 #include "system/artifact-type-definition.h"
78 #include "system/floor-type-definition.h"
79 #include "system/grid-type-definition.h"
80 #include "system/monster-type-definition.h"
81 #include "system/player-type-definition.h"
82 #include "target/grid-selector.h"
83 #include "term/screen-processor.h"
84 #include "util/angband-files.h"
85 #include "util/bit-flags-calculator.h"
86 #include "util/enum-converter.h"
87 #include "util/int-char-converter.h"
88 #include "view/display-messages.h"
89 #include "wizard/tval-descriptions-table.h"
90 #include "wizard/wizard-spells.h"
91 #include "wizard/wizard-spoiler.h"
92 #include "world/world.h"
97 * @brief プレイヤーを完全回復する /
98 * Cure everything instantly
100 void wiz_cure_all(player_type *player_ptr)
102 (void)life_stream(player_ptr, false, false);
103 (void)restore_mana(player_ptr, true);
104 (void)set_food(player_ptr, PY_FOOD_MAX - 1);
108 * @brief ベースアイテムのウィザード生成のために大項目IDと小項目IDを取得する /
109 * Specify tval and sval (type and subtype of object) originally
112 * by RAK, heavily modified by -Bernd-
113 * This function returns the k_idx of an object type, or zero if failed
114 * List up to 50 choices in three columns
116 KIND_OBJECT_IDX wiz_create_itemtype(void)
122 for (num = 0; (num < 80) && tvals[num].tval; num++) {
123 row = 2 + (num % 20);
124 col = 20 * (num / 20);
126 prt(format("[%c] %s", ch, tvals[num].desc), row, col);
130 if (!get_com("Get what type of object? ", &ch, false))
133 for (num = 0; num < max_num; num++)
134 if (listsym[num] == ch)
137 if ((num < 0) || (num >= max_num))
140 tval_type tval = i2enum<tval_type>(tvals[num].tval);
141 concptr tval_desc = tvals[num].desc;
144 KIND_OBJECT_IDX choice[80];
146 for (const auto& k_ref : k_info) {
150 if (k_ref.idx == 0 || k_ref.tval != tval)
153 row = 2 + (num % 20);
154 col = 20 * (num / 20);
157 strip_name(buf, k_ref.idx);
158 prt(format("[%c] %s", ch, buf), row, col);
159 choice[num++] = k_ref.idx;
163 if (!get_com(format("What Kind of %s? ", tval_desc), &ch, false))
166 for (num = 0; num < max_num; num++)
167 if (listsym[num] == ch)
170 if ((num < 0) || (num >= max_num))
177 * @brief 任意のベースアイテム生成のメインルーチン /
178 * Wizard routine for creating objects -RAK-
180 * Heavily modified to allow magification and artifactification -Bernd-
182 * Note that wizards cannot create objects on top of other objects.
184 * Hack -- this routine always makes a "dungeon object", and applies
185 * magic to it, and attempts to decline cursed items.
187 void wiz_create_item(player_type *player_ptr)
190 OBJECT_IDX k_idx = wiz_create_itemtype();
195 if (k_info[k_idx].gen_flags.has(TRG::INSTA_ART)) {
196 for (const auto &a_ref : a_info) {
197 if ((a_ref.idx == 0) || (a_ref.tval != k_info[k_idx].tval) || (a_ref.sval != k_info[k_idx].sval))
200 (void)create_named_art(player_ptr, a_ref.idx, player_ptr->y, player_ptr->x);
201 msg_print("Allocated(INSTA_ART).");
210 apply_magic_to_object(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART);
211 (void)drop_near(player_ptr, q_ptr, -1, player_ptr->y, player_ptr->x);
212 msg_print("Allocated.");
216 * @brief 指定されたIDの固定アーティファクトを生成する / Create the artifact of the specified number
217 * @param player_ptr プレイヤーへの参照ポインタ
219 void wiz_create_named_art(player_type *player_ptr, ARTIFACT_IDX a_idx)
223 if (!get_value("ArtifactID", 1, a_info.size() - 1, &val)) {
226 a_idx = static_cast<ARTIFACT_IDX>(val);
230 (void)create_named_art(player_ptr, a_idx, player_ptr->y, player_ptr->x);
231 msg_print("Allocated.");
235 * @brief プレイヤーの現能力値を調整する / Change various "permanent" player variables.
236 * @param player_ptr プレイヤーへの参照ポインタ
238 void wiz_change_status(player_type *player_ptr)
243 for (int i = 0; i < A_MAX; i++) {
244 sprintf(ppp, "%s (3-%d): ", stat_names[i], player_ptr->stat_max_max[i]);
245 sprintf(tmp_val, "%d", player_ptr->stat_max[i]);
246 if (!get_string(ppp, tmp_val, 3))
249 tmp_int = atoi(tmp_val);
250 if (tmp_int > player_ptr->stat_max_max[i])
251 tmp_int = player_ptr->stat_max_max[i];
252 else if (tmp_int < 3)
255 player_ptr->stat_cur[i] = player_ptr->stat_max[i] = (BASE_STATUS)tmp_int;
258 sprintf(tmp_val, "%d", WEAPON_EXP_MASTER);
259 if (!get_string(_("熟練度: ", "Proficiency: "), tmp_val, 4))
262 int16_t tmp_s16b = (int16_t)atoi(tmp_val);
263 if (tmp_s16b < WEAPON_EXP_UNSKILLED)
264 tmp_s16b = WEAPON_EXP_UNSKILLED;
266 if (tmp_s16b > WEAPON_EXP_MASTER)
267 tmp_s16b = WEAPON_EXP_MASTER;
269 for (int j = 0; j <= TV_WEAPON_END - TV_WEAPON_BEGIN; j++) {
270 for (int i = 0; i < 64; i++) {
271 player_ptr->weapon_exp[j][i] = tmp_s16b;
272 if (player_ptr->weapon_exp[j][i] > s_info[player_ptr->pclass].w_max[j][i])
273 player_ptr->weapon_exp[j][i] = s_info[player_ptr->pclass].w_max[j][i];
277 for (int j = 0; j < 10; j++) {
278 player_ptr->skill_exp[j] = tmp_s16b;
279 if (player_ptr->skill_exp[j] > s_info[player_ptr->pclass].s_max[j])
280 player_ptr->skill_exp[j] = s_info[player_ptr->pclass].s_max[j];
284 for (k = 0; k < 32; k++)
285 player_ptr->spell_exp[k] = (tmp_s16b > SPELL_EXP_MASTER ? SPELL_EXP_MASTER : tmp_s16b);
288 player_ptr->spell_exp[k] = (tmp_s16b > SPELL_EXP_EXPERT ? SPELL_EXP_EXPERT : tmp_s16b);
290 sprintf(tmp_val, "%ld", (long)(player_ptr->au));
291 if (!get_string("Gold: ", tmp_val, 9))
294 long tmp_long = atol(tmp_val);
298 player_ptr->au = tmp_long;
299 sprintf(tmp_val, "%ld", (long)(player_ptr->max_exp));
300 if (!get_string("Experience: ", tmp_val, 9))
303 tmp_long = atol(tmp_val);
307 if (player_ptr->prace == player_race_type::ANDROID)
310 player_ptr->max_exp = tmp_long;
311 player_ptr->exp = tmp_long;
312 check_experience(player_ptr);
313 do_cmd_redraw(player_ptr);
317 * @brief 指定された地点の地形IDを変更する /
318 * Create desired feature
319 * @param creaturer_ptr プレイヤーへの参照ポインタ
321 void wiz_create_feature(player_type *player_ptr)
324 if (!tgt_pt(player_ptr, &x, &y))
328 g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
329 static int prev_feat = 0;
331 sprintf(tmp_val, "%d", prev_feat);
333 if (!get_string(_("地形: ", "Feature: "), tmp_val, 3))
336 FEAT_IDX tmp_feat = (FEAT_IDX)atoi(tmp_val);
339 else if (tmp_feat >= max_f_idx)
340 tmp_feat = max_f_idx - 1;
342 static int prev_mimic = 0;
343 sprintf(tmp_val, "%d", prev_mimic);
345 if (!get_string(_("地形 (mimic): ", "Feature (mimic): "), tmp_val, 3))
348 FEAT_IDX tmp_mimic = (FEAT_IDX)atoi(tmp_val);
351 else if (tmp_mimic >= max_f_idx)
352 tmp_mimic = max_f_idx - 1;
354 cave_set_feat(player_ptr, y, x, tmp_feat);
355 g_ptr->mimic = (int16_t)tmp_mimic;
357 f_ptr = &f_info[g_ptr->get_feat_mimic()];
359 if (f_ptr->flags.has(FF::RUNE_PROTECTION) || f_ptr->flags.has(FF::RUNE_EXPLOSION))
360 g_ptr->info |= CAVE_OBJECT;
361 else if (f_ptr->flags.has(FF::MIRROR))
362 g_ptr->info |= CAVE_GLOW | CAVE_OBJECT;
364 note_spot(player_ptr, y, x);
365 lite_spot(player_ptr, y, x);
366 player_ptr->update |= PU_FLOW;
367 prev_feat = tmp_feat;
368 prev_mimic = tmp_mimic;
372 * @brief 選択したダンジョンの任意フロアを選択する
373 * @param player_ptr プレイヤーへの参照ポインタ
374 * @param dungeon_type ダンジョン番号
375 * @return フロアを選択したらtrue、キャンセルならfalse
376 * @details 0を指定すると地上に飛ぶが、元いた場所にしか飛ばない
377 * @todo 可能ならダンジョンの入口 (例:ルルイエなら大洋の真ん中)へ飛べるようにしたい
379 static bool select_debugging_floor(player_type *player_ptr, int dungeon_type)
381 auto max_depth = d_info[dungeon_type].maxdepth;
382 if ((max_depth == 0) || (dungeon_type > w_ptr->max_d_idx)) {
383 dungeon_type = DUNGEON_ANGBAND;
386 auto min_depth = (int)d_info[dungeon_type].mindepth;
390 sprintf(ppp, "Jump to level (0, %d-%d): ", min_depth, max_depth);
391 sprintf(tmp_val, "%d", (int)player_ptr->current_floor_ptr->dun_level);
392 if (!get_string(ppp, tmp_val, 10)) {
396 auto tmp_command_arg = (COMMAND_ARG)atoi(tmp_val);
397 if (tmp_command_arg == 0) {
398 command_arg = tmp_command_arg;
402 auto is_valid_floor = tmp_command_arg > 0;
403 is_valid_floor &= tmp_command_arg >= min_depth;
404 is_valid_floor &= tmp_command_arg <= max_depth;
405 if (is_valid_floor) {
406 command_arg = tmp_command_arg;
410 msg_print("Invalid floor. Please re-input.");
418 * @brief デバッグ帰還のダンジョンを選ぶ
419 * @param player_ptr プレイヤーへの参照ポインタ
420 * @details 範囲外の値が選択されたら再入力を促す
422 static bool select_debugging_dungeon(player_type *player_ptr, DUNGEON_IDX *dungeon_type)
424 if (command_arg > 0) {
431 sprintf(ppp, "Jump which dungeon : ");
432 sprintf(tmp_val, "%d", player_ptr->dungeon_idx);
433 if (!get_string(ppp, tmp_val, 2)) {
437 *dungeon_type = (DUNGEON_IDX)atoi(tmp_val);
438 if ((*dungeon_type < DUNGEON_ANGBAND) || (*dungeon_type > DUNGEON_MAX)) {
439 msg_print("Invalid dungeon. Please re-input.");
448 * @brief 任意のダンジョン及び階層に飛ぶtための選択処理
451 void wiz_jump_to_dungeon(player_type *player_ptr)
453 DUNGEON_IDX dungeon_type = 1;
454 if (!select_debugging_dungeon(player_ptr, &dungeon_type)) {
458 if (!select_debugging_floor(player_ptr, dungeon_type)) {
462 if (command_arg < d_info[dungeon_type].mindepth)
465 if (command_arg > d_info[dungeon_type].maxdepth)
466 command_arg = (COMMAND_ARG)d_info[dungeon_type].maxdepth;
468 msg_format("You jump to dungeon level %d.", command_arg);
470 do_cmd_save_game(player_ptr, true);
472 jump_floor(player_ptr, dungeon_type, command_arg);
476 * @brief 全ベースアイテムを鑑定済みにする /
477 * Become aware of a lot of objects
478 * @param player_ptr プレイヤーへの参照ポインタ
480 void wiz_learn_items_all(player_type *player_ptr)
484 for (const auto &k_ref : k_info) {
485 if (k_ref.idx > 0 && k_ref.level <= command_arg) {
487 q_ptr->prep(k_ref.idx);
488 object_aware(player_ptr, q_ptr);
494 * @brief プレイヤーの種族を変更する
496 void wiz_reset_race(player_type *player_ptr)
499 sprintf(ppp, "Race (0-%d): ", MAX_RACES - 1);
502 sprintf(tmp_val, "%d", enum2i(player_ptr->prace));
504 if (!get_string(ppp, tmp_val, 2))
507 int tmp_int = atoi(tmp_val);
508 if (tmp_int < 0 || tmp_int >= MAX_RACES)
511 player_ptr->prace = i2enum<player_race_type>(tmp_int);
512 rp_ptr = &race_info[enum2i(player_ptr->prace)];
514 player_ptr->window_flags |= PW_PLAYER;
515 player_ptr->update |= PU_BONUS | PU_HP | PU_MANA | PU_SPELLS;
516 player_ptr->redraw |= PR_BASIC | PR_HP | PR_MANA | PR_STATS;
517 handle_stuff(player_ptr);
521 * @brief プレイヤーの職業を変更する
522 * @todo 魔法領域の再選択などがまだ不完全、要実装。
524 void wiz_reset_class(player_type *player_ptr)
527 sprintf(ppp, "Class (0-%d): ", MAX_CLASS - 1);
530 sprintf(tmp_val, "%d", player_ptr->pclass);
532 if (!get_string(ppp, tmp_val, 2))
535 int tmp_int = atoi(tmp_val);
536 if (tmp_int < 0 || tmp_int >= MAX_CLASS)
539 player_ptr->pclass = i2enum<player_class_type>(tmp_int);
540 cp_ptr = &class_info[player_ptr->pclass];
541 mp_ptr = &m_info[player_ptr->pclass];
542 player_ptr->window_flags |= PW_PLAYER;
543 player_ptr->update |= PU_BONUS | PU_HP | PU_MANA | PU_SPELLS;
544 player_ptr->redraw |= PR_BASIC | PR_HP | PR_MANA | PR_STATS;
545 handle_stuff(player_ptr);
549 * @brief プレイヤーの領域を変更する
550 * @todo 存在有無などは未判定。そのうちすべき。
552 void wiz_reset_realms(player_type *player_ptr)
557 sprintf(ppp, "1st Realm (None=0, 1-%d): ", MAX_REALM - 1);
558 sprintf(tmp_val, "%d", player_ptr->realm1);
559 if (!get_string(ppp, tmp_val, 2))
562 player_ptr->realm1 = static_cast<int16_t>(atoi(tmp_val));
564 sprintf(ppp, "2st Realm (None=0, 1-%d): ", MAX_REALM - 1);
565 sprintf(tmp_val, "%d", player_ptr->realm2);
566 if (!get_string(ppp, tmp_val, 2))
569 player_ptr->realm2 = static_cast<int16_t>(atoi(tmp_val));
570 player_ptr->window_flags |= PW_PLAYER;
571 player_ptr->update |= PU_BONUS | PU_HP | PU_MANA | PU_SPELLS;
572 player_ptr->redraw |= PR_BASIC;
573 handle_stuff(player_ptr);
577 * @brief 現在のオプション設定をダンプ出力する /
578 * @param player_ptr プレイヤーへの参照ポインタ
579 * Hack -- Dump option bits usage
581 void wiz_dump_options(void)
584 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, "opt_info.txt");
586 fff = angband_fopen(buf, "a");
587 if (fff == nullptr) {
588 msg_format(_("ファイル %s を開けませんでした。", "Failed to open file %s."), buf);
593 std::vector<std::vector<int>> exist(NUM_O_SET, std::vector<int>(NUM_O_BIT));
595 for (int i = 0; option_info[i].o_desc; i++) {
596 const option_type *ot_ptr = &option_info[i];
598 exist[ot_ptr->o_set][ot_ptr->o_bit] = i + 1;
603 fprintf(fff, "[Option bits usage on %s\n]", title);
604 fputs("Set - Bit (Page) Option Name\n", fff);
605 fputs("------------------------------------------------\n", fff);
606 for (int i = 0; i < NUM_O_SET; i++) {
607 for (int j = 0; j < NUM_O_BIT; j++) {
609 const option_type *ot_ptr = &option_info[exist[i][j] - 1];
610 fprintf(fff, " %d - %02d (%4d) %s\n", i, j, ot_ptr->o_page, ot_ptr->o_text);
612 fprintf(fff, " %d - %02d\n", i, j);
620 msg_format(_("オプションbit使用状況をファイル %s に書き出しました。", "Option bits usage dump saved to file %s."), buf);
624 * @brief プレイ日数を変更する / Set gametime.
625 * @return 実際に変更を行ったらTRUEを返す
627 void set_gametime(void)
630 char ppp[80], tmp_val[40];
631 sprintf(ppp, "Dungeon Turn (0-%ld): ", (long)w_ptr->dungeon_turn_limit);
632 sprintf(tmp_val, "%ld", (long)w_ptr->dungeon_turn);
633 if (!get_string(ppp, tmp_val, 10))
636 tmp_int = atoi(tmp_val);
637 if (tmp_int >= w_ptr->dungeon_turn_limit)
638 tmp_int = w_ptr->dungeon_turn_limit - 1;
639 else if (tmp_int < 0)
642 w_ptr->dungeon_turn = w_ptr->game_turn = tmp_int;
646 * @brief プレイヤー近辺の全モンスターを消去する / Delete all nearby monsters
648 void wiz_zap_surrounding_monsters(player_type *player_ptr)
650 for (MONSTER_IDX i = 1; i < player_ptr->current_floor_ptr->m_max; i++) {
651 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[i];
652 if (!monster_is_valid(m_ptr) || (i == player_ptr->riding) || (m_ptr->cdis > MAX_SIGHT))
655 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname) {
656 GAME_TEXT m_name[MAX_NLEN];
658 monster_desc(player_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
659 exe_write_diary(player_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_WIZ_ZAP, m_name);
662 delete_monster_idx(player_ptr, i);
667 * @brief フロアに存在する全モンスターを消去する / Delete all monsters
668 * @param player_ptr 術者の参照ポインタ
670 void wiz_zap_floor_monsters(player_type *player_ptr)
672 for (MONSTER_IDX i = 1; i < player_ptr->current_floor_ptr->m_max; i++) {
673 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[i];
674 if (!monster_is_valid(m_ptr) || (i == player_ptr->riding))
677 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname) {
678 GAME_TEXT m_name[MAX_NLEN];
679 monster_desc(player_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
680 exe_write_diary(player_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_WIZ_ZAP, m_name);
683 delete_monster_idx(player_ptr, i);
687 void cheat_death(player_type *player_ptr)
690 player_ptr->sc = player_ptr->age = 0;
693 w_ptr->noscore |= 0x0001;
694 msg_print(_("ウィザードモードに念を送り、死を欺いた。", "You invoke wizard mode and cheat death."));
697 player_ptr->is_dead = false;
698 (void)life_stream(player_ptr, false, false);
699 (void)restore_mana(player_ptr, true);
700 (void)recall_player(player_ptr, 0);
701 reserve_alter_reality(player_ptr, 0);
703 (void)strcpy(player_ptr->died_from, _("死の欺き", "Cheating death"));
704 (void)set_food(player_ptr, PY_FOOD_MAX - 1);
706 floor_type *floor_ptr = player_ptr->current_floor_ptr;
707 floor_ptr->dun_level = 0;
708 floor_ptr->inside_arena = false;
709 player_ptr->phase_out = false;
711 floor_ptr->inside_quest = 0;
712 if (player_ptr->dungeon_idx)
713 player_ptr->recall_dungeon = player_ptr->dungeon_idx;
714 player_ptr->dungeon_idx = 0;
715 if (lite_town || vanilla_town) {
716 player_ptr->wilderness_y = 1;
717 player_ptr->wilderness_x = 1;
719 player_ptr->oldpy = 10;
720 player_ptr->oldpx = 34;
722 player_ptr->oldpy = 33;
723 player_ptr->oldpx = 131;
726 player_ptr->wilderness_y = 48;
727 player_ptr->wilderness_x = 5;
728 player_ptr->oldpy = 33;
729 player_ptr->oldpx = 131;
732 player_ptr->wild_mode = false;
733 player_ptr->leaving = true;
735 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 1, _(" しかし、生き返った。", " but revived."));
736 leave_floor(player_ptr);