summaryrefslogtreecommitdiff
path: root/src/newgrf_industries.cpp
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-01-21 18:32:44 +0000
committeryexo <yexo@openttd.org>2010-01-21 18:32:44 +0000
commite80f4f20afcc2791994ca895d094b4a3581e5a2b (patch)
tree023759df6781b56c0a9f2d74b7b5d418aaebcafd /src/newgrf_industries.cpp
parentd04441e3f7add1ef919649e89baf7a9af464e076 (diff)
downloadopenttd-e80f4f20afcc2791994ca895d094b4a3581e5a2b.tar.xz
(svn r18878) -Fix [NewGRF]: crash when a newgrf used var62 in an industry tile chain when the industry tile was part of an original industry
Diffstat (limited to 'src/newgrf_industries.cpp')
-rw-r--r--src/newgrf_industries.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp
index 9c099a203..f1b0e0ae1 100644
--- a/src/newgrf_industries.cpp
+++ b/src/newgrf_industries.cpp
@@ -43,12 +43,15 @@ IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id)
return _industry_mngr.GetID(GB(grf_type, 0, 6), grf_id);
}
-/** Make an analysis of a tile and check for its belonging to the same
+/**
+ * Make an analysis of a tile and check for its belonging to the same
* industry, and/or the same grf file
* @param tile TileIndex of the tile to query
* @param i Industry to which to compare the tile to
- * @return value encoded as per NFO specs */
-uint32 GetIndustryIDAtOffset(TileIndex tile, const Industry *i)
+ * @param cur_grfid GRFID of the current callback chain
+ * @return value encoded as per NFO specs
+ */
+uint32 GetIndustryIDAtOffset(TileIndex tile, const Industry *i, uint32 cur_grfid)
{
if (!IsTileType(tile, MP_INDUSTRY) || GetIndustryIndex(tile) != i->index) {
/* No industry and/or the tile does not have the same industry as the one we match it with */
@@ -57,17 +60,16 @@ uint32 GetIndustryIDAtOffset(TileIndex tile, const Industry *i)
IndustryGfx gfx = GetCleanIndustryGfx(tile);
const IndustryTileSpec *indtsp = GetIndustryTileSpec(gfx);
- const IndustrySpec *indold = GetIndustrySpec(i->type);
if (gfx < NEW_INDUSTRYOFFSET) { // Does it belongs to an old type?
/* It is an old tile. We have to see if it's been overriden */
if (indtsp->grf_prop.override == INVALID_INDUSTRYTILE) { // has it been overridden?
return 0xFF << 8 | gfx; // no. Tag FF + the gfx id of that tile
}
- /* Not overriden */
+ /* Overriden */
const IndustryTileSpec *tile_ovr = GetIndustryTileSpec(indtsp->grf_prop.override);
- if (tile_ovr->grf_prop.grffile->grfid == indold->grf_prop.grffile->grfid) {
+ if (tile_ovr->grf_prop.grffile->grfid == cur_grfid) {
return tile_ovr->grf_prop.local_id; // same grf file
} else {
return 0xFFFE; // not the same grf file
@@ -75,7 +77,7 @@ uint32 GetIndustryIDAtOffset(TileIndex tile, const Industry *i)
}
/* Not an 'old type' tile */
if (indtsp->grf_prop.spritegroup != NULL) { // tile has a spritegroup ?
- if (indtsp->grf_prop.grffile->grfid == indold->grf_prop.grffile->grfid) { // same industry, same grf ?
+ if (indtsp->grf_prop.grffile->grfid == cur_grfid) { // same industry, same grf ?
return indtsp->grf_prop.local_id;
} else {
return 0xFFFE; // Defined in another grf file
@@ -235,7 +237,7 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par
case 0x46: return industry->construction_date; // Date when built - long format - (in days)
/* Get industry ID at offset param */
- case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, industry->location.tile), industry);
+ case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, industry->location.tile), industry, object->grffile->grfid);
/* Get random tile bits at offset param */
case 0x61: