# oldloader_sl.cpp File Reference

Chunks and fix-ups for TTO/TTD/TTDP savegames. More...

`#include "../stdafx.h"`
`#include "../town.h"`
`#include "../industry.h"`
`#include "../company_func.h"`
`#include "../aircraft.h"`
`#include "../roadveh.h"`
`#include "../ship.h"`
`#include "../train.h"`
`#include "../signs_base.h"`
`#include "../debug.h"`
`#include "../depot_base.h"`
`#include "../newgrf_config.h"`
`#include "../zoom_func.h"`
`#include "../date_func.h"`
`#include "../vehicle_func.h"`
`#include "../variables.h"`
`#include "../effectvehicle_base.h"`
`#include "../core/mem_func.hpp"`
`#include "../core/alloc_type.hpp"`
`#include "saveload_internal.h"`
`#include "oldloader.h"`
`#include "table/strings.h"`
`#include "../table/engines.h"`
`#include "../table/namegen.h"`

Go to the source code of this file.

## Defines
#define | FIXNUM(x, y, z) (((((x) << 16) / (y)) + 1) << z)
## Functions
void | FixOldMapArray ()
static void | FixTTDMapArray ()
static void | FixTTDDepots ()
static uint32 | RemapOldTownName (uint32 townnameparts, byte old_town_name_type)
void | FixOldTowns ()
void | FixOldVehicles ()
static bool | FixTTOMapArray ()
static bool | FixTTOEngines ()
static void | FixTTOCompanies ()
static byte | RemapTTOColour (byte tto)
static uint | RemapTownIndex (uint x)
static uint | RemapOrderIndex (uint x)
static void | ReadTTDPatchFlags ()
static bool | LoadOldTown (LoadgameState *ls, int num)
static bool | LoadOldOrder (LoadgameState *ls, int num)
static bool | LoadOldAnimTileList (LoadgameState *ls, int num)
static bool | LoadOldDepot (LoadgameState *ls, int num)
static bool | LoadOldPrice (LoadgameState *ls, int num)
static bool | LoadOldCargoPaymentRate (LoadgameState *ls, int num)
static bool | LoadOldGood (LoadgameState *ls, int num)
static bool | LoadOldStation (LoadgameState *ls, int num)
static bool | LoadOldIndustry (LoadgameState *ls, int num)
static bool | LoadOldCompanyYearly (LoadgameState *ls, int num)
static bool | LoadOldCompanyEconomy (LoadgameState *ls, int num)
static bool | LoadOldCompany (LoadgameState *ls, int num)
static bool | LoadOldVehicleUnion (LoadgameState *ls, int num)
bool | LoadOldVehicle (LoadgameState *ls, int num)
static bool | LoadOldSign (LoadgameState *ls, int num)
static bool | LoadOldEngine (LoadgameState *ls, int num)
static bool | LoadOldEngineName (LoadgameState *ls, int num)
static bool | LoadOldSubsidy (LoadgameState *ls, int num)
static bool | LoadOldGameDifficulty (LoadgameState *ls, int num)
static bool | LoadOldMapPart1 (LoadgameState *ls, int num)
static bool | LoadOldMapPart2 (LoadgameState *ls, int num)
static bool | LoadTTDPatchExtraChunks (LoadgameState *ls, int num)
bool | LoadTTDMain (LoadgameState *ls)
bool | LoadTTOMain (LoadgameState *ls)
## Variables
static bool | _read_ttdpatch_flags
static uint8 * | _old_map3
StringID * | _old_vehicle_names
static Engine * | _old_engines
TileIndex * | _animated_tile_list
| The table/list with animated tiles.
uint | _animated_tile_count
| The number of animated tiles in the current state.
char * | _old_name_array
| Location to load the old names to.
static byte | _old_vehicle_multiplier
static uint32 | _old_town_index
static uint16 | _old_string_id
static uint16 | _old_string_id_2
static uint16 | _old_extra_chunk_nums
static const OldChunks | town_chunk []
static uint16 | _old_order
static const OldChunks | order_chunk []
static const OldChunks | depot_chunk []
static int32 | _old_price
static uint16 | _old_price_frac
static const OldChunks | price_chunk []
static const OldChunks | cargo_payment_rate_chunk []
static StationID | _current_station_id
static uint16 | _waiting_acceptance
static uint8 | _cargo_source
static uint8 | _cargo_days
static const OldChunks | goods_chunk []
static const OldChunks | station_chunk []
static const OldChunks | industry_chunk []
static CompanyID | _current_company_id
static int32 | _old_yearly
static const OldChunks | _company_yearly_chunk []
static const OldChunks | _company_economy_chunk []
static const OldChunks | _company_chunk []
static uint32 | _old_order_ptr
static uint16 | _old_next_ptr
static VehicleID | _current_vehicle_id
static const OldChunks | vehicle_train_chunk []
static const OldChunks | vehicle_road_chunk []
static const OldChunks | vehicle_ship_chunk []
static const OldChunks | vehicle_air_chunk []
static const OldChunks | vehicle_effect_chunk []
static const OldChunks | vehicle_disaster_chunk []
static const OldChunks | vehicle_empty_chunk []
static uint16 | _cargo_count
static const OldChunks | vehicle_chunk []
static const OldChunks | sign_chunk []
static const OldChunks | engine_chunk []
static const OldChunks | subsidy_chunk []
static const OldChunks | game_difficulty_chunk []
TileIndex | _cur_tileloop_tile
static const OldChunks | main_chunk []

## Detailed Description

Chunks and fix-ups for TTO/TTD/TTDP savegames.

TTO loader code is based on SVXConverter by Roman Vetter.

Definition in file oldloader_sl.cpp.

## Function Documentation

static void FixTTDDepots | ( |  | ) | `[static]`

Workaround for SVXConverter bug, depots 252-255 could be invalid

Definition at line 99 of file oldloader_sl.cpp.

References IsRailDepotTile().

static bool FixTTOEngines | ( |  | ) | `[static]`

TTD->TTO remapping of engines; 255 means there is no equivalent. SVXConverter uses (almost) the same table.

TTO->TTD remapping of engines. SVXConverter uses the same table.

Definition at line 326 of file oldloader_sl.cpp.

References _date, ConvertYMDToDate(), DAYS_TILL_ORIGINAL_BASE_YEAR, ENGINE_AVAILABLE, HasBit(), lengthof, and min().

static byte RemapTTOColour | ( | byte | tto | ) | `[inline, static]`

Lossy remapping of TTO colours to TTD colours. SVXConverter uses the same conversion.

Definition at line 439 of file oldloader_sl.cpp.

References lengthof.

## Variable Documentation

uint _animated_tile_count

The number of animated tiles in the current state.

Definition at line 12 of file animated_tile.cpp.

Referenced by AddAnimatedTile(), AnimateAnimatedTiles(), DeleteAnimatedTile(), InitializeAnimatedTiles(), Load_ANIT(), and Save_ANIT().

TileIndex* _animated_tile_list

The table/list with animated tiles.

Definition at line 10 of file animated_tile.cpp.

Referenced by AddAnimatedTile(), AnimateAnimatedTiles(), DeleteAnimatedTile(), InitializeAnimatedTiles(), Load_ANIT(), and Save_ANIT().

const OldChunks _company_economy_chunk[]`[static]`

Initial value:

     {
      OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, CompanyEconomyEntry, income ),
      OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, CompanyEconomyEntry, expenses ),
      OCL_SVAR( OC_INT32,                 CompanyEconomyEntry, delivered_cargo ),
      OCL_SVAR( OC_INT32,                 CompanyEconomyEntry, performance_history ),
      OCL_SVAR( OC_TTD | OC_FILE_I32 | OC_VAR_I64, CompanyEconomyEntry, company_value ),

    }

Definition at line 930 of file oldloader_sl.cpp.

const OldChunks _company_yearly_chunk[]`[static]`

Initial value:

     {
      OCL_VAR(  OC_INT32,   1, &_old_yearly ),

    }

Definition at line 908 of file oldloader_sl.cpp.

char* _old_name_array

Location to load the old names to.

Definition at line 39 of file strings_sl.cpp.

Referenced by CopyFromOldName(), InitializeOldNames(), and ResetOldNames().

const OldChunks cargo_payment_rate_chunk[]`[static]`

Initial value:

     {
      OCL_VAR (  OC_INT32,   1, &_old_price ),
      OCL_VAR ( OC_UINT16,   1, &_old_price_frac ),

      OCL_NULL( 2 ),

    }

Definition at line 686 of file oldloader_sl.cpp.

const OldChunks depot_chunk[]`[static]`

Initial value:

     {
      OCL_SVAR(   OC_TILE, Depot, xy ),
      OCL_VAR ( OC_UINT32,                1, &_old_town_index ),

    }

Definition at line 632 of file oldloader_sl.cpp.

const OldChunks engine_chunk[]`[static]`

Initial value:

     {
      OCL_SVAR( OC_UINT16, Engine, company_avail ),
      OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Engine, intro_date ),
      OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Engine, age ),
      OCL_SVAR( OC_UINT16, Engine, reliability ),
      OCL_SVAR( OC_UINT16, Engine, reliability_spd_dec ),
      OCL_SVAR( OC_UINT16, Engine, reliability_start ),
      OCL_SVAR( OC_UINT16, Engine, reliability_max ),
      OCL_SVAR( OC_UINT16, Engine, reliability_final ),
      OCL_SVAR( OC_UINT16, Engine, duration_phase_1 ),
      OCL_SVAR( OC_UINT16, Engine, duration_phase_2 ),
      OCL_SVAR( OC_UINT16, Engine, duration_phase_3 ),

      OCL_SVAR(  OC_UINT8, Engine, lifelength ),
      OCL_SVAR(  OC_UINT8, Engine, flags ),
      OCL_SVAR(  OC_UINT8, Engine, preview_company_rank ),
      OCL_SVAR(  OC_UINT8, Engine, preview_wait ),

      OCL_CNULL( OC_TTD, 2 ),

    }

Definition at line 1417 of file oldloader_sl.cpp.

const OldChunks game_difficulty_chunk[]`[static]`

Initial value:

     {
      OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, max_no_competitors ),
      OCL_NULL( 2),
      OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, number_towns ),
      OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, number_industries ),
      OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, DifficultySettings, max_loan ),
      OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, initial_interest ),
      OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, vehicle_costs ),
      OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, competitor_speed ),
      OCL_NULL( 2),
      OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, vehicle_breakdowns ),
      OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, subsidy_multiplier ),
      OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, construction_cost ),
      OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, terrain_type ),
      OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, quantity_sea_lakes ),
      OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, economy ),
      OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, line_reverse_mode ),
      OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, disasters ),

    }

Definition at line 1467 of file oldloader_sl.cpp.

const OldChunks goods_chunk[]`[static]`

Initial value:

     {
      OCL_VAR ( OC_UINT16, 1,          &_waiting_acceptance ),
      OCL_SVAR(  OC_UINT8, GoodsEntry, days_since_pickup ),
      OCL_SVAR(  OC_UINT8, GoodsEntry, rating ),
      OCL_VAR (  OC_UINT8, 1,          &_cargo_source ),
      OCL_VAR (  OC_UINT8, 1,          &_cargo_days ),
      OCL_SVAR(  OC_UINT8, GoodsEntry, last_speed ),
      OCL_SVAR(  OC_UINT8, GoodsEntry, last_age ),

    }

Definition at line 727 of file oldloader_sl.cpp.

const OldChunks order_chunk[]`[static]`

Initial value:

     {
      OCL_VAR ( OC_UINT16,   1, &_old_order ),

    }

Definition at line 588 of file oldloader_sl.cpp.

const OldChunks price_chunk[]`[static]`

Initial value:

     {
      OCL_VAR (  OC_INT32,   1, &_old_price ),
      OCL_VAR ( OC_UINT16,   1, &_old_price_frac ),

    }

Definition at line 654 of file oldloader_sl.cpp.

const OldChunks sign_chunk[]`[static]`

Initial value:

     {
      OCL_VAR ( OC_UINT16, 1, &_old_string_id ),
      OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Sign, x ),
      OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Sign, y ),
      OCL_SVAR( OC_FILE_U16 | OC_VAR_I8, Sign, z ),

      OCL_NULL( 6 ),

    }

Definition at line 1389 of file oldloader_sl.cpp.

const OldChunks subsidy_chunk[]`[static]`

Initial value:

     {
      OCL_SVAR(  OC_UINT8, Subsidy, cargo_type ),
      OCL_SVAR(  OC_UINT8, Subsidy, age ),
      OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, Subsidy, from ),
      OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, Subsidy, to ),

    }

Definition at line 1453 of file oldloader_sl.cpp.

const OldChunks vehicle_air_chunk[]`[static]`

Initial value:

     {
      OCL_SVAR(  OC_UINT8, VehicleAir, pos ),
      OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, VehicleAir, targetairport ),
      OCL_SVAR( OC_UINT16, VehicleAir, crashed_counter ),
      OCL_SVAR(  OC_UINT8, VehicleAir, state ),

      OCL_NULL( 5 ),

    }

Definition at line 1109 of file oldloader_sl.cpp.

const OldChunks vehicle_disaster_chunk[]`[static]`

Initial value:

     {
      OCL_SVAR( OC_UINT16, VehicleDisaster, image_override ),
      OCL_SVAR( OC_UINT16, VehicleDisaster, big_ufo_destroyer_target ),

      OCL_NULL( 6 ),

    }

Definition at line 1129 of file oldloader_sl.cpp.

const OldChunks vehicle_effect_chunk[]`[static]`

Initial value:

     {
      OCL_SVAR( OC_UINT16, VehicleEffect, animation_state ),
      OCL_SVAR(  OC_UINT8, VehicleEffect, animation_substate ),

      OCL_NULL( 7 ),

    }

Definition at line 1120 of file oldloader_sl.cpp.

const OldChunks vehicle_empty_chunk[]`[static]`

Initial value:

     {
      OCL_NULL( 10 ),

    }

Definition at line 1138 of file oldloader_sl.cpp.

const OldChunks vehicle_road_chunk[]`[static]`

Initial value:

     {
      OCL_SVAR(  OC_UINT8, VehicleRoad, state ),
      OCL_SVAR(  OC_UINT8, VehicleRoad, frame ),
      OCL_SVAR( OC_UINT16, VehicleRoad, blocked_ctr ),
      OCL_SVAR(  OC_UINT8, VehicleRoad, overtaking ),
      OCL_SVAR(  OC_UINT8, VehicleRoad, overtaking_ctr ),
      OCL_SVAR( OC_UINT16, VehicleRoad, crashed_ctr ),
      OCL_SVAR(  OC_UINT8, VehicleRoad, reverse_ctr ),

      OCL_NULL( 1 ),

    }

Definition at line 1087 of file oldloader_sl.cpp.

const OldChunks vehicle_ship_chunk[]`[static]`

Initial value:

     {
      OCL_SVAR(  OC_UINT8, VehicleShip, state ),

      OCL_NULL( 9 ),

    }

Definition at line 1101 of file oldloader_sl.cpp.

const OldChunks vehicle_train_chunk[]`[static]`

Initial value:

     {
      OCL_SVAR(  OC_UINT8, VehicleRail, track ),
      OCL_SVAR(  OC_UINT8, VehicleRail, force_proceed ),
      OCL_SVAR( OC_UINT16, VehicleRail, crash_anim_pos ),
      OCL_SVAR(  OC_UINT8, VehicleRail, railtype ),

      OCL_NULL( 5 ),

    }

Definition at line 1076 of file oldloader_sl.cpp.