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

Function updateAndTakeoverRoad

src/OpenLoco/src/World/Town.cpp:802–862  ·  view source on GitHub ↗

0x0047AD83 pos : ax, cx, dx tad : ebp newRoadObjId : bh newOwner : bl newStreetLightStyle : ebx >> 16

Source from the content-addressed store, hash-verified

800 // newOwner : bl
801 // newStreetLightStyle : ebx >> 16
802 static void updateAndTakeoverRoad(const World::Pos3 pos, const Vehicles::TrackAndDirection::_RoadAndDirection tad, const uint8_t newRoadObjId, const CompanyId newOwner, const uint8_t newStreetLightStyle)
803 {
804 auto* newRoadObj = ObjectManager::get<RoadObject>(newRoadObjId);
805 const auto roadPiecesFlags = World::TrackData::getRoadMiscData(tad.id()).compatibleFlags;
806 if ((roadPiecesFlags & newRoadObj->roadPieces) != roadPiecesFlags)
807 {
808 return;
809 }
810
811 const auto roadStart = [tad, &pos]() {
812 if (tad.isReversed())
813 {
814 auto& roadSize = World::TrackData::getUnkRoad(tad._data);
815 auto roadStart = pos + roadSize.pos;
816 if (roadSize.rotationEnd < 12)
817 {
818 roadStart -= World::Pos3{ kRotationOffset[roadSize.rotationEnd], 0 };
819 }
820 return roadStart;
821 }
822 else
823 {
824 return pos;
825 };
826 }();
827 const auto pieces = World::TrackData::getRoadPiece(tad.id());
828 for (auto& piece : pieces)
829 {
830 const auto roadPos = roadStart + World::Pos3{ Math::Vector::rotate(World::Pos2{ piece.x, piece.y }, tad.cardinalDirection()), piece.z };
831
832 auto tile = World::TileManager::get(roadPos);
833 for (auto& el : tile)
834 {
835 auto* elRoad = el.as<World::RoadElement>();
836 if (elRoad == nullptr)
837 {
838 continue;
839 }
840 if (elRoad->baseHeight() != roadPos.z)
841 {
842 continue;
843 }
844 if (elRoad->isGhost() || elRoad->isAiAllocated())
845 {
846 continue;
847 }
848 auto* roadObj = ObjectManager::get<RoadObject>(elRoad->roadObjectId());
849 if (!roadObj->hasFlags(RoadObjectFlags::anyRoadTypeCompatible))
850 {
851 continue;
852 }
853 elRoad->setOwner(newOwner);
854 elRoad->setRoadObjectId(newRoadObjId);
855 if (!elRoad->hasLevelCrossing())
856 {
857 elRoad->setStreetLightStyle(newStreetLightStyle);
858 }
859 Ui::ViewportManager::invalidate(roadPos, elRoad->baseHeight(), elRoad->clearHeight(), ZoomLevel::half);

Callers 1

growMethod · 0.85

Calls 15

getRoadPieceFunction · 0.85
baseHeightMethod · 0.80
isAiAllocatedMethod · 0.80
roadObjectIdMethod · 0.80
setRoadObjectIdMethod · 0.80
setStreetLightStyleMethod · 0.80
clearHeightMethod · 0.80
getFunction · 0.70
rotateFunction · 0.50
invalidateFunction · 0.50
idMethod · 0.45
isReversedMethod · 0.45

Tested by

no test coverage detected