Move some ride functions to struct methods

This commit is contained in:
Michael Steenbeek authored and GitHub committed 2019-03-20 20:05:25 +01:00
1 parent e64aafa735
commit 1c570c8eec
14 files changed
+86 -88

No files matched your search

+5 -5
View File
@@ -2871,20 +2871,20 @@ static void window_ride_vehicle_mousedown(rct_window* w, rct_widgetindex widgetI
break;
case WIDX_VEHICLE_TRAINS_INCREASE:
if (ride->num_vehicles < 32)
ride_set_num_vehicles(ride, ride->num_vehicles + 1);
ride->SetNumVehicles(ride->num_vehicles + 1);
break;
case WIDX_VEHICLE_TRAINS_DECREASE:
if (ride->num_vehicles > 1)
ride_set_num_vehicles(ride, ride->num_vehicles - 1);
ride->SetNumVehicles(ride->num_vehicles - 1);
break;
case WIDX_VEHICLE_CARS_PER_TRAIN_INCREASE:
if (ride->num_cars_per_train < 255)
ride_set_num_cars_per_vehicle(ride, ride->num_cars_per_train + 1);
ride->SetNumCarsPerVehicle(ride->num_cars_per_train + 1);
break;
case WIDX_VEHICLE_CARS_PER_TRAIN_DECREASE:
rct_ride_entry* rideEntry = get_ride_entry_by_ride(ride);
if (ride->num_cars_per_train > rideEntry->zero_cars + 1)
ride_set_num_cars_per_vehicle(ride, ride->num_cars_per_train - 1);
ride->SetNumCarsPerVehicle(ride->num_cars_per_train - 1);
break;
}
}
@@ -2907,7 +2907,7 @@ static void window_ride_vehicle_dropdown(rct_window* w, rct_widgetindex widgetIn
if (ride != nullptr)
{
auto newRideType = VehicleDropdownData[dropdownIndex].subtype_id;
ride_set_ride_entry(ride, newRideType);
ride->SetRideEntry(newRideType);
}
}
break;
+1 -1
View File
@@ -625,7 +625,7 @@ static void window_ride_construction_close(rct_window* w)
}
}
ride_set_to_default_inspection_interval(ride);
ride->SetToDefaultInspectionInterval();
auto intent = Intent(WC_RIDE);
intent.putExtra(INTENT_EXTRA_RIDE_ID, ride->id);
context_open_intent(&intent);
+1 -1
View File
@@ -173,7 +173,7 @@ static void cheat_renew_rides()
FOR_ALL_RIDES (i, ride)
{
ride_renew(ride);
ride->Renew();
}
window_invalidate_by_class(WC_RIDE);
}
+1 -1
View File
@@ -350,7 +350,7 @@ private:
res->ExpenditureType = RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION;
res->Cost = GetRefurbishPrice(ride);
ride_renew(ride);
ride->Renew();
ride->lifecycle_flags &= ~RIDE_LIFECYCLE_EVER_BEEN_OPENED;
ride->last_crash_type = RIDE_CRASH_TYPE_NONE;
+1 -1
View File
@@ -186,7 +186,7 @@ public:
ride_remove_peeps(ride);
ride->mode = _value;
ride_update_max_vehicles(ride);
ride->UpdateMaxVehicles();
break;
case RideSetSetting::Departure:
ride->depart_flags = _value;
@@ -204,7 +204,7 @@ public:
}
ride->num_circuits = 1;
ride_update_max_vehicles(ride);
ride->UpdateMaxVehicles();
auto res = std::make_unique<GameActionResult>();
if (ride->overall_view.xy != RCT_XY8_UNDEFINED)
+1 -1
View File
@@ -682,7 +682,7 @@ public:
mapLoc.x, mapLoc.y, baseZ, _origin.direction, _rideIndex, GAME_COMMAND_FLAG_APPLY);
}
sub_6CB945(ride);
ride_update_max_vehicles(ride);
ride->UpdateMaxVehicles();
}
if (rideTypeFlags & RIDE_TYPE_FLAG_TRACK_MUST_BE_ON_WATER)
+1 -1
View File
@@ -450,7 +450,7 @@ public:
sub_6CB945(ride);
if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST))
{
ride_update_max_vehicles(ride);
ride->UpdateMaxVehicles();
}
}
+1 -1
View File
@@ -192,7 +192,7 @@ void finance_pay_ride_upkeep()
{
if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_EVER_BEEN_OPENED))
{
ride_renew(ride);
ride->Renew();
}
if (ride->status != RIDE_STATUS_CLOSED && !(gParkFlags & PARK_FLAGS_NO_MONEY))
+56 -58
View File
@@ -216,7 +216,6 @@ static void ride_shop_connected(Ride* ride);
static void ride_spiral_slide_update(Ride* ride);
static void ride_update(Ride* ride);
void loc_6DDF9C(Ride* ride, TileElement* tileElement);
static bool ride_is_ride(Ride* ride);
Ride* get_ride(int32_t index)
{
@@ -4973,7 +4972,7 @@ static void ride_create_vehicles_find_first_block(Ride* ride, CoordsXYE* outXYEl
*/
static bool ride_create_vehicles(Ride* ride, CoordsXYE* element, int32_t isApplying)
{
ride_update_max_vehicles(ride);
ride->UpdateMaxVehicles();
if (ride->subtype == RIDE_ENTRY_INDEX_NULL)
{
return true;
@@ -5900,7 +5899,7 @@ void ride_set_colour_preset(Ride* ride, uint8_t index)
const track_colour_preset_list* colourPresets = &RideColourPresets[ride->type];
TrackColour colours = { COLOUR_BLACK, COLOUR_BLACK, COLOUR_BLACK };
// Stalls save their default colour in the vehicle settings (since they share a common ride type)
if (!ride_is_ride(ride))
if (!ride->IsRide())
{
auto rideEntry = get_ride_entry(ride->subtype);
if (rideEntry != nullptr && rideEntry->vehicle_preset_list->count > 0)
@@ -6980,12 +6979,12 @@ static int32_t ride_get_track_length(Ride* ride)
*
* rct2: 0x006DD57D
*/
void ride_update_max_vehicles(Ride* ride)
void Ride::UpdateMaxVehicles()
{
if (ride->subtype == RIDE_ENTRY_INDEX_NULL)
if (subtype == RIDE_ENTRY_INDEX_NULL)
return;
rct_ride_entry* rideEntry = get_ride_entry(ride->subtype);
rct_ride_entry* rideEntry = get_ride_entry(subtype);
if (rideEntry == nullptr)
{
return;
@@ -6997,16 +6996,16 @@ void ride_update_max_vehicles(Ride* ride)
if (rideEntry->cars_per_flat_ride == 0xFF)
{
int32_t trainLength;
ride->num_cars_per_train = std::max(rideEntry->min_cars_in_train, ride->num_cars_per_train);
ride->min_max_cars_per_train = rideEntry->max_cars_in_train | (rideEntry->min_cars_in_train << 4);
num_cars_per_train = std::max(rideEntry->min_cars_in_train, num_cars_per_train);
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(ride);
int32_t stationLength = ride_get_smallest_station_length(this);
if (stationLength == -1)
return;
stationLength = (stationLength * 0x44180) - 0x16B2A;
int32_t maxMass = RideData5[ride->type].max_mass << 8;
int32_t maxMass = RideData5[type].max_mass << 8;
int32_t maxCarsPerTrain = 1;
for (int32_t numCars = rideEntry->max_cars_in_train; numCars > 0; numCars--)
{
@@ -7014,7 +7013,7 @@ void ride_update_max_vehicles(Ride* ride)
int32_t totalMass = 0;
for (int32_t i = 0; i < numCars; i++)
{
vehicleEntry = &rideEntry->vehicles[ride_entry_get_vehicle_at_position(ride->subtype, numCars, i)];
vehicleEntry = &rideEntry->vehicles[ride_entry_get_vehicle_at_position(subtype, numCars, i)];
trainLength += vehicleEntry->spacing;
totalMass += vehicleEntry->car_mass;
}
@@ -7025,19 +7024,19 @@ void ride_update_max_vehicles(Ride* ride)
break;
}
}
int32_t newCarsPerTrain = std::max(ride->proposed_num_cars_per_train, rideEntry->min_cars_in_train);
int32_t newCarsPerTrain = std::max(proposed_num_cars_per_train, rideEntry->min_cars_in_train);
maxCarsPerTrain = std::max(maxCarsPerTrain, (int32_t)rideEntry->min_cars_in_train);
if (!gCheatsDisableTrainLengthLimit)
{
newCarsPerTrain = std::min(maxCarsPerTrain, newCarsPerTrain);
}
ride->min_max_cars_per_train = maxCarsPerTrain | (rideEntry->min_cars_in_train << 4);
min_max_cars_per_train = maxCarsPerTrain | (rideEntry->min_cars_in_train << 4);
switch (ride->mode)
switch (mode)
{
case RIDE_MODE_CONTINUOUS_CIRCUIT_BLOCK_SECTIONED:
case RIDE_MODE_POWERED_LAUNCH_BLOCK_SECTIONED:
maxNumTrains = std::clamp(ride->num_stations + ride->num_block_brakes - 1, 1, 31);
maxNumTrains = std::clamp(num_stations + num_block_brakes - 1, 1, 31);
break;
case RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE:
case RIDE_MODE_POWERED_LAUNCH_PASSTROUGH:
@@ -7051,7 +7050,7 @@ void ride_update_max_vehicles(Ride* ride)
trainLength = 0;
for (int32_t i = 0; i < newCarsPerTrain; i++)
{
vehicleEntry = &rideEntry->vehicles[ride_entry_get_vehicle_at_position(ride->subtype, newCarsPerTrain, i)];
vehicleEntry = &rideEntry->vehicles[ride_entry_get_vehicle_at_position(subtype, newCarsPerTrain, i)];
trainLength += vehicleEntry->spacing;
}
@@ -7066,31 +7065,30 @@ void ride_update_max_vehicles(Ride* ride)
totalLength += trainLength;
} while (totalLength <= stationLength);
if ((ride->mode != RIDE_MODE_STATION_TO_STATION && ride->mode != RIDE_MODE_CONTINUOUS_CIRCUIT)
|| !(RideData4[ride->type].flags & RIDE_TYPE_FLAG4_ALLOW_MORE_VEHICLES_THAN_STATION_FITS))
if ((mode != RIDE_MODE_STATION_TO_STATION && mode != RIDE_MODE_CONTINUOUS_CIRCUIT)
|| !(RideData4[type].flags & RIDE_TYPE_FLAG4_ALLOW_MORE_VEHICLES_THAN_STATION_FITS))
{
maxNumTrains = std::min(maxNumTrains, 31);
}
else
{
vehicleEntry = &rideEntry->vehicles[ride_entry_get_vehicle_at_position(ride->subtype, newCarsPerTrain, 0)];
int32_t speed = vehicleEntry->powered_max_speed;
vehicleEntry = &rideEntry->vehicles[ride_entry_get_vehicle_at_position(subtype, newCarsPerTrain, 0)];
int32_t poweredMaxSpeed = vehicleEntry->powered_max_speed;
int32_t totalSpacing = 0;
for (int32_t i = 0; i < newCarsPerTrain; i++)
{
vehicleEntry = &rideEntry
->vehicles[ride_entry_get_vehicle_at_position(ride->subtype, newCarsPerTrain, i)];
vehicleEntry = &rideEntry->vehicles[ride_entry_get_vehicle_at_position(subtype, newCarsPerTrain, i)];
totalSpacing += vehicleEntry->spacing;
}
totalSpacing >>= 13;
int32_t trackLength = ride_get_track_length(ride) / 4;
if (speed > 10)
int32_t trackLength = ride_get_track_length(this) / 4;
if (poweredMaxSpeed > 10)
trackLength = (trackLength * 3) / 4;
if (speed > 25)
if (poweredMaxSpeed > 25)
trackLength = (trackLength * 3) / 4;
if (speed > 40)
if (poweredMaxSpeed > 40)
trackLength = (trackLength * 3) / 4;
maxNumTrains = 0;
@@ -7103,14 +7101,14 @@ void ride_update_max_vehicles(Ride* ride)
}
break;
}
ride->max_trains = maxNumTrains;
max_trains = maxNumTrains;
numCarsPerTrain = std::min(ride->proposed_num_cars_per_train, (uint8_t)newCarsPerTrain);
numCarsPerTrain = std::min(proposed_num_cars_per_train, (uint8_t)newCarsPerTrain);
}
else
{
ride->max_trains = rideEntry->cars_per_flat_ride;
ride->min_max_cars_per_train = rideEntry->max_cars_in_train | (rideEntry->min_cars_in_train << 4);
max_trains = rideEntry->cars_per_flat_ride;
min_max_cars_per_train = rideEntry->max_cars_in_train | (rideEntry->min_cars_in_train << 4);
numCarsPerTrain = rideEntry->max_cars_in_train;
maxNumTrains = rideEntry->cars_per_flat_ride;
}
@@ -7119,33 +7117,33 @@ void ride_update_max_vehicles(Ride* ride)
{
maxNumTrains = 31;
}
numVehicles = std::min(ride->proposed_num_vehicles, (uint8_t)maxNumTrains);
numVehicles = std::min(proposed_num_vehicles, (uint8_t)maxNumTrains);
// Refresh new current num vehicles / num cars per vehicle
if (numVehicles != ride->num_vehicles || numCarsPerTrain != ride->num_cars_per_train)
if (numVehicles != num_vehicles || numCarsPerTrain != num_cars_per_train)
{
ride->num_cars_per_train = numCarsPerTrain;
ride->num_vehicles = numVehicles;
window_invalidate_by_number(WC_RIDE, ride->id);
num_cars_per_train = numCarsPerTrain;
num_vehicles = numVehicles;
window_invalidate_by_number(WC_RIDE, id);
}
}
void ride_set_ride_entry(Ride* ride, int32_t rideEntry)
void Ride::SetRideEntry(int32_t rideEntry)
{
auto colour = ride_get_unused_preset_vehicle_colour(rideEntry);
auto rideSetVehicleAction = RideSetVehicleAction(ride->id, RideSetVehicleType::RideEntry, rideEntry, colour);
auto rideSetVehicleAction = RideSetVehicleAction(id, RideSetVehicleType::RideEntry, rideEntry, colour);
GameActions::Execute(&rideSetVehicleAction);
}
void ride_set_num_vehicles(Ride* ride, int32_t numVehicles)
void Ride::SetNumVehicles(int32_t numVehicles)
{
auto rideSetVehicleAction = RideSetVehicleAction(ride->id, RideSetVehicleType::NumTrains, numVehicles);
auto rideSetVehicleAction = RideSetVehicleAction(id, RideSetVehicleType::NumTrains, numVehicles);
GameActions::Execute(&rideSetVehicleAction);
}
void ride_set_num_cars_per_vehicle(Ride* ride, int32_t numCarsPerVehicle)
void Ride::SetNumCarsPerVehicle(int32_t numCarsPerVehicle)
{
auto rideSetVehicleAction = RideSetVehicleAction(ride->id, RideSetVehicleType::NumCarsPerTrain, numCarsPerVehicle);
auto rideSetVehicleAction = RideSetVehicleAction(id, RideSetVehicleType::NumCarsPerTrain, numCarsPerVehicle);
GameActions::Execute(&rideSetVehicleAction);
}
@@ -7377,14 +7375,14 @@ void sub_6CB945(Ride* ride)
}
}
void ride_set_to_default_inspection_interval(Ride* ride)
void Ride::SetToDefaultInspectionInterval()
{
uint8_t defaultInspectionInterval = gConfigGeneral.default_inspection_interval;
if (ride->inspection_interval != defaultInspectionInterval)
if (inspection_interval != defaultInspectionInterval)
{
if (defaultInspectionInterval <= RIDE_INSPECTION_NEVER)
{
set_operating_setting(ride->id, RideSetSetting::InspectionInterval, defaultInspectionInterval);
set_operating_setting(id, RideSetSetting::InspectionInterval, defaultInspectionInterval);
}
}
}
@@ -7393,9 +7391,9 @@ void ride_set_to_default_inspection_interval(Ride* ride)
*
* rct2: 0x006B752C
*/
void ride_crash(Ride* ride, uint8_t vehicleIndex)
void Ride::Crash(uint8_t vehicleIndex)
{
rct_vehicle* vehicle = GET_VEHICLE(ride->vehicles[vehicleIndex]);
rct_vehicle* vehicle = GET_VEHICLE(vehicles[vehicleIndex]);
if (!(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO))
{
@@ -7411,11 +7409,11 @@ void ride_crash(Ride* ride, uint8_t vehicleIndex)
}
}
set_format_arg(0, rct_string_id, ride->name);
set_format_arg(2, uint32_t, ride->name_arguments);
set_format_arg(0, rct_string_id, name);
set_format_arg(2, uint32_t, name_arguments);
if (gConfigNotifications.ride_crashed)
{
news_item_add_to_queue(NEWS_ITEM_RIDE, STR_RIDE_HAS_CRASHED, ride->id);
news_item_add_to_queue(NEWS_ITEM_RIDE, STR_RIDE_HAS_CRASHED, id);
}
}
@@ -7508,22 +7506,22 @@ rct_vehicle* ride_get_broken_vehicle(Ride* ride)
*
* rct2: 0x006D235B
*/
void ride_delete(Ride* ride)
void Ride::Delete()
{
user_string_free(ride->name);
ride->type = RIDE_TYPE_NULL;
user_string_free(name);
type = RIDE_TYPE_NULL;
}
void ride_renew(Ride* ride)
void Ride::Renew()
{
// Set build date to current date (so the ride is brand new)
ride->build_date = gDateMonthsElapsed;
ride->reliability = RIDE_INITIAL_RELIABILITY;
build_date = gDateMonthsElapsed;
reliability = RIDE_INITIAL_RELIABILITY;
}
static bool ride_is_ride(Ride* ride)
bool Ride::IsRide() const
{
switch (ride->type)
switch (type)
{
case RIDE_TYPE_FOOD_STALL:
case RIDE_TYPE_1D:
@@ -7545,7 +7543,7 @@ money16 ride_get_price(Ride* ride)
{
if (gParkFlags & PARK_FLAGS_NO_MONEY)
return 0;
if (ride_is_ride(ride))
if (ride->IsRide())
{
if (!park_ride_prices_unlocked())
{
+10 -10
View File
@@ -354,6 +354,16 @@ struct Ride
RideStation stations[MAX_STATIONS];
bool CanBreakDown() const;
bool IsRide() const;
void Renew();
void Delete();
void Crash(uint8_t vehicleIndex);
void SetToDefaultInspectionInterval();
void SetRideEntry(int32_t rideEntry);
void SetNumVehicles(int32_t numVehicles);
void SetNumCarsPerVehicle(int32_t numCarsPerVehicle);
void UpdateMaxVehicles();
};
#pragma pack(push, 1)
@@ -1129,14 +1139,9 @@ void ride_fix_breakdown(Ride* ride, int32_t reliabilityIncreaseFactor);
void ride_entry_get_train_layout(int32_t rideEntryIndex, int32_t numCarsPerTrain, uint8_t* trainLayout);
uint8_t ride_entry_get_vehicle_at_position(int32_t rideEntryIndex, int32_t numCarsPerTrain, int32_t position);
void ride_update_max_vehicles(Ride* ride);
void ride_update_vehicle_colours(Ride* ride);
uint64_t ride_entry_get_supported_track_pieces(const rct_ride_entry* rideEntry);
void ride_set_ride_entry(Ride* ride, int32_t rideEntry);
void ride_set_num_vehicles(Ride* ride, int32_t numVehicles);
void ride_set_num_cars_per_vehicle(Ride* ride, int32_t numCarsPerVehicle);
enum class RideSetSetting : uint8_t;
money32 set_operating_setting(ride_id_t rideId, RideSetSetting setting, uint8_t value);
money32 set_operating_setting_nested(ride_id_t rideId, RideSetSetting setting, uint8_t value, uint8_t flags);
@@ -1147,10 +1152,7 @@ void game_command_set_ride_vehicles(
void game_command_place_ride_entrance_or_exit(
int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp);
void ride_set_to_default_inspection_interval(Ride* ride);
void sub_6CB945(Ride* ride);
void ride_crash(Ride* ride, uint8_t vehicleIndex);
void sub_6C94D8();
@@ -1167,8 +1169,6 @@ rct_vehicle* ride_get_broken_vehicle(Ride* ride);
void window_ride_construction_do_station_check();
void window_ride_construction_do_entrance_exit_check();
void ride_delete(Ride* ride);
void ride_renew(Ride* ride);
money16 ride_get_price(Ride* ride);
TileElement* get_station_platform(int32_t x, int32_t y, int32_t z, int32_t z_tolerance);
+1 -1
View File
@@ -1178,7 +1178,7 @@ static money32 track_remove(
sub_6CB945(ride);
if (!(flags & GAME_COMMAND_FLAG_GHOST))
{
ride_update_max_vehicles(ride);
ride->UpdateMaxVehicles();
}
}
+3 -3
View File
@@ -1662,7 +1662,7 @@ static bool track_design_place_ride(rct_track_td6* td6, int16_t x, int16_t y, in
if (_trackDesignPlaceOperation == PTD_OPERATION_CLEAR_OUTLINES)
{
sub_6CB945(ride);
ride_delete(ride);
ride->Delete();
}
return true;
}
@@ -1995,7 +1995,7 @@ static money32 place_track_design(int16_t x, int16_t y, int16_t z, uint8_t flags
num_circuits = 1;
}
set_operating_setting_nested(ride->id, RideSetSetting::NumCircuits, num_circuits, flags);
ride_set_to_default_inspection_interval(ride);
ride->SetToDefaultInspectionInterval();
ride->lifecycle_flags |= RIDE_LIFECYCLE_NOT_CUSTOM_DESIGN;
ride->colour_scheme_type = td6->version_and_colour_scheme & 3;
@@ -2300,7 +2300,7 @@ void track_design_draw_preview(rct_track_td6* td6, uint8_t* pixels)
dpi.bits += TRACK_PREVIEW_IMAGE_SIZE;
}
ride_delete(ride);
ride->Delete();
track_design_preview_restore_map(mapBackup);
}
+3 -3
View File
@@ -3532,7 +3532,7 @@ static void vehicle_update_collision_setup(rct_vehicle* vehicle)
return;
}
ride_crash(ride, trainIndex);
ride->Crash(trainIndex);
if (ride->status != RIDE_STATUS_CLOSED)
{
@@ -5270,7 +5270,7 @@ static void vehicle_crash_on_land(rct_vehicle* vehicle)
return;
}
ride_crash(ride, trainIndex);
ride->Crash(trainIndex);
if (ride->status != RIDE_STATUS_CLOSED)
{
@@ -5324,7 +5324,7 @@ static void vehicle_crash_on_water(rct_vehicle* vehicle)
return;
}
ride_crash(ride, trainIndex);
ride->Crash(trainIndex);
if (ride->status != RIDE_STATUS_CLOSED)
{