mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Use std::accumulate to get infrastructure total rail/road pieces. (#12442)
This commit is contained in:
parent
08140fdca3
commit
e028c15555
|
@ -42,9 +42,7 @@ struct CompanyInfrastructure {
|
|||
/** Get total sum of all owned track bits. */
|
||||
uint32_t GetRailTotal() const
|
||||
{
|
||||
uint32_t total = 0;
|
||||
for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) total += this->rail[rt];
|
||||
return total;
|
||||
return std::accumulate(std::begin(this->rail), std::end(this->rail), 0U);
|
||||
}
|
||||
|
||||
uint32_t GetRoadTotal() const;
|
||||
|
|
|
@ -2337,16 +2337,15 @@ struct CompanyWindow : Window
|
|||
{
|
||||
int y = r.top;
|
||||
|
||||
uint rail_pieces = c->infrastructure.signal;
|
||||
for (uint i = 0; i < std::size(c->infrastructure.rail); i++) rail_pieces += c->infrastructure.rail[i];
|
||||
uint rail_pieces = c->infrastructure.signal + c->infrastructure.GetRailTotal();
|
||||
if (rail_pieces != 0) {
|
||||
SetDParam(0, rail_pieces);
|
||||
DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL);
|
||||
y += GetCharacterHeight(FS_NORMAL);
|
||||
}
|
||||
|
||||
uint road_pieces = 0;
|
||||
for (uint i = 0; i < std::size(c->infrastructure.road); i++) road_pieces += c->infrastructure.road[i];
|
||||
/* GetRoadTotal() skips tram pieces, but we actually want road and tram here. */
|
||||
uint road_pieces = std::accumulate(std::begin(c->infrastructure.road), std::end(c->infrastructure.road), 0U);
|
||||
if (road_pieces != 0) {
|
||||
SetDParam(0, road_pieces);
|
||||
DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD);
|
||||
|
|
Loading…
Reference in New Issue