OSDN Git Service

[Refactor] #40624 Separated quest-completion-checker.c/h from floor-events.c/h and...
[hengbandforosx/hengbandosx.git] / src / dungeon / dungeon-processor.c
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/hp-mp-regenerator.h"
6 #include "core/player-processor.h"
7 #include "core/player-redraw-types.h"
8 #include "core/player-update-types.h"
9 #include "core/stuff-handler.h"
10 #include "core/turn-compensator.h"
11 #include "core/window-redrawer.h"
12 #include "dungeon/dungeon.h"
13 #include "dungeon/quest.h"
14 #include "floor/floor-save.h"
15 #include "floor/floor.h"
16 #include "game-option/map-screen-options.h"
17 #include "game-option/play-record-options.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 "player/special-defense-types.h"
30 #include "realm/realm-song-numbers.h"
31 #include "realm/realm-song.h"
32 #include "system/floor-type-definition.h"
33 #include "target/target-checker.h"
34 #include "view/display-messages.h"
35 #include "world/world-turn-processor.h"
36 #include "world/world.h"
37
38 /*!
39  * process_player()、process_world() をcore.c から移設するのが先.
40  * process_upkeep_with_speed() はこの関数と同じところでOK
41  * @brief 現在プレイヤーがいるダンジョンの全体処理 / Interact with the current dungeon level.
42  * @return なし
43  * @details
44  * <p>
45  * この関数から現在の階層を出る、プレイヤーがキャラが死ぬ、
46  * ゲームを終了するかのいずれかまでループする。
47  * </p>
48  * <p>
49  * This function will not exit until the level is completed,\n
50  * the user dies, or the game is terminated.\n
51  * </p>
52  */
53 void process_dungeon(player_type *player_ptr, bool load_game)
54 {
55     floor_type *floor_ptr = player_ptr->current_floor_ptr;
56     floor_ptr->base_level = floor_ptr->dun_level;
57     current_world_ptr->is_loading_now = FALSE;
58     player_ptr->leaving = FALSE;
59
60     command_cmd = 0;
61     command_rep = 0;
62     command_arg = 0;
63     command_dir = 0;
64
65     target_who = 0;
66     player_ptr->pet_t_m_idx = 0;
67     player_ptr->riding_t_m_idx = 0;
68     player_ptr->ambush_flag = FALSE;
69     health_track(player_ptr, 0);
70     repair_monsters = TRUE;
71
72     disturb(player_ptr, TRUE, TRUE);
73     int quest_num = quest_num = quest_number(player_ptr, floor_ptr->dun_level);
74     if (quest_num) {
75         r_info[quest[quest_num].r_idx].flags1 |= RF1_QUESTOR;
76     }
77
78     if (player_ptr->max_plv < player_ptr->lev) {
79         player_ptr->max_plv = player_ptr->lev;
80     }
81
82     if ((max_dlv[player_ptr->dungeon_idx] < floor_ptr->dun_level) && !floor_ptr->inside_quest) {
83         max_dlv[player_ptr->dungeon_idx] = floor_ptr->dun_level;
84         if (record_maxdepth)
85             exe_write_diary(player_ptr, DIARY_MAXDEAPTH, floor_ptr->dun_level, NULL);
86     }
87
88     (void)calculate_upkeep(player_ptr);
89     panel_bounds_center();
90     verify_panel(player_ptr);
91     msg_erase();
92
93     current_world_ptr->character_xtra = TRUE;
94     player_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER | PW_MONSTER | PW_OVERHEAD | PW_DUNGEON);
95     player_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_EQUIPPY | PR_MAP);
96     player_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS | PU_VIEW | PU_LITE | PU_MON_LITE | PU_TORCH | PU_MONSTERS | PU_DISTANCE | PU_FLOW);
97     handle_stuff(player_ptr);
98
99     current_world_ptr->character_xtra = FALSE;
100     player_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
101     player_ptr->update |= (PU_COMBINE | PU_REORDER);
102     handle_stuff(player_ptr);
103     term_fresh();
104
105     if (quest_num
106         && (is_fixed_quest_idx(quest_num) && !((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT) || !(quest[quest_num].flags & QUEST_FLAG_PRESET))))
107         do_cmd_feeling(player_ptr);
108
109     if (player_ptr->phase_out) {
110         if (load_game) {
111             player_ptr->energy_need = 0;
112             update_gambling_monsters(player_ptr);
113         } else {
114             msg_print(_("試合開始!", "Ready..Fight!"));
115             msg_print(NULL);
116         }
117     }
118
119     if ((player_ptr->pclass == CLASS_BARD) && (SINGING_SONG_EFFECT(player_ptr) > MUSIC_DETECT))
120         SINGING_SONG_EFFECT(player_ptr) = MUSIC_DETECT;
121
122     if (!player_ptr->playing || player_ptr->is_dead)
123         return;
124
125     if (!floor_ptr->inside_quest && (player_ptr->dungeon_idx == DUNGEON_ANGBAND)) {
126         quest_discovery(random_quest_number(player_ptr, floor_ptr->dun_level));
127         floor_ptr->inside_quest = random_quest_number(player_ptr, floor_ptr->dun_level);
128     }
129     if ((floor_ptr->dun_level == d_info[player_ptr->dungeon_idx].maxdepth) && d_info[player_ptr->dungeon_idx].final_guardian) {
130         if (r_info[d_info[player_ptr->dungeon_idx].final_guardian].max_num)
131 #ifdef JP
132             msg_format("この階には%sの主である%sが棲んでいる。", d_name + d_info[player_ptr->dungeon_idx].name,
133                 r_name + r_info[d_info[player_ptr->dungeon_idx].final_guardian].name);
134 #else
135             msg_format("%^s lives in this level as the keeper of %s.", r_name + r_info[d_info[player_ptr->dungeon_idx].final_guardian].name,
136                 d_name + d_info[player_ptr->dungeon_idx].name);
137 #endif
138     }
139
140     if (!load_game && (player_ptr->special_defense & NINJA_S_STEALTH))
141         set_superstealth(player_ptr, FALSE);
142
143     floor_ptr->monster_level = floor_ptr->base_level;
144     floor_ptr->object_level = floor_ptr->base_level;
145     current_world_ptr->is_loading_now = TRUE;
146     if (player_ptr->energy_need > 0 && !player_ptr->phase_out && (floor_ptr->dun_level || player_ptr->leaving_dungeon || floor_ptr->inside_arena))
147         player_ptr->energy_need = 0;
148
149     player_ptr->leaving_dungeon = FALSE;
150     mproc_init(floor_ptr);
151
152     while (TRUE) {
153         if ((floor_ptr->m_cnt + 32 > current_world_ptr->max_m_idx) && !player_ptr->phase_out)
154             compact_monsters(player_ptr, 64);
155
156         if ((floor_ptr->m_cnt + 32 < floor_ptr->m_max) && !player_ptr->phase_out)
157             compact_monsters(player_ptr, 0);
158
159         if (floor_ptr->o_cnt + 32 > current_world_ptr->max_o_idx)
160             compact_objects(player_ptr, 64);
161
162         if (floor_ptr->o_cnt + 32 < floor_ptr->o_max)
163             compact_objects(player_ptr, 0);
164
165         process_player(player_ptr);
166         process_upkeep_with_speed(player_ptr);
167         handle_stuff(player_ptr);
168
169         move_cursor_relative(player_ptr->y, player_ptr->x);
170         if (fresh_after)
171             term_fresh();
172
173         if (!player_ptr->playing || player_ptr->is_dead)
174             break;
175
176         process_monsters(player_ptr);
177         handle_stuff(player_ptr);
178
179         move_cursor_relative(player_ptr->y, player_ptr->x);
180         if (fresh_after)
181             term_fresh();
182
183         if (!player_ptr->playing || player_ptr->is_dead)
184             break;
185
186         process_world(player_ptr);
187         handle_stuff(player_ptr);
188
189         move_cursor_relative(player_ptr->y, player_ptr->x);
190         if (fresh_after)
191             term_fresh();
192
193         if (!player_ptr->playing || player_ptr->is_dead)
194             break;
195
196         current_world_ptr->game_turn++;
197         if (current_world_ptr->dungeon_turn < current_world_ptr->dungeon_turn_limit) {
198             if (!player_ptr->wild_mode || wild_regen)
199                 current_world_ptr->dungeon_turn++;
200             else if (player_ptr->wild_mode && !(current_world_ptr->game_turn % ((MAX_HGT + MAX_WID) / 2)))
201                 current_world_ptr->dungeon_turn++;
202         }
203
204         prevent_turn_overflow(player_ptr);
205
206         if (player_ptr->leaving)
207             break;
208
209         if (wild_regen)
210             wild_regen--;
211     }
212
213     if (quest_num && !(r_info[quest[quest_num].r_idx].flags1 & RF1_UNIQUE)) {
214         r_info[quest[quest_num].r_idx].flags1 &= ~RF1_QUESTOR;
215     }
216
217     if (player_ptr->playing && !player_ptr->is_dead) {
218         /*
219          * Maintain Unique monsters and artifact, save current
220          * floor, then prepare next floor
221          */
222         leave_floor(player_ptr);
223         reinit_wilderness = FALSE;
224     }
225
226     write_level = TRUE;
227 }