OSDN Git Service

Merge pull request #1421 from sikabane-works/feature/refactor-io-dump-comment
[hengbandforosx/hengbandosx.git] / src / wizard / cmd-wizard.cpp
1 /*!
2  * @brief デバッグコマンドの分岐実装
3  * @date 2020/08/01
4  * @author Hourier
5  * @details 通常のコマンドではないのでcmd-xxx/ ではなくwizard/ 以下に置く
6  */
7
8 #include "wizard/cmd-wizard.h"
9 #include "birth/inventory-initializer.h"
10 #include "cmd-io/cmd-help.h"
11 #include "core/asking-player.h"
12 #include "inventory/inventory-object.h"
13 #include "inventory/inventory-slot-types.h"
14 #include "io/input-key-requester.h"
15 #include "mutation/mutation-investor-remover.h"
16 #include "player/patron.h"
17 #include "spell-kind/spells-detection.h"
18 #include "spell-kind/spells-floor.h"
19 #include "spell-kind/spells-perception.h"
20 #include "spell-kind/spells-sight.h"
21 #include "spell-kind/spells-teleport.h"
22 #include "spell/spells-status.h"
23 #include "status/experience.h"
24 #include "system/floor-type-definition.h"
25 #include "system/grid-type-definition.h"
26 #include "system/object-type-definition.h"
27 #include "system/player-type-definition.h"
28 #include "term/screen-processor.h"
29 #include "util/int-char-converter.h"
30 #include "view/display-messages.h"
31 #include "wizard/wizard-game-modifier.h"
32 #include "wizard/wizard-item-modifier.h"
33 #include "wizard/wizard-player-modifier.h"
34 #include "wizard/wizard-special-process.h"
35 #include "wizard/wizard-spells.h"
36 #include "wizard/wizard-spoiler.h"
37 #include <sstream>
38 #include <string>
39 #include <vector>
40
41 /*!
42  * @brief デバグコマンド一覧表
43  * @details
44  * 空き: A,B,E,I,J,k,K,L,M,q,Q,R,T,U,V,W,y,Y
45  */
46 std::vector<std::vector<std::string>> debug_menu_table = {
47     { "a", _("全状態回復", "Restore all status") },
48     { "b", _("現在のターゲットを引き寄せる", "Teleport target back") },
49     { "c", _("オブジェクト生成", "Create object") },
50     { "C", _("固定アーティファクト生成", "Create fixed artifact") },
51     { "d", _("全感知", "Detection all") },
52     { "D", _("次元の扉", "Dimension door") },
53     { "e", _("能力値変更", "Modify player status") },
54     { "E", _("青魔法を全取得", "Make all blue magic learned") },
55     { "f", _("*鑑定*", "*Idenfity*") },
56     { "F", _("地形ID変更", "Modify feature type under player") },
57     { "G", _("ゲーム設定コマンドメニュー", "Modify game configurations") },
58     { "H", _("モンスターの群れ生成", "Summon monsters") },
59     { "i", _("鑑定", "Idenfity") },
60     { "I", _("アイテム設定コマンドメニュー", "Modify item configurations") },
61     { "j", _("指定ダンジョン階にワープ", "Jump to floor depth of target dungeon") },
62     { "k", _("指定ダメージ・半径0の指定属性のボールを自分に放つ", "Fire a zero ball to self") },
63     { "m", _("魔法の地図", "Magic mapping") },
64     { "n", _("指定モンスター生成", "Summon target monster") },
65     { "N", _("指定モンスターをペットとして生成", "Summon target monster as pet") },
66     { "o", _("オブジェクトの能力変更", "Modift object abilities") },
67     { "O", _("オプション設定をダンプ", "Dump current options") },
68     { "p", _("ショート・テレポート", "Phase door") },
69     { "P", _("プレイヤー設定変更メニュー", "Modify player configurations") },
70     { "r", _("カオスパトロンの報酬", "Get reward of chaos patron") },
71     { "s", _("フロア相当のモンスター召喚", "Summon monster which be in target depth") },
72     { "t", _("テレポート", "Teleport self") },
73     { "u", _("啓蒙(忍者以外)", "Wiz-lite all floor except Ninja") },
74     { "w", _("啓蒙(忍者配慮)", "Wiz-lite all floor") },
75     { "x", _("経験値を得る(指定可)", "Get experience") },
76     { "X", _("所持品を初期状態に戻す", "Return inventory to initial") },
77     { "y", _("ダメージ100万・半径0の射撃のボールを放つ", "Cast missile ball had power a million") },
78     { "Y", _("指定ダメージ・半径0の指定属性のボールを放つ", "Cast zero ball had power a thousand") },
79     { "z", _("近隣のモンスター消去", "Terminate near monsters") },
80     { "Z", _("フロアの全モンスター消去", "Terminate all monsters in floor") },
81     { "@", _("特殊スペルの発動", "Activate specified spells") },
82     { "\"", _("スポイラーのダンプ", "Dump spoiler") },
83     { "?", _("ヘルプ表示", "Help") },
84 };
85
86 /*!
87  * @brief デバグコマンドの一覧を表示する
88  * @param page ページ番号
89  * @param max_page ページ数
90  * @param page_size 1ページ行数
91  * @param max_line コマンド数
92  */
93 void display_debug_menu(int page, int max_page, int page_size, int max_line)
94 {
95     for (int y = 1; y < page_size + 3; y++)
96         term_erase(14, y, 64);
97
98     int r = 1;
99     int c = 15;
100     for (int i = 0; i < page_size; i++) {
101         int pos = page * page_size + i;
102         if (pos >= max_line)
103             break;
104
105         std::stringstream ss;
106         ss << debug_menu_table[pos][0] << ") " << debug_menu_table[pos][1];
107         put_str(ss.str().c_str(), r++, c);
108     }
109     if (max_page > 0)
110         put_str("-- more --", r++, c);
111 }
112
113 /*!
114  * @brief デバッグコマンド選択処理への分岐
115  * @param creature_ptr プレーヤーへの参照ポインタ
116  * @param cmd コマンドキー
117  * @return コマンド終了ならTRUE、ページ送りならFALSE
118  */
119 bool exe_cmd_debug(player_type *creature_ptr, char cmd)
120 {
121     switch (cmd) {
122     case ' ':
123     case '<':
124     case '>':
125     case KTRL('a'):
126         return false;
127     case ESCAPE:
128     case '\n':
129     case '\r':
130         break;
131     case 'a':
132         wiz_cure_all(creature_ptr);
133         break;
134     case 'b':
135         wiz_teleport_back(creature_ptr);
136         break;
137     case 'c':
138         wiz_create_item(creature_ptr);
139         break;
140     case 'C':
141         wiz_create_named_art(creature_ptr, command_arg);
142         break;
143     case 'd':
144         detect_all(creature_ptr, DETECT_RAD_ALL * 3);
145         break;
146     case 'D':
147         wiz_dimension_door(creature_ptr);
148         break;
149     case 'e':
150         wiz_change_status(creature_ptr);
151         break;
152     case 'E':
153         if (creature_ptr->pclass == CLASS_BLUE_MAGE)
154             wiz_learn_blue_magic_all(creature_ptr);
155
156         break;
157     case 'f':
158         identify_fully(creature_ptr, false);
159         break;
160     case 'F':
161         wiz_create_feature(creature_ptr);
162         break;
163     case 'G':
164         wizard_game_modifier(creature_ptr);
165         break;
166     case 'H':
167         wiz_summon_horde(creature_ptr);
168         break;
169     case 'i':
170         (void)ident_spell(creature_ptr, false);
171         break;
172     case 'I':
173         wizard_item_modifier(creature_ptr);
174         break;
175     case 'j':
176         wiz_jump_to_dungeon(creature_ptr);
177         break;
178     case 'k':
179         wiz_kill_me(creature_ptr, 0, command_arg);
180         break;
181     case 'm':
182         map_area(creature_ptr, DETECT_RAD_ALL * 3);
183         break;
184     case 'r':
185         gain_level_reward(creature_ptr, command_arg);
186         break;
187     case 'N':
188         wiz_summon_pet(creature_ptr, command_arg);
189         break;
190     case 'n':
191         wiz_summon_specific_enemy(creature_ptr, command_arg);
192         break;
193     case 'O':
194         wiz_dump_options();
195         break;
196     case 'o':
197         wiz_modify_item(creature_ptr);
198         break;
199     case 'p':
200         teleport_player(creature_ptr, 10, TELEPORT_SPONTANEOUS);
201         break;
202     case 'P':
203         wizard_player_modifier(creature_ptr);
204         break;
205     case 's':
206         if (command_arg <= 0)
207             command_arg = 1;
208
209         wiz_summon_random_enemy(creature_ptr, command_arg);
210         break;
211     case 't':
212         teleport_player(creature_ptr, 100, TELEPORT_SPONTANEOUS);
213         break;
214     case 'u':
215         for (int y = 0; y < creature_ptr->current_floor_ptr->height; y++)
216             for (int x = 0; x < creature_ptr->current_floor_ptr->width; x++)
217                 creature_ptr->current_floor_ptr->grid_array[y][x].info |= CAVE_GLOW | CAVE_MARK;
218
219         wiz_lite(creature_ptr, false);
220         break;
221     case 'w':
222         wiz_lite(creature_ptr, (bool)(creature_ptr->pclass == CLASS_NINJA));
223         break;
224     case 'x':
225         gain_exp(creature_ptr, command_arg ? command_arg : (creature_ptr->exp + 1));
226         break;
227     case 'X':
228         for (INVENTORY_IDX i = INVEN_TOTAL - 1; i >= 0; i--)
229             if (creature_ptr->inventory_list[i].k_idx)
230                 drop_from_inventory(creature_ptr, i, 999);
231
232         player_outfit(creature_ptr);
233         break;
234     case 'y':
235         wiz_kill_enemy(creature_ptr);
236         break;
237     case 'Y':
238         wiz_kill_enemy(creature_ptr, 0, command_arg);
239         break;
240     case 'z':
241         wiz_zap_surrounding_monsters(creature_ptr);
242         break;
243     case 'Z':
244         wiz_zap_floor_monsters(creature_ptr);
245         break;
246     case '_':
247         probing(creature_ptr);
248         break;
249     case '@':
250         wiz_debug_spell(creature_ptr);
251         break;
252     case '"':
253         exe_output_spoilers();
254         break;
255     case '?':
256         do_cmd_help(creature_ptr);
257         break;
258     default:
259         msg_print("That is not a valid debug command.");
260         break;
261     }
262
263     return true;
264 }
265
266 /*!
267  * @brief デバッグコマンドを選択する処理のメインルーチン /
268  * Ask for and parse a "debug command"
269  * The "command_arg" may have been set.
270  * @param creature_ptr プレーヤーへの参照ポインタ
271  * @details
272  * 番号を指定するには、それをN及びデバッグコマンドをXとしてとして「0N^aX」とする
273  */
274 void do_cmd_debug(player_type *creature_ptr)
275 {
276     TERM_LEN hgt, wid;
277     term_get_size(&wid, &hgt);
278
279     size_t max_line = debug_menu_table.size();
280     int page_size = hgt - 5;
281     int max_page = max_line / page_size + 1;
282     int page = 0;
283     char cmd;
284
285     while (true) {
286         screen_save();
287         display_debug_menu(page, max_page, page_size, max_line);
288         get_com("Debug Command: ", &cmd, false);
289         screen_load();
290
291         if (exe_cmd_debug(creature_ptr, cmd))
292             break;
293
294         page = (page + 1) % max_page;
295     }
296 }