(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

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
yexo 15 years ago
parent d04441e3f7
commit e80f4f20af

@ -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:

@ -34,7 +34,7 @@ enum IndustryAvailabilityCallType {
/* in newgrf_industry.cpp */
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);
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);
bool CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint itspec_index, uint32 seed);
bool CheckIfCallBackAllowsAvailability(IndustryType type, IndustryAvailabilityCallType creation_type);

@ -100,7 +100,7 @@ static uint32 IndustryTileGetVariable(const ResolverObject *object, byte variabl
return UINT_MAX;
/* 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);

Loading…
Cancel
Save