MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / TrackDesignPlaceRide

Function TrackDesignPlaceRide

src/openrct2/ride/TrackDesign.cpp:1561–1739  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1559}
1560
1561static GameActions::Result TrackDesignPlaceRide(
1562 TrackDesignState& tds, const TrackDesign& td, const CoordsXYZ& origin, Ride& ride)
1563{
1564 tds.origin = origin;
1565 if (tds.placeOperation == TrackPlaceOperation::drawOutlines)
1566 {
1567 MapSelection::clearSelectedTiles();
1568 gMapSelectArrowPosition = CoordsXYZ{ origin, TileElementHeight(origin) };
1569 gMapSelectArrowDirection = _currentTrackPieceDirection;
1570 }
1571
1572 tds.placeZ = 0;
1573 money64 totalCost = 0;
1574 uint8_t rotation = _currentTrackPieceDirection;
1575
1576 auto& gameState = getGameState();
1577
1578 // Track elements
1579 auto newCoords = origin;
1580 for (const auto& track : td.trackElements)
1581 {
1582 auto trackType = track.type;
1583 const auto& ted = GetTrackElementDescriptor(trackType);
1584
1585 TrackDesignUpdatePreviewBounds(tds, newCoords);
1586
1587 switch (tds.placeOperation)
1588 {
1589 case TrackPlaceOperation::drawOutlines:
1590 for (uint8_t i = 0; i < ted.sequenceData.numSequences; i++)
1591 {
1592 const auto& trackBlock = ted.sequenceData.sequences[i].clearance;
1593 auto tile = CoordsXY{ newCoords } + CoordsXY{ trackBlock.x, trackBlock.y }.Rotate(rotation);
1594 TrackDesignUpdatePreviewBounds(tds, { tile, newCoords.z });
1595 TrackDesignAddSelectedTile(tile);
1596 }
1597 break;
1598 case TrackPlaceOperation::removeGhost:
1599 {
1600 const TrackCoordinates* trackCoordinates = &ted.coordinates;
1601 int32_t tempZ = newCoords.z - trackCoordinates->zBegin + ted.sequenceData.sequences[0].clearance.z;
1602 auto trackRemoveAction = GameActions::TrackRemoveAction(
1603 trackType, 0, { newCoords, tempZ, static_cast<Direction>(rotation & 3) });
1604 trackRemoveAction.SetFlags(
1605 { CommandFlag::allowDuringPaused, CommandFlag::noSpend, CommandFlag::ghost, CommandFlag::trackDesign });
1606 GameActions::ExecuteNested(&trackRemoveAction, gameState);
1607 break;
1608 }
1609 case TrackPlaceOperation::placeQuery:
1610 case TrackPlaceOperation::place:
1611 case TrackPlaceOperation::placeGhost:
1612 case TrackPlaceOperation::placeTrackPreview:
1613 {
1614 const TrackCoordinates* trackCoordinates = &ted.coordinates;
1615
1616 // di
1617 int16_t tempZ = newCoords.z - trackCoordinates->zBegin;
1618

Callers 1

TrackDesignPlaceVirtualFunction · 0.85

Calls 15

clearSelectedTilesFunction · 0.85
TileElementHeightFunction · 0.85
TrackRemoveActionClass · 0.85
ExecuteNestedFunction · 0.85
TrackPlaceActionClass · 0.85
QueryNestedFunction · 0.85
MapIsLocationValidFunction · 0.85
MapGetSurfaceElementAtFunction · 0.85
SetFlagsMethod · 0.80

Tested by

no test coverage detected