OSDN Git Service

Merge remote-tracking branch 'remotes/origin/feature/Fix-Sanity-Blast-by-AutoSave...
[hengband/hengband.git] / src / load / world-loader.c
1 #include "load/world-loader.h"
2 #include "cmd-building/cmd-building.h"
3 #include "dungeon/dungeon.h"
4 #include "floor/wild.h"
5 #include "load/angband-version-comparer.h"
6 #include "load/load-util.h"
7 #include "load/load-zangband.h"
8 #include "market/bounty.h"
9 #include "system/building-type-definition.h"
10 #include "system/floor-type-definition.h"
11 #include "world/world.h"
12
13 static void rd_hengband_dungeons(void)
14 {
15     byte max = (byte)current_world_ptr->max_d_idx;
16     rd_byte(&max);
17     s16b tmp16s;
18     for (int i = 0; i < max; i++) {
19         rd_s16b(&tmp16s);
20         max_dlv[i] = tmp16s;
21         if (max_dlv[i] > d_info[i].maxdepth)
22             max_dlv[i] = d_info[i].maxdepth;
23     }
24 }
25
26 void rd_dungeons(player_type *creature_ptr)
27 {
28     if (z_older_than(10, 3, 8))
29         rd_zangband_dungeon();
30     else
31         rd_hengband_dungeons();
32
33     if (creature_ptr->max_plv < creature_ptr->lev)
34         creature_ptr->max_plv = creature_ptr->lev;
35 }
36
37 /*!
38  * @brief 現実変容処理の有無及びその残りターン数を読み込む
39  * @param creature_ptr プレーヤーへの参照ポインタ
40  * @return なし
41  */
42 void rd_alter_reality(player_type *creature_ptr)
43 {
44     s16b tmp16s;
45     if (z_older_than(10, 3, 8))
46         creature_ptr->recall_dungeon = DUNGEON_ANGBAND;
47     else {
48         rd_s16b(&tmp16s);
49         creature_ptr->recall_dungeon = (byte)tmp16s;
50     }
51
52     if (h_older_than(1, 5, 0, 0))
53         creature_ptr->alter_reality = 0;
54     else
55         rd_s16b(&creature_ptr->alter_reality);
56 }
57
58 void set_gambling_monsters(void)
59 {
60     const int max_gambling_monsters = 4;
61     for (int i = 0; i < max_gambling_monsters; i++) {
62         rd_s16b(&battle_mon[i]);
63         if (z_older_than(10, 3, 4))
64             set_zangband_gambling_monsters(i);
65         else
66             rd_u32b(&mon_odds[i]);
67     }
68 }
69
70 /*!
71  * @details 自動拾い関係はこれしかないのでworldに突っ込むことにする。必要があれば再分割する
72  */
73 void rd_autopick(player_type *creature_ptr)
74 {
75     byte tmp8u;
76     rd_byte(&tmp8u);
77     creature_ptr->autopick_autoregister = tmp8u != 0;
78 }
79
80 static void set_undead_turn_limit(player_type *creature_ptr)
81 {
82     switch (creature_ptr->start_race) {
83     case RACE_VAMPIRE:
84     case RACE_SKELETON:
85     case RACE_ZOMBIE:
86     case RACE_SPECTRE:
87         current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
88         break;
89     default:
90         current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
91         break;
92     }
93 }
94
95 static void rd_world_info(player_type *creature_ptr)
96 {
97     set_undead_turn_limit(creature_ptr);
98     current_world_ptr->dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
99     rd_s32b(&creature_ptr->current_floor_ptr->generated_turn);
100     if (h_older_than(1, 7, 0, 4))
101         creature_ptr->feeling_turn = creature_ptr->current_floor_ptr->generated_turn;
102     else
103         rd_s32b(&creature_ptr->feeling_turn);
104
105     rd_s32b(&current_world_ptr->game_turn);
106     if (z_older_than(10, 3, 12))
107         current_world_ptr->dungeon_turn = current_world_ptr->game_turn;
108     else
109         rd_s32b(&current_world_ptr->dungeon_turn);
110
111     if (z_older_than(11, 0, 13))
112         set_zangband_game_turns(creature_ptr);
113
114     if (z_older_than(10, 3, 13))
115         current_world_ptr->arena_start_turn = current_world_ptr->game_turn;
116     else
117         rd_s32b(&current_world_ptr->arena_start_turn);
118
119     if (z_older_than(10, 0, 3))
120         determine_daily_bounty(creature_ptr, TRUE);
121     else {
122         rd_s16b(&today_mon);
123         rd_s16b(&creature_ptr->today_mon);
124     }
125 }
126
127 void rd_visited_towns(player_type *creature_ptr)
128 {
129     if (z_older_than(10, 3, 9)) {
130         creature_ptr->visit = 1L;
131         return;
132     }
133
134     if (z_older_than(10, 3, 10)) {
135         set_zangband_visited_towns(creature_ptr);
136         return;
137     }
138
139     s32b tmp32s;
140     rd_s32b(&tmp32s);
141     creature_ptr->visit = (BIT_FLAGS)tmp32s;
142 }
143
144 void rd_global_configurations(player_type *creature_ptr)
145 {
146     rd_u32b(&current_world_ptr->seed_flavor);
147     rd_u32b(&current_world_ptr->seed_town);
148
149     rd_u16b(&creature_ptr->panic_save);
150     rd_u16b(&current_world_ptr->total_winner);
151     rd_u16b(&current_world_ptr->noscore);
152
153     byte tmp8u;
154     rd_byte(&tmp8u);
155     creature_ptr->is_dead = tmp8u;
156
157     rd_byte(&creature_ptr->feeling);
158     rd_world_info(creature_ptr);
159 }
160
161 void load_wilderness_info(player_type *creature_ptr)
162 {
163     rd_s32b(&creature_ptr->wilderness_x);
164     rd_s32b(&creature_ptr->wilderness_y);
165     if (z_older_than(10, 3, 13)) {
166         creature_ptr->wilderness_x = 5;
167         creature_ptr->wilderness_y = 48;
168     }
169
170     if (z_older_than(10, 3, 7))
171         creature_ptr->wild_mode = FALSE;
172     else
173         rd_byte((byte *)&creature_ptr->wild_mode);
174
175     if (z_older_than(10, 3, 7))
176         creature_ptr->ambush_flag = FALSE;
177     else
178         rd_byte((byte *)&creature_ptr->ambush_flag);
179 }
180
181 errr analyze_wilderness(void)
182 {
183     s32b wild_x_size;
184     s32b wild_y_size;
185     rd_s32b(&wild_x_size);
186     rd_s32b(&wild_y_size);
187
188     if ((wild_x_size > current_world_ptr->max_wild_x) || (wild_y_size > current_world_ptr->max_wild_y)) {
189         load_note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
190         return (23);
191     }
192
193     for (int i = 0; i < wild_x_size; i++)
194         for (int j = 0; j < wild_y_size; j++)
195             rd_u32b(&wilderness[j][i].seed);
196
197     return 0;
198 }