OSDN Git Service

[fix] #41503 超能力者でゲームを開始しようとするとクラッシュ
[hengband/hengband.git] / src / world / world-turn-processor.c
1 #include "world/world-turn-processor.h"
2 #include "cmd-building/cmd-building.h"
3 #include "cmd-io/cmd-save.h"
4 #include "core/disturbance.h"
5 #include "core/hp-mp-processor.h"
6 #include "core/hp-mp-regenerator.h"
7 #include "core/magic-effects-timeout-reducer.h"
8 #include "dungeon/dungeon.h"
9 #include "floor/floor-events.h"
10 #include "floor/floor-mode-changer.h"
11 #include "floor/wild.h"
12 #include "game-option/birth-options.h"
13 #include "game-option/cheat-options.h"
14 #include "game-option/special-options.h"
15 #include "game-option/text-display-options.h"
16 #include "grid/grid.h"
17 #include "inventory/inventory-curse.h"
18 #include "inventory/recharge-processor.h"
19 #include "io/write-diary.h"
20 #include "market/arena.h"
21 #include "market/bounty.h"
22 #include "monster-floor/monster-generator.h"
23 #include "monster-floor/monster-summon.h"
24 #include "monster/monster-describer.h"
25 #include "monster/monster-status.h"
26 #include "mutation/mutation-processor.h"
27 #include "object/lite-processor.h"
28 #include "perception/simple-perception.h"
29 #include "player/digestion-processor.h"
30 #include "store/store-util.h"
31 #include "store/store.h"
32 #include "system/floor-type-definition.h"
33 #include "term/screen-processor.h"
34 #include "term/term-color-types.h"
35 #include "util/bit-flags-calculator.h"
36 #include "view/display-messages.h"
37 #include "window/main-window-row-column.h"
38 #include "world/world-movement-processor.h"
39 #include "world/world.h"
40
41 /*!
42  * @brief 10ゲームターンが進行する毎にゲーム世界全体の処理を行う。
43  * / Handle certain things once every 10 game turns
44  * @param player_ptr プレーヤーへの参照ポインタ
45  * @return なし
46  */
47 void process_world(player_type *player_ptr)
48 {
49     const s32b A_DAY = TURNS_PER_TICK * TOWN_DAWN;
50     s32b prev_turn_in_today = ((current_world_ptr->game_turn - TURNS_PER_TICK) % A_DAY + A_DAY / 4) % A_DAY;
51     int prev_min = (1440 * prev_turn_in_today / A_DAY) % 60;
52
53     int day, hour, min;
54     extract_day_hour_min(player_ptr, &day, &hour, &min);
55     update_dungeon_feeling(player_ptr);
56
57     /* 帰還無しモード時のレベルテレポバグ対策 / Fix for level teleport bugs on ironman_downward.*/
58     floor_type *floor_ptr = player_ptr->current_floor_ptr;
59     if (ironman_downward && (player_ptr->dungeon_idx != DUNGEON_ANGBAND && player_ptr->dungeon_idx != 0)) {
60         floor_ptr->dun_level = 0;
61         player_ptr->dungeon_idx = 0;
62         prepare_change_floor_mode(player_ptr, CFM_FIRST_FLOOR | CFM_RAND_PLACE);
63         floor_ptr->inside_arena = FALSE;
64         player_ptr->wild_mode = FALSE;
65         player_ptr->leaving = TRUE;
66     }
67
68     if (player_ptr->phase_out && !player_ptr->leaving) {
69         int win_m_idx = 0;
70         int number_mon = 0;
71         for (int i2 = 0; i2 < floor_ptr->width; ++i2) {
72             for (int j2 = 0; j2 < floor_ptr->height; j2++) {
73                 grid_type *g_ptr = &floor_ptr->grid_array[j2][i2];
74                 if ((g_ptr->m_idx > 0) && (g_ptr->m_idx != player_ptr->riding)) {
75                     number_mon++;
76                     win_m_idx = g_ptr->m_idx;
77                 }
78             }
79         }
80
81         if (number_mon == 0) {
82             msg_print(_("相打ちに終わりました。", "Nothing survived."));
83             msg_print(NULL);
84             player_ptr->energy_need = 0;
85             update_gambling_monsters(player_ptr);
86         } else if ((number_mon - 1) == 0) {
87             GAME_TEXT m_name[MAX_NLEN];
88             monster_type *wm_ptr;
89             wm_ptr = &floor_ptr->m_list[win_m_idx];
90             monster_desc(player_ptr, m_name, wm_ptr, 0);
91             msg_format(_("%sが勝利した!", "%s won!"), m_name);
92             msg_print(NULL);
93
94             if (win_m_idx == (sel_monster + 1)) {
95                 msg_print(_("おめでとうございます。", "Congratulations."));
96                 msg_format(_("%d$を受け取った。", "You received %d gold."), battle_odds);
97                 player_ptr->au += battle_odds;
98             } else {
99                 msg_print(_("残念でした。", "You lost gold."));
100             }
101
102             msg_print(NULL);
103             player_ptr->energy_need = 0;
104             update_gambling_monsters(player_ptr);
105         } else if (current_world_ptr->game_turn - floor_ptr->generated_turn == 150 * TURNS_PER_TICK) {
106             msg_print(_("申し訳ありませんが、この勝負は引き分けとさせていただきます。", "Sorry, but this battle ended in a draw."));
107             player_ptr->au += kakekin;
108             msg_print(NULL);
109             player_ptr->energy_need = 0;
110             update_gambling_monsters(player_ptr);
111         }
112     }
113
114     if (current_world_ptr->game_turn % TURNS_PER_TICK)
115         return;
116
117     if (autosave_t && autosave_freq && !player_ptr->phase_out) {
118         if (!(current_world_ptr->game_turn % ((s32b)autosave_freq * TURNS_PER_TICK)))
119             do_cmd_save_game(player_ptr, TRUE);
120     }
121
122     if (floor_ptr->monster_noise && !ignore_unview) {
123         msg_print(_("何かが聞こえた。", "You hear noise."));
124     }
125
126     if (!floor_ptr->dun_level && !floor_ptr->inside_quest && !player_ptr->phase_out && !floor_ptr->inside_arena) {
127         if (!(current_world_ptr->game_turn % ((TURNS_PER_TICK * TOWN_DAWN) / 2))) {
128             bool dawn = (!(current_world_ptr->game_turn % (TURNS_PER_TICK * TOWN_DAWN)));
129             if (dawn)
130                 day_break(player_ptr);
131             else
132                 night_falls(player_ptr);
133         }
134     } else if ((vanilla_town || (lite_town && !floor_ptr->inside_quest && !player_ptr->phase_out && !floor_ptr->inside_arena)) && floor_ptr->dun_level) {
135         if (!(current_world_ptr->game_turn % (TURNS_PER_TICK * STORE_TICKS))) {
136             if (one_in_(STORE_SHUFFLE)) {
137                 int n;
138                 do {
139                     n = randint0(MAX_STORES);
140                 } while ((n == STORE_HOME) || (n == STORE_MUSEUM));
141
142                 for (FEAT_IDX i = 1; i < max_f_idx; i++) {
143                     feature_type *f_ptr = &f_info[i];
144                     if (!f_ptr->name)
145                         continue;
146                     if (!has_flag(f_ptr->flags, FF_STORE))
147                         continue;
148
149                     if (f_ptr->subtype == n) {
150                         if (cheat_xtra)
151                             msg_format(_("%sの店主をシャッフルします。", "Shuffle a Shopkeeper of %s."), f_name + f_ptr->name);
152
153                         store_shuffle(player_ptr, n);
154                         break;
155                     }
156                 }
157             }
158         }
159     }
160
161     if (one_in_(d_info[player_ptr->dungeon_idx].max_m_alloc_chance) && !floor_ptr->inside_arena && !floor_ptr->inside_quest && !player_ptr->phase_out) {
162         (void)alloc_monster(player_ptr, MAX_SIGHT + 5, 0, summon_specific);
163     }
164
165     if (!(current_world_ptr->game_turn % (TURNS_PER_TICK * 10)) && !player_ptr->phase_out)
166         regenerate_monsters(player_ptr);
167     if (!(current_world_ptr->game_turn % (TURNS_PER_TICK * 3)))
168         regenerate_captured_monsters(player_ptr);
169
170     if (!player_ptr->leaving) {
171         for (int i = 0; i < MAX_MTIMED; i++) {
172             if (floor_ptr->mproc_max[i] > 0)
173                 process_monsters_mtimed(player_ptr, i);
174         }
175     }
176
177     if (!hour && !min) {
178         if (min != prev_min) {
179             exe_write_diary(player_ptr, DIARY_DIALY, 0, NULL);
180             determine_daily_bounty(player_ptr, FALSE);
181         }
182     }
183
184     /*
185      * Nightmare mode activates the TY_CURSE at midnight
186      * Require exact minute -- Don't activate multiple times in a minute
187      */
188     if (ironman_nightmare && (min != prev_min)) {
189         if ((hour == 23) && !(min % 15)) {
190             disturb(player_ptr, FALSE, TRUE);
191             switch (min / 15) {
192             case 0:
193                 msg_print(_("遠くで不気味な鐘の音が鳴った。", "You hear a distant bell toll ominously."));
194                 break;
195
196             case 1:
197                 msg_print(_("遠くで鐘が二回鳴った。", "A distant bell sounds twice."));
198                 break;
199
200             case 2:
201                 msg_print(_("遠くで鐘が三回鳴った。", "A distant bell sounds three times."));
202                 break;
203
204             case 3:
205                 msg_print(_("遠くで鐘が四回鳴った。", "A distant bell tolls four times."));
206                 break;
207             }
208         }
209
210         if (!hour && !min) {
211             disturb(player_ptr, TRUE, TRUE);
212             msg_print(_("遠くで鐘が何回も鳴り、死んだような静けさの中へ消えていった。", "A distant bell tolls many times, fading into an deathly silence."));
213             if (player_ptr->wild_mode) {
214                 player_ptr->oldpy = randint1(MAX_HGT - 2);
215                 player_ptr->oldpx = randint1(MAX_WID - 2);
216                 change_wild_mode(player_ptr, TRUE);
217                 take_turn(player_ptr, 100);
218             }
219
220             player_ptr->invoking_midnight_curse = TRUE;
221         }
222     }
223
224     starve_player(player_ptr);
225     process_player_hp_mp(player_ptr);
226     reduce_magic_effects_timeout(player_ptr);
227     reduce_lite_life(player_ptr);
228     process_world_aux_mutation(player_ptr);
229     execute_cursed_items_effect(player_ptr);
230     recharge_magic_items(player_ptr);
231     sense_inventory1(player_ptr);
232     sense_inventory2(player_ptr);
233     execute_recall(player_ptr);
234     execute_floor_reset(player_ptr);
235 }
236
237 /*!
238  * @brief ゲーム時刻を表示する /
239  * Print time
240  * @return なし
241  */
242 void print_time(player_type *player_ptr)
243 {
244     int day, hour, min;
245     c_put_str(TERM_WHITE, "             ", ROW_DAY, COL_DAY);
246     extract_day_hour_min(player_ptr, &day, &hour, &min);
247     if (day < 1000)
248         c_put_str(TERM_WHITE, format(_("%2d日目", "Day%3d"), day), ROW_DAY, COL_DAY);
249     else
250         c_put_str(TERM_WHITE, _("***日目", "Day***"), ROW_DAY, COL_DAY);
251
252     c_put_str(TERM_WHITE, format("%2d:%02d", hour, min), ROW_DAY, COL_DAY + 7);
253 }