Codechange: make TimerGameCalendar Date and Year types strongly typed (#10761)

This commit is contained in:
Patric Stout
2023-08-12 20:14:21 +02:00
committed by GitHub
parent 0238a2b567
commit 299570b2c1
55 changed files with 390 additions and 203 deletions

View File

@@ -63,5 +63,5 @@
{
if (!IsValidBaseStation(station_id)) return ScriptDate::DATE_INVALID;
return (ScriptDate::Date)::BaseStation::Get(station_id)->build_date;
return (ScriptDate::Date)(int32_t)::BaseStation::Get(station_id)->build_date;
}

View File

@@ -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)(int32_t)ci->join_date;
}

View File

@@ -22,7 +22,7 @@
/* static */ ScriptDate::Date ScriptDate::GetCurrentDate()
{
return (ScriptDate::Date)TimerGameCalendar::date;
return (ScriptDate::Date)(int32_t)TimerGameCalendar::date;
}
/* static */ SQInteger ScriptDate::GetYear(ScriptDate::Date date)
@@ -31,7 +31,7 @@
::TimerGameCalendar::YearMonthDay ymd;
::TimerGameCalendar::ConvertDateToYMD(date, &ymd);
return ymd.year;
return (int32_t)ymd.year;
}
/* static */ SQInteger ScriptDate::GetMonth(ScriptDate::Date date)
@@ -58,7 +58,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)::TimerGameCalendar::ConvertYMDToDate(year, month - 1, day_of_month);
return (ScriptDate::Date)(int32_t)::TimerGameCalendar::ConvertYMDToDate(year, month - 1, day_of_month);
}
/* static */ SQInteger ScriptDate::GetSystemTime()

View File

@@ -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 = (int32_t)::INVALID_DATE, ///< A value representing an invalid date.
};
/**

View File

@@ -139,7 +139,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 (int32_t)::Engine::Get(engine_id)->GetLifeLengthInDays();
}
/* static */ Money ScriptEngine::GetRunningCost(EngineID engine_id)
@@ -179,7 +179,7 @@
{
if (!IsValidEngine(engine_id)) return ScriptDate::DATE_INVALID;
return (ScriptDate::Date)::Engine::Get(engine_id)->intro_date;
return (ScriptDate::Date)(int32_t)::Engine::Get(engine_id)->intro_date;
}
/* static */ ScriptVehicle::VehicleType ScriptEngine::GetVehicleType(EngineID engine_id)

View File

@@ -53,7 +53,7 @@
{
Industry *i = Industry::GetIfValid(industry_id);
if (i == nullptr) return ScriptDate::DATE_INVALID;
return (ScriptDate::Date)i->construction_date;
return (ScriptDate::Date)(int32_t)i->construction_date;
}
/* static */ bool ScriptIndustry::SetText(IndustryID industry_id, Text *text)
@@ -222,7 +222,7 @@
{
Industry *i = Industry::GetIfValid(industry_id);
if (i == nullptr) return 0;
return i->last_prod_year;
return (int32_t)i->last_prod_year;
}
/* static */ ScriptDate::Date ScriptIndustry::GetCargoLastAcceptedDate(IndustryID industry_id, CargoID cargo_type)
@@ -232,11 +232,11 @@
if (!::IsValidCargoID(cargo_type)) {
auto it = std::max_element(std::begin(i->accepted), std::end(i->accepted), [](const auto &a, const auto &b) { return a.last_accepted < b.last_accepted; });
return (ScriptDate::Date)it->last_accepted;
return (ScriptDate::Date)(int32_t)it->last_accepted;
} else {
auto it = i->GetCargoAccepted(cargo_type);
if (it == std::end(i->accepted)) return ScriptDate::DATE_INVALID;
return (ScriptDate::Date)it->last_accepted;
return (ScriptDate::Date)(int32_t)it->last_accepted;
}
}

View File

@@ -182,7 +182,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)(int32_t)StoryPage::Get(story_page_id)->date;
}
/* static */ bool ScriptStoryPage::SetDate(StoryPageID story_page_id, ScriptDate::Date date)

View File

@@ -311,7 +311,7 @@
{
if (!IsValidVehicle(vehicle_id)) return -1;
return ::Vehicle::Get(vehicle_id)->age;
return (int32_t)::Vehicle::Get(vehicle_id)->age;
}
/* static */ SQInteger ScriptVehicle::GetWagonAge(VehicleID vehicle_id, SQInteger wagon)
@@ -323,21 +323,21 @@
if (v->type == VEH_TRAIN) {
while (wagon-- > 0) v = ::Train::From(v)->GetNextUnit();
}
return v->age;
return (int32_t)v->age;
}
/* static */ SQInteger ScriptVehicle::GetMaxAge(VehicleID vehicle_id)
{
if (!IsPrimaryVehicle(vehicle_id)) return -1;
return ::Vehicle::Get(vehicle_id)->max_age;
return (int32_t)::Vehicle::Get(vehicle_id)->max_age;
}
/* 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 (int32_t)(::Vehicle::Get(vehicle_id)->max_age - ::Vehicle::Get(vehicle_id)->age);
}
/* static */ SQInteger ScriptVehicle::GetCurrentSpeed(VehicleID vehicle_id)