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