(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
authorrubidium
Thu, 26 Jul 2007 14:07:11 +0000
changeset 7333 e48228e44be8
parent 7332 543ecb9e2caf
child 7334 ed9a43cf642a
(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
src/elrail.cpp
src/industry_cmd.cpp
src/newgrf_house.cpp
src/newgrf_industrytiles.cpp
src/rail_cmd.cpp
src/road_cmd.cpp
src/station_cmd.cpp
src/town_cmd.cpp
src/tree_cmd.cpp
src/tunnelbridge_cmd.cpp
src/unmovable_cmd.cpp
src/vehicle.cpp
src/viewport.cpp
src/viewport.h
src/water_cmd.cpp
--- a/src/elrail.cpp	Thu Jul 26 11:19:03 2007 +0000
+++ b/src/elrail.cpp	Thu Jul 26 14:07:11 2007 +0000
@@ -270,15 +270,9 @@
 						continue; /* No neighbour, go looking for a better position */
 					}
 
-					SpriteID img = pylons_normal[temp];
-					SpriteID pal = PAL_NONE;
-					if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
-						SETBIT(img, PALETTE_MODIFIER_TRANSPARENT);
-						pal = PALETTE_TO_TRANSPARENT;
-					}
-
-					AddSortableSpriteToDraw(img, pal, x, y, 1, 1, 10,
-							GetSlopeZ(ti->x + x_pcp_offsets[i], ti->y + y_pcp_offsets[i]));
+					AddSortableSpriteToDraw(pylons_normal[temp], PAL_NONE, x, y, 1, 1, 10,
+							GetSlopeZ(ti->x + x_pcp_offsets[i], ti->y + y_pcp_offsets[i]),
+							HASBIT(_transparent_opt, TO_BUILDINGS));
 					break; /* We already have drawn a pylon, bail out */
 				}
 			}
@@ -315,15 +309,9 @@
 			assert(!IsSteepSlope(tileh[TS_HOME]));
 			sss = &CatenarySpriteData[Wires[tileh_selector][t][PCPconfig]];
 
-			SpriteID img = sss->image;
-			SpriteID pal = PAL_NONE;
-			if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
-				SETBIT(img, PALETTE_MODIFIER_TRANSPARENT);
-				pal = PALETTE_TO_TRANSPARENT;
-			}
-
-			AddSortableSpriteToDraw(img, pal, ti->x + sss->x_offset, ti->y + sss->y_offset,
-				sss->x_size, sss->y_size, sss->z_size, GetSlopeZ(ti->x + min(sss->x_offset, TILE_SIZE - 1), ti->y + min(sss->y_offset, TILE_SIZE - 1)) + sss->z_offset);
+			AddSortableSpriteToDraw(sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
+				sss->x_size, sss->y_size, sss->z_size, GetSlopeZ(ti->x + min(sss->x_offset, TILE_SIZE - 1), ti->y + min(sss->y_offset, TILE_SIZE - 1)) + sss->z_offset,
+				HASBIT(_transparent_opt, TO_BUILDINGS));
 		}
 	}
 }
@@ -354,41 +342,27 @@
 
 	height = GetBridgeHeight(end);
 
-	SpriteID img = sss->image;
-	SpriteID pal = PAL_NONE;
-	if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
-		SETBIT(img, PALETTE_MODIFIER_TRANSPARENT);
-		pal = PALETTE_TO_TRANSPARENT;
-	}
-
-	AddSortableSpriteToDraw(img, pal, ti->x + sss->x_offset, ti->y + sss->y_offset,
-		sss->x_size, sss->y_size, sss->z_size, height + sss->z_offset
+	AddSortableSpriteToDraw(sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
+		sss->x_size, sss->y_size, sss->z_size, height + sss->z_offset,
+		HASBIT(_transparent_opt, TO_BUILDINGS)
 	);
 
 	/* Finished with wires, draw pylons */
 	/* every other tile needs a pylon on the northern end */
 	if (num % 2) {
 		if (axis == AXIS_X) {
-			img = pylons_bridge[0 + HASBIT(tlg, 0)];
-			if (HASBIT(_transparent_opt, TO_BUILDINGS)) SETBIT(img, PALETTE_MODIFIER_TRANSPARENT);
-			AddSortableSpriteToDraw(img, pal, ti->x, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, height);
+			AddSortableSpriteToDraw(pylons_bridge[0 + HASBIT(tlg, 0)], PAL_NONE, ti->x, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, height, HASBIT(_transparent_opt, TO_BUILDINGS));
 		} else {
-			img = pylons_bridge[2 + HASBIT(tlg, 1)];
-			if (HASBIT(_transparent_opt, TO_BUILDINGS)) SETBIT(img, PALETTE_MODIFIER_TRANSPARENT);
-			AddSortableSpriteToDraw(img, pal, ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y, 1, 1, 10, height);
+			AddSortableSpriteToDraw(pylons_bridge[2 + HASBIT(tlg, 1)], PAL_NONE, ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y, 1, 1, 10, height, HASBIT(_transparent_opt, TO_BUILDINGS));
 		}
 	}
 
 	/* need a pylon on the southern end of the bridge */
 	if (DistanceMax(ti->tile, start) == length) {
 		if (axis == AXIS_X) {
-			img = pylons_bridge[0 + HASBIT(tlg, 0)];
-			if (HASBIT(_transparent_opt, TO_BUILDINGS)) SETBIT(img, PALETTE_MODIFIER_TRANSPARENT);
-			AddSortableSpriteToDraw(img, pal, ti->x + 16, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, height);
+			AddSortableSpriteToDraw(pylons_bridge[0 + HASBIT(tlg, 0)], PAL_NONE, ti->x + 16, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, height, HASBIT(_transparent_opt, TO_BUILDINGS));
 		} else {
-			img = pylons_bridge[2 + HASBIT(tlg, 1)];
-			if (HASBIT(_transparent_opt, TO_BUILDINGS)) SETBIT(img, PALETTE_MODIFIER_TRANSPARENT);
-			AddSortableSpriteToDraw(img, pal, ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y + 16, 1, 1, 10, height);
+			AddSortableSpriteToDraw(pylons_bridge[2 + HASBIT(tlg, 1)], PAL_NONE, ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y + 16, 1, 1, 10, height, HASBIT(_transparent_opt, TO_BUILDINGS));
 		}
 	}
 }
@@ -410,17 +384,11 @@
 			if (IsRailDepot(ti->tile)) {
 				const SortableSpriteStruct *sss = &CatenarySpriteData_Depot[GetRailDepotDirection(ti->tile)];
 
-				SpriteID img = sss->image;
-				SpriteID pal = PAL_NONE;
-				if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
-					SETBIT(img, PALETTE_MODIFIER_TRANSPARENT);
-					pal = PALETTE_TO_TRANSPARENT;
-				}
-
 				AddSortableSpriteToDraw(
-					img, pal, ti->x + sss->x_offset, ti->y + sss->y_offset,
+					sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
 					sss->x_size, sss->y_size, sss->z_size,
-					GetTileMaxZ(ti->tile) + sss->z_offset
+					GetTileMaxZ(ti->tile) + sss->z_offset,
+					HASBIT(_transparent_opt, TO_BUILDINGS)
 				);
 				return;
 			}
--- a/src/industry_cmd.cpp	Thu Jul 26 11:19:03 2007 +0000
+++ b/src/industry_cmd.cpp	Thu Jul 26 14:07:11 2007 +0000
@@ -299,22 +299,15 @@
 	/* Add industry on top of the ground? */
 	image = dits->building.sprite;
 	if (image != 0) {
-		if (HASBIT(_transparent_opt, TO_INDUSTRIES)) {
-			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
-			pal = PALETTE_TO_TRANSPARENT;
-		} else if (HASBIT(image, PALETTE_MODIFIER_COLOR) && dits->building.pal == PAL_NONE) {
-			pal = GENERAL_SPRITE_COLOR(ind->random_color);
-		} else {
-			pal = dits->building.pal;
-		}
-
-		AddSortableSpriteToDraw(image, pal,
+		AddSortableSpriteToDraw(image,
+			(HASBIT(image, PALETTE_MODIFIER_COLOR) && dits->building.pal == PAL_NONE) ? GENERAL_SPRITE_COLOR(ind->random_color) : dits->building.pal,
 			ti->x + dits->subtile_x,
 			ti->y + dits->subtile_y,
 			dits->width  + 1,
 			dits->height + 1,
 			dits->dz,
-			z);
+			z,
+			HASBIT(_transparent_opt, TO_INDUSTRIES));
 
 		if (HASBIT(_transparent_opt, TO_INDUSTRIES)) return;
 	}
--- a/src/newgrf_house.cpp	Thu Jul 26 11:19:03 2007 +0000
+++ b/src/newgrf_house.cpp	Thu Jul 26 14:07:11 2007 +0000
@@ -314,10 +314,7 @@
 		image = dtss->image + stage;
 		pal   = dtss->pal;
 
-		if (!HASBIT(image, SPRITE_MODIFIER_OPAQUE) && HASBIT(_transparent_opt, TO_HOUSES)) {
-			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
-			pal = PALETTE_TO_TRANSPARENT;
-		} else if (HASBIT(image, PALETTE_MODIFIER_COLOR)) {
+		if ((HASBIT(image, SPRITE_MODIFIER_OPAQUE) || !HASBIT(_transparent_opt, TO_HOUSES)) && HASBIT(image, PALETTE_MODIFIER_COLOR)) {
 			if (pal == 0) {
 				const HouseSpec *hs = GetHouseSpecs(house_id);
 				if (HASBIT(hs->callback_mask, CBM_BUILDING_COLOUR)) {
@@ -339,7 +336,8 @@
 				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
+				dtss->size_z, ti->z + dtss->delta_z,
+				HASBIT(_transparent_opt, TO_HOUSES)
 			);
 		} else {
 			AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y);
--- a/src/newgrf_industrytiles.cpp	Thu Jul 26 11:19:03 2007 +0000
+++ b/src/newgrf_industrytiles.cpp	Thu Jul 26 14:07:11 2007 +0000
@@ -166,10 +166,7 @@
 		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)) {
+		if (HASBIT(image, PALETTE_MODIFIER_COLOR)) {
 			pal = GENERAL_SPRITE_COLOR(rnd_color);
 		} else {
 			pal = PAL_NONE;
@@ -180,7 +177,8 @@
 				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
+				dtss->size_z, ti->z + dtss->delta_z,
+				!HASBIT(image, SPRITE_MODIFIER_OPAQUE) && HASBIT(_transparent_opt, TO_INDUSTRIES)
 			);
 		} else {
 			AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y);
--- a/src/rail_cmd.cpp	Thu Jul 26 11:19:03 2007 +0000
+++ b/src/rail_cmd.cpp	Thu Jul 26 14:07:11 2007 +0000
@@ -1526,10 +1526,7 @@
 				image += relocation;
 			}
 
-			if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
-				SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
-				pal = PALETTE_TO_TRANSPARENT;
-			} else if (HASBIT(image, PALETTE_MODIFIER_COLOR)) {
+			if (!HASBIT(_transparent_opt, TO_BUILDINGS) && HASBIT(image, PALETTE_MODIFIER_COLOR)) {
 				pal = _drawtile_track_palette;
 			} else {
 				pal = dtss->pal;
@@ -1540,7 +1537,8 @@
 					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
+					dtss->size_z, ti->z + dtss->delta_z,
+					HASBIT(_transparent_opt, TO_BUILDINGS)
 				);
 			} else {
 				AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y);
--- a/src/road_cmd.cpp	Thu Jul 26 11:19:03 2007 +0000
+++ b/src/road_cmd.cpp	Thu Jul 26 14:07:11 2007 +0000
@@ -918,15 +918,8 @@
 		front = SPR_TRAMWAY_BASE + _road_frontwire_sprites_1[tram];
 	}
 
-	SpriteID pal = PAL_NONE;
-	if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
-		SETBIT(front, PALETTE_MODIFIER_TRANSPARENT);
-		SETBIT(back,  PALETTE_MODIFIER_TRANSPARENT);
-		pal = PALETTE_TO_TRANSPARENT;
-	}
-
-	AddSortableSpriteToDraw(back,  pal, ti->x, ti->y, 16, 16, 0x1F, ti->z);
-	AddSortableSpriteToDraw(front, pal, ti->x, ti->y, 16, 16, 0x1F, ti->z);
+	AddSortableSpriteToDraw(back,  PAL_NONE, ti->x, ti->y, 16, 16, 0x1F, ti->z, HASBIT(_transparent_opt, TO_BUILDINGS));
+	AddSortableSpriteToDraw(front, PAL_NONE, ti->x, ti->y, 16, 16, 0x1F, ti->z, HASBIT(_transparent_opt, TO_BUILDINGS));
 }
 
 /**
@@ -1084,10 +1077,7 @@
 				SpriteID image = dtss->image;
 				SpriteID pal;
 
-				if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
-					SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
-					pal = PALETTE_TO_TRANSPARENT;
-				} else if (HASBIT(image, PALETTE_MODIFIER_COLOR)) {
+				if (!HASBIT(_transparent_opt, TO_BUILDINGS) && HASBIT(image, PALETTE_MODIFIER_COLOR)) {
 					pal = palette;
 				} else {
 					pal = PAL_NONE;
@@ -1097,7 +1087,8 @@
 					image, pal,
 					ti->x + dtss->delta_x, ti->y + dtss->delta_y,
 					dtss->size_x, dtss->size_y,
-					dtss->size_z, ti->z
+					dtss->size_z, ti->z,
+					HASBIT(_transparent_opt, TO_BUILDINGS)
 				);
 			}
 			break;
--- a/src/station_cmd.cpp	Thu Jul 26 11:19:03 2007 +0000
+++ b/src/station_cmd.cpp	Thu Jul 26 14:07:11 2007 +0000
@@ -2131,10 +2131,7 @@
 		}
 
 		SpriteID pal;
-		if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
-			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
-			pal = PALETTE_TO_TRANSPARENT;
-		} else if (HASBIT(image, PALETTE_MODIFIER_COLOR)) {
+		if (!HASBIT(_transparent_opt, TO_BUILDINGS) && HASBIT(image, PALETTE_MODIFIER_COLOR)) {
 			pal = palette;
 		} else {
 			pal = dtss->pal;
@@ -2145,7 +2142,8 @@
 				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
+				dtss->size_z, ti->z + dtss->delta_z,
+				HASBIT(_transparent_opt, TO_BUILDINGS)
 			);
 		} else {
 			AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y);
--- a/src/town_cmd.cpp	Thu Jul 26 11:19:03 2007 +0000
+++ b/src/town_cmd.cpp	Thu Jul 26 14:07:11 2007 +0000
@@ -163,20 +163,14 @@
 	/* Add a house on top of the ground? */
 	image = dcts->building.sprite;
 	if (image != 0) {
-		if (HASBIT(_transparent_opt, TO_HOUSES)) {
-			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
-			pal = PALETTE_TO_TRANSPARENT;
-		} else {
-			pal = dcts->building.pal;
-		}
-
-		AddSortableSpriteToDraw(image, pal,
+		AddSortableSpriteToDraw(image, dcts->building.pal,
 			ti->x + dcts->subtile_x,
 			ti->y + dcts->subtile_y,
 			dcts->width + 1,
 			dcts->height + 1,
 			dcts->dz,
-			ti->z
+			ti->z,
+			HASBIT(_transparent_opt, TO_HOUSES)
 		);
 
 		if (HASBIT(_transparent_opt, TO_HOUSES)) return;
--- a/src/tree_cmd.cpp	Thu Jul 26 11:19:03 2007 +0000
+++ b/src/tree_cmd.cpp	Thu Jul 26 14:07:11 2007 +0000
@@ -374,13 +374,8 @@
 		i = GetTreeCount(ti->tile) + 1;
 		do {
 			SpriteID image = s[0].sprite + (--i == 0 ? GetTreeGrowth(ti->tile) : 3);
-			SpriteID pal;
-			if (HASBIT(_transparent_opt, TO_TREES)) {
-				SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
-				pal = PALETTE_TO_TRANSPARENT;
-			} else {
-				pal = s[0].pal;
-			}
+			SpriteID pal = s[0].pal;
+
 			te[i].image = image;
 			te[i].pal   = pal;
 			te[i].x = d->x;
@@ -404,7 +399,7 @@
 
 			if (tep == NULL) break;
 
-			AddSortableSpriteToDraw(tep->image, tep->pal, ti->x + tep->x, ti->y + tep->y, 5, 5, 0x10, z);
+			AddSortableSpriteToDraw(tep->image, tep->pal, ti->x + tep->x, ti->y + tep->y, 5, 5, 0x10, z, HASBIT(_transparent_opt, TO_TREES));
 			tep->image = 0;
 		}
 	}
--- a/src/tunnelbridge_cmd.cpp	Thu Jul 26 11:19:03 2007 +0000
+++ b/src/tunnelbridge_cmd.cpp	Thu Jul 26 14:07:11 2007 +0000
@@ -831,7 +831,6 @@
 		int back_height, front_height;
 		int i = z;
 		const byte *p;
-		SpriteID pal;
 
 		static const byte _tileh_bits[4][8] = {
 			{ 2, 1, 8, 4,  16,  2, 0, 9 },
@@ -840,13 +839,6 @@
 			{ 2, 4, 8, 1,   2, 16, 9, 0 }
 		};
 
-		if (HASBIT(_transparent_opt, TO_BRIDGES)) {
-			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
-			pal = PALETTE_TO_TRANSPARENT;
-		} else {
-			pal = psid->pal;
-		}
-
 		p = _tileh_bits[(image & 1) * 2 + (axis == AXIS_X ? 0 : 1)];
 		front_height = ti->z + (ti->tileh & p[0] ? TILE_HEIGHT : 0);
 		back_height  = ti->z + (ti->tileh & p[1] ? TILE_HEIGHT : 0);
@@ -861,11 +853,11 @@
 			 * sprites is at the top
 			 */
 			if (z >= front_height) { // front facing pillar
-				AddSortableSpriteToDraw(image, pal, x, y, p[4], p[5], 1, z);
+				AddSortableSpriteToDraw(image, psid->pal, x, y, p[4], p[5], 1, z, HASBIT(_transparent_opt, TO_BRIDGES));
 			}
 
 			if (drawfarpillar && z >= back_height && z < i - TILE_HEIGHT) { // back facing pillar
-				AddSortableSpriteToDraw(image, pal, x - p[6], y - p[7], p[4], p[5], 1, z);
+				AddSortableSpriteToDraw(image, psid->pal, x - p[6], y - p[7], p[4], p[5], 1, z, HASBIT(_transparent_opt, TO_BRIDGES));
 			}
 		}
 	}
@@ -912,18 +904,9 @@
 
 	AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + tram_offsets[overlay][offset], PAL_NONE, x, y, size_x[offset], size_y[offset], offset >= 2 ? 1 : 0, z);
 
-	SpriteID front = SPR_TRAMWAY_BASE + front_offsets[offset];
-	SpriteID back  = SPR_TRAMWAY_BASE + back_offsets[offset];
-	SpriteID pal   = PAL_NONE;
-	if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
-		SETBIT(front, PALETTE_MODIFIER_TRANSPARENT);
-		SETBIT(back,  PALETTE_MODIFIER_TRANSPARENT);
-		pal = PALETTE_TO_TRANSPARENT;
-	}
-
-	AddSortableSpriteToDraw(back,  pal, x, y, size_x[offset], size_y[offset], 0, z);
+	AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + back_offsets[offset],  PAL_NONE, x, y, size_x[offset], size_y[offset], 0, z, HASBIT(_transparent_opt, TO_BUILDINGS));
 	/* For sloped sprites the bounding box needs to be higher, as the pylons stop on a higher point */
-	AddSortableSpriteToDraw(front, pal, x, y, size_x[offset], size_y[offset], offset >= 2 ? 0x30 : 0x10, z);
+	AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + front_offsets[offset], PAL_NONE, x, y, size_x[offset], size_y[offset], offset >= 2 ? 0x30 : 0x10, z, HASBIT(_transparent_opt, TO_BUILDINGS));
 }
 
 /**
@@ -942,7 +925,6 @@
 static void DrawTile_TunnelBridge(TileInfo *ti)
 {
 	SpriteID image;
-	SpriteID pal;
 
 	if (IsTunnel(ti->tile)) {
 		if (GetTunnelTransportType(ti->tile) == TRANSPORT_RAIL) {
@@ -1005,21 +987,13 @@
 			DrawGroundSprite(SPR_FLAT_SNOWY_TILE + _tileh_to_sprite[ti->tileh], PAL_NONE);
 		}
 
-		image = psid->sprite;
-
 		/* draw ramp */
-		if (HASBIT(_transparent_opt, TO_BRIDGES)) {
-			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
-			pal = PALETTE_TO_TRANSPARENT;
-		} else {
-			pal = psid->pal;
-		}
 
 		/* HACK set the height of the BB of a sloped ramp to 1 so a vehicle on
 		 * it doesn't disappear behind it
 		 */
 		AddSortableSpriteToDraw(
-			image, pal, ti->x, ti->y, 16, 16, ti->tileh == SLOPE_FLAT ? 0 : 8, ti->z
+			psid->sprite, psid->pal, ti->x, ti->y, 16, 16, ti->tileh == SLOPE_FLAT ? 0 : 8, ti->z, HASBIT(_transparent_opt, TO_BRIDGES)
 		);
 
 		if (GetBridgeTransportType(ti->tile) == TRANSPORT_ROAD) {
@@ -1082,8 +1056,6 @@
 void DrawBridgeMiddle(const TileInfo* ti)
 {
 	const PalSpriteID* psid;
-	SpriteID image;
-	SpriteID pal;
 	uint base_offset;
 	TileIndex rampnorth;
 	TileIndex rampsouth;
@@ -1120,28 +1092,13 @@
 	uint bridge_z = GetBridgeHeight(rampsouth);
 	z = bridge_z - 3;
 
-	image = psid->sprite;
-	if (HASBIT(_transparent_opt, TO_BRIDGES)) {
-		SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
-		pal = PALETTE_TO_TRANSPARENT;
+	if (axis == AXIS_X) {
+		AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 16, 11, 1, z, HASBIT(_transparent_opt, TO_BRIDGES));
 	} else {
-		pal = psid->pal;
-	}
-
-	if (axis == AXIS_X) {
-		AddSortableSpriteToDraw(image, pal, x, y, 16, 11, 1, z);
-	} else {
-		AddSortableSpriteToDraw(image, pal, x, y, 11, 16, 1, z);
+		AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 11, 16, 1, z, HASBIT(_transparent_opt, TO_BRIDGES));
 	}
 
 	psid++;
-	image = psid->sprite;
-	if (HASBIT(_transparent_opt, TO_BRIDGES)) {
-		SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
-		pal = PALETTE_TO_TRANSPARENT;
-	} else {
-		pal = psid->pal;
-	}
 
 	if (GetBridgeTransportType(rampsouth) == TRANSPORT_ROAD) {
 		RoadTypes rts = GetRoadTypes(rampsouth);
@@ -1156,22 +1113,21 @@
 	/* draw roof, the component of the bridge which is logically between the vehicle and the camera */
 	if (axis == AXIS_X) {
 		y += 12;
-		if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, pal, x, y, 16, 1, 0x28, z);
+		if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 16, 1, 0x28, z, HASBIT(_transparent_opt, TO_BRIDGES));
 	} else {
 		x += 12;
-		if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, pal, x, y, 1, 16, 0x28, z);
+		if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 1, 16, 0x28, z, HASBIT(_transparent_opt, TO_BRIDGES));
 	}
 
 	psid++;
 	if (ti->z + 5 == z) {
 		/* draw poles below for small bridges */
 		if (psid->sprite != 0) {
-			image = psid->sprite;
+			SpriteID image = psid->sprite;
+			SpriteID pal   = psid->pal;
 			if (HASBIT(_transparent_opt, TO_BRIDGES)) {
 				SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
 				pal = PALETTE_TO_TRANSPARENT;
-			} else {
-				pal = psid->pal;
 			}
 
 			DrawGroundSpriteAt(image, pal, x, y, z);
--- a/src/unmovable_cmd.cpp	Thu Jul 26 11:19:03 2007 +0000
+++ b/src/unmovable_cmd.cpp	Thu Jul 26 14:07:11 2007 +0000
@@ -112,8 +112,6 @@
 
 static void DrawTile_Unmovable(TileInfo *ti)
 {
-	SpriteID image;
-	SpriteID pal;
 
 	switch (GetUnmovableType(ti->tile)) {
 		case UNMOVABLE_TRANSMITTER:
@@ -125,17 +123,10 @@
 
 			dtus = &_draw_tile_unmovable_data[GetUnmovableType(ti->tile)];
 
-			image = dtus->image;
-			if (HASBIT(_transparent_opt, TO_STRUCTURES)) {
-				SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
-				pal = PALETTE_TO_TRANSPARENT;
-			} else {
-				pal = PAL_NONE;
-			}
-
 			AddSortableSpriteToDraw(
-				image, pal, ti->x | dtus->subcoord_x, ti->y | dtus->subcoord_y,
-				dtus->width, dtus->height, dtus->z_size, ti->z
+				dtus->image, PAL_NONE, ti->x | dtus->subcoord_x, ti->y | dtus->subcoord_y,
+				dtus->width, dtus->height, dtus->z_size, ti->z,
+				HASBIT(_transparent_opt, TO_STRUCTURES)
 			);
 			break;
 		}
@@ -143,23 +134,14 @@
 		case UNMOVABLE_STATUE:
 			DrawGroundSprite(SPR_CONCRETE_GROUND, PAL_NONE);
 
-			image = SPR_STATUE_COMPANY;
-			if (HASBIT(_transparent_opt, TO_STRUCTURES)) {
-				SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
-				pal = PALETTE_TO_TRANSPARENT;
-			} else {
-				pal = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
-			}
-			AddSortableSpriteToDraw(image, pal, ti->x, ti->y, 16, 16, 25, ti->z);
+			AddSortableSpriteToDraw(SPR_STATUE_COMPANY, PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)), ti->x, ti->y, 16, 16, 25, ti->z, HASBIT(_transparent_opt, TO_STRUCTURES));
 			break;
 
 		case UNMOVABLE_OWNED_LAND:
 			DrawClearLandTile(ti, 0);
 
-			image = SPR_BOUGHT_LAND;
-			pal = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
 			AddSortableSpriteToDraw(
-				image, pal,
+				SPR_BOUGHT_LAND, PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)),
 				ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 10, GetSlopeZ(ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2)
 			);
 			DrawBridgeMiddle(ti);
@@ -179,18 +161,12 @@
 			DrawGroundSprite(t->ground_sprite, palette);
 
 			foreach_draw_tile_seq(dtss, t->seq) {
-				image = dtss->image;
-				if (HASBIT(_transparent_opt, TO_STRUCTURES)) {
-					SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
-					pal = PALETTE_TO_TRANSPARENT;
-				} else {
-					pal = palette;
-				}
 				AddSortableSpriteToDraw(
-					image, pal,
+					dtss->image, palette,
 					ti->x + dtss->delta_x, ti->y + dtss->delta_y,
 					dtss->size_x, dtss->size_y,
-					dtss->size_z, ti->z + dtss->delta_z
+					dtss->size_z, ti->z + dtss->delta_z,
+					HASBIT(_transparent_opt, TO_STRUCTURES)
 				);
 			}
 			break;
--- a/src/vehicle.cpp	Thu Jul 26 11:19:03 2007 +0000
+++ b/src/vehicle.cpp	Thu Jul 26 14:07:11 2007 +0000
@@ -852,17 +852,14 @@
 	SpriteID image = v->cur_image;
 	SpriteID pal;
 
-	if (v->vehstatus & VS_SHADOW) {
-		SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
-		pal = PALETTE_TO_TRANSPARENT;
-	} else if (v->vehstatus & VS_DEFPAL) {
+	if (v->vehstatus & VS_DEFPAL) {
 		pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
 	} else {
 		pal = PAL_NONE;
 	}
 
 	AddSortableSpriteToDraw(image, pal, v->x_pos + v->x_offs, v->y_pos + v->y_offs,
-		v->sprite_width, v->sprite_height, v->z_height, v->z_pos);
+		v->sprite_width, v->sprite_height, v->z_height, v->z_pos, v->vehstatus & VS_SHADOW);
 }
 
 void ViewportAddVehicles(DrawPixelInfo *dpi)
--- a/src/viewport.cpp	Thu Jul 26 11:19:03 2007 +0000
+++ b/src/viewport.cpp	Thu Jul 26 14:07:11 2007 +0000
@@ -478,8 +478,18 @@
 	AddChildSpriteScreen(image, pal, pt.x - vd->parent_list[-1]->left, pt.y - vd->parent_list[-1]->top);
 }
 
-
-void AddSortableSpriteToDraw(SpriteID image, SpriteID pal, int x, int y, int w, int h, byte dz, byte z)
+/** Draw a (transparent) sprite at given coordinates
+ * @param image the image to combine and draw,
+ * @param pal the provided palette,
+ * @param x position x of the sprite,
+ * @param y position y of the sprite,
+ * @param w width of the sprite,
+ * @param h height of the sprite,
+ * @param dz delta z, difference of elevation between sprite and parent sprite,
+ * @param z elevation of the sprite,
+ * @param transparent if true, switch the palette between the provided palette and the transparent palette
+ */
+void AddSortableSpriteToDraw(SpriteID image, SpriteID pal, int x, int y, int w, int h, byte dz, byte z, bool transparent)
 {
 	ViewportDrawer *vd = _cur_vd;
 	ParentSpriteToDraw *ps;
@@ -488,6 +498,12 @@
 
 	assert((image & SPRITE_MASK) < MAX_SPRITES);
 
+	/* make the sprites transparent with the right palette */
+	if (transparent) {
+		SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
+		pal = PALETTE_TO_TRANSPARENT;
+	}
+
 	if (vd->combine_sprites == 2) {
 		AddCombinedSprite(image, pal, x, y, z);
 		return;
--- a/src/viewport.h	Thu Jul 26 11:19:03 2007 +0000
+++ b/src/viewport.h	Thu Jul 26 14:07:11 2007 +0000
@@ -48,7 +48,7 @@
 
 void DrawGroundSprite(SpriteID image, SpriteID pal);
 void DrawGroundSpriteAt(SpriteID image, SpriteID pal, int32 x, int32 y, byte z);
-void AddSortableSpriteToDraw(SpriteID image, SpriteID pal, int x, int y, int w, int h, byte dz, byte z);
+void AddSortableSpriteToDraw(SpriteID image, SpriteID pal, int x, int y, int w, int h, byte dz, byte z, bool transparent = false);
 void *AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint64 params_2);
 void AddChildSpriteScreen(SpriteID image, SpriteID pal, int x, int y);
 
--- a/src/water_cmd.cpp	Thu Jul 26 11:19:03 2007 +0000
+++ b/src/water_cmd.cpp	Thu Jul 26 14:07:11 2007 +0000
@@ -441,23 +441,11 @@
 	DrawGroundSprite(image, PAL_NONE);
 
 	for (; wdts->delta_x != 0x80; wdts++) {
-		SpriteID image = wdts->image;
-		SpriteID pal;
-
-		if (image < 24) image += locks_base;
-		image += base;
-
-		if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
-			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
-			pal = PALETTE_TO_TRANSPARENT;
-		} else {
-			pal = palette;
-		}
-
-		AddSortableSpriteToDraw(image, pal,
+		AddSortableSpriteToDraw(wdts->image + base + ((wdts->image < 24) ? locks_base : 0), palette,
 			ti->x + wdts->delta_x, ti->y + wdts->delta_y,
 			wdts->width, wdts->height,
-			wdts->unk, ti->z + wdts->delta_z);
+			wdts->unk, ti->z + wdts->delta_z,
+			HASBIT(_transparent_opt, TO_BUILDINGS));
 	}
 }