OSDN Git Service

[Refactor] #3286 Removed player-redraw-types.h
[hengbandforosx/hengbandosx.git] / src / dungeon / dungeon-processor.cpp
1 #include "dungeon/dungeon-processor.h"
2 #include "cmd-building/cmd-building.h"
3 #include "cmd-io/cmd-dump.h"
4 #include "core/disturbance.h"
5 #include "core/object-compressor.h"
6 #include "core/player-processor.h"
7 #include "core/stuff-handler.h"
8 #include "core/turn-compensator.h"
9 #include "core/window-redrawer.h"
10 #include "dungeon/quest.h"
11 #include "floor/floor-leaver.h"
12 #include "floor/floor-save-util.h"
13 #include "floor/floor-save.h"
14 #include "game-option/cheat-options.h"
15 #include "game-option/map-screen-options.h"
16 #include "game-option/play-record-options.h"
17 #include "hpmp/hp-mp-regenerator.h"
18 #include "io/cursor.h"
19 #include "io/input-key-requester.h"
20 #include "io/write-diary.h"
21 #include "market/arena.h"
22 #include "mind/mind-ninja.h"
23 #include "monster-race/monster-race.h"
24 #include "monster-race/race-flags1.h"
25 #include "monster/monster-compaction.h"
26 #include "monster/monster-processor.h"
27 #include "monster/monster-status.h"
28 #include "monster/monster-util.h"
29 #include "pet/pet-util.h"
30 #include "player-base/player-class.h"
31 #include "player/special-defense-types.h"
32 #include "realm/realm-song-numbers.h"
33 #include "realm/realm-song.h"
34 #include "spell-realm/spells-song.h"
35 #include "system/dungeon-info.h"
36 #include "system/floor-type-definition.h"
37 #include "system/monster-race-info.h"
38 #include "system/player-type-definition.h"
39 #include "system/redrawing-flags-updater.h"
40 #include "target/target-checker.h"
41 #include "util/bit-flags-calculator.h"
42 #include "view/display-messages.h"
43 #include "world/world-turn-processor.h"
44 #include "world/world.h"
45
46 static void redraw_character_xtra(PlayerType *player_ptr)
47 {
48     w_ptr->character_xtra = true;
49     auto &rfu = RedrawingFlagsUpdater::get_instance();
50     set_bits(player_ptr->window_flags, PW_INVENTORY | PW_EQUIPMENT | PW_SPELL | PW_PLAYER | PW_MONSTER_LORE | PW_OVERHEAD | PW_DUNGEON);
51     const auto flags_mwrf = {
52         MainWindowRedrawingFlag::WIPE,
53         MainWindowRedrawingFlag::BASIC,
54         MainWindowRedrawingFlag::EXTRA,
55         MainWindowRedrawingFlag::EQUIPPY,
56         MainWindowRedrawingFlag::MAP,
57     };
58     rfu.set_flags(flags_mwrf);
59     auto flags_srf = {
60         StatusRedrawingFlag::BONUS,
61         StatusRedrawingFlag::HP,
62         StatusRedrawingFlag::MP,
63         StatusRedrawingFlag::SPELLS,
64         StatusRedrawingFlag::VIEW,
65         StatusRedrawingFlag::LITE,
66         StatusRedrawingFlag::MONSTER_LITE,
67         StatusRedrawingFlag::TORCH,
68         StatusRedrawingFlag::MONSTER_STATUSES,
69         StatusRedrawingFlag::DISTANCE,
70         StatusRedrawingFlag::FLOW,
71     };
72     rfu.set_flags(flags_srf);
73     handle_stuff(player_ptr);
74     w_ptr->character_xtra = false;
75 }
76
77 /*!
78  * process_player()、process_world() をcore.c から移設するのが先.
79  * process_upkeep_with_speed() はこの関数と同じところでOK
80  * @brief 現在プレイヤーがいるダンジョンの全体処理 / Interact with the current dungeon level.
81  * @details
82  * <p>
83  * この関数から現在の階層を出る、プレイヤーがキャラが死ぬ、
84  * ゲームを終了するかのいずれかまでループする。
85  * </p>
86  * <p>
87  * This function will not exit until the level is completed,\n
88  * the user dies, or the game is terminated.\n
89  * </p>
90  */
91 void process_dungeon(PlayerType *player_ptr, bool load_game)
92 {
93     auto *floor_ptr = player_ptr->current_floor_ptr;
94     floor_ptr->base_level = floor_ptr->dun_level;
95     w_ptr->is_loading_now = false;
96     player_ptr->leaving = false;
97
98     command_cmd = 0;
99     command_rep = 0;
100     command_arg = 0;
101     command_dir = 0;
102
103     target_who = 0;
104     player_ptr->pet_t_m_idx = 0;
105     player_ptr->riding_t_m_idx = 0;
106     player_ptr->ambush_flag = false;
107     health_track(player_ptr, 0);
108
109     disturb(player_ptr, true, true);
110     auto quest_num = quest_number(player_ptr, floor_ptr->dun_level);
111     const auto &quest_list = QuestList::get_instance();
112     auto *questor_ptr = &monraces_info[quest_list[quest_num].r_idx];
113     if (inside_quest(quest_num)) {
114         set_bits(questor_ptr->flags1, RF1_QUESTOR);
115     }
116
117     if (player_ptr->max_plv < player_ptr->lev) {
118         player_ptr->max_plv = player_ptr->lev;
119     }
120
121     if ((max_dlv[player_ptr->dungeon_idx] < floor_ptr->dun_level) && !inside_quest(floor_ptr->quest_number)) {
122         max_dlv[player_ptr->dungeon_idx] = floor_ptr->dun_level;
123         if (record_maxdepth) {
124             exe_write_diary(player_ptr, DIARY_MAXDEAPTH, floor_ptr->dun_level, nullptr);
125         }
126     }
127
128     (void)calculate_upkeep(player_ptr);
129     panel_bounds_center();
130     verify_panel(player_ptr);
131     msg_erase();
132
133     redraw_character_xtra(player_ptr);
134     auto flags_srf = {
135         StatusRedrawingFlag::BONUS,
136         StatusRedrawingFlag::HP,
137         StatusRedrawingFlag::MP,
138         StatusRedrawingFlag::SPELLS,
139         StatusRedrawingFlag::COMBINATION,
140         StatusRedrawingFlag::REORDER,
141     };
142     RedrawingFlagsUpdater::get_instance().set_flags(flags_srf);
143     handle_stuff(player_ptr);
144     term_fresh();
145
146     auto no_feeling_quest = (quest_num == QuestId::OBERON);
147     no_feeling_quest |= (quest_num == QuestId::SERPENT);
148     no_feeling_quest |= none_bits(quest_list[quest_num].flags, QUEST_FLAG_PRESET);
149     if (inside_quest(quest_num) && QuestType::is_fixed(quest_num) && !no_feeling_quest) {
150         do_cmd_feeling(player_ptr);
151     }
152
153     if (player_ptr->phase_out) {
154         if (load_game) {
155             player_ptr->energy_need = 0;
156             update_gambling_monsters(player_ptr);
157         } else {
158             msg_print(_("試合開始!", "Ready..Fight!"));
159             msg_print(nullptr);
160         }
161     }
162
163     if (PlayerClass(player_ptr).equals(PlayerClassType::BARD) && (get_singing_song_effect(player_ptr) > MUSIC_DETECT)) {
164         set_singing_song_effect(player_ptr, MUSIC_DETECT);
165     }
166
167     if (!player_ptr->playing || player_ptr->is_dead) {
168         return;
169     }
170
171     if (!inside_quest(floor_ptr->quest_number) && (player_ptr->dungeon_idx == DUNGEON_ANGBAND)) {
172         quest_discovery(random_quest_number(player_ptr, floor_ptr->dun_level));
173         floor_ptr->quest_number = random_quest_number(player_ptr, floor_ptr->dun_level);
174     }
175
176     const auto &dungeon = dungeons_info[player_ptr->dungeon_idx];
177     const auto guardian = dungeon.final_guardian;
178     if ((floor_ptr->dun_level == dungeon.maxdepth) && MonsterRace(guardian).is_valid()) {
179         const auto &guardian_ref = monraces_info[guardian];
180         if (guardian_ref.max_num) {
181 #ifdef JP
182             msg_format("この階には%sの主である%sが棲んでいる。", dungeon.name.data(), guardian_ref.name.data());
183 #else
184             msg_format("%s^ lives in this level as the keeper of %s.", guardian_ref.name.data(), dungeon.name.data());
185 #endif
186         }
187     }
188
189     if (!load_game) {
190         set_superstealth(player_ptr, false);
191     }
192
193     floor_ptr->monster_level = floor_ptr->base_level;
194     floor_ptr->object_level = floor_ptr->base_level;
195     w_ptr->is_loading_now = true;
196     if (player_ptr->energy_need > 0 && !player_ptr->phase_out && (floor_ptr->dun_level || player_ptr->leaving_dungeon || floor_ptr->inside_arena)) {
197         player_ptr->energy_need = 0;
198     }
199
200     player_ptr->leaving_dungeon = false;
201     mproc_init(floor_ptr);
202
203     while (true) {
204         if ((floor_ptr->m_cnt + 32 > w_ptr->max_m_idx) && !player_ptr->phase_out) {
205             compact_monsters(player_ptr, 64);
206         }
207
208         if ((floor_ptr->m_cnt + 32 < floor_ptr->m_max) && !player_ptr->phase_out) {
209             compact_monsters(player_ptr, 0);
210         }
211
212         if (floor_ptr->o_cnt + 32 > w_ptr->max_o_idx) {
213             compact_objects(player_ptr, 64);
214         }
215
216         if (floor_ptr->o_cnt + 32 < floor_ptr->o_max) {
217             compact_objects(player_ptr, 0);
218         }
219
220         process_player(player_ptr);
221         process_upkeep_with_speed(player_ptr);
222         handle_stuff(player_ptr);
223
224         move_cursor_relative(player_ptr->y, player_ptr->x);
225         if (fresh_after) {
226             term_fresh_force();
227         }
228
229         if (!player_ptr->playing || player_ptr->is_dead) {
230             break;
231         }
232
233         process_monsters(player_ptr);
234         handle_stuff(player_ptr);
235
236         move_cursor_relative(player_ptr->y, player_ptr->x);
237         if (fresh_after) {
238             term_fresh_force();
239         }
240
241         if (!player_ptr->playing || player_ptr->is_dead) {
242             break;
243         }
244
245         WorldTurnProcessor(player_ptr).process_world();
246         handle_stuff(player_ptr);
247
248         move_cursor_relative(player_ptr->y, player_ptr->x);
249         if (fresh_after) {
250             term_fresh_force();
251         }
252
253         if (!player_ptr->playing || player_ptr->is_dead) {
254             break;
255         }
256
257         w_ptr->game_turn++;
258         if (w_ptr->dungeon_turn < w_ptr->dungeon_turn_limit) {
259             if (!player_ptr->wild_mode || wild_regen) {
260                 w_ptr->dungeon_turn++;
261             } else if (player_ptr->wild_mode && !(w_ptr->game_turn % ((MAX_HGT + MAX_WID) / 2))) {
262                 w_ptr->dungeon_turn++;
263             }
264         }
265
266         prevent_turn_overflow(player_ptr);
267
268         if (player_ptr->leaving) {
269             break;
270         }
271
272         if (wild_regen) {
273             wild_regen--;
274         }
275     }
276
277     if ((inside_quest(quest_num)) && questor_ptr->kind_flags.has_not(MonsterKindType::UNIQUE)) {
278         reset_bits(questor_ptr->flags1, RF1_QUESTOR);
279     }
280
281     if (player_ptr->playing && !player_ptr->is_dead) {
282         /*
283          * Maintain Unique monsters and artifact, save current
284          * floor, then prepare next floor
285          */
286         leave_floor(player_ptr);
287         reinit_wilderness = false;
288     }
289
290     write_level = true;
291 }