diff --git a/src/league_base.h b/src/league_base.h index 07569d625f..6d448ff507 100644 --- a/src/league_base.h +++ b/src/league_base.h @@ -29,17 +29,19 @@ extern LeagueTablePool _league_table_pool; * Each LeagueTable is composed of one or more elements. Elements are sorted by their rating (higher=better). **/ struct LeagueTableElement : LeagueTableElementPool::PoolItem<&_league_table_element_pool> { - LeagueTableID table; ///< Id of the table which this element belongs to - int64_t rating; ///< Value that determines ordering of elements in the table (higher=better) - CompanyID company; ///< Company Id to show the color blob for or CompanyID::Invalid() - std::string text; ///< Text of the element - std::string score; ///< String representation of the score associated with the element - Link link; ///< What opens when element is clicked + LeagueTableID table = LeagueTableID::Invalid(); ///< Id of the table which this element belongs to + int64_t rating = 0; ///< Value that determines ordering of elements in the table (higher=better) + CompanyID company = CompanyID::Invalid(); ///< Company Id to show the color blob for or CompanyID::Invalid() + std::string text{}; ///< Text of the element + std::string score{}; ///< String representation of the score associated with the element + Link link{}; ///< What opens when element is clicked /** * We need an (empty) constructor so struct isn't zeroed (as C++ standard states) */ LeagueTableElement() { } + LeagueTableElement(LeagueTableID table, int64_t rating, CompanyID company, const std::string &text, const std::string &score, const Link &link) : + table(table), rating(rating), company(company), text(text), score(score), link(link) {} /** * (Empty) destructor has to be defined else operator delete might be called with nullptr parameter @@ -50,14 +52,15 @@ struct LeagueTableElement : LeagueTableElementPool::PoolItem<&_league_table_elem /** Struct about custom league tables */ struct LeagueTable : LeagueTablePool::PoolItem<&_league_table_pool> { - std::string title; ///< Title of the table - std::string header; ///< Text to show above the table - std::string footer; ///< Text to show below the table + std::string title{}; ///< Title of the table + std::string header{}; ///< Text to show above the table + std::string footer{}; ///< Text to show below the table /** * We need an (empty) constructor so struct isn't zeroed (as C++ standard states) */ LeagueTable() { } + LeagueTable(const std::string &title, const std::string &header, const std::string &footer) : title(title), header(header), footer(footer) { } /** * (Empty) destructor has to be defined else operator delete might be called with nullptr parameter diff --git a/src/league_cmd.cpp b/src/league_cmd.cpp index 4db3d3086f..876a6d1a97 100644 --- a/src/league_cmd.cpp +++ b/src/league_cmd.cpp @@ -60,10 +60,7 @@ std::tuple CmdCreateLeagueTable(DoCommandFlags flags if (title.empty()) return { CMD_ERROR, LeagueTableID::Invalid() }; if (flags.Test(DoCommandFlag::Execute)) { - LeagueTable *lt = new LeagueTable(); - lt->title = title; - lt->header = header; - lt->footer = footer; + LeagueTable *lt = new LeagueTable(title, header, footer); return { CommandCost(), lt->index }; } @@ -92,13 +89,7 @@ std::tuple CmdCreateLeagueTableElement(DoComm if (company != CompanyID::Invalid() && !Company::IsValidID(company)) return { CMD_ERROR, LeagueTableElementID::Invalid() }; if (flags.Test(DoCommandFlag::Execute)) { - LeagueTableElement *lte = new LeagueTableElement(); - lte->table = table; - lte->rating = rating; - lte->company = company; - lte->text = text; - lte->score = score; - lte->link = link; + LeagueTableElement *lte = new LeagueTableElement(table, rating, company, text, score, link); InvalidateWindowData(WC_COMPANY_LEAGUE, table); return { CommandCost(), lte->index }; } diff --git a/src/league_type.h b/src/league_type.h index 6ff106110d..e9f0d2e7a4 100644 --- a/src/league_type.h +++ b/src/league_type.h @@ -25,10 +25,11 @@ enum LinkType : uint8_t { typedef uint32_t LinkTargetID; ///< Contains either tile, industry ID, town ID, story page ID or company ID struct Link { - LinkType type; - LinkTargetID target; - Link(LinkType type, LinkTargetID target): type{type}, target{target} {} - Link(): Link(LT_NONE, 0) {} + LinkType type = LT_NONE; + LinkTargetID target = 0; + + Link() {} + Link(LinkType type, LinkTargetID target) : type{type}, target{target} {} }; using LeagueTableID = PoolID; ///< ID of a league table