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

Function applyRoadModToRoad

src/OpenLoco/src/Vehicles/Routing.cpp:1344–1503  ·  view source on GitHub ↗

0x0047A5E6

Source from the content-addressed store, hash-verified

1342
1343 // 0x0047A5E6
1344 static bool applyRoadModToRoad(const LocationOfInterest& interest, const uint8_t flags, RoutingResults* results, ModSection modSelection, uint8_t roadObjectId, uint8_t roadModObjectIds, currency32_t& totalCost, CompanyId companyId, bool& hasFailedAllPlacement)
1345 {
1346 // If not in single segment mode then we should add the reverse
1347 // direction of track to the results to prevent it being visited.
1348 // This is because track mods do not have directions so applying
1349 // to the reverse would do nothing (or worse double spend)
1350 if (results != nullptr)
1351 {
1352 LocationOfInterest reverseInterest = interest;
1353 reverseInterest.loc = interest.loc;
1354 const auto rad = interest.rad();
1355 auto& roadSize = World::TrackData::getUnkRoad(rad._data);
1356 reverseInterest.loc += roadSize.pos;
1357 if (roadSize.rotationEnd < 12)
1358 {
1359 reverseInterest.loc -= World::Pos3{ World::kRotationOffset[roadSize.rotationEnd], 0 };
1360 }
1361 reverseInterest.trackAndDirection ^= (1 << 2); // Reverse flag
1362
1363 results->reachableLocs.tryAdd(reverseInterest);
1364 }
1365
1366 auto* roadObj = ObjectManager::get<RoadObject>(roadObjectId);
1367 bool placementFailure = false;
1368
1369 for (auto i = 0; i < 2; ++i)
1370 {
1371 if (!(roadModObjectIds & (1U << i)))
1372 {
1373 continue;
1374 }
1375
1376 auto* roadModObj = ObjectManager::get<RoadExtraObject>(roadObj->mods[i]);
1377
1378 const auto pieceFlags = TrackData::getRoadMiscData(interest.rad().id()).compatibleFlags;
1379 if ((roadModObj->roadPieces & pieceFlags) != pieceFlags)
1380 {
1381 //_1135F64 |= (1 << 0); placement failed at least once
1382 placementFailure = true;
1383 break;
1384 }
1385 }
1386
1387 if (!placementFailure)
1388 {
1389 auto roadStart = interest.loc;
1390 const auto rad = interest.rad();
1391 if (rad.isReversed())
1392 {
1393 auto& roadSize = World::TrackData::getUnkRoad(rad._data);
1394 roadStart += roadSize.pos;
1395 if (roadSize.rotationEnd < 12)
1396 {
1397 roadStart -= World::Pos3{ World::kRotationOffset[roadSize.rotationEnd], 0 };
1398 }
1399 }
1400
1401 for (auto& roadPiece : TrackData::getRoadPiece(rad.id()))

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