OSDN Git Service

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