Skip to content

Commit

Permalink
Merge pull request #9867 from duncanspumpkin/refactor_map
Browse files Browse the repository at this point in the history
Refactor map
  • Loading branch information
duncanspumpkin committed Aug 20, 2019
2 parents 9897572 + 4f15724 commit 2f8dccb
Show file tree
Hide file tree
Showing 93 changed files with 931 additions and 1,105 deletions.
4 changes: 2 additions & 2 deletions src/openrct2-ui/interface/ViewportInteraction.cpp
Expand Up @@ -296,7 +296,7 @@ int32_t viewport_interaction_get_item_right(int32_t x, int32_t y, viewport_inter
}
else
{
if (!gCheatsSandboxMode && !map_is_location_owned(info->x, info->y, tileElement->base_height << 4))
if (!gCheatsSandboxMode && !map_is_location_owned({ info->x, info->y, tileElement->base_height << 4 }))
{
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
}
Expand Down Expand Up @@ -686,7 +686,7 @@ void sub_68A15E(int32_t screenX, int32_t screenY, int16_t* x, int16_t* y, int32_
int16_t z = originalZ;
if (interactionType != VIEWPORT_INTERACTION_ITEM_WATER)
{
z = tile_element_height(map_pos.x, map_pos.y);
z = tile_element_height({ map_pos.x, map_pos.y });
}
map_pos = viewport_coord_to_map_coord(start_vp_pos.x, start_vp_pos.y, z);
map_pos.x = std::clamp<int16_t>(map_pos.x, my_x, my_x + 31);
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2-ui/title/TitleSequencePlayer.cpp
Expand Up @@ -524,7 +524,7 @@ class TitleSequencePlayer final : public ITitleSequencePlayer
rct_window* w = window_get_main();
if (w != nullptr)
{
int32_t z = tile_element_height(x, y);
int32_t z = tile_element_height({ x, y });

// Prevent scroll adjustment due to window placement when in-game
auto oldScreenFlags = gScreenFlags;
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2-ui/windows/Footpath.cpp
Expand Up @@ -895,7 +895,7 @@ static void window_footpath_place_path_at_point(int32_t x, int32_t y)
// Don't play sound if it is no cost to prevent multiple sounds. TODO: make this work in no money scenarios
if (result->Cost != 0)
{
audio_play_sound_at_location(SoundId::PlaceItem, result->Position.x, result->Position.y, result->Position.z);
audio_play_sound_at_location(SoundId::PlaceItem, result->Position);
}
}
else
Expand Down Expand Up @@ -983,7 +983,7 @@ static void window_footpath_construct()
footpathPlaceAction.SetCallback([=](const GameAction* ga, const GameActionResult* result) {
if (result->Error == GA_ERROR::OK)
{
audio_play_sound_at_location(SoundId::PlaceItem, result->Position.x, result->Position.y, result->Position.z);
audio_play_sound_at_location(SoundId::PlaceItem, result->Position);

if (gFootpathConstructSlope == 0)
{
Expand Down
27 changes: 14 additions & 13 deletions src/openrct2-ui/windows/Map.cpp
Expand Up @@ -566,7 +566,7 @@ static void window_map_scrollmousedown(rct_window* w, int32_t scrollIndex, int32
CoordsXY c = map_window_screen_to_map(x, y);
int32_t mapX = std::clamp(c.x, 0, MAXIMUM_MAP_SIZE_TECHNICAL * 32 - 1);
int32_t mapY = std::clamp(c.y, 0, MAXIMUM_MAP_SIZE_TECHNICAL * 32 - 1);
int32_t mapZ = tile_element_height(x, y);
int32_t mapZ = tile_element_height({ x, y });

rct_window* mainWindow = window_get_main();
if (mainWindow != nullptr)
Expand Down Expand Up @@ -1198,15 +1198,15 @@ static void place_park_entrance_get_map_position(
if (*mapX == LOCATION_NULL)
return;

tileElement = map_get_surface_element_at(*mapX >> 5, *mapY >> 5);
*mapZ = tileElement->AsSurface()->GetWaterHeight();
auto surfaceElement = map_get_surface_element_at(*mapX >> 5, *mapY >> 5);
*mapZ = surfaceElement->GetWaterHeight();
if (*mapZ == 0)
{
*mapZ = tileElement->base_height / 2;
if ((tileElement->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP) != 0)
*mapZ = surfaceElement->base_height / 2;
if ((surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP) != 0)
{
(*mapZ)++;
if (tileElement->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
if (surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
{
(*mapZ)++;
}
Expand Down Expand Up @@ -1316,7 +1316,7 @@ static void window_map_place_park_entrance_tool_down(int32_t x, int32_t y)
money32 price = place_park_entrance(mapX, mapY, mapZ, direction);
if (price != MONEY32_UNDEFINED)
{
audio_play_sound_at_location(SoundId::PlaceItem, gCommandPosition.x, gCommandPosition.y, gCommandPosition.z);
audio_play_sound_at_location(SoundId::PlaceItem, { gCommandPosition.x, gCommandPosition.y, gCommandPosition.z });
}
}
}
Expand All @@ -1340,7 +1340,7 @@ static void window_map_set_peep_spawn_tool_down(int32_t x, int32_t y)
bool result = place_peep_spawn({ mapX, mapY, mapZ, (uint8_t)direction });
if (result)
{
audio_play_sound_at_location(SoundId::PlaceItem, gCommandPosition.x, gCommandPosition.y, gCommandPosition.z);
audio_play_sound_at_location(SoundId::PlaceItem, { gCommandPosition.x, gCommandPosition.y, gCommandPosition.z });
}
}

Expand Down Expand Up @@ -1541,15 +1541,16 @@ static constexpr const uint8_t RideColourKey[] = {

static uint16_t map_window_get_pixel_colour_peep(CoordsXY c)
{
TileElement* tileElement = map_get_surface_element_at(c);
uint16_t colour = TerrainColour[tileElement->AsSurface()->GetSurfaceStyle()];
if (tileElement->AsSurface()->GetWaterHeight() > 0)
auto* surfaceElement = map_get_surface_element_at(c);
uint16_t colour = TerrainColour[surfaceElement->GetSurfaceStyle()];
if (surfaceElement->GetWaterHeight() > 0)
colour = WaterColour;

if (!(tileElement->AsSurface()->GetOwnership() & OWNERSHIP_OWNED))
if (!(surfaceElement->GetOwnership() & OWNERSHIP_OWNED))
colour = MAP_COLOUR_UNOWNED(colour);

const int32_t maxSupportedTileElementType = (int32_t)std::size(ElementTypeAddColour);
auto tileElement = reinterpret_cast<TileElement*>(surfaceElement);
while (!(tileElement++)->IsLastForTile())
{
if (tileElement->IsGhost())
Expand Down Expand Up @@ -1577,7 +1578,7 @@ static uint16_t map_window_get_pixel_colour_ride(CoordsXY c)
uint16_t colourB = MAP_COLOUR(PALETTE_INDEX_13); // surface colour (dark grey)

// as an improvement we could use first_element to show underground stuff?
TileElement* tileElement = map_get_surface_element_at(c);
TileElement* tileElement = reinterpret_cast<TileElement*>(map_get_surface_element_at(c));
do
{
if (tileElement->IsGhost())
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2-ui/windows/MazeConstruction.cpp
Expand Up @@ -377,7 +377,7 @@ static void window_maze_construction_entrance_tooldown(int32_t x, int32_t y, rct
if (result->Error != GA_ERROR::OK)
return;

audio_play_sound_at_location(SoundId::PlaceItem, result->Position.x, result->Position.y, result->Position.z);
audio_play_sound_at_location(SoundId::PlaceItem, result->Position);

auto ride = get_ride(rideIndex);
if (ride != nullptr && ride_are_all_possible_entrances_and_exits_built(ride))
Expand Down Expand Up @@ -514,6 +514,6 @@ static void window_maze_construction_construct(int32_t direction)
_currentTrackBegin.y = y;
if (_rideConstructionState != RIDE_CONSTRUCTION_STATE_MAZE_MOVE)
{
audio_play_sound_at_location(SoundId::PlaceItem, x, y, z);
audio_play_sound_at_location(SoundId::PlaceItem, { x, y, z });
}
}
19 changes: 9 additions & 10 deletions src/openrct2-ui/windows/RideConstruction.cpp
Expand Up @@ -1834,7 +1834,7 @@ static void window_ride_construction_construct(rct_window* w)
{
return;
}
audio_play_sound_at_location(SoundId::PlaceItem, x, y, z);
audio_play_sound_at_location(SoundId::PlaceItem, { x, y, z });

if (network_get_mode() != NETWORK_MODE_NONE)
{
Expand Down Expand Up @@ -2180,8 +2180,8 @@ static bool ride_get_place_position_from_screen_position(int32_t screenX, int32_
_trackPlaceZ = 0;
if (_trackPlaceShiftState)
{
tileElement = map_get_surface_element_at(mapX >> 5, mapY >> 5);
mapZ = floor2(tileElement->base_height * 8, 16);
auto surfaceElement = map_get_surface_element_at(mapX >> 5, mapY >> 5);
mapZ = floor2(surfaceElement->base_height * 8, 16);
mapZ += _trackPlaceShiftZ;
mapZ = std::max<int16_t>(mapZ, 16);
_trackPlaceZ = mapZ;
Expand Down Expand Up @@ -3489,7 +3489,7 @@ void ride_construction_toolupdate_construct(int32_t screenX, int32_t screenY)

z = _trackPlaceZ;
if (z == 0)
z = map_get_highest_z(x >> 5, y >> 5);
z = map_get_highest_z({ x, y });

gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE_CONSTRUCT;
gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE_ARROW;
Expand Down Expand Up @@ -3531,7 +3531,7 @@ void ride_construction_toolupdate_construct(int32_t screenX, int32_t screenY)
{
if (selectedTile.x < (256 * 32) && selectedTile.y < (256 * 32))
{
z = map_get_highest_z(selectedTile.x / 32, selectedTile.y / 32);
z = map_get_highest_z(selectedTile);
if (z > highestZ)
highestZ = z;
}
Expand Down Expand Up @@ -3755,7 +3755,7 @@ void ride_construction_tooldown_construct(int32_t screenX, int32_t screenY)
if (selectedTile.x >= (256 * 32) || selectedTile.y >= (256 * 32))
continue;

z = map_get_highest_z(selectedTile.x / 32, selectedTile.y / 32);
z = map_get_highest_z(selectedTile);
if (z > highestZ)
highestZ = z;
}
Expand All @@ -3769,7 +3769,7 @@ void ride_construction_tooldown_construct(int32_t screenX, int32_t screenY)

z = _trackPlaceZ;
if (z == 0)
z = map_get_highest_z(x >> 5, y >> 5);
z = map_get_highest_z({ x, y });

tool_cancel();

Expand Down Expand Up @@ -3854,8 +3854,7 @@ void ride_construction_tooldown_construct(int32_t screenX, int32_t screenY)
else
{
window_close_by_class(WC_ERROR);
audio_play_sound_at_location(
SoundId::PlaceItem, _currentTrackBegin.x, _currentTrackBegin.y, _currentTrackBegin.z);
audio_play_sound_at_location(SoundId::PlaceItem, _currentTrackBegin);
break;
}
}
Expand Down Expand Up @@ -3946,7 +3945,7 @@ static void ride_construction_tooldown_entrance_exit(int32_t screenX, int32_t sc
if (result->Error != GA_ERROR::OK)
return;

audio_play_sound_at_location(SoundId::PlaceItem, result->Position.x, result->Position.y, result->Position.z);
audio_play_sound_at_location(SoundId::PlaceItem, result->Position);

auto ride = get_ride(gRideEntranceExitPlaceRideIndex);
if (ride != nullptr && ride_are_all_possible_entrances_and_exits_built(ride))
Expand Down
40 changes: 18 additions & 22 deletions src/openrct2-ui/windows/TopToolbar.cpp
Expand Up @@ -1355,15 +1355,15 @@ static void sub_6E1F34(
// If SHIFT pressed
if (gSceneryShiftPressed)
{
TileElement* tile_element = map_get_surface_element_at(*grid_x / 32, *grid_y / 32);
auto* surfaceElement = map_get_surface_element_at(*grid_x / 32, *grid_y / 32);

if (tile_element == nullptr)
if (surfaceElement == nullptr)
{
*grid_x = LOCATION_NULL;
return;
}

int16_t z = (tile_element->base_height * 8) & 0xFFF0;
int16_t z = (surfaceElement->base_height * 8) & 0xFFF0;
z += gSceneryShiftPressZOffset;

z = std::clamp<int16_t>(z, 16, maxPossibleHeight);
Expand Down Expand Up @@ -1435,15 +1435,15 @@ static void sub_6E1F34(
// If SHIFT pressed
if (gSceneryShiftPressed)
{
tile_element = map_get_surface_element_at(*grid_x / 32, *grid_y / 32);
auto surfaceElement = map_get_surface_element_at(*grid_x / 32, *grid_y / 32);

if (tile_element == nullptr)
if (surfaceElement == nullptr)
{
*grid_x = LOCATION_NULL;
return;
}

int16_t z = (tile_element->base_height * 8) & 0xFFF0;
int16_t z = (surfaceElement->base_height * 8) & 0xFFF0;
z += gSceneryShiftPressZOffset;

z = std::clamp<int16_t>(z, 16, maxPossibleHeight);
Expand Down Expand Up @@ -1532,15 +1532,15 @@ static void sub_6E1F34(
// If SHIFT pressed
if (gSceneryShiftPressed)
{
TileElement* tile_element = map_get_surface_element_at(*grid_x / 32, *grid_y / 32);
auto* surfaceElement = map_get_surface_element_at(*grid_x / 32, *grid_y / 32);

if (tile_element == nullptr)
if (surfaceElement == nullptr)
{
*grid_x = LOCATION_NULL;
return;
}

int16_t z = (tile_element->base_height * 8) & 0xFFF0;
int16_t z = (surfaceElement->base_height * 8) & 0xFFF0;
z += gSceneryShiftPressZOffset;

z = std::clamp<int16_t>(z, 16, maxPossibleHeight);
Expand Down Expand Up @@ -1591,15 +1591,15 @@ static void sub_6E1F34(
// If SHIFT pressed
if (gSceneryShiftPressed)
{
TileElement* tile_element = map_get_surface_element_at(*grid_x / 32, *grid_y / 32);
auto* surfaceElement = map_get_surface_element_at(*grid_x / 32, *grid_y / 32);

if (tile_element == nullptr)
if (surfaceElement == nullptr)
{
*grid_x = LOCATION_NULL;
return;
}

int16_t z = (tile_element->base_height * 8) & 0xFFF0;
int16_t z = (surfaceElement->base_height * 8) & 0xFFF0;
z += gSceneryShiftPressZOffset;

z = std::clamp<int16_t>(z, 16, maxPossibleHeight);
Expand Down Expand Up @@ -1798,8 +1798,7 @@ static void window_top_toolbar_scenery_tool_down(int16_t x, int16_t y, rct_windo
smallSceneryPlaceAction.SetCallback([=](const GameAction* ga, const GameActionResult* result) {
if (result->Error == GA_ERROR::OK)
{
audio_play_sound_at_location(
SoundId::PlaceItem, result->Position.x, result->Position.y, result->Position.z);
audio_play_sound_at_location(SoundId::PlaceItem, result->Position);
}
});
auto res = GameActions::Execute(&smallSceneryPlaceAction);
Expand Down Expand Up @@ -1828,7 +1827,7 @@ static void window_top_toolbar_scenery_tool_down(int16_t x, int16_t y, rct_windo
{
return;
}
audio_play_sound_at_location(SoundId::PlaceItem, result->Position.x, result->Position.y, result->Position.z);
audio_play_sound_at_location(SoundId::PlaceItem, result->Position);
});
auto res = GameActions::Execute(&footpathSceneryPlaceAction);
break;
Expand Down Expand Up @@ -1875,8 +1874,7 @@ static void window_top_toolbar_scenery_tool_down(int16_t x, int16_t y, rct_windo
wallPlaceAction.SetCallback([](const GameAction* ga, const GameActionResult* result) {
if (result->Error == GA_ERROR::OK)
{
audio_play_sound_at_location(
SoundId::PlaceItem, result->Position.x, result->Position.y, result->Position.z);
audio_play_sound_at_location(SoundId::PlaceItem, result->Position);
}
});
auto res = GameActions::Execute(&wallPlaceAction);
Expand Down Expand Up @@ -1926,12 +1924,11 @@ static void window_top_toolbar_scenery_tool_down(int16_t x, int16_t y, rct_windo
sceneryPlaceAction.SetCallback([=](const GameAction* ga, const GameActionResult* result) {
if (result->Error == GA_ERROR::OK)
{
audio_play_sound_at_location(
SoundId::PlaceItem, result->Position.x, result->Position.y, result->Position.z);
audio_play_sound_at_location(SoundId::PlaceItem, result->Position);
}
else
{
audio_play_sound_at_location(SoundId::Error, loc.x, loc.y, gSceneryPlaceZ);
audio_play_sound_at_location(SoundId::Error, { loc.x, loc.y, gSceneryPlaceZ });
}
});
auto res = GameActions::Execute(&sceneryPlaceAction);
Expand All @@ -1954,8 +1951,7 @@ static void window_top_toolbar_scenery_tool_down(int16_t x, int16_t y, rct_windo
bannerPlaceAction.SetCallback([=](const GameAction* ga, const GameActionResult* result) {
if (result->Error == GA_ERROR::OK)
{
audio_play_sound_at_location(
SoundId::PlaceItem, result->Position.x, result->Position.y, result->Position.z);
audio_play_sound_at_location(SoundId::PlaceItem, result->Position);
context_open_detail_window(WD_BANNER, bannerIndex);
}
});
Expand Down
17 changes: 8 additions & 9 deletions src/openrct2-ui/windows/TrackDesignPlace.cpp
Expand Up @@ -338,7 +338,7 @@ static void window_track_place_tooldown(rct_window* w, rct_widgetindex widgetInd
if (cost != MONEY32_UNDEFINED)
{
window_close_by_class(WC_ERROR);
audio_play_sound_at_location(SoundId::PlaceItem, mapX, mapY, mapZ);
audio_play_sound_at_location(SoundId::PlaceItem, { mapX, mapY, mapZ });

_currentRideIndex = rideIndex;
if (track_design_are_entrance_and_exit_placed())
Expand All @@ -365,7 +365,7 @@ static void window_track_place_tooldown(rct_window* w, rct_widgetindex widgetInd
}

// Unable to build track
audio_play_sound_at_location(SoundId::Error, mapX, mapY, mapZ);
audio_play_sound_at_location(SoundId::Error, { mapX, mapY, mapZ });
}

/**
Expand Down Expand Up @@ -413,25 +413,24 @@ static void window_track_place_clear_provisional()
*/
static int32_t window_track_place_get_base_z(int32_t x, int32_t y)
{
TileElement* tileElement;
uint32_t z;

tileElement = map_get_surface_element_at(x >> 5, y >> 5);
z = tileElement->base_height * 8;
auto surfaceElement = map_get_surface_element_at(x >> 5, y >> 5);
z = surfaceElement->base_height * 8;

// Increase Z above slope
if (tileElement->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
if (surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
{
z += 16;

// Increase Z above double slope
if (tileElement->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
if (surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
z += 16;
}

// Increase Z above water
if (tileElement->AsSurface()->GetWaterHeight() > 0)
z = std::max(z, tileElement->AsSurface()->GetWaterHeight() << 4);
if (surfaceElement->GetWaterHeight() > 0)
z = std::max(z, surfaceElement->GetWaterHeight() << 4);

return z + place_virtual_track(_trackDesign.get(), PTD_OPERATION_GET_PLACE_Z, true, GetOrAllocateRide(0), x, y, z);
}
Expand Down

0 comments on commit 2f8dccb

Please sign in to comment.