OSDN Git Service

Merge pull request #1254 from habu1010/feature/fix-r-info-english-name-load
[hengbandforosx/hengbandosx.git] / src / wizard / wizard-game-modifier.cpp
1 /*!
2  * @brief ゲーム属性を変更するデバッグコマンド
3  * @date 2021/03/07
4  */
5
6 #include "wizard/wizard-game-modifier.h"
7 #include "core/asking-player.h"
8 #include "dungeon/quest.h"
9 #include "info-reader/fixed-map-parser.h"
10 #include "io/input-key-requester.h"
11 #include "market/arena.h"
12 #include "monster-race/monster-race.h"
13 #include "monster-race/race-flags1.h"
14 #include "monster-race/race-flags7.h"
15 #include "player-info/self-info.h"
16 #include "system/floor-type-definition.h"
17 #include "system/monster-race-definition.h"
18 #include "system/player-type-definition.h"
19 #include "system/system-variables.h"
20 #include "term/screen-processor.h"
21 #include "util/bit-flags-calculator.h"
22 #include "util/int-char-converter.h"
23 #include "view/display-messages.h"
24 #include "wizard/wizard-special-process.h"
25 #include <string>
26 #include <vector>
27 #include <sstream>
28
29 void wiz_enter_quest(player_type *creature_ptr);
30 void wiz_complete_quest(player_type *creature_ptr);
31 void wiz_restore_monster_max_num();
32
33 /*!
34  * @brief ゲーム設定コマンド一覧表
35  */
36 std::vector<std::vector<std::string>> wizard_game_modifier_menu_table = {
37     { "t", _("プレイ時間変更", "Modify played time") },
38     { "q", _("現在のクエストを完了", "Complete current quest") },
39     { "Q", _("クエストに突入", "Enter quest") },
40     { "u", _("ユニーク/ナズグルの生存数を復元", "Restore living info of unique/nazgul") },
41     { "g", _("モンスター闘技場出場者更新", "Update gambling monster") },
42 };
43
44 /*!
45  * @brief ゲーム設定コマンドの一覧を表示する
46  */
47 void display_wizard_game_modifier_menu()
48 {
49     for (int y = 1; y < 6; y++)
50         term_erase(14, y, 64);
51
52     int r = 1;
53     int c = 15;
54     int sz = wizard_game_modifier_menu_table.size();
55     for (int i = 0; i < sz; i++) {
56         std::stringstream ss;
57         ss << wizard_game_modifier_menu_table[i][0] << ") " << wizard_game_modifier_menu_table[i][1];
58         put_str(ss.str().c_str(), r++, c);
59     }
60 }
61
62 /*!
63  * @brief ゲーム設定コマンドの入力を受け付ける
64  * @param creature_ptr プレイヤーの情報へのポインタ
65  */
66 void wizard_game_modifier(player_type *creature_ptr)
67 {
68     screen_save();
69     display_wizard_game_modifier_menu();
70
71     char cmd;
72     get_com("Player Command: ", &cmd, false);
73     screen_load();
74
75     switch (cmd) {
76     case ESCAPE:
77     case ' ':
78     case '\n':
79     case '\r':
80         break;
81     case 'g':
82         update_gambling_monsters(creature_ptr);
83         break;
84     case 'q':
85         wiz_complete_quest(creature_ptr);
86         break;
87     case 'Q':
88         wiz_enter_quest(creature_ptr);
89         break;
90     case 'u':
91         wiz_restore_monster_max_num();
92         break;
93     case 't':
94         set_gametime();
95         break;
96     }
97 }
98
99 /*!
100  * @brief 指定したクエストに突入する
101  * @param プレイヤーの情報へのポインタ
102  */
103 void wiz_enter_quest(player_type* creature_ptr)
104 {
105     char ppp[30];
106     char tmp_val[5];
107     int tmp_int;
108     sprintf(ppp, "QuestID (0-%d):", max_q_idx - 1);
109     sprintf(tmp_val, "%d", 0);
110
111     if (!get_string(ppp, tmp_val, 3))
112         return;
113
114     tmp_int = atoi(tmp_val);
115     if ((tmp_int < 0) || (tmp_int >= max_q_idx))
116         return;
117
118     init_flags = static_cast<init_flags_type>(INIT_SHOW_TEXT | INIT_ASSIGN);
119     creature_ptr->current_floor_ptr->inside_quest = (QUEST_IDX)tmp_int;
120     parse_fixed_map(creature_ptr, "q_info.txt", 0, 0, 0, 0);
121     quest[tmp_int].status = QUEST_STATUS_TAKEN;
122     if (quest[tmp_int].dungeon == 0)
123         exe_enter_quest(creature_ptr, (QUEST_IDX)tmp_int);
124 }
125
126 /*!
127  * @brief 指定したクエストを完了させる
128  * @param プレイヤーの情報へのポインタ
129  */
130 void wiz_complete_quest(player_type *creature_ptr)
131 {
132     if (!creature_ptr->current_floor_ptr->inside_quest) {
133         msg_print("No current quest");
134         msg_print(NULL);
135         return;
136     }
137
138     if (quest[creature_ptr->current_floor_ptr->inside_quest].status == QUEST_STATUS_TAKEN)
139         complete_quest(creature_ptr, creature_ptr->current_floor_ptr->inside_quest);
140 }
141
142 void wiz_restore_monster_max_num()
143 {
144     MONRACE_IDX r_idx = command_arg;
145     if (r_idx <= 0) {
146         std::stringstream ss;
147         ss << "Monster race (1-" << max_r_idx << "): ";
148
149         char tmp_val[160] = "\0";
150         if (!get_string(ss.str().c_str(), tmp_val, 5))
151             return;
152
153         r_idx = (MONRACE_IDX)atoi(tmp_val);
154         if (r_idx <= 0 || r_idx >= max_r_idx)
155             return;
156     }
157
158     monster_race *r_ptr = &r_info[r_idx];
159     if (r_ptr->name.empty()) {
160         msg_print("そのモンスターは存在しません。");
161         msg_print(NULL);
162         return;
163     }
164
165     MONSTER_NUMBER n = 0;
166     if (any_bits(r_ptr->flags1, RF1_UNIQUE))
167         n = 1;
168     else if (any_bits(r_ptr->flags7, RF7_NAZGUL))
169         n = MAX_NAZGUL_NUM;
170
171     if (n == 0) {
172         msg_print("出現数に制限がないモンスターです。");
173         msg_print(NULL);
174         return;
175     }
176
177     r_ptr->max_num = n;
178     r_ptr->r_pkills = 0;
179     r_ptr->r_akills = 0;
180
181     std::stringstream ss;
182     ss << r_ptr->name << _("の出現数を復元しました。", " can appear again now.");
183     msg_print(ss.str().c_str());
184     msg_print(NULL);
185 }