1
0
Fork 0

Codechange: use INVALID_TOWN instead of 0 to denote 'not applicable'

pull/13339/head
Rubidium 2025-01-19 15:14:25 +01:00 committed by rubidium42
parent 00367aa391
commit 0aa9faf187
8 changed files with 12 additions and 12 deletions

View File

@ -604,7 +604,7 @@ static CommandCost CheckRoadSlope(Slope tileh, RoadBits *pieces, RoadBits existi
* @param pieces road pieces to build (RoadBits) * @param pieces road pieces to build (RoadBits)
* @param rt road type * @param rt road type
* @param toggle_drd disallowed directions to toggle * @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 * @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) 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 /* 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 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) { if (company != OWNER_TOWN) {
const Town *town = CalcClosestTownFromTile(tile); const Town *town = CalcClosestTownFromTile(tile);
town_id = (town != nullptr) ? town->index : INVALID_TOWN; 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); if (tile == start_tile && start_half) bits &= DiagDirToRoadBits(dir);
} }
CommandCost ret = Command<CMD_BUILD_ROAD>::Do(flags, tile, bits, rt, drd, 0); CommandCost ret = Command<CMD_BUILD_ROAD>::Do(flags, tile, bits, rt, drd, INVALID_TOWN);
if (ret.Failed()) { if (ret.Failed()) {
last_error = ret; last_error = ret;
if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT) { if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT) {

View File

@ -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 there is a roadpiece just outside of the station entrance, build a connecting route */
if (IsNormalRoadTile(tile)) { if (IsNormalRoadTile(tile)) {
if (GetRoadBits(tile, GetRoadTramType(_cur_roadtype)) != ROAD_NONE) { if (GetRoadBits(tile, GetRoadTramType(_cur_roadtype)) != ROAD_NONE) {
Command<CMD_BUILD_ROAD>::Post(tile, DiagDirToRoadBits(ReverseDiagDir(direction)), _cur_roadtype, DRD_NONE, 0); Command<CMD_BUILD_ROAD>::Post(tile, DiagDirToRoadBits(ReverseDiagDir(direction)), _cur_roadtype, DRD_NONE, INVALID_TOWN);
} }
} }
} }

View File

@ -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. */ /* The 'current' company is not necessarily the owner of the vehicle. */
Backup<CompanyID> cur_company(_current_company, c); Backup<CompanyID> cur_company(_current_company, c);
CommandCost ret = Command<CMD_BUILD_ROAD>::Do(DC_NO_WATER, t, r, rt, DRD_NONE, 0); CommandCost ret = Command<CMD_BUILD_ROAD>::Do(DC_NO_WATER, t, r, rt, DRD_NONE, INVALID_TOWN);
cur_company.Restore(); cur_company.Restore();
return ret.Succeeded(); return ret.Succeeded();

View File

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

View File

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

View File

@ -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_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 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_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 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. static const uint16_t TOWN_GROWTH_RATE_NONE = 0xFFFF; ///< Special value for Town::growth_rate to disable town growth.

View File

@ -1077,7 +1077,7 @@ static bool IsRoadAllowedHere(Town *t, TileIndex tile, DiagDirection dir)
* If that fails clear the land, and if that fails exit. * If that fails clear the land, and if that fails exit.
* This is to make sure that we can build a road here later. */ * This is to make sure that we can build a road here later. */
RoadType rt = GetTownRoadType(); RoadType rt = GetTownRoadType();
if (Command<CMD_BUILD_ROAD>::Do(DC_AUTO | DC_NO_WATER, tile, (dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_Y : ROAD_X, rt, DRD_NONE, 0).Failed() && if (Command<CMD_BUILD_ROAD>::Do(DC_AUTO | DC_NO_WATER, tile, (dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_Y : ROAD_X, rt, DRD_NONE, INVALID_TOWN).Failed() &&
Command<CMD_LANDSCAPE_CLEAR>::Do(DC_AUTO | DC_NO_WATER, tile).Failed()) { Command<CMD_LANDSCAPE_CLEAR>::Do(DC_AUTO | DC_NO_WATER, tile).Failed()) {
return false; return false;
} }

View File

@ -13,6 +13,8 @@
#include "core/enum_type.hpp" #include "core/enum_type.hpp"
typedef uint16_t TownID; typedef uint16_t TownID;
static const TownID INVALID_TOWN = 0xFFFF;
struct Town; struct Town;
/** Supported initial town sizes */ /** Supported initial town sizes */