Skip to content

Commit

Permalink
Allow cable lift to start after block brake
Browse files Browse the repository at this point in the history
  • Loading branch information
X123M3-256 authored and Gymnasiast committed Dec 23, 2023
1 parent 2147b69 commit eb8c48b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 83 deletions.
2 changes: 1 addition & 1 deletion data/language/en-GB.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2208,7 +2208,7 @@ STR_3136 :Warning: This design will be built with an alternative vehicle type
STR_3137 :Select Nearby Scenery
STR_3138 :Reset Selection
STR_3139 :Cable lift unable to work in this operating mode
STR_3140 :Cable lift hill must start immediately after station
STR_3140 :Cable lift hill must start immediately after station or block brake
STR_3141 :Multi-circuit per ride not possible with cable lift hill
STR_3142 :{WINDOW_COLOUR_2}Capacity: {BLACK}{STRINGID}
STR_3143 :Show people on map
Expand Down
5 changes: 2 additions & 3 deletions src/openrct2/ride/CableLift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ void Vehicle::CableLiftUpdateTravelling()

velocity = std::min(passengerVehicle->velocity, 439800);
acceleration = 0;
if (passengerVehicle->HasFlag(VehicleFlags::TrainIsBroken))
return;

if (!(CableLiftUpdateTrackMotion() & VEHICLE_UPDATE_MOTION_TRACK_FLAG_1))
return;
Expand Down Expand Up @@ -325,7 +323,8 @@ bool Vehicle::CableLiftUpdateTrackMotionBackwards()
SetTrackDirection(output.begin_direction);
SetTrackType(output.begin_element->AsTrack()->GetTrackType());

if (output.begin_element->AsTrack()->GetTrackType() == TrackElemType::EndStation)
if (output.begin_element->AsTrack()->GetTrackType() == TrackElemType::EndStation
|| output.begin_element->AsTrack()->GetTrackType() == TrackElemType::BlockBrakes)
{
_vehicleMotionTrackFlags = VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_AT_STATION;
}
Expand Down
104 changes: 25 additions & 79 deletions src/openrct2/ride/Ride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3736,97 +3736,43 @@ void Ride::MoveTrainsToBlockBrakes(const CoordsXYZ& firstBlockPosition, TrackEle
*/
static ResultWithMessage RideInitialiseCableLiftTrack(const Ride& ride, bool isApplying)
{
CoordsXYZ location;
location.SetNull();
for (const auto& station : ride.GetStations())
{
location = station.GetStart();
if (!location.IsNull())
break;
}

if (location.IsNull())
{
return { false, STR_CABLE_LIFT_HILL_MUST_START_IMMEDIATELY_AFTER_STATION };
}

bool success = false;
TileElement* tileElement = MapGetFirstElementAt(location);
if (tileElement == nullptr)
TileElement* cableLiftTileElement = MapGetTrackElementAtOfTypeSeq(ride.CableLiftLoc, TrackElemType::CableLiftHill, 0);
if (cableLiftTileElement == nullptr)
return { false };
do
{
if (tileElement->GetType() != TileElementType::Track)
continue;
if (tileElement->GetBaseZ() != location.z)
continue;

const auto& ted = GetTrackElementDescriptor(tileElement->AsTrack()->GetTrackType());
if (!(std::get<0>(ted.SequenceProperties) & TRACK_SEQUENCE_FLAG_ORIGIN))
{
continue;
}
success = true;
break;
} while (!(tileElement++)->IsLastForTile());

if (!success)
return { false };

enum
{
STATE_FIND_CABLE_LIFT,
STATE_FIND_STATION,
STATE_REST_OF_TRACK
};
int32_t state = STATE_FIND_CABLE_LIFT;

TrackCircuitIterator it;
TrackCircuitIteratorBegin(&it, { location, tileElement });
TrackCircuitIteratorBegin(&it, { ride.CableLiftLoc, cableLiftTileElement });
while (TrackCircuitIteratorPrevious(&it))
{
tileElement = it.current.element;
TileElement* tileElement = it.current.element;
auto trackType = tileElement->AsTrack()->GetTrackType();

uint16_t flags = TRACK_ELEMENT_SET_HAS_CABLE_LIFT_FALSE;
switch (state)
// Search for the start of the hill
switch (trackType)
{
case STATE_FIND_CABLE_LIFT:
// Search for a cable lift hill track element
if (trackType == TrackElemType::CableLiftHill)
case TrackElemType::Flat:
case TrackElemType::Up25:
case TrackElemType::Up60:
case TrackElemType::FlatToUp25:
case TrackElemType::Up25ToFlat:
case TrackElemType::Up25ToUp60:
case TrackElemType::Up60ToUp25:
case TrackElemType::FlatToUp60LongBase:
if (isApplying)
{
flags = TRACK_ELEMENT_SET_HAS_CABLE_LIFT_TRUE;
state = STATE_FIND_STATION;
auto tmpLoc = CoordsXYZ{ it.current, tileElement->GetBaseZ() };
auto direction = tileElement->GetDirection();
trackType = tileElement->AsTrack()->GetTrackType();
GetTrackElementOriginAndApplyChanges(
{ tmpLoc, direction }, trackType, 0, &tileElement, TRACK_ELEMENT_SET_HAS_CABLE_LIFT_TRUE);
}
break;
case STATE_FIND_STATION:
// Search for the start of the hill
switch (trackType)
{
case TrackElemType::Flat:
case TrackElemType::Up25:
case TrackElemType::Up60:
case TrackElemType::FlatToUp25:
case TrackElemType::Up25ToFlat:
case TrackElemType::Up25ToUp60:
case TrackElemType::Up60ToUp25:
case TrackElemType::FlatToUp60LongBase:
flags = TRACK_ELEMENT_SET_HAS_CABLE_LIFT_TRUE;
break;
case TrackElemType::EndStation:
state = STATE_REST_OF_TRACK;
break;
default:
return { false, STR_CABLE_LIFT_HILL_MUST_START_IMMEDIATELY_AFTER_STATION };
}
case TrackElemType::EndStation:
case TrackElemType::BlockBrakes:
return { true };
break;
}
if (isApplying)
{
auto tmpLoc = CoordsXYZ{ it.current, tileElement->GetBaseZ() };
auto direction = tileElement->GetDirection();
trackType = tileElement->AsTrack()->GetTrackType();
GetTrackElementOriginAndApplyChanges({ tmpLoc, direction }, trackType, 0, &tileElement, flags);
default:
return { false, STR_CABLE_LIFT_HILL_MUST_START_IMMEDIATELY_AFTER_STATION };
}
}
return { true };
Expand Down
30 changes: 30 additions & 0 deletions src/openrct2/ride/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4076,6 +4076,7 @@ void Vehicle::UpdateTravellingCableLift()
if (curRide == nullptr)
return;

// Should only run when departing station
if (sub_state == 0)
{
if (HasFlag(VehicleFlags::TrainIsBroken))
Expand Down Expand Up @@ -6082,6 +6083,35 @@ void Vehicle::CheckAndApplyBlockSectionStopSite()
{
case TrackElemType::BlockBrakes:
case TrackElemType::DiagBlockBrakes:

// Do not apply brake if vehicle is already on cable lift
if (status == Vehicle::Status::TravellingCableLift)
return;

// Check if this brake is followed by a cable lift
if (curRide->lifecycle_flags & RIDE_LIFECYCLE_CABLE_LIFT)
{
CoordsXYE track;
int32_t zUnused;
int32_t direction;
uint8_t trackDirection = GetTrackDirection();
if (TrackBlockGetNextFromZero(TrackLocation, *curRide, trackDirection, &track, &zUnused, &direction, false)
&& track.element != nullptr && track.element->AsTrack()->HasCableLift())
{
if (velocity > kBlockBrakeBaseSpeed)
{
velocity -= velocity >> 3;
acceleration = 0;
}
if (track_progress >= 18)
{
velocity = 0;
if (!curRide->IsBlockSectioned() || !trackElement->AsTrack()->IsBrakeClosed())
SetState(Vehicle::Status::WaitingForCableLift, 2);
}
return;
}
}
if (curRide->IsBlockSectioned() && trackElement->AsTrack()->IsBrakeClosed())
ApplyStopBlockBrake();
else
Expand Down

0 comments on commit eb8c48b

Please sign in to comment.