Codechange: Use std::accumulate to get infrastructure total rail/road pieces. (#12442)

This commit is contained in:
Peter Nelson 2024-04-20 10:22:19 +01:00 committed by GitHub
parent 08140fdca3
commit e028c15555
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 7 deletions

View File

@ -42,9 +42,7 @@ struct CompanyInfrastructure {
/** Get total sum of all owned track bits. */ /** Get total sum of all owned track bits. */
uint32_t GetRailTotal() const uint32_t GetRailTotal() const
{ {
uint32_t total = 0; return std::accumulate(std::begin(this->rail), std::end(this->rail), 0U);
for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) total += this->rail[rt];
return total;
} }
uint32_t GetRoadTotal() const; uint32_t GetRoadTotal() const;

View File

@ -2337,16 +2337,15 @@ struct CompanyWindow : Window
{ {
int y = r.top; int y = r.top;
uint rail_pieces = c->infrastructure.signal; uint rail_pieces = c->infrastructure.signal + c->infrastructure.GetRailTotal();
for (uint i = 0; i < std::size(c->infrastructure.rail); i++) rail_pieces += c->infrastructure.rail[i];
if (rail_pieces != 0) { if (rail_pieces != 0) {
SetDParam(0, rail_pieces); SetDParam(0, rail_pieces);
DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL); DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL);
y += GetCharacterHeight(FS_NORMAL); y += GetCharacterHeight(FS_NORMAL);
} }
uint road_pieces = 0; /* GetRoadTotal() skips tram pieces, but we actually want road and tram here. */
for (uint i = 0; i < std::size(c->infrastructure.road); i++) road_pieces += c->infrastructure.road[i]; uint road_pieces = std::accumulate(std::begin(c->infrastructure.road), std::end(c->infrastructure.road), 0U);
if (road_pieces != 0) { if (road_pieces != 0) {
SetDParam(0, road_pieces); SetDParam(0, road_pieces);
DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD); DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD);