author | truelight |
Fri, 10 Sep 2004 19:02:27 +0000 | |
changeset 193 | 0a7025304867 |
parent 123 | d550772c61e6 |
child 206 | 7f8c26d8526b |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
3 |
||
4 |
#include "town.h" |
|
5 |
#include "industry.h" |
|
6 |
#include "station.h" |
|
7 |
#include "economy.h" |
|
8 |
#include "player.h" |
|
9 |
#include "engine.h" |
|
10 |
#include "vehicle.h" |
|
11 |
||
12 |
extern byte _name_array[512][32]; |
|
13 |
extern TileIndex _animated_tile_list[256]; |
|
14 |
||
15 |
#if defined(_MSC_VER) |
|
16 |
#pragma pack(push, 1) |
|
17 |
#endif |
|
18 |
||
19 |
typedef struct { |
|
20 |
uint16 string_id; |
|
21 |
uint16 x; |
|
22 |
uint16 right; |
|
23 |
uint16 y; |
|
24 |
uint16 bottom; |
|
25 |
uint16 duration; |
|
26 |
uint32 params[2]; |
|
27 |
} GCC_PACK OldTextEffect; |
|
28 |
assert_compile(sizeof(OldTextEffect) == 0x14); |
|
29 |
||
30 |
typedef struct { |
|
31 |
uint16 xy; |
|
32 |
uint16 population; |
|
33 |
uint16 townnametype; |
|
34 |
uint32 townnameparts; |
|
35 |
byte grow_counter; |
|
36 |
byte sort_index; |
|
37 |
int16 sign_left, sign_top; |
|
38 |
byte namewidth_1, namewidth_2; |
|
39 |
uint16 flags12; |
|
40 |
uint16 radius[5]; |
|
41 |
uint16 ratings[8]; |
|
42 |
uint32 have_ratings; |
|
43 |
uint32 statues; |
|
44 |
uint16 num_houses; |
|
45 |
byte time_until_rebuild; |
|
46 |
byte growth_rate; |
|
47 |
uint16 new_max_pass, new_max_mail; |
|
48 |
uint16 new_act_pass, new_act_mail; |
|
49 |
uint16 max_pass, max_mail; |
|
50 |
uint16 act_pass, act_mail; |
|
51 |
byte pct_pass_transported, pct_mail_transported; |
|
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
52 |
uint16 new_act_food, new_act_water; |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
53 |
uint16 act_food, act_water; |
0 | 54 |
byte road_build_months; |
55 |
byte fund_buildings_months; |
|
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
56 |
// unused bytes at the end of the Town Struct |
0 | 57 |
uint32 unk56; |
58 |
uint32 unk5A; |
|
59 |
} GCC_PACK OldTown; |
|
60 |
assert_compile(sizeof(OldTown) == 0x5E); |
|
61 |
||
62 |
typedef struct { |
|
63 |
uint16 xy; |
|
64 |
uint32 town; |
|
65 |
} GCC_PACK OldDepot; |
|
66 |
assert_compile(sizeof(OldDepot) == 0x6); |
|
67 |
||
68 |
typedef struct { |
|
69 |
uint32 price; |
|
70 |
uint16 frac; |
|
71 |
} GCC_PACK OldPrice; |
|
72 |
assert_compile(sizeof(OldPrice) == 0x6); |
|
73 |
||
74 |
typedef struct { |
|
75 |
uint32 price; |
|
76 |
uint16 frac; |
|
77 |
uint16 unused; |
|
78 |
} GCC_PACK OldPaymentRate; |
|
79 |
assert_compile(sizeof(OldPaymentRate) == 8); |
|
80 |
||
81 |
typedef struct { |
|
82 |
uint16 waiting_acceptance; |
|
83 |
byte days_since_pickup; |
|
84 |
byte rating; |
|
85 |
byte enroute_from; |
|
86 |
byte enroute_time; |
|
87 |
byte last_speed; |
|
88 |
byte last_age; |
|
89 |
} GCC_PACK OldGoodsEntry; |
|
90 |
assert_compile(sizeof(OldGoodsEntry) == 8); |
|
91 |
||
92 |
typedef struct { |
|
93 |
uint16 xy; |
|
94 |
uint32 town; |
|
95 |
uint16 bus_tile, lorry_tile, train_tile, airport_tile, dock_tile; |
|
96 |
byte platforms; |
|
97 |
byte alpha_order_obsolete; // alpha_order is obsolete since savegame format 4 |
|
98 |
byte namewidth_1, namewidth_2; |
|
99 |
uint16 string_id; |
|
100 |
int16 sign_left, sign_top; |
|
101 |
uint16 had_vehicle_of_type; |
|
102 |
OldGoodsEntry goods[12]; |
|
103 |
byte time_since_load, time_since_unload; |
|
104 |
byte delete_ctr; |
|
105 |
byte owner; |
|
106 |
byte facilities; |
|
107 |
byte airport_type; |
|
108 |
byte truck_stop_status, bus_stop_status; |
|
123
d550772c61e6
(svn r124) Prepared code for removal of block_months variable in next major savegame version
dominik
parents:
4
diff
changeset
|
109 |
byte blocked_months_obsolete; |
0 | 110 |
byte unk85; |
111 |
uint16 airport_flags; |
|
112 |
uint16 last_vehicle; |
|
113 |
uint32 unk8A; |
|
114 |
} GCC_PACK OldStation; |
|
115 |
assert_compile(sizeof(OldStation) == 0x8E); |
|
116 |
||
117 |
typedef struct { |
|
118 |
uint16 xy; |
|
119 |
uint32 town; |
|
120 |
byte width; |
|
121 |
byte height; |
|
122 |
byte produced_cargo[2]; |
|
123 |
uint16 cargo_waiting[2]; |
|
124 |
byte production_rate[2]; |
|
125 |
byte accepts_cargo[3]; |
|
126 |
byte prod_level; |
|
127 |
uint16 last_mo_production[2]; |
|
128 |
uint16 last_mo_transported[2]; |
|
129 |
byte pct_transported[2]; |
|
130 |
uint16 total_production[2]; |
|
131 |
uint16 total_transported[2]; |
|
132 |
byte type; |
|
133 |
byte owner; |
|
134 |
byte color_map; |
|
135 |
byte last_prod_year; |
|
136 |
uint16 counter; |
|
137 |
byte was_cargo_delivered; |
|
138 |
byte nothing; |
|
139 |
uint32 unk2E; |
|
140 |
uint32 unk32; |
|
141 |
} GCC_PACK OldIndustry; |
|
142 |
assert_compile(sizeof(OldIndustry) == 0x36); |
|
143 |
||
144 |
typedef struct { |
|
145 |
int32 cost[13]; |
|
146 |
} GCC_PACK OldPlayerExpenses; |
|
147 |
assert_compile(sizeof(OldPlayerExpenses) == 0x34); |
|
148 |
||
149 |
typedef struct { |
|
150 |
int32 income; |
|
151 |
int32 expenses; |
|
152 |
uint32 delivered_cargo; |
|
153 |
uint32 performance_history; |
|
154 |
uint32 company_value; |
|
155 |
} GCC_PACK OldPlayerEconomy; |
|
156 |
assert_compile(sizeof(OldPlayerEconomy) == 0x14); |
|
157 |
||
158 |
typedef struct { |
|
159 |
uint16 spec_tile; |
|
160 |
uint16 use_tile; |
|
161 |
byte rand_rng; |
|
162 |
byte cur_rule; |
|
163 |
byte unk6; |
|
164 |
byte unk7; |
|
165 |
byte buildcmd_a; |
|
166 |
byte buildcmd_b; |
|
167 |
byte direction; |
|
168 |
byte cargo; |
|
169 |
byte unused[8]; |
|
170 |
} GCC_PACK OldAiBuildRec; |
|
171 |
assert_compile(sizeof(OldAiBuildRec) == 0x14); |
|
172 |
||
173 |
typedef struct { |
|
174 |
uint16 tile; |
|
175 |
byte data; |
|
176 |
} GCC_PACK OldAiBannedTile; |
|
177 |
assert_compile(sizeof(OldAiBannedTile) == 3); |
|
178 |
||
179 |
typedef struct { |
|
180 |
uint16 name_1; |
|
181 |
uint32 name_2; |
|
182 |
uint32 face; |
|
183 |
uint16 pres_name_1; |
|
184 |
uint32 pres_name_2; |
|
185 |
uint32 money; |
|
186 |
uint32 loan; |
|
187 |
byte color; |
|
188 |
byte money_fract; |
|
189 |
byte quarters_of_bankrupcy; |
|
190 |
byte bankrupt_asked; |
|
191 |
uint32 bankrupt_value; |
|
192 |
uint16 bankrupt_timeout; |
|
193 |
uint32 cargo_types; |
|
194 |
OldPlayerExpenses expenses[3]; |
|
195 |
OldPlayerEconomy economy[24 + 1]; |
|
196 |
uint16 inaugurated_date; |
|
197 |
uint16 last_build_coordinate; |
|
198 |
byte num_valid_stat_ent; |
|
199 |
byte ai_state; |
|
200 |
byte unused; |
|
201 |
byte ai_state_mode; |
|
202 |
uint16 ai_state_counter; |
|
203 |
uint16 ai_timeout_counter; |
|
204 |
OldAiBuildRec ai_src, ai_dst, ai_mid1, ai_mid2; |
|
205 |
byte unused_2[20]; |
|
206 |
byte ai_cargo_type; |
|
207 |
byte ai_num_wagons; |
|
208 |
byte ai_build_kind; |
|
209 |
byte ai_num_build_rec; |
|
210 |
byte ai_num_loco_to_build; |
|
211 |
byte ai_num_want_fullload; |
|
212 |
byte unused_3[14]; |
|
213 |
uint16 ai_loco_id; // NOT USED |
|
214 |
uint16 ai_wagonlist[9]; |
|
215 |
byte ai_order_list_blocks[20]; |
|
216 |
uint16 ai_start_tile_a; |
|
217 |
uint16 ai_start_tile_b; |
|
218 |
uint16 ai_cur_tile_a; |
|
219 |
uint16 ai_cur_tile_b; |
|
220 |
byte ai_start_dir_a; |
|
221 |
byte ai_start_dir_b; |
|
222 |
byte ai_cur_dir_a; |
|
223 |
byte ai_cur_dir_b; |
|
224 |
byte ai_banned_tile_count; |
|
225 |
OldAiBannedTile banned_tiles[16]; |
|
226 |
byte ai_railtype_to_use; |
|
227 |
byte ai_route_type_mask; |
|
228 |
byte block_preview; |
|
229 |
byte ai_tick; |
|
230 |
byte max_railtype; |
|
231 |
uint16 location_of_house; |
|
232 |
byte share_owners[4]; |
|
233 |
uint32 unk3AA; |
|
234 |
uint32 unk3AE; |
|
235 |
} GCC_PACK OldPlayer; |
|
236 |
assert_compile(sizeof(OldPlayer) == 0x3B2); |
|
237 |
||
238 |
typedef struct { |
|
239 |
byte track; |
|
240 |
byte force_proceed; |
|
241 |
uint16 crash_anim_pos; |
|
242 |
byte railtype; |
|
243 |
} GCC_PACK OldVehicleRailUnion; |
|
244 |
assert_compile(sizeof(OldVehicleRailUnion) == 5); |
|
245 |
||
246 |
typedef struct { |
|
247 |
byte unk0; |
|
248 |
byte targetairport; |
|
249 |
uint16 crashed_counter; |
|
250 |
byte state; |
|
251 |
} GCC_PACK OldVehicleAirUnion; |
|
252 |
assert_compile(sizeof(OldVehicleAirUnion) == 5); |
|
253 |
||
254 |
typedef struct { |
|
255 |
byte state; |
|
256 |
byte frame; |
|
257 |
uint16 unk2; |
|
258 |
byte overtaking; |
|
259 |
byte overtaking_ctr; |
|
260 |
uint16 crashed_ctr; |
|
261 |
byte reverse_ctr; |
|
262 |
} GCC_PACK OldVehicleRoadUnion; |
|
263 |
assert_compile(sizeof(OldVehicleRoadUnion) == 9); |
|
264 |
||
265 |
typedef struct { |
|
266 |
uint16 unk0; |
|
267 |
byte unk2; |
|
268 |
} GCC_PACK OldVehicleSpecialUnion; |
|
269 |
assert_compile(sizeof(OldVehicleSpecialUnion) == 3); |
|
270 |
||
271 |
typedef struct { |
|
272 |
uint16 image_override; |
|
273 |
uint16 unk2; |
|
274 |
} GCC_PACK OldVehicleDisasterUnion; |
|
275 |
assert_compile(sizeof(OldVehicleDisasterUnion) == 4); |
|
276 |
||
277 |
typedef struct { |
|
278 |
byte state; |
|
279 |
} OldVehicleShipUnion; |
|
280 |
assert_compile(sizeof(OldVehicleShipUnion) == 1); |
|
281 |
||
282 |
typedef union { |
|
283 |
OldVehicleRailUnion rail; |
|
284 |
OldVehicleAirUnion air; |
|
285 |
OldVehicleRoadUnion road; |
|
286 |
OldVehicleSpecialUnion special; |
|
287 |
OldVehicleDisasterUnion disaster; |
|
288 |
OldVehicleShipUnion ship; |
|
289 |
byte pad[10]; |
|
290 |
} GCC_PACK OldVehicleUnion; |
|
291 |
assert_compile(sizeof(OldVehicleUnion) == 10); |
|
292 |
||
293 |
typedef struct { |
|
294 |
byte type; |
|
295 |
byte subtype; |
|
296 |
uint16 next_hash; // NOLOAD, calculated automatically. |
|
297 |
uint16 index; // NOLOAD, calculated automatically. |
|
298 |
uint32 schedule_ptr; |
|
299 |
byte next_order, next_order_param; |
|
300 |
byte num_orders; |
|
301 |
byte cur_order_index; |
|
302 |
uint16 dest_tile; |
|
303 |
uint16 load_unload_time_rem; |
|
304 |
uint16 date_of_last_service; |
|
305 |
uint16 service_interval; |
|
306 |
byte last_station_visited; |
|
307 |
byte tick_counter; |
|
308 |
uint16 max_speed; |
|
309 |
uint16 x_pos, y_pos; |
|
310 |
byte z_pos; |
|
311 |
byte direction; |
|
312 |
byte x_offs, y_offs; |
|
313 |
byte sprite_width, sprite_height, z_height; |
|
314 |
byte owner; |
|
315 |
uint16 tile; |
|
316 |
uint16 cur_image; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
317 |
|
0 | 318 |
int16 left_coord, right_coord, top_coord, bottom_coord; // NOLOAD, calculated automatically. |
319 |
uint16 vehstatus; |
|
320 |
uint16 cur_speed; |
|
321 |
byte subspeed; |
|
322 |
byte acceleration; |
|
323 |
byte progress; |
|
324 |
byte cargo_type; |
|
325 |
uint16 capacity; |
|
326 |
uint16 number_of_pieces; |
|
327 |
byte source_of_pieces; |
|
328 |
byte days_in_transit; |
|
329 |
uint16 age_in_days, max_age_in_days; |
|
330 |
byte build_year; |
|
331 |
byte unitnumber; |
|
332 |
uint16 engine_type; |
|
333 |
byte spritenum; |
|
334 |
byte day_counter; |
|
335 |
byte breakdowns_since_last_service; |
|
336 |
byte breakdown_ctr, breakdown_delay, breakdown_chance; |
|
337 |
uint16 reliability, reliability_spd_dec; |
|
338 |
uint32 profit_this_year, profit_last_year; |
|
339 |
uint16 next_in_chain; |
|
340 |
uint32 value; |
|
341 |
uint16 string_id; |
|
342 |
OldVehicleUnion u; |
|
343 |
byte unused[20]; |
|
344 |
} GCC_PACK OldVehicle; |
|
345 |
assert_compile(sizeof(OldVehicle) == 0x80); |
|
346 |
||
347 |
typedef struct { |
|
348 |
byte name[32]; |
|
349 |
} GCC_PACK OldName; |
|
350 |
||
351 |
typedef struct { |
|
352 |
uint16 text; |
|
353 |
int16 x,y,z; |
|
354 |
byte namewidth_1, namewidth_2; |
|
355 |
int16 sign_left, sign_top; |
|
356 |
} GCC_PACK OldSign; |
|
357 |
assert_compile(sizeof(OldSign) == 0xE); |
|
358 |
||
359 |
typedef struct { |
|
360 |
uint16 player_avail; |
|
361 |
uint16 intro_date; |
|
362 |
uint16 age; |
|
363 |
uint16 reliability, reliability_spd_dec, reliability_start, reliability_max, reliability_final; |
|
364 |
uint16 duration_phase_1, duration_phase_2, duration_phase_3; |
|
365 |
byte lifelength; |
|
366 |
byte flags; |
|
367 |
byte preview_player; |
|
368 |
byte preview_wait; |
|
369 |
byte railtype; |
|
370 |
byte unk1B; |
|
371 |
} GCC_PACK OldEngine; |
|
372 |
assert_compile(sizeof(OldEngine) == 0x1C); |
|
373 |
||
374 |
typedef struct { |
|
375 |
byte cargo_type; |
|
376 |
byte age; |
|
377 |
byte from; |
|
378 |
byte to; |
|
379 |
} GCC_PACK OldSubsidy; |
|
380 |
assert_compile(sizeof(OldSubsidy) == 4); |
|
381 |
||
382 |
typedef struct { |
|
383 |
uint16 max_no_competitors; |
|
384 |
uint16 competitor_start_time; |
|
385 |
uint16 number_towns; |
|
386 |
uint16 number_industries; |
|
387 |
uint16 max_loan; |
|
388 |
uint16 initial_interest; |
|
389 |
uint16 vehicle_costs; |
|
390 |
uint16 competitor_speed; |
|
391 |
uint16 competitor_intelligence; |
|
392 |
uint16 vehicle_breakdowns; |
|
393 |
uint16 subsidy_multiplier; |
|
394 |
uint16 construction_cost; |
|
395 |
uint16 terrain_type; |
|
396 |
uint16 quantity_sea_lakes; |
|
397 |
uint16 economy; |
|
398 |
uint16 line_reverse_mode; |
|
399 |
uint16 disasters; |
|
400 |
} GCC_PACK OldGameSettings; |
|
401 |
assert_compile(sizeof(OldGameSettings) == 0x22); |
|
402 |
||
403 |
typedef struct { |
|
404 |
uint16 date; |
|
405 |
uint16 date_fract; |
|
406 |
||
407 |
OldTextEffect te_list[30]; // NOLOAD: not so important. |
|
408 |
uint32 seed_1, seed_2; |
|
409 |
||
410 |
OldTown town_list[70]; |
|
411 |
uint16 order_list[5000]; |
|
412 |
||
413 |
uint16 animated_tile_list[256]; |
|
414 |
uint32 ptr_to_next_order; |
|
415 |
OldDepot depots[255]; |
|
416 |
||
417 |
uint32 cur_town_ptr; |
|
418 |
uint16 timer_counter; |
|
419 |
uint16 land_code; // NOLOAD: never needed in game |
|
420 |
uint16 age_cargo_skip_counter; |
|
421 |
uint16 tick_counter; |
|
422 |
uint16 cur_tileloop_tile; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
423 |
|
0 | 424 |
OldPrice prices[49]; |
425 |
OldPaymentRate cargo_payment_rates[12]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
426 |
|
0 | 427 |
byte map_owner[256*256]; |
428 |
byte map2[256*256]; |
|
429 |
uint16 map3[256*256]; |
|
430 |
byte map_extra[256*256/4]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
431 |
|
0 | 432 |
OldStation stations[250]; |
433 |
OldIndustry industries[90]; |
|
434 |
OldPlayer players[8]; |
|
435 |
OldVehicle vehicles[850]; |
|
436 |
OldName names[500]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
437 |
|
0 | 438 |
uint16 vehicle_position_hash[0x1000]; // NOLOAD, calculated automatically. |
439 |
||
440 |
OldSign signs[40]; |
|
441 |
OldEngine engines[256]; |
|
442 |
||
443 |
uint16 vehicle_id_ctr_day; |
|
444 |
OldSubsidy subsidies[8]; |
|
445 |
||
446 |
uint16 next_competitor_start; |
|
447 |
||
448 |
uint16 saved_main_scrollpos_x, saved_main_scrollpos_y, saved_main_scrollpos_zoom; |
|
449 |
uint32 maximum_loan, maximum_loan_unround; |
|
450 |
uint16 economy_fluct; |
|
451 |
uint16 disaster_delay; |
|
452 |
||
453 |
//NOLOAD. These are calculated from InitializeLandscapeVariables |
|
454 |
uint16 cargo_names_s[12], cargo_names_p[12], cargo_names_long_s[12], cargo_names_long_p[12], cargo_names_short[12]; |
|
455 |
uint16 cargo_sprites[12]; |
|
456 |
||
457 |
uint16 engine_name_strings[256]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
458 |
|
0 | 459 |
//NOLOAD. These are calculated from InitializeLandscapeVariables |
460 |
uint16 railveh_by_cargo_1[12], railveh_by_cargo_2[12], railveh_by_cargo_3[12]; |
|
461 |
uint16 roadveh_by_cargo_start[12]; |
|
462 |
byte roadveh_by_cargo_count[12]; |
|
463 |
uint16 ship_of_type_start[12]; |
|
464 |
byte ship_of_type_count[12]; |
|
465 |
||
466 |
byte human_player_1, human_player_2; //NOLOAD. Calculated automatically. |
|
467 |
byte station_tick_ctr; |
|
468 |
byte currency; |
|
469 |
byte use_kilometers; |
|
470 |
byte cur_player_tick_index; |
|
471 |
byte cur_year, cur_month; //NOLOAD. Calculated automatically. |
|
472 |
byte player_colors[8]; //NOLOAD. Calculated automatically |
|
473 |
||
474 |
byte inflation_amount; |
|
475 |
byte inflation_amount_payment_rates; |
|
476 |
byte interest_rate; |
|
477 |
||
478 |
byte avail_aircraft; |
|
479 |
byte road_side; |
|
480 |
byte town_name_type; |
|
481 |
OldGameSettings game_diff; |
|
482 |
byte difficulty_level; |
|
483 |
byte landscape_type; |
|
484 |
byte trees_tick_ctr; |
|
485 |
byte vehicle_design_names; |
|
486 |
byte snow_line_height; |
|
487 |
||
488 |
byte new_industry_randtable[32]; // NOLOAD. Not needed due to different code design. |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
489 |
|
0 | 490 |
//NOLOAD. Initialized by InitializeLandscapeVariables |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
491 |
byte cargo_weights[12]; |
0 | 492 |
byte transit_days_table_1[12]; |
493 |
byte transit_days_table_2[12]; |
|
494 |
||
495 |
byte map_type_and_height[256*256]; |
|
496 |
byte map5[256*256]; |
|
497 |
} GCC_PACK OldMain; |
|
498 |
assert_compile(sizeof(OldMain) == 487801 + 256*256*2); |
|
499 |
||
500 |
#if defined(_MSC_VER) |
|
501 |
#pragma pack(pop) |
|
502 |
#endif |
|
503 |
||
504 |
#define REMAP_TOWN_IDX(x) (x - (0x0459154 - 0x0458EF0)) / sizeof(OldTown) |
|
505 |
#define REMAP_TOWN_PTR(x) DEREF_TOWN( REMAP_TOWN_IDX(x) ) |
|
506 |
||
507 |
#define REMAP_ORDER_IDX(x) (x - (0x045AB08 - 0x0458EF0)) / sizeof(uint16) |
|
508 |
||
509 |
typedef struct LoadSavegameState { |
|
510 |
int8 mode; |
|
511 |
byte rep_char; |
|
512 |
||
513 |
size_t count; |
|
514 |
size_t buffer_count; |
|
515 |
FILE *fin; |
|
516 |
||
517 |
byte *buffer_cur; |
|
518 |
||
519 |
byte buffer[4096]; |
|
520 |
||
521 |
} LoadSavegameState; |
|
522 |
||
523 |
static LoadSavegameState *_cur_state; |
|
524 |
||
525 |
static byte GetSavegameByteFromBuffer() |
|
526 |
{ |
|
527 |
LoadSavegameState *lss = _cur_state; |
|
528 |
||
529 |
if (lss->buffer_count == 0) { |
|
530 |
int count = fread(lss->buffer, 1, 4096, lss->fin) ; |
|
531 |
/* if (count == 0) { |
|
532 |
memset(lss->buffer, 0, sizeof(lss->buffer)); |
|
533 |
count = 4096; |
|
534 |
}*/ |
|
535 |
assert(count != 0); |
|
536 |
lss->buffer_count = count; |
|
537 |
lss->buffer_cur = lss->buffer; |
|
538 |
} |
|
539 |
||
540 |
lss->buffer_count--; |
|
541 |
return *lss->buffer_cur++; |
|
542 |
} |
|
543 |
||
544 |
static byte DecodeSavegameByte() |
|
545 |
{ |
|
546 |
LoadSavegameState *lss = _cur_state; |
|
547 |
int8 x; |
|
548 |
||
549 |
if (lss->mode < 0) { |
|
550 |
if (lss->count != 0) { |
|
551 |
lss->count--; |
|
552 |
return lss->rep_char; |
|
553 |
} |
|
554 |
} else if (lss->mode > 0) { |
|
555 |
if (lss->count != 0) { |
|
556 |
lss->count--; |
|
557 |
return GetSavegameByteFromBuffer(); |
|
558 |
} |
|
559 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
560 |
|
0 | 561 |
x = GetSavegameByteFromBuffer(); |
562 |
if (x >= 0) { |
|
563 |
lss->count = x; |
|
564 |
lss->mode = 1; |
|
565 |
return GetSavegameByteFromBuffer(); |
|
566 |
} else { |
|
567 |
lss->mode = -1; |
|
568 |
lss->count = -x; |
|
569 |
lss->rep_char = GetSavegameByteFromBuffer(); |
|
570 |
return lss->rep_char; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
571 |
} |
0 | 572 |
} |
573 |
||
574 |
static void LoadSavegameBytes(void *p, size_t count) |
|
575 |
{ |
|
576 |
byte *ptr = (byte*)p; |
|
577 |
assert(count > 0); |
|
578 |
do { |
|
579 |
*ptr++ = DecodeSavegameByte(); |
|
580 |
} while (--count); |
|
581 |
} |
|
582 |
||
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
583 |
extern uint32 GetOldTownName(uint32 townnameparts, byte old_town_name_type); |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
584 |
|
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
585 |
static void FixTown(Town *t, OldTown *o, int num, byte town_name_type) |
0 | 586 |
{ |
587 |
do { |
|
588 |
t->xy = o->xy; |
|
589 |
t->population = o->population; |
|
590 |
t->townnametype = o->townnametype; |
|
591 |
t->townnameparts = o->townnameparts; |
|
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
592 |
// Random TownNames |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
593 |
if (IS_INT_INSIDE(o->townnametype, 0x20C1, 0x20C2 + 1)) { |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
594 |
t->townnametype = SPECSTR_TOWNNAME_ENGLISH + town_name_type; |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
595 |
if (o->xy) |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
596 |
t->townnameparts = GetOldTownName(o->townnameparts, town_name_type); |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
597 |
} |
0 | 598 |
|
599 |
t->grow_counter = o->grow_counter; |
|
600 |
t->flags12 = o->flags12; |
|
601 |
memcpy(t->ratings,o->ratings,sizeof(t->ratings)); |
|
602 |
t->have_ratings = o->have_ratings; |
|
603 |
t->statues = o->statues; |
|
604 |
t->num_houses = o->num_houses; |
|
605 |
t->time_until_rebuild = o->time_until_rebuild; |
|
606 |
t->growth_rate = o->growth_rate; |
|
607 |
t->new_max_pass = o->new_max_pass; |
|
608 |
t->new_max_mail = o->new_max_mail; |
|
609 |
t->new_act_pass = o->new_act_pass; |
|
610 |
t->new_act_mail = o->new_act_mail; |
|
611 |
t->max_pass = o->max_pass; |
|
612 |
t->max_mail = o->max_mail; |
|
613 |
t->act_pass = o->act_pass; |
|
614 |
t->act_mail = o->act_mail; |
|
615 |
t->pct_pass_transported = o->pct_pass_transported; |
|
616 |
t->pct_mail_transported = o->pct_mail_transported; |
|
617 |
t->new_act_food = o->new_act_food; |
|
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
618 |
t->new_act_water = o->new_act_water; |
0 | 619 |
t->act_food = o->act_food; |
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
620 |
t->act_water = o->act_water; |
0 | 621 |
t->road_build_months = o->road_build_months; |
622 |
t->fund_buildings_months = o->fund_buildings_months; |
|
623 |
} while (t++,o++,--num); |
|
624 |
} |
|
625 |
||
626 |
static void FixIndustry(Industry *i, OldIndustry *o, int num) |
|
627 |
{ |
|
628 |
do { |
|
629 |
i->xy = o->xy; |
|
630 |
i->town = REMAP_TOWN_PTR(o->town); |
|
631 |
i->width = o->width; |
|
632 |
i->height = o->height; |
|
633 |
i->produced_cargo[0] = o->produced_cargo[0]; |
|
634 |
i->produced_cargo[1] = o->produced_cargo[1]; |
|
635 |
i->cargo_waiting[0] = o->cargo_waiting[0]; |
|
636 |
i->cargo_waiting[1] = o->cargo_waiting[1]; |
|
637 |
i->production_rate[0] = o->production_rate[0]; |
|
638 |
i->production_rate[1] = o->production_rate[1]; |
|
639 |
i->accepts_cargo[0] = o->accepts_cargo[0]; |
|
640 |
i->accepts_cargo[1] = o->accepts_cargo[1]; |
|
641 |
i->accepts_cargo[2] = o->accepts_cargo[2]; |
|
642 |
i->prod_level = o->prod_level; |
|
643 |
i->last_mo_production[0] = o->last_mo_production[0]; |
|
644 |
i->last_mo_production[1] = o->last_mo_production[1]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
645 |
|
0 | 646 |
i->last_mo_transported[0] = o->last_mo_transported[0]; |
647 |
i->last_mo_transported[1] = o->last_mo_transported[1]; |
|
648 |
i->last_mo_transported[2] = o->last_mo_transported[2]; |
|
649 |
||
650 |
i->pct_transported[0] = o->pct_transported[0]; |
|
651 |
i->pct_transported[1] = o->pct_transported[1]; |
|
652 |
||
653 |
i->total_production[0] = o->total_production[0]; |
|
654 |
i->total_production[1] = o->total_production[1]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
655 |
|
0 | 656 |
i->total_transported[0] = i->total_transported[0]; |
657 |
i->total_transported[1] = i->total_transported[1]; |
|
658 |
||
659 |
i->type = o->type; |
|
660 |
i->owner = o->owner; |
|
661 |
i->color_map = o->color_map; |
|
662 |
i->last_prod_year = o->last_prod_year; |
|
663 |
i->counter = o->counter; |
|
664 |
i->was_cargo_delivered = o->was_cargo_delivered; |
|
665 |
} while (i++,o++,--num); |
|
666 |
} |
|
667 |
||
668 |
static void FixGoodsEntry(GoodsEntry *g, OldGoodsEntry *o, int num) |
|
669 |
{ |
|
670 |
do { |
|
671 |
g->waiting_acceptance = o->waiting_acceptance; |
|
672 |
g->days_since_pickup = o->days_since_pickup; |
|
673 |
g->rating = o->rating; |
|
674 |
g->enroute_from = o->enroute_from; |
|
675 |
g->enroute_time = o->enroute_time; |
|
676 |
g->last_speed = o->last_speed; |
|
677 |
g->last_age = o->last_age; |
|
678 |
} while (g++,o++,--num); |
|
679 |
} |
|
680 |
||
681 |
static void FixStation(Station *s, OldStation *o, int num) |
|
682 |
{ |
|
683 |
do { |
|
684 |
s->xy = o->xy; |
|
685 |
s->town = REMAP_TOWN_PTR(o->town); |
|
686 |
s->bus_tile = o->bus_tile; |
|
687 |
s->lorry_tile = o->lorry_tile; |
|
688 |
s->train_tile = o->train_tile; |
|
689 |
s->airport_tile = o->airport_tile; |
|
690 |
s->dock_tile = o->dock_tile; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
691 |
|
0 | 692 |
if (o->train_tile) { |
693 |
int w = (o->platforms >> 3) & 0x7; |
|
694 |
int h = (o->platforms & 0x7); |
|
695 |
if (_map5[o->train_tile]&1) intswap(w,h); |
|
696 |
s->trainst_w = w; |
|
697 |
s->trainst_h = h; |
|
698 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
699 |
|
0 | 700 |
s->string_id = RemapOldStringID(o->string_id); |
701 |
s->had_vehicle_of_type = o->had_vehicle_of_type; |
|
702 |
FixGoodsEntry(s->goods, o->goods, lengthof(o->goods)); |
|
703 |
s->time_since_load = o->time_since_load; |
|
704 |
s->time_since_unload = o->time_since_unload; |
|
705 |
s->delete_ctr = o->delete_ctr; |
|
706 |
s->owner = o->owner; |
|
707 |
s->facilities = o->facilities; |
|
708 |
s->airport_type = o->airport_type; |
|
709 |
s->truck_stop_status = o->truck_stop_status; |
|
710 |
s->bus_stop_status = o->bus_stop_status; |
|
123
d550772c61e6
(svn r124) Prepared code for removal of block_months variable in next major savegame version
dominik
parents:
4
diff
changeset
|
711 |
s->blocked_months_obsolete = o->blocked_months_obsolete; |
0 | 712 |
s->airport_flags = o->airport_flags; |
713 |
s->last_vehicle = o->last_vehicle; |
|
714 |
} while (s++,o++,--num); |
|
715 |
} |
|
716 |
||
717 |
static void FixDepot(Depot *n, OldDepot *o, int num) |
|
718 |
{ |
|
719 |
do { |
|
720 |
n->town_index = REMAP_TOWN_IDX(o->town); |
|
721 |
n->xy = o->xy; |
|
722 |
} while (n++,o++,--num); |
|
723 |
} |
|
724 |
||
725 |
static void FixVehicle(Vehicle *n, OldVehicle *o, int num) |
|
726 |
{ |
|
727 |
do { |
|
728 |
n->type = o->type; |
|
729 |
n->subtype = o->subtype; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
730 |
|
0 | 731 |
if (o->schedule_ptr == 0xFFFFFFFF || o->schedule_ptr == 0) { |
732 |
n->schedule_ptr = NULL; |
|
733 |
} else { |
|
734 |
n->schedule_ptr = _order_array + REMAP_ORDER_IDX(o->schedule_ptr); |
|
735 |
assert(n->schedule_ptr >= _order_array && n->schedule_ptr < _ptr_to_next_order); |
|
736 |
} |
|
737 |
||
738 |
n->next_order = o->next_order; |
|
739 |
n->next_order_param = o->next_order_param; |
|
740 |
n->num_orders = o->num_orders; |
|
741 |
n->cur_order_index = o->cur_order_index; |
|
742 |
n->dest_tile = o->dest_tile; |
|
743 |
n->load_unload_time_rem = o->load_unload_time_rem; |
|
744 |
n->date_of_last_service = o->date_of_last_service; |
|
745 |
n->service_interval = o->service_interval; |
|
746 |
n->last_station_visited = o->last_station_visited; |
|
747 |
n->tick_counter = o->tick_counter; |
|
748 |
n->max_speed = o->max_speed; |
|
749 |
n->x_pos = o->x_pos; |
|
750 |
n->y_pos = o->y_pos; |
|
751 |
n->z_pos = o->z_pos; |
|
752 |
n->direction = o->direction; |
|
753 |
n->x_offs = o->x_offs; |
|
754 |
n->y_offs = o->y_offs; |
|
755 |
n->sprite_width = o->sprite_width; |
|
756 |
n->sprite_height = o->sprite_height; |
|
757 |
n->z_height = o->z_height; |
|
758 |
n->owner = o->owner; |
|
759 |
n->tile = o->tile; |
|
760 |
n->cur_image = o->cur_image; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
761 |
|
0 | 762 |
n->vehstatus = o->vehstatus; |
763 |
n->cur_speed = o->cur_speed; |
|
764 |
n->subspeed = o->subspeed; |
|
765 |
n->acceleration = o->acceleration; |
|
766 |
n->progress = o->progress; |
|
767 |
n->cargo_type = o->cargo_type; |
|
768 |
n->cargo_cap = o->capacity; |
|
769 |
n->cargo_count = o->number_of_pieces; |
|
770 |
n->cargo_source = o->source_of_pieces; |
|
771 |
n->cargo_days = o->days_in_transit; |
|
772 |
n->age = o->age_in_days; |
|
773 |
n->max_age = o->max_age_in_days; |
|
774 |
n->build_year = o->build_year; |
|
775 |
n->unitnumber = o->unitnumber; |
|
776 |
n->engine_type = o->engine_type; |
|
777 |
n->spritenum = o->spritenum>>1; |
|
778 |
n->day_counter = o->day_counter; |
|
779 |
n->breakdowns_since_last_service = o->breakdowns_since_last_service; |
|
780 |
n->breakdown_ctr = o->breakdown_ctr; |
|
781 |
n->breakdown_delay = o->breakdown_delay; |
|
782 |
n->breakdown_chance = o->breakdown_chance; |
|
783 |
n->reliability = o->reliability; |
|
784 |
n->reliability_spd_dec = o->reliability_spd_dec; |
|
785 |
n->profit_this_year = o->profit_this_year; |
|
786 |
n->profit_last_year = o->profit_last_year; |
|
787 |
n->next = o->next_in_chain == 0xffff ? NULL : &_vehicles[o->next_in_chain]; |
|
788 |
n->value = o->value; |
|
789 |
n->string_id = RemapOldStringID(o->string_id); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
790 |
|
0 | 791 |
switch(o->type) { |
792 |
case VEH_Train: |
|
793 |
n->u.rail.track = o->u.rail.track; |
|
794 |
n->u.rail.force_proceed = o->u.rail.force_proceed; |
|
795 |
n->u.rail.crash_anim_pos = o->u.rail.crash_anim_pos; |
|
796 |
n->u.rail.railtype = o->u.rail.railtype; |
|
797 |
break; |
|
798 |
||
799 |
case VEH_Road: |
|
800 |
n->u.road.state = o->u.road.state; |
|
801 |
n->u.road.frame = o->u.road.frame; |
|
802 |
n->u.road.unk2 = o->u.road.unk2; |
|
803 |
n->u.road.overtaking = o->u.road.overtaking; |
|
804 |
n->u.road.overtaking_ctr = o->u.road.overtaking_ctr; |
|
805 |
n->u.road.crashed_ctr = o->u.road.crashed_ctr; |
|
806 |
n->u.road.reverse_ctr = o->u.road.reverse_ctr; |
|
807 |
break; |
|
808 |
case VEH_Ship: |
|
809 |
n->u.ship.state = o->u.ship.state; |
|
810 |
break; |
|
811 |
case VEH_Aircraft: |
|
812 |
n->u.air.crashed_counter = o->u.air.crashed_counter; |
|
813 |
n->u.air.pos = o->u.air.unk0; |
|
814 |
n->u.air.targetairport = o->u.air.targetairport; |
|
815 |
n->u.air.state = o->u.air.state; |
|
816 |
break; |
|
817 |
case VEH_Special: |
|
818 |
n->u.special.unk0 = o->u.special.unk0; |
|
819 |
n->u.special.unk2 = o->u.special.unk2; |
|
820 |
n->subtype = o->subtype >> 1; |
|
821 |
break; |
|
822 |
case VEH_Disaster: |
|
823 |
n->u.disaster.image_override = o->u.disaster.image_override; |
|
824 |
n->u.disaster.unk2 = o->u.disaster.unk2; |
|
825 |
break; |
|
826 |
} |
|
827 |
} while (n++,o++,--num); |
|
828 |
} |
|
829 |
||
830 |
static void FixSubsidy(Subsidy *n, OldSubsidy *o, int num) |
|
831 |
{ |
|
832 |
do { |
|
833 |
n->age = o->age; |
|
834 |
n->cargo_type = o->cargo_type; |
|
835 |
n->from = o->from; |
|
836 |
n->to = o->to; |
|
837 |
} while (n++,o++,--num); |
|
838 |
} |
|
839 |
||
840 |
static void FixEconomy(PlayerEconomyEntry *n, OldPlayerEconomy *o) |
|
841 |
{ |
|
842 |
n->company_value = o->company_value; |
|
843 |
n->delivered_cargo = o->delivered_cargo; |
|
844 |
n->income = -o->income; |
|
845 |
n->expenses = -o->expenses; |
|
846 |
n->performance_history = o->performance_history; |
|
847 |
} |
|
848 |
||
849 |
static void FixAiBuildRec(AiBuildRec *n, OldAiBuildRec *o) |
|
850 |
{ |
|
851 |
n->spec_tile = o->spec_tile; |
|
852 |
n->use_tile = o->use_tile; |
|
853 |
n->rand_rng = o->rand_rng; |
|
854 |
n->cur_building_rule = o->cur_rule; |
|
855 |
n->unk6 = o->unk6; |
|
856 |
n->unk7 = o->unk7; |
|
857 |
n->buildcmd_a = o->buildcmd_a; |
|
858 |
n->buildcmd_b = o->buildcmd_b; |
|
859 |
n->direction = o->direction; |
|
860 |
n->cargo = o->cargo; |
|
861 |
} |
|
862 |
||
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
863 |
static void FixPlayer(Player *n, OldPlayer *o, int num, byte town_name_type) |
0 | 864 |
{ |
865 |
int i, j; |
|
866 |
int x = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
867 |
|
0 | 868 |
do { |
869 |
n->name_1 = RemapOldStringID(o->name_1); |
|
870 |
n->name_2 = o->name_2; |
|
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
871 |
/* In every Old TTD(Patch) game Player1 (0) is human, and all others are AI |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
872 |
* (Except in .SV2 savegames, which were 2 player games, but we are not fixing |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
873 |
* that |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
874 |
*/ |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
875 |
|
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
876 |
if (x == 0) { |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
877 |
if (o->name_1 == 0) // if first player doesn't have a name, he is 'unnamed' |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
878 |
n->name_1 = STR_SV_UNNAMED; |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
879 |
} else { |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
880 |
n->is_ai = 1; |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
881 |
} |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
882 |
|
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
883 |
if (o->name_1 != 0) |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
884 |
n->is_active = true; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
885 |
|
0 | 886 |
n->face = o->face; |
887 |
n->president_name_1 = o->pres_name_1; |
|
888 |
n->president_name_2 = o->pres_name_2; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
889 |
|
0 | 890 |
n->money64 = n->player_money = o->money; |
891 |
n->current_loan = o->loan; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
892 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
893 |
// Correct money for scenario loading. |
0 | 894 |
// It's always 893288 pounds (and no loan), if not corrected |
895 |
if(o->money==0xda168) |
|
896 |
n->money64 = n->player_money = n->current_loan =100000; |
|
897 |
||
898 |
n->player_color = o->color; |
|
899 |
_player_colors[x] = o->color; |
|
900 |
x++; |
|
901 |
||
902 |
n->player_money_fraction = o->money_fract; |
|
903 |
n->quarters_of_bankrupcy = o->quarters_of_bankrupcy; |
|
904 |
n->bankrupt_asked = o->bankrupt_asked; |
|
905 |
n->bankrupt_value = o->bankrupt_value; |
|
906 |
n->bankrupt_timeout = o->bankrupt_timeout; |
|
907 |
n->cargo_types = o->cargo_types; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
908 |
|
0 | 909 |
for(i=0; i!=3; i++) |
910 |
for(j=0; j!=13; j++) |
|
911 |
n->yearly_expenses[i][j] = o->expenses[i].cost[j]; |
|
912 |
||
913 |
FixEconomy(&n->cur_economy, &o->economy[0]); |
|
914 |
for(i=0; i!=24; i++) FixEconomy(&n->old_economy[i], &o->economy[i+1]); |
|
915 |
n->inaugurated_year = o->inaugurated_date - 1920; |
|
916 |
n->last_build_coordinate = o->last_build_coordinate; |
|
917 |
n->num_valid_stat_ent = o->num_valid_stat_ent; |
|
918 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
919 |
/* Not good, since AI doesn't have a vehicle assigned as |
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
920 |
* in p->ai.cur_veh and thus will crash on certain actions. |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
921 |
* Best is to set state to AiStateVehLoop (2) |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
922 |
* n->ai.state = o->ai_state; |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
923 |
*/ |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
924 |
n->ai.state = 2; |
0 | 925 |
n->ai.state_mode = o->ai_state_mode; |
926 |
n->ai.state_counter = o->ai_state_counter; |
|
927 |
n->ai.timeout_counter = o->ai_timeout_counter; |
|
928 |
n->ai.banned_tile_count = o->ai_banned_tile_count; |
|
929 |
n->ai.railtype_to_use = o->ai_railtype_to_use; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
930 |
|
0 | 931 |
FixAiBuildRec(&n->ai.src, &o->ai_src); |
932 |
FixAiBuildRec(&n->ai.dst, &o->ai_dst); |
|
933 |
FixAiBuildRec(&n->ai.mid1, &o->ai_mid1); |
|
934 |
FixAiBuildRec(&n->ai.mid2, &o->ai_mid2); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
935 |
|
0 | 936 |
n->ai.cargo_type = o->ai_cargo_type; |
937 |
n->ai.num_wagons = o->ai_num_wagons; |
|
938 |
n->ai.num_build_rec = o->ai_num_build_rec; |
|
939 |
n->ai.num_loco_to_build = o->ai_num_loco_to_build; |
|
940 |
n->ai.num_want_fullload = o->ai_num_want_fullload; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
941 |
|
0 | 942 |
for(i=0; i!=9; i++) n->ai.wagon_list[i] = o->ai_wagonlist[i]; |
943 |
memcpy(n->ai.order_list_blocks, o->ai_order_list_blocks, 20); |
|
944 |
n->ai.start_tile_a = o->ai_start_tile_a; |
|
945 |
n->ai.start_tile_b = o->ai_start_tile_b; |
|
946 |
n->ai.cur_tile_a = o->ai_cur_tile_a; |
|
947 |
n->ai.cur_tile_b = o->ai_cur_tile_b; |
|
948 |
n->ai.start_dir_a = o->ai_start_dir_a; |
|
949 |
n->ai.start_dir_b = o->ai_start_dir_b; |
|
950 |
n->ai.cur_dir_a = o->ai_cur_dir_a; |
|
951 |
n->ai.cur_dir_b = o->ai_cur_dir_b; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
952 |
|
0 | 953 |
for(i=0; i!=16; i++) { |
954 |
n->ai.banned_tiles[i] = o->banned_tiles[i].tile; |
|
955 |
n->ai.banned_val[i] = o->banned_tiles[i].data; |
|
956 |
} |
|
957 |
||
958 |
n->ai.build_kind = o->ai_build_kind; |
|
959 |
n->ai.route_type_mask = o->ai_route_type_mask; |
|
960 |
n->ai.tick = o->ai_tick; |
|
961 |
||
962 |
n->block_preview = o->block_preview; |
|
963 |
n->max_railtype = (o->max_railtype == 0) ? 1 : o->max_railtype; |
|
964 |
n->location_of_house = o->location_of_house; |
|
965 |
if (o->location_of_house == 0xFFFF) n->location_of_house = 0; |
|
966 |
||
967 |
n->share_owners[0] = o->share_owners[0]; |
|
968 |
n->share_owners[1] = o->share_owners[1]; |
|
969 |
n->share_owners[2] = o->share_owners[2]; |
|
970 |
n->share_owners[3] = o->share_owners[3]; |
|
971 |
||
972 |
if (o->ai_state == 2) { |
|
973 |
n->ai.cur_veh = NULL; |
|
974 |
} |
|
975 |
} while (n++,o++,--num); |
|
976 |
} |
|
977 |
||
978 |
static void FixName(OldName *o, int num) |
|
979 |
{ |
|
980 |
int i; |
|
981 |
for(i=0; i!=num; i++) { |
|
982 |
memcpy(_name_array[i], o[i].name, sizeof(o[i].name)); |
|
983 |
} |
|
984 |
} |
|
985 |
||
986 |
static void FixSign(SignStruct *n, OldSign *o, int num) |
|
987 |
{ |
|
988 |
do { |
|
989 |
n->str = o->text; |
|
990 |
n->x = o->x; |
|
991 |
n->y = o->y; |
|
992 |
n->z = o->z; |
|
993 |
} while (n++,o++,--num); |
|
994 |
} |
|
995 |
||
996 |
static void FixEngine(Engine *n, OldEngine *o, int num) |
|
997 |
{ |
|
998 |
int i = 0; |
|
999 |
||
1000 |
do { |
|
1001 |
n->player_avail = o->player_avail; |
|
1002 |
n->intro_date = o->intro_date; |
|
1003 |
n->age = o->age; |
|
1004 |
if ((i >= 27 && i < 54) || (i >= 57 && i < 84) || (i >= 89 && i < 116)) |
|
1005 |
n->age = 0xffff; |
|
1006 |
n->reliability = o->reliability; |
|
1007 |
n->reliability_spd_dec = o->reliability_spd_dec; |
|
1008 |
n->reliability_start = o->reliability_start; |
|
1009 |
n->reliability_max = o->reliability_max; |
|
1010 |
n->reliability_final = o->reliability_final; |
|
1011 |
n->duration_phase_1 = o->duration_phase_1; |
|
1012 |
n->duration_phase_2 = o->duration_phase_2; |
|
1013 |
n->duration_phase_3 = o->duration_phase_3; |
|
1014 |
n->lifelength = o->lifelength; |
|
1015 |
n->flags = o->flags; |
|
1016 |
n->preview_player = o->preview_player; |
|
1017 |
n->preview_wait = o->preview_wait; |
|
1018 |
n->railtype = o->railtype; |
|
1019 |
} while (n++,o++,i++,--num); |
|
1020 |
} |
|
1021 |
||
1022 |
void FixGameDifficulty(GameDifficulty *n, OldGameSettings *o) |
|
1023 |
{ |
|
1024 |
n->max_no_competitors = o->max_no_competitors; |
|
1025 |
n->competitor_start_time = o->competitor_start_time; |
|
1026 |
n->number_towns = o->number_towns; |
|
1027 |
n->number_industries = o->number_industries; |
|
1028 |
n->max_loan = o->max_loan; |
|
1029 |
n->initial_interest = o->initial_interest; |
|
1030 |
n->vehicle_costs = o->vehicle_costs; |
|
1031 |
n->competitor_speed = o->competitor_speed; |
|
1032 |
n->competitor_intelligence = o->competitor_intelligence; |
|
1033 |
n->vehicle_breakdowns = o->vehicle_breakdowns; |
|
1034 |
n->subsidy_multiplier = o->subsidy_multiplier; |
|
1035 |
n->construction_cost = o->construction_cost; |
|
1036 |
n->terrain_type = o->terrain_type; |
|
1037 |
n->quantity_sea_lakes = o->quantity_sea_lakes; |
|
1038 |
n->economy = o->economy; |
|
1039 |
n->line_reverse_mode = o->line_reverse_mode; |
|
1040 |
n->disasters = o->disasters; |
|
1041 |
} |
|
1042 |
||
1043 |
||
1044 |
// loader for old style savegames |
|
1045 |
bool LoadOldSaveGame(const char *file) |
|
1046 |
{ |
|
1047 |
LoadSavegameState lss; |
|
1048 |
OldMain *m; |
|
1049 |
int i; |
|
1050 |
||
1051 |
_cur_state = &lss; |
|
1052 |
memset(&lss, 0, sizeof(lss)); |
|
1053 |
||
1054 |
lss.fin = fopen(file, "rb"); |
|
1055 |
if (lss.fin == NULL) return false; |
|
1056 |
||
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
1057 |
/* B - byte 8bit (1) |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
1058 |
* W - word 16bit (2 bytes) |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
1059 |
* L - 'long' word 32bit (4 bytes) |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
1060 |
*/ |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
1061 |
fseek(lss.fin, 49, SEEK_SET); // 47B TITLE, W Checksum - Total 49 |
0 | 1062 |
|
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
1063 |
/* Load the file into memory |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
1064 |
* Game Data 0x77179 + L4 (256x256) + L5 (256x256) |
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
1065 |
*/ |
0 | 1066 |
m = (OldMain *)malloc(sizeof(OldMain)); |
1067 |
LoadSavegameBytes(m, sizeof(OldMain)); |
|
1068 |
||
1069 |
// copy sections of it to our datastructures. |
|
1070 |
memcpy(_map_owner, m->map_owner, sizeof(_map_owner)); |
|
1071 |
memcpy(_map2, m->map2, sizeof(_map2)); |
|
1072 |
memcpy(_map_type_and_height, m->map_type_and_height, sizeof(_map_type_and_height)); |
|
1073 |
memcpy(_map5, m->map5, sizeof(_map5)); |
|
1074 |
for(i=0; i!=256*256; i++) { |
|
1075 |
_map3_lo[i] = m->map3[i] & 0xFF; |
|
1076 |
_map3_hi[i] = m->map3[i] >> 8; |
|
1077 |
} |
|
1078 |
memcpy(_map_extra_bits, m->map_extra, sizeof(_map_extra_bits)); |
|
1079 |
||
1080 |
// go through the tables and see if we can find any ttdpatch presignals. Then convert those to our format. |
|
1081 |
for(i=0; i!=256*256; i++) { |
|
1082 |
if (IS_TILETYPE(i, MP_RAILWAY) && (_map5[i] & 0xC0) == 0x40) { |
|
1083 |
// this byte is always zero in real ttd. |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
1084 |
if (_map3_hi[i]) { |
0 | 1085 |
// convert ttdpatch presignal format to openttd presignal format. |
1086 |
_map3_hi[i] = (_map3_hi[i] >> 1) & 7; |
|
1087 |
} |
|
1088 |
} |
|
1089 |
} |
|
1090 |
||
1091 |
memcpy(_order_array, m->order_list, sizeof(m->order_list)); |
|
1092 |
_ptr_to_next_order = _order_array + REMAP_ORDER_IDX(m->ptr_to_next_order); |
|
1093 |
||
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
1094 |
FixTown(_towns, m->town_list, lengthof(m->town_list), m->town_name_type); |
0 | 1095 |
FixIndustry(_industries, m->industries, lengthof(m->industries)); |
1096 |
FixStation(_stations, m->stations, lengthof(m->stations)); |
|
1097 |
||
1098 |
FixDepot(_depots, m->depots, lengthof(m->depots)); |
|
1099 |
FixVehicle(_vehicles, m->vehicles, lengthof(m->vehicles)); |
|
1100 |
FixSubsidy(_subsidies, m->subsidies, lengthof(m->subsidies)); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
1101 |
|
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
1102 |
FixPlayer(_players, m->players, lengthof(m->players), m->town_name_type); |
0 | 1103 |
FixName(m->names, lengthof(m->names)); |
1104 |
FixSign(_sign_list, m->signs, lengthof(m->signs)); |
|
1105 |
FixEngine(_engines, m->engines, lengthof(m->engines)); |
|
1106 |
||
1107 |
_opt.diff_level = m->difficulty_level; |
|
1108 |
_opt.currency = m->currency; |
|
1109 |
_opt.kilometers = m->use_kilometers; |
|
1110 |
_opt.town_name = m->town_name_type; |
|
1111 |
_opt.landscape = m->landscape_type; |
|
1112 |
_opt.snow_line = m->snow_line_height; |
|
1113 |
_opt.autosave = 0; |
|
1114 |
_opt.road_side = m->road_side; |
|
1115 |
FixGameDifficulty(&_opt.diff, &m->game_diff); |
|
1116 |
||
1117 |
// Load globals |
|
1118 |
_date = m->date; |
|
1119 |
_date_fract = m->date_fract; |
|
1120 |
_tick_counter = m->tick_counter; |
|
1121 |
_vehicle_id_ctr_day = m->vehicle_id_ctr_day; |
|
1122 |
_age_cargo_skip_counter = m->age_cargo_skip_counter; |
|
1123 |
_avail_aircraft = m->avail_aircraft; |
|
1124 |
_cur_tileloop_tile = m->cur_tileloop_tile; |
|
1125 |
_disaster_delay = m->disaster_delay; |
|
1126 |
_station_tick_ctr = m->station_tick_ctr; |
|
1127 |
_random_seed_1 = m->seed_1; |
|
1128 |
_random_seed_2 = m->seed_2; |
|
1129 |
_cur_town_ctr = REMAP_TOWN_IDX(m->cur_town_ptr); |
|
1130 |
_cur_player_tick_index = m->cur_player_tick_index; |
|
1131 |
_next_competitor_start = m->next_competitor_start; |
|
1132 |
_trees_tick_ctr = m->trees_tick_ctr; |
|
1133 |
_saved_scrollpos_x = m->saved_main_scrollpos_x; |
|
1134 |
_saved_scrollpos_y = m->saved_main_scrollpos_y; |
|
1135 |
_saved_scrollpos_zoom = m->saved_main_scrollpos_zoom; |
|
1136 |
||
1137 |
// Load economy stuff |
|
1138 |
_economy.max_loan = m->maximum_loan; |
|
1139 |
_economy.max_loan_unround = m->maximum_loan_unround; |
|
1140 |
_economy.fluct = m->economy_fluct; |
|
1141 |
_economy.interest_rate = m->interest_rate; |
|
1142 |
_economy.infl_amount = m->inflation_amount; |
|
1143 |
_economy.infl_amount_pr = m->inflation_amount_payment_rates; |
|
1144 |
||
1145 |
memcpy(_animated_tile_list, m->animated_tile_list, sizeof(m->animated_tile_list)); |
|
1146 |
memcpy(_engine_name_strings, m->engine_name_strings, sizeof(m->engine_name_strings)); |
|
1147 |
||
1148 |
for(i=0; i!=lengthof(m->prices); i++) { |
|
1149 |
((uint32*)&_price)[i] = m->prices[i].price; |
|
1150 |
_price_frac[i] = m->prices[i].frac; |
|
1151 |
} |
|
1152 |
||
1153 |
for(i=0; i!=lengthof(m->cargo_payment_rates); i++) { |
|
1154 |
_cargo_payment_rates[i] = -(int32)m->cargo_payment_rates[i].price; |
|
1155 |
_cargo_payment_rates_frac[i] = m->cargo_payment_rates[i].frac; |
|
1156 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
123
diff
changeset
|
1157 |
|
0 | 1158 |
free(m); |
1159 |
fclose(lss.fin); |
|
1160 |
return true; |
|
1161 |
} |
|
1162 |
||
1163 |
void GetOldSaveGameName(char *title, const char *file) |
|
1164 |
{ |
|
1165 |
FILE *f; |
|
1166 |
||
1167 |
f = fopen(file, "rb"); |
|
1168 |
title[0] = 0; |
|
1169 |
title[48] = 0; |
|
1170 |
||
1171 |
if (!f) return; |
|
1172 |
if (fread(title, 1, 48, f) != 48) title[0] = 0; |
|
1173 |
fclose(f); |
|
1174 |
} |
|
1175 |
||
1176 |
void GetOldScenarioGameName(char *title, const char *file) |
|
1177 |
{ |
|
1178 |
GetOldSaveGameName(title, file); |
|
1179 |
} |