1
0
Fork 0

Codechange: explicitly initialise Subsidy member variables

pull/13618/head
Rubidium 2025-02-18 20:14:25 +01:00 committed by rubidium42
parent be01c2cd2a
commit ce2ae07233
2 changed files with 9 additions and 13 deletions

View File

@ -201,12 +201,7 @@ static bool CheckSubsidyDistance(Source src, Source dst)
*/ */
void CreateSubsidy(CargoType cargo_type, Source src, Source dst) void CreateSubsidy(CargoType cargo_type, Source src, Source dst)
{ {
Subsidy *s = new Subsidy(); Subsidy *s = new Subsidy(cargo_type, src, dst, SUBSIDY_OFFER_MONTHS);
s->cargo_type = cargo_type;
s->src = src;
s->dst = dst;
s->remaining = SUBSIDY_OFFER_MONTHS;
s->awarded = CompanyID::Invalid();
std::pair<NewsReference, NewsReference> references = SetupSubsidyDecodeParam(s, SubsidyDecodeParamType::NewsOffered); std::pair<NewsReference, NewsReference> references = SetupSubsidyDecodeParam(s, SubsidyDecodeParamType::NewsOffered);
AddNewsItem(STR_NEWS_SERVICE_SUBSIDY_OFFERED, NewsType::Subsidies, NewsStyle::Normal, {}, references.first, references.second); AddNewsItem(STR_NEWS_SERVICE_SUBSIDY_OFFERED, NewsType::Subsidies, NewsStyle::Normal, {}, references.first, references.second);

View File

@ -21,21 +21,22 @@ extern SubsidyPool _subsidy_pool;
/** Struct about subsidies, offered and awarded */ /** Struct about subsidies, offered and awarded */
struct Subsidy : SubsidyPool::PoolItem<&_subsidy_pool> { struct Subsidy : SubsidyPool::PoolItem<&_subsidy_pool> {
CargoType cargo_type; ///< Cargo type involved in this subsidy, INVALID_CARGO for invalid subsidy CargoType cargo_type = INVALID_CARGO; ///< Cargo type involved in this subsidy, INVALID_CARGO for invalid subsidy
uint16_t remaining; ///< Remaining months when this subsidy is valid uint16_t remaining = 0; ///< Remaining months when this subsidy is valid
CompanyID awarded; ///< Subsidy is awarded to this company; CompanyID::Invalid() if it's not awarded to anyone CompanyID awarded = CompanyID::Invalid(); ///< Subsidy is awarded to this company; CompanyID::Invalid() if it's not awarded to anyone
Source src; ///< Source of subsidised path Source src{}; ///< Source of subsidised path
Source dst; ///< Destination of subsidised path Source dst{}; ///< Destination of subsidised path
/** /**
* We need an (empty) constructor so struct isn't zeroed (as C++ standard states) * We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
*/ */
inline Subsidy() { } Subsidy() { }
Subsidy(CargoType cargo_type, Source src, Source dst, uint16_t remaining) : cargo_type(cargo_type), remaining(remaining), src(src), dst(dst) {}
/** /**
* (Empty) destructor has to be defined else operator delete might be called with nullptr parameter * (Empty) destructor has to be defined else operator delete might be called with nullptr parameter
*/ */
inline ~Subsidy() { } ~Subsidy() { }
/** /**
* Tests whether this subsidy has been awarded to someone * Tests whether this subsidy has been awarded to someone