summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/disaster_cmd.cpp2
-rw-r--r--src/industry.h10
-rw-r--r--src/newgrf_industries.cpp4
-rw-r--r--src/newgrf_industrytiles.cpp4
4 files changed, 15 insertions, 5 deletions
diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp
index 89e19a67e..a551d83a6 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 b31bbd01e..85d86a110 100644
--- a/src/industry.h
+++ b/src/industry.h
@@ -78,6 +78,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
* @pre IsTileType(t, MP_INDUSTRY)
diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp
index 70e270b26..38daaa09b 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 bf5859864..c269c40a5 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);
}
}