Strong typedef: Use strong typedefs for date, date tick, minutes types
Add delta types Adjust/add type conversion functions Add various utility methods on types Remove the various minute macros Fix some minute conversion inconsistencies
This commit is contained in:
@@ -57,5 +57,5 @@
|
||||
{
|
||||
if (!IsValidBaseStation(station_id)) return ScriptDate::DATE_INVALID;
|
||||
|
||||
return (ScriptDate::Date)::BaseStation::Get(station_id)->build_date;
|
||||
return (ScriptDate::Date)::BaseStation::Get(station_id)->build_date.base();
|
||||
}
|
||||
|
@@ -50,5 +50,5 @@ static NetworkClientInfo *FindClientInfo(ScriptClient::ClientID client)
|
||||
{
|
||||
NetworkClientInfo *ci = FindClientInfo(client);
|
||||
if (ci == nullptr) return ScriptDate::DATE_INVALID;
|
||||
return (ScriptDate::Date)ci->join_date;
|
||||
return (ScriptDate::Date)ci->join_date.base();
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@
|
||||
|
||||
/* static */ ScriptDate::Date ScriptDate::GetCurrentDate()
|
||||
{
|
||||
return (ScriptDate::Date)_date;
|
||||
return (ScriptDate::Date)_date.base();
|
||||
}
|
||||
|
||||
/* static */ SQInteger ScriptDate::GetDayLengthFactor()
|
||||
@@ -66,7 +66,7 @@
|
||||
if (day_of_month < 1 || day_of_month > 31) return DATE_INVALID;
|
||||
if (year < 0 || year > MAX_YEAR) return DATE_INVALID;
|
||||
|
||||
return (ScriptDate::Date)::ConvertYMDToDate(year, month - 1, day_of_month);
|
||||
return (ScriptDate::Date)::ConvertYMDToDate(year, month - 1, day_of_month).base();
|
||||
}
|
||||
|
||||
/* static */ SQInteger ScriptDate::GetSystemTime()
|
||||
@@ -88,17 +88,17 @@
|
||||
|
||||
/* static */ SQInteger ScriptDate::GetCurrentScaledDateTicks()
|
||||
{
|
||||
return _scaled_date_ticks;
|
||||
return _scaled_date_ticks.base();
|
||||
}
|
||||
|
||||
/* static */ SQInteger ScriptDate::GetHour(DateTicksScaled ticks)
|
||||
/* static */ SQInteger ScriptDate::GetHour(SQInteger ticks)
|
||||
{
|
||||
Minutes minutes = (ticks / _settings_game.game_time.ticks_per_minute) + _settings_game.game_time.clock_offset;
|
||||
return MINUTES_HOUR(minutes);
|
||||
TickMinutes minutes = _settings_game.game_time.ToTickMinutes(DateTicksScaled(ticks));
|
||||
return minutes.ClockHour();
|
||||
}
|
||||
|
||||
/* static */ SQInteger ScriptDate::GetMinute(DateTicksScaled ticks)
|
||||
/* static */ SQInteger ScriptDate::GetMinute(SQInteger ticks)
|
||||
{
|
||||
Minutes minutes = (ticks / _settings_game.game_time.ticks_per_minute) + _settings_game.game_time.clock_offset;
|
||||
return MINUTES_MINUTE(minutes);
|
||||
TickMinutes minutes = _settings_game.game_time.ToTickMinutes(DateTicksScaled(ticks));
|
||||
return minutes.ClockMinute();
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ public:
|
||||
* compose valid date values for a known year, month and day.
|
||||
*/
|
||||
enum Date {
|
||||
DATE_INVALID = ::INVALID_DATE, ///< A value representing an invalid date.
|
||||
DATE_INVALID = ::INVALID_DATE.base(), ///< A value representing an invalid date.
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -96,9 +96,9 @@ public:
|
||||
|
||||
static SQInteger GetCurrentScaledDateTicks();
|
||||
|
||||
static SQInteger GetHour(DateTicksScaled ticks);
|
||||
static SQInteger GetHour(SQInteger ticks);
|
||||
|
||||
static SQInteger GetMinute(DateTicksScaled ticks);
|
||||
static SQInteger GetMinute(SQInteger ticks);
|
||||
};
|
||||
|
||||
#endif /* SCRIPT_DATE_HPP */
|
||||
|
@@ -131,7 +131,7 @@
|
||||
if (!IsValidEngine(engine_id)) return -1;
|
||||
if (GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL && IsWagon(engine_id)) return -1;
|
||||
|
||||
return ::Engine::Get(engine_id)->GetLifeLengthInDays();
|
||||
return ::Engine::Get(engine_id)->GetLifeLengthInDays().base();
|
||||
}
|
||||
|
||||
/* static */ Money ScriptEngine::GetRunningCost(EngineID engine_id)
|
||||
@@ -171,7 +171,7 @@
|
||||
{
|
||||
if (!IsValidEngine(engine_id)) return ScriptDate::DATE_INVALID;
|
||||
|
||||
return (ScriptDate::Date)::Engine::Get(engine_id)->intro_date;
|
||||
return (ScriptDate::Date)::Engine::Get(engine_id)->intro_date.base();
|
||||
}
|
||||
|
||||
/* static */ ScriptVehicle::VehicleType ScriptEngine::GetVehicleType(EngineID engine_id)
|
||||
|
@@ -52,7 +52,7 @@
|
||||
{
|
||||
Industry *i = Industry::GetIfValid(industry_id);
|
||||
if (i == nullptr) return ScriptDate::DATE_INVALID;
|
||||
return (ScriptDate::Date)i->construction_date;
|
||||
return (ScriptDate::Date)i->construction_date.base();
|
||||
}
|
||||
|
||||
/* static */ bool ScriptIndustry::SetText(IndustryID industry_id, Text *text)
|
||||
@@ -230,11 +230,11 @@
|
||||
if (i == nullptr) return ScriptDate::DATE_INVALID;
|
||||
|
||||
if (cargo_type == CT_INVALID) {
|
||||
return (ScriptDate::Date)std::accumulate(std::begin(i->last_cargo_accepted_at), std::end(i->last_cargo_accepted_at), 0, [](Date a, Date b) { return std::max(a, b); });
|
||||
return (ScriptDate::Date)std::accumulate(std::begin(i->last_cargo_accepted_at), std::end(i->last_cargo_accepted_at), Date(0), [](Date a, Date b) { return std::max(a, b); }).base();
|
||||
} else {
|
||||
int index = i->GetCargoAcceptedIndex(cargo_type);
|
||||
if (index < 0) return ScriptDate::DATE_INVALID;
|
||||
return (ScriptDate::Date)i->last_cargo_accepted_at[index];
|
||||
return (ScriptDate::Date)i->last_cargo_accepted_at[index].base();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -190,7 +190,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
|
||||
EnforcePrecondition(ScriptDate::DATE_INVALID, IsValidStoryPage(story_page_id));
|
||||
EnforceDeityMode(ScriptDate::DATE_INVALID);
|
||||
|
||||
return (ScriptDate::Date)StoryPage::Get(story_page_id)->date;
|
||||
return (ScriptDate::Date)StoryPage::Get(story_page_id)->date.base();
|
||||
}
|
||||
|
||||
/* static */ bool ScriptStoryPage::SetDate(StoryPageID story_page_id, ScriptDate::Date date)
|
||||
|
@@ -310,7 +310,7 @@
|
||||
{
|
||||
if (!IsValidVehicle(vehicle_id)) return -1;
|
||||
|
||||
return ::Vehicle::Get(vehicle_id)->age;
|
||||
return ::Vehicle::Get(vehicle_id)->age.base();
|
||||
}
|
||||
|
||||
/* static */ SQInteger ScriptVehicle::GetWagonAge(VehicleID vehicle_id, SQInteger wagon)
|
||||
@@ -322,21 +322,21 @@
|
||||
if (v->type == VEH_TRAIN) {
|
||||
while (wagon-- > 0) v = ::Train::From(v)->GetNextUnit();
|
||||
}
|
||||
return v->age;
|
||||
return v->age.base();
|
||||
}
|
||||
|
||||
/* static */ SQInteger ScriptVehicle::GetMaxAge(VehicleID vehicle_id)
|
||||
{
|
||||
if (!IsPrimaryVehicle(vehicle_id)) return -1;
|
||||
|
||||
return ::Vehicle::Get(vehicle_id)->max_age;
|
||||
return ::Vehicle::Get(vehicle_id)->max_age.base();
|
||||
}
|
||||
|
||||
/* static */ SQInteger ScriptVehicle::GetAgeLeft(VehicleID vehicle_id)
|
||||
{
|
||||
if (!IsPrimaryVehicle(vehicle_id)) return -1;
|
||||
|
||||
return ::Vehicle::Get(vehicle_id)->max_age - ::Vehicle::Get(vehicle_id)->age;
|
||||
return ::Vehicle::Get(vehicle_id)->max_age.base() - ::Vehicle::Get(vehicle_id)->age.base();
|
||||
}
|
||||
|
||||
/* static */ SQInteger ScriptVehicle::GetCurrentSpeed(VehicleID vehicle_id)
|
||||
|
Reference in New Issue
Block a user