MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / removeRoadModToTrack

Function removeRoadModToTrack

src/OpenLoco/src/Vehicles/Routing.cpp:1530–1664  ·  view source on GitHub ↗

0x0047A8F0

Source from the content-addressed store, hash-verified

1528
1529 // 0x0047A8F0
1530 static bool removeRoadModToTrack(const LocationOfInterest& interest, const uint8_t flags, RoutingResults* results, ModSection modSelection, uint8_t roadObjectId, uint8_t roadModObjectIds, currency32_t& totalCost, CompanyId companyId)
1531 {
1532 // If not in single segment mode then we should add the reverse
1533 // direction of track to the results to prevent it being visited.
1534 // This is because track mods do not have directions so applying
1535 // to the reverse would do nothing (or worse double spend)
1536 if (results != nullptr)
1537 {
1538 LocationOfInterest reverseInterest = interest;
1539 reverseInterest.loc = interest.loc;
1540 const auto rad = interest.rad();
1541 auto& roadSize = World::TrackData::getUnkRoad(rad._data);
1542 reverseInterest.loc += roadSize.pos;
1543 if (roadSize.rotationEnd < 12)
1544 {
1545 reverseInterest.loc -= World::Pos3{ World::kRotationOffset[roadSize.rotationEnd], 0 };
1546 }
1547 reverseInterest.trackAndDirection ^= (1 << 2); // Reverse flag
1548
1549 results->reachableLocs.tryAdd(reverseInterest);
1550 }
1551
1552 auto* roadObj = ObjectManager::get<RoadObject>(roadObjectId);
1553
1554 auto roadStart = interest.loc;
1555 const auto rad = interest.rad();
1556 if (rad.isReversed())
1557 {
1558 auto& roadSize = World::TrackData::getUnkRoad(rad._data);
1559 roadStart += roadSize.pos;
1560 if (roadSize.rotationEnd < 12)
1561 {
1562 roadStart -= World::Pos3{ World::kRotationOffset[roadSize.rotationEnd], 0 };
1563 }
1564 }
1565
1566 for (auto& roadPiece : TrackData::getRoadPiece(rad.id()))
1567 {
1568 auto roadLoc = roadStart + World::Pos3{ Math::Vector::rotate(World::Pos2{ roadPiece.x, roadPiece.y }, rad.cardinalDirection()), 0 };
1569 roadLoc.z += roadPiece.z;
1570
1571 auto tile = TileManager::get(roadLoc);
1572 World::RoadElement* elRoad = nullptr;
1573 for (auto& el : tile)
1574 {
1575 elRoad = el.as<World::RoadElement>();
1576 if (elRoad == nullptr)
1577 {
1578 continue;
1579 }
1580 if (elRoad->baseHeight() != roadLoc.z)
1581 {
1582 continue;
1583 }
1584 if (elRoad->rotation() != rad.cardinalDirection())
1585 {
1586 continue;
1587 }

Callers 1

Calls 15

getRoadPieceFunction · 0.85
getInflationAdjustedCostFunction · 0.85
getControllingIdFunction · 0.85
radMethod · 0.80
tryAddMethod · 0.80
baseHeightMethod · 0.80
roadObjectIdMethod · 0.80
roadIdMethod · 0.80
clearHeightMethod · 0.80
rotateFunction · 0.50
getFunction · 0.50
invalidateFunction · 0.50

Tested by

no test coverage detected