(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

This commit is contained in:
yexo 2010-01-21 18:32:44 +00:00
parent d04441e3f7
commit e80f4f20af
3 changed files with 12 additions and 10 deletions

View File

@ -43,12 +43,15 @@ IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id)
return _industry_mngr.GetID(GB(grf_type, 0, 6), 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 * industry, and/or the same grf file
* @param tile TileIndex of the tile to query * @param tile TileIndex of the tile to query
* @param i Industry to which to compare the tile to * @param i Industry to which to compare the tile to
* @return value encoded as per NFO specs */ * @param cur_grfid GRFID of the current callback chain
uint32 GetIndustryIDAtOffset(TileIndex tile, const Industry *i) * @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) { 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 */ /* 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); IndustryGfx gfx = GetCleanIndustryGfx(tile);
const IndustryTileSpec *indtsp = GetIndustryTileSpec(gfx); const IndustryTileSpec *indtsp = GetIndustryTileSpec(gfx);
const IndustrySpec *indold = GetIndustrySpec(i->type);
if (gfx < NEW_INDUSTRYOFFSET) { // Does it belongs to an old 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 */ /* 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? if (indtsp->grf_prop.override == INVALID_INDUSTRYTILE) { // has it been overridden?
return 0xFF << 8 | gfx; // no. Tag FF + the gfx id of that tile 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); 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 return tile_ovr->grf_prop.local_id; // same grf file
} else { } else {
return 0xFFFE; // not the same grf file return 0xFFFE; // not the same grf file
@ -75,7 +77,7 @@ uint32 GetIndustryIDAtOffset(TileIndex tile, const Industry *i)
} }
/* Not an 'old type' tile */ /* Not an 'old type' tile */
if (indtsp->grf_prop.spritegroup != NULL) { // tile has a spritegroup ? 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; return indtsp->grf_prop.local_id;
} else { } else {
return 0xFFFE; // Defined in another grf file 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) case 0x46: return industry->construction_date; // Date when built - long format - (in days)
/* Get industry ID at offset param */ /* 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 */ /* Get random tile bits at offset param */
case 0x61: case 0x61:

View File

@ -34,7 +34,7 @@ enum IndustryAvailabilityCallType {
/* in newgrf_industry.cpp */ /* in newgrf_industry.cpp */
uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available); uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available);
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile); uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile);
uint32 GetIndustryIDAtOffset(TileIndex new_tile, const Industry *i); uint32 GetIndustryIDAtOffset(TileIndex new_tile, const Industry *i, uint32 cur_grfid);
void IndustryProductionCallback(Industry *ind, int reason); void IndustryProductionCallback(Industry *ind, int reason);
bool CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint itspec_index, uint32 seed); bool CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint itspec_index, uint32 seed);
bool CheckIfCallBackAllowsAvailability(IndustryType type, IndustryAvailabilityCallType creation_type); bool CheckIfCallBackAllowsAvailability(IndustryType type, IndustryAvailabilityCallType creation_type);

View File

@ -100,7 +100,7 @@ static uint32 IndustryTileGetVariable(const ResolverObject *object, byte variabl
return UINT_MAX; return UINT_MAX;
/* Get industry tile ID at offset */ /* Get industry tile ID at offset */
case 0x62: return GetIndustryIDAtOffset(GetNearbyTile(parameter, tile), inds); case 0x62: return GetIndustryIDAtOffset(GetNearbyTile(parameter, tile), inds, object->grffile->grfid);
} }
DEBUG(grf, 1, "Unhandled industry tile property 0x%X", variable); DEBUG(grf, 1, "Unhandled industry tile property 0x%X", variable);