Fix #3788: Self-intersecting track designs cannot be placed (#25894)

When placing a track design that loops back on itself, earlier placed pieces would block later pieces during clearance checks.

This commit adds an optional RideId parameter to MapCanConstructWithClearAt to skip track elements belonging to the same ride during track design placement.
This commit is contained in:
frozensnowy authored and GitHub committed 2026-01-31 12:29:58 +01:00
1 parent a94841b162
commit 52b0f68aee
4 files changed
+18 -4

No files matched your search

+1
View File
@@ -5,6 +5,7 @@
- Improved: [#25765] The ‘View options’ and ‘Special track elements’ dropdowns no longer need click-and-hold.
- Improved: [#25858] macOS now supports the onboarding menu.
- Change: [#25018] Add upkeep cost to booster pieces.
- Fix: [#3788] Self-intersecting track designs cannot be placed.
- Fix: [#4643, #25167] Many metal supports draw with a filled in top when they didn't in vanilla, causing some slight misalignment and glitching.
- Fix: [#15009] Landscaping tools do not display estimates when the game is paused (original bug).
- Fix: [#18441] Replacing footpaths sometimes results in a spurious “Footpath in the way” error (original bug).
+6 -2
View File
@@ -263,9 +263,11 @@ namespace OpenRCT2::GameActions
auto crossingMode = (rtd.HasFlag(RtdFlag::supportsLevelCrossings) && _trackType == TrackElemType::flat)
? CreateCrossingMode::trackOverPath
: CreateCrossingMode::none;
// When placing from a track design, ignore track elements from the same ride to allow it to intersect itself.
auto ignoreRideId = _fromTrackDesign ? _rideIndex : RideId::GetNull();
auto canBuild = MapCanConstructWithClearAt(
{ mapLoc, baseZ, clearanceZ }, MapPlaceNonSceneryClearFunc, quarterTile, GetFlags(), kTileSlopeFlat,
crossingMode);
crossingMode, false, ignoreRideId);
if (canBuild.error != Status::ok)
{
canBuild.errorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE;
@@ -467,9 +469,11 @@ namespace OpenRCT2::GameActions
auto crossingMode = (rtd.HasFlag(RtdFlag::supportsLevelCrossings) && _trackType == TrackElemType::flat)
? CreateCrossingMode::trackOverPath
: CreateCrossingMode::none;
// When placing from a track design, ignore track elements from the same ride to allow it to intersect itself.
auto ignoreRideId = _fromTrackDesign ? _rideIndex : RideId::GetNull();
auto canBuild = MapCanConstructWithClearAt(
mapLocWithClearance, MapPlaceNonSceneryClearFunc, quarterTile, GetFlags().with(CommandFlag::apply),
kTileSlopeFlat, crossingMode);
kTileSlopeFlat, crossingMode, false, ignoreRideId);
if (canBuild.error != Status::ok)
{
canBuild.errorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE;
+8 -1
View File
@@ -182,7 +182,7 @@ static bool MapLoc68BABCShouldContinue(
*/
GameActions::Result MapCanConstructWithClearAt(
const CoordsXYRangedZ& pos, ClearingFunction clearFunc, const QuarterTile quarterTile, const CommandFlags flags,
const uint8_t slope, const CreateCrossingMode crossingMode, const bool isTree)
const uint8_t slope, const CreateCrossingMode crossingMode, const bool isTree, const RideId ignoreRideId)
{
auto res = GameActions::Result();
@@ -215,6 +215,13 @@ GameActions::Result MapCanConstructWithClearAt(
{
if (tileElement->GetType() != TileElementType::Surface)
{
// Skip track elements belonging to the ride that's being ignored for rides that intersect themselves.
if (!ignoreRideId.IsNull() && tileElement->GetType() == TileElementType::Track
&& tileElement->AsTrack()->GetRideIndex() == ignoreRideId)
{
continue;
}
if (pos.baseZ < tileElement->GetClearanceZ() && pos.clearanceZ > tileElement->GetBaseZ()
&& !(tileElement->IsGhost()))
{
+3 -1
View File
@@ -9,6 +9,7 @@
#pragma once
#include "../Identifiers.h"
#include "../actions/CommandFlag.h"
#include "../actions/GameActionResult.h"
#include "Location.hpp"
@@ -56,7 +57,8 @@ struct ConstructClearResult
[[nodiscard]] OpenRCT2::GameActions::Result MapCanConstructWithClearAt(
const CoordsXYRangedZ& pos, ClearingFunction clearFunc, QuarterTile quarterTile, OpenRCT2::GameActions::CommandFlags flags,
uint8_t slope, CreateCrossingMode crossingMode = CreateCrossingMode::none, bool isTree = false);
uint8_t slope, CreateCrossingMode crossingMode = CreateCrossingMode::none, bool isTree = false,
RideId ignoreRideId = RideId::GetNull());
[[nodiscard]] OpenRCT2::GameActions::Result MapCanConstructAt(const CoordsXYRangedZ& pos, QuarterTile bl);