From 0aa9faf187a6fb41d932d67496dc872437f63ab4 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sun, 19 Jan 2025 15:14:25 +0100 Subject: [PATCH] Codechange: use INVALID_TOWN instead of 0 to denote 'not applicable' --- src/road_cmd.cpp | 6 +++--- src/road_gui.cpp | 2 +- src/roadveh_cmd.cpp | 2 +- src/script/api/script_bridge.cpp | 4 ++-- src/script/api/script_tunnel.cpp | 4 ++-- src/town.h | 2 -- src/town_cmd.cpp | 2 +- src/town_type.h | 2 ++ 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index 8bbfc28bdc..fcbc0eaf07 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -604,7 +604,7 @@ static CommandCost CheckRoadSlope(Slope tileh, RoadBits *pieces, RoadBits existi * @param pieces road pieces to build (RoadBits) * @param rt road type * @param toggle_drd disallowed directions to toggle - * @param town_id the town that is building the road (0 if not applicable) + * @param town_id the town that is building the road (INVALID_TOWN if not applicable) * @return the cost of this operation or an error */ CommandCost CmdBuildRoad(DoCommandFlag flags, TileIndex tile, RoadBits pieces, RoadType rt, DisallowedRoadDirections toggle_drd, TownID town_id) @@ -617,7 +617,7 @@ CommandCost CmdBuildRoad(DoCommandFlag flags, TileIndex tile, RoadBits pieces, R /* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero * if a non-company is building the road */ - if ((Company::IsValidID(company) && town_id != 0) || (company == OWNER_TOWN && !Town::IsValidID(town_id)) || (company == OWNER_DEITY && town_id != 0)) return CMD_ERROR; + if ((Company::IsValidID(company) && town_id != INVALID_TOWN) || (company == OWNER_TOWN && !Town::IsValidID(town_id)) || (company == OWNER_DEITY && town_id != INVALID_TOWN)) return CMD_ERROR; if (company != OWNER_TOWN) { const Town *town = CalcClosestTownFromTile(tile); town_id = (town != nullptr) ? town->index : INVALID_TOWN; @@ -1026,7 +1026,7 @@ CommandCost CmdBuildLongRoad(DoCommandFlag flags, TileIndex end_tile, TileIndex if (tile == start_tile && start_half) bits &= DiagDirToRoadBits(dir); } - CommandCost ret = Command::Do(flags, tile, bits, rt, drd, 0); + CommandCost ret = Command::Do(flags, tile, bits, rt, drd, INVALID_TOWN); if (ret.Failed()) { last_error = ret; if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT) { diff --git a/src/road_gui.cpp b/src/road_gui.cpp index bb0207ea3a..947bbd3b72 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -165,7 +165,7 @@ void ConnectRoadToStructure(TileIndex tile, DiagDirection direction) /* if there is a roadpiece just outside of the station entrance, build a connecting route */ if (IsNormalRoadTile(tile)) { if (GetRoadBits(tile, GetRoadTramType(_cur_roadtype)) != ROAD_NONE) { - Command::Post(tile, DiagDirToRoadBits(ReverseDiagDir(direction)), _cur_roadtype, DRD_NONE, 0); + Command::Post(tile, DiagDirToRoadBits(ReverseDiagDir(direction)), _cur_roadtype, DRD_NONE, INVALID_TOWN); } } } diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index b54c0f9d7f..d500efb9ee 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -1126,7 +1126,7 @@ static bool CanBuildTramTrackOnTile(CompanyID c, TileIndex t, RoadType rt, RoadB /* The 'current' company is not necessarily the owner of the vehicle. */ Backup cur_company(_current_company, c); - CommandCost ret = Command::Do(DC_NO_WATER, t, r, rt, DRD_NONE, 0); + CommandCost ret = Command::Do(DC_NO_WATER, t, r, rt, DRD_NONE, INVALID_TOWN); cur_company.Restore(); return ret.Succeeded(); diff --git a/src/script/api/script_bridge.cpp b/src/script/api/script_bridge.cpp index 699b01ccaf..2dc3f6933c 100644 --- a/src/script/api/script_bridge.cpp +++ b/src/script/api/script_bridge.cpp @@ -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::Do(&::_DoCommandReturnBuildBridge2, start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2), (::RoadType)ScriptRoad::GetCurrentRoadType(), DRD_NONE, 0); + return ScriptObject::Command::Do(&::_DoCommandReturnBuildBridge2, start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2), (::RoadType)ScriptRoad::GetCurrentRoadType(), DRD_NONE, INVALID_TOWN); } /* 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::Do(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1), (::RoadType)ScriptRoad::GetCurrentRoadType(), DRD_NONE, 0); + return ScriptObject::Command::Do(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1), (::RoadType)ScriptRoad::GetCurrentRoadType(), DRD_NONE, INVALID_TOWN); } /* static */ bool ScriptBridge::RemoveBridge(TileIndex tile) diff --git a/src/script/api/script_tunnel.cpp b/src/script/api/script_tunnel.cpp index 158bca7964..4dea5787c4 100644 --- a/src/script/api/script_tunnel.cpp +++ b/src/script/api/script_tunnel.cpp @@ -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::Do(&::_DoCommandReturnBuildTunnel2, start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2), ScriptRoad::GetRoadType(), DRD_NONE, 0); + return ScriptObject::Command::Do(&::_DoCommandReturnBuildTunnel2, start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2), ScriptRoad::GetRoadType(), DRD_NONE, INVALID_TOWN); } /* 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::Do(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1), ScriptRoad::GetRoadType(), DRD_NONE, 0); + return ScriptObject::Command::Do(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1), ScriptRoad::GetRoadType(), DRD_NONE, INVALID_TOWN); } /* static */ bool ScriptTunnel::RemoveTunnel(TileIndex tile) diff --git a/src/town.h b/src/town.h index 9b2fc87b68..a61ad9c529 100644 --- a/src/town.h +++ b/src/town.h @@ -28,8 +28,6 @@ struct BuildingCounts { static const uint CUSTOM_TOWN_NUMBER_DIFFICULTY = 4; ///< value for custom town number in difficulty settings static const uint CUSTOM_TOWN_MAX_NUMBER = 5000; ///< this is the maximum number of towns a user can specify in customisation -static const TownID INVALID_TOWN = 0xFFFF; - static const uint TOWN_GROWTH_WINTER = 0xFFFFFFFE; ///< The town only needs this cargo in the winter (any amount) static const uint TOWN_GROWTH_DESERT = 0xFFFFFFFF; ///< The town needs the cargo for growth when on desert (any amount) static const uint16_t TOWN_GROWTH_RATE_NONE = 0xFFFF; ///< Special value for Town::growth_rate to disable town growth. diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 28259aed75..076f24e50b 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -1077,7 +1077,7 @@ static bool IsRoadAllowedHere(Town *t, TileIndex tile, DiagDirection dir) * If that fails clear the land, and if that fails exit. * This is to make sure that we can build a road here later. */ RoadType rt = GetTownRoadType(); - if (Command::Do(DC_AUTO | DC_NO_WATER, tile, (dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_Y : ROAD_X, rt, DRD_NONE, 0).Failed() && + if (Command::Do(DC_AUTO | DC_NO_WATER, tile, (dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_Y : ROAD_X, rt, DRD_NONE, INVALID_TOWN).Failed() && Command::Do(DC_AUTO | DC_NO_WATER, tile).Failed()) { return false; } diff --git a/src/town_type.h b/src/town_type.h index d86b947022..eb20722645 100644 --- a/src/town_type.h +++ b/src/town_type.h @@ -13,6 +13,8 @@ #include "core/enum_type.hpp" typedef uint16_t TownID; +static const TownID INVALID_TOWN = 0xFFFF; + struct Town; /** Supported initial town sizes */