OSDN Git Service

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