OSDN Git Service

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