MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / ScreenPosToMapPos

Function ScreenPosToMapPos

src/openrct2/interface/Viewport.cpp:1019–1063  ·  view source on GitHub ↗

* * rct2: 0x0068958D */

Source from the content-addressed store, hash-verified

1017 * rct2: 0x0068958D
1018 */
1019 std::optional<CoordsXY> ScreenPosToMapPos(const ScreenCoordsXY& screenCoords, int32_t* direction)
1020 {
1021 auto mapCoords = ScreenGetMapXY(screenCoords, nullptr);
1022 if (!mapCoords.has_value())
1023 return std::nullopt;
1024
1025 int32_t my_direction;
1026 int32_t dist_from_centre_x = abs(mapCoords->x % 32);
1027 int32_t dist_from_centre_y = abs(mapCoords->y % 32);
1028 if (dist_from_centre_x > 8 && dist_from_centre_x < 24 && dist_from_centre_y > 8 && dist_from_centre_y < 24)
1029 {
1030 my_direction = 4;
1031 }
1032 else
1033 {
1034 auto mod_x = mapCoords->x & 0x1F;
1035 auto mod_y = mapCoords->y & 0x1F;
1036 if (mod_x <= 16)
1037 {
1038 if (mod_y < 16)
1039 {
1040 my_direction = 2;
1041 }
1042 else
1043 {
1044 my_direction = 3;
1045 }
1046 }
1047 else
1048 {
1049 if (mod_y < 16)
1050 {
1051 my_direction = 1;
1052 }
1053 else
1054 {
1055 my_direction = 0;
1056 }
1057 }
1058 }
1059
1060 if (direction != nullptr)
1061 *direction = my_direction;
1062 return { mapCoords->ToTileStart() };
1063 }
1064
1065 [[nodiscard]] bool Viewport::ContainsTile(const TileCoordsXY coords) const noexcept
1066 {

Callers 6

ToolUpdateLandMethod · 0.85
onToolUpdateMethod · 0.85
onToolDownMethod · 0.85
onToolDragMethod · 0.85
onToolUpdateMethod · 0.85
UpdateSelectedTileMethod · 0.85

Calls 2

ScreenGetMapXYFunction · 0.85
ToTileStartMethod · 0.45

Tested by 2

onToolUpdateMethod · 0.68
UpdateSelectedTileMethod · 0.68