Codechange: use TileIndex constructor explicitly

This commit is contained in:
Rubidium 2025-01-01 09:24:26 +01:00 committed by rubidium42
parent fd5f6caed4
commit f55ba40b13
12 changed files with 57 additions and 51 deletions

View File

@ -31,7 +31,7 @@ Money GetAvailableMoneyForCommand();
bool CheckCompanyHasMoney(CommandCost &cost);
void SubtractMoneyFromCompany(const CommandCost &cost);
void SubtractMoneyFromCompanyFract(CompanyID company, const CommandCost &cost);
CommandCost CheckOwnership(Owner owner, TileIndex tile = 0U);
CommandCost CheckOwnership(Owner owner, TileIndex tile = {});
CommandCost CheckTileOwnership(TileIndex tile);
extern CompanyID _local_company;

View File

@ -229,7 +229,7 @@ private:
*/
struct IterateWrapper {
Iterator begin() { return Iterator(TileIndex{}); }
Iterator end() { return Iterator(Map::Size()); }
Iterator end() { return Iterator(TileIndex{Map::Size()}); }
bool empty() { return false; }
};
@ -316,7 +316,7 @@ public:
*/
static inline TileIndex WrapToMap(TileIndex tile)
{
return tile.base() & Map::tile_mask;
return TileIndex{tile.base() & Map::tile_mask};
}
/**
@ -372,7 +372,7 @@ public:
*/
debug_inline static TileIndex TileXY(uint x, uint y)
{
return (y << Map::LogX()) + x;
return TileIndex{(y << Map::LogX()) + x};
}
/**
@ -403,7 +403,7 @@ inline TileIndexDiff TileDiffXY(int x, int y)
*/
debug_inline static TileIndex TileVirtXY(uint x, uint y)
{
return (y >> 4 << Map::LogX()) + (x >> 4);
return TileIndex{(y >> 4 << Map::LogX()) + (x >> 4)};
}
@ -649,7 +649,7 @@ bool CircularTileSearch(TileIndex *tile, uint radius, uint w, uint h, TestTileOn
*/
inline TileIndex RandomTileSeed(uint32_t r)
{
return Map::WrapToMap(r);
return Map::WrapToMap(TileIndex{r});
}
/**

View File

@ -442,7 +442,7 @@ static void FixOwnerOfRailTrack(Tile t)
/* try to find any connected rail */
for (DiagDirection dd = DIAGDIR_BEGIN; dd < DIAGDIR_END; dd++) {
TileIndex tt = t + TileOffsByDiagDir(dd);
TileIndex tt{t + TileOffsByDiagDir(dd)};
if (GetTileTrackStatus(t, TRANSPORT_RAIL, 0, dd) != 0 &&
GetTileTrackStatus(tt, TRANSPORT_RAIL, 0, ReverseDiagDir(dd)) != 0 &&
Company::IsValidID(GetTileOwner(tt))) {

View File

@ -404,7 +404,7 @@ public:
assert(CargoPacket::CanAllocateItem());
/* Don't construct the packet with station here, because that'll fail with old savegames */
CargoPacket *cp = new CargoPacket(GB(_waiting_acceptance, 0, 12), _cargo_periods, source, _cargo_source_xy, _cargo_feeder_share);
CargoPacket *cp = new CargoPacket(GB(_waiting_acceptance, 0, 12), _cargo_periods, source, TileIndex{_cargo_source_xy}, _cargo_feeder_share);
ge.cargo.Append(cp, INVALID_STATION);
SetBit(ge.status, GoodsEntry::GES_RATING);
}

View File

@ -1138,7 +1138,7 @@ struct VEHSChunkHandler : ChunkHandler {
if (_cargo_count != 0 && IsCompanyBuildableVehicleType(v) && CargoPacket::CanAllocateItem()) {
/* Don't construct the packet with station here, because that'll fail with old savegames */
CargoPacket *cp = new CargoPacket(_cargo_count, _cargo_periods, _cargo_source, _cargo_source_xy, _cargo_feeder_share);
CargoPacket *cp = new CargoPacket(_cargo_count, _cargo_periods, _cargo_source, TileIndex{_cargo_source_xy}, _cargo_feeder_share);
v->cargo.Append(cp);
}

View File

@ -719,7 +719,7 @@ void SetupScreenshotViewport(ScreenshotType t, Viewport *vp, uint32_t width, uin
vp->zoom = ZOOM_LVL_WORLD_SCREENSHOT;
TileIndex north_tile = _settings_game.construction.freeform_edges ? TileXY(1, 1) : TileXY(0, 0);
TileIndex south_tile = Map::Size() - 1;
TileIndex south_tile{Map::Size() - 1};
/* We need to account for a hill or high building at tile 0,0. */
int extra_height_top = TilePixelHeight(north_tile) + 150;

View File

@ -99,8 +99,8 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance)
EnforceDeityOrCompanyModeValid(false);
/* Build the piece of road on the 'start' side of the bridge */
TileIndex end = ScriptObject::GetCallbackVariable(0);
TileIndex start = ScriptObject::GetCallbackVariable(1);
TileIndex end(ScriptObject::GetCallbackVariable(0));
TileIndex start(ScriptObject::GetCallbackVariable(1));
DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start);
DiagDirection dir_2 = ::ReverseDiagDir(dir_1);
@ -113,8 +113,8 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance)
EnforceDeityOrCompanyModeValid(false);
/* Build the piece of road on the 'end' side of the bridge */
TileIndex end = ScriptObject::GetCallbackVariable(0);
TileIndex start = ScriptObject::GetCallbackVariable(1);
TileIndex end(ScriptObject::GetCallbackVariable(0));
TileIndex start(ScriptObject::GetCallbackVariable(1));
DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start);
DiagDirection dir_2 = ::ReverseDiagDir(dir_1);

View File

@ -35,7 +35,7 @@
StoryPage *story_page = nullptr;
if (type == GT_STORY_PAGE && ScriptStoryPage::IsValidStoryPage((ScriptStoryPage::StoryPageID)destination)) story_page = ::StoryPage::Get((ScriptStoryPage::StoryPageID)destination);
return (type == GT_NONE && destination == 0) ||
(type == GT_TILE && ScriptMap::IsValidTile(destination)) ||
(type == GT_TILE && ScriptMap::IsValidTile(::TileIndex(destination))) ||
(type == GT_INDUSTRY && ScriptIndustry::IsValidIndustry(destination)) ||
(type == GT_TOWN && ScriptTown::IsValidTown(destination)) ||
(type == GT_COMPANY && ScriptCompany::ResolveCompanyID((ScriptCompany::CompanyID)destination) != ScriptCompany::COMPANY_INVALID) ||

View File

@ -31,7 +31,7 @@
EnforcePrecondition(false, type == NT_ECONOMY || type == NT_SUBSIDIES || type == NT_GENERAL);
EnforcePrecondition(false, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID);
EnforcePrecondition(false, (ref_type == NR_NONE) ||
(ref_type == NR_TILE && ScriptMap::IsValidTile(reference)) ||
(ref_type == NR_TILE && ScriptMap::IsValidTile(::TileIndex(reference))) ||
(ref_type == NR_STATION && ScriptStation::IsValidStation(reference)) ||
(ref_type == NR_INDUSTRY && ScriptIndustry::IsValidIndustry(reference)) ||
(ref_type == NR_TOWN && ScriptTown::IsValidTown(reference)));

View File

@ -102,8 +102,8 @@ static void _DoCommandReturnBuildTunnel1(class ScriptInstance *instance)
EnforceDeityOrCompanyModeValid(false);
/* Build the piece of road on the 'start' side of the tunnel */
TileIndex end = ScriptObject::GetCallbackVariable(0);
TileIndex start = ScriptTunnel::GetOtherTunnelEnd(end);
TileIndex end(ScriptObject::GetCallbackVariable(0));
TileIndex start{ScriptTunnel::GetOtherTunnelEnd(end)};
DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start);
DiagDirection dir_2 = ::ReverseDiagDir(dir_1);
@ -116,8 +116,8 @@ static void _DoCommandReturnBuildTunnel1(class ScriptInstance *instance)
EnforceDeityOrCompanyModeValid(false);
/* Build the piece of road on the 'end' side of the tunnel */
TileIndex end = ScriptObject::GetCallbackVariable(0);
TileIndex start = ScriptTunnel::GetOtherTunnelEnd(end);
TileIndex end(ScriptObject::GetCallbackVariable(0));
TileIndex start{ScriptTunnel::GetOtherTunnelEnd(end)};
DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start);
DiagDirection dir_2 = ::ReverseDiagDir(dir_1);

View File

@ -136,16 +136,17 @@ static const NIVariable _niv_stations[] = {
};
class NIHStation : public NIHelper {
bool IsInspectable(uint index) const override { return GetStationSpec(index) != nullptr; }
uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Station::GetByTile(index)->town->index); }
bool IsInspectable(uint index) const override { return GetStationSpec(TileIndex{index}) != nullptr; }
uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Station::GetByTile(TileIndex{index})->town->index); }
const void *GetInstance(uint ) const override { return nullptr; }
const void *GetSpec(uint index) const override { return GetStationSpec(index); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), index); }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetStationSpec(index)->grf_prop.grfid : 0; }
const void *GetSpec(uint index) const override { return GetStationSpec(TileIndex{index}); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), TileIndex{index}); }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetStationSpec(TileIndex{index})->grf_prop.grfid : 0; }
uint Resolve(uint index, uint var, uint param, bool &avail) const override
{
StationResolverObject ro(GetStationSpec(index), Station::GetByTile(index), index);
TileIndex tile{index};
StationResolverObject ro(GetStationSpec(tile), Station::GetByTile(tile), tile);
return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
}
};
@ -205,12 +206,13 @@ class NIHHouse : public NIHelper {
uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, GetTownIndex(index)); }
const void *GetInstance(uint)const override { return nullptr; }
const void *GetSpec(uint index) const override { return HouseSpec::Get(GetHouseType(index)); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_TOWN_NAME, GetTownIndex(index), index); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_TOWN_NAME, GetTownIndex(index), TileIndex{index}); }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? HouseSpec::Get(GetHouseType(index))->grf_prop.grfid : 0; }
uint Resolve(uint index, uint var, uint param, bool &avail) const override
{
HouseResolverObject ro(GetHouseType(index), index, Town::GetByTile(index));
TileIndex tile{index};
HouseResolverObject ro(GetHouseType(tile), tile, Town::GetByTile(tile));
return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
}
};
@ -255,12 +257,13 @@ class NIHIndustryTile : public NIHelper {
uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_INDUSTRIES, GetIndustryIndex(index)); }
const void *GetInstance(uint)const override { return nullptr; }
const void *GetSpec(uint index) const override { return GetIndustryTileSpec(GetIndustryGfx(index)); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_INDUSTRY_NAME, GetIndustryIndex(index), index); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_INDUSTRY_NAME, GetIndustryIndex(index), TileIndex{index}); }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetIndustryTileSpec(GetIndustryGfx(index))->grf_prop.grfid : 0; }
uint Resolve(uint index, uint var, uint param, bool &avail) const override
{
IndustryTileResolverObject ro(GetIndustryGfx(index), index, Industry::GetByTile(index));
TileIndex tile{index};
IndustryTileResolverObject ro(GetIndustryGfx(tile), tile, Industry::GetByTile(tile));
return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
}
};
@ -427,16 +430,17 @@ static const NIVariable _niv_objects[] = {
};
class NIHObject : public NIHelper {
bool IsInspectable(uint index) const override { return ObjectSpec::GetByTile(index)->grf_prop.HasGrfFile(); }
uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Object::GetByTile(index)->town->index); }
const void *GetInstance(uint index)const override { return Object::GetByTile(index); }
const void *GetSpec(uint index) const override { return ObjectSpec::GetByTile(index); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_OBJECT, INVALID_STRING_ID, index); }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? ObjectSpec::GetByTile(index)->grf_prop.grfid : 0; }
bool IsInspectable(uint index) const override { return ObjectSpec::GetByTile(TileIndex{index})->grf_prop.HasGrfFile(); }
uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Object::GetByTile(TileIndex{index})->town->index); }
const void *GetInstance(uint index)const override { return Object::GetByTile(TileIndex{index}); }
const void *GetSpec(uint index) const override { return ObjectSpec::GetByTile(TileIndex{index}); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_OBJECT, INVALID_STRING_ID, TileIndex{index}); }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? ObjectSpec::GetByTile(TileIndex{index})->grf_prop.grfid : 0; }
uint Resolve(uint index, uint var, uint param, bool &avail) const override
{
ObjectResolverObject ro(ObjectSpec::GetByTile(index), Object::GetByTile(index), index);
TileIndex tile{index};
ObjectResolverObject ro(ObjectSpec::GetByTile(tile), Object::GetByTile(tile), tile);
return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
}
};
@ -465,14 +469,14 @@ class NIHRailType : public NIHelper {
uint GetParent(uint) const override { return UINT32_MAX; }
const void *GetInstance(uint) const override { return nullptr; }
const void *GetSpec(uint) const override { return nullptr; }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_RAIL_TYPE, INVALID_STRING_ID, index); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_RAIL_TYPE, INVALID_STRING_ID, TileIndex{index}); }
uint32_t GetGRFID(uint) const override { return 0; }
uint Resolve(uint index, uint var, uint param, bool &avail) const override
{
/* There is no unique GRFFile for the tile. Multiple GRFs can define different parts of the railtype.
* However, currently the NewGRF Debug GUI does not display variables depending on the GRF (like 0x7F) anyway. */
RailTypeResolverObject ro(nullptr, index, TCX_NORMAL, RTSG_END);
RailTypeResolverObject ro(nullptr, TileIndex{index}, TCX_NORMAL, RTSG_END);
return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
}
};
@ -501,12 +505,13 @@ class NIHAirportTile : public NIHelper {
uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_AIRPORTS, GetStationIndex(index)); }
const void *GetInstance(uint)const override { return nullptr; }
const void *GetSpec(uint index) const override { return AirportTileSpec::Get(GetAirportGfx(index)); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), index); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), TileIndex{index}); }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? AirportTileSpec::Get(GetAirportGfx(index))->grf_prop.grfid : 0; }
uint Resolve(uint index, uint var, uint param, bool &avail) const override
{
AirportTileResolverObject ro(AirportTileSpec::GetByTile(index), index, Station::GetByTile(index));
TileIndex tile{index};
AirportTileResolverObject ro(AirportTileSpec::GetByTile(tile), tile, Station::GetByTile(tile));
return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
}
};
@ -633,14 +638,14 @@ class NIHRoadType : public NIHelper {
uint GetParent(uint) const override { return UINT32_MAX; }
const void *GetInstance(uint) const override { return nullptr; }
const void *GetSpec(uint) const override { return nullptr; }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_ROAD_TYPE, INVALID_STRING_ID, index); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_ROAD_TYPE, INVALID_STRING_ID, TileIndex{index}); }
uint32_t GetGRFID(uint) const override { return 0; }
uint Resolve(uint index, uint var, uint param, bool &avail) const override
{
/* There is no unique GRFFile for the tile. Multiple GRFs can define different parts of the railtype.
* However, currently the NewGRF Debug GUI does not display variables depending on the GRF (like 0x7F) anyway. */
RoadTypeResolverObject ro(nullptr, index, TCX_NORMAL, ROTSG_END);
RoadTypeResolverObject ro(nullptr, TileIndex{index}, TCX_NORMAL, ROTSG_END);
return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
}
};
@ -695,17 +700,18 @@ static const NIVariable _nif_roadstops[] = {
};
class NIHRoadStop : public NIHelper {
bool IsInspectable(uint index) const override { return GetRoadStopSpec(index) != nullptr; }
uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, BaseStation::GetByTile(index)->town->index); }
bool IsInspectable(uint index) const override { return GetRoadStopSpec(TileIndex{index}) != nullptr; }
uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, BaseStation::GetByTile(TileIndex{index})->town->index); }
const void *GetInstance(uint)const override { return nullptr; }
const void *GetSpec(uint index) const override { return GetRoadStopSpec(index); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), index); }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetRoadStopSpec(index)->grf_prop.grfid : 0; }
const void *GetSpec(uint index) const override { return GetRoadStopSpec(TileIndex{index}); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), TileIndex{index}); }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetRoadStopSpec(TileIndex{index})->grf_prop.grfid : 0; }
uint Resolve(uint index, uint var, uint32_t param, bool &avail) const override
{
StationGfx view = GetStationGfx(index);
RoadStopResolverObject ro(GetRoadStopSpec(index), BaseStation::GetByTile(index), index, INVALID_ROADTYPE, GetStationType(index), view);
TileIndex tile{index};
StationGfx view = GetStationGfx(tile);
RoadStopResolverObject ro(GetRoadStopSpec(tile), BaseStation::GetByTile(tile), tile, INVALID_ROADTYPE, GetStationType(tile), view);
return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
}
};

View File

@ -1262,7 +1262,7 @@ public:
break;
case WID_TF_RANDOM_TOWN:
this->ExecuteFoundTownCommand(0, true, STR_ERROR_CAN_T_GENERATE_TOWN, CcFoundRandomTown);
this->ExecuteFoundTownCommand(TileIndex{}, true, STR_ERROR_CAN_T_GENERATE_TOWN, CcFoundRandomTown);
break;
case WID_TF_TOWN_NAME_RANDOM: