OSDN Git Service

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