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

Function TrackDesignPlaceEntrances

src/openrct2/ride/TrackDesign.cpp:1325–1432  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1323}
1324
1325static std::optional<GameActions::Result> TrackDesignPlaceEntrances(
1326 TrackDesignState& tds, const TrackDesign& td, CoordsXYZ newCoords, RideId rideId, money64& totalCost)
1327{
1328 for (const auto& entrance : td.entranceElements)
1329 {
1330 auto rotation = _currentTrackPieceDirection & 3;
1331 CoordsXY entranceMapPos = entrance.location.ToCoordsXY();
1332 auto rotatedEntranceMapPos = entranceMapPos.Rotate(rotation);
1333 newCoords = { rotatedEntranceMapPos + tds.origin, newCoords.z };
1334
1335 TrackDesignUpdatePreviewBounds(tds, newCoords);
1336
1337 auto& gameState = getGameState();
1338
1339 switch (tds.placeOperation)
1340 {
1341 case TrackPlaceOperation::drawOutlines:
1342 TrackDesignAddSelectedTile(newCoords);
1343 break;
1344 case TrackPlaceOperation::placeQuery:
1345 case TrackPlaceOperation::place:
1346 case TrackPlaceOperation::placeGhost:
1347 case TrackPlaceOperation::placeTrackPreview:
1348 {
1349 rotation = (rotation + entrance.location.direction) & 3;
1350 newCoords.z = entrance.location.z * kCoordsZStep;
1351 newCoords.z += tds.origin.z;
1352
1353 if (tds.placeOperation != TrackPlaceOperation::placeQuery)
1354 {
1355 auto tile = CoordsXY{ newCoords } + CoordsDirectionDelta[rotation];
1356 TileElement* tile_element = MapGetFirstElementAt(tile);
1357 if (tile_element == nullptr)
1358 {
1359 return GameActions::Result(
1360 GameActions::Status::invalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_TILE_ELEMENT_NOT_FOUND);
1361 }
1362
1363 do
1364 {
1365 if (tile_element->getType() != TileElementType::Track)
1366 {
1367 continue;
1368 }
1369 if (tile_element->getBaseZ() != newCoords.z)
1370 {
1371 continue;
1372 }
1373
1374 auto stationIndex = tile_element->asTrack()->GetStationIndex();
1375 CommandFlags flags = { CommandFlag::apply };
1376 if (tds.placeOperation == TrackPlaceOperation::placeTrackPreview)
1377 {
1378 flags = { CommandFlag::apply, CommandFlag::allowDuringPaused, CommandFlag::noSpend };
1379 }
1380 if (tds.placeOperation == TrackPlaceOperation::placeGhost)
1381 {
1382 flags = { CommandFlag::apply, CommandFlag::allowDuringPaused, CommandFlag::noSpend,

Callers 2

TrackDesignPlaceMazeFunction · 0.85
TrackDesignPlaceRideFunction · 0.85

Calls 15

MapGetFirstElementAtFunction · 0.85
ExecuteNestedFunction · 0.85
QueryNestedFunction · 0.85
ToCoordsXYMethod · 0.80
SetFlagsMethod · 0.80
setMethod · 0.65
hasMethod · 0.65
ResultClass · 0.50
RotateMethod · 0.45

Tested by

no test coverage detected