Codechange: use explicit TileIndex constructor for tile 0

This commit is contained in:
Rubidium 2024-12-31 22:44:12 +01:00 committed by rubidium42
parent 562ec74812
commit fd5f6caed4
20 changed files with 48 additions and 48 deletions

View File

@ -831,7 +831,7 @@ static uint8_t AircraftGetEntryPoint(const Aircraft *v, const AirportFTAClass *a
/* In the case the station doesn't exit anymore, set target tile 0.
* It doesn't hurt much, aircraft will go to next order, nearest hangar
* or it will simply crash in next tick */
TileIndex tile = 0;
TileIndex tile{};
const Station *st = Station::GetIfValid(v->targetairport);
if (st != nullptr) {
@ -1305,7 +1305,7 @@ TileIndex Aircraft::GetOrderStationLocation(StationID)
}
/* Aircraft do not use dest-tile */
return 0;
return TileIndex{};
}
void Aircraft::MarkDirty()

View File

@ -861,7 +861,7 @@ public:
case WID_GL_START_ALL:
case WID_GL_STOP_ALL: { // Start/stop all vehicles of the list
Command<CMD_MASS_START_STOP>::Post(0, widget == WID_GL_START_ALL, true, this->vli);
Command<CMD_MASS_START_STOP>::Post(TileIndex{}, widget == WID_GL_START_ALL, true, this->vli);
break;
}

View File

@ -682,7 +682,7 @@ public:
case WID_DPI_FUND_WIDGET: {
if (this->selected_type != INVALID_INDUSTRYTYPE) {
if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && GetIndustrySpec(this->selected_type)->IsRawIndustry()) {
Command<CMD_BUILD_INDUSTRY>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, 0, this->selected_type, 0, false, InteractiveRandom());
Command<CMD_BUILD_INDUSTRY>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, TileIndex{}, this->selected_type, 0, false, InteractiveRandom());
this->HandleButtonClick(WID_DPI_FUND_WIDGET);
} else {
HandlePlacePushButton(this, WID_DPI_FUND_WIDGET, SPR_CURSOR_INDUSTRY, HT_RECT);

View File

@ -792,7 +792,7 @@ void RunTileLoop()
/* Manually update tile 0 every TILE_UPDATE_FREQUENCY ticks - the LFSR never iterates over it itself. */
if (TimerGameTick::counter % TILE_UPDATE_FREQUENCY == 0) {
_tile_type_procs[GetTileType(0)]->tile_loop_proc(0);
_tile_type_procs[GetTileType(0)]->tile_loop_proc(TileIndex{});
count--;
}

View File

@ -228,7 +228,7 @@ private:
* Iterable ensemble of all Tiles
*/
struct IterateWrapper {
Iterator begin() { return Iterator(0); }
Iterator begin() { return Iterator(TileIndex{}); }
Iterator end() { return Iterator(Map::Size()); }
bool empty() { return false; }
};

View File

@ -173,7 +173,7 @@ CommandCost CmdClearOrderBackup(DoCommandFlag flags, TileIndex tile, ClientID us
/* If it's not a backup of us, ignore it. */
if (ob->user != user) continue;
Command<CMD_CLEAR_ORDER_BACKUP>::Post(0, static_cast<ClientID>(user));
Command<CMD_CLEAR_ORDER_BACKUP>::Post(TileIndex{}, static_cast<ClientID>(user));
return;
}
}

View File

@ -1999,7 +1999,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool
{
if (conditional_depth > v->GetNumOrders()) {
v->current_order.Free();
v->SetDestTile(0);
v->SetDestTile(TileIndex{});
return false;
}
@ -2093,7 +2093,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool
}
default:
v->SetDestTile(0);
v->SetDestTile(TileIndex{});
return false;
}
@ -2109,7 +2109,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool
if (order == nullptr) {
v->current_order.Free();
v->SetDestTile(0);
v->SetDestTile(TileIndex{});
return false;
}
@ -2184,7 +2184,7 @@ bool ProcessOrders(Vehicle *v)
}
v->current_order.Free();
v->SetDestTile(0);
v->SetDestTile(TileIndex{});
return false;
}

View File

@ -588,7 +588,7 @@ TileIndex RoadVehicle::GetOrderStationLocation(StationID station)
if (!CanVehicleUseStation(this, st)) {
/* There is no stop left at the station, so don't even TRY to go there */
this->IncrementRealOrderIndex();
return 0;
return TileIndex{};
}
return st->xy;

View File

@ -220,7 +220,7 @@ struct INDYChunkHandler : ChunkHandler {
if (IsSavegameVersionBefore(SLV_161) && !IsSavegameVersionBefore(SLV_76)) {
/* Store the old persistent storage. The GRFID will be added later. */
assert(PersistentStorage::CanAllocateItem());
i->psa = new PersistentStorage(0, 0, 0);
i->psa = new PersistentStorage(0, 0, TileIndex{});
std::copy(std::begin(_old_ind_persistent_storage.storage), std::end(_old_ind_persistent_storage.storage), std::begin(i->psa->storage));
}
if (IsSavegameVersionBefore(SLV_EXTEND_INDUSTRY_CARGO_SLOTS)) {

View File

@ -74,7 +74,7 @@ struct MAPTChunkHandler : ChunkHandler {
std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
uint size = Map::Size();
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) Tile(i++).type() = buf[j];
}
@ -86,7 +86,7 @@ struct MAPTChunkHandler : ChunkHandler {
uint size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = Tile(i++).type();
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
}
@ -101,7 +101,7 @@ struct MAPHChunkHandler : ChunkHandler {
std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
uint size = Map::Size();
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) Tile(i++).height() = buf[j];
}
@ -113,7 +113,7 @@ struct MAPHChunkHandler : ChunkHandler {
uint size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = Tile(i++).height();
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
}
@ -128,7 +128,7 @@ struct MAPOChunkHandler : ChunkHandler {
std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
uint size = Map::Size();
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) Tile(i++).m1() = buf[j];
}
@ -140,7 +140,7 @@ struct MAPOChunkHandler : ChunkHandler {
uint size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = Tile(i++).m1();
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
}
@ -155,7 +155,7 @@ struct MAP2ChunkHandler : ChunkHandler {
std::array<uint16_t, MAP_SL_BUF_SIZE> buf;
uint size = Map::Size();
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE,
/* In those versions the m2 was 8 bits */
IsSavegameVersionBefore(SLV_5) ? SLE_FILE_U8 | SLE_VAR_U16 : SLE_UINT16
@ -170,7 +170,7 @@ struct MAP2ChunkHandler : ChunkHandler {
uint size = Map::Size();
SlSetLength(static_cast<uint32_t>(size) * sizeof(uint16_t));
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = Tile(i++).m2();
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT16);
}
@ -185,7 +185,7 @@ struct M3LOChunkHandler : ChunkHandler {
std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
uint size = Map::Size();
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) Tile(i++).m3() = buf[j];
}
@ -197,7 +197,7 @@ struct M3LOChunkHandler : ChunkHandler {
uint size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = Tile(i++).m3();
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
}
@ -212,7 +212,7 @@ struct M3HIChunkHandler : ChunkHandler {
std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
uint size = Map::Size();
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) Tile(i++).m4() = buf[j];
}
@ -224,7 +224,7 @@ struct M3HIChunkHandler : ChunkHandler {
uint size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = Tile(i++).m4();
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
}
@ -239,7 +239,7 @@ struct MAP5ChunkHandler : ChunkHandler {
std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
uint size = Map::Size();
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) Tile(i++).m5() = buf[j];
}
@ -251,7 +251,7 @@ struct MAP5ChunkHandler : ChunkHandler {
uint size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = Tile(i++).m5();
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
}
@ -267,7 +267,7 @@ struct MAPEChunkHandler : ChunkHandler {
uint size = Map::Size();
if (IsSavegameVersionBefore(SLV_42)) {
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
/* 1024, otherwise we overflow on 64x64 maps! */
SlCopy(buf.data(), 1024, SLE_UINT8);
for (uint j = 0; j != 1024; j++) {
@ -278,7 +278,7 @@ struct MAPEChunkHandler : ChunkHandler {
}
}
} else {
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) Tile(i++).m6() = buf[j];
}
@ -291,7 +291,7 @@ struct MAPEChunkHandler : ChunkHandler {
uint size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = Tile(i++).m6();
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
}
@ -306,7 +306,7 @@ struct MAP7ChunkHandler : ChunkHandler {
std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
uint size = Map::Size();
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) Tile(i++).m7() = buf[j];
}
@ -318,7 +318,7 @@ struct MAP7ChunkHandler : ChunkHandler {
uint size = Map::Size();
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = Tile(i++).m7();
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
}
@ -333,7 +333,7 @@ struct MAP8ChunkHandler : ChunkHandler {
std::array<uint16_t, MAP_SL_BUF_SIZE> buf;
uint size = Map::Size();
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT16);
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) Tile(i++).m8() = buf[j];
}
@ -345,7 +345,7 @@ struct MAP8ChunkHandler : ChunkHandler {
uint size = Map::Size();
SlSetLength(static_cast<uint32_t>(size) * sizeof(uint16_t));
for (TileIndex i = 0; i != size;) {
for (TileIndex i{}; i != size;) {
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = Tile(i++).m8();
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT16);
}

View File

@ -538,7 +538,7 @@ static void ReadTTDPatchFlags()
_bump_assert_value = (_old_vehicle_multiplier - 1) * 850 * 128;
/* The first 17 bytes are used by TTDP1, which translates to the first 9 m3s and first 8 m4s. */
for (TileIndex i = 0; i <= 8; i++) { // check tile 0, too
for (TileIndex i{}; i <= 8; i++) { // check tile 0, too
Tile tile(i);
if (tile.m3() != 0 || (i != 8 && tile.m4() != 0)) _savegame_type = SGT_TTDP1;
}
@ -555,7 +555,7 @@ static void ReadTTDPatchFlags()
_old_extra_chunk_nums = extra_chunk_tile.m3() | extra_chunk_tile.m4() << 8;
/* Clean the misused places */
for (TileIndex i = 0; i < 9; i++) ClearOldMap3(i);
for (TileIndex i{}; i < 9; i++) ClearOldMap3(i);
for (TileIndex i = TileXY(0, Map::MaxY()); i < Map::Size(); i++) ClearOldMap3(i);
if (_savegame_type == SGT_TTDP2) Debug(oldloader, 2, "Found TTDPatch game");

View File

@ -380,7 +380,7 @@ public:
if (IsSavegameVersionBefore(SLV_161) && !IsSavegameVersionBefore(SLV_145) && st->facilities & FACIL_AIRPORT) {
/* Store the old persistent storage. The GRFID will be added later. */
assert(PersistentStorage::CanAllocateItem());
st->airport.psa = new PersistentStorage(0, 0, 0);
st->airport.psa = new PersistentStorage(0, 0, TileIndex{});
std::copy(std::begin(_old_st_persistent_storage.storage), std::end(_old_st_persistent_storage.storage), std::begin(st->airport.psa->storage));
}

View File

@ -35,7 +35,7 @@ struct PSACChunkHandler : ChunkHandler {
while ((index = SlIterateArray()) != -1) {
assert(PersistentStorage::CanAllocateItem());
PersistentStorage *ps = new (index) PersistentStorage(0, 0, 0);
PersistentStorage *ps = new (index) PersistentStorage(0, 0, TileIndex{});
SlObject(ps, slt);
}
}

View File

@ -134,7 +134,7 @@
EnforcePrecondition(false, CanProspectIndustry(industry_type));
uint32_t seed = ScriptBase::Rand();
return ScriptObject::Command<CMD_BUILD_INDUSTRY>::Do(0, industry_type, 0, false, seed);
return ScriptObject::Command<CMD_BUILD_INDUSTRY>::Do(TileIndex{}, industry_type, 0, false, seed);
}
/* static */ bool ScriptIndustryType::IsBuiltOnWater(IndustryType industry_type)

View File

@ -80,7 +80,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_GOAL || !(StoryPage::Get(story_page_id)->company == INVALID_COMPANY && Goal::Get(reference)->company != INVALID_COMPANY));
uint32_t refid = 0;
TileIndex reftile = 0;
TileIndex reftile{};
switch (type) {
case SPET_LOCATION:
reftile = reference;
@ -129,7 +129,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
EnforcePrecondition(false, type != ::SPET_GOAL || !(p->company == INVALID_COMPANY && Goal::Get(reference)->company != INVALID_COMPANY));
uint32_t refid = 0;
TileIndex reftile = 0;
TileIndex reftile{};
switch (type) {
case ::SPET_LOCATION:
reftile = reference;

View File

@ -324,7 +324,7 @@ TileIndex Ship::GetOrderStationLocation(StationID station)
return st->xy;
} else {
this->IncrementRealOrderIndex();
return 0;
return TileIndex{};
}
}

View File

@ -1838,7 +1838,7 @@ static CommandCost RemoveRailStation(TileIndex tile, DoCommandFlag flags)
{
/* if there is flooding, remove platforms tile by tile */
if (_current_company == OWNER_WATER) {
return Command<CMD_REMOVE_FROM_RAIL_STATION>::Do(DC_EXEC, tile, 0, false);
return Command<CMD_REMOVE_FROM_RAIL_STATION>::Do(DC_EXEC, tile, TileIndex{}, false);
}
Station *st = Station::GetByTile(tile);
@ -1859,7 +1859,7 @@ static CommandCost RemoveRailWaypoint(TileIndex tile, DoCommandFlag flags)
{
/* if there is flooding, remove waypoints tile by tile */
if (_current_company == OWNER_WATER) {
return Command<CMD_REMOVE_FROM_RAIL_WAYPOINT>::Do(DC_EXEC, tile, 0, false);
return Command<CMD_REMOVE_FROM_RAIL_WAYPOINT>::Do(DC_EXEC, tile, TileIndex{}, false);
}
return RemoveRailStation(Waypoint::GetByTile(tile), flags, _price[PR_CLEAR_WAYPOINT_RAIL]);

View File

@ -557,7 +557,7 @@ protected:
this->SetTimeout();
this->SetWidgetDirty(WID_SB_PAGE_PANEL);
Command<CMD_STORY_PAGE_BUTTON>::Post(0, pe.index, 0);
Command<CMD_STORY_PAGE_BUTTON>::Post(TileIndex{}, pe.index, 0);
break;
case SPET_BUTTON_TILE:
@ -925,7 +925,7 @@ public:
VehicleType wanted_vehtype = data.GetVehicleType();
if (wanted_vehtype != VEH_INVALID && wanted_vehtype != v->type) return false;
Command<CMD_STORY_PAGE_BUTTON>::Post(0, pe->index, v->index);
Command<CMD_STORY_PAGE_BUTTON>::Post(TileIndex{}, pe->index, v->index);
ResetObjectToPlace();
return true;
}

View File

@ -2956,7 +2956,7 @@ TileIndex Train::GetOrderStationLocation(StationID station)
if (!(st->facilities & FACIL_TRAIN)) {
/* The destination station has no trainstation tiles. */
this->IncrementRealOrderIndex();
return 0;
return TileIndex{};
}
return st->xy;

View File

@ -2217,7 +2217,7 @@ public:
case WID_VL_STOP_ALL:
case WID_VL_START_ALL:
Command<CMD_MASS_START_STOP>::Post(0, widget == WID_VL_START_ALL, true, this->vli);
Command<CMD_MASS_START_STOP>::Post(TileIndex{}, widget == WID_VL_START_ALL, true, this->vli);
break;
}
}