1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-23 20:24:12 +01:00

Codechange: replace INVALID_X with XID::Invalid() for PoolIDs

This commit is contained in:
Rubidium
2025-02-16 19:29:53 +01:00
committed by rubidium42
parent d13b0e0813
commit fd4adc55e3
157 changed files with 744 additions and 772 deletions

View File

@@ -77,7 +77,7 @@
EnforcePrecondition(false, IsValidAirportType(type));
EnforcePrecondition(false, station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id));
return ScriptObject::Command<CMD_BUILD_AIRPORT>::Do(tile, type, 0, (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION), station_id != ScriptStation::STATION_JOIN_ADJACENT);
return ScriptObject::Command<CMD_BUILD_AIRPORT>::Do(tile, type, 0, (ScriptStation::IsValidStation(station_id) ? station_id : StationID::Invalid()), station_id != ScriptStation::STATION_JOIN_ADJACENT);
}
/* static */ bool ScriptAirport::RemoveAirport(TileIndex tile)
@@ -148,11 +148,11 @@
/* static */ TownID ScriptAirport::GetNearestTown(TileIndex tile, AirportType type)
{
if (!::IsValidTile(tile)) return INVALID_TOWN;
if (!IsAirportInformationAvailable(type)) return INVALID_TOWN;
if (!::IsValidTile(tile)) return TownID::Invalid();
if (!IsAirportInformationAvailable(type)) return TownID::Invalid();
const AirportSpec *as = AirportSpec::Get(type);
if (!as->IsWithinMapBounds(0, tile)) return INVALID_TOWN;
if (!as->IsWithinMapBounds(0, tile)) return TownID::Invalid();
uint dist;
const auto &layout = as->layouts[0];

View File

@@ -22,7 +22,7 @@ class ScriptBaseStation : public ScriptObject {
public:
static constexpr StationID STATION_NEW = ::NEW_STATION; ///< Build a new station
static constexpr StationID STATION_JOIN_ADJACENT = ::ADJACENT_STATION; ///< Join an neighbouring station if one exists
static constexpr StationID STATION_INVALID = ::INVALID_STATION; ///< Invalid station id.
static constexpr StationID STATION_INVALID = ::StationID::Invalid(); ///< Invalid station id.
/**
* Checks whether the given basestation is valid and owned by you.

View File

@@ -105,7 +105,7 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance)
DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start);
DiagDirection dir_2 = ::ReverseDiagDir(dir_1);
return ScriptObject::Command<CMD_BUILD_ROAD>::Do(&::_DoCommandReturnBuildBridge2, start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2), (::RoadType)ScriptRoad::GetCurrentRoadType(), DRD_NONE, INVALID_TOWN);
return ScriptObject::Command<CMD_BUILD_ROAD>::Do(&::_DoCommandReturnBuildBridge2, start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2), (::RoadType)ScriptRoad::GetCurrentRoadType(), DRD_NONE, TownID::Invalid());
}
/* static */ bool ScriptBridge::_BuildBridgeRoad2()
@@ -119,7 +119,7 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance)
DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start);
DiagDirection dir_2 = ::ReverseDiagDir(dir_1);
return ScriptObject::Command<CMD_BUILD_ROAD>::Do(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1), (::RoadType)ScriptRoad::GetCurrentRoadType(), DRD_NONE, INVALID_TOWN);
return ScriptObject::Command<CMD_BUILD_ROAD>::Do(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1), (::RoadType)ScriptRoad::GetCurrentRoadType(), DRD_NONE, TownID::Invalid());
}
/* static */ bool ScriptBridge::RemoveBridge(TileIndex tile)

View File

@@ -33,13 +33,13 @@
/* If this assert gets triggered, then ScriptCompany::ResolveCompanyID needed to be called before. */
assert(company != ScriptCompany::COMPANY_SELF && company != ScriptCompany::COMPANY_SPECTATOR);
if (company == ScriptCompany::COMPANY_INVALID) return ::INVALID_COMPANY;
if (company == ScriptCompany::COMPANY_INVALID) return ::CompanyID::Invalid();
return static_cast<::CompanyID>(company);
}
/* static */ ScriptCompany::CompanyID ScriptCompany::ToScriptCompanyID(::CompanyID company)
{
if (company == ::INVALID_COMPANY) return ScriptCompany::COMPANY_INVALID;
if (company == ::CompanyID::Invalid()) return ScriptCompany::COMPANY_INVALID;
return static_cast<::ScriptCompany::CompanyID>(company.base());
}

View File

@@ -30,8 +30,8 @@ public:
/** Different constants related to CompanyID. */
enum CompanyID {
/* Note: these values represent part of the in-game Owner enum */
COMPANY_FIRST = ::COMPANY_FIRST.base(), ///< The first available company.
COMPANY_LAST = ::MAX_COMPANIES, ///< The last available company.
COMPANY_FIRST = ::CompanyID::Begin().base(), ///< The first available company.
COMPANY_LAST = ::CompanyID::End().base(), ///< The last available company.
/* Custom added value, only valid for this API */
COMPANY_INVALID = -1, ///< An invalid company.

View File

@@ -38,7 +38,7 @@
(type == GT_INDUSTRY && ScriptIndustry::IsValidIndustry(static_cast<IndustryID>(destination))) ||
(type == GT_TOWN && ScriptTown::IsValidTown(static_cast<TownID>(destination))) ||
(type == GT_COMPANY && ScriptCompany::ResolveCompanyID(ScriptCompany::ToScriptCompanyID(static_cast<::CompanyID>(destination))) != ScriptCompany::COMPANY_INVALID) ||
(type == GT_STORY_PAGE && story_page != nullptr && (c == INVALID_COMPANY ? story_page->company == INVALID_COMPANY : story_page->company == INVALID_COMPANY || story_page->company == c));
(type == GT_STORY_PAGE && story_page != nullptr && (c == CompanyID::Invalid() ? story_page->company == CompanyID::Invalid() : story_page->company == CompanyID::Invalid() || story_page->company == c));
}
/* static */ GoalID ScriptGoal::New(ScriptCompany::CompanyID company, Text *goal, GoalType type, SQInteger destination)

View File

@@ -25,7 +25,7 @@
*/
class ScriptGoal : public ScriptObject {
public:
static constexpr GoalID GOAL_INVALID = ::INVALID_GOAL; ///< An invalid goal id.
static constexpr GoalID GOAL_INVALID = ::GoalID::Invalid(); ///< An invalid goal id.
/**
* Goal types that can be given to a goal.

View File

@@ -65,7 +65,7 @@
EnforcePreconditionEncodedText(false, text);
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_GROUP_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
return ScriptObject::Command<CMD_ALTER_GROUP>::Do(AlterGroupMode::Rename, group_id, ::INVALID_GROUP, text);
return ScriptObject::Command<CMD_ALTER_GROUP>::Do(AlterGroupMode::Rename, group_id, ::GroupID::Invalid(), text);
}
/* static */ std::optional<std::string> ScriptGroup::GetName(GroupID group_id)
@@ -87,7 +87,7 @@
/* static */ GroupID ScriptGroup::GetParent(GroupID group_id)
{
EnforcePrecondition(INVALID_GROUP, IsValidGroup(group_id));
EnforcePrecondition(::GroupID::Invalid(), IsValidGroup(group_id));
const Group *g = ::Group::GetIfValid(group_id);
return g->parent;
@@ -163,8 +163,8 @@
/* static */ EngineID ScriptGroup::GetEngineReplacement(GroupID group_id, EngineID engine_id)
{
EnforceCompanyModeValid(::INVALID_ENGINE);
if (!IsValidGroup(group_id) && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return ::INVALID_ENGINE;
EnforceCompanyModeValid(::EngineID::Invalid());
if (!IsValidGroup(group_id) && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return ::EngineID::Invalid();
return ::EngineReplacementForCompany(Company::Get(ScriptObject::GetCompany()), engine_id, group_id);
}
@@ -174,7 +174,7 @@
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL);
return ScriptObject::Command<CMD_SET_AUTOREPLACE>::Do(group_id, engine_id, ::INVALID_ENGINE, false);
return ScriptObject::Command<CMD_SET_AUTOREPLACE>::Do(group_id, engine_id, ::EngineID::Invalid(), false);
}
/* static */ Money ScriptGroup::GetProfitThisYear(GroupID group_id)

View File

@@ -21,7 +21,7 @@ class ScriptGroup : public ScriptObject {
public:
static constexpr GroupID GROUP_ALL = ::ALL_GROUP; ///< All vehicles are in this group.
static constexpr GroupID GROUP_DEFAULT = ::DEFAULT_GROUP; ///< Vehicles not put in any other group are in this one.
static constexpr GroupID GROUP_INVALID = ::INVALID_GROUP; ///< An invalid group id.
static constexpr GroupID GROUP_INVALID = ::GroupID::Invalid(); ///< An invalid group id.
/**
* Checks whether the given group is valid.

View File

@@ -37,7 +37,7 @@
/* static */ IndustryID ScriptIndustry::GetIndustryID(TileIndex tile)
{
if (!::IsValidTile(tile) || !::IsTileType(tile, MP_INDUSTRY)) return INVALID_INDUSTRY;
if (!::IsValidTile(tile) || !::IsTileType(tile, MP_INDUSTRY)) return IndustryID::Invalid();
return ::GetIndustryIndex(tile);
}

View File

@@ -25,9 +25,9 @@
*/
class ScriptLeagueTable : public ScriptObject {
public:
static constexpr LeagueTableID LEAGUE_TABLE_INVALID = ::INVALID_LEAGUE_TABLE; ///< An invalid league table id.
static constexpr LeagueTableID LEAGUE_TABLE_INVALID = ::LeagueTableID::Invalid(); ///< An invalid league table id.
static constexpr LeagueTableElementID LEAGUE_TABLE_ELEMENT_INVALID = ::INVALID_LEAGUE_TABLE_ELEMENT; ///< An invalid league table element id.
static constexpr LeagueTableElementID LEAGUE_TABLE_ELEMENT_INVALID = ::LeagueTableElementID::Invalid(); ///< An invalid league table element id.
/**
* The type of a link.

View File

@@ -92,7 +92,7 @@
EnforcePrecondition(false, ::IsValidTile(tile));
EnforcePrecondition(false, station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id));
return ScriptObject::Command<CMD_BUILD_DOCK>::Do(tile, ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION, station_id != ScriptStation::STATION_JOIN_ADJACENT);
return ScriptObject::Command<CMD_BUILD_DOCK>::Do(tile, ScriptStation::IsValidStation(station_id) ? station_id : StationID::Invalid(), station_id != ScriptStation::STATION_JOIN_ADJACENT);
}
/* static */ bool ScriptMarine::BuildBuoy(TileIndex tile)

View File

@@ -484,7 +484,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
if (order_flags & OF_GOTO_NEAREST_DEPOT) odaf |= ODATFB_NEAREST_DEPOT;
OrderNonStopFlags onsf = (OrderNonStopFlags)((order_flags & OF_NON_STOP_INTERMEDIATE) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
if (order_flags & OF_GOTO_NEAREST_DEPOT) {
order.MakeGoToDepot(INVALID_DEPOT, odtf, onsf, odaf);
order.MakeGoToDepot(DepotID::Invalid(), odtf, onsf, odaf);
} else {
/* Check explicitly if the order is to a station (for aircraft) or
* to a depot (other vehicle types). */
@@ -680,7 +680,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
EnforceCompanyModeValid(false);
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
return ScriptObject::Command<CMD_CLONE_ORDER>::Do(0, CO_UNSHARE, vehicle_id, ::INVALID_VEHICLE);
return ScriptObject::Command<CMD_CLONE_ORDER>::Do(0, CO_UNSHARE, vehicle_id, VehicleID::Invalid());
}
/* static */ SQInteger ScriptOrder::GetOrderDistance(ScriptVehicle::VehicleType vehicle_type, TileIndex origin_tile, TileIndex dest_tile)

View File

@@ -159,7 +159,7 @@
EnforcePrecondition(false, station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id));
bool adjacent = station_id != ScriptStation::STATION_JOIN_ADJACENT;
return ScriptObject::Command<CMD_BUILD_RAIL_STATION>::Do(tile, (::RailType)GetCurrentRailType(), direction == RAILTRACK_NW_SE ? AXIS_Y : AXIS_X, num_platforms, platform_length, STAT_CLASS_DFLT, 0, ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION, adjacent);
return ScriptObject::Command<CMD_BUILD_RAIL_STATION>::Do(tile, (::RailType)GetCurrentRailType(), direction == RAILTRACK_NW_SE ? AXIS_Y : AXIS_X, num_platforms, platform_length, STAT_CLASS_DFLT, 0, ScriptStation::IsValidStation(station_id) ? station_id : StationID::Invalid(), adjacent);
}
/* static */ bool ScriptRail::BuildNewGRFRailStation(TileIndex tile, RailTrack direction, SQInteger num_platforms, SQInteger platform_length, StationID station_id, CargoType cargo_type, IndustryType source_industry, IndustryType goal_industry, SQInteger distance, bool source_station)
@@ -191,7 +191,7 @@
Axis axis = direction == RAILTRACK_NW_SE ? AXIS_Y : AXIS_X;
bool adjacent = station_id != ScriptStation::STATION_JOIN_ADJACENT;
StationID to_join = ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION;
StationID to_join = ScriptStation::IsValidStation(station_id) ? station_id : StationID::Invalid();
if (res != CALLBACK_FAILED) {
const StationSpec *spec = StationClass::GetByGrf(file->grfid, res);
if (spec == nullptr) {
@@ -213,7 +213,7 @@
EnforcePrecondition(false, GetRailTracks(tile) == RAILTRACK_NE_SW || GetRailTracks(tile) == RAILTRACK_NW_SE);
EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType()));
return ScriptObject::Command<CMD_BUILD_RAIL_WAYPOINT>::Do(tile, GetRailTracks(tile) == RAILTRACK_NE_SW ? AXIS_X : AXIS_Y, 1, 1, STAT_CLASS_WAYP, 0, INVALID_STATION, false);
return ScriptObject::Command<CMD_BUILD_RAIL_WAYPOINT>::Do(tile, GetRailTracks(tile) == RAILTRACK_NE_SW ? AXIS_X : AXIS_Y, 1, 1, STAT_CLASS_WAYP, 0, StationID::Invalid(), false);
}
/* static */ bool ScriptRail::RemoveRailWaypointTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail)

View File

@@ -579,7 +579,7 @@ static bool NeighbourHasReachableRoad(::RoadType rt, TileIndex start_tile, DiagD
DiagDirection entrance_dir = DiagdirBetweenTiles(tile, front);
RoadStopType stop_type = road_veh_type == ROADVEHTYPE_TRUCK ? RoadStopType::Truck : RoadStopType::Bus;
StationID to_join = ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION;
StationID to_join = ScriptStation::IsValidStation(station_id) ? station_id : StationID::Invalid();
return ScriptObject::Command<CMD_BUILD_ROAD_STOP>::Do(tile, 1, 1, stop_type, drive_through, entrance_dir, ScriptObject::GetRoadType(), ROADSTOP_CLASS_DFLT, 0, to_join, station_id != ScriptStation::STATION_JOIN_ADJACENT);
}

View File

@@ -74,14 +74,14 @@
{
ScriptObjectRef counter(name);
EnforceDeityOrCompanyModeValid(INVALID_SIGN);
EnforcePrecondition(INVALID_SIGN, ::IsValidTile(location));
EnforcePrecondition(INVALID_SIGN, name != nullptr);
EnforceDeityOrCompanyModeValid(SignID::Invalid());
EnforcePrecondition(SignID::Invalid(), ::IsValidTile(location));
EnforcePrecondition(SignID::Invalid(), name != nullptr);
const std::string &text = name->GetDecodedText();
EnforcePreconditionEncodedText(INVALID_SIGN, text);
EnforcePreconditionCustomError(INVALID_SIGN, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
EnforcePreconditionEncodedText(SignID::Invalid(), text);
EnforcePreconditionCustomError(SignID::Invalid(), ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
if (!ScriptObject::Command<CMD_PLACE_SIGN>::Do(&ScriptInstance::DoCommandReturnSignID, location, text)) return INVALID_SIGN;
if (!ScriptObject::Command<CMD_PLACE_SIGN>::Do(&ScriptInstance::DoCommandReturnSignID, location, text)) return SignID::Invalid();
/* In case of test-mode, we return SignID 0 */
return SignID::Begin();

View File

@@ -35,7 +35,7 @@
/* static */ StationID ScriptStation::GetStationID(TileIndex tile)
{
if (!::IsValidTile(tile) || !::IsTileType(tile, MP_STATION)) return INVALID_STATION;
if (!::IsValidTile(tile) || !::IsTileType(tile, MP_STATION)) return StationID::Invalid();
return ::GetStationIndex(tile);
}
@@ -229,7 +229,7 @@ template <bool Tfrom, bool Tvia>
/* static */ TownID ScriptStation::GetNearestTown(StationID station_id)
{
if (!IsValidStation(station_id)) return INVALID_TOWN;
if (!IsValidStation(station_id)) return TownID::Invalid();
return ::Station::Get(station_id)->town->index;
}

View File

@@ -122,7 +122,7 @@ private:
CargoCollector::CargoCollector(ScriptStationList_Cargo *parent,
StationID station_id, CargoType cargo, StationID other) :
list(parent), ge(nullptr), other_station(other), last_key(INVALID_STATION), amount(0)
list(parent), ge(nullptr), other_station(other), last_key(StationID::Invalid()), amount(0)
{
if (!ScriptStation::IsValidStation(station_id)) return;
if (!ScriptCargo::IsValidCargo(cargo)) return;
@@ -149,7 +149,7 @@ void CargoCollector::SetValue()
template <ScriptStationList_Cargo::CargoSelector Tselector>
void CargoCollector::Update(StationID from, StationID via, uint amount)
{
StationID key = INVALID_STATION;
StationID key = StationID::Invalid();
switch (Tselector) {
case ScriptStationList_Cargo::CS_VIA_BY_FROM:
if (via != this->other_station) return;

View File

@@ -93,7 +93,7 @@ protected:
* @param other_station Other station to restrict the query with.
*/
template <CargoSelector Tselector>
void Add(StationID station_id, CargoType cargo, StationID other_station = INVALID_STATION);
void Add(StationID station_id, CargoType cargo, StationID other_station = StationID::Invalid());
public:
@@ -130,7 +130,7 @@ protected:
* @param other_station Other station to restrict the query with.
*/
template <CargoSelector Tselector>
void Add(StationID station_id, CargoType cargo, StationID other_station = INVALID_STATION);
void Add(StationID station_id, CargoType cargo, StationID other_station = StationID::Invalid());
public:

View File

@@ -76,7 +76,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
}
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_LOCATION || ::IsValidTile((::TileIndex)reference));
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_GOAL || ScriptGoal::IsValidGoal(static_cast<::GoalID>(reference)));
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_GOAL || !(StoryPage::Get(story_page_id)->company == INVALID_COMPANY && Goal::Get(reference)->company != INVALID_COMPANY));
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_GOAL || !(StoryPage::Get(story_page_id)->company == CompanyID::Invalid() && Goal::Get(reference)->company != CompanyID::Invalid()));
uint32_t refid = 0;
TileIndex reftile{};
@@ -125,7 +125,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
}
EnforcePrecondition(false, type != ::SPET_LOCATION || ::IsValidTile((::TileIndex)reference));
EnforcePrecondition(false, type != ::SPET_GOAL || ScriptGoal::IsValidGoal(static_cast<::GoalID>(reference)));
EnforcePrecondition(false, type != ::SPET_GOAL || !(p->company == INVALID_COMPANY && Goal::Get(reference)->company != INVALID_COMPANY));
EnforcePrecondition(false, type != ::SPET_GOAL || !(p->company == CompanyID::Invalid() && Goal::Get(reference)->company != CompanyID::Invalid()));
uint32_t refid = 0;
TileIndex reftile{};

View File

@@ -38,8 +38,8 @@
*/
class ScriptStoryPage : public ScriptObject {
public:
static constexpr StoryPageID STORY_PAGE_INVALID = ::INVALID_STORY_PAGE; ///< An invalid story page id.
static constexpr StoryPageElementID STORY_PAGE_ELEMENT_INVALID = ::INVALID_STORY_PAGE_ELEMENT; ///< An invalid story page element id.
static constexpr StoryPageID STORY_PAGE_INVALID = ::StoryPageID::Invalid(); ///< An invalid story page id.
static constexpr StoryPageElementID STORY_PAGE_ELEMENT_INVALID = ::StoryPageElementID::Invalid(); ///< An invalid story page element id.
/**
* Story page element types.

View File

@@ -19,6 +19,6 @@ ScriptStoryPageList::ScriptStoryPageList(ScriptCompany::CompanyID company)
::CompanyID c = ScriptCompany::FromScriptCompanyID(company);
ScriptList::FillList<StoryPage>(this,
[c](const StoryPage *p) {return p->company == c || p->company == INVALID_COMPANY; }
[c](const StoryPage *p) {return p->company == c || p->company == CompanyID::Invalid(); }
);
}

View File

@@ -310,20 +310,20 @@
/* static */ TownID ScriptTile::GetTownAuthority(TileIndex tile)
{
if (!::IsValidTile(tile)) return INVALID_TOWN;
if (!::IsValidTile(tile)) return TownID::Invalid();
Town *town = ::ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
if (town == nullptr) return INVALID_TOWN;
if (town == nullptr) return TownID::Invalid();
return town->index;
}
/* static */ TownID ScriptTile::GetClosestTown(TileIndex tile)
{
if (!::IsValidTile(tile)) return INVALID_TOWN;
if (!::IsValidTile(tile)) return TownID::Invalid();
Town *town = ::ClosestTownFromTile(tile, UINT_MAX);
if (town == nullptr) return INVALID_TOWN;
if (town == nullptr) return TownID::Invalid();
return town->index;
}

View File

@@ -108,7 +108,7 @@ static void _DoCommandReturnBuildTunnel1(class ScriptInstance *instance)
DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start);
DiagDirection dir_2 = ::ReverseDiagDir(dir_1);
return ScriptObject::Command<CMD_BUILD_ROAD>::Do(&::_DoCommandReturnBuildTunnel2, start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2), ScriptRoad::GetRoadType(), DRD_NONE, INVALID_TOWN);
return ScriptObject::Command<CMD_BUILD_ROAD>::Do(&::_DoCommandReturnBuildTunnel2, start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2), ScriptRoad::GetRoadType(), DRD_NONE, TownID::Invalid());
}
/* static */ bool ScriptTunnel::_BuildTunnelRoad2()
@@ -122,7 +122,7 @@ static void _DoCommandReturnBuildTunnel1(class ScriptInstance *instance)
DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start);
DiagDirection dir_2 = ::ReverseDiagDir(dir_1);
return ScriptObject::Command<CMD_BUILD_ROAD>::Do(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1), ScriptRoad::GetRoadType(), DRD_NONE, INVALID_TOWN);
return ScriptObject::Command<CMD_BUILD_ROAD>::Do(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1), ScriptRoad::GetRoadType(), DRD_NONE, TownID::Invalid());
}
/* static */ bool ScriptTunnel::RemoveTunnel(TileIndex tile)

View File

@@ -134,7 +134,7 @@
while (dest_wagon-- > 0) w = w->GetNextUnit();
}
return ScriptObject::Command<CMD_MOVE_RAIL_VEHICLE>::Do(v->index, w == nullptr ? ::INVALID_VEHICLE : w->index, move_attached_wagons);
return ScriptObject::Command<CMD_MOVE_RAIL_VEHICLE>::Do(v->index, w == nullptr ? VehicleID::Invalid() : w->index, move_attached_wagons);
}
/* static */ bool ScriptVehicle::MoveWagon(VehicleID source_vehicle_id, SQInteger source_wagon, SQInteger dest_vehicle_id, SQInteger dest_wagon)
@@ -275,15 +275,15 @@
/* static */ EngineID ScriptVehicle::GetEngineType(VehicleID vehicle_id)
{
if (!IsValidVehicle(vehicle_id)) return INVALID_ENGINE;
if (!IsValidVehicle(vehicle_id)) return ::EngineID::Invalid();
return ::Vehicle::Get(vehicle_id)->engine_type;
}
/* static */ EngineID ScriptVehicle::GetWagonEngineType(VehicleID vehicle_id, SQInteger wagon)
{
if (!IsValidVehicle(vehicle_id)) return INVALID_ENGINE;
if (wagon >= GetNumWagons(vehicle_id)) return INVALID_ENGINE;
if (!IsValidVehicle(vehicle_id)) return ::EngineID::Invalid();
if (wagon >= GetNumWagons(vehicle_id)) return ::EngineID::Invalid();
const Vehicle *v = ::Vehicle::Get(vehicle_id);
if (v->type == VEH_TRAIN) {

View File

@@ -95,7 +95,7 @@ public:
VS_INVALID = 0xFF, ///< An invalid vehicle state.
};
static constexpr VehicleID VEHICLE_INVALID = ::INVALID_VEHICLE; ///< Invalid VehicleID.
static constexpr VehicleID VEHICLE_INVALID = ::VehicleID::Invalid(); ///< Invalid VehicleID.
/**
* Checks whether the given vehicle is valid and owned by you.

View File

@@ -24,7 +24,7 @@
/* static */ StationID ScriptWaypoint::GetWaypointID(TileIndex tile)
{
if (!::IsValidTile(tile) || !::IsTileType(tile, MP_STATION) || ::Waypoint::GetByTile(tile) == nullptr) return INVALID_STATION;
if (!::IsValidTile(tile) || !::IsTileType(tile, MP_STATION) || ::Waypoint::GetByTile(tile) == nullptr) return StationID::Invalid();
return ::GetStationIndex(tile);
}