summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--disaster_cmd.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/disaster_cmd.c b/disaster_cmd.c
index 27ca9e29d..f34b1446f 100644
--- a/disaster_cmd.c
+++ b/disaster_cmd.c
@@ -116,7 +116,6 @@ static void DeleteDisasterVeh(Vehicle *v)
static void SetDisasterVehiclePos(Vehicle *v, int x, int y, byte z)
{
Vehicle *u;
- int yt;
BeginVehicleMove(v);
v->x_pos = x;
@@ -129,11 +128,14 @@ static void SetDisasterVehiclePos(Vehicle *v, int x, int y, byte z)
EndVehicleMove(v);
if ( (u=v->next) != NULL) {
+ int safe_x = clamp(x, 0, MapMaxX() * TILE_SIZE);
+ int safe_y = clamp(y - 1, 0, MapMaxY() * TILE_SIZE);
BeginVehicleMove(u);
u->x_pos = x;
- u->y_pos = yt = y - 1 - (max(z - GetSlopeZ(x, y-1), 0) >> 3);
- u->z_pos = GetSlopeZ(x,yt);
+ u->y_pos = y - 1 - (max(z - GetSlopeZ(safe_x, safe_y), 0) >> 3);
+ safe_y = clamp(u->y_pos, 0, MapMaxY() * TILE_SIZE);
+ u->z_pos = GetSlopeZ(safe_x, safe_y);
u->direction = v->direction;
DisasterVehicleUpdateImage(u);