OSDN Git Service

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