mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 18:40:29 +00:00
Codechange: use TimerGameCalendar::Year and friends when working with years (#11188)
This commit is contained in:
parent
01f55eb734
commit
b7acf9e50e
@ -260,7 +260,7 @@ static Money DrawYearCategory (const Rect &r, int start_y, ExpensesList list, co
|
||||
* @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, int year, const Money (&tbl)[EXPENSES_END])
|
||||
static void DrawYearColumn(const Rect &r, TimerGameCalendar::Year year, const Money (&tbl)[EXPENSES_END])
|
||||
{
|
||||
int y = r.top;
|
||||
Money sum;
|
||||
@ -434,7 +434,7 @@ struct CompanyFinancesWindow : Window {
|
||||
case WID_CF_EXPS_PRICE2:
|
||||
case WID_CF_EXPS_PRICE3: {
|
||||
const Company *c = Company::Get((CompanyID)this->window_number);
|
||||
int age = std::min(TimerGameCalendar::year - c->inaugurated_year, 2);
|
||||
auto age = std::min(TimerGameCalendar::year - c->inaugurated_year, TimerGameCalendar::Year(2));
|
||||
int wid_offset = widget - WID_CF_EXPS_PRICE1;
|
||||
if (wid_offset <= age) {
|
||||
DrawYearColumn(r, TimerGameCalendar::year - (age - wid_offset), c->yearly_expenses[age - wid_offset]);
|
||||
|
@ -987,7 +987,7 @@ struct GenerateLandscapeWindow : public Window {
|
||||
|
||||
case WID_GL_START_DATE_TEXT:
|
||||
this->SetWidgetDirty(WID_GL_START_DATE_TEXT);
|
||||
_settings_newgame.game_creation.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
|
||||
_settings_newgame.game_creation.starting_year = Clamp(TimerGameCalendar::Year(value), MIN_YEAR, MAX_YEAR);
|
||||
break;
|
||||
|
||||
case WID_GL_SNOW_COVERAGE_TEXT:
|
||||
@ -1258,7 +1258,7 @@ struct CreateScenarioWindow : public Window
|
||||
switch (this->widget_id) {
|
||||
case WID_CS_START_DATE_TEXT:
|
||||
this->SetWidgetDirty(WID_CS_START_DATE_TEXT);
|
||||
_settings_newgame.game_creation.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
|
||||
_settings_newgame.game_creation.starting_year = Clamp(TimerGameCalendar::Year(value), MIN_YEAR, MAX_YEAR);
|
||||
break;
|
||||
|
||||
case WID_CS_FLAT_LAND_HEIGHT_TEXT:
|
||||
|
@ -2257,7 +2257,7 @@ static ChangeInfoResult BridgeChangeInfo(uint brid, int numinfo, int prop, ByteR
|
||||
break;
|
||||
|
||||
case 0x0F: // Long format year of availability (year since year 0)
|
||||
bridge->avail_year = Clamp(buf->ReadDWord(), MIN_YEAR, MAX_YEAR);
|
||||
bridge->avail_year = Clamp(TimerGameCalendar::Year(buf->ReadDWord()), MIN_YEAR, MAX_YEAR);
|
||||
break;
|
||||
|
||||
case 0x10: { // purchase string
|
||||
|
@ -1944,7 +1944,7 @@ VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v)
|
||||
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(DateToYear(v->max_age - v->age + DAYS_IN_LEAP_YEAR - 1), TimerGameCalendar::Date(0)), value); break;
|
||||
case OCV_REMAINING_LIFETIME: skip_order = OrderConditionCompare(occ, std::max(DateToYear(v->max_age - v->age + DAYS_IN_LEAP_YEAR - 1), TimerGameCalendar::Year(0)), value); break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ struct StatusBarWindow : Window {
|
||||
Dimension d;
|
||||
switch (widget) {
|
||||
case WID_S_LEFT:
|
||||
SetDParamMaxValue(0, MAX_YEAR * DAYS_IN_YEAR);
|
||||
SetDParamMaxValue(0, DateAtStartOfYear(MAX_YEAR));
|
||||
d = GetStringBoundingBox(STR_JUST_DATE_LONG);
|
||||
break;
|
||||
|
||||
|
@ -193,7 +193,7 @@ struct TimetableWindow : Window {
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_VT_ARRIVAL_DEPARTURE_PANEL:
|
||||
SetDParamMaxValue(1, MAX_YEAR * DAYS_IN_YEAR, 0, FS_SMALL);
|
||||
SetDParamMaxValue(1, DateAtStartOfYear(MAX_YEAR), 0, FS_SMALL);
|
||||
size->width = std::max(GetStringBoundingBox(STR_TIMETABLE_ARRIVAL).width, GetStringBoundingBox(STR_TIMETABLE_DEPARTURE).width) + WidgetDimensions::scaled.hsep_wide + padding.width;
|
||||
FALLTHROUGH;
|
||||
|
||||
|
@ -1376,7 +1376,7 @@ void AgeVehicle(Vehicle *v)
|
||||
|
||||
if (!v->IsPrimaryVehicle() && (v->type != VEH_TRAIN || !Train::From(v)->IsEngine())) return;
|
||||
|
||||
int age = v->age - v->max_age;
|
||||
auto age = v->age - v->max_age;
|
||||
for (int32_t i = 0; i <= 4; i++) {
|
||||
if (age == DateAtStartOfYear(i)) {
|
||||
v->reliability_spd_dec <<= 1;
|
||||
@ -1396,11 +1396,11 @@ void AgeVehicle(Vehicle *v)
|
||||
if (EngineHasReplacementForCompany(c, v->engine_type, v->group_id)) return;
|
||||
|
||||
StringID str;
|
||||
if (age == -DAYS_IN_LEAP_YEAR) {
|
||||
if (age == DateAtStartOfYear(-1)) {
|
||||
str = STR_NEWS_VEHICLE_IS_GETTING_OLD;
|
||||
} else if (age == 0) {
|
||||
} else if (age == DateAtStartOfYear(0)) {
|
||||
str = STR_NEWS_VEHICLE_IS_GETTING_VERY_OLD;
|
||||
} else if (age > 0 && (age % DAYS_IN_LEAP_YEAR) == 0) {
|
||||
} else if (age > DateAtStartOfYear(0) && (age % DAYS_IN_LEAP_YEAR) == 0) {
|
||||
str = STR_NEWS_VEHICLE_IS_GETTING_VERY_OLD_AND;
|
||||
} else {
|
||||
return;
|
||||
|
@ -2438,7 +2438,7 @@ struct VehicleDetailsWindow : Window {
|
||||
|
||||
case WID_VD_SERVICING_INTERVAL:
|
||||
SetDParamMaxValue(0, MAX_SERVINT_DAYS); // Roughly the maximum interval
|
||||
SetDParamMaxValue(1, MAX_YEAR * DAYS_IN_YEAR); // Roughly the maximum year
|
||||
SetDParamMaxValue(1, DateAtStartOfYear(MAX_YEAR)); // Roughly the maximum year
|
||||
size->width = std::max(
|
||||
GetStringBoundingBox(STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT).width,
|
||||
GetStringBoundingBox(STR_VEHICLE_DETAILS_SERVICING_INTERVAL_DAYS).width
|
||||
|
Loading…
Reference in New Issue
Block a user