0x0047AD83 pos : ax, cx, dx tad : ebp newRoadObjId : bh newOwner : bl newStreetLightStyle : ebx >> 16
| 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); |
no test coverage detected