OSDN Git Service

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