From 35b9038807b7095c83cf8c7f4bbbfcb4ef8750fb Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Mon, 25 Sep 2017 17:46:26 +0200 Subject: [PATCH] Refactor adjacency distance constant + loop fix --- src/openrct2/ride/ride.c | 2 +- src/openrct2/ride/ride.h | 3 +-- src/openrct2/ride/vehicle.c | 15 +++++++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/openrct2/ride/ride.c b/src/openrct2/ride/ride.c index 9d07ef001b..59390e8ad6 100644 --- a/src/openrct2/ride/ride.c +++ b/src/openrct2/ride/ride.c @@ -8480,7 +8480,7 @@ static bool check_for_adjacent_station(sint32 x, sint32 y, sint32 z, uint8 direc bool found = false; sint32 adjX = x; sint32 adjY = y; - for (int i = 0; i < ride_adjacent_station_max_distance; i++) { + for (int i = 0; i <= RIDE_ADJACENCY_CHECK_DISTANCE; i++) { adjX += TileDirectionDelta[direction].x; adjY += TileDirectionDelta[direction].y; rct_map_element *stationElement = get_station_platform(adjX, adjY, z, 2); diff --git a/src/openrct2/ride/ride.h b/src/openrct2/ride/ride.h index 1fdb162ff0..470f940dd8 100644 --- a/src/openrct2/ride/ride.h +++ b/src/openrct2/ride/ride.h @@ -40,8 +40,7 @@ #define RIDE_MEASUREMENT_MAX_ITEMS 4800 #define MAX_RIDES 255 #define RIDE_ID_NULL 255 - -static const uint8 ride_adjacent_station_max_distance = 5; +#define RIDE_ADJACENCY_CHECK_DISTANCE 5 #pragma pack(push, 1) diff --git a/src/openrct2/ride/vehicle.c b/src/openrct2/ride/vehicle.c index c54a66552b..8c4a1e77e5 100644 --- a/src/openrct2/ride/vehicle.c +++ b/src/openrct2/ride/vehicle.c @@ -2424,18 +2424,21 @@ static bool vehicle_can_depart_synchronised(rct_vehicle *vehicle) // Reset the list of synchronised vehicles to empty. _lastSynchronisedVehicle = _synchronisedVehicles; - // Search for stations to sync in both directions from the current tile. + /* Search for stations to sync in both directions from the current tile. + * We allow for some space between stations, and every time a station + * is found we allow for space between that and the next. + */ - // First search direction. sint32 direction = (mapElement->type + 1) & 3; sint32 spaceBetween; + sint32 maxCheckDistance = RIDE_ADJACENCY_CHECK_DISTANCE; - spaceBetween = ride_adjacent_station_max_distance; + spaceBetween = maxCheckDistance; while (_lastSynchronisedVehicle < &_synchronisedVehicles[SYNCHRONISED_VEHICLE_COUNT - 1]) { x += TileDirectionDelta[direction].x; y += TileDirectionDelta[direction].y; if (try_add_synchronised_station(x, y, z)) { - spaceBetween = ride_adjacent_station_max_distance; + spaceBetween = maxCheckDistance; continue; } if (spaceBetween-- == 0) @@ -2448,12 +2451,12 @@ static bool vehicle_can_depart_synchronised(rct_vehicle *vehicle) // Other search direction. direction = (direction ^ 2) & 3; - spaceBetween = ride_adjacent_station_max_distance; + spaceBetween = maxCheckDistance; while (_lastSynchronisedVehicle < &_synchronisedVehicles[SYNCHRONISED_VEHICLE_COUNT - 1]) { x += TileDirectionDelta[direction].x; y += TileDirectionDelta[direction].y; if (try_add_synchronised_station(x, y, z)) { - spaceBetween = ride_adjacent_station_max_distance; + spaceBetween = maxCheckDistance; continue; } if (spaceBetween-- == 0)