summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-07-26 14:07:11 +0000
committerrubidium <rubidium@openttd.org>2007-07-26 14:07:11 +0000
commit02ab86631e59bc247b9f01c21b69e6f6b99a0d3f (patch)
treef9ea4c50fe8ce5b57839ce0b5407aac9a6f2b452 /src
parentd031da78d8271b8d57a0e2cd33b6c7d6e4231421 (diff)
downloadopenttd-02ab86631e59bc247b9f01c21b69e6f6b99a0d3f.tar.xz
(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
Diffstat (limited to 'src')
-rw-r--r--src/elrail.cpp64
-rw-r--r--src/industry_cmd.cpp15
-rw-r--r--src/newgrf_house.cpp8
-rw-r--r--src/newgrf_industrytiles.cpp8
-rw-r--r--src/rail_cmd.cpp8
-rw-r--r--src/road_cmd.cpp19
-rw-r--r--src/station_cmd.cpp8
-rw-r--r--src/town_cmd.cpp12
-rw-r--r--src/tree_cmd.cpp11
-rw-r--r--src/tunnelbridge_cmd.cpp66
-rw-r--r--src/unmovable_cmd.cpp40
-rw-r--r--src/vehicle.cpp7
-rw-r--r--src/viewport.cpp20
-rw-r--r--src/viewport.h2
-rw-r--r--src/water_cmd.cpp18
15 files changed, 86 insertions, 220 deletions
diff --git a/src/elrail.cpp b/src/elrail.cpp
index 6faf76615..a0a0bbdf9 100644
--- a/src/elrail.cpp
+++ b/src/elrail.cpp
@@ -270,15 +270,9 @@ static void DrawCatenaryRailway(const TileInfo *ti)
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 @@ static void DrawCatenaryRailway(const TileInfo *ti)
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 @@ static void DrawCatenaryOnBridge(const TileInfo *ti)
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 @@ void DrawCatenary(const TileInfo *ti)
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;
}
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 958f1a013..fc307beed 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -299,22 +299,15 @@ static void DrawTile_Industry(TileInfo *ti)
/* 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;
}
diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp
index 5656470f3..533bf561f 100644
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -314,10 +314,7 @@ void DrawTileLayout(const TileInfo *ti, const SpriteGroup *group, byte stage, Ho
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 @@ void DrawTileLayout(const TileInfo *ti, const SpriteGroup *group, byte stage, Ho
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);
diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp
index ec7b269c5..ede452290 100644
--- a/src/newgrf_industrytiles.cpp
+++ b/src/newgrf_industrytiles.cpp
@@ -166,10 +166,7 @@ void IndustryDrawTileLayout(const TileInfo *ti, const SpriteGroup *group, byte r
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 @@ void IndustryDrawTileLayout(const TileInfo *ti, const SpriteGroup *group, byte r
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);
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index e2f3eb6d1..c3aebcaa6 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -1526,10 +1526,7 @@ default_waypoint:
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 @@ default_waypoint:
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);
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index 423086645..480dd5419 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -918,15 +918,8 @@ void DrawTramCatenary(TileInfo *ti, RoadBits tram)
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 @@ static void DrawTile_Road(TileInfo *ti)
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 @@ static void DrawTile_Road(TileInfo *ti)
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;
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 1c858c91a..0e07583b1 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -2131,10 +2131,7 @@ static void DrawTile_Station(TileInfo *ti)
}
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 @@ static void DrawTile_Station(TileInfo *ti)
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);
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index cb090c682..79e1fb347 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -163,20 +163,14 @@ static void DrawTile_Town(TileInfo *ti)
/* 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;
diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp
index a19ff0ce7..a28bbbbb9 100644
--- a/src/tree_cmd.cpp
+++ b/src/tree_cmd.cpp
@@ -374,13 +374,8 @@ static void DrawTile_Trees(TileInfo *ti)
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 @@ static void DrawTile_Trees(TileInfo *ti)
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;
}
}
diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp
index 1f80a3c4d..cdba7bbd7 100644
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -831,7 +831,6 @@ static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo* ti, Axis
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 @@ static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo* ti, Axis
{ 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 @@ static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo* ti, Axis
* 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 @@ static void DrawBridgeTramBits(int x, int y, byte z, int offset, bool overlay)
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 DrawBridgeTramBits(int x, int y, byte z, int offset, bool overlay)
static void DrawTile_TunnelBridge(TileInfo *ti)
{
SpriteID image;
- SpriteID pal;
if (IsTunnel(ti->tile)) {
if (GetTunnelTransportType(ti->tile) == TRANSPORT_RAIL) {
@@ -1005,21 +987,13 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
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 @@ static uint CalcBridgePiece(uint north, uint south)
void DrawBridgeMiddle(const TileInfo* ti)
{
const PalSpriteID* psid;
- SpriteID image;
- SpriteID pal;
uint base_offset;
TileIndex rampnorth;
TileIndex rampsouth;
@@ -1120,28 +1092,13 @@ void DrawBridgeMiddle(const TileInfo* ti)
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;
- } else {
- pal = psid->pal;
- }
-
if (axis == AXIS_X) {
- AddSortableSpriteToDraw(image, pal, x, y, 16, 11, 1, z);
+ AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 16, 11, 1, z, HASBIT(_transparent_opt, TO_BRIDGES));
} 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 @@ void DrawBridgeMiddle(const TileInfo* ti)
/* 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);
diff --git a/src/unmovable_cmd.cpp b/src/unmovable_cmd.cpp
index fcf00805b..877e89b19 100644
--- a/src/unmovable_cmd.cpp
+++ b/src/unmovable_cmd.cpp
@@ -112,8 +112,6 @@ CommandCost CmdBuildCompanyHQ(TileIndex tile, uint32 flags, uint32 p1, uint32 p2
static void DrawTile_Unmovable(TileInfo *ti)
{
- SpriteID image;
- SpriteID pal;
switch (GetUnmovableType(ti->tile)) {
case UNMOVABLE_TRANSMITTER:
@@ -125,17 +123,10 @@ static void DrawTile_Unmovable(TileInfo *ti)
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 @@ static void DrawTile_Unmovable(TileInfo *ti)
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 @@ static void DrawTile_Unmovable(TileInfo *ti)
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;
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index ee210f3ac..2e3e6e3fb 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -852,17 +852,14 @@ static void DoDrawVehicle(const Vehicle *v)
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)
diff --git a/src/viewport.cpp b/src/viewport.cpp
index 289e12900..528d51abc 100644
--- a/src/viewport.cpp
+++ b/src/viewport.cpp
@@ -478,8 +478,18 @@ static void AddCombinedSprite(SpriteID image, SpriteID pal, int x, int y, byte z
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 @@ void AddSortableSpriteToDraw(SpriteID image, SpriteID pal, int x, int y, int w,
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;
diff --git a/src/viewport.h b/src/viewport.h
index 6a4b4b0bc..c811b55dd 100644
--- a/src/viewport.h
+++ b/src/viewport.h
@@ -48,7 +48,7 @@ void OffsetGroundSprite(int x, int y);
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);
diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp
index a15c3b96f..0b8ce0550 100644
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -441,23 +441,11 @@ static void DrawWaterStuff(const TileInfo *ti, const WaterDrawTileStruct *wdts,
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));
}
}