/** Load industry-type build data. */ static void Load_ITBL() { int index; for (int i = 0; i < NUM_INDUSTRYTYPES; i++) { index = SlIterateArray(); assert(index == i); SlObject(_industry_builder.builddata + i, _industrytype_builder_desc); } index = SlIterateArray(); assert(index == -1); }
static void Load_TOWN() { int index; while ((index = SlIterateArray()) != -1) { Town *t = new (index) Town(); SlObject(t, _town_desc); for (CargoID i = 0; i < NUM_CARGO; i++) { SlObject(&t->supplied[i], _town_supplied_desc); } for (int i = TE_BEGIN; i < TE_END; i++) { SlObject(&t->received[i], _town_received_desc); } if (t->townnamegrfid == 0 && !IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1) && GB(t->townnametype, 11, 5) != 15) { SlErrorCorrupt("Invalid town name generator"); } if (IsSavegameVersionBefore(166)) continue; SlObject(&t->cargo_accepted, GetTileMatrixDesc()); if (t->cargo_accepted.area.w != 0) { uint arr_len = t->cargo_accepted.area.w / AcceptanceMatrix::GRID * t->cargo_accepted.area.h / AcceptanceMatrix::GRID; t->cargo_accepted.data = MallocT<uint32>(arr_len); SlArray(t->cargo_accepted.data, arr_len, SLE_UINT32); /* Rebuild total cargo acceptance. */ UpdateTownCargoTotal(t); } } }
void Load_TOWN() { int index; while ((index = SlIterateArray()) != -1) { Town *t = new (index) Town(); SlObject(t, _town_desc); t->LoadCargoSourceSink(); if (IsSavegameVersionBefore(161)) continue; SlObject(&t->cargo_accepted, GetTileMatrixDesc()); if (t->cargo_accepted.area.w != 0) { uint arr_len = t->cargo_accepted.area.w / AcceptanceMatrix::GRID * t->cargo_accepted.area.h / AcceptanceMatrix::GRID; t->cargo_accepted.data = MallocT<uint32>(arr_len); SlArray(t->cargo_accepted.data, arr_len, SLE_UINT32); /* Rebuild total cargo acceptance. */ UpdateTownCargoTotal(t); } /* Cache the aligned tile index of the centre tile. */ uint town_x = (TileX(t->xy) / AcceptanceMatrix::GRID) * AcceptanceMatrix::GRID; uint town_y = (TileY(t->xy) / AcceptanceMatrix::GRID) * AcceptanceMatrix::GRID; t->xy_aligned= TileXY(town_x, town_y); } }
static void Load_STNN() { int index; while ((index = SlIterateArray()) != -1) { bool waypoint = (SlReadByte() & FACIL_WAYPOINT) != 0; BaseStation *bst = waypoint ? (BaseStation *)new (index) Waypoint() : new (index) Station(); SlObject(bst, waypoint ? _waypoint_desc : _station_desc); if (!waypoint) { Station *st = Station::From(bst); for (CargoID i = 0; i < NUM_CARGO; i++) { SlObject(&st->goods[i], GetGoodsDesc()); } } if (bst->num_specs != 0) { /* Allocate speclist memory when loading a game */ bst->speclist = CallocT<StationSpecList>(bst->num_specs); for (uint i = 0; i < bst->num_specs; i++) { SlObject(&bst->speclist[i], _station_speclist_desc); } } } }
static void Load_NAME() { int index; while ((index = SlIterateArray()) != -1) { SlArray(&_old_name_array[32 * index], SlGetFieldLength(), SLE_UINT8); } }
static void Load_GOAL() { int index; while ((index = SlIterateArray()) != -1) { Goal *s = new (index) Goal(); SlObject(s, _goals_desc); } }
static void Load_OBJS() { int index; while ((index = SlIterateArray()) != -1) { Object *o = new (index) Object(); SlObject(o, _object_desc); } }
static void Load_CAPY() { int index; while ((index = SlIterateArray()) != -1) { CargoPayment *cp = new (index) CargoPayment(); SlObject(cp, _cargopayment_desc); } }
static void Load_EIDS() { _engine_mngr.Clear(); while (SlIterateArray() != -1) { EngineIDMapping *eid = _engine_mngr.Append(); SlObject(eid, _engine_id_mapping_desc); } }
static void Load_AIPL() { /* Free all current data */ for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { AIConfig::GetConfig(c, AIConfig::SSS_FORCE_GAME)->Change(NULL); } CompanyID index; while ((index = (CompanyID)SlIterateArray()) != (CompanyID)-1) { if (index >= MAX_COMPANIES) SlErrorCorrupt("Too many AI configs"); _ai_saveload_is_random = 0; _ai_saveload_version = -1; SlObject(NULL, _ai_company); if (_networking && !_network_server) { if (Company::IsValidAiID(index)) AIInstance::LoadEmpty(); continue; } AIConfig *config = AIConfig::GetConfig(index, AIConfig::SSS_FORCE_GAME); if (StrEmpty(_ai_saveload_name)) { /* A random AI. */ config->Change(NULL, -1, false, true); } else { config->Change(_ai_saveload_name, _ai_saveload_version, false, _ai_saveload_is_random); if (!config->HasScript()) { /* No version of the AI available that can load the data. Try to load the * latest version of the AI instead. */ config->Change(_ai_saveload_name, -1, false, _ai_saveload_is_random); if (!config->HasScript()) { if (strcmp(_ai_saveload_name, "%_dummy") != 0) { DEBUG(script, 0, "The savegame has an AI by the name '%s', version %d which is no longer available.", _ai_saveload_name, _ai_saveload_version); DEBUG(script, 0, "A random other AI will be loaded in its place."); } else { DEBUG(script, 0, "The savegame had no AIs available at the time of saving."); DEBUG(script, 0, "A random available AI will be loaded now."); } } else { DEBUG(script, 0, "The savegame has an AI by the name '%s', version %d which is no longer available.", _ai_saveload_name, _ai_saveload_version); DEBUG(script, 0, "The latest version of that AI has been loaded instead, but it'll not get the savegame data as it's incompatible."); } /* Make sure the AI doesn't get the saveload data, as he was not the * writer of the saveload data in the first place */ _ai_saveload_version = -1; } } config->StringToSettings(_ai_saveload_settings); /* Start the AI directly if it was active in the savegame */ if (Company::IsValidAiID(index)) { AI::StartNew(index, false); AI::Load(index, _ai_saveload_version); } } }
static void Load_GRPS() { int index; while ((index = SlIterateArray()) != -1) { Group *g = new (index) Group(); SlObject(g, _group_desc); } }
/** Load persistent storage data. */ static void Load_PSAC() { int index; while ((index = SlIterateArray()) != -1) { assert(PersistentStorage::CanAllocateItem()); PersistentStorage *ps = new (index) PersistentStorage(0); SlObject(ps, _storage_desc); } }
static void Load_NGRF_common(GRFConfig *&grfconfig) { ClearGRFConfigList(&grfconfig); while (SlIterateArray() != -1) { GRFConfig *c = new GRFConfig(); SlObject(c, _grfconfig_desc); if (IsSavegameVersionBefore(101)) c->SetSuitablePalette(); AppendToGRFConfigList(&grfconfig, c); } }
static void Load_ROADSTOP() { int index; while ((index = SlIterateArray()) != -1) { RoadStop *rs = new (index) RoadStop(INVALID_TILE); SlObject(rs, _roadstop_desc); } }
static void Load_ENGN() { /* As engine data is loaded before engines are initialized we need to load * this information into a temporary array. This is then copied into the * engine pool after processing NewGRFs by CopyTempEngineData(). */ int index; while ((index = SlIterateArray()) != -1) { Engine *e = GetTempDataEngine(index); SlObject(e, _engine_desc); } }
static void Load_DEPT() { int index; while ((index = SlIterateArray()) != -1) { Depot *depot = new (index) Depot(); SlObject(depot, _depot_desc); /* Set the town 'pointer' so we can restore it later. */ if (IsSavegameVersionBefore(141)) depot->town = (Town *)(size_t)_town_index; } }
static void Load_RAIL() { _railtype_list.Clear(); LabelObject lo; int index; while ((index = SlIterateArray()) != -1) { SlObject(&lo, _label_object_desc); *_railtype_list.Append() = (RailTypeLabel)lo.label; } }
static void Load_INDY() { int index; Industry::ResetIndustryCounts(); while ((index = SlIterateArray()) != -1) { Industry *i = new (index) Industry(); SlObject(i, _industry_desc); Industry::IncIndustryTypeCount(i->type); } }
static void Load_AIPL() { CompanyID index; while ((index = (CompanyID)SlIterateArray()) != (CompanyID)-1) { SlObject(NULL, _ai_company); if (!Company::IsValidAiID(index)) continue; SlObject(NULL, _ai_byte); /* Check if there was anything saved at all. */ if (_ai_sl_byte == 0) continue; LoadObjects(); } }
/** * Load the NAME chunk. */ static void Load_NAME() { int index; while ((index = SlIterateArray()) != -1) { if (index >= NUM_OLD_STRINGS) SlErrorCorrupt("Invalid old name index"); if (SlGetFieldLength() > (uint)LEN_OLD_STRINGS) SlErrorCorrupt("Invalid old name length"); SlArray(&_old_name_array[LEN_OLD_STRINGS * index], SlGetFieldLength(), SLE_UINT8); /* Make sure the old name is null terminated */ _old_name_array[LEN_OLD_STRINGS * index + LEN_OLD_STRINGS - 1] = '\0'; } }
/** * Load a GRF ID + local id -> OpenTTD's id mapping. * @param mapping The mapping to load. */ void Load_NewGRFMapping(OverrideManagerBase &mapping) { /* Clear the current mapping stored. * This will create the manager if ever it is not yet done */ mapping.ResetMapping(); uint max_id = mapping.GetMaxMapping(); int index; while ((index = SlIterateArray()) != -1) { if ((uint)index >= max_id) break; SlObject(&mapping.mapping_ID[index], _newgrf_mapping_desc); } }
/** * Load all link graphs. */ static void Load_LGRP() { int index; while ((index = SlIterateArray()) != -1) { if (!LinkGraph::CanAllocateItem()) { /* Impossible as they have been present in previous game. */ NOT_REACHED(); } LinkGraph *lg = new (index) LinkGraph(); SlObject(lg, GetLinkGraphDesc()); lg->Init(_num_nodes); SaveLoad_LinkGraph(*lg); } }
static void Load_WAYP() { /* Precaution for when loading failed and it didn't get cleared */ _old_waypoints.Clear(); int index; while ((index = SlIterateArray()) != -1) { OldWaypoint *wp = _old_waypoints.Append(); memset(wp, 0, sizeof(*wp)); wp->index = index; SlObject(wp, _old_waypoint_desc); } }
static void Load_STORY_PAGE() { int index; uint32 max_sort_value = 0; while ((index = SlIterateArray()) != -1) { StoryPage *s = new (index) StoryPage(); SlObject(s, _story_pages_desc); if (s->sort_value > max_sort_value) { max_sort_value = s->sort_value; } } /* Update the next sort value, so that the next * created page is shown after all existing pages. */ _story_page_next_sort_value = max_sort_value + 1; }
/** * Load all link graph jobs. */ static void Load_LGRJ() { int index; while ((index = SlIterateArray()) != -1) { if (!LinkGraphJob::CanAllocateItem()) { /* Impossible as they have been present in previous game. */ NOT_REACHED(); } LinkGraphJob *lgj = new (index) LinkGraphJob(); SlObject(lgj, GetLinkGraphJobDesc()); LinkGraph &lg = const_cast<LinkGraph &>(lgj->Graph()); SlObject(&lg, GetLinkGraphDesc()); lg.Init(_num_nodes); SaveLoad_LinkGraph(lg); } }
static void Load_ERNW() { int index; while ((index = SlIterateArray()) != -1) { EngineRenew *er = new (index) EngineRenew(); SlObject(er, _engine_renew_desc); /* Advanced vehicle lists, ungrouped vehicles got added */ if (IsSavegameVersionBefore(SLV_60)) { er->group_id = ALL_GROUP; } else if (IsSavegameVersionBefore(SLV_71)) { if (er->group_id == DEFAULT_GROUP) er->group_id = ALL_GROUP; } } }
/** Load all signs */ static void Load_SIGN() { int index; while ((index = SlIterateArray()) != -1) { Sign *si = new (index) Sign(); SlObject(si, _sign_desc); /* Before version 6.1, signs didn't have owner. * Before version 83, invalid signs were determined by si->str == 0. * Before version 103, owner could be a bankrupted company. * - we can't use IsValidCompany() now, so this is fixed in AfterLoadGame() * All signs that were saved are valid (including those with just 'Sign' and INVALID_OWNER). * - so set owner to OWNER_NONE if needed (signs from pre-version 6.1 would be lost) */ if (IsSavegameVersionBefore(6, 1) || (IsSavegameVersionBefore(83) && si->owner == INVALID_OWNER)) { si->owner = OWNER_NONE; } } }
static void Load_ENGN() { /* As engine data is loaded before engines are initialized we need to load * this information into a temporary array. This is then copied into the * engine pool after processing NewGRFs by CopyTempEngineData(). */ int index; while ((index = SlIterateArray()) != -1) { Engine *e = GetTempDataEngine(index); SlObject(e, _engine_desc); if (IsSavegameVersionBefore(179)) { /* preview_company_rank was replaced with preview_company and preview_asked. * Just cancel any previews. */ e->flags &= ~4; // ENGINE_OFFER_WINDOW_OPEN e->preview_company = INVALID_COMPANY; e->preview_asked = (CompanyMask)-1; } } }
static void Load_INDY() { int index; Industry::ResetIndustryCounts(); while ((index = SlIterateArray()) != -1) { Industry *i = new (index) Industry(); SlObject(i, _industry_desc); /* Before savegame version 161, persistent storages were not stored in a pool. */ if (IsSavegameVersionBefore(161) && !IsSavegameVersionBefore(76)) { /* Store the old persistent storage. The GRFID will be added later. */ assert(PersistentStorage::CanAllocateItem()); i->psa = new PersistentStorage(0, 0, 0); memcpy(i->psa->storage, _old_ind_persistent_storage.storage, sizeof(i->psa->storage)); } Industry::IncIndustryTypeCount(i->type); } }
static void Load_STNS() { int index; while ((index = SlIterateArray()) != -1) { Station *st = new (index) Station(); SlObject(st, _old_station_desc); _waiting_acceptance = 0; uint num_cargo = CheckSavegameVersion(55) ? 12 : NUM_CARGO; for (CargoID i = 0; i < num_cargo; i++) { GoodsEntry *ge = &st->goods[i]; SlObject(ge, GetGoodsDesc()); if (CheckSavegameVersion(68)) { SB(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1, HasBit(_waiting_acceptance, 15)); if (GB(_waiting_acceptance, 0, 12) != 0) { /* In old versions, enroute_from used 0xFF as INVALID_STATION */ StationID source = (CheckSavegameVersion(7) && _cargo_source == 0xFF) ? INVALID_STATION : _cargo_source; /* Don't construct the packet with station here, because that'll fail with old savegames */ ge->cargo.Append(new CargoPacket(GB(_waiting_acceptance, 0, 12), _cargo_days, source, _cargo_source_xy, _cargo_source_xy, _cargo_feeder_share)); SB(ge->acceptance_pickup, GoodsEntry::PICKUP, 1, 1); } } } if (st->num_specs != 0) { /* Allocate speclist memory when loading a game */ st->speclist = CallocT<StationSpecList>(st->num_specs); for (uint i = 0; i < st->num_specs; i++) { SlObject(&st->speclist[i], _station_speclist_desc); } } } }