mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-18 20:43:04 +01:00
@@ -1604,8 +1604,8 @@ void input_scroll_viewport(const ScreenCoordsXY& scrollScreenCoords)
|
||||
int32_t y = mainWindow->savedViewPos.y + viewport->view_height / 2;
|
||||
int32_t y_dy = mainWindow->savedViewPos.y + viewport->view_height / 2 + dy;
|
||||
|
||||
auto mapCoord = viewport_coord_to_map_coord(x, y, 0);
|
||||
auto mapCoord_dy = viewport_coord_to_map_coord(x, y_dy, 0);
|
||||
auto mapCoord = viewport_coord_to_map_coord({ x, y }, 0);
|
||||
auto mapCoord_dy = viewport_coord_to_map_coord({ x, y_dy }, 0);
|
||||
|
||||
// Check if we're crossing the boundary
|
||||
// Clamp to the map minimum value
|
||||
|
||||
@@ -694,7 +694,7 @@ CoordsXY sub_68A15E(const ScreenCoordsXY& screenCoords)
|
||||
{
|
||||
z = tile_element_height(mapPos);
|
||||
}
|
||||
mapPos = viewport_coord_to_map_coord(initialVPPos.x, initialVPPos.y, z);
|
||||
mapPos = viewport_coord_to_map_coord(initialVPPos, z);
|
||||
mapPos.x = std::clamp(mapPos.x, initialPos.x, initialPos.x + 31);
|
||||
mapPos.y = std::clamp(mapPos.y, initialPos.y, initialPos.y + 31);
|
||||
}
|
||||
|
||||
@@ -177,9 +177,8 @@ namespace OpenRCT2::Scripting
|
||||
auto viewport = GetViewport();
|
||||
if (viewport != nullptr)
|
||||
{
|
||||
auto centreX = viewport->viewPos.x + (viewport->view_width / 2);
|
||||
auto centreY = viewport->viewPos.y + (viewport->view_height / 2);
|
||||
auto coords = viewport_coord_to_map_coord(centreX, centreY, 24);
|
||||
auto centre = viewport->viewPos + ScreenCoordsXY{ viewport->view_width / 2, viewport->view_height / 2 };
|
||||
auto coords = viewport_coord_to_map_coord(centre, 24);
|
||||
|
||||
auto ctx = GetContext()->GetScriptEngine().GetContext();
|
||||
auto obj = duk_push_object(ctx);
|
||||
|
||||
@@ -215,7 +215,7 @@ CoordsXYZ viewport_adjust_for_map_height(const ScreenCoordsXY& startCoords)
|
||||
CoordsXY pos{};
|
||||
for (int32_t i = 0; i < 6; i++)
|
||||
{
|
||||
pos = viewport_coord_to_map_coord(startCoords.x, startCoords.y, height);
|
||||
pos = viewport_coord_to_map_coord(startCoords, height);
|
||||
height = tile_element_height(pos);
|
||||
|
||||
// HACK: This is to prevent the x and y values being set to values outside
|
||||
@@ -547,7 +547,7 @@ void viewport_update_position(rct_window* window)
|
||||
auto viewportMidPoint = ScreenCoordsXY{ static_cast<int16_t>(window->savedViewPos.x + viewport->view_width / 2),
|
||||
static_cast<int16_t>(window->savedViewPos.y + viewport->view_height / 2) };
|
||||
|
||||
auto mapCoord = viewport_coord_to_map_coord(viewportMidPoint.x, viewportMidPoint.y, 0);
|
||||
auto mapCoord = viewport_coord_to_map_coord(viewportMidPoint, 0);
|
||||
|
||||
// Clamp to the map minimum value
|
||||
int32_t at_map_edge = 0;
|
||||
@@ -1072,26 +1072,26 @@ ScreenCoordsXY screen_coord_to_viewport_coord(rct_viewport* viewport, const Scre
|
||||
return ret;
|
||||
}
|
||||
|
||||
CoordsXY viewport_coord_to_map_coord(int32_t x, int32_t y, int32_t z)
|
||||
CoordsXY viewport_coord_to_map_coord(const ScreenCoordsXY& coords, int32_t z)
|
||||
{
|
||||
CoordsXY ret{};
|
||||
switch (get_current_rotation())
|
||||
{
|
||||
case 0:
|
||||
ret.x = -x / 2 + y + z;
|
||||
ret.y = x / 2 + y + z;
|
||||
ret.x = -coords.x / 2 + coords.y + z;
|
||||
ret.y = coords.x / 2 + coords.y + z;
|
||||
break;
|
||||
case 1:
|
||||
ret.x = -x / 2 - y - z;
|
||||
ret.y = -x / 2 + y + z;
|
||||
ret.x = -coords.x / 2 - coords.y - z;
|
||||
ret.y = -coords.x / 2 + coords.y + z;
|
||||
break;
|
||||
case 2:
|
||||
ret.x = x / 2 - y - z;
|
||||
ret.y = -x / 2 - y - z;
|
||||
ret.x = coords.x / 2 - coords.y - z;
|
||||
ret.y = -coords.x / 2 - coords.y - z;
|
||||
break;
|
||||
case 3:
|
||||
ret.x = x / 2 + y + z;
|
||||
ret.y = x / 2 - y - z;
|
||||
ret.x = coords.x / 2 + coords.y + z;
|
||||
ret.y = coords.x / 2 - coords.y - z;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
@@ -1794,7 +1794,7 @@ std::optional<CoordsXY> screen_get_map_xy(const ScreenCoordsXY& screenCoords, rc
|
||||
for (int32_t i = 0; i < 5; i++)
|
||||
{
|
||||
int32_t z = tile_element_height(cursorMapPos);
|
||||
cursorMapPos = viewport_coord_to_map_coord(start_vp_pos.x, start_vp_pos.y, z);
|
||||
cursorMapPos = viewport_coord_to_map_coord(start_vp_pos, z);
|
||||
cursorMapPos.x = std::clamp(cursorMapPos.x, tileLoc.x, tileLoc.x + 31);
|
||||
cursorMapPos.y = std::clamp(cursorMapPos.y, tileLoc.y, tileLoc.y + 31);
|
||||
}
|
||||
@@ -1818,7 +1818,7 @@ std::optional<CoordsXY> screen_get_map_xy_with_z(const ScreenCoordsXY& screenCoo
|
||||
}
|
||||
|
||||
auto vpCoords = screen_coord_to_viewport_coord(viewport, screenCoords);
|
||||
auto mapPosition = viewport_coord_to_map_coord(vpCoords.x, vpCoords.y, z);
|
||||
auto mapPosition = viewport_coord_to_map_coord(vpCoords, z);
|
||||
if (!map_is_location_valid(mapPosition))
|
||||
{
|
||||
return std::nullopt;
|
||||
|
||||
@@ -148,7 +148,7 @@ void viewport_paint(
|
||||
CoordsXYZ viewport_adjust_for_map_height(const ScreenCoordsXY& startCoords);
|
||||
|
||||
ScreenCoordsXY screen_coord_to_viewport_coord(rct_viewport* viewport, const ScreenCoordsXY& screenCoords);
|
||||
CoordsXY viewport_coord_to_map_coord(int32_t x, int32_t y, int32_t z);
|
||||
CoordsXY viewport_coord_to_map_coord(const ScreenCoordsXY& coords, int32_t z);
|
||||
std::optional<CoordsXY> screen_pos_to_map_pos(const ScreenCoordsXY& screenCoords, int32_t* direction);
|
||||
|
||||
void show_gridlines();
|
||||
|
||||
@@ -288,7 +288,7 @@ CoordsXY footpath_get_coordinates_from_pos(const ScreenCoordsXY& screenCoords, i
|
||||
{
|
||||
z = tile_element_height(position);
|
||||
}
|
||||
position = viewport_coord_to_map_coord(start_vp_pos.x, start_vp_pos.y, z);
|
||||
position = viewport_coord_to_map_coord(start_vp_pos, z);
|
||||
position.x = std::clamp(position.x, minPosition.x, maxPosition.x);
|
||||
position.y = std::clamp(position.y, minPosition.y, maxPosition.y);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user