diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp index 89e19a67e6..a551d83a62 100644 --- a/src/disaster_cmd.cpp +++ b/src/disaster_cmd.cpp @@ -376,7 +376,7 @@ static bool DisasterTick_Ufo(DisasterVehicle *v) static void DestructIndustry(Industry *i) { for (TileIndex tile = 0; tile != MapSize(); tile++) { - if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == i->index) { + if (i->TileBelongsToIndustry(tile)) { ResetIndustryConstructionStage(tile); MarkTileDirtyByTile(tile); } diff --git a/src/industry.h b/src/industry.h index b31bbd01e2..85d86a1107 100644 --- a/src/industry.h +++ b/src/industry.h @@ -77,6 +77,16 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> { void RecomputeProductionMultipliers(); + /** + * Check if a given tile belongs to this industry. + * @param tile The tile to check. + * @return True if the tils is part of this industry. + */ + inline bool TileBelongsToIndustry(TileIndex tile) const + { + return IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == this->index; + } + /** * Get the industry of the given tile * @param tile the tile to get the industry from diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index 70e270b263..38daaa09be 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -248,7 +248,7 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, uint32 p /* Get random tile bits at offset param */ case 0x61: tile = GetNearbyTile(parameter, tile, false); - return (IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile) == industry) ? GetIndustryRandomBits(tile) : 0; + return industry->TileBelongsToIndustry(tile) ? GetIndustryRandomBits(tile) : 0; /* Land info of nearby tiles */ case 0x62: return GetNearbyIndustryTileInformation(parameter, tile, INVALID_INDUSTRY, false, object->grffile->grf_version >= 8); @@ -256,7 +256,7 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, uint32 p /* Animation stage of nearby tiles */ case 0x63: tile = GetNearbyTile(parameter, tile, false); - if (IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile) == industry) { + if (industry->TileBelongsToIndustry(tile)) { return GetAnimationFrame(tile); } return 0xFFFFFFFF; diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp index bf58598647..c269c40a5b 100644 --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -345,7 +345,7 @@ bool StartStopIndustryTileAnimation(const Industry *ind, IndustryAnimationTrigge bool ret = true; uint32 random = Random(); TILE_AREA_LOOP(tile, ind->location) { - if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) { + if (ind->TileBelongsToIndustry(tile)) { if (StartStopIndustryTileAnimation(tile, iat, random)) { SB(random, 0, 16, Random()); } else { @@ -429,7 +429,7 @@ void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger) { uint32 reseed_industry = 0; TILE_AREA_LOOP(tile, ind->location) { - if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) { + if (ind->TileBelongsToIndustry(tile)) { DoTriggerIndustryTile(tile, trigger, ind, reseed_industry); } }