Skip to content

Commit 9bcea39

Browse files
committed
Generalize cable launch
1 parent 810a0bf commit 9bcea39

11 files changed

Lines changed: 106 additions & 56 deletions

File tree

src/openrct2/paint/track/coaster/HydraulicLaunchedRollerCoaster.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace OpenRCT2::HydraulicLaunchedRC
4646

4747
if (trackElement.HasCableLift())
4848
{
49-
int sprites[9] = { 3, 3, 3, 2, 1, 0, 0, 1, 2 };
49+
int sprites[10] = { 3, 3, 3, 2, 1, 0, 0, 1, 2, 3 };
5050
int spriteIndex = sprites[trackElement.GetCableLaunchFinState()];
5151
PaintAddImageAsParentRotated(
5252
session, direction, session.TrackColours.WithIndex(imageIds[direction][1] + 2 * spriteIndex), { 0, 0, height },
@@ -18806,7 +18806,7 @@ namespace OpenRCT2::HydraulicLaunchedRC
1880618806
PaintSession& session, const Ride& ride, uint8_t trackSequence, uint8_t direction, int32_t height,
1880718807
const TrackElement& trackElement, SupportType supportType)
1880818808
{
18809-
int sprites[9] = { 3, 3, 3, 2, 1, 0, 0, 1, 2 };
18809+
int sprites[10] = { 3, 3, 3, 2, 1, 0, 0, 1, 2, 3 };
1881018810
int spriteIndex = sprites[trackElement.GetCableLaunchFinState()];
1881118811
PaintAddImageAsParentRotated(
1881218812
session, direction,

src/openrct2/paint/track/coaster/LoopingRollerCoaster.cpp

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,24 @@ static void LoopingRCTrackFlat(
6868
{ { 0, 6, height }, { 32, 20, 3 } });
6969
break;
7070
}
71-
if (TrackPaintUtilShouldPaintSupports(session.MapPosition))
71+
}
72+
else if (trackElement.HasCableLift())
73+
{
74+
switch (direction)
7275
{
73-
MetalASupportsPaintSetup(session, supportType.metal, MetalSupportPlace::Centre, 0, height, session.SupportColours);
76+
case 0:
77+
case 2:
78+
PaintAddImageAsParentRotated(
79+
80+
session, direction, session.TrackColours.WithIndex(SPR_LOOPING_RC_FLAT_CHAINED_SW_NE), { 0, 0, height },
81+
{ { 0, 6, height }, { 32, 20, 3 } });
82+
break;
83+
case 1:
84+
case 3:
85+
PaintAddImageAsParentRotated(
86+
session, direction, session.TrackColours.WithIndex(SPR_LOOPING_RC_FLAT_CHAINED_NW_SE), { 0, 0, height },
87+
{ { 0, 6, height }, { 32, 20, 3 } });
88+
break;
7489
}
7590
}
7691
else
@@ -90,10 +105,38 @@ static void LoopingRCTrackFlat(
90105
{ { 0, 6, height }, { 32, 20, 3 } });
91106
break;
92107
}
93-
if (TrackPaintUtilShouldPaintSupports(session.MapPosition))
94-
{
95-
MetalASupportsPaintSetup(session, supportType.metal, MetalSupportPlace::Centre, 0, height, session.SupportColours);
96-
}
108+
}
109+
if (TrackPaintUtilShouldPaintSupports(session.MapPosition))
110+
{
111+
MetalASupportsPaintSetup(session, supportType.metal, MetalSupportPlace::Centre, 0, height, session.SupportColours);
112+
}
113+
PaintUtilPushTunnelRotated(session, direction, height, kTunnelGroup, TunnelSubType::Flat);
114+
PaintUtilSetSegmentSupportHeight(session, PaintUtilRotateSegments(BlockedSegments::kStraightFlat, direction), 0xFFFF, 0);
115+
PaintUtilSetGeneralSupportHeight(session, height + kDefaultGeneralSupportHeight);
116+
}
117+
118+
static void TrackCableLaunch(
119+
PaintSession& session, const Ride& ride, uint8_t trackSequence, uint8_t direction, int32_t height,
120+
const TrackElement& trackElement, SupportType supportType)
121+
{
122+
switch (direction)
123+
{
124+
case 0:
125+
case 2:
126+
PaintAddImageAsParentRotated(
127+
session, direction, session.TrackColours.WithIndex(SPR_LOOPING_RC_FLAT_CHAINED_SW_NE), { 0, 0, height },
128+
{ { 0, 6, height }, { 32, 20, 3 } });
129+
break;
130+
case 1:
131+
case 3:
132+
PaintAddImageAsParentRotated(
133+
session, direction, session.TrackColours.WithIndex(SPR_LOOPING_RC_FLAT_CHAINED_NW_SE), { 0, 0, height },
134+
{ { 0, 6, height }, { 32, 20, 3 } });
135+
break;
136+
}
137+
if (TrackPaintUtilShouldPaintSupports(session.MapPosition))
138+
{
139+
MetalASupportsPaintSetup(session, supportType.metal, MetalSupportPlace::Centre, 0, height, session.SupportColours);
97140
}
98141
PaintUtilPushTunnelRotated(session, direction, height, kTunnelGroup, TunnelSubType::Flat);
99142
PaintUtilSetSegmentSupportHeight(session, PaintUtilRotateSegments(BlockedSegments::kStraightFlat, direction), 0xFFFF, 0);
@@ -10585,6 +10628,8 @@ TrackPaintFunction GetTrackPaintFunctionLoopingRC(OpenRCT2::TrackElemType trackT
1058510628

1058610629
case TrackElemType::Booster:
1058710630
return LoopingRCTrackBooster;
10631+
case TrackElemType::CableLaunch:
10632+
return TrackCableLaunch;
1058810633

1058910634
case TrackElemType::DiagBrakes:
1059010635
case TrackElemType::DiagBlockBrakes:

src/openrct2/paint/vehicle/VehiclePaint.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4640,7 +4640,7 @@ void Vehicle::Paint(PaintSession& session, int32_t imageDirection) const
46404640
int32_t zOffset = 0;
46414641
if (IsCableLift())
46424642
{
4643-
carEntry = GetRide()->getRideTypeDescriptor().CatchCarParameters.carEntry;
4643+
carEntry = GetRide()->getRideTypeDescriptor().CatchCarParameters.Car;
46444644
if (carEntry == nullptr)
46454645
{
46464646
// Fall back on the default cable lift vehicle

src/openrct2/ride/CableLaunch.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,13 @@ void Vehicle::CableLaunchUpdateArriving()
9191

9292
CableLiftUpdateTrackMotion();
9393

94-
if (track_progress == 3)
94+
auto wait_position = GetRide()->getRideTypeDescriptor().CatchCarParameters.WaitPosition;
95+
if (track_progress <= wait_position)
9596
{
9697
velocity = 0;
9798
acceleration = 0;
9899
SetState(Vehicle::Status::WaitingForPassengers, sub_state);
99100
}
100-
// sub_state++;
101-
// if (sub_state >= 64)
102-
// SetState(Vehicle::Status::MovingToEndOfStation, sub_state);
103101
}
104102

105103
static TileElement* CableLaunchGetTileElement(const Ride& ride)
@@ -153,7 +151,7 @@ static void CableLaunchUpdateFinStateForTile(CoordsXYZ loc, TrackElement* tileEl
153151
default:
154152
break;
155153
}
156-
if (set_lowered)
154+
if (set_lowered && state != CABLE_LAUNCH_FIN_STATE_NONE)
157155
new_state = CABLE_LAUNCH_FIN_STATE_LOWERING_0;
158156
if (new_state != state)
159157
{
@@ -363,11 +361,11 @@ void Vehicle::CableLaunchUpdateTravelling()
363361
// If the catch car has already stopped, don't run the motion update
364362
if (sub_state & 0x80)
365363
{
366-
// if (CableLaunchCheckBlockClosed(*curRide))
367-
//{
368-
SetState(Vehicle::Status::MovingToEndOfStation, sub_state & 0x7F);
369-
// return;
370-
//}
364+
if ((sub_state & 0x7F) > 32) // CableLaunchCheckBlockClosed(*curRide))
365+
{
366+
SetState(Vehicle::Status::MovingToEndOfStation, sub_state & 0x7F);
367+
return;
368+
}
371369
return;
372370
}
373371

src/openrct2/ride/CableLaunch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ enum CableLaunchState
2525
CABLE_LAUNCH_FIN_STATE_LOWERING_0 = 0x6,
2626
CABLE_LAUNCH_FIN_STATE_LOWERING_1 = 0x7,
2727
CABLE_LAUNCH_FIN_STATE_LOWERING_2 = 0x8,
28+
CABLE_LAUNCH_FIN_STATE_NONE = 0x9,
2829
CABLE_LAUNCH_IS_BRAKE_SECTION = 0x10,
2930
};
3031

src/openrct2/ride/Ride.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3780,7 +3780,7 @@ static void RideCreateCatchCar(Ride& ride)
37803780
auto tileElement = MapGetTrackElementAt(cableLiftLoc);
37813781
int32_t direction = tileElement->GetDirection();
37823782

3783-
int segments = ride.getRideTypeDescriptor().CatchCarParameters.segments;
3783+
int segments = ride.getRideTypeDescriptor().CatchCarParameters.Segments;
37843784

37853785
Vehicle* head = nullptr;
37863786
Vehicle* tail = nullptr;
@@ -3914,10 +3914,10 @@ ResultWithMessage RideInitialiseCableLiftTrack(const Ride& ride, bool applyVehic
39143914
int targetSpeed = ride.launchSpeed;
39153915
int launchAccel = ((6 * (targetSpeed * targetSpeed)) / (4 * (numTiles - brakeTiles)));
39163916

3917-
// Set max acceleration at 10 tiles per second^2 (about 18.5m/s^2)
3918-
if (launchAccel > 210)
3917+
int maxAccel = ride.getRideTypeDescriptor().CatchCarParameters.MaxAcceleration;
3918+
if (launchAccel > maxAccel)
39193919
{
3920-
launchAccel = 210;
3920+
launchAccel = maxAccel;
39213921
}
39223922
Vehicle* catchCar = GetEntity<Vehicle>(ride.cableLift);
39233923
// This shouldn't happen
@@ -3927,13 +3927,15 @@ ResultWithMessage RideInitialiseCableLiftTrack(const Ride& ride, bool applyVehic
39273927

39283928
if (applyTrack)
39293929
{
3930+
int fin_state = (ride.mode == RideMode::poweredLaunchPasstrough) ? CABLE_LAUNCH_FIN_STATE_NONE
3931+
: CABLE_LAUNCH_FIN_STATE_RAISED;
39303932
// Set first tile of cable launch end piece
39313933
cableLiftTileElement->AsTrack()->SetHasCableLift(true);
39323934
if (brakeTiles >= 2)
39333935
cableLiftTileElement->AsTrack()->SetCableLaunchIsBrakeSection(true);
39343936
else
39353937
cableLiftTileElement->AsTrack()->SetCableLaunchIsBrakeSection(false);
3936-
cableLiftTileElement->AsTrack()->SetCableLaunchFinState(CABLE_LAUNCH_FIN_STATE_RAISED);
3938+
cableLiftTileElement->AsTrack()->SetCableLaunchFinState(fin_state);
39373939

39383940
// Set second tile of cable launch end piece
39393941
auto type = cableLiftTileElement->AsTrack()->GetTrackType();
@@ -3946,7 +3948,7 @@ ResultWithMessage RideInitialiseCableLiftTrack(const Ride& ride, bool applyVehic
39463948
{
39473949
trackElement->SetCableLaunchIsBrakeSection(true);
39483950
trackElement->SetHasCableLift(true);
3949-
trackElement->SetCableLaunchFinState(CABLE_LAUNCH_FIN_STATE_RAISED);
3951+
trackElement->SetCableLaunchFinState(fin_state);
39503952
}
39513953

39523954
// Set remaining launch tiles
@@ -3972,7 +3974,7 @@ ResultWithMessage RideInitialiseCableLiftTrack(const Ride& ride, bool applyVehic
39723974
break;
39733975

39743976
// Set all fins to raised
3975-
tileElement->AsTrack()->SetCableLaunchFinState(CABLE_LAUNCH_FIN_STATE_RAISED);
3977+
tileElement->AsTrack()->SetCableLaunchFinState(fin_state);
39763978
MapInvalidateElement(loc, tileElement);
39773979
}
39783980
}
@@ -3991,17 +3993,18 @@ static ResultWithMessage RideCreateCableLift(RideId rideIndex, bool isApplying)
39913993
if (ride == nullptr)
39923994
return { false };
39933995

3994-
if (ride->mode != RideMode::continuousCircuitBlockSectioned && ride->mode != RideMode::continuousCircuit)
3995-
{
3996-
return { false, STR_CABLE_LIFT_UNABLE_TO_WORK_IN_THIS_OPERATING_MODE };
3997-
}
3996+
// TODO don't think this is necessary
3997+
// if (ride->mode != RideMode::continuousCircuitBlockSectioned && ride->mode != RideMode::continuousCircuit)
3998+
//{
3999+
// return { false, STR_CABLE_LIFT_UNABLE_TO_WORK_IN_THIS_OPERATING_MODE };
4000+
// }
39984001

39994002
if (ride->numCircuits > 1)
40004003
{
40014004
return { false, STR_MULTICIRCUIT_NOT_POSSIBLE_WITH_CABLE_LIFT_HILL };
40024005
}
40034006

4004-
if (count_free_misc_sprite_slots() <= ride->getRideTypeDescriptor().CatchCarParameters.segments)
4007+
if (count_free_misc_sprite_slots() <= ride->getRideTypeDescriptor().CatchCarParameters.Segments)
40054008
{
40064009
return { false, STR_UNABLE_TO_CREATE_ENOUGH_VEHICLES };
40074010
}

src/openrct2/ride/RideData.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,10 @@ struct RideLegacyBoosterSettings
228228

229229
struct RideCatchCarParameters
230230
{
231-
const CarEntry* carEntry;
232-
uint8_t segments;
231+
const CarEntry* Car;
232+
uint8_t Segments;
233+
uint8_t MaxAcceleration;
234+
uint8_t WaitPosition;
233235
};
234236

235237
struct RideAlternateTrack
@@ -529,7 +531,7 @@ struct RideTypeDescriptor
529531

530532
RideRatingsDescriptor RatingsData{};
531533

532-
RideCatchCarParameters CatchCarParameters = { nullptr, 0 };
534+
RideCatchCarParameters CatchCarParameters = { nullptr, 0, 0, 0 };
533535
RideAlternateTrackList AlternateTrackList = { 0, { { 0, 0 }, { 0, 0 }, { 0, 0 } } };
534536
UpdateRotatingFunction UpdateRotating = UpdateRotatingDefault;
535537

@@ -670,7 +672,7 @@ constexpr RideTypeDescriptor kDummyRTD =
670672
{ RatingsModifierType::NoModifier, 0, 0, 0, 0 },
671673
},
672674
},
673-
.CatchCarParameters = {nullptr,0},
675+
.CatchCarParameters = {nullptr,0,0,0},
674676
.AlternateTrackList = {0,{{0,0}}},
675677
.UpdateRotating = UpdateRotatingDefault,
676678
.LightFXAddLightsMagicVehicle = nullptr,

src/openrct2/ride/Vehicle.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3371,20 +3371,20 @@ void Vehicle::UpdateArriving()
33713371

33723372
// This is triggered if train rolls back after cable launch and enters the station backwards; it should relaunch without
33733373
// unloading passengers
3374-
if (curRide->lifecycleFlags & RIDE_LIFECYCLE_CABLE_LAUNCH)
3374+
if (curRide->lifecycleFlags & RIDE_LIFECYCLE_CABLE_LAUNCH && status == Vehicle::Status::Travelling)
33753375
{
33763376
printf("Detected rollback into station ride %d\n", curRide->id.ToUnderlying());
33773377
velocity = 0;
33783378

33793379
SetState(Vehicle::Status::WaitingForCableLift, 0);
33803380
// ClearFlag(VehicleFlags::PassedDeferredBlock);
33813381

3382-
// Recall catch car if it exists
3383-
Vehicle* cableLift = GetEntity<Vehicle>(curRide->cableLift);
3384-
if (cableLift != nullptr)
3385-
{
3386-
cableLift->SetState(Vehicle::Status::MovingToEndOfStation, 0);
3387-
}
3382+
// Recall catch car if it exists TODO only needed for deferred blocks
3383+
// Vehicle* cableLift = GetEntity<Vehicle>(curRide->cableLift);
3384+
// if (cableLift != nullptr)
3385+
//{
3386+
// cableLift->SetState(Vehicle::Status::MovingToEndOfStation, 0);
3387+
//}
33883388
return;
33893389
}
33903390

@@ -5673,12 +5673,12 @@ void Vehicle::CheckAndApplyBlockSectionStopSite()
56735673
acceleration = 0;
56745674
NumLaps++;
56755675
SetState(Vehicle::Status::WaitingForCableLift, sub_state);
5676-
// Recall catch car if it exists
5677-
Vehicle* cableLift = GetEntity<Vehicle>(curRide->cableLift);
5678-
if (cableLift != nullptr)
5679-
{
5680-
cableLift->SetState(Vehicle::Status::MovingToEndOfStation, 0);
5681-
}
5676+
// Recall catch car if it exists TODO only needed for deferred blocks
5677+
// Vehicle* cableLift = GetEntity<Vehicle>(curRide->cableLift);
5678+
// if (cableLift != nullptr)
5679+
//{
5680+
// cableLift->SetState(Vehicle::Status::MovingToEndOfStation, 0);
5681+
//}
56825682
}
56835683

56845684
return;

src/openrct2/ride/rtd/coaster/GigaCoaster.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,6 @@ constexpr RideTypeDescriptor GigaCoasterRTD =
8686
{ RatingsModifierType::PenaltyLateralGs, 0, 36864, 30384, 49648 },
8787
},
8888
},
89-
.CatchCarParameters = { &kCableLiftVehicle, 5}
89+
.CatchCarParameters = { &kCableLiftVehicle, 5, 0, 0}
9090
};
9191
// clang-format on

0 commit comments

Comments
 (0)