mirror of https://github.com/OpenRCT2/OpenRCT2.git
Prefer std::optional over LOCATION_NULL on Viewport (#10297)
This commit is contained in:
parent
7e96ddf1d6
commit
4537c061d9
|
@ -295,9 +295,9 @@ static void window_land_rights_tool_update_land_rights(ScreenCoordsXY screenCoor
|
||||||
map_invalidate_selection_rect();
|
map_invalidate_selection_rect();
|
||||||
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE;
|
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE;
|
||||||
|
|
||||||
CoordsXY mapTile = screen_get_map_xy(screenCoords, nullptr);
|
auto mapTile = screen_get_map_xy(screenCoords, nullptr);
|
||||||
|
|
||||||
if (mapTile.x == LOCATION_NULL)
|
if (!mapTile)
|
||||||
{
|
{
|
||||||
if (_landRightsCost != MONEY32_UNDEFINED)
|
if (_landRightsCost != MONEY32_UNDEFINED)
|
||||||
{
|
{
|
||||||
|
@ -328,35 +328,35 @@ static void window_land_rights_tool_update_land_rights(ScreenCoordsXY screenCoor
|
||||||
int16_t tool_length = (tool_size - 1) * 32;
|
int16_t tool_length = (tool_size - 1) * 32;
|
||||||
|
|
||||||
// Move to tool bottom left
|
// Move to tool bottom left
|
||||||
mapTile.x -= (tool_size - 1) * 16;
|
mapTile->x -= (tool_size - 1) * 16;
|
||||||
mapTile.y -= (tool_size - 1) * 16;
|
mapTile->y -= (tool_size - 1) * 16;
|
||||||
mapTile.x &= 0xFFE0;
|
mapTile->x &= 0xFFE0;
|
||||||
mapTile.y &= 0xFFE0;
|
mapTile->y &= 0xFFE0;
|
||||||
|
|
||||||
if (gMapSelectPositionA.x != mapTile.x)
|
if (gMapSelectPositionA.x != mapTile->x)
|
||||||
{
|
{
|
||||||
gMapSelectPositionA.x = mapTile.x;
|
gMapSelectPositionA.x = mapTile->x;
|
||||||
state_changed++;
|
state_changed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gMapSelectPositionA.y != mapTile.y)
|
if (gMapSelectPositionA.y != mapTile->y)
|
||||||
{
|
{
|
||||||
gMapSelectPositionA.y = mapTile.y;
|
gMapSelectPositionA.y = mapTile->y;
|
||||||
state_changed++;
|
state_changed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
mapTile.x += tool_length;
|
mapTile->x += tool_length;
|
||||||
mapTile.y += tool_length;
|
mapTile->y += tool_length;
|
||||||
|
|
||||||
if (gMapSelectPositionB.x != mapTile.x)
|
if (gMapSelectPositionB.x != mapTile->x)
|
||||||
{
|
{
|
||||||
gMapSelectPositionB.x = mapTile.x;
|
gMapSelectPositionB.x = mapTile->x;
|
||||||
state_changed++;
|
state_changed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gMapSelectPositionB.y != mapTile.y)
|
if (gMapSelectPositionB.y != mapTile->y)
|
||||||
{
|
{
|
||||||
gMapSelectPositionB.y = mapTile.y;
|
gMapSelectPositionB.y = mapTile->y;
|
||||||
state_changed++;
|
state_changed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1162,8 +1162,8 @@ static void window_map_set_land_rights_tool_update(ScreenCoordsXY screenCoords)
|
||||||
|
|
||||||
map_invalidate_selection_rect();
|
map_invalidate_selection_rect();
|
||||||
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE;
|
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE;
|
||||||
CoordsXY mapCoords = screen_get_map_xy(screenCoords, &viewport);
|
auto mapCoords = screen_get_map_xy(screenCoords, &viewport);
|
||||||
if (mapCoords.x == LOCATION_NULL)
|
if (!mapCoords)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE;
|
gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE;
|
||||||
|
@ -1175,12 +1175,12 @@ static void window_map_set_land_rights_tool_update(ScreenCoordsXY screenCoords)
|
||||||
|
|
||||||
int32_t size = (landRightsToolSize * 32) - 32;
|
int32_t size = (landRightsToolSize * 32) - 32;
|
||||||
int32_t radius = (landRightsToolSize * 16) - 16;
|
int32_t radius = (landRightsToolSize * 16) - 16;
|
||||||
mapCoords.x = (mapCoords.x - radius) & 0xFFE0;
|
mapCoords->x = (mapCoords->x - radius) & 0xFFE0;
|
||||||
mapCoords.y = (mapCoords.y - radius) & 0xFFE0;
|
mapCoords->y = (mapCoords->y - radius) & 0xFFE0;
|
||||||
gMapSelectPositionA.x = mapCoords.x;
|
gMapSelectPositionA.x = mapCoords->x;
|
||||||
gMapSelectPositionA.y = mapCoords.y;
|
gMapSelectPositionA.y = mapCoords->y;
|
||||||
gMapSelectPositionB.x = mapCoords.x + size;
|
gMapSelectPositionB.x = mapCoords->x + size;
|
||||||
gMapSelectPositionB.y = mapCoords.y + size;
|
gMapSelectPositionB.y = mapCoords->y + size;
|
||||||
map_invalidate_selection_rect();
|
map_invalidate_selection_rect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2192,7 +2192,15 @@ static std::optional<CoordsXY> ride_get_place_position_from_screen_position(Scre
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto mapZ = _trackPlaceCtrlZ;
|
auto mapZ = _trackPlaceCtrlZ;
|
||||||
mapCoords = screen_get_map_xy_with_z(screenCoords, mapZ);
|
auto mapXYCoords = screen_get_map_xy_with_z(screenCoords, mapZ);
|
||||||
|
if (mapXYCoords)
|
||||||
|
{
|
||||||
|
mapCoords = *mapXYCoords;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
if (_trackPlaceShiftState != 0)
|
if (_trackPlaceShiftState != 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1346,12 +1346,14 @@ static void sub_6E1F34(
|
||||||
// If CTRL not pressed
|
// If CTRL not pressed
|
||||||
if (!gSceneryCtrlPressed)
|
if (!gSceneryCtrlPressed)
|
||||||
{
|
{
|
||||||
CoordsXY gridCoords = screen_get_map_xy_quadrant({ x, y }, &cl);
|
auto gridCoords = screen_get_map_xy_quadrant({ x, y }, &cl);
|
||||||
*grid_x = gridCoords.x;
|
if (!gridCoords)
|
||||||
*grid_y = gridCoords.y;
|
{
|
||||||
|
*grid_x = LOCATION_NULL;
|
||||||
if (*grid_x == LOCATION_NULL)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
*grid_x = gridCoords->x;
|
||||||
|
*grid_y = gridCoords->y;
|
||||||
|
|
||||||
gSceneryPlaceZ = 0;
|
gSceneryPlaceZ = 0;
|
||||||
|
|
||||||
|
@ -1467,8 +1469,15 @@ static void sub_6E1F34(
|
||||||
{
|
{
|
||||||
int16_t z = gSceneryCtrlPressZ;
|
int16_t z = gSceneryCtrlPressZ;
|
||||||
auto coords = screen_get_map_xy_with_z({ x, y }, z);
|
auto coords = screen_get_map_xy_with_z({ x, y }, z);
|
||||||
*grid_x = coords.x;
|
if (coords)
|
||||||
*grid_y = coords.y;
|
{
|
||||||
|
*grid_x = coords->x;
|
||||||
|
*grid_y = coords->y;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*grid_x = LOCATION_NULL;
|
||||||
|
}
|
||||||
// If SHIFT pressed
|
// If SHIFT pressed
|
||||||
if (gSceneryShiftPressed)
|
if (gSceneryShiftPressed)
|
||||||
{
|
{
|
||||||
|
@ -1538,12 +1547,14 @@ static void sub_6E1F34(
|
||||||
// If CTRL not pressed
|
// If CTRL not pressed
|
||||||
if (!gSceneryCtrlPressed)
|
if (!gSceneryCtrlPressed)
|
||||||
{
|
{
|
||||||
CoordsXY gridCoords = screen_get_map_xy_side({ x, y }, &cl);
|
auto gridCoords = screen_get_map_xy_side({ x, y }, &cl);
|
||||||
*grid_x = gridCoords.x;
|
if (!gridCoords)
|
||||||
*grid_y = gridCoords.y;
|
{
|
||||||
|
*grid_x = LOCATION_NULL;
|
||||||
if (*grid_x == LOCATION_NULL)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
*grid_x = gridCoords->x;
|
||||||
|
*grid_y = gridCoords->y;
|
||||||
|
|
||||||
gSceneryPlaceZ = 0;
|
gSceneryPlaceZ = 0;
|
||||||
|
|
||||||
|
@ -1638,8 +1649,15 @@ static void sub_6E1F34(
|
||||||
{
|
{
|
||||||
int16_t z = gSceneryCtrlPressZ;
|
int16_t z = gSceneryCtrlPressZ;
|
||||||
auto coords = screen_get_map_xy_with_z({ x, y }, z);
|
auto coords = screen_get_map_xy_with_z({ x, y }, z);
|
||||||
*grid_x = coords.x;
|
if (coords)
|
||||||
*grid_y = coords.y;
|
{
|
||||||
|
*grid_x = coords->x;
|
||||||
|
*grid_y = coords->y;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*grid_x = LOCATION_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// If SHIFT pressed
|
// If SHIFT pressed
|
||||||
if (gSceneryShiftPressed)
|
if (gSceneryShiftPressed)
|
||||||
|
@ -2000,9 +2018,9 @@ static uint8_t top_toolbar_tool_update_land_paint(int16_t x, int16_t y)
|
||||||
map_invalidate_selection_rect();
|
map_invalidate_selection_rect();
|
||||||
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE;
|
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE;
|
||||||
|
|
||||||
CoordsXY mapTile = screen_get_map_xy({ x, y }, nullptr);
|
auto mapTile = screen_get_map_xy({ x, y }, nullptr);
|
||||||
|
|
||||||
if (mapTile.x == LOCATION_NULL)
|
if (!mapTile)
|
||||||
{
|
{
|
||||||
if (gClearSceneryCost != MONEY32_UNDEFINED)
|
if (gClearSceneryCost != MONEY32_UNDEFINED)
|
||||||
{
|
{
|
||||||
|
@ -2028,35 +2046,35 @@ static uint8_t top_toolbar_tool_update_land_paint(int16_t x, int16_t y)
|
||||||
int16_t tool_length = (tool_size - 1) * 32;
|
int16_t tool_length = (tool_size - 1) * 32;
|
||||||
|
|
||||||
// Move to tool bottom left
|
// Move to tool bottom left
|
||||||
mapTile.x -= (tool_size - 1) * 16;
|
mapTile->x -= (tool_size - 1) * 16;
|
||||||
mapTile.y -= (tool_size - 1) * 16;
|
mapTile->y -= (tool_size - 1) * 16;
|
||||||
mapTile.x &= 0xFFE0;
|
mapTile->x &= 0xFFE0;
|
||||||
mapTile.y &= 0xFFE0;
|
mapTile->y &= 0xFFE0;
|
||||||
|
|
||||||
if (gMapSelectPositionA.x != mapTile.x)
|
if (gMapSelectPositionA.x != mapTile->x)
|
||||||
{
|
{
|
||||||
gMapSelectPositionA.x = mapTile.x;
|
gMapSelectPositionA.x = mapTile->x;
|
||||||
state_changed++;
|
state_changed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gMapSelectPositionA.y != mapTile.y)
|
if (gMapSelectPositionA.y != mapTile->y)
|
||||||
{
|
{
|
||||||
gMapSelectPositionA.y = mapTile.y;
|
gMapSelectPositionA.y = mapTile->y;
|
||||||
state_changed++;
|
state_changed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
mapTile.x += tool_length;
|
mapTile->x += tool_length;
|
||||||
mapTile.y += tool_length;
|
mapTile->y += tool_length;
|
||||||
|
|
||||||
if (gMapSelectPositionB.x != mapTile.x)
|
if (gMapSelectPositionB.x != mapTile->x)
|
||||||
{
|
{
|
||||||
gMapSelectPositionB.x = mapTile.x;
|
gMapSelectPositionB.x = mapTile->x;
|
||||||
state_changed++;
|
state_changed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gMapSelectPositionB.y != mapTile.y)
|
if (gMapSelectPositionB.y != mapTile->y)
|
||||||
{
|
{
|
||||||
gMapSelectPositionB.y = mapTile.y;
|
gMapSelectPositionB.y = mapTile->y;
|
||||||
state_changed++;
|
state_changed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2111,7 +2129,7 @@ static void top_toolbar_tool_update_land(int16_t x, int16_t y)
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t tool_size = gLandToolSize;
|
int16_t tool_size = gLandToolSize;
|
||||||
CoordsXY mapTile;
|
std::optional<CoordsXY> mapTile;
|
||||||
uint8_t side;
|
uint8_t side;
|
||||||
|
|
||||||
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE;
|
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE;
|
||||||
|
@ -2122,7 +2140,7 @@ static void top_toolbar_tool_update_land(int16_t x, int16_t y)
|
||||||
screen_pos_to_map_pos({ x, y }, &selectionType);
|
screen_pos_to_map_pos({ x, y }, &selectionType);
|
||||||
mapTile = screen_get_map_xy_side({ x, y }, &side);
|
mapTile = screen_get_map_xy_side({ x, y }, &side);
|
||||||
|
|
||||||
if (mapTile.x == LOCATION_NULL)
|
if (!mapTile)
|
||||||
{
|
{
|
||||||
money32 lower_cost = MONEY32_UNDEFINED;
|
money32 lower_cost = MONEY32_UNDEFINED;
|
||||||
money32 raise_cost = MONEY32_UNDEFINED;
|
money32 raise_cost = MONEY32_UNDEFINED;
|
||||||
|
@ -2156,27 +2174,27 @@ static void top_toolbar_tool_update_land(int16_t x, int16_t y)
|
||||||
state_changed++;
|
state_changed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gMapSelectPositionA.x != mapTile.x)
|
if (gMapSelectPositionA.x != mapTile->x)
|
||||||
{
|
{
|
||||||
gMapSelectPositionA.x = mapTile.x;
|
gMapSelectPositionA.x = mapTile->x;
|
||||||
state_changed++;
|
state_changed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gMapSelectPositionA.y != mapTile.y)
|
if (gMapSelectPositionA.y != mapTile->y)
|
||||||
{
|
{
|
||||||
gMapSelectPositionA.y = mapTile.y;
|
gMapSelectPositionA.y = mapTile->y;
|
||||||
state_changed++;
|
state_changed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gMapSelectPositionB.x != mapTile.x)
|
if (gMapSelectPositionB.x != mapTile->x)
|
||||||
{
|
{
|
||||||
gMapSelectPositionB.x = mapTile.x;
|
gMapSelectPositionB.x = mapTile->x;
|
||||||
state_changed++;
|
state_changed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gMapSelectPositionB.y != mapTile.y)
|
if (gMapSelectPositionB.y != mapTile->y)
|
||||||
{
|
{
|
||||||
gMapSelectPositionB.y = mapTile.y;
|
gMapSelectPositionB.y = mapTile->y;
|
||||||
state_changed++;
|
state_changed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2199,7 +2217,7 @@ static void top_toolbar_tool_update_land(int16_t x, int16_t y)
|
||||||
// Get map coordinates and the side of the tile that is being hovered over
|
// Get map coordinates and the side of the tile that is being hovered over
|
||||||
mapTile = screen_get_map_xy_side({ x, y }, &side);
|
mapTile = screen_get_map_xy_side({ x, y }, &side);
|
||||||
|
|
||||||
if (mapTile.x == LOCATION_NULL)
|
if (!mapTile)
|
||||||
{
|
{
|
||||||
money32 lower_cost = MONEY32_UNDEFINED;
|
money32 lower_cost = MONEY32_UNDEFINED;
|
||||||
money32 raise_cost = MONEY32_UNDEFINED;
|
money32 raise_cost = MONEY32_UNDEFINED;
|
||||||
|
@ -2244,33 +2262,33 @@ static void top_toolbar_tool_update_land(int16_t x, int16_t y)
|
||||||
case MAP_SELECT_TYPE_EDGE_0:
|
case MAP_SELECT_TYPE_EDGE_0:
|
||||||
case MAP_SELECT_TYPE_EDGE_2:
|
case MAP_SELECT_TYPE_EDGE_2:
|
||||||
// Line
|
// Line
|
||||||
mapTile.y -= (tool_size - 1) * 16;
|
mapTile->y -= (tool_size - 1) * 16;
|
||||||
mapTile.y &= 0xFFE0;
|
mapTile->y &= 0xFFE0;
|
||||||
break;
|
break;
|
||||||
case MAP_SELECT_TYPE_EDGE_1:
|
case MAP_SELECT_TYPE_EDGE_1:
|
||||||
case MAP_SELECT_TYPE_EDGE_3:
|
case MAP_SELECT_TYPE_EDGE_3:
|
||||||
// Line
|
// Line
|
||||||
mapTile.x -= (tool_size - 1) * 16;
|
mapTile->x -= (tool_size - 1) * 16;
|
||||||
mapTile.x &= 0xFFE0;
|
mapTile->x &= 0xFFE0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// Move to tool bottom left
|
// Move to tool bottom left
|
||||||
mapTile.x -= (tool_size - 1) * 16;
|
mapTile->x -= (tool_size - 1) * 16;
|
||||||
mapTile.y -= (tool_size - 1) * 16;
|
mapTile->y -= (tool_size - 1) * 16;
|
||||||
mapTile.x &= 0xFFE0;
|
mapTile->x &= 0xFFE0;
|
||||||
mapTile.y &= 0xFFE0;
|
mapTile->y &= 0xFFE0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gMapSelectPositionA.x != mapTile.x)
|
if (gMapSelectPositionA.x != mapTile->x)
|
||||||
{
|
{
|
||||||
gMapSelectPositionA.x = mapTile.x;
|
gMapSelectPositionA.x = mapTile->x;
|
||||||
state_changed++;
|
state_changed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gMapSelectPositionA.y != mapTile.y)
|
if (gMapSelectPositionA.y != mapTile->y)
|
||||||
{
|
{
|
||||||
gMapSelectPositionA.y = mapTile.y;
|
gMapSelectPositionA.y = mapTile->y;
|
||||||
state_changed++;
|
state_changed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2280,30 +2298,30 @@ static void top_toolbar_tool_update_land(int16_t x, int16_t y)
|
||||||
case MAP_SELECT_TYPE_EDGE_0:
|
case MAP_SELECT_TYPE_EDGE_0:
|
||||||
case MAP_SELECT_TYPE_EDGE_2:
|
case MAP_SELECT_TYPE_EDGE_2:
|
||||||
// Line
|
// Line
|
||||||
mapTile.y += tool_length;
|
mapTile->y += tool_length;
|
||||||
gMapSelectType = MAP_SELECT_TYPE_FULL;
|
gMapSelectType = MAP_SELECT_TYPE_FULL;
|
||||||
break;
|
break;
|
||||||
case MAP_SELECT_TYPE_EDGE_1:
|
case MAP_SELECT_TYPE_EDGE_1:
|
||||||
case MAP_SELECT_TYPE_EDGE_3:
|
case MAP_SELECT_TYPE_EDGE_3:
|
||||||
// Line
|
// Line
|
||||||
mapTile.x += tool_length;
|
mapTile->x += tool_length;
|
||||||
gMapSelectType = MAP_SELECT_TYPE_FULL;
|
gMapSelectType = MAP_SELECT_TYPE_FULL;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
mapTile.x += tool_length;
|
mapTile->x += tool_length;
|
||||||
mapTile.y += tool_length;
|
mapTile->y += tool_length;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gMapSelectPositionB.x != mapTile.x)
|
if (gMapSelectPositionB.x != mapTile->x)
|
||||||
{
|
{
|
||||||
gMapSelectPositionB.x = mapTile.x;
|
gMapSelectPositionB.x = mapTile->x;
|
||||||
state_changed++;
|
state_changed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gMapSelectPositionB.y != mapTile.y)
|
if (gMapSelectPositionB.y != mapTile->y)
|
||||||
{
|
{
|
||||||
gMapSelectPositionB.y = mapTile.y;
|
gMapSelectPositionB.y = mapTile->y;
|
||||||
state_changed++;
|
state_changed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -998,21 +998,21 @@ static void viewport_paint_weather_gloom(rct_drawpixelinfo* dpi)
|
||||||
*/
|
*/
|
||||||
CoordsXY screen_pos_to_map_pos(ScreenCoordsXY screenCoords, int32_t* direction)
|
CoordsXY screen_pos_to_map_pos(ScreenCoordsXY screenCoords, int32_t* direction)
|
||||||
{
|
{
|
||||||
CoordsXY mapCoords = screen_get_map_xy(screenCoords, nullptr);
|
auto mapCoords = screen_get_map_xy(screenCoords, nullptr);
|
||||||
if (mapCoords.x == LOCATION_NULL)
|
if (!mapCoords)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
int32_t my_direction;
|
int32_t my_direction;
|
||||||
int32_t dist_from_centre_x = abs(mapCoords.x % 32);
|
int32_t dist_from_centre_x = abs(mapCoords->x % 32);
|
||||||
int32_t dist_from_centre_y = abs(mapCoords.y % 32);
|
int32_t dist_from_centre_y = abs(mapCoords->y % 32);
|
||||||
if (dist_from_centre_x > 8 && dist_from_centre_x < 24 && dist_from_centre_y > 8 && dist_from_centre_y < 24)
|
if (dist_from_centre_x > 8 && dist_from_centre_x < 24 && dist_from_centre_y > 8 && dist_from_centre_y < 24)
|
||||||
{
|
{
|
||||||
my_direction = 4;
|
my_direction = 4;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int16_t mod_x = mapCoords.x & 0x1F;
|
int16_t mod_x = mapCoords->x & 0x1F;
|
||||||
int16_t mod_y = mapCoords.y & 0x1F;
|
int16_t mod_y = mapCoords->y & 0x1F;
|
||||||
if (mod_x <= 16)
|
if (mod_x <= 16)
|
||||||
{
|
{
|
||||||
if (mod_y < 16)
|
if (mod_y < 16)
|
||||||
|
@ -1037,11 +1037,11 @@ CoordsXY screen_pos_to_map_pos(ScreenCoordsXY screenCoords, int32_t* direction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mapCoords.x = mapCoords.x & ~0x1F;
|
mapCoords->x = mapCoords->x & ~0x1F;
|
||||||
mapCoords.y = mapCoords.y & ~0x1F;
|
mapCoords->y = mapCoords->y & ~0x1F;
|
||||||
if (direction != nullptr)
|
if (direction != nullptr)
|
||||||
*direction = my_direction;
|
*direction = my_direction;
|
||||||
return mapCoords;
|
return *mapCoords;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocationXY16 screen_coord_to_viewport_coord(rct_viewport* viewport, ScreenCoordsXY screenCoords)
|
LocationXY16 screen_coord_to_viewport_coord(rct_viewport* viewport, ScreenCoordsXY screenCoords)
|
||||||
|
@ -1753,7 +1753,7 @@ static rct_viewport* viewport_find_from_point(ScreenCoordsXY screenCoords)
|
||||||
* tile_element: edx ?
|
* tile_element: edx ?
|
||||||
* viewport: edi
|
* viewport: edi
|
||||||
*/
|
*/
|
||||||
CoordsXY screen_get_map_xy(ScreenCoordsXY screenCoords, rct_viewport** viewport)
|
std::optional<CoordsXY> screen_get_map_xy(ScreenCoordsXY screenCoords, rct_viewport** viewport)
|
||||||
{
|
{
|
||||||
int32_t interactionType;
|
int32_t interactionType;
|
||||||
rct_viewport* myViewport = nullptr;
|
rct_viewport* myViewport = nullptr;
|
||||||
|
@ -1762,7 +1762,7 @@ CoordsXY screen_get_map_xy(ScreenCoordsXY screenCoords, rct_viewport** viewport)
|
||||||
screenCoords, VIEWPORT_INTERACTION_MASK_TERRAIN, map_pos, &interactionType, nullptr, &myViewport);
|
screenCoords, VIEWPORT_INTERACTION_MASK_TERRAIN, map_pos, &interactionType, nullptr, &myViewport);
|
||||||
if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE)
|
if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE)
|
||||||
{
|
{
|
||||||
return { LOCATION_NULL, 0 };
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocationXY16 start_vp_pos = screen_coord_to_viewport_coord(myViewport, screenCoords);
|
LocationXY16 start_vp_pos = screen_coord_to_viewport_coord(myViewport, screenCoords);
|
||||||
|
@ -1786,20 +1786,19 @@ CoordsXY screen_get_map_xy(ScreenCoordsXY screenCoords, rct_viewport** viewport)
|
||||||
*
|
*
|
||||||
* rct2: 0x006894D4
|
* rct2: 0x006894D4
|
||||||
*/
|
*/
|
||||||
CoordsXY screen_get_map_xy_with_z(ScreenCoordsXY screenCoords, int16_t z)
|
std::optional<CoordsXY> screen_get_map_xy_with_z(ScreenCoordsXY screenCoords, int16_t z)
|
||||||
{
|
{
|
||||||
CoordsXY ret{ LOCATION_NULL, 0 };
|
|
||||||
rct_viewport* viewport = viewport_find_from_point(screenCoords);
|
rct_viewport* viewport = viewport_find_from_point(screenCoords);
|
||||||
if (viewport == nullptr)
|
if (viewport == nullptr)
|
||||||
{
|
{
|
||||||
return ret;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto vpCoords = screen_coord_to_viewport_coord(viewport, screenCoords);
|
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.x, vpCoords.y, z);
|
||||||
if (!map_is_location_valid(mapPosition))
|
if (!map_is_location_valid(mapPosition))
|
||||||
{
|
{
|
||||||
return ret;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapPosition;
|
return mapPosition;
|
||||||
|
@ -1809,14 +1808,14 @@ CoordsXY screen_get_map_xy_with_z(ScreenCoordsXY screenCoords, int16_t z)
|
||||||
*
|
*
|
||||||
* rct2: 0x00689604
|
* rct2: 0x00689604
|
||||||
*/
|
*/
|
||||||
CoordsXY screen_get_map_xy_quadrant(ScreenCoordsXY screenCoords, uint8_t* quadrant)
|
std::optional<CoordsXY> screen_get_map_xy_quadrant(ScreenCoordsXY screenCoords, uint8_t* quadrant)
|
||||||
{
|
{
|
||||||
CoordsXY mapCoords = screen_get_map_xy(screenCoords, nullptr);
|
auto mapCoords = screen_get_map_xy(screenCoords, nullptr);
|
||||||
if (mapCoords.x == LOCATION_NULL)
|
if (!mapCoords)
|
||||||
return mapCoords;
|
return std::nullopt;
|
||||||
|
|
||||||
*quadrant = map_get_tile_quadrant(mapCoords.x, mapCoords.y);
|
*quadrant = map_get_tile_quadrant(mapCoords->x, mapCoords->y);
|
||||||
return { floor2(mapCoords.x, 32), floor2(mapCoords.y, 32) };
|
return CoordsXY(floor2(mapCoords->x, 32), floor2(mapCoords->y, 32));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1826,25 +1825,25 @@ CoordsXY screen_get_map_xy_quadrant(ScreenCoordsXY screenCoords, uint8_t* quadra
|
||||||
std::optional<CoordsXY> screen_get_map_xy_quadrant_with_z(ScreenCoordsXY screenCoords, int16_t z, uint8_t* quadrant)
|
std::optional<CoordsXY> screen_get_map_xy_quadrant_with_z(ScreenCoordsXY screenCoords, int16_t z, uint8_t* quadrant)
|
||||||
{
|
{
|
||||||
auto mapCoords = screen_get_map_xy_with_z(screenCoords, z);
|
auto mapCoords = screen_get_map_xy_with_z(screenCoords, z);
|
||||||
if (mapCoords.x == LOCATION_NULL)
|
if (!mapCoords)
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|
||||||
*quadrant = map_get_tile_quadrant(mapCoords.x, mapCoords.y);
|
*quadrant = map_get_tile_quadrant(mapCoords->x, mapCoords->y);
|
||||||
return CoordsXY(floor2(mapCoords.x, 32), floor2(mapCoords.y, 32));
|
return CoordsXY(floor2(mapCoords->x, 32), floor2(mapCoords->y, 32));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* rct2: 0x00689692
|
* rct2: 0x00689692
|
||||||
*/
|
*/
|
||||||
CoordsXY screen_get_map_xy_side(ScreenCoordsXY screenCoords, uint8_t* side)
|
std::optional<CoordsXY> screen_get_map_xy_side(ScreenCoordsXY screenCoords, uint8_t* side)
|
||||||
{
|
{
|
||||||
CoordsXY mapCoords = screen_get_map_xy(screenCoords, nullptr);
|
auto mapCoords = screen_get_map_xy(screenCoords, nullptr);
|
||||||
if (mapCoords.x == LOCATION_NULL)
|
if (!mapCoords)
|
||||||
return mapCoords;
|
return std::nullopt;
|
||||||
|
|
||||||
*side = map_get_tile_side(mapCoords.x, mapCoords.y);
|
*side = map_get_tile_side(mapCoords->x, mapCoords->y);
|
||||||
return { floor2(mapCoords.x, 32), floor2(mapCoords.y, 32) };
|
return CoordsXY(floor2(mapCoords->x, 32), floor2(mapCoords->y, 32));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1854,11 +1853,11 @@ CoordsXY screen_get_map_xy_side(ScreenCoordsXY screenCoords, uint8_t* side)
|
||||||
std::optional<CoordsXY> screen_get_map_xy_side_with_z(ScreenCoordsXY screenCoords, int16_t z, uint8_t* side)
|
std::optional<CoordsXY> screen_get_map_xy_side_with_z(ScreenCoordsXY screenCoords, int16_t z, uint8_t* side)
|
||||||
{
|
{
|
||||||
auto mapCoords = screen_get_map_xy_with_z(screenCoords, z);
|
auto mapCoords = screen_get_map_xy_with_z(screenCoords, z);
|
||||||
if (mapCoords.x == LOCATION_NULL)
|
if (!mapCoords)
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|
||||||
*side = map_get_tile_side(mapCoords.x, mapCoords.y);
|
*side = map_get_tile_side(mapCoords->x, mapCoords->y);
|
||||||
return CoordsXY(floor2(mapCoords.x, 32), floor2(mapCoords.y, 32));
|
return CoordsXY(floor2(mapCoords->x, 32), floor2(mapCoords->y, 32));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -171,11 +171,11 @@ void sub_68B2B7(paint_session* session, CoordsXY mapCoords);
|
||||||
|
|
||||||
void viewport_invalidate(rct_viewport* viewport, int32_t left, int32_t top, int32_t right, int32_t bottom);
|
void viewport_invalidate(rct_viewport* viewport, int32_t left, int32_t top, int32_t right, int32_t bottom);
|
||||||
|
|
||||||
CoordsXY screen_get_map_xy(ScreenCoordsXY screenCoords, rct_viewport** viewport);
|
std::optional<CoordsXY> screen_get_map_xy(ScreenCoordsXY screenCoords, rct_viewport** viewport);
|
||||||
CoordsXY screen_get_map_xy_with_z(ScreenCoordsXY screenCoords, int16_t z);
|
std::optional<CoordsXY> screen_get_map_xy_with_z(ScreenCoordsXY screenCoords, int16_t z);
|
||||||
CoordsXY screen_get_map_xy_quadrant(ScreenCoordsXY screenCoords, uint8_t* quadrant);
|
std::optional<CoordsXY> screen_get_map_xy_quadrant(ScreenCoordsXY screenCoords, uint8_t* quadrant);
|
||||||
std::optional<CoordsXY> screen_get_map_xy_quadrant_with_z(ScreenCoordsXY screenCoords, int16_t z, uint8_t* quadrant);
|
std::optional<CoordsXY> screen_get_map_xy_quadrant_with_z(ScreenCoordsXY screenCoords, int16_t z, uint8_t* quadrant);
|
||||||
CoordsXY screen_get_map_xy_side(ScreenCoordsXY screenCoords, uint8_t* side);
|
std::optional<CoordsXY> screen_get_map_xy_side(ScreenCoordsXY screenCoords, uint8_t* side);
|
||||||
std::optional<CoordsXY> screen_get_map_xy_side_with_z(ScreenCoordsXY screenCoords, int16_t z, uint8_t* side);
|
std::optional<CoordsXY> screen_get_map_xy_side_with_z(ScreenCoordsXY screenCoords, int16_t z, uint8_t* side);
|
||||||
|
|
||||||
uint8_t get_current_rotation();
|
uint8_t get_current_rotation();
|
||||||
|
|
|
@ -915,11 +915,12 @@ void window_rotate_camera(rct_window* w, int32_t direction)
|
||||||
|
|
||||||
// has something to do with checking if middle of the viewport is obstructed
|
// has something to do with checking if middle of the viewport is obstructed
|
||||||
rct_viewport* other;
|
rct_viewport* other;
|
||||||
CoordsXYZ coords{ screen_get_map_xy({ x, y }, &other), 0 };
|
auto mapXYCoords = screen_get_map_xy({ x, y }, &other);
|
||||||
|
CoordsXYZ coords{};
|
||||||
|
|
||||||
// other != viewport probably triggers on viewports in ride or guest window?
|
// other != viewport probably triggers on viewports in ride or guest window?
|
||||||
// x is LOCATION_NULL if middle of viewport is obstructed by another window?
|
// naoXYCoords is nullopt if middle of viewport is obstructed by another window?
|
||||||
if (coords.x == LOCATION_NULL || other != viewport)
|
if (!mapXYCoords || other != viewport)
|
||||||
{
|
{
|
||||||
int16_t view_x = (viewport->view_width >> 1) + viewport->view_x;
|
int16_t view_x = (viewport->view_width >> 1) + viewport->view_x;
|
||||||
int16_t view_y = (viewport->view_height >> 1) + viewport->view_y;
|
int16_t view_y = (viewport->view_height >> 1) + viewport->view_y;
|
||||||
|
@ -928,6 +929,8 @@ void window_rotate_camera(rct_window* w, int32_t direction)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
coords.x = mapXYCoords->x;
|
||||||
|
coords.y = mapXYCoords->y;
|
||||||
coords.z = tile_element_height(coords);
|
coords.z = tile_element_height(coords);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6218,16 +6218,16 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsX
|
||||||
stationHeight = ride->stations[gRideEntranceExitPlaceStationIndex].Height;
|
stationHeight = ride->stations[gRideEntranceExitPlaceStationIndex].Height;
|
||||||
|
|
||||||
auto coords = screen_get_map_xy_with_z(screenCoords, stationHeight * 8);
|
auto coords = screen_get_map_xy_with_z(screenCoords, stationHeight * 8);
|
||||||
if (coords.x == LOCATION_NULL)
|
if (!coords)
|
||||||
{
|
{
|
||||||
entranceExitCoords.x = LOCATION_NULL;
|
entranceExitCoords.x = LOCATION_NULL;
|
||||||
return entranceExitCoords;
|
return entranceExitCoords;
|
||||||
}
|
}
|
||||||
|
|
||||||
word_F4418C = coords.x;
|
word_F4418C = coords->x;
|
||||||
word_F4418E = coords.y;
|
word_F4418E = coords->y;
|
||||||
|
|
||||||
entranceExitCoords = { floor2(coords.x, 32), floor2(coords.y, 32), stationHeight, INVALID_DIRECTION };
|
entranceExitCoords = { floor2(coords->x, 32), floor2(coords->y, 32), stationHeight, INVALID_DIRECTION };
|
||||||
|
|
||||||
if (ride->type == RIDE_TYPE_NULL)
|
if (ride->type == RIDE_TYPE_NULL)
|
||||||
{
|
{
|
||||||
|
|
|
@ -94,12 +94,12 @@ void rct_money_effect::Create(money32 value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
rct_viewport* mainViewport = window_get_viewport(mainWindow);
|
rct_viewport* mainViewport = window_get_viewport(mainWindow);
|
||||||
CoordsXY mapPositionXY = screen_get_map_xy(
|
auto mapPositionXY = screen_get_map_xy(
|
||||||
{ mainViewport->x + (mainViewport->width / 2), mainViewport->y + (mainViewport->height / 2) }, nullptr);
|
{ mainViewport->x + (mainViewport->width / 2), mainViewport->y + (mainViewport->height / 2) }, nullptr);
|
||||||
if (mapPositionXY.x == LOCATION_NULL)
|
if (!mapPositionXY)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mapPosition = { mapPositionXY, tile_element_height(mapPositionXY) };
|
mapPosition = { *mapPositionXY, tile_element_height(*mapPositionXY) };
|
||||||
}
|
}
|
||||||
mapPosition.z += 10;
|
mapPosition.z += 10;
|
||||||
CreateAt(-value, mapPosition.x, mapPosition.y, mapPosition.z, false);
|
CreateAt(-value, mapPosition.x, mapPosition.y, mapPosition.z, false);
|
||||||
|
|
Loading…
Reference in New Issue