summaryrefslogtreecommitdiff
path: root/src/newgrf_industrytiles.cpp
diff options
context:
space:
mode:
authorbelugas <belugas@openttd.org>2007-06-19 17:33:12 +0000
committerbelugas <belugas@openttd.org>2007-06-19 17:33:12 +0000
commit2ad0d708cc9aeb55bbde1becae6a631e2d23e604 (patch)
tree7dce3da428d6c168798136589729b15e8493b68d /src/newgrf_industrytiles.cpp
parent2a6b7e4e02556f00161be4ac884b74486d6a9c6e (diff)
downloadopenttd-2ad0d708cc9aeb55bbde1becae6a631e2d23e604.tar.xz
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
Heavily based on Maedhros's newhouses implementation
Diffstat (limited to 'src/newgrf_industrytiles.cpp')
-rw-r--r--src/newgrf_industrytiles.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp
index d7cbe350d..5bce8b12d 100644
--- a/src/newgrf_industrytiles.cpp
+++ b/src/newgrf_industrytiles.cpp
@@ -143,6 +143,44 @@ static void NewIndustryTileResolver(ResolverObject *res, IndustryGfx gfx, TileIn
res->reseed = 0;
}
+void IndustryDrawTileLayout(const TileInfo *ti, const SpriteGroup *group, byte rnd_color, byte stage, IndustryGfx gfx)
+{
+ const DrawTileSprites *dts = group->g.layout.dts;
+ const DrawTileSeqStruct *dtss;
+
+ SpriteID image = dts->ground_sprite;
+ SpriteID pal = dts->ground_pal;
+
+ 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;
+ pal = dtss->pal;
+
+ if (!HASBIT(image, SPRITE_MODIFIER_OPAQUE) && HASBIT(_transparent_opt, TO_INDUSTRIES)) {
+ SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
+ pal = PALETTE_TO_TRANSPARENT;
+ } else if (HASBIT(image, PALETTE_MODIFIER_COLOR)) {
+ pal = GENERAL_SPRITE_COLOR(rnd_color);
+ } else {
+ pal = PAL_NONE;
+ }
+
+ if ((byte)dtss->delta_z != 0x80) {
+ AddSortableSpriteToDraw(
+ image, pal,
+ ti->x + dtss->delta_x, ti->y + dtss->delta_y,
+ dtss->size_x, dtss->size_y,
+ dtss->size_z, ti->z + dtss->delta_z
+ );
+ } else {
+ AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y);
+ }
+ }
+}
+
uint16 GetIndustryTileCallback(uint16 callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile)
{
ResolverObject object;
@@ -158,3 +196,33 @@ uint16 GetIndustryTileCallback(uint16 callback, uint32 param1, uint32 param2, In
return group->g.callback.result;
}
+
+bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const IndustryTileSpec *inds)
+{
+ const SpriteGroup *group;
+ ResolverObject object;
+
+ if (ti->tileh != SLOPE_FLAT) {
+ bool draw_old_one = true;
+ if (HASBIT(inds->callback_flags, CBM_INDT_DRAW_FOUNDATIONS)) {
+ /* Called to determine the type (if any) of foundation to draw for industry tile */
+ uint32 callback_res = GetIndustryTileCallback(CBID_INDUSTRY_DRAW_FOUNDATIONS, 0, 0, gfx, i, ti->tile);
+ draw_old_one = callback_res == 0 || callback_res == CALLBACK_FAILED;
+ }
+
+ if (draw_old_one) DrawFoundation(ti, ti->tileh);
+ }
+
+ NewIndustryTileResolver(&object, gfx, ti->tile, i);
+
+ group = Resolve(inds->grf_prop.spritegroup, &object);
+ if (group == NULL || group->type != SGT_TILELAYOUT) {
+ return false;
+ } else {
+ /* Limit the building stage to the number of stages supplied. */
+ byte stage = GetIndustryConstructionStage(ti->tile);
+ stage = clamp(stage - 4 + group->g.layout.num_sprites, 0, group->g.layout.num_sprites - 1);
+ IndustryDrawTileLayout(ti, group, i->random_color, stage, gfx);
+ return true;
+ }
+}