diff -r 76282d3b748d -r ca3fd1fbe311 src/newgrf_industrytiles.cpp --- a/src/newgrf_industrytiles.cpp Thu Sep 06 19:42:48 2007 +0000 +++ b/src/newgrf_industrytiles.cpp Sat Oct 06 21:16:00 2007 +0000 @@ -39,7 +39,9 @@ is_same_industry = (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == index); tile_type = GetTerrainType(tile) << 2 | (IsTileType(tile, MP_WATER) ? 1 : 0) << 1 | (is_same_industry ? 1 : 0); - return GetTileType(tile) << 24 | (TileHeight(tile) * 8) << 16 | tile_type << 8 | GetTileSlope(tile, NULL); + uint z; + Slope tileh = GetTileSlope(tile, &z); + return GetTileType(tile) << 24 | z << 16 | tile_type << 8 | tileh; } /** This is the position of the tile relative to the northernmost tile of the industry. @@ -97,7 +99,7 @@ } /* Get industry tile ID at offset */ - case 0x62 : return GetIndustryIDAtOffset(GetNearbyTile(parameter, tile), tile, inds); + case 0x62 : return GetIndustryIDAtOffset(GetNearbyTile(parameter, tile), inds); } DEBUG(grf, 1, "Unhandled industry tile property 0x%X", variable); @@ -112,22 +114,30 @@ return NULL; } -uint32 IndustryTileGetRandomBits(const ResolverObject *object) +static uint32 IndustryTileGetRandomBits(const ResolverObject *object) { const TileIndex tile = object->u.industry.tile; - return (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) ? 0 : GetIndustryRandomBits(tile); + if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return 0; + return (object->scope == VSG_SCOPE_SELF) ? GetIndustryRandomBits(tile) : 0; //GetIndustryByTile(tile)->random_bits; } -uint32 IndustryTileGetTriggers(const ResolverObject *object) +static uint32 IndustryTileGetTriggers(const ResolverObject *object) { const TileIndex tile = object->u.industry.tile; - return (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) ? 0 : GetIndustryTriggers(tile); + if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return 0; + return (object->scope == VSG_SCOPE_SELF) ? GetIndustryTriggers(tile) : 0; //GetIndustryByTile(tile)->triggers; } -void IndustryTileSetTriggers(const ResolverObject *object, int triggers) +static void IndustryTileSetTriggers(const ResolverObject *object, int triggers) { const TileIndex tile = object->u.industry.tile; - if (IsTileType(tile, MP_INDUSTRY)) SetIndustryTriggers(tile, triggers); + if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return; + + if (object->scope != VSG_SCOPE_SELF) { + SetIndustryTriggers(tile, triggers); + } else { + //GetIndustryByTile(tile)->triggers = triggers; + } } static void NewIndustryTileResolver(ResolverObject *res, IndustryGfx gfx, TileIndex tile, Industry *indus) @@ -138,6 +148,7 @@ res->GetVariable = IndustryTileGetVariable; res->ResolveReal = IndustryTileResolveReal; + res->psa = &indus->psa; res->u.industry.tile = tile; res->u.industry.ind = indus; res->u.industry.gfx = gfx; @@ -158,14 +169,18 @@ SpriteID image = dts->ground_sprite; SpriteID pal = dts->ground_pal; + if (IS_CUSTOM_SPRITE(image)) image += stage; + if (GB(image, 0, SPRITE_WIDTH) != 0) DrawGroundSprite(image, pal); foreach_draw_tile_seq(dtss, dts->seq) { if (GB(dtss->image, 0, SPRITE_WIDTH) == 0) continue; - image = dtss->image + stage; + image = dtss->image; pal = dtss->pal; + if (IS_CUSTOM_SPRITE(image)) image += stage; + if (HASBIT(image, PALETTE_MODIFIER_COLOR)) { pal = GENERAL_SPRITE_COLOR(rnd_color); } else { @@ -181,7 +196,7 @@ !HASBIT(image, SPRITE_MODIFIER_OPAQUE) && HASBIT(_transparent_opt, TO_INDUSTRIES) ); } else { - AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y); + AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y, HASBIT(_transparent_opt, TO_INDUSTRIES)); } } } @@ -232,18 +247,23 @@ } } -bool PerformIndustryTileSlopeCheck(TileIndex tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx) +extern bool IsSlopeRefused(Slope current, Slope refused); + +bool PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, uint itspec_index) { Industry ind; - ind.xy = 0; + ind.index = INVALID_INDUSTRY; + ind.xy = ind_base_tile; ind.width = 0; ind.type = type; - uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, 0, gfx, &ind, tile); + uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, itspec_index, gfx, &ind, ind_tile); + if (callback_res == CALLBACK_FAILED) { + return !IsSlopeRefused(GetTileSlope(ind_tile, NULL), its->slopes_refused); + } if (its->grf_prop.grffile->grf_version < 7) { return callback_res != 0; } - if (callback_res == CALLBACK_FAILED) return false; switch (callback_res) { case 0x400: return true; @@ -347,8 +367,11 @@ uint32 random = Random(); BEGIN_TILE_LOOP(tile, ind->width, ind->height, ind->xy) if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) { - ret &= StartStopIndustryTileAnimation(tile, iat, random); - SB(random, 0, 16, Random()); + if (StartStopIndustryTileAnimation(tile, iat, random)) { + SB(random, 0, 16, Random()); + } else { + ret = false; + } } END_TILE_LOOP(tile, ind->width, ind->height, ind->xy)