From 8a4493f990d84b81e033acb785cdd853ba5da12c Mon Sep 17 00:00:00 2001 From: Rubidium Date: Tue, 18 Feb 2025 20:26:18 +0100 Subject: [PATCH] Codechange: explicitly initialise Town member variables --- src/town.h | 74 ++++++++++++++++++++++++------------------------- src/town_type.h | 10 +++---- 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/town.h b/src/town.h index e2ba175359..6dc104f241 100644 --- a/src/town.h +++ b/src/town.h @@ -19,8 +19,8 @@ template struct BuildingCounts { - std::vector id_count; - std::vector class_count; + std::vector id_count{}; + std::vector class_count{}; auto operator<=>(const BuildingCounts &) const = default; }; @@ -38,47 +38,47 @@ extern TownPool _town_pool; /** Data structure with cached data of towns. */ struct TownCache { - uint32_t num_houses; ///< Amount of houses - uint32_t population; ///< Current population of people - TrackedViewportSign sign; ///< Location of name sign, UpdateVirtCoord updates this - PartOfSubsidy part_of_subsidy; ///< Is this town a source/destination of a subsidy? - std::array squared_town_zone_radius; ///< UpdateTownRadius updates this given the house count - BuildingCounts building_counts; ///< The number of each type of building in the town + uint32_t num_houses = 0; ///< Amount of houses + uint32_t population = 0; ///< Current population of people + TrackedViewportSign sign{}; ///< Location of name sign, UpdateVirtCoord updates this + PartOfSubsidy part_of_subsidy{}; ///< Is this town a source/destination of a subsidy? + std::array squared_town_zone_radius{}; ///< UpdateTownRadius updates this given the house count + BuildingCounts building_counts{}; ///< The number of each type of building in the town auto operator<=>(const TownCache &) const = default; }; /** Town data structure. */ struct Town : TownPool::PoolItem<&_town_pool> { - TileIndex xy; ///< town center tile + TileIndex xy = INVALID_TILE; ///< town center tile - TownCache cache; ///< Container for all cacheable data. + TownCache cache{}; ///< Container for all cacheable data. /* Town name */ - uint32_t townnamegrfid; - uint16_t townnametype; - uint32_t townnameparts; - std::string name; ///< Custom town name. If empty, the town was not renamed and uses the generated name. - mutable std::string cached_name; ///< NOSAVE: Cache of the resolved name of the town, if not using a custom town name + uint32_t townnamegrfid = 0; + uint16_t townnametype = 0; + uint32_t townnameparts = 0; + std::string name{}; ///< Custom town name. If empty, the town was not renamed and uses the generated name. + mutable std::string cached_name{}; ///< NOSAVE: Cache of the resolved name of the town, if not using a custom town name - uint8_t flags; ///< See #TownFlags. + uint8_t flags = 0; ///< See #TownFlags. - uint16_t noise_reached; ///< level of noise that all the airports are generating + uint16_t noise_reached = 0; ///< level of noise that all the airports are generating - CompanyMask statues; ///< which companies have a statue? + CompanyMask statues{}; ///< which companies have a statue? /* Company ratings. */ - CompanyMask have_ratings; ///< which companies have a rating - ReferenceThroughBaseContainer> unwanted; ///< how many months companies aren't wanted by towns (bribe) - CompanyID exclusivity; ///< which company has exclusivity - uint8_t exclusive_counter; ///< months till the exclusivity expires - ReferenceThroughBaseContainer> ratings; ///< ratings of each company for this town + CompanyMask have_ratings{}; ///< which companies have a rating + ReferenceThroughBaseContainer> 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 - TransportedCargoStat supplied[NUM_CARGO]; ///< Cargo statistics about supplied cargo. - TransportedCargoStat received[NUM_TAE]; ///< Cargo statistics about received cargotypes. - uint32_t goal[NUM_TAE]; ///< Amount of cargo required for the town to grow. + std::array, NUM_CARGO> supplied{}; ///< Cargo statistics about supplied cargo. + std::array, NUM_TAE> received{}; ///< Cargo statistics about received cargotypes. + std::array goal{}; ///< Amount of cargo required for the town to grow. - std::string text; ///< General text with additional information. + std::string text{}; ///< General text with additional information. inline uint8_t GetPercentTransported(CargoType cargo_type) const { @@ -86,22 +86,22 @@ struct Town : TownPool::PoolItem<&_town_pool> { return this->supplied[cargo_type].old_act * 256 / (this->supplied[cargo_type].old_max + 1); } - StationList stations_near; ///< NOSAVE: List of nearby stations. + StationList stations_near{}; ///< NOSAVE: List of nearby stations. - uint16_t time_until_rebuild; ///< time until we rebuild a house + uint16_t time_until_rebuild = 0; ///< time until we rebuild a house - uint16_t grow_counter; ///< counter to count when to grow, value is smaller than or equal to growth_rate - uint16_t growth_rate; ///< town growth rate + uint16_t grow_counter = 0; ///< counter to count when to grow, value is smaller than or equal to growth_rate + uint16_t growth_rate = 0; ///< town growth rate - uint8_t fund_buildings_months; ///< fund buildings program in action? - uint8_t road_build_months; ///< fund road reconstruction in action? + uint8_t fund_buildings_months = 0; ///< fund buildings program in action? + uint8_t road_build_months = 0; ///< fund road reconstruction in action? - bool larger_town; ///< if this is a larger town and should grow more quickly - TownLayout layout; ///< town specific road layout + bool larger_town = false; ///< if this is a larger town and should grow more quickly + TownLayout layout{}; ///< town specific road layout - bool show_zone; ///< NOSAVE: mark town to show the local authority zone in the viewports + bool show_zone = false; ///< NOSAVE: mark town to show the local authority zone in the viewports - std::vector psa_list; + std::vector psa_list{}; /** * Creates a new town. diff --git a/src/town_type.h b/src/town_type.h index 8925b8d9af..dffd93bb68 100644 --- a/src/town_type.h +++ b/src/town_type.h @@ -113,12 +113,10 @@ static const uint MAX_LENGTH_TOWN_NAME_CHARS = 32; ///< The maximum length of a /** Store the maximum and actually transported cargo amount for the current and the last month. */ template struct TransportedCargoStat { - Tstorage old_max; ///< Maximum amount last month - Tstorage new_max; ///< Maximum amount this month - Tstorage old_act; ///< Actually transported last month - Tstorage new_act; ///< Actually transported this month - - TransportedCargoStat() : old_max(0), new_max(0), old_act(0), new_act(0) {} + Tstorage old_max = 0; ///< Maximum amount last month + Tstorage new_max = 0; ///< Maximum amount this month + Tstorage old_act = 0; ///< Actually transported last month + Tstorage new_act = 0; ///< Actually transported this month /** Update stats for a new month. */ void NewMonth()