From 34cc30e7fb7060185a92d15f9d68136ba64a8efd Mon Sep 17 00:00:00 2001 From: rubidium Date: Mon, 13 Apr 2009 22:27:21 +0000 Subject: (svn r16057) -Fix [FS#2834] (r16037): division by zero when having an order with only one station that has either middle or near end stop location and where the platform is (significantly) longer than the train. --- src/station_cmd.cpp | 2 +- src/train_cmd.cpp | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 563c440a9..91a7c73f0 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -2681,7 +2681,7 @@ static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, i * begin of the platform to the stop location is longer than the length * of the platform. Station ahead 'includes' the current tile where the * vehicle is on, so we need to substract that. */ - if (station_length <= stop + station_ahead - TILE_SIZE) return VETSB_CONTINUE; + if (!IsInsideBS(stop + station_ahead, station_length, TILE_SIZE)) return VETSB_CONTINUE; DiagDirection dir = DirToDiagDir(v->direction); diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 484d0c5c1..87d716627 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -474,15 +474,18 @@ static int GetTrainAcceleration(Vehicle *v, bool mode) /* The distance to go is whatever is still ahead of the train minus the * distance from the train's stop location to the end of the platform */ int distance_to_go = station_ahead / TILE_SIZE - (station_length - stop_at) / TILE_SIZE; - int st_max_speed = 120; - int delta_v = v->cur_speed / (distance_to_go + 1); - if (v->max_speed > (v->cur_speed - delta_v)) { - st_max_speed = v->cur_speed - (delta_v / 10); - } + if (distance_to_go > 0) { + int st_max_speed = 120; + + int delta_v = v->cur_speed / (distance_to_go + 1); + if (v->max_speed > (v->cur_speed - delta_v)) { + st_max_speed = v->cur_speed - (delta_v / 10); + } - st_max_speed = max(st_max_speed, 25 * distance_to_go); - max_speed = min(max_speed, st_max_speed); + st_max_speed = max(st_max_speed, 25 * distance_to_go); + max_speed = min(max_speed, st_max_speed); + } } } -- cgit v1.2.3-70-g09d2