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

Method updateRoadTileOccupancy

src/OpenLoco/src/Vehicles/Vehicle.cpp:577–634  ·  view source on GitHub ↗

0x0047D959 ax : loc.x cx : loc.y dl : loc.z / 4 bp : trackAndDirection ebp : bp | (setOccupied << 31) returns dh : trackType

Source from the content-addressed store, hash-verified

575 // ebp : bp | (setOccupied << 31)
576 // returns dh : trackType
577 uint8_t VehicleBase::updateRoadTileOccupancy(const World::Pos3& loc, const TrackAndDirection::_RoadAndDirection rad, const bool setOccupied)
578 {
579 auto roadType = getTrackType();
580 auto tile = World::TileManager::get(loc);
581 for (auto& el : tile)
582 {
583 auto* elRoad = el.as<World::RoadElement>();
584 if (elRoad == nullptr)
585 {
586 continue;
587 }
588
589 const auto heightDiff = std::abs(loc.z / 4 - elRoad->baseZ());
590 if (heightDiff > 4)
591 {
592 continue;
593 }
594
595 if (elRoad->rotation() != rad.cardinalDirection())
596 {
597 continue;
598 }
599
600 if (elRoad->roadId() != rad.id())
601 {
602 continue;
603 }
604
605 if (elRoad->isAiAllocated())
606 {
607 continue;
608 }
609
610 const auto newLaneOccupation = World::TrackData::getRoadOccupationMask(rad._data >> 2) >> 4;
611 if (setOccupied)
612 {
613 elRoad->setLaneOccupation(elRoad->laneOccupation() | newLaneOccupation);
614 }
615 else
616 {
617 elRoad->setLaneOccupation(elRoad->laneOccupation() & (~newLaneOccupation));
618 }
619
620 if (getTrackType() == 0xFF)
621 {
622 if (getGameState().roadObjectIdIsAnyRoadTypeCompatible & (1 << elRoad->roadObjectId()))
623 {
624 elRoad->setUnk7_40(true);
625 roadType = elRoad->roadObjectId();
626 }
627 }
628 else
629 {
630 roadType = getTrackType();
631 }
632 }
633 return roadType;
634 }

Callers 4

sub_4AD778Method · 0.80
liftUpTailFunction · 0.80

Calls 12

getRoadOccupationMaskFunction · 0.85
baseZMethod · 0.80
roadIdMethod · 0.80
isAiAllocatedMethod · 0.80
setLaneOccupationMethod · 0.80
laneOccupationMethod · 0.80
roadObjectIdMethod · 0.80
setUnk7_40Method · 0.80
getFunction · 0.50
rotationMethod · 0.45
cardinalDirectionMethod · 0.45
idMethod · 0.45

Tested by

no test coverage detected