Codechange: Add base() method to StrongType to allow access to the base type without casting. (#11445)
This removes the ability to explicitly cast to the base type, but the requirement to use .base() means the conversion is still explicit.
This commit is contained in:
@@ -63,5 +63,5 @@
|
||||
{
|
||||
if (!IsValidBaseStation(station_id)) return ScriptDate::DATE_INVALID;
|
||||
|
||||
return (ScriptDate::Date)(int32_t)::BaseStation::Get(station_id)->build_date;
|
||||
return (ScriptDate::Date)::BaseStation::Get(station_id)->build_date.base();
|
||||
}
|
||||
|
@@ -83,8 +83,8 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance)
|
||||
|
||||
switch (vehicle_type) {
|
||||
case ScriptVehicle::VT_ROAD:
|
||||
ScriptObject::SetCallbackVariable(0, static_cast<uint32_t>(start));
|
||||
ScriptObject::SetCallbackVariable(1, static_cast<uint32_t>(end));
|
||||
ScriptObject::SetCallbackVariable(0, start.base());
|
||||
ScriptObject::SetCallbackVariable(1, end.base());
|
||||
return ScriptObject::Command<CMD_BUILD_BRIDGE>::Do(&::_DoCommandReturnBuildBridge1, end, start, TRANSPORT_ROAD, bridge_id, ScriptRoad::GetCurrentRoadType());
|
||||
case ScriptVehicle::VT_RAIL:
|
||||
return ScriptObject::Command<CMD_BUILD_BRIDGE>::Do(end, start, TRANSPORT_RAIL, bridge_id, ScriptRail::GetCurrentRailType());
|
||||
|
@@ -50,5 +50,5 @@ static NetworkClientInfo *FindClientInfo(ScriptClient::ClientID client)
|
||||
{
|
||||
NetworkClientInfo *ci = FindClientInfo(client);
|
||||
if (ci == nullptr) return ScriptDate::DATE_INVALID;
|
||||
return (ScriptDate::Date)(int32_t)ci->join_date;
|
||||
return (ScriptDate::Date)ci->join_date.base();
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@
|
||||
|
||||
/* static */ ScriptDate::Date ScriptDate::GetCurrentDate()
|
||||
{
|
||||
return (ScriptDate::Date)(int32_t)TimerGameCalendar::date;
|
||||
return (ScriptDate::Date)TimerGameCalendar::date.base();
|
||||
}
|
||||
|
||||
/* static */ SQInteger ScriptDate::GetYear(ScriptDate::Date date)
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
::TimerGameCalendar::YearMonthDay ymd;
|
||||
::TimerGameCalendar::ConvertDateToYMD(date, &ymd);
|
||||
return (int32_t)ymd.year;
|
||||
return ymd.year.base();
|
||||
}
|
||||
|
||||
/* 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 > CalendarTime::MAX_YEAR) return DATE_INVALID;
|
||||
|
||||
return (ScriptDate::Date)(int32_t)::TimerGameCalendar::ConvertYMDToDate(year, month - 1, day_of_month);
|
||||
return (ScriptDate::Date)::TimerGameCalendar::ConvertYMDToDate(year, month - 1, day_of_month).base();
|
||||
}
|
||||
|
||||
/* static */ SQInteger ScriptDate::GetSystemTime()
|
||||
|
@@ -31,7 +31,7 @@ public:
|
||||
* compose valid date values for a known year, month and day.
|
||||
*/
|
||||
enum Date {
|
||||
DATE_INVALID = (int32_t)::CalendarTime::INVALID_DATE, ///< A value representing an invalid date.
|
||||
DATE_INVALID = ::CalendarTime::INVALID_DATE.base(), ///< A value representing an invalid date.
|
||||
};
|
||||
|
||||
/**
|
||||
|
@@ -30,7 +30,7 @@ ScriptDepotList::ScriptDepotList(ScriptTile::TransportType transport_type)
|
||||
for (const Station *st : Station::Iterate()) {
|
||||
if (st->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity()) {
|
||||
for (uint i = 0; i < st->airport.GetNumHangars(); i++) {
|
||||
this->AddItem(static_cast<uint32_t>(st->airport.GetHangarTile(i)));
|
||||
this->AddItem(st->airport.GetHangarTile(i).base());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,6 @@ ScriptDepotList::ScriptDepotList(ScriptTile::TransportType transport_type)
|
||||
|
||||
/* Handle 'standard' depots. */
|
||||
for (const Depot *depot : Depot::Iterate()) {
|
||||
if ((::GetTileOwner(depot->xy) == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity()) && ::IsTileType(depot->xy, tile_type)) this->AddItem(static_cast<uint32_t>(depot->xy));
|
||||
if ((::GetTileOwner(depot->xy) == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity()) && ::IsTileType(depot->xy, tile_type)) this->AddItem(depot->xy.base());
|
||||
}
|
||||
}
|
||||
|
@@ -139,7 +139,7 @@
|
||||
if (!IsValidEngine(engine_id)) return -1;
|
||||
if (GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL && IsWagon(engine_id)) return -1;
|
||||
|
||||
return (int32_t)::Engine::Get(engine_id)->GetLifeLengthInDays();
|
||||
return ::Engine::Get(engine_id)->GetLifeLengthInDays().base();
|
||||
}
|
||||
|
||||
/* static */ Money ScriptEngine::GetRunningCost(EngineID engine_id)
|
||||
@@ -179,7 +179,7 @@
|
||||
{
|
||||
if (!IsValidEngine(engine_id)) return ScriptDate::DATE_INVALID;
|
||||
|
||||
return (ScriptDate::Date)(int32_t)::Engine::Get(engine_id)->intro_date;
|
||||
return (ScriptDate::Date)::Engine::Get(engine_id)->intro_date.base();
|
||||
}
|
||||
|
||||
/* static */ ScriptVehicle::VehicleType ScriptEngine::GetVehicleType(EngineID engine_id)
|
||||
|
@@ -53,7 +53,7 @@
|
||||
{
|
||||
Industry *i = Industry::GetIfValid(industry_id);
|
||||
if (i == nullptr) return ScriptDate::DATE_INVALID;
|
||||
return (ScriptDate::Date)(int32_t)i->construction_date;
|
||||
return (ScriptDate::Date)i->construction_date.base();
|
||||
}
|
||||
|
||||
/* 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 (int32_t)i->last_prod_year;
|
||||
return i->last_prod_year.base();
|
||||
}
|
||||
|
||||
/* 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)(int32_t)it->last_accepted;
|
||||
return (ScriptDate::Date)it->last_accepted.base();
|
||||
} else {
|
||||
auto it = i->GetCargoAccepted(cargo_type);
|
||||
if (it == std::end(i->accepted)) return ScriptDate::DATE_INVALID;
|
||||
return (ScriptDate::Date)(int32_t)it->last_accepted;
|
||||
return (ScriptDate::Date)it->last_accepted.base();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
class ScriptMap : public ScriptObject {
|
||||
public:
|
||||
static const int TILE_INVALID = static_cast<uint32_t>(INVALID_TILE); ///< Invalid TileIndex.
|
||||
static const int TILE_INVALID = INVALID_TILE.base(); ///< Invalid TileIndex.
|
||||
|
||||
/**
|
||||
* Checks whether the given tile is valid.
|
||||
|
@@ -382,8 +382,8 @@ static bool NormaliseTileOffset(int32_t *tile)
|
||||
/* static */ SQInteger ScriptRoad::CanBuildConnectedRoadParts(ScriptTile::Slope slope_, Array<> &&existing, TileIndex start_, TileIndex end_)
|
||||
{
|
||||
::Slope slope = (::Slope)slope_;
|
||||
int32_t start = static_cast<uint32_t>(start_);
|
||||
int32_t end = static_cast<uint32_t>(end_);
|
||||
int32_t start = start_.base();
|
||||
int32_t end = end_.base();
|
||||
|
||||
/* The start tile and end tile cannot be the same tile either. */
|
||||
if (start == end) return -1;
|
||||
|
@@ -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)(int32_t)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)
|
||||
|
@@ -21,14 +21,14 @@ void ScriptTileList::AddRectangle(TileIndex t1, TileIndex t2)
|
||||
if (!::IsValidTile(t2)) return;
|
||||
|
||||
TileArea ta(t1, t2);
|
||||
for (TileIndex t : ta) this->AddItem(static_cast<uint32_t>(t));
|
||||
for (TileIndex t : ta) this->AddItem(t.base());
|
||||
}
|
||||
|
||||
void ScriptTileList::AddTile(TileIndex tile)
|
||||
{
|
||||
if (!::IsValidTile(tile)) return;
|
||||
|
||||
this->AddItem(static_cast<uint32_t>(tile));
|
||||
this->AddItem(tile.base());
|
||||
}
|
||||
|
||||
void ScriptTileList::RemoveRectangle(TileIndex t1, TileIndex t2)
|
||||
@@ -37,14 +37,14 @@ void ScriptTileList::RemoveRectangle(TileIndex t1, TileIndex t2)
|
||||
if (!::IsValidTile(t2)) return;
|
||||
|
||||
TileArea ta(t1, t2);
|
||||
for (TileIndex t : ta) this->RemoveItem(static_cast<uint32_t>(t));
|
||||
for (TileIndex t : ta) this->RemoveItem(t.base());
|
||||
}
|
||||
|
||||
void ScriptTileList::RemoveTile(TileIndex tile)
|
||||
{
|
||||
if (!::IsValidTile(tile)) return;
|
||||
|
||||
this->RemoveItem(static_cast<uint32_t>(tile));
|
||||
this->RemoveItem(tile.base());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -93,7 +93,7 @@ static void _DoCommandReturnBuildTunnel1(class ScriptInstance *instance)
|
||||
/* For rail we do nothing special */
|
||||
return ScriptObject::Command<CMD_BUILD_TUNNEL>::Do(start, TRANSPORT_RAIL, ScriptRail::GetCurrentRailType());
|
||||
} else {
|
||||
ScriptObject::SetCallbackVariable(0, static_cast<uint32_t>(start));
|
||||
ScriptObject::SetCallbackVariable(0, start.base());
|
||||
return ScriptObject::Command<CMD_BUILD_TUNNEL>::Do(&::_DoCommandReturnBuildTunnel1, start, TRANSPORT_ROAD, ScriptRoad::GetCurrentRoadType());
|
||||
}
|
||||
}
|
||||
|
@@ -311,7 +311,7 @@
|
||||
{
|
||||
if (!IsValidVehicle(vehicle_id)) return -1;
|
||||
|
||||
return (int32_t)::Vehicle::Get(vehicle_id)->age;
|
||||
return ::Vehicle::Get(vehicle_id)->age.base();
|
||||
}
|
||||
|
||||
/* 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 (int32_t)v->age;
|
||||
return v->age.base();
|
||||
}
|
||||
|
||||
/* static */ SQInteger ScriptVehicle::GetMaxAge(VehicleID vehicle_id)
|
||||
{
|
||||
if (!IsPrimaryVehicle(vehicle_id)) return -1;
|
||||
|
||||
return (int32_t)::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 (int32_t)(::Vehicle::Get(vehicle_id)->max_age - ::Vehicle::Get(vehicle_id)->age);
|
||||
return (::Vehicle::Get(vehicle_id)->max_age - ::Vehicle::Get(vehicle_id)->age).base();
|
||||
}
|
||||
|
||||
/* static */ SQInteger ScriptVehicle::GetCurrentSpeed(VehicleID vehicle_id)
|
||||
|
Reference in New Issue
Block a user