0x004A43E4
| 4574 | |
| 4575 | // 0x004A43E4 |
| 4576 | static uint16_t getTrackProgressAtCursor(const Point& cursorLoc, Ui::Viewport& viewport, const TrackElement& trackElement, const World::Pos3& loc) |
| 4577 | { |
| 4578 | // Get the coordinates of the first tile of the possibly multi-tile track |
| 4579 | const auto& trackDataArr = World::TrackData::getTrackPiece(trackElement.trackId()); |
| 4580 | const auto& trackData = trackDataArr[trackElement.sequenceIndex()]; |
| 4581 | auto trackOffset2 = Math::Vector::rotate(World::Pos2(trackData.x, trackData.y), trackElement.rotation()); |
| 4582 | auto trackOffset = World::Pos3(trackOffset2.x, trackOffset2.y, trackData.z); |
| 4583 | auto trackFirstTile = loc - trackOffset; |
| 4584 | |
| 4585 | // Get the movement info for this specific track id |
| 4586 | uint16_t trackAndDirection = trackElement.rotation() | (trackElement.trackId() << 3); |
| 4587 | const auto moveInfoArr = World::TrackData::getTrackSubPositon(trackAndDirection); |
| 4588 | |
| 4589 | // This iterates the movement info trying to find the distance along the track that is as close as possible |
| 4590 | // to the cursors location. |
| 4591 | int32_t bestDistance = std::numeric_limits<int32_t>::max(); |
| 4592 | uint16_t bestProgress = 0; |
| 4593 | for (const auto& moveInfo : moveInfoArr) |
| 4594 | { |
| 4595 | auto potentialLoc = trackFirstTile + moveInfo.loc; |
| 4596 | auto viewPos = World::gameToScreen(potentialLoc, viewport.getRotation()); |
| 4597 | auto uiPos = viewport.viewportToScreen(viewPos); |
| 4598 | auto distance = Math::Vector::manhattanDistance2D(uiPos, cursorLoc); |
| 4599 | if (distance < bestDistance) |
| 4600 | { |
| 4601 | bestDistance = distance; |
| 4602 | bestProgress = std::distance(&*moveInfoArr.begin(), &moveInfo); |
| 4603 | } |
| 4604 | } |
| 4605 | return bestProgress; |
| 4606 | } |
| 4607 | |
| 4608 | // 0x004A40C5 |
| 4609 | static std::optional<GameCommands::VehiclePlacementArgs> getTrackAtCursor(const int16_t x, const int16_t y) |
no test coverage detected