From 63f1c2aa3a166ff3eb8f6af929244e33d04e7eb5 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 8 Jun 2025 20:46:58 +0100 Subject: [PATCH] Codechange: Use TypedIndexContainer for typed index containers Instead of ReferenceThroughBaseContainer --- src/company_cmd.cpp | 2 +- src/company_func.h | 2 +- src/economy.cpp | 2 +- src/economy_func.h | 2 +- src/game/game_text.hpp | 6 +++--- src/linkgraph/mcf.cpp | 2 +- src/network/network_func.h | 2 +- src/newgrf.cpp | 2 +- src/newgrf/newgrf_internal_vehicle.h | 2 +- src/newgrf_text.cpp | 2 +- src/pathfinder/water_regions.cpp | 4 ++-- src/saveload/engine_sl.cpp | 4 ++-- src/script/api/script_object.hpp | 2 +- src/settings_type.h | 2 +- src/smallmap_gui.cpp | 2 +- src/station_cmd.cpp | 4 ++-- src/town.h | 4 ++-- 17 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index b83d08d8e5..6399a34cc1 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -52,7 +52,7 @@ void UpdateObjectColours(const Company *c); CompanyID _local_company; ///< Company controlled by the human player at this client. Can also be #COMPANY_SPECTATOR. CompanyID _current_company; ///< Company currently doing an action. -ReferenceThroughBaseContainer> _company_colours; ///< NOSAVE: can be determined from company structs. +TypedIndexContainer, CompanyID> _company_colours; ///< NOSAVE: can be determined from company structs. CompanyManagerFace _company_manager_face; ///< for company manager face storage in openttd.cfg uint _cur_company_tick_index; ///< used to generate a name for one company that doesn't have a name yet per tick diff --git a/src/company_func.h b/src/company_func.h index 4e6029cc15..deddcd4b60 100644 --- a/src/company_func.h +++ b/src/company_func.h @@ -36,7 +36,7 @@ CommandCost CheckTileOwnership(TileIndex tile); extern CompanyID _local_company; extern CompanyID _current_company; -extern ReferenceThroughBaseContainer> _company_colours; +extern TypedIndexContainer, CompanyID> _company_colours; extern CompanyManagerFace _company_manager_face; PaletteID GetCompanyPalette(CompanyID company); diff --git a/src/economy.cpp b/src/economy.cpp index 9d428bc07c..03ed9a9053 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -101,7 +101,7 @@ const ScoreInfo _score_info[] = { { 0, 0} // SCORE_TOTAL }; -ReferenceThroughBaseContainer, MAX_COMPANIES>> _score_part; +TypedIndexContainer, MAX_COMPANIES>, CompanyID> _score_part; Economy _economy; Prices _price; static PriceMultipliers _price_base_multiplier; diff --git a/src/economy_func.h b/src/economy_func.h index e85e36bdb0..e199af3c90 100644 --- a/src/economy_func.h +++ b/src/economy_func.h @@ -23,7 +23,7 @@ void ResetPriceBaseMultipliers(); void SetPriceBaseMultiplier(Price price, int factor); extern const ScoreInfo _score_info[]; -extern ReferenceThroughBaseContainer, MAX_COMPANIES>> _score_part; +extern TypedIndexContainer, MAX_COMPANIES>, CompanyID> _score_part; extern Economy _economy; /* Prices and also the fractional part. */ extern Prices _price; diff --git a/src/game/game_text.hpp b/src/game/game_text.hpp index ada1a3824a..76a08a2db3 100644 --- a/src/game/game_text.hpp +++ b/src/game/game_text.hpp @@ -39,7 +39,7 @@ void ReconsiderGameScriptLanguage(); /** Container for the raw (unencoded) language strings of a language. */ struct LanguageStrings { std::string language; ///< Name of the language (base filename). Empty string if invalid. - ReferenceThroughBaseContainer lines; ///< The lines of the file to pass into the parser/encoder. + TypedIndexContainer lines; ///< The lines of the file to pass into the parser/encoder. LanguageStrings() {} LanguageStrings(const std::string &lang) : language(lang) {} @@ -56,8 +56,8 @@ struct GameStrings { std::vector raw_strings; ///< The raw strings per language, first must be English/the master language!. std::vector compiled_strings; ///< The compiled strings per language, first must be English/the master language!. - ReferenceThroughBaseContainer string_names; ///< The names of the compiled strings. - ReferenceThroughBaseContainer string_params; ///< The parameters for the strings. + TypedIndexContainer string_names; ///< The names of the compiled strings. + TypedIndexContainer string_params; ///< The parameters for the strings. void Compile(); diff --git a/src/linkgraph/mcf.cpp b/src/linkgraph/mcf.cpp index ef8ea4966b..490ab9168c 100644 --- a/src/linkgraph/mcf.cpp +++ b/src/linkgraph/mcf.cpp @@ -134,7 +134,7 @@ private: LinkGraphJob &job; ///< Link graph job we're working with. /** Lookup table for getting NodeIDs from StationIDs. */ - ReferenceThroughBaseContainer> station_to_node; + TypedIndexContainer, StationID> station_to_node; /** Current iterator in the shares map. */ FlowStat::SharesMap::const_iterator it; diff --git a/src/network/network_func.h b/src/network/network_func.h index 57309d4438..40a6bc8a4c 100644 --- a/src/network/network_func.h +++ b/src/network/network_func.h @@ -45,7 +45,7 @@ void NetworkDisconnect(bool close_admins = true); void NetworkGameLoop(); void NetworkBackgroundLoop(); std::string_view ParseFullConnectionString(std::string_view connection_string, uint16_t &port, CompanyID *company_id = nullptr); -using NetworkCompanyStatsArray = ReferenceThroughBaseContainer>; +using NetworkCompanyStatsArray = TypedIndexContainer, CompanyID>; NetworkCompanyStatsArray NetworkGetCompanyStats(); void NetworkUpdateClientInfo(ClientID client_id); diff --git a/src/newgrf.cpp b/src/newgrf.cpp index f1bb512784..c1d9904ad2 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -74,7 +74,7 @@ GRFLoadedFeatures _loaded_newgrf_features; GrfProcessingState _cur_gps; -ReferenceThroughBaseContainer> _gted; ///< Temporary engine data used during NewGRF loading +TypedIndexContainer, EngineID> _gted; ///< Temporary engine data used during NewGRF loading /** * Debug() function dedicated to newGRF debugging messages diff --git a/src/newgrf/newgrf_internal_vehicle.h b/src/newgrf/newgrf_internal_vehicle.h index 31b2eac9ea..185382c530 100644 --- a/src/newgrf/newgrf_internal_vehicle.h +++ b/src/newgrf/newgrf_internal_vehicle.h @@ -49,7 +49,7 @@ struct GRFTempEngineData { } }; -extern ReferenceThroughBaseContainer> _gted; ///< Temporary engine data used during NewGRF loading +extern TypedIndexContainer, EngineID> _gted; ///< Temporary engine data used during NewGRF loading Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16_t internal_id, bool static_access = false); void ConvertTTDBasePrice(uint32_t base_pointer, std::string_view error_location, Price *index); diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp index 86d4b24a39..3480598032 100644 --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -74,7 +74,7 @@ struct GRFTextEntry { }; -static ReferenceThroughBaseContainer> _grf_text; +static TypedIndexContainer, StringIndexInTab> _grf_text; static uint8_t _current_lang_id = GRFLX_ENGLISH; ///< by default, english is used. /** diff --git a/src/pathfinder/water_regions.cpp b/src/pathfinder/water_regions.cpp index 60e1c9b723..4ef9694af1 100644 --- a/src/pathfinder/water_regions.cpp +++ b/src/pathfinder/water_regions.cpp @@ -222,8 +222,8 @@ public: } }; -ReferenceThroughBaseContainer> _water_region_data; -ReferenceThroughBaseContainer> _is_water_region_valid; +TypedIndexContainer, WaterRegionIndex> _water_region_data; +TypedIndexContainer, WaterRegionIndex> _is_water_region_valid; static TileIndex GetTileIndexFromLocalCoordinate(int region_x, int region_y, int local_x, int local_y) { diff --git a/src/saveload/engine_sl.cpp b/src/saveload/engine_sl.cpp index 3c7e07fa36..8be236866d 100644 --- a/src/saveload/engine_sl.cpp +++ b/src/saveload/engine_sl.cpp @@ -41,7 +41,7 @@ static const SaveLoad _engine_desc[] = { SLE_CONDSSTR(Engine, name, SLE_STR, SLV_84, SL_MAX_VERSION), }; -static ReferenceThroughBaseContainer> _temp_engine; +static TypedIndexContainer, EngineID> _temp_engine; Engine *GetTempDataEngine(EngineID index) { @@ -134,7 +134,7 @@ struct ENGSChunkHandler : ChunkHandler { { /* Load old separate String ID list into a temporary array. This * was always 256 entries. */ - ReferenceThroughBaseContainer> names{}; + TypedIndexContainer, EngineID> names{}; SlCopy(names.data(), std::size(names), SLE_STRINGID); diff --git a/src/script/api/script_object.hpp b/src/script/api/script_object.hpp index a0d6821e8a..d7f4aaae11 100644 --- a/src/script/api/script_object.hpp +++ b/src/script/api/script_object.hpp @@ -347,7 +347,7 @@ private: static std::tuple DoCommandPrep(); static bool DoCommandProcessResult(const CommandCost &res, Script_SuspendCallbackProc *callback, bool estimate_only, bool asynchronous); static CommandCallbackData *GetDoCommandCallback(); - using RandomizerArray = ReferenceThroughBaseContainer>; + using RandomizerArray = TypedIndexContainer, Owner>; static RandomizerArray random_states; ///< Random states for each of the scripts (game script uses OWNER_DEITY) }; diff --git a/src/settings_type.h b/src/settings_type.h index f6dd5bc98c..255038e537 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -598,7 +598,7 @@ struct CompanySettings { /** Container for AI and Game script configuration. */ struct ScriptConfigSettings { - ReferenceThroughBaseContainer, MAX_COMPANIES>> ai; ///< settings per company + TypedIndexContainer, MAX_COMPANIES>, CompanyID> ai; ///< settings per company std::unique_ptr game; ///< settings for gamescript ScriptConfigSettings(); diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index 3282c907e8..827b654fe9 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -181,7 +181,7 @@ static IndustryType _smallmap_industry_highlight = IT_INVALID; /** State of highlight blinking */ static bool _smallmap_industry_highlight_state; /** For connecting company ID to position in owner list (small map legend) */ -static ReferenceThroughBaseContainer> _company_to_list_pos; +static TypedIndexContainer, CompanyID> _company_to_list_pos; /** * Fills an array for the industries legends. diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index db141507e0..677c81ba8e 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -4431,8 +4431,8 @@ uint MoveGoodsToStation(CargoType cargo, uint amount, Source source, const Stati return UpdateStationWaiting(first_station, cargo, amount, source); } - ReferenceThroughBaseContainer> company_best = {}; // best rating for each company, including OWNER_NONE - ReferenceThroughBaseContainer> company_sum = {}; // sum of ratings for each company + TypedIndexContainer, Owner> company_best = {}; // best rating for each company, including OWNER_NONE + TypedIndexContainer, Owner> company_sum = {}; // sum of ratings for each company uint best_rating = 0; uint best_sum = 0; // sum of best ratings for each company diff --git a/src/town.h b/src/town.h index 7ddbc0f5ff..7894d19f86 100644 --- a/src/town.h +++ b/src/town.h @@ -69,10 +69,10 @@ struct Town : TownPool::PoolItem<&_town_pool> { /* Company ratings. */ CompanyMask have_ratings{}; ///< which companies have a rating - ReferenceThroughBaseContainer> unwanted{}; ///< how many months companies aren't wanted by towns (bribe) + TypedIndexContainer, CompanyID> unwanted{}; ///< how many months companies aren't wanted by towns (bribe) CompanyID exclusivity = CompanyID::Invalid(); ///< which company has exclusivity uint8_t exclusive_counter = 0; ///< months till the exclusivity expires - ReferenceThroughBaseContainer> ratings{}; ///< ratings of each company for this town + TypedIndexContainer, CompanyID> ratings{}; ///< ratings of each company for this town std::array, NUM_CARGO> supplied{}; ///< Cargo statistics about supplied cargo. std::array, NUM_TAE> received{}; ///< Cargo statistics about received cargotypes.