summaryrefslogtreecommitdiff
path: root/src/vehicle.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2016-10-16 14:59:44 +0000
committerfrosch <frosch@openttd.org>2016-10-16 14:59:44 +0000
commit117e73751c9aeea9f9663c15226c52541d2c8723 (patch)
tree694627f8d7396e81945fc84bce6b951f229add22 /src/vehicle.cpp
parentc175067ed9c17d43feaf356cd575dddddd699889 (diff)
downloadopenttd-117e73751c9aeea9f9663c15226c52541d2c8723.tar.xz
(svn r27668) -Feature: [NewGRF] Allow composing vehicles from multiple sprites.
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r--src/vehicle.cpp37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 54a2bfa28..b68646131 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -75,11 +75,23 @@ INSTANTIATE_POOL_METHODS(Vehicle)
*/
void VehicleSpriteSeq::GetBounds(Rect *bounds) const
{
- const Sprite *spr = GetSprite(this->sprite, ST_NORMAL);
- bounds->left = spr->x_offs;
- bounds->top = spr->y_offs;
- bounds->right = spr->width + spr->x_offs - 1;
- bounds->bottom = spr->height + spr->y_offs - 1;
+ bounds->left = bounds->top = bounds->right = bounds->bottom = 0;
+ for (uint i = 0; i < this->count; ++i) {
+ const Sprite *spr = GetSprite(this->seq[i].sprite, ST_NORMAL);
+ if (i == 0) {
+ bounds->left = spr->x_offs;
+ bounds->top = spr->y_offs;
+ bounds->right = spr->width + spr->x_offs - 1;
+ bounds->bottom = spr->height + spr->y_offs - 1;
+ } else {
+ if (spr->x_offs < bounds->left) bounds->left = spr->x_offs;
+ if (spr->y_offs < bounds->top) bounds->top = spr->y_offs;
+ int right = spr->width + spr->x_offs - 1;
+ int bottom = spr->height + spr->y_offs - 1;
+ if (right > bounds->right) bounds->right = right;
+ if (bottom > bounds->bottom) bounds->bottom = bottom;
+ }
+ }
}
/**
@@ -91,7 +103,10 @@ void VehicleSpriteSeq::GetBounds(Rect *bounds) const
*/
void VehicleSpriteSeq::Draw(int x, int y, PaletteID default_pal, bool force_pal) const
{
- DrawSprite(this->sprite, default_pal, x, y);
+ for (uint i = 0; i < this->count; ++i) {
+ PaletteID pal = force_pal || !this->seq[i].pal ? default_pal : this->seq[i].pal;
+ DrawSprite(this->seq[i].sprite, pal, x, y);
+ }
}
/**
@@ -1048,8 +1063,14 @@ static void DoDrawVehicle(const Vehicle *v)
if (to != TO_INVALID && (IsTransparencySet(to) || IsInvisibilitySet(to))) return;
}
- AddSortableSpriteToDraw(v->sprite_seq.sprite, pal, v->x_pos + v->x_offs, v->y_pos + v->y_offs,
- v->x_extent, v->y_extent, v->z_extent, v->z_pos, shadowed, v->x_bb_offs, v->y_bb_offs);
+ StartSpriteCombine();
+ for (uint i = 0; i < v->sprite_seq.count; ++i) {
+ PaletteID pal2 = v->sprite_seq.seq[i].pal;
+ if (!pal2 || (v->vehstatus & VS_CRASHED)) pal2 = pal;
+ AddSortableSpriteToDraw(v->sprite_seq.seq[i].sprite, pal2, v->x_pos + v->x_offs, v->y_pos + v->y_offs,
+ v->x_extent, v->y_extent, v->z_extent, v->z_pos, shadowed, v->x_bb_offs, v->y_bb_offs);
+ }
+ EndSpriteCombine();
}
/**