Skip to content

Commit

Permalink
Fix OpenRCT2#8142: Reliability of unbreakable rides can go below 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
felixpelletier authored and Gymnasiast committed Nov 2, 2018
1 parent f8add7f commit 0cd7f1e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions distribution/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- Fix: [#8101] Title sequences window flashes after opening.
- Fix: [#8120] Crash trying to place peep spawn outside of map.
- Fix: [#8121] Crash Renaming park with server logging enabled.
- Fix: [#8142] Reliability of mazes and crooked houses can go below 100%.
- Fix: [#8187] Cannot set land ownership over ride entrances or exits in sandbox mode.
- Improved: [#2940] Allow mouse-dragging to set patrol area (Singleplayer only).
- Improved: [#7730] Draw extreme vertical and lateral Gs red in the ride window's graph tab.
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/network/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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 "6"
#define NETWORK_STREAM_VERSION "7"
#define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION

static rct_peep* _pickup_peep = nullptr;
Expand Down
28 changes: 24 additions & 4 deletions src/openrct2/ride/Ride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ rct_ride_measurement* get_ride_measurement(int32_t index)
return &gRideMeasurements[index];
}

rct_ride_entry* get_ride_entry_by_ride(Ride* ride)
rct_ride_entry* get_ride_entry_by_ride(const Ride* ride)
{
rct_ride_entry* type = get_ride_entry(ride->subtype);
if (type == nullptr)
Expand Down Expand Up @@ -2479,6 +2479,12 @@ static void ride_breakdown_update(int32_t rideIndex)
if (ride->status == RIDE_STATUS_CLOSED)
return;

if (!ride->CanBreakDown())
{
ride->reliability = RIDE_INITIAL_RELIABILITY;
return;
}

// Calculate breakdown probability?
int32_t unreliabilityAccumulator = ride->unreliability_factor + get_age_penalty(ride);
ride->reliability = (uint16_t)std::max(0, (ride->reliability - unreliabilityAccumulator));
Expand Down Expand Up @@ -2506,13 +2512,11 @@ static void ride_breakdown_update(int32_t rideIndex)
static int32_t ride_get_new_breakdown_problem(Ride* ride)
{
int32_t availableBreakdownProblems, monthsOld, totalProbability, randomProbability, problemBits, breakdownProblem;
rct_ride_entry* entry;

// Brake failure is more likely when it's raining
_breakdownProblemProbabilities[BREAKDOWN_BRAKES_FAILURE] = climate_is_raining() ? 20 : 3;

entry = get_ride_entry_by_ride(ride);
if (entry == nullptr || entry->flags & RIDE_ENTRY_FLAG_CANNOT_BREAK_DOWN)
if (!ride->CanBreakDown())
return -1;

availableBreakdownProblems = RideAvailableBreakdowns[ride->type];
Expand Down Expand Up @@ -2562,6 +2566,22 @@ static int32_t ride_get_new_breakdown_problem(Ride* ride)
return BREAKDOWN_BRAKES_FAILURE;
}

bool Ride::CanBreakDown() const
{
if (RideAvailableBreakdowns[this->type] == 0)
{
return false;
}

rct_ride_entry* entry = get_ride_entry_by_ride(this);
if (entry == nullptr || entry->flags & RIDE_ENTRY_FLAG_CANNOT_BREAK_DOWN)
{
return false;
}

return true;
}

static void choose_random_train_to_breakdown_safe(Ride* ride)
{
ride->broken_vehicle = scenario_rand() % ride->num_vehicles;
Expand Down
3 changes: 2 additions & 1 deletion src/openrct2/ride/Ride.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ struct Ride
uint8_t cable_lift_z;
uint16_t cable_lift;
uint16_t queue_length[MAX_STATIONS];
bool CanBreakDown() const;
};

#pragma pack(push, 1)
Expand Down Expand Up @@ -1032,7 +1033,7 @@ track_colour ride_get_track_colour(Ride* ride, int32_t colourScheme);
vehicle_colour ride_get_vehicle_colour(Ride* ride, int32_t vehicleIndex);
int32_t ride_get_unused_preset_vehicle_colour(uint8_t ride_sub_type);
void ride_set_vehicle_colours_to_random_preset(Ride* ride, uint8_t preset_index);
rct_ride_entry* get_ride_entry_by_ride(Ride* ride);
rct_ride_entry* get_ride_entry_by_ride(const Ride* ride);
uint8_t* get_ride_entry_indices_for_ride_type(uint8_t rideType);
void reset_type_to_ride_entry_index_map(IObjectManager& objectManager);
void ride_measurement_clear(Ride* ride);
Expand Down
2 changes: 1 addition & 1 deletion test/testpaint/Compat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ rct_ride_entry* get_ride_entry(int index)
return gRideEntries[index];
}

rct_ride_entry* get_ride_entry_by_ride(Ride* ride)
rct_ride_entry* get_ride_entry_by_ride(const Ride* ride)
{
rct_ride_entry* type = get_ride_entry(ride->subtype);
if (type == nullptr)
Expand Down

0 comments on commit 0cd7f1e

Please sign in to comment.