diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index cc2a671a2f..163ded73cd 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2830,18 +2830,6 @@ bool AfterLoadGame() * which is done by StartupEngines(). */ if (gcf_res != GLC_ALL_GOOD) StartupEngines(); - if (IsSavegameVersionBefore(SLV_166)) { - /* Update cargo acceptance map of towns. */ - for (TileIndex t = 0; t < map_size; t++) { - if (!IsTileType(t, MP_HOUSE)) continue; - Town::Get(GetTownIndex(t))->cargo_accepted.Add(t); - } - - for (Town *town : Town::Iterate()) { - UpdateTownCargoes(town); - } - } - /* The road owner of standard road stops was not properly accounted for. */ if (IsSavegameVersionBefore(SLV_172)) { for (TileIndex t = 0; t < map_size; t++) { diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp index cbf7205d07..78765dbdaf 100644 --- a/src/saveload/town_sl.cpp +++ b/src/saveload/town_sl.cpp @@ -13,12 +13,16 @@ #include "../landscape.h" #include "../subsidy_func.h" #include "../strings_func.h" +#include "../tilematrix_type.hpp" #include "saveload.h" #include "newgrf_sl.h" #include "../safeguards.h" +/* TODO: Remove acceptance matrix from the savegame completely. */ +typedef TileMatrix AcceptanceMatrix; + /** * Rebuild all the cached variables of towns. */ @@ -48,9 +52,7 @@ void RebuildTownCaches() /* Update the population and num_house dependent values */ for (Town *town : Town::Iterate()) { UpdateTownRadius(town); - UpdateTownCargoes(town); } - UpdateTownCargoBitmap(); } /** @@ -190,8 +192,8 @@ static const SaveLoad _town_desc[] = { SLE_CONDLST(Town, psa_list, REF_STORAGE, SLV_161, SL_MAX_VERSION), - SLE_CONDVAR(Town, cargo_produced, SLE_FILE_U32 | SLE_VAR_U64, SLV_166, SLV_EXTEND_CARGOTYPES), - SLE_CONDVAR(Town, cargo_produced, SLE_UINT64, SLV_EXTEND_CARGOTYPES, SL_MAX_VERSION), + SLE_CONDNULL(4, SLV_166, SLV_EXTEND_CARGOTYPES), ///< cargo_produced, no longer in use + SLE_CONDNULL(8, SLV_EXTEND_CARGOTYPES, SL_MAX_VERSION), ///< cargo_produced, no longer in use /* reserve extra space in savegame here. (currently 30 bytes) */ SLE_CONDNULL(30, SLV_2, SL_MAX_VERSION), @@ -253,11 +255,9 @@ static void RealSave_Town(Town *t) if (IsSavegameVersionBefore(SLV_166)) return; - 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; - SlArray(t->cargo_accepted.data, arr_len, SLE_UINT32); - } + /* Write an empty matrix to avoid bumping savegame version. */ + AcceptanceMatrix dummy; + SlObject(&dummy, GetTileMatrixDesc()); } static void Save_TOWN() @@ -290,14 +290,12 @@ static void Load_TOWN() if (IsSavegameVersionBefore(SLV_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(arr_len); - SlArray(t->cargo_accepted.data, arr_len, SLE_UINT32); - - /* Rebuild total cargo acceptance. */ - UpdateTownCargoTotal(t); + /* Discard acceptance matrix to avoid bumping savegame version. */ + AcceptanceMatrix dummy; + SlObject(&dummy, GetTileMatrixDesc()); + if (dummy.area.w != 0) { + uint arr_len = dummy.area.w / AcceptanceMatrix::GRID * dummy.area.h / AcceptanceMatrix::GRID; + for (arr_len *= 4; arr_len != 0; arr_len--) SlReadByte(); } } } diff --git a/src/subsidy.cpp b/src/subsidy.cpp index 25651a91ef..0a1af3c666 100644 --- a/src/subsidy.cpp +++ b/src/subsidy.cpp @@ -434,7 +434,7 @@ bool FindSubsidyCargoDestination(CargoID cid, SourceType src_type, SourceID src) CargoArray town_cargo_accepted = GetAcceptanceAroundTiles(dst_town->xy, 1, 1, SUBSIDY_TOWN_CARGO_RADIUS); /* Check if the town can accept this cargo. */ - if (town_cargo_accepted[cid] >= 8) return false; + if (town_cargo_accepted[cid] < 8) return false; dst = dst_town->index; break; diff --git a/src/town.h b/src/town.h index af06fa03c3..3bb9e10d66 100644 --- a/src/town.h +++ b/src/town.h @@ -15,7 +15,6 @@ #include "subsidy_type.h" #include "newgrf_storage.h" #include "cargotype.h" -#include "tilematrix_type.hpp" #include template @@ -24,8 +23,6 @@ struct BuildingCounts { T class_count[HOUSE_CLASS_MAX]; }; -typedef TileMatrix AcceptanceMatrix; - static const uint CUSTOM_TOWN_NUMBER_DIFFICULTY = 4; ///< value for custom town number in difficulty settings static const uint CUSTOM_TOWN_MAX_NUMBER = 5000; ///< this is the maximum number of towns a user can specify in customisation @@ -83,10 +80,6 @@ struct Town : TownPool::PoolItem<&_town_pool> { inline byte GetPercentTransported(CargoID cid) const { return this->supplied[cid].old_act * 256 / (this->supplied[cid].old_max + 1); } - /* Cargo production and acceptance stats. */ - CargoTypes cargo_produced; ///< Bitmap of all cargoes produced by houses in this town. - AcceptanceMatrix cargo_accepted; ///< Bitmap of cargoes accepted by houses for each 4*4 map square of the town. - CargoTypes cargo_accepted_total; ///< NOSAVE: Bitmap of all cargoes accepted by houses in this town. StationList stations_near; ///< NOSAVE: List of nearby stations. uint16 time_until_rebuild; ///< time until we rebuild a house @@ -203,9 +196,6 @@ void ResetHouses(); void ClearTownHouse(Town *t, TileIndex tile); void UpdateTownMaxPass(Town *t); void UpdateTownRadius(Town *t); -void UpdateTownCargoes(Town *t); -void UpdateTownCargoTotal(Town *t); -void UpdateTownCargoBitmap(); CommandCost CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags); Town *ClosestTownFromTile(TileIndex tile, uint threshold); void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags); @@ -313,8 +303,6 @@ static inline uint16 TownTicksToGameTicks(uint16 ticks) { } -extern CargoTypes _town_cargoes_accepted; - RoadType GetTownRoadType(const Town *t); #endif /* TOWN_H */ diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 39dfa7db17..374601cad2 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -55,7 +55,6 @@ #include "safeguards.h" TownID _new_town_id; -CargoTypes _town_cargoes_accepted; ///< Bitmap of all cargoes accepted by houses. /* Initialize the town-pool */ TownPool _town_pool("Town"); @@ -782,85 +781,6 @@ static void ChangeTileOwner_Town(TileIndex tile, Owner old_owner, Owner new_owne /* not used */ } -/** Update the total cargo acceptance of the whole town. - * @param t The town to update. - */ -void UpdateTownCargoTotal(Town *t) -{ - t->cargo_accepted_total = 0; - - const TileArea &area = t->cargo_accepted.GetArea(); - TILE_AREA_LOOP(tile, area) { - if (TileX(tile) % AcceptanceMatrix::GRID == 0 && TileY(tile) % AcceptanceMatrix::GRID == 0) { - t->cargo_accepted_total |= t->cargo_accepted[tile]; - } - } -} - -/** - * Update accepted town cargoes around a specific tile. - * @param t The town to update. - * @param start Update the values around this tile. - * @param update_total Set to true if the total cargo acceptance should be updated. - */ -static void UpdateTownCargoes(Town *t, TileIndex start, bool update_total = true) -{ - CargoArray accepted, produced; - CargoTypes dummy = 0; - - /* Gather acceptance for all houses in an area around the start tile. - * The area is composed of the square the tile is in, extended one square in all - * directions as the coverage area of a single station is bigger than just one square. */ - TileArea area = AcceptanceMatrix::GetAreaForTile(start, 1); - TILE_AREA_LOOP(tile, area) { - if (!IsTileType(tile, MP_HOUSE) || GetTownIndex(tile) != t->index) continue; - - AddAcceptedCargo_Town(tile, accepted, &dummy); - AddProducedCargo_Town(tile, produced); - } - - /* Create bitmap of produced and accepted cargoes. */ - CargoTypes acc = 0; - for (uint cid = 0; cid < NUM_CARGO; cid++) { - if (accepted[cid] >= 8) SetBit(acc, cid); - if (produced[cid] > 0) SetBit(t->cargo_produced, cid); - } - t->cargo_accepted[start] = acc; - - if (update_total) UpdateTownCargoTotal(t); -} - -/** Update cargo acceptance for the complete town. - * @param t The town to update. - */ -void UpdateTownCargoes(Town *t) -{ - t->cargo_produced = 0; - - const TileArea &area = t->cargo_accepted.GetArea(); - if (area.tile == INVALID_TILE) return; - - /* Update acceptance for each grid square. */ - TILE_AREA_LOOP(tile, area) { - if (TileX(tile) % AcceptanceMatrix::GRID == 0 && TileY(tile) % AcceptanceMatrix::GRID == 0) { - UpdateTownCargoes(t, tile, false); - } - } - - /* Update the total acceptance. */ - UpdateTownCargoTotal(t); -} - -/** Updates the bitmap of all cargoes accepted by houses. */ -void UpdateTownCargoBitmap() -{ - _town_cargoes_accepted = 0; - - for (const Town *town : Town::Iterate()) { - _town_cargoes_accepted |= town->cargo_accepted_total; - } -} - static bool GrowTown(Town *t); static void TownTickHandler(Town *t) @@ -2588,7 +2508,6 @@ static bool BuildTownHouse(Town *t, TileIndex tile) MakeTownHouse(tile, t, construction_counter, construction_stage, house, random_bits); UpdateTownRadius(t); UpdateTownGrowthRate(t); - UpdateTownCargoes(t, tile); return true; } @@ -2673,9 +2592,6 @@ void ClearTownHouse(Town *t, TileIndex tile) RemoveNearbyStations(t, tile, hs->building_flags); UpdateTownRadius(t); - - /* Update cargo acceptance. */ - UpdateTownCargoes(t, tile); } /** @@ -3698,10 +3614,8 @@ void TownsMonthlyLoop() UpdateTownGrowth(t); UpdateTownRating(t); UpdateTownUnwanted(t); - UpdateTownCargoes(t); } - UpdateTownCargoBitmap(); } void TownsYearlyLoop()