mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 18:40:29 +00:00
Codechange: Add a DateToYear function instead of dividing each time (#11173)
This commit is contained in:
parent
4928ccf916
commit
6190f48df0
@ -967,7 +967,7 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number,
|
||||
if (e->type != VEH_TRAIN || e->u.rail.railveh_type != RAILVEH_WAGON) {
|
||||
/* Design date - Life length */
|
||||
SetDParam(0, ymd.year);
|
||||
SetDParam(1, e->GetLifeLengthInDays() / DAYS_IN_LEAP_YEAR);
|
||||
SetDParam(1, DateToYear(e->GetLifeLengthInDays()));
|
||||
DrawString(left, right, y, STR_PURCHASE_INFO_DESIGNED_LIFE);
|
||||
y += FONT_HEIGHT_NORMAL;
|
||||
|
||||
|
@ -63,6 +63,16 @@ static constexpr TimerGameCalendar::Date DateAtStartOfYear(TimerGameCalendar::Ye
|
||||
return (DAYS_IN_YEAR * year) + number_of_leap_years;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the year of a given date.
|
||||
* @param date The date to consider.
|
||||
* @return the year.
|
||||
*/
|
||||
static inline TimerGameCalendar::Year DateToYear(TimerGameCalendar::Date date)
|
||||
{
|
||||
return date / DAYS_IN_LEAP_YEAR;
|
||||
}
|
||||
|
||||
/**
|
||||
* The date of the first day of the original base year.
|
||||
*/
|
||||
|
@ -1941,10 +1941,10 @@ VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v)
|
||||
case OCV_RELIABILITY: skip_order = OrderConditionCompare(occ, ToPercent16(v->reliability), value); break;
|
||||
case OCV_MAX_RELIABILITY: skip_order = OrderConditionCompare(occ, ToPercent16(v->GetEngine()->reliability), value); break;
|
||||
case OCV_MAX_SPEED: skip_order = OrderConditionCompare(occ, v->GetDisplayMaxSpeed() * 10 / 16, value); break;
|
||||
case OCV_AGE: skip_order = OrderConditionCompare(occ, v->age / DAYS_IN_LEAP_YEAR, value); break;
|
||||
case OCV_AGE: skip_order = OrderConditionCompare(occ, DateToYear(v->age), value); break;
|
||||
case OCV_REQUIRES_SERVICE: skip_order = OrderConditionCompare(occ, v->NeedsServicing(), value); break;
|
||||
case OCV_UNCONDITIONALLY: skip_order = true; break;
|
||||
case OCV_REMAINING_LIFETIME: skip_order = OrderConditionCompare(occ, std::max(v->max_age - v->age + DAYS_IN_LEAP_YEAR - 1, 0) / DAYS_IN_LEAP_YEAR, value); break;
|
||||
case OCV_REMAINING_LIFETIME: skip_order = OrderConditionCompare(occ, std::max(DateToYear(v->max_age - v->age + DAYS_IN_LEAP_YEAR - 1), 0), value); break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
|
||||
|
@ -2495,9 +2495,9 @@ struct VehicleDetailsWindow : Window {
|
||||
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
|
||||
|
||||
/* Draw running cost */
|
||||
SetDParam(1, v->age / DAYS_IN_LEAP_YEAR);
|
||||
SetDParam(1, DateToYear(v->age));
|
||||
SetDParam(0, (v->age + DAYS_IN_YEAR < v->max_age) ? STR_VEHICLE_INFO_AGE : STR_VEHICLE_INFO_AGE_RED);
|
||||
SetDParam(2, v->max_age / DAYS_IN_LEAP_YEAR);
|
||||
SetDParam(2, DateToYear(v->max_age));
|
||||
SetDParam(3, v->GetDisplayRunningCost());
|
||||
DrawString(tr, STR_VEHICLE_INFO_AGE_RUNNING_COST_YR);
|
||||
tr.top += FONT_HEIGHT_NORMAL;
|
||||
|
Loading…
Reference in New Issue
Block a user