OSDN Git Service

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