Changeset - r27275:44cfdb7649c7
[Not reviewed]
master
0 11 0
Tyler Trahan - 18 months ago 2023-05-07 09:25:24
tyler@tylertrahan.com
Codechange: Don't use macros for DAYS_TILL and friends (#10746)
11 files changed with 26 insertions and 36 deletions:
0 comments (0 inline, 0 general)
src/company_gui.cpp
Show inline comments
 
@@ -1863,23 +1863,23 @@ struct CompanyInfrastructureWindow : Win
 
			if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
 

	
 
			this->railtypes |= GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes;
 
		}
 

	
 
		/* Get the date introduced railtypes as well. */
 
		this->railtypes = AddDateIntroducedRailTypes(this->railtypes, MAX_DAY);
 
		this->railtypes = AddDateIntroducedRailTypes(this->railtypes, MAX_DATE);
 

	
 
		/* Find the used roadtypes. */
 
		for (const Engine *e : Engine::IterateType(VEH_ROAD)) {
 
			if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
 

	
 
			this->roadtypes |= GetRoadTypeInfo(e->u.road.roadtype)->introduces_roadtypes;
 
		}
 

	
 
		/* Get the date introduced roadtypes as well. */
 
		this->roadtypes = AddDateIntroducedRoadTypes(this->roadtypes, MAX_DAY);
 
		this->roadtypes = AddDateIntroducedRoadTypes(this->roadtypes, MAX_DATE);
 
		this->roadtypes &= ~_roadtypes_hidden_mask;
 
	}
 

	
 
	/** Get total infrastructure maintenance cost. */
 
	Money GetTotalMaintenanceCost() const
 
	{
src/console_cmds.cpp
Show inline comments
 
@@ -2290,13 +2290,13 @@ DEF_CONSOLE_CMD(ConNewGRFProfile)
 

	
 
				char datestrbuf[32]{ 0 };
 
				SetDParam(0, _newgrf_profile_end_date);
 
				GetString(datestrbuf, STR_JUST_DATE_ISO, lastof(datestrbuf));
 
				IConsolePrint(CC_DEBUG, "Profiling will automatically stop on game date {}.", datestrbuf);
 
			} else {
 
				_newgrf_profile_end_date = MAX_DAY;
 
				_newgrf_profile_end_date = MAX_DATE;
 
			}
 
		} else if (_newgrf_profilers.empty()) {
 
			IConsolePrint(CC_ERROR, "No GRFs selected for profiling, did not start.");
 
		} else {
 
			IConsolePrint(CC_ERROR, "Did not start profiling for any GRFs, all selected GRFs are already profiling.");
 
		}
 
@@ -2311,13 +2311,13 @@ DEF_CONSOLE_CMD(ConNewGRFProfile)
 

	
 
	/* "abort" sub-command */
 
	if (StrStartsWithIgnoreCase(argv[1], "abo")) {
 
		for (NewGRFProfiler &pr : _newgrf_profilers) {
 
			pr.Abort();
 
		}
 
		_newgrf_profile_end_date = MAX_DAY;
 
		_newgrf_profile_end_date = MAX_DATE;
 
		return true;
 
	}
 

	
 
	return false;
 
}
 

	
src/date_type.h
Show inline comments
 
@@ -49,37 +49,27 @@ static const TimerGameCalendar::Year ORI
 
/** The original ending year */
 
static const TimerGameCalendar::Year ORIGINAL_END_YEAR  = 2051;
 
/** The maximum year of the original TTD */
 
static const TimerGameCalendar::Year ORIGINAL_MAX_YEAR  = 2090;
 

	
 
/**
 
 * Calculate the number of leap years till a given year.
 
 *
 
 * Each passed leap year adds one day to the 'day count'.
 
 *
 
 * A special case for the year 0 as no year has been passed,
 
 * but '(year - 1) / 4' does not yield '-1' to counteract the
 
 * '+1' at the end of the formula as divisions round to zero.
 
 *
 
 * @param year the year to get the leap years till.
 
 * @return the number of leap years.
 
 */
 
#define LEAP_YEARS_TILL(year) ((year) == 0 ? 0 : ((year) - 1) / 4 - ((year) - 1) / 100 + ((year) - 1) / 400 + 1)
 

	
 
/**
 
 * Calculate the date of the first day of a given year.
 
 * @param year the year to get the first day of.
 
 * @return the date.
 
 */
 
#define DAYS_TILL(year) (DAYS_IN_YEAR * (year) + LEAP_YEARS_TILL(year))
 
static inline TimerGameCalendar::Date DateAtStartOfYear(TimerGameCalendar::Year year)
 
{
 
	uint number_of_leap_years = (year == 0) ? 0 : ((year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400 + 1);
 

	
 
	return (DAYS_IN_YEAR * year) + number_of_leap_years;
 
}
 

	
 
/**
 
 * The offset in days from the 'TimerGameCalendar::date == 0' till
 
 * 'TimerGameCalendar::ConvertYMDToDate(ORIGINAL_BASE_YEAR, 0, 1)'
 
 * The date of the first day of the original base year.
 
 */
 
#define DAYS_TILL_ORIGINAL_BASE_YEAR DAYS_TILL(ORIGINAL_BASE_YEAR)
 
static const TimerGameCalendar::Date DAYS_TILL_ORIGINAL_BASE_YEAR = DateAtStartOfYear(ORIGINAL_BASE_YEAR);
 

	
 
/** The absolute minimum & maximum years in OTTD */
 
static const TimerGameCalendar::Year MIN_YEAR = 0;
 

	
 
/** The default starting year */
 
static const TimerGameCalendar::Year DEF_START_YEAR = 1950;
 
@@ -89,14 +79,14 @@ static const TimerGameCalendar::Year DEF
 
/**
 
 * MAX_YEAR, nicely rounded value of the number of years that can
 
 * be encoded in a single 32 bits date, about 2^31 / 366 years.
 
 */
 
static const TimerGameCalendar::Year MAX_YEAR  = 5000000;
 

	
 
/** The number of days till the last day */
 
#define MAX_DAY (DAYS_TILL(MAX_YEAR + 1) - 1)
 
/** The date of the last day of the max year. */
 
static const TimerGameCalendar::Date MAX_DATE = DateAtStartOfYear(MAX_YEAR + 1) - 1;
 

	
 
static const TimerGameCalendar::Year INVALID_YEAR = -1; ///< Representation of an invalid year
 
static const TimerGameCalendar::Date INVALID_DATE = -1; ///< Representation of an invalid date
 
static const Ticks INVALID_TICKS = -1; ///< Representation of an invalid number of ticks
 

	
 
#endif /* DATE_TYPE_H */
src/newgrf_profiling.cpp
Show inline comments
 
@@ -153,13 +153,13 @@ uint32 NewGRFProfiler::FinishAll()
 
	}
 

	
 
	if (total_microseconds > 0 && max_ticks > 0) {
 
		IConsolePrint(CC_DEBUG, "Total NewGRF callback processing: {} microseconds over {} ticks.", total_microseconds, max_ticks);
 
	}
 

	
 
	_newgrf_profile_end_date = MAX_DAY;
 
	_newgrf_profile_end_date = MAX_DATE;
 

	
 
	return total_microseconds;
 
}
 

	
 
/**
 
 * Check whether profiling is active and should be finished.
src/rail.cpp
Show inline comments
 
@@ -222,13 +222,13 @@ RailTypes AddDateIntroducedRailTypes(Rai
 
	for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
 
		const RailtypeInfo *rti = GetRailTypeInfo(rt);
 
		/* Unused rail type. */
 
		if (rti->label == 0) continue;
 

	
 
		/* Not date introduced. */
 
		if (!IsInsideMM(rti->introduction_date, 0, MAX_DAY)) continue;
 
		if (!IsInsideMM(rti->introduction_date, 0, MAX_DATE)) continue;
 

	
 
		/* Not yet introduced at this date. */
 
		if (rti->introduction_date > date) continue;
 

	
 
		/* Have we introduced all required railtypes? */
 
		RailTypes required = rti->introduction_required_railtypes;
 
@@ -295,13 +295,13 @@ RailTypes GetRailTypes(bool introduces)
 
			} else {
 
				SetBit(rts, rvi->railtype);
 
			}
 
		}
 
	}
 

	
 
	if (introduces) return AddDateIntroducedRailTypes(rts, MAX_DAY);
 
	if (introduces) return AddDateIntroducedRailTypes(rts, MAX_DATE);
 
	return rts;
 
}
 

	
 
/**
 
 * Get the rail type for a given label.
 
 * @param label the railtype label.
src/road.cpp
Show inline comments
 
@@ -160,13 +160,13 @@ RoadTypes AddDateIntroducedRoadTypes(Roa
 
	for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
 
		const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
 
		/* Unused road type. */
 
		if (rti->label == 0) continue;
 

	
 
		/* Not date introduced. */
 
		if (!IsInsideMM(rti->introduction_date, 0, MAX_DAY)) continue;
 
		if (!IsInsideMM(rti->introduction_date, 0, MAX_DATE)) continue;
 

	
 
		/* Not yet introduced at this date. */
 
		if (rti->introduction_date > date) continue;
 

	
 
		/* Have we introduced all required roadtypes? */
 
		RoadTypes required = rti->introduction_required_roadtypes;
 
@@ -228,13 +228,13 @@ RoadTypes GetRoadTypes(bool introduces)
 
			rts |= GetRoadTypeInfo(rvi->roadtype)->introduces_roadtypes;
 
		} else {
 
			SetBit(rts, rvi->roadtype);
 
		}
 
	}
 

	
 
	if (introduces) return AddDateIntroducedRoadTypes(rts, MAX_DAY);
 
	if (introduces) return AddDateIntroducedRoadTypes(rts, MAX_DATE);
 
	return rts;
 
}
 

	
 
/**
 
 * Get the road type for a given label.
 
 * @param label the roadtype label.
 
@@ -289,10 +289,10 @@ RoadTypes ExistingRoadTypes(CompanyID c)
 
		if (e->company_avail != MAX_UVALUE(CompanyMask)) continue;
 

	
 
		known_roadtypes |= GetRoadTypeInfo(e->u.road.roadtype)->introduces_roadtypes;
 
	}
 

	
 
	/* Get the date introduced roadtypes as well. */
 
	known_roadtypes = AddDateIntroducedRoadTypes(known_roadtypes, MAX_DAY);
 
	known_roadtypes = AddDateIntroducedRoadTypes(known_roadtypes, MAX_DATE);
 

	
 
	return known_roadtypes;
 
}
src/table/object_land.h
Show inline comments
 
@@ -118,13 +118,13 @@ static const DrawTileSprites _object_hq[
 
	TILE_SPRITE_LINE(SPR_HUGEHQ_EAST_GROUND,   _object_hq_huge_east)
 
	TILE_SPRITE_LINE(SPR_HUGEHQ_SOUTH,         _object_nothing)
 
};
 

	
 
#undef TILE_SPRITE_LINE
 

	
 
#define M(name, size, build_cost_multiplier, clear_cost_multiplier, height, climate, gen_amount, flags) { GRFFilePropsBase<2>(), {0, 0, 0, 0}, INVALID_OBJECT_CLASS, name, climate, size, build_cost_multiplier, clear_cost_multiplier, 0, MAX_DAY + 1, flags, 0, height, 1, gen_amount }
 
#define M(name, size, build_cost_multiplier, clear_cost_multiplier, height, climate, gen_amount, flags) { GRFFilePropsBase<2>(), {0, 0, 0, 0}, INVALID_OBJECT_CLASS, name, climate, size, build_cost_multiplier, clear_cost_multiplier, 0, MAX_DATE + 1, flags, 0, height, 1, gen_amount }
 

	
 
/* Climates
 
 * T = Temperate
 
 * A = Sub-Arctic
 
 * S = Sub-Tropic
 
 * Y = Toyland */
src/timer/timer_game_calendar.cpp
Show inline comments
 
@@ -128,13 +128,13 @@ static const uint16 _accum_days_for_mont
 
	/* Day-offset in a leap year */
 
	int days = _accum_days_for_month[month] + day - 1;
 

	
 
	/* Account for the missing of the 29th of February in non-leap years */
 
	if (!TimerGameCalendar::IsLeapYear(year) && days >= ACCUM_MAR) days--;
 

	
 
	return DAYS_TILL(year) + days;
 
	return DateAtStartOfYear(year) + days;
 
}
 

	
 
/**
 
 * Checks whether the given year is a leap year or not.
 
 * @param yr The year to check.
 
 * @return True if \c yr is a leap year, otherwise false.
src/timetable_cmd.cpp
Show inline comments
 
@@ -300,17 +300,17 @@ CommandCost CmdSetTimetableStart(DoComma
 
	CommandCost ret = CheckOwnership(v->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	int total_duration = v->orders->GetTimetableTotalDuration();
 

	
 
	/* 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_DAY) return CMD_ERROR;
 
	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 (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_DAY) return CMD_ERROR;
 
	if (timetable_all && start_date + total_duration / DAY_TICKS > MAX_DATE) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		std::vector<Vehicle *> vehs;
 

	
 
		if (timetable_all) {
 
			for (Vehicle *w = v->orders->GetFirstSharedVehicle(); w != nullptr; w = w->NextShared()) {
src/town_cmd.cpp
Show inline comments
 
@@ -870,13 +870,13 @@ RoadType GetTownRoadType(const Town *t)
 
		if (rti->label == 0) continue;
 

	
 
		/* Can town build this road. */
 
		if (!HasBit(rti->flags, ROTF_TOWN_BUILD)) continue;
 

	
 
		/* Not yet introduced at this date. */
 
		if (IsInsideMM(rti->introduction_date, 0, MAX_DAY) && rti->introduction_date > TimerGameCalendar::date) continue;
 
		if (IsInsideMM(rti->introduction_date, 0, MAX_DATE) && rti->introduction_date > TimerGameCalendar::date) continue;
 

	
 
		if (best != nullptr) {
 
			if ((rti->max_speed == 0 ? assume_max_speed : rti->max_speed) < (best->max_speed == 0 ? assume_max_speed : best->max_speed)) continue;
 
		}
 

	
 
		best_rt = rt;
src/vehicle.cpp
Show inline comments
 
@@ -1367,13 +1367,13 @@ bool Vehicle::HandleBreakdown()
 
/**
 
 * Update age of a vehicle.
 
 * @param v Vehicle to update.
 
 */
 
void AgeVehicle(Vehicle *v)
 
{
 
	if (v->age < MAX_DAY) {
 
	if (v->age < MAX_DATE) {
 
		v->age++;
 
		if (v->IsPrimaryVehicle() && v->age == VEHICLE_PROFIT_MIN_AGE + 1) GroupStatistics::VehicleReachedMinAge(v);
 
	}
 

	
 
	if (!v->IsPrimaryVehicle() && (v->type != VEH_TRAIN || !Train::From(v)->IsEngine())) return;
 

	
0 comments (0 inline, 0 general)