Changeset - r27785:88286657899e
[Not reviewed]
master
0 8 0
Patric Stout - 10 months ago 2023-08-12 14:02:31
truebrain@openttd.org
Codechange: use TimerGameCalendar::Year and friends when working with years (#11188)
8 files changed with 13 insertions and 13 deletions:
0 comments (0 inline, 0 general)
src/company_gui.cpp
Show inline comments
 
@@ -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, 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]);
src/genworld_gui.cpp
Show inline comments
 
@@ -987,7 +987,7 @@ struct GenerateLandscapeWindow : public 
 

	
 
			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 Win
 
			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:
src/newgrf.cpp
Show inline comments
 
@@ -2257,7 +2257,7 @@ static ChangeInfoResult BridgeChangeInfo
 
				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
src/order_cmd.cpp
Show inline comments
 
@@ -1944,7 +1944,7 @@ VehicleOrderID ProcessConditionalOrder(c
 
		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();
 
	}
 

	
src/statusbar_gui.cpp
Show inline comments
 
@@ -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;
 

	
src/timetable_gui.cpp
Show inline comments
 
@@ -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;
 

	
src/vehicle.cpp
Show inline comments
 
@@ -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;
src/vehicle_gui.cpp
Show inline comments
 
@@ -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
0 comments (0 inline, 0 general)