Codechange: Use DateAtStartOfYear() instead of multiplying by DAYS_IN_LEAP_YEAR (#11174)
This commit is contained in:
@@ -437,8 +437,7 @@ uint Engine::GetDisplayMaxTractiveEffort() const
|
||||
*/
|
||||
TimerGameCalendar::Date Engine::GetLifeLengthInDays() const
|
||||
{
|
||||
/* Assume leap years; this gives the player a bit more than the given amount of years, but never less. */
|
||||
return (this->info.lifelength + _settings_game.vehicle.extend_vehicle_life) * DAYS_IN_LEAP_YEAR;
|
||||
return DateAtStartOfYear(this->info.lifelength + _settings_game.vehicle.extend_vehicle_life);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -663,7 +662,7 @@ void SetYearEngineAgingStops()
|
||||
|
||||
/* Base year ending date on half the model life */
|
||||
TimerGameCalendar::YearMonthDay ymd;
|
||||
TimerGameCalendar::ConvertDateToYMD(ei->base_intro + (ei->lifelength * DAYS_IN_LEAP_YEAR) / 2, &ymd);
|
||||
TimerGameCalendar::ConvertDateToYMD(ei->base_intro + DateAtStartOfYear(ei->lifelength) / 2, &ymd);
|
||||
|
||||
_year_engine_aging_stops = std::max(_year_engine_aging_stops, ymd.year);
|
||||
}
|
||||
|
@@ -304,7 +304,7 @@ CommandCost CmdSetTimetableStart(DoCommandFlag flags, VehicleID veh_id, bool tim
|
||||
|
||||
/* Don't let a timetable start more than 15 years into the future or 1 year in the past. */
|
||||
if (start_date < 0 || start_date > MAX_DATE) return CMD_ERROR;
|
||||
if (start_date - TimerGameCalendar::date > MAX_TIMETABLE_START_YEARS * DAYS_IN_LEAP_YEAR) return CMD_ERROR;
|
||||
if (start_date - TimerGameCalendar::date > DateAtStartOfYear(MAX_TIMETABLE_START_YEARS)) return CMD_ERROR;
|
||||
if (TimerGameCalendar::date - start_date > DAYS_IN_LEAP_YEAR) return CMD_ERROR;
|
||||
if (timetable_all && !v->orders->IsCompleteTimetable()) return CommandCost(STR_ERROR_TIMETABLE_INCOMPLETE);
|
||||
if (timetable_all && start_date + total_duration / DAY_TICKS > MAX_DATE) return CMD_ERROR;
|
||||
|
@@ -1377,9 +1377,11 @@ void AgeVehicle(Vehicle *v)
|
||||
if (!v->IsPrimaryVehicle() && (v->type != VEH_TRAIN || !Train::From(v)->IsEngine())) return;
|
||||
|
||||
int age = v->age - v->max_age;
|
||||
if (age == DAYS_IN_LEAP_YEAR * 0 || age == DAYS_IN_LEAP_YEAR * 1 ||
|
||||
age == DAYS_IN_LEAP_YEAR * 2 || age == DAYS_IN_LEAP_YEAR * 3 || age == DAYS_IN_LEAP_YEAR * 4) {
|
||||
v->reliability_spd_dec <<= 1;
|
||||
for (int32_t i = 0; i <= 4; i++) {
|
||||
if (age == DateAtStartOfYear(i)) {
|
||||
v->reliability_spd_dec <<= 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SetWindowDirty(WC_VEHICLE_DETAILS, v->index);
|
||||
|
Reference in New Issue
Block a user