diff --git a/src/company_base.h b/src/company_base.h --- a/src/company_base.h +++ b/src/company_base.h @@ -92,7 +92,7 @@ struct CompanyProperties { */ bool is_ai; - Money yearly_expenses[3][EXPENSES_END]; ///< Expenses of the company for the last three years, in every #ExpensesType category. + std::array yearly_expenses{}; ///< Expenses of the company for the last three years. CompanyEconomyEntry cur_economy; ///< Economic data of the company of this quarter. CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]; ///< Economic data of the company of the last #MAX_HISTORY_QUARTERS quarters. byte num_valid_stat_ent; ///< Number of valid statistical entries in #old_economy. diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -750,8 +750,9 @@ static IntervalTimer { /* Copy statistics */ for (Company *c : Company::Iterate()) { - memmove(&c->yearly_expenses[1], &c->yearly_expenses[0], sizeof(c->yearly_expenses) - sizeof(c->yearly_expenses[0])); - memset(&c->yearly_expenses[0], 0, sizeof(c->yearly_expenses[0])); + /* Move expenses to previous years. */ + std::rotate(std::rbegin(c->yearly_expenses), std::rbegin(c->yearly_expenses) + 1, std::rend(c->yearly_expenses)); + c->yearly_expenses[0] = {}; SetWindowDirty(WC_FINANCES, c->index); } diff --git a/src/company_gui.cpp b/src/company_gui.cpp --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -229,7 +229,7 @@ static void DrawPrice(Money amount, int * Draw a category of expenses/revenues in the year column. * @return The income sum of the category. */ -static Money DrawYearCategory (const Rect &r, int start_y, ExpensesList list, const Money(&tbl)[EXPENSES_END]) +static Money DrawYearCategory(const Rect &r, int start_y, ExpensesList list, const Expenses &tbl) { int y = start_y; ExpensesType et; @@ -260,7 +260,7 @@ static Money DrawYearCategory (const Rec * @param tbl Reference to table of amounts for \a year. * @note The environment must provide padding at the left and right of \a r. */ -static void DrawYearColumn(const Rect &r, TimerGameCalendar::Year year, const Money (&tbl)[EXPENSES_END]) +static void DrawYearColumn(const Rect &r, TimerGameCalendar::Year year, const Expenses &tbl) { int y = r.top; Money sum; diff --git a/src/economy_type.h b/src/economy_type.h --- a/src/economy_type.h +++ b/src/economy_type.h @@ -173,6 +173,11 @@ enum ExpensesType : byte { }; /** + * Data type for storage of Money for each #ExpensesType category. + */ +using Expenses = std::array; + +/** * Categories of a price bases. */ enum PriceCategory { diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp --- a/src/network/network_admin.cpp +++ b/src/network/network_admin.cpp @@ -383,10 +383,7 @@ NetworkRecvStatus ServerNetworkAdminSock { for (const Company *company : Company::Iterate()) { /* Get the income. */ - Money income = 0; - for (uint i = 0; i < lengthof(company->yearly_expenses[0]); i++) { - income -= company->yearly_expenses[0][i]; - } + Money income = -std::reduce(std::begin(company->yearly_expenses[0]), std::end(company->yearly_expenses[0])); Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_ECONOMY);