From 9e461b2e34d30dff71fe5134a8457d2f6835a1e2 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 9 Feb 2019 11:25:21 +0000 Subject: [PATCH] Pass Ride* instead of ride_id_t --- .../windows/DemolishRidePrompt.cpp | 4 +- src/openrct2-ui/windows/Ride.cpp | 6 +- src/openrct2-ui/windows/RideConstruction.cpp | 14 ++-- src/openrct2-ui/windows/TrackDesignPlace.cpp | 2 +- src/openrct2/actions/RideDemolishAction.hpp | 12 +-- src/openrct2/peep/Guest.cpp | 20 ++--- src/openrct2/peep/GuestPathfinding.cpp | 6 +- src/openrct2/peep/Staff.cpp | 15 ++-- src/openrct2/ride/Ride.cpp | 76 +++++++++---------- src/openrct2/ride/Ride.h | 8 +- src/openrct2/ride/RideRatings.cpp | 4 +- src/openrct2/ride/Station.cpp | 6 +- src/openrct2/ride/Station.h | 4 +- src/openrct2/ride/TrackDesignSave.cpp | 33 ++++---- src/openrct2/windows/_legacy.cpp | 5 +- src/openrct2/world/Entrance.cpp | 4 +- src/openrct2/world/Footpath.cpp | 2 +- 17 files changed, 108 insertions(+), 113 deletions(-) diff --git a/src/openrct2-ui/windows/DemolishRidePrompt.cpp b/src/openrct2-ui/windows/DemolishRidePrompt.cpp index d38d9e01f9..e0e48fc76d 100644 --- a/src/openrct2-ui/windows/DemolishRidePrompt.cpp +++ b/src/openrct2-ui/windows/DemolishRidePrompt.cpp @@ -141,7 +141,7 @@ rct_window* window_ride_demolish_prompt_open(Ride* ride) w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_CANCEL) | (1 << WIDX_DEMOLISH); window_init_scroll_widgets(w); w->number = ride->id; - _demolishRideCost = -ride_get_refund_price(ride->id); + _demolishRideCost = -ride_get_refund_price(ride); return w; } @@ -167,7 +167,7 @@ rct_window* window_ride_refurbish_prompt_open(Ride* ride) w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_CANCEL) | (1 << WIDX_REFURBISH); window_init_scroll_widgets(w); w->number = ride->id; - _demolishRideCost = -ride_get_refund_price(ride->id); + _demolishRideCost = -ride_get_refund_price(ride); return w; } diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 6df89a4bbb..9ee46bfc3d 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -2708,14 +2708,14 @@ static rct_string_id window_ride_get_status_station(rct_window* w, void* argumen // Entrance / exit if (ride->status == RIDE_STATUS_CLOSED) { - if (ride_get_entrance_location((uint8_t)w->number, (uint8_t)stationIndex).isNull()) + if (ride_get_entrance_location(ride, (uint8_t)stationIndex).isNull()) stringId = STR_NO_ENTRANCE; - else if (ride_get_exit_location((uint8_t)w->number, (uint8_t)stationIndex).isNull()) + else if (ride_get_exit_location(ride, (uint8_t)stationIndex).isNull()) stringId = STR_NO_EXIT; } else { - if (ride_get_entrance_location((uint8_t)w->number, (uint8_t)stationIndex).isNull()) + if (ride_get_entrance_location(ride, (uint8_t)stationIndex).isNull()) stringId = STR_EXIT_ONLY; } diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index f5656ffd9c..f682305e05 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -605,7 +605,7 @@ static void window_ride_construction_close(rct_window* w) return; } - if (ride_try_get_origin_element(ride->id, nullptr)) + if (ride_try_get_origin_element(ride, nullptr)) { // Auto open shops if required. if (ride->mode == RIDE_MODE_SHOP_STALL && gConfigGeneral.auto_open_shops) @@ -1914,9 +1914,10 @@ static void window_ride_construction_entrance_click(rct_window* w) { if (tool_set(w, WIDX_ENTRANCE, TOOL_CROSSHAIR)) { - if (!ride_try_get_origin_element(_currentRideIndex, nullptr)) + auto ride = get_ride(_currentRideIndex); + if (!ride_try_get_origin_element(ride, nullptr)) { - ride_initialise_construction_window(_currentRideIndex); + ride_initialise_construction_window(ride); } } else @@ -1943,9 +1944,10 @@ static void window_ride_construction_exit_click(rct_window* w) { if (tool_set(w, WIDX_EXIT, TOOL_CROSSHAIR)) { - if (!ride_try_get_origin_element(_currentRideIndex, nullptr)) + auto ride = get_ride(_currentRideIndex); + if (!ride_try_get_origin_element(ride, nullptr)) { - ride_initialise_construction_window(_currentRideIndex); + ride_initialise_construction_window(ride); } } else @@ -3864,7 +3866,7 @@ void ride_construction_tooldown_construct(int32_t screenX, int32_t screenY) int32_t saveCurrentTrackAlternative = _currentTrackAlternative; int32_t saveCurrentTrackLiftHill = _currentTrackLiftHill; - ride_initialise_construction_window(_currentRideIndex); + ride_initialise_construction_window(ride); _currentTrackPieceDirection = saveTrackDirection; _currentTrackCurve = saveCurrentTrackCurve; diff --git a/src/openrct2-ui/windows/TrackDesignPlace.cpp b/src/openrct2-ui/windows/TrackDesignPlace.cpp index dd53a5c3f1..0ed1d1817c 100644 --- a/src/openrct2-ui/windows/TrackDesignPlace.cpp +++ b/src/openrct2-ui/windows/TrackDesignPlace.cpp @@ -353,7 +353,7 @@ static void window_track_place_tooldown(rct_window* w, rct_widgetindex widgetInd } else { - ride_initialise_construction_window(rideIndex); + ride_initialise_construction_window(get_ride(rideIndex)); w = window_find_by_class(WC_RIDE_CONSTRUCTION); window_event_mouse_up_call(w, WC_RIDE_CONSTRUCTION__WIDX_ENTRANCE); } diff --git a/src/openrct2/actions/RideDemolishAction.hpp b/src/openrct2/actions/RideDemolishAction.hpp index aa39e64a74..30df16be76 100644 --- a/src/openrct2/actions/RideDemolishAction.hpp +++ b/src/openrct2/actions/RideDemolishAction.hpp @@ -90,7 +90,7 @@ public: } result->ErrorTitle = STR_CANT_REFURBISH_RIDE; - result->Cost = GetRefurbishPrice(); + result->Cost = GetRefurbishPrice(ride); } return result; @@ -344,7 +344,7 @@ private: { auto res = std::make_unique(); res->ExpenditureType = RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION; - res->Cost = GetRefurbishPrice(); + res->Cost = GetRefurbishPrice(ride); ride_renew(ride); @@ -367,13 +367,13 @@ private: return res; } - money32 GetRefurbishPrice() const + money32 GetRefurbishPrice(const Ride* ride) const { - return -GetRefundPrice() / 2; + return -GetRefundPrice(ride) / 2; } - money32 GetRefundPrice() const + money32 GetRefundPrice(const Ride* ride) const { - return ride_get_refund_price(_rideIndex); + return ride_get_refund_price(ride); } }; diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 9910b36e78..b51c9608c4 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -2263,7 +2263,7 @@ static void peep_choose_seat_from_car(rct_peep* peep, Ride* ride, rct_vehicle* v */ static void peep_go_to_ride_entrance(rct_peep* peep, Ride* ride) { - TileCoordsXYZD location = ride_get_entrance_location(peep->current_ride, peep->current_ride_station); + TileCoordsXYZD location = ride_get_entrance_location(ride, peep->current_ride_station); Guard::Assert(!location.isNull()); int32_t x = location.x; int32_t y = location.y; @@ -3502,7 +3502,7 @@ static uint8_t peep_get_waypointed_seat_location( static void peep_update_ride_leave_entrance_waypoints(rct_peep* peep, Ride* ride) { - TileCoordsXYZD entranceLocation = ride_get_entrance_location(peep->current_ride, peep->current_ride_station); + TileCoordsXYZD entranceLocation = ride_get_entrance_location(ride, peep->current_ride_station); Guard::Assert(!entranceLocation.isNull()); uint8_t direction_entrance = entranceLocation.direction; @@ -3582,7 +3582,7 @@ void rct_peep::UpdateRideAdvanceThroughEntrance() Guard::Assert(sub_state == PEEP_RIDE_LEAVE_ENTRANCE, "Peep substate should be LEAVE_ENTRANCE"); if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_NO_VEHICLES)) { - TileCoordsXYZD entranceLocation = ride_get_entrance_location(current_ride, current_ride_station); + TileCoordsXYZD entranceLocation = ride_get_entrance_location(ride, current_ride_station); Guard::Assert(!entranceLocation.isNull()); if (ride->type == RIDE_TYPE_MAZE) @@ -3797,7 +3797,7 @@ void rct_peep::UpdateRideFreeVehicleEnterRide(Ride* ride) */ static void peep_update_ride_no_free_vehicle_rejoin_queue(rct_peep* peep, Ride* ride) { - TileCoordsXYZD entranceLocation = ride_get_entrance_location(peep->current_ride, peep->current_ride_station); + TileCoordsXYZD entranceLocation = ride_get_entrance_location(ride, peep->current_ride_station); int32_t x = entranceLocation.x * 32; int32_t y = entranceLocation.y * 32; @@ -4036,7 +4036,7 @@ void rct_peep::UpdateRideLeaveVehicle() if (!(vehicle_entry->flags & VEHICLE_ENTRY_FLAG_LOADING_WAYPOINTS)) { assert(current_ride_station < MAX_STATIONS); - TileCoordsXYZD exitLocation = ride_get_exit_location(current_ride, current_ride_station); + TileCoordsXYZD exitLocation = ride_get_exit_location(ride, current_ride_station); CoordsXYZD platformLocation; platformLocation.z = ride->stations[current_ride_station].Height; @@ -4128,7 +4128,7 @@ void rct_peep::UpdateRideLeaveVehicle() return; } - TileCoordsXYZD exitLocation = ride_get_exit_location(current_ride, current_ride_station); + TileCoordsXYZD exitLocation = ride_get_exit_location(ride, current_ride_station); Guard::Assert(!exitLocation.isNull()); CoordsXYZ waypointLoc; @@ -4184,7 +4184,7 @@ static void peep_update_ride_prepare_for_exit(rct_peep* peep) Ride* ride = get_ride(peep->current_ride); Guard::Assert(peep->current_ride_station < std::size(ride->stations), GUARD_LINE); - auto exit = ride_get_exit_location(peep->current_ride, peep->current_ride_station); + auto exit = ride_get_exit_location(ride, peep->current_ride_station); int16_t x = exit.x; int16_t y = exit.y; uint8_t exit_direction = exit.direction; @@ -4422,7 +4422,7 @@ void rct_peep::UpdateRideApproachExitWaypoints() var_37 |= 3; - auto exit = ride_get_exit_location(current_ride, current_ride_station); + auto exit = ride_get_exit_location(ride, current_ride_station); actionX = exit.x; actionY = exit.y; uint8_t exit_direction = direction_reverse(exit.direction); @@ -4497,7 +4497,7 @@ void rct_peep::UpdateRideApproachSpiralSlide() if (lastRide) { - auto exit = ride_get_exit_location(current_ride, current_ride_station); + auto exit = ride_get_exit_location(ride, current_ride_station); waypoint = 1; var_37 = (exit.direction * 4) | (var_37 & 0x30) | waypoint; actionX = ride->stations[current_ride_station].Start.x * 32; @@ -4683,7 +4683,7 @@ void rct_peep::UpdateRideLeaveSpiralSlide() // Actually force the final waypoint var_37 |= 3; - auto exit = ride_get_exit_location(current_ride, current_ride_station); + auto exit = ride_get_exit_location(ride, current_ride_station); actionX = exit.x * 32 + 16; actionY = exit.y * 32 + 16; diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 3d294720ee..763c0f19ef 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -2063,13 +2063,13 @@ int32_t guest_path_finding(rct_peep* peep) for (uint8_t stationNum = 0; stationNum < MAX_STATIONS; ++stationNum) { // Skip if stationNum has no entrance (so presumably an exit only station) - if (ride_get_entrance_location(rideIndex, stationNum).isNull()) + if (ride_get_entrance_location(ride, stationNum).isNull()) continue; numEntranceStations++; entranceStations |= (1 << stationNum); - TileCoordsXYZD entranceLocation = ride_get_entrance_location(rideIndex, stationNum); + TileCoordsXYZD entranceLocation = ride_get_entrance_location(ride, stationNum); int16_t stationX = (int16_t)(entranceLocation.x * 32); int16_t stationY = (int16_t)(entranceLocation.y * 32); @@ -2119,7 +2119,7 @@ int32_t guest_path_finding(rct_peep* peep) } else { - TileCoordsXYZD entranceXYZD = ride_get_entrance_location(rideIndex, closestStationNum); + TileCoordsXYZD entranceXYZD = ride_get_entrance_location(ride, closestStationNum); loc.x = entranceXYZD.x; loc.y = entranceXYZD.y; loc.z = entranceXYZD.z; diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 344eed44c7..233246cb0f 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -1089,12 +1089,14 @@ static uint8_t staff_mechanic_direction_surface(rct_peep* peep) { uint8_t direction = scenario_rand() & 3; - if ((peep->state == PEEP_STATE_ANSWERING || peep->state == PEEP_STATE_HEADING_TO_INSPECTION) && scenario_rand() & 1) + auto ride = get_ride(peep->current_ride); + if (ride != nullptr && (peep->state == PEEP_STATE_ANSWERING || peep->state == PEEP_STATE_HEADING_TO_INSPECTION) + && (scenario_rand() & 1)) { - TileCoordsXYZD location = ride_get_exit_location(peep->current_ride, peep->current_ride_station); + auto location = ride_get_exit_location(ride, peep->current_ride_station); if (location.isNull()) { - location = ride_get_entrance_location(peep->current_ride, peep->current_ride_station); + location = ride_get_entrance_location(ride, peep->current_ride_station); } LocationXY16 chosenTile = { static_cast(location.x * 32), static_cast(location.y * 32) }; @@ -1180,14 +1182,15 @@ static uint8_t staff_mechanic_direction_path(rct_peep* peep, uint8_t validDirect pathDirections |= (1 << direction); // Mechanic is heading to ride (either broken down or for inspection). - if (peep->state == PEEP_STATE_ANSWERING || peep->state == PEEP_STATE_HEADING_TO_INSPECTION) + auto ride = get_ride(peep->current_ride); + if (ride != nullptr && (peep->state == PEEP_STATE_ANSWERING || peep->state == PEEP_STATE_HEADING_TO_INSPECTION)) { /* Find location of the exit for the target ride station * or if the ride has no exit, the entrance. */ - TileCoordsXYZD location = ride_get_exit_location(peep->current_ride, peep->current_ride_station); + TileCoordsXYZD location = ride_get_exit_location(ride, peep->current_ride_station); if (location.isNull()) { - location = ride_get_entrance_location(peep->current_ride, peep->current_ride_station); + location = ride_get_entrance_location(ride, peep->current_ride_station); // If no entrance is present either. This is an incorrect state. if (location.isNull()) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 9841e9cd62..28a4e06052 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -485,7 +485,7 @@ static money32 ride_calculate_income_per_hour(Ride* ride) * dl ride index * esi result map element */ -bool ride_try_get_origin_element(ride_id_t rideIndex, CoordsXYE* output) +bool ride_try_get_origin_element(const Ride* ride, CoordsXYE* output) { TileElement* resultTileElement = nullptr; @@ -495,7 +495,7 @@ bool ride_try_get_origin_element(ride_id_t rideIndex, CoordsXYE* output) { if (it.element->GetType() != TILE_ELEMENT_TYPE_TRACK) continue; - if (rideIndex != it.element->AsTrack()->GetRideIndex()) + if (it.element->AsTrack()->GetRideIndex() != ride->id) continue; // Found a track piece for target ride @@ -822,14 +822,12 @@ bool track_block_get_previous(int32_t x, int32_t y, TileElement* tileElement, tr * bx result y * esi input / output map element */ -int32_t ride_find_track_gap(ride_id_t rideIndex, CoordsXYE* input, CoordsXYE* output) +int32_t ride_find_track_gap(const Ride* ride, CoordsXYE* input, CoordsXYE* output) { assert(input->element->GetType() == TILE_ELEMENT_TYPE_TRACK); - - Ride* ride = get_ride(rideIndex); if (ride == nullptr) { - log_error("Trying to access invalid ride %d", rideIndex); + log_error("Trying to access invalid ride %d", ride->id); return 0; } @@ -839,7 +837,7 @@ int32_t ride_find_track_gap(ride_id_t rideIndex, CoordsXYE* input, CoordsXYE* ou } rct_window* w = window_find_by_class(WC_RIDE_CONSTRUCTION); - if (w != nullptr && _rideConstructionState != RIDE_CONSTRUCTION_STATE_0 && _currentRideIndex == rideIndex) + if (w != nullptr && _rideConstructionState != RIDE_CONSTRUCTION_STATE_0 && _currentRideIndex == ride->id) { ride_construction_invalidate_current_track(); } @@ -1068,10 +1066,9 @@ static rct_window* ride_create_or_find_construction_window(ride_id_t rideIndex) void ride_construct(Ride* ride) { CoordsXYE trackElement; - - if (ride_try_get_origin_element(ride->id, &trackElement)) + if (ride_try_get_origin_element(ride, &trackElement)) { - ride_find_track_gap(ride->id, &trackElement, &trackElement); + ride_find_track_gap(ride, &trackElement, &trackElement); rct_window* w = window_get_main(); if (w != nullptr && ride_modify(&trackElement)) @@ -1079,7 +1076,7 @@ void ride_construct(Ride* ride) } else { - ride_initialise_construction_window(ride->id); + ride_initialise_construction_window(ride); } } @@ -1887,6 +1884,7 @@ static int32_t ride_modify_entrance_or_exit(TileElement* tileElement, int32_t x, rct_window* constructionWindow; ride_id_t rideIndex = tileElement->AsEntrance()->GetRideIndex(); + auto ride = get_ride(rideIndex); entranceType = tileElement->AsEntrance()->GetEntranceType(); if (entranceType != ENTRANCE_TYPE_RIDE_ENTRANCE && entranceType != ENTRANCE_TYPE_RIDE_EXIT) @@ -1898,7 +1896,7 @@ static int32_t ride_modify_entrance_or_exit(TileElement* tileElement, int32_t x, constructionWindow = window_find_by_class(WC_RIDE_CONSTRUCTION); if (constructionWindow == nullptr) { - if (!ride_initialise_construction_window(rideIndex)) + if (!ride_initialise_construction_window(ride)) return 0; constructionWindow = window_find_by_class(WC_RIDE_CONSTRUCTION); @@ -2009,7 +2007,7 @@ int32_t ride_modify(CoordsXYE* input) if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_CANNOT_HAVE_GAPS)) { - if (ride_find_track_gap(rideIndex, &tileElement, &endOfTrackElement)) + if (ride_find_track_gap(ride, &tileElement, &endOfTrackElement)) tileElement = endOfTrackElement; } @@ -2076,13 +2074,11 @@ int32_t ride_modify(CoordsXYE* input) * * rct2: 0x006CC3FB */ -int32_t ride_initialise_construction_window(ride_id_t rideIndex) +int32_t ride_initialise_construction_window(Ride* ride) { - Ride* ride; rct_window* w; tool_cancel(); - ride = get_ride(rideIndex); if (!ride_check_if_construction_allowed(ride)) return 0; @@ -2090,7 +2086,7 @@ int32_t ride_initialise_construction_window(ride_id_t rideIndex) ride_clear_for_construction(ride); ride_remove_peeps(ride); - w = ride_create_or_find_construction_window(rideIndex); + w = ride_create_or_find_construction_window(ride->id); tool_set(w, WC_RIDE_CONSTRUCTION__WIDX_CONSTRUCT, TOOL_CROSSHAIR); input_set_flag(INPUT_FLAG_6, true); @@ -3450,8 +3446,8 @@ static void ride_entrance_exit_connected(Ride* ride) for (int32_t i = 0; i < MAX_STATIONS; ++i) { LocationXY8 station_start = ride->stations[i].Start; - TileCoordsXYZD entrance = ride_get_entrance_location(ride->id, i); - TileCoordsXYZD exit = ride_get_exit_location(ride->id, i); + auto entrance = ride_get_entrance_location(ride, i); + auto exit = ride_get_exit_location(ride, i); if (station_start.xy == RCT_XY8_UNDEFINED) continue; @@ -4396,11 +4392,11 @@ static int32_t ride_check_for_entrance_exit(ride_id_t rideIndex) * * rct2: 0x006B5952 */ -static void sub_6B5952(ride_id_t rideIndex) +static void sub_6B5952(Ride* ride) { for (int32_t i = 0; i < MAX_STATIONS; i++) { - TileCoordsXYZD location = ride_get_entrance_location(rideIndex, i); + auto location = ride_get_entrance_location(ride, i); if (location.isNull()) continue; @@ -4419,7 +4415,7 @@ static void sub_6B5952(ride_id_t rideIndex) continue; int32_t direction = tileElement->GetDirection(); - footpath_chain_ride_queue(rideIndex, i, x, y, tileElement, direction_reverse(direction)); + footpath_chain_ride_queue(ride->id, i, x, y, tileElement, direction_reverse(direction)); } while (!(tileElement++)->IsLastForTile()); } } @@ -5559,10 +5555,8 @@ static bool ride_create_cable_lift(ride_id_t rideIndex, bool isApplying) * * rct2: 0x006B51C0 */ -static void loc_6B51C0(ride_id_t rideIndex) +static void loc_6B51C0(const Ride* ride) { - Ride* ride = get_ride(rideIndex); - if (gUnk141F568 != gUnk13CA740) return; @@ -5577,13 +5571,13 @@ static void loc_6B51C0(ride_id_t rideIndex) if (ride->stations[i].Start.xy == RCT_XY8_UNDEFINED) continue; - if (ride_get_entrance_location(rideIndex, i).isNull()) + if (ride_get_entrance_location(ride, i).isNull()) { entranceOrExit = 0; break; } - if (ride_get_exit_location(rideIndex, i).isNull()) + if (ride_get_exit_location(ride, i).isNull()) { entranceOrExit = 1; break; @@ -5601,8 +5595,8 @@ static void loc_6B51C0(ride_id_t rideIndex) window_scroll_to_location(w, x, y, z); CoordsXYE trackElement; - ride_try_get_origin_element(rideIndex, &trackElement); - ride_find_track_gap(rideIndex, &trackElement, &trackElement); + ride_try_get_origin_element(ride, &trackElement); + ride_find_track_gap(ride, &trackElement, &trackElement); int32_t ok = ride_modify(&trackElement); if (ok == 0) { @@ -5687,13 +5681,13 @@ int32_t ride_is_valid_for_test(ride_id_t rideIndex, int32_t goingToBeOpen, int32 if (!ride_check_for_entrance_exit(rideIndex)) { - loc_6B51C0(rideIndex); + loc_6B51C0(ride); return 0; } if (goingToBeOpen && isApplying) { - sub_6B5952(rideIndex); + sub_6B5952(ride); ride->lifecycle_flags |= RIDE_LIFECYCLE_EVER_BEEN_OPENED; } @@ -5711,7 +5705,7 @@ int32_t ride_is_valid_for_test(ride_id_t rideIndex, int32_t goingToBeOpen, int32 if (ride->type == RIDE_TYPE_AIR_POWERED_VERTICAL_COASTER || ride->mode == RIDE_MODE_CONTINUOUS_CIRCUIT || ride->mode == RIDE_MODE_CONTINUOUS_CIRCUIT_BLOCK_SECTIONED || ride->mode == RIDE_MODE_POWERED_LAUNCH_BLOCK_SECTIONED) { - if (ride_find_track_gap(rideIndex, &trackElement, &problematicTrackElement) + if (ride_find_track_gap(ride, &trackElement, &problematicTrackElement) && (!gConfigGeneral.test_unfinished_tracks || ride->mode == RIDE_MODE_CONTINUOUS_CIRCUIT_BLOCK_SECTIONED || ride->mode == RIDE_MODE_POWERED_LAUNCH_BLOCK_SECTIONED)) { @@ -5755,7 +5749,7 @@ int32_t ride_is_valid_for_test(ride_id_t rideIndex, int32_t goingToBeOpen, int32 if (ride->mode == RIDE_MODE_STATION_TO_STATION) { - if (!ride_find_track_gap(rideIndex, &trackElement, &problematicTrackElement)) + if (!ride_find_track_gap(ride, &trackElement, &problematicTrackElement)) { gGameCommandErrorText = STR_RIDE_MUST_START_AND_END_WITH_STATIONS; return 0; @@ -5826,13 +5820,13 @@ int32_t ride_is_valid_for_open(ride_id_t rideIndex, int32_t goingToBeOpen, int32 if (!ride_check_for_entrance_exit(rideIndex)) { - loc_6B51C0(rideIndex); + loc_6B51C0(ride); return 0; } if (goingToBeOpen && isApplying) { - sub_6B5952(rideIndex); + sub_6B5952(ride); ride->lifecycle_flags |= RIDE_LIFECYCLE_EVER_BEEN_OPENED; } @@ -5851,7 +5845,7 @@ int32_t ride_is_valid_for_open(ride_id_t rideIndex, int32_t goingToBeOpen, int32 || ride->mode == RIDE_MODE_CONTINUOUS_CIRCUIT || ride->mode == RIDE_MODE_CONTINUOUS_CIRCUIT_BLOCK_SECTIONED || ride->mode == RIDE_MODE_POWERED_LAUNCH_BLOCK_SECTIONED) { - if (ride_find_track_gap(rideIndex, &trackElement, &problematicTrackElement)) + if (ride_find_track_gap(ride, &trackElement, &problematicTrackElement)) { gGameCommandErrorText = STR_TRACK_IS_NOT_A_COMPLETE_CIRCUIT; ride_scroll_to_track_error(&problematicTrackElement); @@ -5893,7 +5887,7 @@ int32_t ride_is_valid_for_open(ride_id_t rideIndex, int32_t goingToBeOpen, int32 if (ride->mode == RIDE_MODE_STATION_TO_STATION) { - if (!ride_find_track_gap(rideIndex, &trackElement, &problematicTrackElement)) + if (!ride_find_track_gap(ride, &trackElement, &problematicTrackElement)) { gGameCommandErrorText = STR_RIDE_MUST_START_AND_END_WITH_STATIONS; return 0; @@ -5982,12 +5976,12 @@ void ride_get_start_of_track(CoordsXYE* output) * * rct2: 0x006CB7FB */ -int32_t ride_get_refund_price(int32_t ride_id) +int32_t ride_get_refund_price(const Ride* ride) { CoordsXYE trackElement; money32 addedcost, cost = 0; - if (!ride_try_get_origin_element(ride_id, &trackElement)) + if (!ride_try_get_origin_element(ride, &trackElement)) { return 0; // Ride has no track to refund } @@ -7825,14 +7819,14 @@ void sub_6CB945(ride_id_t rideIndex) TileCoordsXYZD* locationList = locations; for (uint8_t stationId = 0; stationId < MAX_STATIONS; ++stationId) { - TileCoordsXYZD entrance = ride_get_entrance_location(rideIndex, stationId); + auto entrance = ride_get_entrance_location(ride, stationId); if (!entrance.isNull()) { *locationList++ = entrance; ride_clear_entrance_location(ride, stationId); } - TileCoordsXYZD exit = ride_get_exit_location(rideIndex, stationId); + auto exit = ride_get_exit_location(ride, stationId); if (!exit.isNull()) { *locationList++ = exit; diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index e2ceb563e1..082872dc87 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -1015,8 +1015,8 @@ void ride_update_all(); void ride_check_all_reachable(); void ride_update_satisfaction(Ride* ride, uint8_t happiness); void ride_update_popularity(Ride* ride, uint8_t pop_amount); -bool ride_try_get_origin_element(ride_id_t rideIndex, CoordsXYE* output); -int32_t ride_find_track_gap(ride_id_t rideIndex, CoordsXYE* input, CoordsXYE* output); +bool ride_try_get_origin_element(const Ride* ride, CoordsXYE* output); +int32_t ride_find_track_gap(const Ride* ride, CoordsXYE* input, CoordsXYE* output); void ride_construct_new(ride_list_item listItem); void ride_construct(Ride* ride); int32_t ride_modify(CoordsXYE* input); @@ -1041,7 +1041,7 @@ void ride_breakdown_add_news_item(ride_id_t rideIndex); rct_peep* ride_find_closest_mechanic(Ride* ride, int32_t forInspection); int32_t ride_is_valid_for_open(ride_id_t rideIndex, int32_t goingToBeOpen, int32_t isApplying); int32_t ride_is_valid_for_test(ride_id_t rideIndex, int32_t goingToBeOpen, int32_t isApplying); -int32_t ride_initialise_construction_window(ride_id_t rideIndex); +int32_t ride_initialise_construction_window(Ride* ride); void ride_construction_invalidate_current_track(); int32_t sub_6C683D( int32_t* x, int32_t* y, int32_t* z, int32_t direction, int32_t type, uint16_t extra_params, TileElement** output_element, @@ -1061,7 +1061,7 @@ void game_command_set_ride_name( int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp); void game_command_set_ride_setting( int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp); -int32_t ride_get_refund_price(int32_t ride_id); +int32_t ride_get_refund_price(const Ride* ride); int32_t ride_get_random_colour_preset_index(uint8_t ride_type); void ride_set_colour_preset(Ride* ride, uint8_t index); money32 ride_get_common_price(Ride* forRide); diff --git a/src/openrct2/ride/RideRatings.cpp b/src/openrct2/ride/RideRatings.cpp index 347c08d954..37b8be4efd 100644 --- a/src/openrct2/ride/RideRatings.cpp +++ b/src/openrct2/ride/RideRatings.cpp @@ -216,7 +216,7 @@ static void ride_ratings_update_state_2() { int32_t entranceIndex = tileElement->AsTrack()->GetStationIndex(); gRideRatingsCalcData.station_flags &= ~RIDE_RATING_STATION_FLAG_NO_ENTRANCE; - if (ride_get_entrance_location(rideIndex, entranceIndex).isNull()) + if (ride_get_entrance_location(ride, entranceIndex).isNull()) { gRideRatingsCalcData.station_flags |= RIDE_RATING_STATION_FLAG_NO_ENTRANCE; } @@ -371,7 +371,7 @@ static void ride_ratings_begin_proximity_loop() if (ride->stations[i].Start.xy != RCT_XY8_UNDEFINED) { gRideRatingsCalcData.station_flags &= ~RIDE_RATING_STATION_FLAG_NO_ENTRANCE; - if (ride_get_entrance_location(rideIndex, i).isNull()) + if (ride_get_entrance_location(ride, i).isNull()) { gRideRatingsCalcData.station_flags |= RIDE_RATING_STATION_FLAG_NO_ENTRANCE; } diff --git a/src/openrct2/ride/Station.cpp b/src/openrct2/ride/Station.cpp index ac77cb351a..2bcd002b89 100644 --- a/src/openrct2/ride/Station.cpp +++ b/src/openrct2/ride/Station.cpp @@ -392,15 +392,13 @@ int8_t ride_get_first_empty_station_start(const Ride* ride) return -1; } -TileCoordsXYZD ride_get_entrance_location(const ride_id_t rideIndex, const int32_t stationIndex) +TileCoordsXYZD ride_get_entrance_location(Ride* ride, const int32_t stationIndex) { - const Ride* ride = get_ride(rideIndex); return ride->stations[stationIndex].Entrance; } -TileCoordsXYZD ride_get_exit_location(const ride_id_t rideIndex, const int32_t stationIndex) +TileCoordsXYZD ride_get_exit_location(Ride* ride, const int32_t stationIndex) { - const Ride* ride = get_ride(rideIndex); return ride->stations[stationIndex].Exit; } diff --git a/src/openrct2/ride/Station.h b/src/openrct2/ride/Station.h index 938a8ed322..6b7e8b222c 100644 --- a/src/openrct2/ride/Station.h +++ b/src/openrct2/ride/Station.h @@ -17,8 +17,8 @@ int8_t ride_get_first_valid_station_exit(Ride* ride); int8_t ride_get_first_valid_station_start(const Ride* ride); int8_t ride_get_first_empty_station_start(const Ride* ride); -TileCoordsXYZD ride_get_entrance_location(const ride_id_t rideIndex, const int32_t stationIndex); -TileCoordsXYZD ride_get_exit_location(const ride_id_t rideIndex, const int32_t stationIndex); +TileCoordsXYZD ride_get_entrance_location(const Ride* ride, const int32_t stationIndex); +TileCoordsXYZD ride_get_exit_location(const Ride* ride, const int32_t stationIndex); TileCoordsXYZD ride_get_entrance_location(const Ride* ride, const int32_t stationIndex); TileCoordsXYZD ride_get_exit_location(const Ride* ride, const int32_t stationIndex); diff --git a/src/openrct2/ride/TrackDesignSave.cpp b/src/openrct2/ride/TrackDesignSave.cpp index 2638313ee0..a6e690d7a2 100644 --- a/src/openrct2/ride/TrackDesignSave.cpp +++ b/src/openrct2/ride/TrackDesignSave.cpp @@ -54,8 +54,8 @@ static bool track_design_save_add_tile_element(int32_t interactionType, int32_t static void track_design_save_remove_tile_element(int32_t interactionType, int32_t x, int32_t y, TileElement* tileElement); static bool track_design_save_copy_scenery_to_td6(rct_track_td6* td6); static rct_track_td6* track_design_save_to_td6(ride_id_t rideIndex); -static bool track_design_save_to_td6_for_maze(ride_id_t rideIndex, rct_track_td6* td6); -static bool track_design_save_to_td6_for_tracked_ride(ride_id_t rideIndex, rct_track_td6* td6); +static bool track_design_save_to_td6_for_maze(const Ride* ride, rct_track_td6* td6); +static bool track_design_save_to_td6_for_tracked_ride(const Ride* ride, rct_track_td6* td6); void track_design_save_init() { @@ -819,11 +819,11 @@ static rct_track_td6* track_design_save_to_td6(ride_id_t rideIndex) bool result; if (td6->type == RIDE_TYPE_MAZE) { - result = track_design_save_to_td6_for_maze(rideIndex, td6); + result = track_design_save_to_td6_for_maze(ride, td6); } else { - result = track_design_save_to_td6_for_tracked_ride(rideIndex, td6); + result = track_design_save_to_td6_for_tracked_ride(ride, td6); } if (!result) @@ -838,7 +838,7 @@ static rct_track_td6* track_design_save_to_td6(ride_id_t rideIndex) * * rct2: 0x006CEAAE */ -static bool track_design_save_to_td6_for_maze(ride_id_t rideIndex, rct_track_td6* td6) +static bool track_design_save_to_td6_for_maze(const Ride* ride, rct_track_td6* td6) { TileElement* tileElement = nullptr; bool mapFound = false; @@ -853,7 +853,7 @@ static bool track_design_save_to_td6_for_maze(ride_id_t rideIndex, rct_track_td6 { if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK) continue; - if (tileElement->AsTrack()->GetRideIndex() == rideIndex) + if (tileElement->AsTrack()->GetRideIndex() == ride->id) { mapFound = true; break; @@ -894,7 +894,7 @@ static bool track_design_save_to_td6_for_maze(ride_id_t rideIndex, rct_track_td6 { if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK) continue; - if (tileElement->AsTrack()->GetRideIndex() != rideIndex) + if (tileElement->AsTrack()->GetRideIndex() != ride->id) continue; maze->maze_entry = tileElement->AsTrack()->GetMazeEntry(); @@ -914,8 +914,7 @@ static bool track_design_save_to_td6_for_maze(ride_id_t rideIndex, rct_track_td6 x = 0; } - TileCoordsXYZD location = ride_get_entrance_location(rideIndex, 0); - + auto location = ride_get_entrance_location(ride, 0); if (location.isNull()) { gGameCommandErrorText = STR_TRACK_TOO_LARGE_OR_TOO_MUCH_SCENERY; @@ -933,7 +932,7 @@ static bool track_design_save_to_td6_for_maze(ride_id_t rideIndex, rct_track_td6 continue; if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_ENTRANCE) continue; - if (tileElement->AsEntrance()->GetRideIndex() == rideIndex) + if (tileElement->AsEntrance()->GetRideIndex() == ride->id) break; } while (!(tileElement++)->IsLastForTile()); // Add something that stops this from walking off the end @@ -946,7 +945,7 @@ static bool track_design_save_to_td6_for_maze(ride_id_t rideIndex, rct_track_td6 maze++; numMazeElements++; - location = ride_get_exit_location(rideIndex, 0); + location = ride_get_exit_location(ride, 0); if (location.isNull()) { gGameCommandErrorText = STR_TRACK_TOO_LARGE_OR_TOO_MUCH_SCENERY; @@ -963,7 +962,7 @@ static bool track_design_save_to_td6_for_maze(ride_id_t rideIndex, rct_track_td6 continue; if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_EXIT) continue; - if (tileElement->AsEntrance()->GetRideIndex() == rideIndex) + if (tileElement->AsEntrance()->GetRideIndex() == ride->id) break; } while (!(tileElement++)->IsLastForTile()); // Add something that stops this from walking off the end @@ -1004,12 +1003,10 @@ static bool track_design_save_to_td6_for_maze(ride_id_t rideIndex, rct_track_td6 * * rct2: 0x006CE68D */ -static bool track_design_save_to_td6_for_tracked_ride(ride_id_t rideIndex, rct_track_td6* td6) +static bool track_design_save_to_td6_for_tracked_ride(const Ride* ride, rct_track_td6* td6) { - Ride* ride = get_ride(rideIndex); CoordsXYE trackElement; - - if (!ride_try_get_origin_element(rideIndex, &trackElement)) + if (!ride_try_get_origin_element(ride, &trackElement)) { gGameCommandErrorText = STR_TRACK_TOO_LARGE_OR_TOO_MUCH_SCENERY; return false; @@ -1113,11 +1110,11 @@ static bool track_design_save_to_td6_for_tracked_ride(ride_id_t rideIndex, rct_t TileCoordsXYZD location; if (i == 0) { - location = ride_get_entrance_location(rideIndex, station_index); + location = ride_get_entrance_location(ride, station_index); } else { - location = ride_get_exit_location(rideIndex, station_index); + location = ride_get_exit_location(ride, station_index); } if (location.isNull()) diff --git a/src/openrct2/windows/_legacy.cpp b/src/openrct2/windows/_legacy.cpp index 043ae35da1..9832032deb 100644 --- a/src/openrct2/windows/_legacy.cpp +++ b/src/openrct2/windows/_legacy.cpp @@ -562,9 +562,10 @@ void window_ride_construction_mouseup_demolish_next_piece(int32_t x, int32_t y, int32_t b4 = _currentTrackLiftHill; ride_construction_set_default_next_piece(); window_ride_construction_update_active_elements(); - if (!ride_try_get_origin_element(_currentRideIndex, nullptr)) + auto ride = get_ride(_currentRideIndex); + if (!ride_try_get_origin_element(ride, nullptr)) { - ride_initialise_construction_window(_currentRideIndex); + ride_initialise_construction_window(ride); _currentTrackPieceDirection = direction & 3; if (!(slope & 0x100)) { diff --git a/src/openrct2/world/Entrance.cpp b/src/openrct2/world/Entrance.cpp index 48d73d1cf4..7c730a1a5c 100644 --- a/src/openrct2/world/Entrance.cpp +++ b/src/openrct2/world/Entrance.cpp @@ -176,7 +176,7 @@ static money32 RideEntranceExitPlace( if (isExit) { - const auto exit = ride_get_exit_location(rideIndex, stationNum); + const auto exit = ride_get_exit_location(ride, stationNum); if (!exit.isNull()) { if (flags & GAME_COMMAND_FLAG_GHOST) @@ -192,7 +192,7 @@ static money32 RideEntranceExitPlace( } else { - const auto entrance = ride_get_entrance_location(rideIndex, stationNum); + const auto entrance = ride_get_entrance_location(ride, stationNum); if (!entrance.isNull()) { if (flags & GAME_COMMAND_FLAG_GHOST) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index ccd8d758a4..0892247387 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1774,7 +1774,7 @@ void footpath_update_queue_chains() for (int32_t i = 0; i < MAX_STATIONS; i++) { - TileCoordsXYZD location = ride_get_entrance_location(rideIndex, i); + TileCoordsXYZD location = ride_get_entrance_location(ride, i); if (location.isNull()) continue;