76 OC_UINT32 = OC_VAR_U32 | OC_FILE_U32, |
76 OC_UINT32 = OC_VAR_U32 | OC_FILE_U32, |
77 |
77 |
78 OC_TILE = OC_VAR_U32 | OC_FILE_U16, |
78 OC_TILE = OC_VAR_U32 | OC_FILE_U16, |
79 |
79 |
80 OC_END = 0 ///< End of the whole chunk, all 32bits set to zero |
80 OC_END = 0 ///< End of the whole chunk, all 32bits set to zero |
81 } OldChunkType; |
81 }; |
82 |
82 |
83 DECLARE_ENUM_AS_BIT_SET(OldChunkType); |
83 DECLARE_ENUM_AS_BIT_SET(OldChunkType); |
84 |
84 |
85 typedef bool OldChunkProc(LoadgameState *ls, int num); |
85 typedef bool OldChunkProc(LoadgameState *ls, int num); |
86 |
86 |
87 typedef struct OldChunks { |
87 struct OldChunks { |
88 OldChunkType type; ///< Type of field |
88 OldChunkType type; ///< Type of field |
89 uint32 amount; ///< Amount of fields |
89 uint32 amount; ///< Amount of fields |
90 |
90 |
91 void *ptr; ///< Pointer where to save the data (may only be set if offset is 0) |
91 void *ptr; ///< Pointer where to save the data (may only be set if offset is 0) |
92 uint offset; ///< Offset from basepointer (may only be set if ptr is NULL) |
92 uint offset; ///< Offset from basepointer (may only be set if ptr is NULL) |
93 OldChunkProc *proc; ///< Pointer to function that is called with OC_CHUNK |
93 OldChunkProc *proc; ///< Pointer to function that is called with OC_CHUNK |
94 } OldChunks; |
94 }; |
95 |
95 |
96 /* If it fails, check lines above.. */ |
96 /* If it fails, check lines above.. */ |
97 assert_compile(sizeof(TileIndex) == 4); |
97 assert_compile(sizeof(TileIndex) == 4); |
98 |
98 |
99 static uint32 _bump_assert_value; |
99 static uint32 _bump_assert_value; |
288 * Begin -- Stuff to fix the savegames to be OpenTTD compatible |
288 * Begin -- Stuff to fix the savegames to be OpenTTD compatible |
289 */ |
289 */ |
290 |
290 |
291 extern uint32 GetOldTownName(uint32 townnameparts, byte old_town_name_type); |
291 extern uint32 GetOldTownName(uint32 townnameparts, byte old_town_name_type); |
292 |
292 |
293 static void FixOldTowns(void) |
293 static void FixOldTowns() |
294 { |
294 { |
295 Town *town; |
295 Town *town; |
296 |
296 |
297 /* Convert town-names if needed */ |
297 /* Convert town-names if needed */ |
298 FOR_ALL_TOWNS(town) { |
298 FOR_ALL_TOWNS(town) { |
372 static uint32 _old_town_index; |
372 static uint32 _old_town_index; |
373 static uint16 _old_string_id; |
373 static uint16 _old_string_id; |
374 static uint16 _old_string_id_2; |
374 static uint16 _old_string_id_2; |
375 static uint16 _old_extra_chunk_nums; |
375 static uint16 _old_extra_chunk_nums; |
376 |
376 |
377 static void ReadTTDPatchFlags(void) |
377 static void ReadTTDPatchFlags() |
378 { |
378 { |
379 int i; |
379 int i; |
380 |
380 |
381 if (_read_ttdpatch_flags) return; |
381 if (_read_ttdpatch_flags) return; |
382 |
382 |
484 if (!LoadChunk(ls, NULL, order_chunk)) return false; |
484 if (!LoadChunk(ls, NULL, order_chunk)) return false; |
485 |
485 |
486 AssignOrder(GetOrder(num), UnpackOldOrder(_old_order)); |
486 AssignOrder(GetOrder(num), UnpackOldOrder(_old_order)); |
487 |
487 |
488 /* Relink the orders to eachother (in TTD(Patch) the orders for one |
488 /* Relink the orders to eachother (in TTD(Patch) the orders for one |
489 vehicle are behind eachother, with OT_NOTHING as indication that |
489 vehicle are behind eachother, with an invalid order (OT_NOTHING) as indication that |
490 it is the last order */ |
490 it is the last order */ |
491 if (num > 0 && GetOrder(num)->type != OT_NOTHING) |
491 if (num > 0 && GetOrder(num)->IsValid()) |
492 GetOrder(num - 1)->next = GetOrder(num); |
492 GetOrder(num - 1)->next = GetOrder(num); |
493 |
493 |
494 return true; |
494 return true; |
495 } |
495 } |
496 |
496 |
1066 |
1066 |
1067 /* We changed the offset of the vehicle types, so fix it |
1067 /* We changed the offset of the vehicle types, so fix it |
1068 * Basically v->type -= 0x10; would suffice, but play safely */ |
1068 * Basically v->type -= 0x10; would suffice, but play safely */ |
1069 switch (v->type) { |
1069 switch (v->type) { |
1070 default: NOT_REACHED(); |
1070 default: NOT_REACHED(); |
1071 case 0x00 /*VEH_Invalid */: v->type = VEH_Invalid; res = LoadChunk(ls, NULL, vehicle_empty_chunk); break; |
1071 case 0x00 /*VEH_INVALID */: v->type = VEH_INVALID; res = LoadChunk(ls, NULL, vehicle_empty_chunk); break; |
1072 case 0x10 /*VEH_Train */: v->type = VEH_Train; res = LoadChunk(ls, &v->u.rail, vehicle_train_chunk); break; |
1072 case 0x10 /*VEH_TRAIN */: v->type = VEH_TRAIN; res = LoadChunk(ls, &v->u.rail, vehicle_train_chunk); break; |
1073 case 0x11 /*VEH_Road */: v->type = VEH_Road; res = LoadChunk(ls, &v->u.road, vehicle_road_chunk); break; |
1073 case 0x11 /*VEH_ROAD */: v->type = VEH_ROAD; res = LoadChunk(ls, &v->u.road, vehicle_road_chunk); break; |
1074 case 0x12 /*VEH_Ship */: v->type = VEH_Ship; res = LoadChunk(ls, &v->u.ship, vehicle_ship_chunk); break; |
1074 case 0x12 /*VEH_SHIP */: v->type = VEH_SHIP; res = LoadChunk(ls, &v->u.ship, vehicle_ship_chunk); break; |
1075 case 0x13 /*VEH_Aircraft*/: v->type = VEH_Aircraft; res = LoadChunk(ls, &v->u.air, vehicle_air_chunk); break; |
1075 case 0x13 /*VEH_AIRCRAFT*/: v->type = VEH_AIRCRAFT; res = LoadChunk(ls, &v->u.air, vehicle_air_chunk); break; |
1076 case 0x14 /*VEH_Special */: v->type = VEH_Special; res = LoadChunk(ls, &v->u.special, vehicle_special_chunk); break; |
1076 case 0x14 /*VEH_SPECIAL */: v->type = VEH_SPECIAL; res = LoadChunk(ls, &v->u.special, vehicle_special_chunk); break; |
1077 case 0x15 /*VEH_Disaster*/: v->type = VEH_Disaster; res = LoadChunk(ls, &v->u.disaster, vehicle_disaster_chunk); break; |
1077 case 0x15 /*VEH_DISASTER*/: v->type = VEH_DISASTER; res = LoadChunk(ls, &v->u.disaster, vehicle_disaster_chunk); break; |
1078 } |
1078 } |
1079 |
1079 |
1080 /* This chunk size should always be 10 bytes */ |
1080 /* This chunk size should always be 10 bytes */ |
1081 if (ls->total_read - temp != 10) { |
1081 if (ls->total_read - temp != 10) { |
1082 DEBUG(oldloader, 0, "Assert failed in VehicleUnion: invalid chunk size"); |
1082 DEBUG(oldloader, 0, "Assert failed in VehicleUnion: invalid chunk size"); |