From 99158287fd34351e811acef1cb5e1fbdbe059439 Mon Sep 17 00:00:00 2001 From: belugas Date: Fri, 24 Aug 2007 00:23:35 +0000 Subject: [PATCH] (svn r10972) -Codechange: Implement the counterpart(GetTranslatedIndustryTileID) of getindustileid of TTDPatch. This allows to ensure that the ID of a tile (taken out of the map or not) is still a valid one regarding the possible override it may have been flagged to. It is not the strict same thing, but is what we need regarding the slightly different approach we took for newindustries. --- src/industry.h | 7 +++++++ src/industry_cmd.cpp | 8 ++++---- src/industry_map.h | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/industry.h b/src/industry.h index c92c120418..2cdf1ce7ed 100644 --- a/src/industry.h +++ b/src/industry.h @@ -220,6 +220,13 @@ void PlantRandomFarmField(const Industry *i); extern IndustrySpec _industry_specs[NUM_INDUSTRYTYPES]; extern IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES]; +static inline IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx) +{ + assert(gfx < INVALID_INDUSTRYTILE); + const IndustryTileSpec *it = &_industry_tile_specs[gfx]; + return it->grf_prop.override == INVALID_INDUSTRYTILE ? gfx : it->grf_prop.override; +} + /* smallmap_gui.cpp */ void BuildIndustriesLegend(); diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 28732cf75f..1d5b2939dc 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -328,7 +328,6 @@ static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac) { IndustryGfx gfx = GetIndustryGfx(tile); const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx); - if (itspec->grf_prop.override != INVALID_INDUSTRYTILE) itspec = GetIndustryTileSpec(itspec->grf_prop.override); /* When we have to use a callback, we put our data in the next two variables */ CargoID raw_accepts_cargo[lengthof(itspec->accepts_cargo)]; @@ -1180,14 +1179,15 @@ static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable _error_message = STR_0239_SITE_UNSUITABLE; do { + IndustryGfx gfx = GetTranslatedIndustryTileID(it->gfx); TileIndex cur_tile = tile + ToTileIndexDiff(it->ti); if (!IsValidTile(cur_tile)) { - if (it->gfx == 0xff) continue; + if (gfx == 0xff) continue; return false; } - if (it->gfx == 0xFF) { + if (gfx == 0xFF) { if (!IsTileType(cur_tile, MP_WATER) || GetTileSlope(cur_tile, NULL) != SLOPE_FLAT) { return false; @@ -1201,7 +1201,7 @@ static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable if (HASBIT(its->callback_flags, CBM_INDT_SHAPE_CHECK)) { if (custom_shape_check != NULL) *custom_shape_check = true; - if (!PerformIndustryTileSlopeCheck(cur_tile, its, type, it->gfx)) return false; + if (!PerformIndustryTileSlopeCheck(cur_tile, its, type, gfx)) return false; } else { if (ind_behav & INDUSTRYBEH_BUILT_ONWATER) { /* As soon as the tile is not water, bail out. diff --git a/src/industry_map.h b/src/industry_map.h index 91ea969724..18e72eb33d 100644 --- a/src/industry_map.h +++ b/src/industry_map.h @@ -132,7 +132,7 @@ static inline void SetIndustryConstructionStage(TileIndex tile, byte value) static inline IndustryGfx GetIndustryGfx(TileIndex t) { assert(IsTileType(t, MP_INDUSTRY)); - return _m[t].m5; + return GetTranslatedIndustryTileID(_m[t].m5 | (GB(_m[t].m6, 2, 1) << 8)); } /**