0x004A43E4
| 4474 | |
| 4475 | // 0x004A43E4 |
| 4476 | static uint16_t getRoadProgressAtCursor(const Point& cursorLoc, Ui::Viewport& viewport, const RoadElement& roadElement, const World::Pos3& loc) |
| 4477 | { |
| 4478 | // Get the coordinates of the first tile of the possibly multi-tile road |
| 4479 | const auto& roadDataArr = World::TrackData::getRoadPiece(roadElement.roadId()); |
| 4480 | const auto& roadData = roadDataArr[roadElement.sequenceIndex()]; |
| 4481 | auto roadOffset2 = Math::Vector::rotate(World::Pos2(roadData.x, roadData.y), roadElement.rotation()); |
| 4482 | auto roadOffset = World::Pos3(roadOffset2.x, roadOffset2.y, roadData.z); |
| 4483 | auto roadFirstTile = loc - roadOffset; |
| 4484 | |
| 4485 | // Get the movement info for this specific road id |
| 4486 | uint16_t trackAndDirection = roadElement.rotation() | (roadElement.roadId() << 3); |
| 4487 | const auto moveInfoArr = World::TrackData::getRoadPlacementSubPositon(trackAndDirection); |
| 4488 | |
| 4489 | // This iterates the movement info trying to find the distance along the road that is as close as possible |
| 4490 | // to the cursors location. |
| 4491 | int32_t bestDistance = std::numeric_limits<int32_t>::max(); |
| 4492 | uint16_t bestProgress = 0; |
| 4493 | for (const auto& moveInfo : moveInfoArr) |
| 4494 | { |
| 4495 | auto potentialLoc = roadFirstTile + moveInfo.loc; |
| 4496 | auto viewPos = World::gameToScreen(potentialLoc, viewport.getRotation()); |
| 4497 | auto uiPos = viewport.viewportToScreen(viewPos); |
| 4498 | auto distance = Math::Vector::manhattanDistance2D(uiPos, cursorLoc); |
| 4499 | if (distance < bestDistance) |
| 4500 | { |
| 4501 | bestDistance = distance; |
| 4502 | bestProgress = std::distance(&*moveInfoArr.begin(), &moveInfo); |
| 4503 | } |
| 4504 | } |
| 4505 | return bestProgress; |
| 4506 | } |
| 4507 | |
| 4508 | // 0x00478415 |
| 4509 | static std::optional<GameCommands::VehiclePlacementArgs> getRoadAtCursor(const int16_t x, const int16_t y) |
no test coverage detected