Fix 3c047b1: AIGroup.GetProfitLastYear could get values different than those displayed in GUI (#10227)

* Change: Store "all time" and "since minimum age" last year profits on groups

* Fix: Update last year profit for groups when copying vehicle statistics on autoreplace

* Codechange: Refactor profit last year

* Change: Rename some group related items for clarity

* Change: Reorder the fields in GroupStatistics

That way less memory gets wasted.
This commit is contained in:
SamuXarick
2023-01-22 13:14:02 +00:00
committed by GitHub
parent 8b5fa2cc7b
commit b2a5ebcfc4
5 changed files with 55 additions and 34 deletions

View File

@@ -302,13 +302,13 @@ private:
/* draw the profit icon */
x = rtl ? x - WidgetDimensions::scaled.hsep_normal - this->column_size[VGC_PROFIT].width : x + WidgetDimensions::scaled.hsep_normal + this->column_size[VGC_AUTOREPLACE].width;
SpriteID spr;
uint num_profit_vehicle = GetGroupNumProfitVehicle(this->vli.company, g_id, this->vli.vtype);
Money profit_last_year = GetGroupProfitLastYear(this->vli.company, g_id, this->vli.vtype);
if (num_profit_vehicle == 0) {
uint num_vehicle_min_age = GetGroupNumVehicleMinAge(this->vli.company, g_id, this->vli.vtype);
Money profit_last_year_min_age = GetGroupProfitLastYearMinAge(this->vli.company, g_id, this->vli.vtype);
if (num_vehicle_min_age == 0) {
spr = SPR_PROFIT_NA;
} else if (profit_last_year < 0) {
} else if (profit_last_year_min_age < 0) {
spr = SPR_PROFIT_NEGATIVE;
} else if (profit_last_year < VEHICLE_PROFIT_THRESHOLD * num_profit_vehicle) {
} else if (profit_last_year_min_age < VEHICLE_PROFIT_THRESHOLD * num_vehicle_min_age) {
spr = SPR_PROFIT_SOME;
} else {
spr = SPR_PROFIT_LOT;