src/newgrf_industrytiles.cpp
branchnoai
changeset 9629 66dde6412125
parent 9628 b5c2449616b5
child 9641 855e32c08c9b
equal deleted inserted replaced
9628:b5c2449616b5 9629:66dde6412125
   141 	res->last_value      = 0;
   141 	res->last_value      = 0;
   142 	res->trigger         = 0;
   142 	res->trigger         = 0;
   143 	res->reseed          = 0;
   143 	res->reseed          = 0;
   144 }
   144 }
   145 
   145 
       
   146 void IndustryDrawTileLayout(const TileInfo *ti, const SpriteGroup *group, byte rnd_color, byte stage, IndustryGfx gfx)
       
   147 {
       
   148 	const DrawTileSprites *dts = group->g.layout.dts;
       
   149 	const DrawTileSeqStruct *dtss;
       
   150 
       
   151 	SpriteID image = dts->ground_sprite;
       
   152 	SpriteID pal   = dts->ground_pal;
       
   153 
       
   154 	if (GB(image, 0, SPRITE_WIDTH) != 0) DrawGroundSprite(image, pal);
       
   155 
       
   156 	foreach_draw_tile_seq(dtss, dts->seq) {
       
   157 		if (GB(dtss->image, 0, SPRITE_WIDTH) == 0) continue;
       
   158 
       
   159 		image = dtss->image + stage;
       
   160 		pal   = dtss->pal;
       
   161 
       
   162 		if (!HASBIT(image, SPRITE_MODIFIER_OPAQUE) && HASBIT(_transparent_opt, TO_INDUSTRIES)) {
       
   163 			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
       
   164 			pal = PALETTE_TO_TRANSPARENT;
       
   165 		} else if (HASBIT(image, PALETTE_MODIFIER_COLOR)) {
       
   166 			pal = GENERAL_SPRITE_COLOR(rnd_color);
       
   167 		} else {
       
   168 			pal = PAL_NONE;
       
   169 		}
       
   170 
       
   171 		if ((byte)dtss->delta_z != 0x80) {
       
   172 			AddSortableSpriteToDraw(
       
   173 				image, pal,
       
   174 				ti->x + dtss->delta_x, ti->y + dtss->delta_y,
       
   175 				dtss->size_x, dtss->size_y,
       
   176 				dtss->size_z, ti->z + dtss->delta_z
       
   177 			);
       
   178 		} else {
       
   179 			AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y);
       
   180 		}
       
   181 	}
       
   182 }
       
   183 
   146 uint16 GetIndustryTileCallback(uint16 callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile)
   184 uint16 GetIndustryTileCallback(uint16 callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile)
   147 {
   185 {
   148 	ResolverObject object;
   186 	ResolverObject object;
   149 	const SpriteGroup *group;
   187 	const SpriteGroup *group;
   150 
   188 
   156 	group = Resolve(GetIndustryTileSpec(gfx_id)->grf_prop.spritegroup, &object);
   194 	group = Resolve(GetIndustryTileSpec(gfx_id)->grf_prop.spritegroup, &object);
   157 	if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
   195 	if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
   158 
   196 
   159 	return group->g.callback.result;
   197 	return group->g.callback.result;
   160 }
   198 }
       
   199 
       
   200 bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const IndustryTileSpec *inds)
       
   201 {
       
   202 	const SpriteGroup *group;
       
   203 	ResolverObject object;
       
   204 
       
   205 	if (ti->tileh != SLOPE_FLAT) {
       
   206 		bool draw_old_one = true;
       
   207 		if (HASBIT(inds->callback_flags, CBM_INDT_DRAW_FOUNDATIONS)) {
       
   208 			/* Called to determine the type (if any) of foundation to draw for industry tile */
       
   209 			uint32 callback_res = GetIndustryTileCallback(CBID_INDUSTRY_DRAW_FOUNDATIONS, 0, 0, gfx, i, ti->tile);
       
   210 			draw_old_one = callback_res == 0 || callback_res == CALLBACK_FAILED;
       
   211 		}
       
   212 
       
   213 		if (draw_old_one) DrawFoundation(ti, ti->tileh);
       
   214 	}
       
   215 
       
   216 	NewIndustryTileResolver(&object, gfx, ti->tile, i);
       
   217 
       
   218 	group = Resolve(inds->grf_prop.spritegroup, &object);
       
   219 	if (group == NULL || group->type != SGT_TILELAYOUT) {
       
   220 		return false;
       
   221 	} else {
       
   222 		/* Limit the building stage to the number of stages supplied. */
       
   223 		byte stage = GetIndustryConstructionStage(ti->tile);
       
   224 		stage = clamp(stage - 4 + group->g.layout.num_sprites, 0, group->g.layout.num_sprites - 1);
       
   225 		IndustryDrawTileLayout(ti, group, i->random_color, stage, gfx);
       
   226 		return true;
       
   227 	}
       
   228 }