OSDN Git Service

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