OSDN Git Service

[Refactor] #40413 Separated sound-of-music.c/h from util.c/h
[hengband/hengband.git] / src / world / world-movement-processor.c
1 #include "world/world-movement-processor.h"
2 #include "cmd-io/cmd-save.h"
3 #include "dungeon/dungeon.h"
4 #include "dungeon/quest.h"
5 #include "game-option/birth-options.h"
6 #include "game-option/play-record-options.h"
7 #include "game-option/special-options.h"
8 #include "io/write-diary.h"
9 #include "main/sound-definitions-table.h"
10 #include "main/sound-of-music.h"
11 #include "monster-race/race-flags1.h"
12 #include "player/player-move.h"
13 #include "view/display-main-window.h"
14 #include "world/world.h"
15
16 /*!
17  * @brief 10ゲームターンが進行するごとに帰還の残り時間カウントダウンと発動を処理する。
18  * / Handle involuntary movement once every 10 game turns
19  * @param creature_ptr プレーヤーへの参照ポインタ
20  * @return なし
21  * @details
22  * Autosave BEFORE resetting the recall counter (rr9)
23  * The player is yanked up/down as soon as he loads the autosaved game.
24  */
25 void execute_recall(player_type *creature_ptr)
26 {
27     if (creature_ptr->word_recall == 0)
28         return;
29
30     if (autosave_l && (creature_ptr->word_recall == 1) && !creature_ptr->phase_out)
31         do_cmd_save_game(creature_ptr, TRUE);
32
33     creature_ptr->word_recall--;
34     creature_ptr->redraw |= (PR_STATUS);
35     if (creature_ptr->word_recall != 0)
36         return;
37
38     disturb(creature_ptr, FALSE, TRUE);
39     floor_type *floor_ptr = creature_ptr->current_floor_ptr;
40     if (floor_ptr->dun_level || creature_ptr->current_floor_ptr->inside_quest || creature_ptr->enter_dungeon) {
41         msg_print(_("上に引っ張りあげられる感じがする!", "You feel yourself yanked upwards!"));
42         if (creature_ptr->dungeon_idx)
43             creature_ptr->recall_dungeon = creature_ptr->dungeon_idx;
44         if (record_stair)
45             exe_write_diary(creature_ptr, DIARY_RECALL, floor_ptr->dun_level, NULL);
46
47         floor_ptr->dun_level = 0;
48         creature_ptr->dungeon_idx = 0;
49         leave_quest_check(creature_ptr);
50         leave_tower_check(creature_ptr);
51         creature_ptr->current_floor_ptr->inside_quest = 0;
52         creature_ptr->leaving = TRUE;
53         sound(SOUND_TPLEVEL);
54         return;
55     }
56
57     msg_print(_("下に引きずり降ろされる感じがする!", "You feel yourself yanked downwards!"));
58     creature_ptr->dungeon_idx = creature_ptr->recall_dungeon;
59     if (record_stair)
60         exe_write_diary(creature_ptr, DIARY_RECALL, floor_ptr->dun_level, NULL);
61
62     floor_ptr->dun_level = max_dlv[creature_ptr->dungeon_idx];
63     if (floor_ptr->dun_level < 1)
64         floor_ptr->dun_level = 1;
65     if (ironman_nightmare && !randint0(666) && (creature_ptr->dungeon_idx == DUNGEON_ANGBAND)) {
66         if (floor_ptr->dun_level < 50) {
67             floor_ptr->dun_level *= 2;
68         } else if (floor_ptr->dun_level < 99) {
69             floor_ptr->dun_level = (floor_ptr->dun_level + 99) / 2;
70         } else if (floor_ptr->dun_level > 100) {
71             floor_ptr->dun_level = d_info[creature_ptr->dungeon_idx].maxdepth - 1;
72         }
73     }
74
75     if (creature_ptr->wild_mode) {
76         creature_ptr->wilderness_y = creature_ptr->y;
77         creature_ptr->wilderness_x = creature_ptr->x;
78     } else {
79         creature_ptr->oldpx = creature_ptr->x;
80         creature_ptr->oldpy = creature_ptr->y;
81     }
82
83     creature_ptr->wild_mode = FALSE;
84
85     /*
86      * Clear all saved floors
87      * and create a first saved floor
88      */
89     prepare_change_floor_mode(creature_ptr, CFM_FIRST_FLOOR);
90     creature_ptr->leaving = TRUE;
91
92     if (creature_ptr->dungeon_idx != DUNGEON_ANGBAND) {
93         sound(SOUND_TPLEVEL);
94         return;
95     }
96
97     for (int i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++) {
98         quest_type *const q_ptr = &quest[i];
99         if ((q_ptr->type == QUEST_TYPE_RANDOM) && (q_ptr->status == QUEST_STATUS_TAKEN) && (q_ptr->level < floor_ptr->dun_level)) {
100             q_ptr->status = QUEST_STATUS_FAILED;
101             q_ptr->complev = (byte)creature_ptr->lev;
102             update_playtime();
103             q_ptr->comptime = current_world_ptr->play_time;
104             r_info[q_ptr->r_idx].flags1 &= ~(RF1_QUESTOR);
105         }
106     }
107
108     sound(SOUND_TPLEVEL);
109 }
110
111 /*!
112  * @brief 10ゲームターンが進行するごとにフロア・リセット/現実変容の残り時間カウントダウンと発動を処理する。
113  * / Handle involuntary movement once every 10 game turns
114  * @param creature_ptr プレーヤーへの参照ポインタ
115  * @return なし
116  */
117 void execute_floor_reset(player_type *creature_ptr)
118 {
119     floor_type *floor_ptr = creature_ptr->current_floor_ptr;
120     if (creature_ptr->alter_reality == 0)
121         return;
122
123     if (autosave_l && (creature_ptr->alter_reality == 1) && !creature_ptr->phase_out)
124         do_cmd_save_game(creature_ptr, TRUE);
125
126     creature_ptr->alter_reality--;
127     creature_ptr->redraw |= (PR_STATUS);
128     if (creature_ptr->alter_reality != 0)
129         return;
130
131     disturb(creature_ptr, FALSE, TRUE);
132     if (!quest_number(creature_ptr, floor_ptr->dun_level) && floor_ptr->dun_level) {
133         msg_print(_("世界が変わった!", "The world changes!"));
134
135         /*
136          * Clear all saved floors
137          * and create a first saved floor
138          */
139         prepare_change_floor_mode(creature_ptr, CFM_FIRST_FLOOR);
140         creature_ptr->leaving = TRUE;
141     } else {
142         msg_print(_("世界が少しの間変化したようだ。", "The world seems to change for a moment!"));
143     }
144
145     sound(SOUND_TPLEVEL);
146 }