diff options
-rw-r--r-- | src/newgrf.cpp | 10 | ||||
-rw-r--r-- | src/newgrf_industries.cpp | 31 | ||||
-rw-r--r-- | src/newgrf_industries.h | 2 | ||||
-rw-r--r-- | src/newgrf_industrytiles.cpp | 5 |
4 files changed, 42 insertions, 6 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp index f7bce1cb9..7afed1eea 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -44,6 +44,7 @@ #include "table/build_industry.h" #include "newgrf_commons.h" #include "newgrf_townname.h" +#include "newgrf_industries.h" /* TTDPatch extended GRF format codec * (c) Petr Baudis 2004 (GPL'd) @@ -5228,6 +5229,15 @@ static void FinaliseIndustriesArray() } } } + + for (uint j = 0; j < NUM_INDUSTRYTYPES; j++) { + IndustrySpec *indsp = &_industry_specs[j]; + if (indsp->enabled && indsp->grf_prop.grffile != NULL) { + for (uint i = 0; i < 3; i++) { + indsp->conflicting[i] = MapNewGRFIndustryType(indsp->conflicting[i], indsp->grf_prop.grffile->grfid); + } + } + } } /** Each cargo string needs to be mapped from TTDPatch to OpenTTD string IDs. diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index 33925dcbe..e66c5bc47 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -27,6 +27,14 @@ IndustryOverrideManager _industry_mngr(NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, INVALID_INDUSTRYTYPE); IndustryTileOverrideManager _industile_mngr(NEW_INDUSTRYTILEOFFSET, NUM_INDUSTRYTILES, INVALID_INDUSTRYTILE); +IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id) +{ + if (grf_type == IT_INVALID) return IT_INVALID; + if (!HASBIT(grf_type, 7)) return GB(grf_type, 0, 6); + + return _industry_mngr.GetID(GB(grf_type, 0, 6), grf_id); +} + /** * Finds the distance for the closest tile with water/land given a tile * @param tile the tile to find the distance too @@ -112,6 +120,19 @@ uint32 GetIndustryIDAtOffset(TileIndex new_tile, TileIndex old_tile, const Indus return 0xFFFF; // tile is not an industry one or does not belong to the current industry } +static uint32 GetClosestIndustry(TileIndex tile, IndustryType type, const Industry *current) +{ + uint32 best_dist = MAX_UVALUE(uint32); + const Industry *i; + FOR_ALL_INDUSTRIES(i) { + if (i->type != type || i == current) continue; + + best_dist = min(best_dist, DistanceManhattan(tile, i->xy)); + } + + return best_dist; +} + /** This function implements the industries variables that newGRF defines. * @param variable that is queried * @param parameter unused @@ -145,8 +166,8 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par case 0x61: return 0; // Get random tile bits at offset param case 0x62: // Land info of nearby tiles - case 0x63: // Animation stage of nerby tiles - case 0x64: break; // Distance of nearest industry of given type + case 0x63: break; // Animation stage of nerby tiles + case 0x64: return GetClosestIndustry(tile, MapNewGRFIndustryType(parameter, indspec->grf_prop.grffile->grfid), industry); // Distance of nearest industry of given type /* Get town zone and Manhattan distance of closest town */ case 0x65: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceManhattan(tile, industry->town->xy), 0xFFFF); /* Get square of Euclidian distance of closes town */ @@ -275,8 +296,8 @@ uint32 IndustryLocationGetVariable(const ResolverObject *object, byte variable, } switch (variable) { - case 0x62: // Land info of nearby tiles - case 0x64: break; // Distance of nearest industry of given type + case 0x62: break;// Land info of nearby tiles + case 0x64: return GetClosestIndustry(tile, MapNewGRFIndustryType(parameter, object->u.industry_location.spec->grf_prop.grffile->grfid), NULL); // Distance of nearest industry of given type /* Location where to build the industry */ case 0x80: return tile; @@ -309,7 +330,7 @@ uint32 IndustryLocationGetVariable(const ResolverObject *object, byte variable, case 0x8D: return min(DistanceSquare(ClosestTownFromTile(tile, (uint)-1)->xy, tile), 65535); } - DEBUG(grf, 1, "Unhandled industry property 0x%X", variable); + DEBUG(grf, 1, "Unhandled location industry property 0x%X", variable); *available = false; return (uint32)-1; diff --git a/src/newgrf_industries.h b/src/newgrf_industries.h index 997a9e3f9..a493c37e8 100644 --- a/src/newgrf_industries.h +++ b/src/newgrf_industries.h @@ -15,6 +15,8 @@ uint32 GetIndustryIDAtOffset(TileIndex new_tile, TileIndex old_tile, const Indus void IndustryProductionCallback(Industry *ind, int reason); bool CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint itspec_index); +IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id); + /* in newgrf_industrytiles.cpp*/ uint32 IndustryTileGetRandomBits(const ResolverObject *object); uint32 IndustryTileGetTriggers(const ResolverObject *object); diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp index f87e4a6d7..028cbf54d 100644 --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -99,7 +99,10 @@ static uint32 IndustryTileGetVariable(const ResolverObject *object, byte variabl case 0x62 : return GetIndustryIDAtOffset(GetNearbyTile(parameter, tile), tile, inds); } - return 0; + DEBUG(grf, 1, "Unhandled industry tile property 0x%X", variable); + + *available = false; + return (uint32)-1; } static const SpriteGroup *IndustryTileResolveReal(const ResolverObject *object, const SpriteGroup *group) |