1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-21 05:53:02 +01:00

Fix error value checked from ride_get_smallest_station_length (#8719)

ride_get_smallest_station_length returns the int32_t::max instead of -1
on error.
This commit is contained in:
Michał Janiszewski
2019-05-08 23:34:41 +02:00
committed by Ted John
parent da6794ad9e
commit 7b71fe8acd
2 changed files with 13 additions and 9 deletions

View File

@@ -31,7 +31,7 @@
// This string specifies which version of network stream current build uses.
// It is used for making sure only compatible builds get connected, even within
// single OpenRCT2 version.
#define NETWORK_STREAM_VERSION "23"
#define NETWORK_STREAM_VERSION "24"
#define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION
static Peep* _pickup_peep = nullptr;

View File

@@ -24,6 +24,7 @@
#include "../common.h"
#include "../config/Config.h"
#include "../core/Guard.hpp"
#include "../core/Optional.hpp"
#include "../interface/Window.h"
#include "../localisation/Date.h"
#include "../localisation/Localisation.h"
@@ -6881,14 +6882,17 @@ uint64_t ride_entry_get_supported_track_pieces(const rct_ride_entry* rideEntry)
return supportedPieces;
}
static int32_t ride_get_smallest_station_length(Ride* ride)
static opt::optional<int32_t> ride_get_smallest_station_length(Ride* ride)
{
auto result = std::numeric_limits<int32_t>::max();
for (int32_t i = 0; i < MAX_STATIONS; i++)
opt::optional<int32_t> result;
for (const auto& station : ride->stations)
{
if (ride->stations[i].Start.xy != RCT_XY8_UNDEFINED)
if (station.Start.xy != RCT_XY8_UNDEFINED)
{
result = std::min<int32_t>(result, ride->stations[i].Length);
if (!result.has_value() || station.Length < *result)
{
result = station.Length;
}
}
}
return result;
@@ -6996,11 +7000,11 @@ void Ride::UpdateMaxVehicles()
min_max_cars_per_train = rideEntry->max_cars_in_train | (rideEntry->min_cars_in_train << 4);
// Calculate maximum train length based on smallest station length
int32_t stationLength = ride_get_smallest_station_length(this);
if (stationLength == -1)
auto stationNumTiles = ride_get_smallest_station_length(this);
if (!stationNumTiles.has_value())
return;
stationLength = (stationLength * 0x44180) - 0x16B2A;
auto stationLength = (*stationNumTiles * 0x44180) - 0x16B2A;
int32_t maxMass = RideData5[type].max_mass << 8;
int32_t maxCarsPerTrain = 1;
for (int32_t numCars = rideEntry->max_cars_in_train; numCars > 0; numCars--)