Merge pull request #9867 from duncanspumpkin/refactor_map

Refactor map
This commit is contained in:
Duncan 2019-08-20 18:22:24 +01:00 committed by GitHub
commit 2f8dccbba2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
93 changed files with 930 additions and 1104 deletions

View File

@ -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;
}
@ -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);

View File

@ -524,7 +524,7 @@ private:
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;

View File

@ -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
@ -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)
{

View File

@ -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)
@ -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)++;
}
@ -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 });
}
}
}
@ -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 });
}
}
@ -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())
@ -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())

View File

@ -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))
@ -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 });
}
}

View File

@ -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)
{
@ -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;
@ -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;
@ -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;
}
@ -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;
}
@ -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();
@ -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;
}
}
@ -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))

View File

@ -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);
@ -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);
@ -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);
@ -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);
@ -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);
@ -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;
@ -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);
@ -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);
@ -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);
}
});

View File

@ -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())
@ -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 });
}
/**
@ -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);
}

View File

@ -152,7 +152,7 @@ static void window_viewport_mouseup(rct_window* w, rct_widgetindex widgetIndex)
get_map_coordinates_from_pos(
w->x + (w->width / 2), w->y + (w->height / 2), VIEWPORT_INTERACTION_MASK_NONE, &x, &y, nullptr, nullptr,
nullptr);
window_scroll_to_location(mainWindow, x, y, tile_element_height(x, y));
window_scroll_to_location(mainWindow, x, y, tile_element_height({ x, y }));
}
break;
}

View File

@ -638,27 +638,28 @@ void game_fix_save_vars()
{
for (int32_t x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++)
{
TileElement* tileElement = map_get_surface_element_at(x, y);
auto* surfaceElement = map_get_surface_element_at(x, y);
if (tileElement == nullptr)
if (surfaceElement == nullptr)
{
log_error("Null map element at x = %d and y = %d. Fixing...", x, y);
tileElement = tile_element_insert(x, y, 14, 0);
auto tileElement = tile_element_insert({ x, y, 14 }, 0);
if (tileElement == nullptr)
{
log_error("Unable to fix: Map element limit reached.");
return;
}
surfaceElement = tileElement->AsSurface();
}
// Fix the invisible border tiles.
// At this point, we can be sure that tileElement is not NULL.
// At this point, we can be sure that surfaceElement is not NULL.
if (x == 0 || x == gMapSize - 1 || y == 0 || y == gMapSize - 1)
{
tileElement->base_height = 2;
tileElement->clearance_height = 2;
tileElement->AsSurface()->SetSlope(0);
tileElement->AsSurface()->SetWaterHeight(0);
surfaceElement->base_height = 2;
surfaceElement->clearance_height = 2;
surfaceElement->SetSlope(0);
surfaceElement->SetWaterHeight(0);
}
}
}

View File

@ -60,7 +60,7 @@ public:
return MakeResult(GA_ERROR::NO_FREE_ELEMENTS, STR_CANT_POSITION_THIS_HERE);
}
if (!map_is_location_valid({ _loc.x, _loc.y }))
if (!map_is_location_valid(_loc))
{
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_POSITION_THIS_HERE);
}
@ -72,7 +72,7 @@ public:
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_POSITION_THIS_HERE, STR_CAN_ONLY_BE_BUILT_ACROSS_PATHS);
}
if (!map_can_build_at(_loc.x, _loc.y, _loc.z))
if (!map_can_build_at(_loc))
{
return MakeResult(GA_ERROR::NOT_OWNED, STR_CANT_POSITION_THIS_HERE, STR_LAND_NOT_OWNED_BY_PARK);
}
@ -137,7 +137,7 @@ public:
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_POSITION_THIS_HERE);
}
TileElement* newTileElement = tile_element_insert(_loc.x / 32, _loc.y / 32, baseHeight, 0);
TileElement* newTileElement = tile_element_insert({ _loc.x / 32, _loc.y / 32, baseHeight }, 0);
assert(newTileElement != nullptr);
banner->flags = 0;

View File

@ -48,7 +48,7 @@ public:
res->Position.z = _loc.z;
res->ErrorTitle = STR_CANT_REMOVE_THIS;
if (!map_can_build_at(_loc.x, _loc.y, _loc.z - 16))
if (!map_can_build_at({ _loc.x, _loc.y, _loc.z - 16 }))
{
return MakeResult(GA_ERROR::NOT_OWNED, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK);
}

View File

@ -74,7 +74,7 @@ private:
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_REPAINT_THIS);
}
if (!map_can_build_at(_loc.x, _loc.y, _loc.z - 16))
if (!map_can_build_at({ _loc.x, _loc.y, _loc.z - 16 }))
{
return MakeResult(GA_ERROR::NOT_OWNED, STR_CANT_REPAINT_THIS, STR_LAND_NOT_OWNED_BY_PARK);
}

View File

@ -68,7 +68,7 @@ public:
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;
res->Position.x = banner->position.x * 32 + 16;
res->Position.y = banner->position.y * 32 + 16;
res->Position.z = tile_element_height(banner->position.x, banner->position.y);
res->Position.z = tile_element_height(res->Position);
TileElement* tileElement = banner_get_tile_element(_bannerIndex);
@ -118,7 +118,7 @@ public:
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;
res->Position.x = banner->position.x * 32 + 16;
res->Position.y = banner->position.y * 32 + 16;
res->Position.z = tile_element_height(banner->position.x, banner->position.y);
res->Position.z = tile_element_height(res->Position);
TileElement* tileElement = banner_get_tile_element(_bannerIndex);

View File

@ -78,7 +78,7 @@ private:
auto x = (_range.GetLeft() + _range.GetRight()) / 2 + 16;
auto y = (_range.GetTop() + _range.GetBottom()) / 2 + 16;
auto z = tile_element_height(x, y);
auto z = tile_element_height({ x, y });
result->Position = CoordsXYZ(x, y, z);
return result;
@ -252,6 +252,7 @@ private:
static bool MapCanClearAt(int32_t x, int32_t y)
{
return (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gCheatsSandboxMode || map_is_location_owned_or_has_rights(x, y);
return (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gCheatsSandboxMode
|| map_is_location_owned_or_has_rights({ x, y });
}
};

View File

@ -63,13 +63,12 @@ public:
gFootpathGroundFlags = 0;
if (map_is_edge({ _loc.x, _loc.y }))
if (map_is_edge(_loc))
{
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_BUILD_FOOTPATH_HERE, STR_OFF_EDGE_OF_MAP);
}
if (!((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gCheatsSandboxMode)
&& !map_is_location_owned(_loc.x, _loc.y, _loc.z))
if (!((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gCheatsSandboxMode) && !map_is_location_owned(_loc))
{
return MakeResult(GA_ERROR::DISALLOWED, STR_CANT_BUILD_FOOTPATH_HERE, STR_LAND_NOT_OWNED_BY_PARK);
}
@ -252,12 +251,11 @@ private:
return MakeResult(GA_ERROR::DISALLOWED, STR_CANT_BUILD_FOOTPATH_HERE, STR_CANT_BUILD_THIS_UNDERWATER);
}
auto tileElement = map_get_surface_element_at({ _loc.x, _loc.y });
if (tileElement == nullptr)
auto surfaceElement = map_get_surface_element_at(_loc);
if (surfaceElement == nullptr)
{
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_BUILD_FOOTPATH_HERE);
}
auto surfaceElement = tileElement->AsSurface();
int32_t supportHeight = zLow - surfaceElement->base_height;
res->Cost += supportHeight < 0 ? MONEY(20, 00) : (supportHeight / 2) * MONEY(5, 00);
@ -314,12 +312,11 @@ private:
gFootpathGroundFlags = gMapGroundFlags;
auto tileElement = map_get_surface_element_at({ _loc.x, _loc.y });
if (tileElement == nullptr)
auto surfaceElement = map_get_surface_element_at(_loc);
if (surfaceElement == nullptr)
{
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_BUILD_FOOTPATH_HERE);
}
auto surfaceElement = tileElement->AsSurface();
int32_t supportHeight = zLow - surfaceElement->base_height;
res->Cost += supportHeight < 0 ? MONEY(20, 00) : (supportHeight / 2) * MONEY(5, 00);
@ -334,7 +331,7 @@ private:
}
else
{
tileElement = tile_element_insert(_loc.x / 32, _loc.y / 32, zLow, 0b1111);
auto tileElement = tile_element_insert({ _loc.x / 32, _loc.y / 32, zLow }, 0b1111);
assert(tileElement != nullptr);
tileElement->SetType(TILE_ELEMENT_TYPE_PATH);
PathElement* pathElement = tileElement->AsPath();

View File

@ -63,14 +63,13 @@ public:
gFootpathGroundFlags = 0;
if (map_is_edge({ _loc.x, _loc.y }))
if (map_is_edge(_loc))
{
return MakeResult(
GA_ERROR::INVALID_PARAMETERS, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_OFF_EDGE_OF_MAP);
}
if (!((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gCheatsSandboxMode)
&& !map_is_location_owned(_loc.x, _loc.y, _loc.z))
if (!((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gCheatsSandboxMode) && !map_is_location_owned(_loc))
{
return MakeResult(GA_ERROR::DISALLOWED, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_LAND_NOT_OWNED_BY_PARK);
}
@ -164,12 +163,11 @@ private:
GA_ERROR::DISALLOWED, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_CANT_BUILD_THIS_UNDERWATER);
}
auto tileElement = map_get_surface_element_at({ _loc.x, _loc.y });
if (tileElement == nullptr)
auto surfaceElement = map_get_surface_element_at(_loc);
if (surfaceElement == nullptr)
{
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE);
}
auto surfaceElement = tileElement->AsSurface();
int32_t supportHeight = zLow - surfaceElement->base_height;
res->Cost += supportHeight < 0 ? MONEY(20, 00) : (supportHeight / 2) * MONEY(5, 00);
@ -228,12 +226,11 @@ private:
gFootpathGroundFlags = gMapGroundFlags;
auto tileElement = map_get_surface_element_at({ _loc.x, _loc.y });
if (tileElement == nullptr)
auto surfaceElement = map_get_surface_element_at(_loc);
if (surfaceElement == nullptr)
{
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE);
}
auto surfaceElement = tileElement->AsSurface();
int32_t supportHeight = zLow - surfaceElement->base_height;
res->Cost += supportHeight < 0 ? MONEY(20, 00) : (supportHeight / 2) * MONEY(5, 00);
@ -248,7 +245,7 @@ private:
}
else
{
tileElement = tile_element_insert(_loc.x / 32, _loc.y / 32, zLow, 0b1111);
auto tileElement = tile_element_insert({ _loc.x / 32, _loc.y / 32, zLow }, 0b1111);
assert(tileElement != nullptr);
tileElement->SetType(TILE_ELEMENT_TYPE_PATH);
PathElement* pathElement = tileElement->AsPath();

View File

@ -53,8 +53,7 @@ public:
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;
res->Position = { _loc.x + 16, _loc.y + 16, _loc.z };
if (!((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gCheatsSandboxMode)
&& !map_is_location_owned(_loc.x, _loc.y, _loc.z))
if (!((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gCheatsSandboxMode) && !map_is_location_owned(_loc))
{
return MakeResult(GA_ERROR::NOT_OWNED, STR_CANT_REMOVE_FOOTPATH_FROM_HERE, STR_LAND_NOT_OWNED_BY_PARK);
}

View File

@ -53,13 +53,12 @@ public:
auto res = MakeResult();
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;
res->Position = _loc;
if (!map_is_location_valid({ _loc.x, _loc.y }))
if (!map_is_location_valid(_loc))
{
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_POSITION_THIS_HERE, STR_OFF_EDGE_OF_MAP);
}
if (!((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gCheatsSandboxMode)
&& !map_is_location_owned(_loc.x, _loc.y, _loc.z / 8))
if (!((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gCheatsSandboxMode) && !map_is_location_owned(_loc))
{
return MakeResult(GA_ERROR::DISALLOWED, STR_CANT_POSITION_THIS_HERE, STR_LAND_NOT_OWNED_BY_PARK);
}

View File

@ -47,13 +47,12 @@ public:
GameActionResult::Ptr Query() const override
{
if (!map_is_location_valid({ _loc.x, _loc.y }))
if (!map_is_location_valid(_loc))
{
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_REMOVE_THIS, STR_OFF_EDGE_OF_MAP);
}
if (!((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gCheatsSandboxMode)
&& !map_is_location_owned(_loc.x, _loc.y, _loc.z / 8))
if (!((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gCheatsSandboxMode) && !map_is_location_owned(_loc))
{
return MakeResult(GA_ERROR::DISALLOWED, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK);
}

View File

@ -93,7 +93,7 @@ private:
CoordsXYZ centre{ (validRange.GetLeft() + validRange.GetRight()) / 2 + 16,
(validRange.GetTop() + validRange.GetBottom()) / 2 + 16, 0 };
centre.z = tile_element_height(centre.x, centre.y);
centre.z = tile_element_height(centre);
res->Position = centre;
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LAND_PURCHASE;
@ -125,7 +125,7 @@ private:
return MakeResult(GA_ERROR::INVALID_PARAMETERS, _ErrorTitles[0], STR_NONE);
}
SurfaceElement* surfaceElement = map_get_surface_element_at(loc)->AsSurface();
SurfaceElement* surfaceElement = map_get_surface_element_at(loc);
if (surfaceElement == nullptr)
{
log_error("Could not find surface. x = %d, y = %d", loc.x, loc.y);

View File

@ -83,26 +83,24 @@ private:
MapRange validRange = MapRange{ aX, aY, bX, bY };
res->Position = { _coords.x, _coords.y, tile_element_height(_coords.x, _coords.y) };
res->Position = { _coords.x, _coords.y, tile_element_height(_coords) };
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;
if (isExecuting)
{
audio_play_sound_at_location(SoundId::PlaceItem, _coords.x, _coords.y, tile_element_height(_coords.x, _coords.y));
audio_play_sound_at_location(SoundId::PlaceItem, { _coords.x, _coords.y, tile_element_height(_coords) });
}
uint8_t maxHeight = map_get_highest_land_height(
validRange.GetLeft(), validRange.GetRight(), validRange.GetTop(), validRange.GetBottom());
uint8_t maxHeight = map_get_highest_land_height(validRange);
for (int32_t y = validRange.GetTop(); y <= validRange.GetBottom(); y += 32)
{
for (int32_t x = validRange.GetLeft(); x <= validRange.GetRight(); x += 32)
{
TileElement* tileElement = map_get_surface_element_at(x / 32, y / 32);
if (tileElement == nullptr)
auto* surfaceElement = map_get_surface_element_at(x / 32, y / 32);
if (surfaceElement == nullptr)
continue;
SurfaceElement* surfaceElement = tileElement->AsSurface();
uint8_t height = surfaceElement->base_height;
if (surfaceElement->GetSlope() & TILE_ELEMENT_SURFACE_RAISED_CORNERS_MASK)
height += 2;

View File

@ -84,26 +84,23 @@ private:
MapRange validRange = MapRange{ aX, aY, bX, bY };
res->Position = { _coords.x, _coords.y, tile_element_height(_coords.x, _coords.y) };
res->Position = { _coords.x, _coords.y, tile_element_height(_coords) };
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;
if (isExecuting)
{
audio_play_sound_at_location(SoundId::PlaceItem, _coords.x, _coords.y, tile_element_height(_coords.x, _coords.y));
audio_play_sound_at_location(SoundId::PlaceItem, { _coords.x, _coords.y, tile_element_height(_coords) });
}
uint8_t minHeight = map_get_lowest_land_height(
validRange.GetLeft(), validRange.GetRight(), validRange.GetTop(), validRange.GetBottom());
uint8_t minHeight = map_get_lowest_land_height(validRange);
for (int32_t y = validRange.GetTop(); y <= validRange.GetBottom(); y += 32)
{
for (int32_t x = validRange.GetLeft(); x <= validRange.GetRight(); x += 32)
{
TileElement* tileElement = map_get_surface_element_at(x / 32, y / 32);
if (tileElement == nullptr)
auto* surfaceElement = map_get_surface_element_at(x / 32, y / 32);
if (surfaceElement == nullptr)
continue;
SurfaceElement* surfaceElement = tileElement->AsSurface();
uint8_t height = surfaceElement->base_height;
if (height > minHeight)

View File

@ -101,8 +101,8 @@ public:
}
}
TileElement* surfaceElement = map_get_surface_element_at(_coords);
TileElement* tileElement = CheckFloatingStructures(surfaceElement, _height);
auto* surfaceElement = map_get_surface_element_at(_coords);
TileElement* tileElement = CheckFloatingStructures(reinterpret_cast<TileElement*>(surfaceElement), _height);
if (tileElement != nullptr)
{
map_obstruction_set_error_text(tileElement);
@ -128,7 +128,7 @@ public:
GA_ERROR::DISALLOWED, STR_NONE, gGameCommandErrorText, gCommonFormatArgs);
}
tileElement = CheckUnremovableObstructions(surfaceElement, zCorner);
tileElement = CheckUnremovableObstructions(reinterpret_cast<TileElement*>(surfaceElement), zCorner);
if (tileElement != nullptr)
{
map_obstruction_set_error_text(tileElement);
@ -144,7 +144,7 @@ public:
GameActionResult::Ptr Execute() const override
{
money32 cost = MONEY(0, 0);
auto surfaceHeight = tile_element_height(_coords.x, _coords.y);
auto surfaceHeight = tile_element_height(_coords);
footpath_remove_litter(_coords.x, _coords.y, surfaceHeight);
if (!gCheatsDisableClearanceChecks)
@ -154,9 +154,9 @@ public:
SmallSceneryRemoval();
}
TileElement* surfaceElement = map_get_surface_element_at(_coords);
auto* surfaceElement = map_get_surface_element_at(_coords);
cost += GetSurfaceHeightChangeCost(surfaceElement);
SetSurfaceHeight(surfaceElement);
SetSurfaceHeight(reinterpret_cast<TileElement*>(surfaceElement));
auto res = std::make_unique<GameActionResult>();
res->Position = { _coords.x + 16, _coords.y + 16, surfaceHeight };
@ -336,7 +336,7 @@ private:
return nullptr;
}
money32 GetSurfaceHeightChangeCost(TileElement * surfaceElement) const
money32 GetSurfaceHeightChangeCost(SurfaceElement * surfaceElement) const
{
money32 cost{ 0 };
for (int32_t i = 0; i < 4; i += 1)

View File

@ -97,7 +97,7 @@ private:
CoordsXYZ centre{ (validRange.GetLeft() + validRange.GetRight()) / 2 + 16,
(validRange.GetTop() + validRange.GetBottom()) / 2 + 16, 0 };
centre.z = tile_element_height(centre.x, centre.y);
centre.z = tile_element_height(centre);
res->Position = centre;
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LAND_PURCHASE;
@ -123,14 +123,14 @@ private:
if (isExecuting)
{
map_count_remaining_land_rights();
audio_play_sound_at_location(SoundId::PlaceItem, centre.x, centre.y, centre.z);
audio_play_sound_at_location(SoundId::PlaceItem, centre);
}
return res;
}
GameActionResult::Ptr map_buy_land_rights_for_tile(const CoordsXY loc, bool isExecuting) const
{
SurfaceElement* surfaceElement = map_get_surface_element_at(loc)->AsSurface();
SurfaceElement* surfaceElement = map_get_surface_element_at(loc);
if (surfaceElement == nullptr)
{
log_error("Could not find surface. x = %d, y = %d", loc.x, loc.y);

View File

@ -72,11 +72,11 @@ public:
}
private:
GameActionResult::Ptr SmoothLandTile(int32_t direction, bool isExecuting, int32_t x, int32_t y, TileElement* surfaceElement)
const
GameActionResult::Ptr SmoothLandTile(
int32_t direction, bool isExecuting, int32_t x, int32_t y, SurfaceElement* surfaceElement) const
{
int32_t targetBaseZ = surfaceElement->base_height;
int32_t slope = surfaceElement->AsSurface()->GetSlope();
int32_t slope = surfaceElement->GetSlope();
if (_isLowering)
{
slope = tile_element_lower_styles[direction][slope];
@ -188,7 +188,7 @@ private:
// change land of current tile
int32_t targetBaseZ = surfaceElement->base_height;
int32_t slope = surfaceElement->AsSurface()->GetSlope();
int32_t slope = surfaceElement->GetSlope();
int32_t oldSlope = slope;
if (_isLowering)
{
@ -350,7 +350,7 @@ private:
auto b = std::clamp(normRange.GetBottom(), 0, (MAXIMUM_MAP_SIZE_TECHNICAL - 1) * 32);
auto validRange = MapRange{ l, t, r, b };
int32_t centreZ = tile_element_height(_coords.x, _coords.y);
int32_t centreZ = tile_element_height(_coords);
auto res = MakeResult();
res->ErrorTitle = _ErrorTitles[_isLowering ? 0 : 1];
@ -362,14 +362,8 @@ private:
{
case MAP_SELECT_TYPE_FULL:
{
uint8_t minHeight = heightOffset
+ map_get_lowest_land_height(
validRange.GetLeft(), validRange.GetRight(), validRange.GetTop(),
validRange.GetBottom());
uint8_t maxHeight = heightOffset
+ map_get_highest_land_height(
validRange.GetLeft(), validRange.GetRight(), validRange.GetTop(),
validRange.GetBottom());
uint8_t minHeight = heightOffset + map_get_lowest_land_height(validRange);
uint8_t maxHeight = heightOffset + map_get_highest_land_height(validRange);
// Smooth the 4 corners
{ // top-left
@ -398,11 +392,10 @@ private:
}
// Smooth the edges
TileElement* surfaceElement = nullptr;
int32_t z1, z2;
for (int32_t y = validRange.GetTop(); y <= validRange.GetBottom(); y += 32)
{
surfaceElement = map_get_surface_element_at({ validRange.GetLeft(), y });
auto surfaceElement = map_get_surface_element_at({ validRange.GetLeft(), y });
z1 = std::clamp((uint8_t)tile_element_get_corner_height(surfaceElement, 3), minHeight, maxHeight);
z2 = std::clamp((uint8_t)tile_element_get_corner_height(surfaceElement, 2), minHeight, maxHeight);
res->Cost += SmoothLandRowByEdge(isExecuting, { validRange.GetLeft(), y }, z1, z2, -32, 0, 0, 1, 3, 2);
@ -415,7 +408,7 @@ private:
for (int32_t x = validRange.GetLeft(); x <= validRange.GetRight(); x += 32)
{
surfaceElement = map_get_surface_element_at({ x, validRange.GetTop() });
auto surfaceElement = map_get_surface_element_at({ x, validRange.GetTop() });
z1 = std::clamp((uint8_t)tile_element_get_corner_height(surfaceElement, 1), minHeight, maxHeight);
z2 = std::clamp((uint8_t)tile_element_get_corner_height(surfaceElement, 2), minHeight, maxHeight);
res->Cost += SmoothLandRowByEdge(isExecuting, { x, validRange.GetTop() }, z1, z2, 0, -32, 0, 3, 1, 2);
@ -434,7 +427,7 @@ private:
{
auto surfaceElement = map_get_surface_element_at({ validRange.GetLeft(), validRange.GetTop() });
uint8_t newBaseZ = surfaceElement->base_height;
uint8_t newSlope = surfaceElement->AsSurface()->GetSlope();
uint8_t newSlope = surfaceElement->GetSlope();
if (raiseLand)
{
@ -531,7 +524,7 @@ private:
// Get the two corners to raise
auto surfaceElement = map_get_surface_element_at({ validRange.GetLeft(), validRange.GetTop() });
uint8_t newBaseZ = surfaceElement->base_height;
uint8_t oldSlope = surfaceElement->AsSurface()->GetSlope();
uint8_t oldSlope = surfaceElement->GetSlope();
uint8_t newSlope = oldSlope;
int32_t rowIndex = selectionType - (MAP_SELECT_TYPE_EDGE_0 - MAP_SELECT_TYPE_FULL - 1);
@ -633,7 +626,7 @@ private:
if (isExecuting)
{
audio_play_sound_at_location(SoundId::PlaceItem, _coords.x, _coords.y, centreZ);
audio_play_sound_at_location(SoundId::PlaceItem, { _coords.x, _coords.y, centreZ });
}
res->Cost += result->Cost;
return res;

View File

@ -89,7 +89,7 @@ public:
auto res = std::make_unique<LargeSceneryPlaceActionResult>();
res->ErrorTitle = STR_CANT_POSITION_THIS_HERE;
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;
int16_t surfaceHeight = tile_element_height(_loc.x, _loc.y);
int16_t surfaceHeight = tile_element_height(_loc);
res->Position.x = _loc.x + 16;
res->Position.y = _loc.y + 16;
res->Position.z = surfaceHeight;
@ -195,7 +195,7 @@ public:
return std::make_unique<LargeSceneryPlaceActionResult>(GA_ERROR::DISALLOWED, STR_OFF_EDGE_OF_MAP);
}
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !map_is_location_owned(curTile.x, curTile.y, zLow * 8)
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !map_is_location_owned({ curTile, zLow * 8 })
&& !gCheatsSandboxMode)
{
return std::make_unique<LargeSceneryPlaceActionResult>(GA_ERROR::DISALLOWED, STR_LAND_NOT_OWNED_BY_PARK);
@ -214,7 +214,7 @@ public:
auto res = std::make_unique<LargeSceneryPlaceActionResult>();
res->ErrorTitle = STR_CANT_POSITION_THIS_HERE;
int16_t surfaceHeight = tile_element_height(_loc.x, _loc.y);
int16_t surfaceHeight = tile_element_height(_loc);
res->Position.x = _loc.x + 16;
res->Position.y = _loc.y + 16;
res->Position.z = surfaceHeight;
@ -317,7 +317,7 @@ public:
}
TileElement* newTileElement = tile_element_insert(
curTile.x / 32, curTile.y / 32, zLow, quarterTile.GetBaseQuarterOccupied());
{ curTile.x / 32, curTile.y / 32, zLow }, quarterTile.GetBaseQuarterOccupied());
Guard::Assert(newTileElement != nullptr);
map_animation_create(MAP_ANIMATION_TYPE_LARGE_SCENERY, curTile.x, curTile.y, zLow);
newTileElement->SetType(TILE_ELEMENT_TYPE_LARGE_SCENERY);
@ -369,11 +369,10 @@ private:
continue;
}
TileElement* tileElement = map_get_surface_element_at({ curTile.x, curTile.y });
if (tileElement == nullptr)
auto* surfaceElement = map_get_surface_element_at(curTile);
if (surfaceElement == nullptr)
continue;
SurfaceElement* surfaceElement = tileElement->AsSurface();
int32_t height = surfaceElement->base_height * 8;
int32_t slope = surfaceElement->GetSlope();

View File

@ -56,7 +56,7 @@ public:
const uint32_t flags = GetFlags();
int32_t z = tile_element_height(_loc.x, _loc.x);
int32_t z = tile_element_height(_loc);
res->Position.x = _loc.x + 16;
res->Position.y = _loc.y + 16;
res->Position.z = z;
@ -96,7 +96,7 @@ public:
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode)
{
if (!map_is_location_owned(currentTile.x, currentTile.y, currentTile.z))
if (!map_is_location_owned({ currentTile.x, currentTile.y, currentTile.z }))
{
return MakeResult(GA_ERROR::NO_CLEARANCE, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK);
}
@ -126,7 +126,7 @@ public:
const uint32_t flags = GetFlags();
int32_t z = tile_element_height(_loc.x, _loc.y);
int32_t z = tile_element_height(_loc);
res->Position.x = _loc.x + 16;
res->Position.y = _loc.y + 16;
res->Position.z = z;
@ -167,7 +167,7 @@ public:
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode)
{
if (!map_is_location_owned(currentTile.x, currentTile.y, currentTile.z))
if (!map_is_location_owned({ currentTile.x, currentTile.y, currentTile.z }))
{
return MakeResult(GA_ERROR::NO_CLEARANCE, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK);
}

View File

@ -62,7 +62,7 @@ private:
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;
res->Position.x = _loc.x + 16;
res->Position.y = _loc.y + 16;
res->Position.z = tile_element_height(_loc.x, _loc.y);
res->Position.z = tile_element_height(_loc);
res->ErrorTitle = STR_CANT_REPAINT_THIS;
if (_loc.x < 0 || _loc.y < 0 || _loc.x > gMapSizeMaxXY || _loc.y > gMapSizeMaxXY)
@ -124,7 +124,7 @@ private:
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode)
{
if (!map_is_location_owned(currentTile.x, currentTile.y, currentTile.z))
if (!map_is_location_owned(currentTile))
{
return MakeResult(GA_ERROR::NOT_OWNED, STR_CANT_REPAINT_THIS, STR_LAND_NOT_OWNED_BY_PARK);
}

View File

@ -94,15 +94,15 @@ public:
return res;
}
if (!map_is_location_owned(floor2(_loc.x, 32), floor2(_loc.y, 32), _loc.z) && !gCheatsSandboxMode)
if (!map_is_location_owned(_loc) && !gCheatsSandboxMode)
{
res->Error = GA_ERROR::NOT_OWNED;
res->ErrorMessage = STR_LAND_NOT_OWNED_BY_PARK;
return res;
}
TileElement* tileElement = map_get_surface_element_at(_loc.x / 32, _loc.y / 32);
if (tileElement == nullptr)
auto surfaceElement = map_get_surface_element_at(_loc);
if (surfaceElement == nullptr)
{
res->Error = GA_ERROR::UNKNOWN;
res->ErrorMessage = STR_INVALID_SELECTION_OF_OBJECTS;
@ -112,7 +112,7 @@ public:
uint8_t baseHeight = _loc.z / 8;
uint8_t clearanceHeight = (_loc.z + 32) / 8;
int8_t heightDifference = baseHeight - tileElement->base_height;
int8_t heightDifference = baseHeight - surfaceElement->base_height;
if (heightDifference >= 0 && !gCheatsDisableSupportLimits)
{
heightDifference = heightDifference >> 1;
@ -125,7 +125,8 @@ public:
}
}
tileElement = map_get_track_element_at_of_type_from_ride(_loc.x, _loc.y, baseHeight, TRACK_ELEM_MAZE, _rideIndex);
TileElement* tileElement = map_get_track_element_at_of_type_from_ride(
_loc.x, _loc.y, baseHeight, TRACK_ELEM_MAZE, _rideIndex);
if (tileElement == nullptr)
{
if (_mode != GC_SET_MAZE_TRACK_BUILD)
@ -215,7 +216,7 @@ public:
uint16_t flooredX = floor2(_loc.x, 32);
uint16_t flooredY = floor2(_loc.y, 32);
tileElement = tile_element_insert(_loc.x / 32, _loc.y / 32, baseHeight, 0xF);
tileElement = tile_element_insert({ _loc.x / 32, _loc.y / 32, baseHeight }, 0xF);
assert(tileElement != nullptr);
tileElement->clearance_height = clearanceHeight;

View File

@ -142,11 +142,11 @@ public:
if (!(flags & GAME_COMMAND_FLAG_GHOST))
{
SurfaceElement* surfaceElement = map_get_surface_element_at(entranceLoc)->AsSurface();
SurfaceElement* surfaceElement = map_get_surface_element_at(entranceLoc);
surfaceElement->SetOwnership(OWNERSHIP_UNOWNED);
}
TileElement* newElement = tile_element_insert(entranceLoc.x / 32, entranceLoc.y / 32, zLow, 0xF);
TileElement* newElement = tile_element_insert({ entranceLoc.x / 32, entranceLoc.y / 32, zLow }, 0xF);
Guard::Assert(newElement != nullptr);
newElement->SetType(TILE_ELEMENT_TYPE_ENTRANCE);
auto entranceElement = newElement->AsEntrance();

View File

@ -71,22 +71,21 @@ public:
GA_ERROR::INVALID_PARAMETERS, STR_ERR_CANT_PLACE_PEEP_SPAWN_HERE, STR_OFF_EDGE_OF_MAP);
}
TileElement *mapElement, *surfaceMapElement;
// Verify footpath exists at location, and retrieve coordinates
mapElement = map_get_path_element_at(_location.x >> 5, _location.y >> 5, _location.z / 8);
if (mapElement == nullptr)
auto pathElement = map_get_path_element_at({ _location.x >> 5, _location.y >> 5, _location.z / 8 });
if (pathElement == nullptr)
{
return std::make_unique<GameActionResult>(
GA_ERROR::INVALID_PARAMETERS, STR_ERR_CANT_PLACE_PEEP_SPAWN_HERE, STR_CAN_ONLY_BE_BUILT_ACROSS_PATHS);
}
// Verify location is unowned
surfaceMapElement = map_get_surface_element_at(_location.x >> 5, _location.y >> 5);
auto surfaceMapElement = map_get_surface_element_at(_location);
if (surfaceMapElement == nullptr)
{
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_ERR_CANT_PLACE_PEEP_SPAWN_HERE, STR_NONE);
}
if (surfaceMapElement->AsSurface()->GetOwnership() != OWNERSHIP_UNOWNED)
if (surfaceMapElement->GetOwnership() != OWNERSHIP_UNOWNED)
{
return std::make_unique<GameActionResult>(
GA_ERROR::INVALID_PARAMETERS, STR_ERR_CANT_PLACE_PEEP_SPAWN_HERE, STR_ERR_MUST_BE_OUTSIDE_PARK_BOUNDARIES);

View File

@ -238,7 +238,7 @@ private:
{
int32_t x = (ride->overall_view.x * 32) + 16;
int32_t y = (ride->overall_view.y * 32) + 16;
int32_t z = tile_element_height(x, y);
int32_t z = tile_element_height({ x, y });
res->Position = { x, y, z };
}
@ -366,7 +366,7 @@ private:
{
int32_t x = (ride->overall_view.x * 32) + 16;
int32_t y = (ride->overall_view.y * 32) + 16;
int32_t z = tile_element_height(x, y);
int32_t z = tile_element_height({ x, y });
res->Position = { x, y, z };
}

View File

@ -102,7 +102,7 @@ public:
auto z = ride->stations[_stationNum].Height * 8;
gCommandPosition.z = z;
if (!gCheatsSandboxMode && !map_is_location_owned(_loc.x, _loc.y, z))
if (!gCheatsSandboxMode && !map_is_location_owned({ _loc, z }))
{
return MakeResult(GA_ERROR::NOT_OWNED, errorTitle);
}
@ -129,7 +129,7 @@ public:
auto res = MakeResult();
res->Position.x = _loc.x + 16;
res->Position.y = _loc.y + 16;
res->Position.z = tile_element_height(_loc.x, _loc.y);
res->Position.z = tile_element_height(_loc);
res->ExpenditureType = RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION;
return res;
}
@ -189,10 +189,10 @@ public:
auto res = MakeResult();
res->Position.x = _loc.x + 16;
res->Position.y = _loc.y + 16;
res->Position.z = tile_element_height(_loc.x, _loc.y);
res->Position.z = tile_element_height(_loc);
res->ExpenditureType = RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION;
TileElement* tileElement = tile_element_insert(_loc.x / 32, _loc.y / 32, z / 8, 0b1111);
TileElement* tileElement = tile_element_insert({ _loc.x / 32, _loc.y / 32, z / 8 }, 0b1111);
assert(tileElement != nullptr);
tileElement->SetType(TILE_ELEMENT_TYPE_ENTRANCE);
tileElement->SetDirection(_direction);
@ -245,7 +245,7 @@ public:
return MakeResult(GA_ERROR::NO_FREE_ELEMENTS, errorTitle);
}
if (!gCheatsSandboxMode && !map_is_location_owned(loc.x, loc.y, loc.z))
if (!gCheatsSandboxMode && !map_is_location_owned(loc))
{
return MakeResult(GA_ERROR::NOT_OWNED, errorTitle);
}
@ -272,7 +272,7 @@ public:
auto res = MakeResult();
res->Position.x = loc.x + 16;
res->Position.y = loc.y + 16;
res->Position.z = tile_element_height(loc.x, loc.y);
res->Position.z = tile_element_height(loc);
res->ExpenditureType = RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION;
return res;
}

View File

@ -168,7 +168,7 @@ public:
auto res = MakeResult();
res->Position.x = _loc.x + 16;
res->Position.y = _loc.y + 16;
res->Position.z = tile_element_height(res->Position.x, res->Position.y);
res->Position.z = tile_element_height(res->Position);
footpath_queue_chain_reset();
maze_entrance_hedge_replacement(_loc.x, _loc.y, tileElement);

View File

@ -163,7 +163,7 @@ public:
{
res->Position.x = ride->overall_view.x * 32 + 16;
res->Position.y = ride->overall_view.y * 32 + 16;
res->Position.z = tile_element_height(res->Position.x, res->Position.y);
res->Position.z = tile_element_height(res->Position);
}
return res;

View File

@ -97,7 +97,7 @@ public:
auto res = std::make_unique<GameActionResult>();
res->Position.x = ride->overall_view.x * 32 + 16;
res->Position.y = ride->overall_view.y * 32 + 16;
res->Position.z = tile_element_height(res->Position.x, res->Position.y);
res->Position.z = tile_element_height(res->Position);
return res;
}

View File

@ -97,7 +97,7 @@ public:
{
res->Position.x = ride->overall_view.x * 32 + 16;
res->Position.y = ride->overall_view.y * 32 + 16;
res->Position.z = tile_element_height(res->Position.x, res->Position.y);
res->Position.z = tile_element_height(res->Position);
}
uint32_t shopItem;

View File

@ -246,7 +246,7 @@ public:
{
res->Position.x = ride->overall_view.x * 32 + 16;
res->Position.y = ride->overall_view.y * 32 + 16;
res->Position.z = tile_element_height(res->Position.x, res->Position.y);
res->Position.z = tile_element_height(res->Position);
}
window_invalidate_by_number(WC_RIDE, _rideIndex);
return res;

View File

@ -124,7 +124,7 @@ public:
{
res->Position.x = ride->overall_view.x * 32 + 16;
res->Position.y = ride->overall_view.y * 32 + 16;
res->Position.z = tile_element_height(res->Position.x, res->Position.y);
res->Position.z = tile_element_height(res->Position);
}
switch (_status)

View File

@ -205,7 +205,7 @@ public:
{
res->Position.x = ride->overall_view.x * 32 + 16;
res->Position.y = ride->overall_view.y * 32 + 16;
res->Position.z = tile_element_height(res->Position.x, res->Position.y);
res->Position.z = tile_element_height(res->Position);
}
auto intent = Intent(INTENT_ACTION_RIDE_PAINT_RESET_VEHICLE);

View File

@ -356,11 +356,10 @@ private:
{
for (x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++)
{
auto tileElement = map_get_surface_element_at(x, y);
if (tileElement == nullptr)
auto surfaceElement = map_get_surface_element_at(x, y);
if (surfaceElement == nullptr)
continue;
auto surfaceElement = tileElement->AsSurface();
if (surfaceElement != nullptr && (surfaceElement->GetOwnership() & OWNERSHIP_OWNED)
&& surfaceElement->GetWaterHeight() == 0 && surfaceElement->CanGrassGrow())
{
@ -728,12 +727,12 @@ private:
{
for (coords.x = min; coords.x <= max; coords.x += 32)
{
TileElement* surfaceElement = map_get_surface_element_at(coords);
auto* surfaceElement = map_get_surface_element_at(coords);
if (surfaceElement == nullptr)
continue;
// Ignore already owned tiles.
if (surfaceElement->AsSurface()->GetOwnership() & OWNERSHIP_OWNED)
if (surfaceElement->GetOwnership() & OWNERSHIP_OWNED)
continue;
int32_t base_z = surfaceElement->base_height;
@ -742,7 +741,7 @@ private:
// only own tiles that were not set to 0
if (destOwnership != OWNERSHIP_UNOWNED)
{
surfaceElement->AsSurface()->SetOwnership(destOwnership);
surfaceElement->SetOwnership(destOwnership);
update_park_fences_around_tile(coords);
uint16_t baseHeight = surfaceElement->base_height * 8;
map_invalidate_tile(coords.x, coords.y, baseHeight, baseHeight + 16);
@ -757,8 +756,8 @@ private:
int32_t y = spawn.y;
if (x != PEEP_SPAWN_UNDEFINED)
{
TileElement* surfaceElement = map_get_surface_element_at({ x, y });
surfaceElement->AsSurface()->SetOwnership(OWNERSHIP_UNOWNED);
auto* surfaceElement = map_get_surface_element_at({ x, y });
surfaceElement->SetOwnership(OWNERSHIP_UNOWNED);
update_park_fences_around_tile({ x, y });
uint16_t baseHeight = surfaceElement->base_height * 8;
map_invalidate_tile(x, y, baseHeight, baseHeight + 16);

View File

@ -99,8 +99,8 @@ public:
{
supportsRequired = true;
}
int32_t landHeight = tile_element_height(_loc.x, _loc.y);
int16_t waterHeight = tile_element_water_height(_loc.x, _loc.y);
int32_t landHeight = tile_element_height(_loc);
int16_t waterHeight = tile_element_water_height(_loc);
int32_t surfaceHeight = landHeight;
// If on water
@ -159,8 +159,8 @@ public:
x2 += ScenerySubTileOffsets[quadrant & 3].x - 1;
y2 += ScenerySubTileOffsets[quadrant & 3].y - 1;
}
landHeight = tile_element_height(x2, y2);
waterHeight = tile_element_water_height(x2, y2);
landHeight = tile_element_height({ x2, y2 });
waterHeight = tile_element_water_height({ x2, y2 });
surfaceHeight = landHeight;
// If on water
@ -180,16 +180,16 @@ public:
}
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode
&& !map_is_location_owned(_loc.x, _loc.y, targetHeight))
&& !map_is_location_owned({ _loc.x, _loc.y, targetHeight }))
{
return std::make_unique<SmallSceneryPlaceActionResult>(GA_ERROR::NOT_OWNED, STR_LAND_NOT_OWNED_BY_PARK);
}
TileElement* surfaceElement = map_get_surface_element_at({ _loc.x, _loc.y });
auto* surfaceElement = map_get_surface_element_at(_loc);
if (surfaceElement != nullptr && !gCheatsDisableClearanceChecks && surfaceElement->AsSurface()->GetWaterHeight() > 0)
if (surfaceElement != nullptr && !gCheatsDisableClearanceChecks && surfaceElement->GetWaterHeight() > 0)
{
int32_t water_height = (surfaceElement->AsSurface()->GetWaterHeight() * 16) - 1;
int32_t water_height = (surfaceElement->GetWaterHeight() * 16) - 1;
if (water_height > targetHeight)
{
return std::make_unique<SmallSceneryPlaceActionResult>(GA_ERROR::DISALLOWED, STR_CANT_BUILD_THIS_UNDERWATER);
@ -203,9 +203,9 @@ public:
return std::make_unique<SmallSceneryPlaceActionResult>(GA_ERROR::DISALLOWED, STR_CAN_ONLY_BUILD_THIS_ON_LAND);
}
if (surfaceElement != nullptr && surfaceElement->AsSurface()->GetWaterHeight() > 0)
if (surfaceElement != nullptr && surfaceElement->GetWaterHeight() > 0)
{
if (static_cast<int32_t>((surfaceElement->AsSurface()->GetWaterHeight() * 16)) > targetHeight)
if (static_cast<int32_t>((surfaceElement->GetWaterHeight() * 16)) > targetHeight)
{
return std::make_unique<SmallSceneryPlaceActionResult>(
GA_ERROR::DISALLOWED, STR_CAN_ONLY_BUILD_THIS_ON_LAND);
@ -215,7 +215,7 @@ public:
if (!gCheatsDisableClearanceChecks
&& (scenery_small_entry_has_flag(sceneryEntry, SMALL_SCENERY_FLAG_REQUIRE_FLAT_SURFACE)) && !supportsRequired
&& !isOnWater && surfaceElement != nullptr && (surfaceElement->AsSurface()->GetSlope() != TILE_ELEMENT_SLOPE_FLAT))
&& !isOnWater && surfaceElement != nullptr && (surfaceElement->GetSlope() != TILE_ELEMENT_SLOPE_FLAT))
{
return std::make_unique<SmallSceneryPlaceActionResult>(GA_ERROR::DISALLOWED, STR_LEVEL_LAND_REQUIRED);
}
@ -227,7 +227,7 @@ public:
{
if (surfaceElement != nullptr)
{
if (surfaceElement->AsSurface()->GetWaterHeight() || (surfaceElement->base_height * 8) != targetHeight)
if (surfaceElement->GetWaterHeight() || (surfaceElement->base_height * 8) != targetHeight)
{
return std::make_unique<SmallSceneryPlaceActionResult>(GA_ERROR::DISALLOWED, STR_LEVEL_LAND_REQUIRED);
}
@ -302,8 +302,8 @@ public:
{
supportsRequired = true;
}
int32_t landHeight = tile_element_height(_loc.x, _loc.y);
int16_t waterHeight = tile_element_water_height(_loc.x, _loc.y);
int32_t landHeight = tile_element_height(_loc);
int16_t waterHeight = tile_element_water_height(_loc);
int32_t surfaceHeight = landHeight;
// If on water
@ -352,8 +352,8 @@ public:
x2 += ScenerySubTileOffsets[quadrant & 3].x - 1;
y2 += ScenerySubTileOffsets[quadrant & 3].y - 1;
}
landHeight = tile_element_height(x2, y2);
waterHeight = tile_element_water_height(x2, y2);
landHeight = tile_element_height({ x2, y2 });
waterHeight = tile_element_water_height({ x2, y2 });
surfaceHeight = landHeight;
// If on water
@ -430,7 +430,7 @@ public:
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;
res->Cost = (sceneryEntry->small_scenery.price * 10) + clearCost;
TileElement* newElement = tile_element_insert(_loc.x / 32, _loc.y / 32, zLow, quarterTile.GetBaseQuarterOccupied());
TileElement* newElement = tile_element_insert({ _loc.x / 32, _loc.y / 32, zLow }, quarterTile.GetBaseQuarterOccupied());
assert(newElement != nullptr);
res->tileElement = newElement;
newElement->SetType(TILE_ELEMENT_TYPE_SMALL_SCENERY);

View File

@ -56,7 +56,7 @@ public:
{
GameActionResult::Ptr res = std::make_unique<GameActionResult>();
if (!map_is_location_valid({ _loc.x, _loc.y }))
if (!map_is_location_valid(_loc))
{
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK);
}
@ -86,7 +86,7 @@ public:
}
// Check if the land is owned
if (!map_is_location_owned(_loc.x, _loc.y, _loc.z))
if (!map_is_location_owned(_loc))
{
res->Error = GA_ERROR::NO_CLEARANCE;
res->ErrorTitle = STR_CANT_REMOVE_THIS;
@ -124,7 +124,7 @@ public:
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS);
}
res->Position.z = tile_element_height(res->Position.x, res->Position.y);
res->Position.z = tile_element_height(res->Position);
map_invalidate_tile_full(_loc.x, _loc.y);
tile_element_remove(tileElement);

View File

@ -84,7 +84,7 @@ private:
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode)
{
if (!map_is_location_owned(_loc.x, _loc.y, _loc.z))
if (!map_is_location_owned(_loc))
{
return MakeResult(GA_ERROR::NOT_OWNED, STR_CANT_REPAINT_THIS, STR_LAND_NOT_OWNED_BY_PARK);
}

View File

@ -274,7 +274,7 @@ private:
uint32_t count = 0;
uint16_t sprite_index;
Peep* guest = nullptr;
TileElement* guest_tile = nullptr;
PathElement* guest_tile = nullptr;
// Count number of walking guests
FOR_ALL_GUESTS (sprite_index, guest)
@ -282,7 +282,7 @@ private:
if (guest->state == PEEP_STATE_WALKING)
{
// Check the walking guest's tile. Only count them if they're on a path tile.
guest_tile = map_get_path_element_at(guest->next_x / 32, guest->next_y / 32, guest->next_z);
guest_tile = map_get_path_element_at({ guest->next_x / 32, guest->next_y / 32, guest->next_z });
if (guest_tile != nullptr)
++count;
}
@ -296,7 +296,7 @@ private:
{
if (guest->state == PEEP_STATE_WALKING)
{
guest_tile = map_get_path_element_at(guest->next_x / 32, guest->next_y / 32, guest->next_z);
guest_tile = map_get_path_element_at({ guest->next_x / 32, guest->next_y / 32, guest->next_z });
if (guest_tile != nullptr)
{
if (rand == 0)

View File

@ -99,7 +99,7 @@ public:
auto xMid = (validRange.GetLeft() + validRange.GetRight()) / 2 + 16;
auto yMid = (validRange.GetTop() + validRange.GetBottom()) / 2 + 16;
auto heightMid = tile_element_height(xMid, yMid);
auto heightMid = tile_element_height({ xMid, yMid });
res->Position.x = xMid;
res->Position.y = yMid;
@ -124,13 +124,12 @@ public:
continue;
}
auto tileElement = map_get_surface_element_at({ x, y });
if (tileElement == nullptr)
auto surfaceElement = map_get_surface_element_at({ x, y });
if (surfaceElement == nullptr)
{
continue;
}
auto surfaceElement = tileElement->AsSurface();
if (_surfaceStyle != 0xFF)
{
uint8_t curSurfaceStyle = surfaceElement->GetSurfaceStyle();
@ -178,7 +177,7 @@ public:
auto xMid = (validRange.GetLeft() + validRange.GetRight()) / 2 + 16;
auto yMid = (validRange.GetTop() + validRange.GetBottom()) / 2 + 16;
auto heightMid = tile_element_height(xMid, yMid);
auto heightMid = tile_element_height({ xMid, yMid });
res->Position.x = xMid;
res->Position.y = yMid;
@ -196,13 +195,12 @@ public:
continue;
}
auto tileElement = map_get_surface_element_at({ x, y });
if (tileElement == nullptr)
auto surfaceElement = map_get_surface_element_at({ x, y });
if (surfaceElement == nullptr)
{
continue;
}
auto surfaceElement = tileElement->AsSurface();
if (_surfaceStyle != 0xFF)
{
uint8_t curSurfaceStyle = surfaceElement->GetSurfaceStyle();
@ -219,7 +217,7 @@ public:
surfaceElement->SetSurfaceStyle(_surfaceStyle);
map_invalidate_tile_full(x, y);
footpath_remove_litter(x, y, tile_element_height(x, y));
footpath_remove_litter(x, y, tile_element_height({ x, y }));
}
}
}

View File

@ -255,7 +255,7 @@ private:
res->Position.x = _loc.x;
res->Position.y = _loc.y;
res->Position.z = tile_element_height(_loc.x, _loc.y);
res->Position.z = tile_element_height(_loc);
return res;
}

View File

@ -160,7 +160,6 @@ public:
}
money32 cost = 0;
TileElement* tileElement;
const rct_preview_track* trackBlock = get_track_def_from_ride(ride, _trackType);
uint32_t numElements = 0;
// First check if any of the track pieces are outside the park
@ -172,7 +171,7 @@ public:
tileCoords.x += track.x;
tileCoords.y += track.y;
if (!map_is_location_owned(tileCoords.x, tileCoords.y, tileCoords.z) && !gCheatsSandboxMode)
if (!map_is_location_owned(tileCoords) && !gCheatsSandboxMode)
{
return std::make_unique<TrackPlaceActionResult>(GA_ERROR::DISALLOWED, STR_LAND_NOT_OWNED_BY_PARK);
}
@ -309,9 +308,9 @@ public:
if ((rideTypeFlags & RIDE_TYPE_FLAG_TRACK_MUST_BE_ON_WATER) && !byte_9D8150)
{
tileElement = map_get_surface_element_at({ mapLoc.x, mapLoc.y });
auto surfaceElement = map_get_surface_element_at(mapLoc);
uint8_t waterHeight = tileElement->AsSurface()->GetWaterHeight() * 2;
uint8_t waterHeight = surfaceElement->GetWaterHeight() * 2;
if (waterHeight == 0)
{
return std::make_unique<TrackPlaceActionResult>(GA_ERROR::DISALLOWED, STR_CAN_ONLY_BUILD_THIS_ON_WATER);
@ -322,9 +321,9 @@ public:
return std::make_unique<TrackPlaceActionResult>(GA_ERROR::DISALLOWED, STR_CAN_ONLY_BUILD_THIS_ON_WATER);
}
waterHeight -= 2;
if (waterHeight == tileElement->base_height)
if (waterHeight == surfaceElement->base_height)
{
uint8_t slope = tileElement->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP;
uint8_t slope = surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP;
if (slope == TILE_ELEMENT_SLOPE_W_CORNER_DN || slope == TILE_ELEMENT_SLOPE_S_CORNER_DN
|| slope == TILE_ELEMENT_SLOPE_E_CORNER_DN || slope == TILE_ELEMENT_SLOPE_N_CORNER_DN)
{
@ -351,10 +350,10 @@ public:
}
// 6c5648 12 push
tileElement = map_get_surface_element_at({ mapLoc.x, mapLoc.y });
auto surfaceElement = map_get_surface_element_at(mapLoc);
if (!gCheatsDisableSupportLimits)
{
int32_t ride_height = clearanceZ - tileElement->base_height;
int32_t ride_height = clearanceZ - surfaceElement->base_height;
if (ride_height >= 0)
{
uint16_t maxHeight;
@ -381,7 +380,7 @@ public:
}
}
int32_t supportHeight = baseZ - tileElement->base_height;
int32_t supportHeight = baseZ - surfaceElement->base_height;
if (supportHeight < 0)
{
supportHeight = 10;
@ -435,7 +434,6 @@ public:
}
money32 cost = 0;
TileElement* tileElement;
const rct_preview_track* trackBlock = get_track_def_from_ride(ride, _trackType);
trackBlock = get_track_def_from_ride(ride, _trackType);
@ -507,9 +505,9 @@ public:
res->GroundFlags = mapGroundFlags;
// 6c5648 12 push
tileElement = map_get_surface_element_at({ mapLoc.x, mapLoc.y });
auto surfaceElement = map_get_surface_element_at(mapLoc);
int32_t supportHeight = baseZ - tileElement->base_height;
int32_t supportHeight = baseZ - surfaceElement->base_height;
if (supportHeight < 0)
{
supportHeight = 10;
@ -581,7 +579,8 @@ public:
ride->overall_view.y = mapLoc.y / 32;
}
tileElement = tile_element_insert(mapLoc.x / 32, mapLoc.y / 32, baseZ, quarterTile.GetBaseQuarterOccupied());
auto tileElement = tile_element_insert(
{ mapLoc.x / 32, mapLoc.y / 32, baseZ }, quarterTile.GetBaseQuarterOccupied());
assert(tileElement != nullptr);
tileElement->clearance_height = clearanceZ;
tileElement->SetType(TILE_ELEMENT_TYPE_TRACK);
@ -673,9 +672,9 @@ public:
if (rideTypeFlags & RIDE_TYPE_FLAG_TRACK_MUST_BE_ON_WATER)
{
TileElement* surfaceElement = map_get_surface_element_at({ mapLoc.x, mapLoc.y });
surfaceElement->AsSurface()->SetHasTrackThatNeedsWater(true);
tileElement = surfaceElement;
auto* waterSurfaceElement = map_get_surface_element_at(mapLoc);
waterSurfaceElement->SetHasTrackThatNeedsWater(true);
tileElement = reinterpret_cast<TileElement*>(waterSurfaceElement);
}
if (!gCheatsDisableClearanceChecks || !(GetFlags() & GAME_COMMAND_FLAG_GHOST))

View File

@ -216,7 +216,7 @@ public:
}
}
TileElement* surfaceElement = map_get_surface_element_at({ mapLoc.x, mapLoc.y });
auto* surfaceElement = map_get_surface_element_at(mapLoc);
if (surfaceElement == nullptr)
{
log_warning("Surface Element not found. x = %d, y = %d", mapLoc.x, mapLoc.y);
@ -411,7 +411,7 @@ public:
}
}
TileElement* surfaceElement = map_get_surface_element_at({ mapLoc.x, mapLoc.y });
auto* surfaceElement = map_get_surface_element_at(mapLoc);
if (surfaceElement == nullptr)
{
log_warning("Surface Element not found. x = %d, y = %d", mapLoc.x, mapLoc.y);
@ -437,7 +437,7 @@ public:
if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_TRACK_MUST_BE_ON_WATER))
{
surfaceElement->AsSurface()->SetHasTrackThatNeedsWater(false);
surfaceElement->SetHasTrackThatNeedsWater(false);
}
invalidate_test_results(ride);

View File

@ -109,7 +109,7 @@ public:
if (_loc.z == 0)
{
res->Position.z = tile_element_height(res->Position.x, res->Position.y);
res->Position.z = tile_element_height(res->Position);
}
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !(GetFlags() & GAME_COMMAND_FLAG_PATH_SCENERY)
@ -117,12 +117,12 @@ public:
{
if (_loc.z == 0)
{
if (!map_is_location_in_park({ _loc.x, _loc.y }))
if (!map_is_location_in_park(_loc))
{
return std::make_unique<WallPlaceActionResult>(GA_ERROR::NOT_OWNED);
}
}
else if (!map_is_location_owned(_loc.x, _loc.y, _loc.z))
else if (!map_is_location_owned(_loc))
{
return std::make_unique<WallPlaceActionResult>(GA_ERROR::NOT_OWNED);
}
@ -142,7 +142,7 @@ public:
auto targetHeight = _loc.z;
if (targetHeight == 0)
{
TileElement* surfaceElement = map_get_surface_element_at({ _loc.x, _loc.y });
auto* surfaceElement = map_get_surface_element_at(_loc);
if (surfaceElement == nullptr)
{
log_error("Surface element not found at %d, %d.", _loc.x, _loc.y);
@ -150,7 +150,7 @@ public:
}
targetHeight = surfaceElement->base_height * 8;
uint8_t slope = surfaceElement->AsSurface()->GetSlope();
uint8_t slope = surfaceElement->GetSlope();
edgeSlope = EdgeSlopes[slope][_edge & 3];
if (edgeSlope & EDGE_SLOPE_ELEVATED)
{
@ -159,16 +159,16 @@ public:
}
}
TileElement* surfaceElement = map_get_surface_element_at({ _loc.x, _loc.y });
auto* surfaceElement = map_get_surface_element_at(_loc);
if (surfaceElement == nullptr)
{
log_error("Surface element not found at %d, %d.", _loc.x, _loc.y);
return std::make_unique<WallPlaceActionResult>(GA_ERROR::INVALID_PARAMETERS);
}
if (surfaceElement->AsSurface()->GetWaterHeight() > 0)
if (surfaceElement->GetWaterHeight() > 0)
{
uint16_t waterHeight = surfaceElement->AsSurface()->GetWaterHeight() * 16;
uint16_t waterHeight = surfaceElement->GetWaterHeight() * 16;
if (targetHeight < waterHeight && !gCheatsDisableClearanceChecks)
{
@ -186,21 +186,21 @@ public:
uint8_t newEdge = (_edge + 2) & 3;
uint8_t newBaseHeight = surfaceElement->base_height;
newBaseHeight += 2;
if (surfaceElement->AsSurface()->GetSlope() & (1 << newEdge))
if (surfaceElement->GetSlope() & (1 << newEdge))
{
if (targetHeight / 8 < newBaseHeight)
{
return std::make_unique<WallPlaceActionResult>(GA_ERROR::DISALLOWED, STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND);
}
if (surfaceElement->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
if (surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
{
newEdge = (newEdge - 1) & 3;
if (surfaceElement->AsSurface()->GetSlope() & (1 << newEdge))
if (surfaceElement->GetSlope() & (1 << newEdge))
{
newEdge = (newEdge + 2) & 3;
if (surfaceElement->AsSurface()->GetSlope() & (1 << newEdge))
if (surfaceElement->GetSlope() & (1 << newEdge))
{
newBaseHeight += 2;
if (targetHeight / 8 < newBaseHeight)
@ -215,21 +215,21 @@ public:
}
newEdge = (_edge + 3) & 3;
if (surfaceElement->AsSurface()->GetSlope() & (1 << newEdge))
if (surfaceElement->GetSlope() & (1 << newEdge))
{
if (targetHeight / 8 < newBaseHeight)
{
return std::make_unique<WallPlaceActionResult>(GA_ERROR::DISALLOWED, STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND);
}
if (surfaceElement->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
if (surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
{
newEdge = (newEdge - 1) & 3;
if (surfaceElement->AsSurface()->GetSlope() & (1 << newEdge))
if (surfaceElement->GetSlope() & (1 << newEdge))
{
newEdge = (newEdge + 2) & 3;
if (surfaceElement->AsSurface()->GetSlope() & (1 << newEdge))
if (surfaceElement->GetSlope() & (1 << newEdge))
{
newBaseHeight += 2;
if (targetHeight / 8 < newBaseHeight)
@ -309,14 +309,14 @@ public:
if (res->Position.z == 0)
{
res->Position.z = tile_element_height(res->Position.x, res->Position.y);
res->Position.z = tile_element_height(res->Position);
}
uint8_t edgeSlope = 0;
auto targetHeight = _loc.z;
if (targetHeight == 0)
{
TileElement* surfaceElement = map_get_surface_element_at({ _loc.x, _loc.y });
auto* surfaceElement = map_get_surface_element_at(_loc);
if (surfaceElement == nullptr)
{
log_error("Surface element not found at %d, %d.", _loc.x, _loc.y);
@ -324,7 +324,7 @@ public:
}
targetHeight = surfaceElement->base_height * 8;
uint8_t slope = surfaceElement->AsSurface()->GetSlope();
uint8_t slope = surfaceElement->GetSlope();
edgeSlope = EdgeSlopes[slope][_edge & 3];
if (edgeSlope & EDGE_SLOPE_ELEVATED)
{
@ -394,7 +394,7 @@ public:
return std::make_unique<WallPlaceActionResult>(GA_ERROR::NO_FREE_ELEMENTS, gGameCommandErrorText);
}
TileElement* tileElement = tile_element_insert(_loc.x / 32, _loc.y / 32, targetHeight / 8, 0);
TileElement* tileElement = tile_element_insert({ _loc.x / 32, _loc.y / 32, targetHeight / 8 }, 0);
assert(tileElement != nullptr);
map_animation_create(MAP_ANIMATION_TYPE_WALL, _loc.x, _loc.y, targetHeight / 8);
@ -613,7 +613,7 @@ private:
*wallAcrossTrack = false;
gMapGroundFlags = ELEMENT_IS_ABOVE_GROUND;
if (map_is_location_at_edge(_loc.x, _loc.y))
if (map_is_location_at_edge(_loc))
{
gGameCommandErrorText = STR_OFF_EDGE_OF_MAP;
return false;

View File

@ -44,15 +44,14 @@ public:
res->Cost = 0;
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;
if (!map_is_location_valid({ _loc.x, _loc.y }))
if (!map_is_location_valid(_loc))
{
return std::make_unique<GameActionResult>(
GA_ERROR::INVALID_PARAMETERS, STR_CANT_REMOVE_THIS, STR_INVALID_SELECTION_OF_OBJECTS);
}
const bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST;
if (!isGhost && !(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode
&& !map_is_location_owned(_loc.x, _loc.y, _loc.z))
if (!isGhost && !(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode && !map_is_location_owned(_loc))
{
return std::make_unique<GameActionResult>(GA_ERROR::NOT_OWNED, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK);
}
@ -85,7 +84,7 @@ public:
res->Position.x = _loc.x + 16;
res->Position.y = _loc.y + 16;
res->Position.z = tile_element_height(res->Position.x, res->Position.y);
res->Position.z = tile_element_height(res->Position);
tile_element_remove_banner_entry(wallElement);
map_invalidate_tile_zoom1(_loc.x, _loc.y, wallElement->base_height * 8, (wallElement->base_height * 8) + 72);

View File

@ -65,8 +65,7 @@ public:
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !map_is_location_in_park({ _loc.x, _loc.y })
&& !gCheatsSandboxMode)
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !map_is_location_in_park(_loc) && !gCheatsSandboxMode)
{
return MakeResult(GA_ERROR::NOT_OWNED, STR_CANT_REPAINT_THIS, STR_LAND_NOT_OWNED_BY_PARK);
}

View File

@ -63,8 +63,8 @@ private:
res->Position.x = ((validRange.GetLeft() + validRange.GetRight()) / 2) + 16;
res->Position.y = ((validRange.GetTop() + validRange.GetBottom()) / 2) + 16;
int16_t z = tile_element_height(res->Position.x, res->Position.y);
int16_t waterHeight = tile_element_water_height(res->Position.x, res->Position.y);
int16_t z = tile_element_height(res->Position);
int16_t waterHeight = tile_element_water_height(res->Position);
if (waterHeight != 0)
{
z = waterHeight;
@ -78,11 +78,10 @@ private:
{
for (int32_t x = validRange.GetLeft(); x <= validRange.GetRight(); x += 32)
{
TileElement* tileElement = map_get_surface_element_at(x / 32, y / 32);
if (tileElement == nullptr)
auto* surfaceElement = map_get_surface_element_at(x / 32, y / 32);
if (surfaceElement == nullptr)
continue;
SurfaceElement* surfaceElement = tileElement->AsSurface();
uint8_t height = surfaceElement->GetWaterHeight();
if (height == 0)
continue;
@ -111,7 +110,7 @@ private:
if (isExecuting && hasChanged)
{
audio_play_sound_at_location(SoundId::LayingOutWater, res->Position.x, res->Position.y, res->Position.z);
audio_play_sound_at_location(SoundId::LayingOutWater, res->Position);
}
// Force ride construction to recheck area
_currentTrackSelectionFlags |= TRACK_SELECTION_FLAG_RECHECK;
@ -127,11 +126,11 @@ private:
{
for (int32_t x = _range.GetLeft(); x <= _range.GetRight(); x += 32)
{
TileElement* tile_element = map_get_surface_element_at({ x, y });
if (tile_element == nullptr)
auto* surfaceElement = map_get_surface_element_at({ x, y });
if (surfaceElement == nullptr)
continue;
uint8_t height = tile_element->AsSurface()->GetWaterHeight();
uint8_t height = surfaceElement->GetWaterHeight();
if (height == 0)
continue;

View File

@ -64,8 +64,8 @@ private:
res->Position.x = ((validRange.GetLeft() + validRange.GetRight()) / 2) + 16;
res->Position.y = ((validRange.GetTop() + validRange.GetBottom()) / 2) + 16;
int32_t z = tile_element_height(res->Position.x, res->Position.y);
int16_t waterHeight = tile_element_water_height(res->Position.x, res->Position.y);
int32_t z = tile_element_height(res->Position);
int16_t waterHeight = tile_element_water_height(res->Position);
if (waterHeight != 0)
{
z = waterHeight;
@ -79,11 +79,9 @@ private:
{
for (int32_t x = validRange.GetLeft(); x <= validRange.GetRight(); x += 32)
{
TileElement* tileElement = map_get_surface_element_at(x / 32, y / 32);
if (tileElement == nullptr)
auto surfaceElement = map_get_surface_element_at(x / 32, y / 32);
if (surfaceElement == nullptr)
continue;
SurfaceElement* surfaceElement = tileElement->AsSurface();
uint8_t height = surfaceElement->GetWaterHeight();
if (surfaceElement->base_height > maxHeight)
@ -119,7 +117,7 @@ private:
if (isExecuting && hasChanged)
{
audio_play_sound_at_location(SoundId::LayingOutWater, res->Position.x, res->Position.y, res->Position.z);
audio_play_sound_at_location(SoundId::LayingOutWater, res->Position);
}
// Force ride construction to recheck area
_currentTrackSelectionFlags |= TRACK_SELECTION_FLAG_RECHECK;
@ -135,14 +133,14 @@ private:
{
for (int32_t x = _range.GetLeft(); x <= _range.GetRight(); x += 32)
{
TileElement* tile_element = map_get_surface_element_at({ x, y });
if (tile_element == nullptr)
auto* surfaceElement = map_get_surface_element_at({ x, y });
if (surfaceElement == nullptr)
continue;
uint8_t height = tile_element->base_height;
if (tile_element->AsSurface()->GetWaterHeight() > 0)
uint8_t height = surfaceElement->base_height;
if (surfaceElement->GetWaterHeight() > 0)
{
height = tile_element->AsSurface()->GetWaterHeight() * 2;
height = surfaceElement->GetWaterHeight() * 2;
}
if (maxHeight > height)

View File

@ -71,7 +71,7 @@ public:
}
}
SurfaceElement* surfaceElement = map_get_surface_element_at(_coords)->AsSurface();
SurfaceElement* surfaceElement = map_get_surface_element_at(_coords);
if (surfaceElement == nullptr)
{
log_error("Could not find surface element at: x %u, y %u", _coords.x, _coords.y);
@ -113,12 +113,12 @@ public:
res->Position.y = _coords.y + 16;
res->Position.z = _height * 8;
int32_t surfaceHeight = tile_element_height(_coords.x, _coords.y);
int32_t surfaceHeight = tile_element_height(_coords);
footpath_remove_litter(_coords.x, _coords.y, surfaceHeight);
if (!gCheatsDisableClearanceChecks)
wall_remove_at_z(_coords.x, _coords.y, surfaceHeight);
SurfaceElement* surfaceElement = map_get_surface_element_at(_coords)->AsSurface();
SurfaceElement* surfaceElement = map_get_surface_element_at(_coords);
if (surfaceElement == nullptr)
{
log_error("Could not find surface element at: x %u, y %u", _coords.x, _coords.y);

View File

@ -125,7 +125,7 @@ static int32_t SoundVolumeAdjust[RCT2SoundCount] =
};
// clang-format on
AudioParams audio_get_params_from_location(SoundId soundId, const LocationXYZ16* location);
static AudioParams audio_get_params_from_location(SoundId soundId, const CoordsXYZ& location);
void audio_init()
{
@ -180,17 +180,12 @@ void audio_populate_devices()
}
}
void audio_play_sound_at_location(SoundId soundId, int16_t x, int16_t y, int16_t z)
void audio_play_sound_at_location(SoundId soundId, const CoordsXYZ& loc)
{
if (gGameSoundsOff)
return;
LocationXYZ16 location;
location.x = x;
location.y = y;
location.z = z;
AudioParams params = audio_get_params_from_location(soundId, &location);
AudioParams params = audio_get_params_from_location(soundId, loc);
if (params.in_range)
{
audio_play_sound(soundId, params.volume, params.pan);
@ -203,7 +198,7 @@ void audio_play_sound_at_location(SoundId soundId, int16_t x, int16_t y, int16_t
* @param location The location at which the sound effect is to be played.
* @return The audio parameters to be used when playing this sound effect.
*/
AudioParams audio_get_params_from_location(SoundId soundId, const LocationXYZ16* location)
static AudioParams audio_get_params_from_location(SoundId soundId, const CoordsXYZ& location)
{
int32_t volumeDown = 0;
AudioParams params;
@ -211,14 +206,14 @@ AudioParams audio_get_params_from_location(SoundId soundId, const LocationXYZ16*
params.volume = 0;
params.pan = 0;
TileElement* element = map_get_surface_element_at({ location->x, location->y });
if (element && (element->base_height * 8) - 5 > location->z)
auto element = map_get_surface_element_at(location);
if (element && (element->base_height * 8) - 5 > location.z)
{
volumeDown = 10;
}
uint8_t rotation = get_current_rotation();
LocationXY16 pos2 = coordinate_3d_to_2d(location, rotation);
auto pos2 = translate_3d_to_2d_with_z(rotation, location);
rct_viewport* viewport = nullptr;
while ((viewport = window_get_previous_viewport(viewport)) != nullptr)

View File

@ -21,6 +21,7 @@
#define SOUND_ID_NULL 0xFFFF
enum class SoundId : uint8_t;
struct CoordsXYZ;
struct audio_device
{
@ -209,7 +210,7 @@ void audio_play_sound(SoundId soundId, int32_t volume, int32_t pan);
* @param y The y coordinate of the location.
* @param z The z coordinate of the location.
*/
void audio_play_sound_at_location(SoundId soundId, int16_t x, int16_t y, int16_t z);
void audio_play_sound_at_location(SoundId soundId, const CoordsXYZ& loc);
/**
* Populates the gAudioDevices array with the available audio devices.
*/

View File

@ -105,7 +105,7 @@ static std::vector<paint_session> extract_paint_session(const std::string parkFi
int32_t customY = (gMapSize / 2) * 32 + 16;
int32_t x = 0, y = 0;
int32_t z = tile_element_height(customX, customY);
int32_t z = tile_element_height({ customX, customY });
x = customY - customX;
y = ((customX + customY) / 2) - z;

View File

@ -187,14 +187,14 @@ void lightfx_prepare_light_list()
continue;
}
LocationXYZ16 coord_3d = { /* .x = */ entry->x,
/* .y = */ entry->y,
/* .z = */ entry->z };
CoordsXYZ coord_3d = { /* .x = */ entry->x,
/* .y = */ entry->y,
/* .z = */ entry->z };
LocationXY16 coord_2d = coordinate_3d_to_2d(&coord_3d, _current_view_rotation_front);
auto screenCoords = translate_3d_to_2d_with_z(_current_view_rotation_front, coord_3d);
entry->x = coord_2d.x; // - (_current_view_x_front);
entry->y = coord_2d.y; // - (_current_view_y_front);
entry->x = screenCoords.x; // - (_current_view_x_front);
entry->y = screenCoords.y; // - (_current_view_y_front);
int32_t posOnScreenX = entry->x - _current_view_x_front;
int32_t posOnScreenY = entry->y - _current_view_y_front;

View File

@ -907,7 +907,7 @@ static int32_t cc_set(InteractiveConsole& console, const arguments_t& argv)
{
int32_t x = (int16_t)(int_val[0] * 32 + 16);
int32_t y = (int16_t)(int_val[1] * 32 + 16);
int32_t z = tile_element_height(x, y);
int32_t z = tile_element_height({ x, y });
w->SetLocation(x, y, z);
viewport_update_position(w);
console.Execute("get location");

View File

@ -251,10 +251,10 @@ void screenshot_giant()
int32_t centreX = (mapSize / 2) * 32 + 16;
int32_t centreY = (mapSize / 2) * 32 + 16;
int32_t z = tile_element_height(centreX, centreY);
int32_t z = tile_element_height({ centreX, centreY });
CoordsXYZ centreCoords3d = { centreX, centreY, z };
CoordsXY centreCoords2d = translate_3d_to_2d_with_z(rotation, centreCoords3d);
auto centreCoords2d = translate_3d_to_2d_with_z(rotation, centreCoords3d);
viewport.view_x = centreCoords2d.x - ((viewport.view_width << zoom) / 2);
viewport.view_y = centreCoords2d.y - ((viewport.view_height << zoom) / 2);
@ -336,7 +336,7 @@ static void benchgfx_render_screenshots(const char* inputPath, std::unique_ptr<I
int32_t customY = (gMapSize / 2) * 32 + 16;
int32_t x = 0, y = 0;
int32_t z = tile_element_height(customX, customY);
int32_t z = tile_element_height({ customX, customY });
x = customY - customX;
y = ((customX + customY) / 2) - z;
@ -522,10 +522,10 @@ int32_t cmdline_for_screenshot(const char** argv, int32_t argc, ScreenshotOption
if (centreMapY)
customY = (mapSize / 2) * 32 + 16;
int32_t z = tile_element_height(customX, customY);
int32_t z = tile_element_height({ customX, customY });
CoordsXYZ coords3d = { customX, customY, z };
CoordsXY coords2d = translate_3d_to_2d_with_z(customRotation, coords3d);
auto coords2d = translate_3d_to_2d_with_z(customRotation, coords3d);
viewport.view_x = coords2d.x - ((viewport.view_width << customZoom) / 2);
viewport.view_y = coords2d.y - ((viewport.view_height << customZoom) / 2);

View File

@ -95,6 +95,7 @@ void viewport_init_all()
textinput_cancel();
}
// TODO: Return ScreenCoords, takein CoordsXYZ
/**
* Converts between 3d point of a sprite to 2d coordinates for centring on that
* sprite
@ -109,9 +110,9 @@ void centre_2d_coordinates(int32_t x, int32_t y, int32_t z, int32_t* out_x, int3
{
int32_t start_x = x;
LocationXYZ16 coord_3d = { (int16_t)x, (int16_t)y, (int16_t)z };
CoordsXYZ coord_3d = { x, y, z };
LocationXY16 coord_2d = coordinate_3d_to_2d(&coord_3d, get_current_rotation());
auto coord_2d = translate_3d_to_2d_with_z(get_current_rotation(), coord_3d);
// If the start location was invalid
// propagate the invalid location to the output.
@ -221,7 +222,7 @@ void viewport_adjust_for_map_height(int16_t* x, int16_t* y, int16_t* z)
for (int32_t i = 0; i < 6; i++)
{
pos = viewport_coord_to_map_coord(start_x, start_y, height);
height = tile_element_height((0xFFFF) & pos.x, (0xFFFF) & pos.y);
height = tile_element_height({ (0xFFFF) & pos.x, (0xFFFF) & pos.y });
// HACK: This is to prevent the x and y values being set to values outside
// of the map. This can happen when the height is larger than the map size.
@ -640,7 +641,7 @@ void viewport_update_sprite_follow(rct_window* window)
{
rct_sprite* sprite = get_sprite(window->viewport_target_sprite);
int32_t height = (tile_element_height(0xFFFF & sprite->generic.x, 0xFFFF & sprite->generic.y)) - 16;
int32_t height = (tile_element_height({ sprite->generic.x, sprite->generic.y })) - 16;
int32_t underground = sprite->generic.z < height;
viewport_set_underground_flag(underground, window, window->viewport);
@ -733,7 +734,7 @@ viewport_focus viewport_update_smart_guest_follow(rct_window* window, Peep* peep
focus.type = VIEWPORT_FOCUS_TYPE_COORDINATE;
focus.coordinate.x = x;
focus.coordinate.y = y;
focus.coordinate.z = tile_element_height(x, y) + 32;
focus.coordinate.z = tile_element_height({ x, y }) + 32;
focus.sprite.type |= VIEWPORT_FOCUS_TYPE_COORDINATE;
}
}
@ -1808,7 +1809,7 @@ void screen_get_map_xy(int32_t screenX, int32_t screenY, int16_t* x, int16_t* y,
for (int32_t i = 0; i < 5; i++)
{
int32_t z = tile_element_height(map_pos.x, map_pos.y);
int32_t 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);
map_pos.y = std::clamp<int16_t>(map_pos.y, my_y, my_y + 31);

View File

@ -808,7 +808,7 @@ rct_window* window_get_main()
*/
void window_scroll_to_location(rct_window* w, int32_t x, int32_t y, int32_t z)
{
LocationXYZ16 location_3d = { (int16_t)x, (int16_t)y, (int16_t)z };
CoordsXYZ location_3d = { x, y, z };
assert(w != nullptr);
@ -816,7 +816,7 @@ void window_scroll_to_location(rct_window* w, int32_t x, int32_t y, int32_t z)
if (w->viewport)
{
int16_t height = tile_element_height(x, y);
int16_t height = tile_element_height({ x, y });
if (z < height - 16)
{
if (!(w->viewport->flags & 1 << 0))
@ -834,7 +834,7 @@ void window_scroll_to_location(rct_window* w, int32_t x, int32_t y, int32_t z)
}
}
LocationXY16 map_coordinate = coordinate_3d_to_2d(&location_3d, get_current_rotation());
auto screenCoords = translate_3d_to_2d_with_z(get_current_rotation(), location_3d);
int32_t i = 0;
if (!(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO))
@ -878,8 +878,8 @@ void window_scroll_to_location(rct_window* w, int32_t x, int32_t y, int32_t z)
{
if (!(w->flags & WF_NO_SCROLLING))
{
w->saved_view_x = map_coordinate.x - (int16_t)(w->viewport->view_width * window_scroll_locations[i][0]);
w->saved_view_y = map_coordinate.y - (int16_t)(w->viewport->view_height * window_scroll_locations[i][1]);
w->saved_view_x = screenCoords.x - (int16_t)(w->viewport->view_width * window_scroll_locations[i][0]);
w->saved_view_y = screenCoords.y - (int16_t)(w->viewport->view_height * window_scroll_locations[i][1]);
w->flags |= WF_SCROLLING_TO_LOCATION;
}
}
@ -927,7 +927,7 @@ void window_rotate_camera(rct_window* w, int32_t direction)
}
else
{
z = tile_element_height(x, y);
z = tile_element_height({ x, y });
}
gCurrentRotation = (get_current_rotation() + direction) & 3;
@ -957,7 +957,7 @@ void window_viewport_get_map_coords_by_cursor(
get_map_coordinates_from_pos(mouse_x, mouse_y, VIEWPORT_INTERACTION_MASK_NONE, map_x, map_y, nullptr, nullptr, nullptr);
// Get viewport coordinates centring around the tile.
int32_t base_height = tile_element_height(*map_x, *map_y);
int32_t base_height = tile_element_height({ *map_x, *map_y });
int32_t dest_x, dest_y;
centre_2d_coordinates(*map_x, *map_y, base_height, &dest_x, &dest_y, w->viewport);
@ -974,7 +974,7 @@ void window_viewport_centre_tile_around_cursor(rct_window* w, int16_t map_x, int
{
// Get viewport coordinates centring around the tile.
int32_t dest_x, dest_y;
int32_t base_height = tile_element_height(map_x, map_y);
int32_t base_height = tile_element_height({ map_x, map_y });
centre_2d_coordinates(map_x, map_y, base_height, &dest_x, &dest_y, w->viewport);
// Get mouse position to offset against.

View File

@ -224,7 +224,7 @@ void news_item_get_subject_location(int32_t type, int32_t subject, int32_t* x, i
}
*x = ride->overall_view.x * 32 + 16;
*y = ride->overall_view.y * 32 + 16;
*z = tile_element_height(*x, *y);
*z = tile_element_height({ *x, *y });
break;
case NEWS_ITEM_PEEP_ON_RIDE:
peep = GET_PEEP(subject);
@ -268,7 +268,7 @@ void news_item_get_subject_location(int32_t type, int32_t subject, int32_t* x, i
case NEWS_ITEM_BLANK:
*x = subject;
*y = subject >> 16;
*z = tile_element_height(*x, *y);
*z = tile_element_height({ *x, *y });
break;
default:
*x = LOCATION_NULL;

View File

@ -71,7 +71,8 @@ static void paint_session_add_ps_to_quadrant(paint_session* session, paint_struc
* Extracted from 0x0098196c, 0x0098197c, 0x0098198c, 0x0098199c
*/
static paint_struct* sub_9819_c(
paint_session* session, uint32_t image_id, LocationXYZ16 offset, LocationXYZ16 boundBoxSize, LocationXYZ16 boundBoxOffset)
paint_session* session, uint32_t image_id, const CoordsXYZ& offset, LocationXYZ16 boundBoxSize,
LocationXYZ16 boundBoxOffset)
{
if (session->NextFreePaintStruct >= session->EndOfPaintStructArray)
return nullptr;
@ -85,17 +86,18 @@ static paint_struct* sub_9819_c(
ps->image_id = image_id;
uint8_t swappedRotation = (session->CurrentRotation * 3) % 4; // swaps 1 and 3
rotate_map_coordinates(&offset.x, &offset.y, swappedRotation);
offset.x += session->SpritePosition.x;
offset.y += session->SpritePosition.y;
auto swappedRotCoord = CoordsXYZ{ offset.Rotate(swappedRotation), offset.z };
LocationXY16 map = coordinate_3d_to_2d(&offset, session->CurrentRotation);
swappedRotCoord.x += session->SpritePosition.x;
swappedRotCoord.y += session->SpritePosition.y;
ps->x = map.x;
ps->y = map.y;
auto screenCoords = translate_3d_to_2d_with_z(session->CurrentRotation, swappedRotCoord);
int32_t left = map.x + g1->x_offset;
int32_t bottom = map.y + g1->y_offset;
ps->x = screenCoords.x;
ps->y = screenCoords.y;
int32_t left = screenCoords.x + g1->x_offset;
int32_t bottom = screenCoords.y + g1->y_offset;
int32_t right = left + g1->width;
int32_t top = bottom + g1->height;
@ -541,61 +543,61 @@ static void paint_ps_image_with_bounding_boxes(rct_drawpixelinfo* dpi, paint_str
const uint8_t colour = BoundBoxDebugColours[ps->sprite_type];
const uint8_t rotation = get_current_rotation();
const LocationXYZ16 frontTop = {
(int16_t)ps->bounds.x_end,
(int16_t)ps->bounds.y_end,
(int16_t)ps->bounds.z_end,
const CoordsXYZ frontTop = {
ps->bounds.x_end,
ps->bounds.y_end,
ps->bounds.z_end,
};
const LocationXY16 screenCoordFrontTop = coordinate_3d_to_2d(&frontTop, rotation);
const auto screenCoordFrontTop = translate_3d_to_2d_with_z(rotation, frontTop);
const LocationXYZ16 frontBottom = {
(int16_t)ps->bounds.x_end,
(int16_t)ps->bounds.y_end,
(int16_t)ps->bounds.z,
const CoordsXYZ frontBottom = {
ps->bounds.x_end,
ps->bounds.y_end,
ps->bounds.z,
};
const LocationXY16 screenCoordFrontBottom = coordinate_3d_to_2d(&frontBottom, rotation);
const auto screenCoordFrontBottom = translate_3d_to_2d_with_z(rotation, frontBottom);
const LocationXYZ16 leftTop = {
(int16_t)ps->bounds.x,
(int16_t)ps->bounds.y_end,
(int16_t)ps->bounds.z_end,
const CoordsXYZ leftTop = {
ps->bounds.x,
ps->bounds.y_end,
ps->bounds.z_end,
};
const LocationXY16 screenCoordLeftTop = coordinate_3d_to_2d(&leftTop, rotation);
const auto screenCoordLeftTop = translate_3d_to_2d_with_z(rotation, leftTop);
const LocationXYZ16 leftBottom = {
(int16_t)ps->bounds.x,
(int16_t)ps->bounds.y_end,
(int16_t)ps->bounds.z,
const CoordsXYZ leftBottom = {
ps->bounds.x,
ps->bounds.y_end,
ps->bounds.z,
};
const LocationXY16 screenCoordLeftBottom = coordinate_3d_to_2d(&leftBottom, rotation);
const auto screenCoordLeftBottom = translate_3d_to_2d_with_z(rotation, leftBottom);
const LocationXYZ16 rightTop = {
(int16_t)ps->bounds.x_end,
(int16_t)ps->bounds.y,
(int16_t)ps->bounds.z_end,
const CoordsXYZ rightTop = {
ps->bounds.x_end,
ps->bounds.y,
ps->bounds.z_end,
};
const LocationXY16 screenCoordRightTop = coordinate_3d_to_2d(&rightTop, rotation);
const auto screenCoordRightTop = translate_3d_to_2d_with_z(rotation, rightTop);
const LocationXYZ16 rightBottom = {
(int16_t)ps->bounds.x_end,
(int16_t)ps->bounds.y,
(int16_t)ps->bounds.z,
const CoordsXYZ rightBottom = {
ps->bounds.x_end,
ps->bounds.y,
ps->bounds.z,
};
const LocationXY16 screenCoordRightBottom = coordinate_3d_to_2d(&rightBottom, rotation);
const auto screenCoordRightBottom = translate_3d_to_2d_with_z(rotation, rightBottom);
const LocationXYZ16 backTop = {
(int16_t)ps->bounds.x,
(int16_t)ps->bounds.y,
(int16_t)ps->bounds.z_end,
const CoordsXYZ backTop = {
ps->bounds.x,
ps->bounds.y,
ps->bounds.z_end,
};
const LocationXY16 screenCoordBackTop = coordinate_3d_to_2d(&backTop, rotation);
const auto screenCoordBackTop = translate_3d_to_2d_with_z(rotation, backTop);
const LocationXYZ16 backBottom = {
(int16_t)ps->bounds.x,
(int16_t)ps->bounds.y,
(int16_t)ps->bounds.z,
const CoordsXYZ backBottom = {
ps->bounds.x,
ps->bounds.y,
ps->bounds.z,
};
const LocationXY16 screenCoordBackBottom = coordinate_3d_to_2d(&backBottom, rotation);
const auto screenCoordBackBottom = translate_3d_to_2d_with_z(rotation, backBottom);
// bottom square
gfx_draw_line(
@ -743,7 +745,7 @@ paint_struct* sub_98196C(
paint_struct* ps = &session->NextFreePaintStruct->basic;
ps->image_id = image_id;
LocationXYZ16 coord_3d = {
CoordsXYZ coord_3d = {
x_offset, // ax
y_offset, // cx
z_offset,
@ -758,7 +760,7 @@ paint_struct* sub_98196C(
switch (session->CurrentRotation)
{
case 0:
rotate_map_coordinates(&coord_3d.x, &coord_3d.y, TILE_ELEMENT_DIRECTION_WEST);
coord_3d = CoordsXYZ{ coord_3d.Rotate(TILE_ELEMENT_DIRECTION_WEST), coord_3d.z };
boundBox.x--;
boundBox.y--;
@ -766,19 +768,19 @@ paint_struct* sub_98196C(
break;
case 1:
rotate_map_coordinates(&coord_3d.x, &coord_3d.y, TILE_ELEMENT_DIRECTION_SOUTH);
coord_3d = CoordsXYZ{ coord_3d.Rotate(TILE_ELEMENT_DIRECTION_SOUTH), coord_3d.z };
boundBox.x--;
rotate_map_coordinates(&boundBox.x, &boundBox.y, TILE_ELEMENT_DIRECTION_SOUTH);
break;
case 2:
rotate_map_coordinates(&coord_3d.x, &coord_3d.y, TILE_ELEMENT_DIRECTION_EAST);
coord_3d = CoordsXYZ{ coord_3d.Rotate(TILE_ELEMENT_DIRECTION_EAST), coord_3d.z };
rotate_map_coordinates(&boundBox.x, &boundBox.y, TILE_ELEMENT_DIRECTION_EAST);
break;
case 3:
rotate_map_coordinates(&coord_3d.x, &coord_3d.y, TILE_ELEMENT_DIRECTION_NORTH);
coord_3d = CoordsXYZ{ coord_3d.Rotate(TILE_ELEMENT_DIRECTION_NORTH), coord_3d.z };
boundBox.y--;
rotate_map_coordinates(&boundBox.x, &boundBox.y, TILE_ELEMENT_DIRECTION_NORTH);
@ -795,7 +797,7 @@ paint_struct* sub_98196C(
ps->bounds.z = coord_3d.z;
ps->bounds.z_end = (boundBox.z + coord_3d.z);
LocationXY16 map = coordinate_3d_to_2d(&coord_3d, session->CurrentRotation);
auto map = translate_3d_to_2d_with_z(session->CurrentRotation, coord_3d);
ps->x = map.x;
ps->y = map.y;
@ -877,7 +879,7 @@ paint_struct* sub_98197C(
session->LastRootPS = nullptr;
session->UnkF1AD2C = nullptr;
LocationXYZ16 offset = { x_offset, y_offset, z_offset };
CoordsXYZ offset = { x_offset, y_offset, z_offset };
LocationXYZ16 boundBoxSize = { bound_box_length_x, bound_box_length_y, bound_box_length_z };
LocationXYZ16 boundBoxOffset = { bound_box_offset_x, bound_box_offset_y, bound_box_offset_z };
paint_struct* ps = sub_9819_c(session, image_id, offset, boundBoxSize, boundBoxOffset);
@ -939,7 +941,7 @@ paint_struct* sub_98198C(
session->LastRootPS = nullptr;
session->UnkF1AD2C = nullptr;
LocationXYZ16 offset = { x_offset, y_offset, z_offset };
CoordsXYZ offset = { x_offset, y_offset, z_offset };
LocationXYZ16 boundBoxSize = { bound_box_length_x, bound_box_length_y, bound_box_length_z };
LocationXYZ16 boundBoxOffset = { bound_box_offset_x, bound_box_offset_y, bound_box_offset_z };
paint_struct* ps = sub_9819_c(session, image_id, offset, boundBoxSize, boundBoxOffset);
@ -985,7 +987,7 @@ paint_struct* sub_98199C(
bound_box_offset_x, bound_box_offset_y, bound_box_offset_z);
}
LocationXYZ16 offset = { x_offset, y_offset, z_offset };
CoordsXYZ offset = { x_offset, y_offset, z_offset };
LocationXYZ16 boundBox = { bound_box_length_x, bound_box_length_y, bound_box_length_z };
LocationXYZ16 boundBoxOffset = { bound_box_offset_x, bound_box_offset_y, bound_box_offset_z };
paint_struct* ps = sub_9819_c(session, image_id, offset, boundBox, boundBoxOffset);
@ -1107,12 +1109,12 @@ void paint_floating_money_effect(
ps->args[3] = 0;
ps->y_offsets = (uint8_t*)y_offsets;
const LocationXYZ16 position = {
const CoordsXYZ position = {
session->SpritePosition.x,
session->SpritePosition.y,
z,
};
const LocationXY16 coord = coordinate_3d_to_2d(&position, rotation);
const auto coord = translate_3d_to_2d_with_z(rotation, position);
ps->x = coord.x + offset_x;
ps->y = coord.y;

View File

@ -233,7 +233,7 @@ static void virtual_floor_get_tile_properties(
}
}
*tileOwned = map_is_location_owned(x, y, height);
*tileOwned = map_is_location_owned({ x, y, height });
if (gCheatsSandboxMode)
*tileOwned = true;

View File

@ -859,7 +859,7 @@ void path_paint(paint_session* session, uint16_t height, const TileElement* tile
int16_t x = session->MapPosition.x, y = session->MapPosition.y;
TileElement* surface = map_get_surface_element_at({ session->MapPosition.x, session->MapPosition.y });
auto surface = map_get_surface_element_at({ session->MapPosition.x, session->MapPosition.y });
uint16_t bl = height / 8;
if (surface == nullptr)
@ -876,14 +876,14 @@ void path_paint(paint_session* session, uint16_t height, const TileElement* tile
{
// Diagonal path
if (surface->AsSurface()->GetSlope() != PathSlopeToLandSlope[tile_element->AsPath()->GetSlopeDirection()])
if (surface->GetSlope() != PathSlopeToLandSlope[tile_element->AsPath()->GetSlopeDirection()])
{
hasSupports = true;
}
}
else
{
if (surface->AsSurface()->GetSlope() != TILE_ELEMENT_SLOPE_FLAT)
if (surface->GetSlope() != TILE_ELEMENT_SLOPE_FLAT)
{
hasSupports = true;
}

View File

@ -952,19 +952,20 @@ void surface_paint(paint_session* session, uint8_t direction, uint16_t height, c
continue;
}
TileElement* surfaceElement = map_get_surface_element_at(position);
auto surfaceElement = map_get_surface_element_at(position);
if (surfaceElement == nullptr)
{
continue;
}
const uint32_t surfaceSlope = viewport_surface_paint_setup_get_relative_slope(surfaceElement, rotation);
const uint32_t surfaceSlope = viewport_surface_paint_setup_get_relative_slope(
reinterpret_cast<TileElement*>(surfaceElement), rotation);
const uint8_t baseHeight = surfaceElement->base_height / 2;
const corner_height& ch = corner_heights[surfaceSlope];
descriptor.tile_coords = { position.x / 32, position.y / 32 };
descriptor.tile_element = surfaceElement;
descriptor.terrain = surfaceElement->AsSurface()->GetSurfaceStyle();
descriptor.tile_element = reinterpret_cast<TileElement*>(surfaceElement);
descriptor.terrain = surfaceElement->GetSurfaceStyle();
descriptor.slope = surfaceSlope;
descriptor.corner_heights.top = baseHeight + ch.top;
descriptor.corner_heights.right = baseHeight + ch.right;
@ -977,7 +978,7 @@ void surface_paint(paint_session* session, uint8_t direction, uint16_t height, c
const int16_t x = session->MapPosition.x;
const int16_t y = session->MapPosition.y;
int32_t dx = tile_element_height(x + 16, y + 16);
int32_t dx = tile_element_height({ x + 16, y + 16 });
dx += 3;
int32_t image_id = (SPR_HEIGHT_MARKER_BASE + dx / 16) | 0x20780000;
@ -1088,7 +1089,7 @@ void surface_paint(paint_session* session, uint8_t direction, uint16_t height, c
else if (tileElement->AsSurface()->GetOwnership() & OWNERSHIP_AVAILABLE)
{
const LocationXY16& pos = session->MapPosition;
const int32_t height2 = (tile_element_height(pos.x + 16, pos.y + 16)) + 3;
const int32_t height2 = (tile_element_height({ pos.x + 16, pos.y + 16 })) + 3;
paint_struct* backup = session->LastRootPS;
sub_98196C(session, SPR_LAND_OWNERSHIP_AVAILABLE, 16, 16, 1, 1, 0, height2);
session->LastRootPS = backup;
@ -1105,7 +1106,7 @@ void surface_paint(paint_session* session, uint8_t direction, uint16_t height, c
else if (tileElement->AsSurface()->GetOwnership() & OWNERSHIP_CONSTRUCTION_RIGHTS_AVAILABLE)
{
const LocationXY16& pos = session->MapPosition;
const int32_t height2 = tile_element_height(pos.x + 16, pos.y + 16);
const int32_t height2 = tile_element_height({ pos.x + 16, pos.y + 16 });
paint_struct* backup = session->LastRootPS;
sub_98196C(session, SPR_LAND_CONSTRUCTION_RIGHTS_AVAILABLE, 16, 16, 1, 1, 0, height2 + 3);
session->LastRootPS = backup;

View File

@ -715,7 +715,7 @@ void Guest::Tick128UpdateGuest(int32_t index)
{
if (state == PEEP_STATE_WALKING || state == PEEP_STATE_SITTING)
{
audio_play_sound_at_location(SoundId::Crash, x, y, z);
audio_play_sound_at_location(SoundId::Crash, { x, y, z });
sprite_misc_explosion_cloud_create(x, y, z + 16);
sprite_misc_explosion_flare_create(x, y, z + 16);
@ -1831,7 +1831,7 @@ void Guest::OnExitRide(ride_id_t rideIndex)
int32_t laughType = scenario_rand() & 7;
if (laughType < 3)
{
audio_play_sound_at_location(laughs[laughType], x, y, z);
audio_play_sound_at_location(laughs[laughType], { x, y, z });
}
}
@ -2370,7 +2370,7 @@ void Guest::SpendMoney(money16& peep_expend_type, money32 amount)
}
}
audio_play_sound_at_location(SoundId::Purchase, x, y, z);
audio_play_sound_at_location(SoundId::Purchase, { x, y, z });
}
void Guest::SetHasRidden(const Ride* ride)
@ -2941,7 +2941,7 @@ static bool peep_really_liked_ride(Peep* peep, Ride* ride)
*/
static PeepThoughtType peep_assess_surroundings(int16_t centre_x, int16_t centre_y, int16_t centre_z)
{
if ((tile_element_height(centre_x, centre_y)) > centre_z)
if ((tile_element_height({ centre_x, centre_y })) > centre_z)
return PEEP_THOUGHT_TYPE_NONE;
uint16_t num_scenery = 0;
@ -5156,7 +5156,7 @@ void Guest::UpdateRideShopInteract()
// Do not play toilet flush sound on title screen as it's considered loud and annoying
if (!(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO))
{
audio_play_sound_at_location(SoundId::ToiletFlush, x, y, z);
audio_play_sound_at_location(SoundId::ToiletFlush, { x, y, z });
}
sub_state = PEEP_SHOP_LEAVE;
@ -5464,9 +5464,9 @@ void Guest::UpdateWalking()
if (GetNextIsSurface())
{
TileElement* tile_element = map_get_surface_element_at({ next_x, next_y });
auto surfaceElement = map_get_surface_element_at({ next_x, next_y });
int32_t water_height = tile_element->AsSurface()->GetWaterHeight();
int32_t water_height = surfaceElement->GetWaterHeight();
if (water_height)
{
Invalidate();
@ -6484,11 +6484,11 @@ bool loc_690FD0(Peep* peep, uint8_t* rideToView, uint8_t* rideSeatToView, TileEl
*/
static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToView, uint8_t* rideSeatToView)
{
TileElement *tileElement, *surfaceElement;
TileElement* tileElement;
surfaceElement = map_get_surface_element_at({ peep->next_x, peep->next_y });
auto surfaceElement = map_get_surface_element_at({ peep->next_x, peep->next_y });
tileElement = surfaceElement;
tileElement = reinterpret_cast<TileElement*>(surfaceElement);
if (tileElement == nullptr)
{
return false;
@ -6527,7 +6527,7 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
surfaceElement = map_get_surface_element_at({ x, y });
tileElement = surfaceElement;
tileElement = reinterpret_cast<TileElement*>(surfaceElement);
if (tileElement == nullptr)
{
return false;
@ -6559,7 +6559,7 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
} while (!(tileElement++)->IsLastForTile());
// TODO: Extract loop B
tileElement = surfaceElement;
tileElement = reinterpret_cast<TileElement*>(surfaceElement);
do
{
// Ghosts are purely this-client-side and should not cause any interaction,
@ -6603,7 +6603,7 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
} while (!(tileElement++)->IsLastForTile());
// TODO: Extract loop C
tileElement = surfaceElement;
tileElement = reinterpret_cast<TileElement*>(surfaceElement);
do
{
// Ghosts are purely this-client-side and should not cause any interaction,
@ -6644,7 +6644,7 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
surfaceElement = map_get_surface_element_at({ x, y });
// TODO: extract loop A
tileElement = surfaceElement;
tileElement = reinterpret_cast<TileElement*>(surfaceElement);
if (tileElement == nullptr)
{
@ -6676,7 +6676,7 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
} while (!(tileElement++)->IsLastForTile());
// TODO: Extract loop B
tileElement = surfaceElement;
tileElement = reinterpret_cast<TileElement*>(surfaceElement);
do
{
// Ghosts are purely this-client-side and should not cause any interaction,
@ -6720,7 +6720,7 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
} while (!(tileElement++)->IsLastForTile());
// TODO: Extract loop C
tileElement = surfaceElement;
tileElement = reinterpret_cast<TileElement*>(surfaceElement);
do
{
// Ghosts are purely this-client-side and should not cause any interaction,
@ -6761,7 +6761,7 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
surfaceElement = map_get_surface_element_at({ x, y });
// TODO: extract loop A
tileElement = surfaceElement;
tileElement = reinterpret_cast<TileElement*>(surfaceElement);
if (tileElement == nullptr)
{
return false;
@ -6792,7 +6792,7 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
} while (!(tileElement++)->IsLastForTile());
// TODO: Extract loop B
tileElement = surfaceElement;
tileElement = reinterpret_cast<TileElement*>(surfaceElement);
do
{
// Ghosts are purely this-client-side and should not cause any interaction,
@ -6932,7 +6932,7 @@ void Guest::UpdateSpriteType()
if ((scenario_rand() & 0xFFFF) <= 13107)
{
isBalloonPopped = true;
audio_play_sound_at_location(SoundId::BalloonPop, x, y, z);
audio_play_sound_at_location(SoundId::BalloonPop, { x, y, z });
}
create_balloon(x, y, z + 9, balloon_colour, isBalloonPopped);
}

View File

@ -7,6 +7,7 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "../core/Guard.hpp"
#include "../ride/Station.h"
#include "../ride/Track.h"
#include "../scenario/Scenario.h"
@ -77,11 +78,11 @@ static TileElement* get_banner_on_path(TileElement* path_element)
return nullptr;
}
static int32_t banner_clear_path_edges(TileElement* tileElement, int32_t edges)
static int32_t banner_clear_path_edges(PathElement* pathElement, int32_t edges)
{
if (_peepPathFindIsStaff)
return edges;
TileElement* bannerElement = get_banner_on_path(tileElement);
TileElement* bannerElement = get_banner_on_path(reinterpret_cast<TileElement*>(pathElement));
if (bannerElement != nullptr)
{
do
@ -95,9 +96,9 @@ static int32_t banner_clear_path_edges(TileElement* tileElement, int32_t edges)
/**
* Gets the connected edges of a path that are permitted (i.e. no 'no entry' signs)
*/
static int32_t path_get_permitted_edges(TileElement* tileElement)
static int32_t path_get_permitted_edges(PathElement* pathElement)
{
return banner_clear_path_edges(tileElement, tileElement->AsPath()->GetEdgesAndCorners()) & 0x0F;
return banner_clear_path_edges(pathElement, pathElement->GetEdgesAndCorners()) & 0x0F;
}
/**
@ -222,13 +223,13 @@ static int32_t guest_surface_path_finding(Peep* peep)
* Returns the type of the next footpath tile a peep can get to from x,y,z /
* inputTileElement in the given direction.
*/
static uint8_t footpath_element_next_in_direction(TileCoordsXYZ loc, TileElement* tileElement, uint8_t chosenDirection)
static uint8_t footpath_element_next_in_direction(TileCoordsXYZ loc, PathElement* pathElement, uint8_t chosenDirection)
{
TileElement* nextTileElement;
if (tileElement->AsPath()->IsSloped())
if (pathElement->IsSloped())
{
if (tileElement->AsPath()->GetSlopeDirection() == chosenDirection)
if (pathElement->GetSlopeDirection() == chosenDirection)
{
loc.z += 2;
}
@ -274,9 +275,7 @@ static uint8_t footpath_element_next_in_direction(TileCoordsXYZ loc, TileElement
*
* This is the recursive portion of footpath_element_destination_in_direction().
*/
static uint8_t footpath_element_dest_in_dir(
TileCoordsXYZ loc, [[maybe_unused]] TileElement* inputTileElement, uint8_t chosenDirection, ride_id_t* outRideIndex,
int32_t level)
static uint8_t footpath_element_dest_in_dir(TileCoordsXYZ loc, uint8_t chosenDirection, ride_id_t* outRideIndex, int32_t level)
{
TileElement* tileElement;
int32_t direction;
@ -341,7 +340,7 @@ static uint8_t footpath_element_dest_in_dir(
if (tileElement->AsPath()->IsWide())
return PATH_SEARCH_WIDE;
uint8_t edges = path_get_permitted_edges(tileElement);
uint8_t edges = path_get_permitted_edges(tileElement->AsPath());
edges &= ~(1 << direction_reverse(chosenDirection));
loc.z = tileElement->base_height;
@ -361,7 +360,7 @@ static uint8_t footpath_element_dest_in_dir(
loc.z += 2;
}
}
return footpath_element_dest_in_dir(loc, tileElement, direction, outRideIndex, level + 1);
return footpath_element_dest_in_dir(loc, direction, outRideIndex, level + 1);
}
return PATH_SEARCH_DEAD_END;
}
@ -394,17 +393,17 @@ static uint8_t footpath_element_dest_in_dir(
* width path, for example that leads from a ride exit back to the main path.
*/
static uint8_t footpath_element_destination_in_direction(
TileCoordsXYZ loc, TileElement* inputTileElement, uint8_t chosenDirection, ride_id_t* outRideIndex)
TileCoordsXYZ loc, PathElement* pathElement, uint8_t chosenDirection, ride_id_t* outRideIndex)
{
if (inputTileElement->AsPath()->IsSloped())
if (pathElement->IsSloped())
{
if (inputTileElement->AsPath()->GetSlopeDirection() == chosenDirection)
if (pathElement->GetSlopeDirection() == chosenDirection)
{
loc.z += 2;
}
}
return footpath_element_dest_in_dir(loc, inputTileElement, chosenDirection, outRideIndex, 0);
return footpath_element_dest_in_dir(loc, chosenDirection, outRideIndex, 0);
}
/**
@ -473,9 +472,9 @@ static uint8_t peep_pathfind_get_max_number_junctions(Peep* peep)
* since entrances and ride queues coming off a path should not result in
* the path being considered a junction.
*/
static bool path_is_thin_junction(TileElement* path, TileCoordsXYZ loc)
static bool path_is_thin_junction(PathElement* path, TileCoordsXYZ loc)
{
uint8_t edges = path->AsPath()->GetEdges();
uint8_t edges = path->GetEdges();
int32_t test_edge = bitscanforward(edges);
if (test_edge == -1)
@ -893,7 +892,8 @@ static void peep_pathfind_heuristic_search(
/* At this point the map element is a non-wide path.*/
/* Get all the permitted_edges of the map element. */
uint8_t edges = path_get_permitted_edges(tileElement);
Guard::Assert(tileElement->AsPath() != nullptr);
uint8_t edges = path_get_permitted_edges(tileElement->AsPath());
#if defined(DEBUG_LEVEL_2) && DEBUG_LEVEL_2
if (gPathFindDebug)
@ -964,7 +964,7 @@ static void peep_pathfind_heuristic_search(
{
/* Check if this is a thin junction. And perform additional
* necessary checks. */
thin_junction = path_is_thin_junction(tileElement, loc);
thin_junction = path_is_thin_junction(tileElement->AsPath(), loc);
if (thin_junction)
{
@ -1224,10 +1224,10 @@ int32_t peep_pathfind_choose_direction(TileCoordsXYZ loc, Peep* peep)
* check if the combination is 'thin'!
* The junction is considered 'thin' simply if any of the
* overlaid path elements there is a 'thin junction'. */
isThin = isThin || path_is_thin_junction(dest_tile_element, loc);
isThin = isThin || path_is_thin_junction(dest_tile_element->AsPath(), loc);
// Collect the permitted edges of ALL matching path elements at this location.
permitted_edges |= path_get_permitted_edges(dest_tile_element);
permitted_edges |= path_get_permitted_edges(dest_tile_element->AsPath());
} while (!(dest_tile_element++)->IsLastForTile());
// Peep is not on a path.
if (!found)
@ -1561,7 +1561,7 @@ static uint8_t get_nearest_park_entrance_index(uint16_t x, uint16_t y)
*
* rct2: 0x006952C0
*/
static int32_t guest_path_find_entering_park(Peep* peep, [[maybe_unused]] TileElement* tile_element, uint8_t edges)
static int32_t guest_path_find_entering_park(Peep* peep, uint8_t edges)
{
// Send peeps to the nearest park entrance.
uint8_t chosenEntrance = get_nearest_park_entrance_index(peep->next_x, peep->next_y);
@ -1614,7 +1614,7 @@ static uint8_t get_nearest_peep_spawn_index(uint16_t x, uint16_t y)
*
* rct2: 0x0069536C
*/
static int32_t guest_path_find_leaving_park(Peep* peep, [[maybe_unused]] TileElement* tile_element, uint8_t edges)
static int32_t guest_path_find_leaving_park(Peep* peep, uint8_t edges)
{
// Send peeps to the nearest spawn point.
uint8_t chosenSpawn = get_nearest_peep_spawn_index(peep->next_x, peep->next_y);
@ -1649,7 +1649,7 @@ static int32_t guest_path_find_leaving_park(Peep* peep, [[maybe_unused]] TileEle
*
* rct2: 0x00695161
*/
static int32_t guest_path_find_park_entrance(Peep* peep, [[maybe_unused]] TileElement* tile_element, uint8_t edges)
static int32_t guest_path_find_park_entrance(Peep* peep, uint8_t edges)
{
// If entrance no longer exists, choose a new one
if ((peep->peep_flags & PEEP_FLAGS_PARK_ENTRANCE_CHOSEN) && peep->current_ride >= gParkEntrances.size())
@ -1870,14 +1870,14 @@ int32_t guest_path_finding(Guest* peep)
TileCoordsXYZ loc = { peep->next_x / 32, peep->next_y / 32, peep->next_z };
TileElement* tileElement = map_get_path_element_at(loc.x, loc.y, loc.z);
if (tileElement == nullptr)
auto* pathElement = map_get_path_element_at(loc);
if (pathElement == nullptr)
{
return 1;
}
_peepPathFindIsStaff = false;
uint8_t edges = path_get_permitted_edges(tileElement);
uint8_t edges = path_get_permitted_edges(pathElement);
if (edges == 0)
{
@ -1897,7 +1897,7 @@ int32_t guest_path_finding(Guest* peep)
/* If there is a wide path in that direction,
remove that edge and try another */
if (footpath_element_next_in_direction(loc, tileElement, chosenDirection) == PATH_SEARCH_WIDE)
if (footpath_element_next_in_direction(loc, pathElement, chosenDirection) == PATH_SEARCH_WIDE)
{
adjustedEdges &= ~(1 << chosenDirection);
}
@ -1954,9 +1954,9 @@ int32_t guest_path_finding(Guest* peep)
switch (peep->state)
{
case PEEP_STATE_ENTERING_PARK:
return guest_path_find_entering_park(peep, tileElement, edges);
return guest_path_find_entering_park(peep, edges);
case PEEP_STATE_LEAVING_PARK:
return guest_path_find_leaving_park(peep, tileElement, edges);
return guest_path_find_leaving_park(peep, edges);
default:
return guest_path_find_aimless(peep, edges);
}
@ -1978,7 +1978,7 @@ int32_t guest_path_finding(Guest* peep)
continue;
ride_id_t rideIndex, pathSearchResult;
pathSearchResult = footpath_element_destination_in_direction(loc, tileElement, chosenDirection, &rideIndex);
pathSearchResult = footpath_element_destination_in_direction(loc, pathElement, chosenDirection, &rideIndex);
switch (pathSearchResult)
{
case PATH_SEARCH_DEAD_END:
@ -2021,7 +2021,7 @@ int32_t guest_path_finding(Guest* peep)
}
pathfind_logging_disable();
#endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1
return guest_path_find_park_entrance(peep, tileElement, edges);
return guest_path_find_park_entrance(peep, edges);
}
if (peep->guest_heading_to_ride_id == 0xFF)

View File

@ -669,7 +669,7 @@ std::optional<CoordsXY> Peep::UpdateAction(int16_t& xy_distance)
SoundId coughs[4] = { SoundId::Cough1, SoundId::Cough2, SoundId::Cough3, SoundId::Cough4 };
auto soundId = coughs[scenario_rand() & 3];
audio_play_sound_at_location(soundId, x, y, z);
audio_play_sound_at_location(soundId, { x, y, z });
Invalidate();
return { { x, y } };
@ -763,25 +763,21 @@ void Peep::PickupAbort(int32_t old_x)
// Returns true when a peep can be dropped at the given location. When apply is set to true the peep gets dropped.
bool Peep::Place(TileCoordsXYZ location, bool apply)
{
TileElement* tileElement = map_get_path_element_at(location.x, location.y, location.z);
if (!tileElement)
auto* pathElement = map_get_path_element_at(location);
TileElement* tileElement = reinterpret_cast<TileElement*>(pathElement);
if (!pathElement)
{
tileElement = map_get_surface_element_at(location.x, location.y);
tileElement = reinterpret_cast<TileElement*>(map_get_surface_element_at(location.x, location.y));
}
if (!tileElement)
return false;
CoordsXYZ destination = { location.x * 32, location.y * 32, location.z * 8 };
// Set the coordinate of destination to be exactly
// in the middle of a tile.
destination.x += 16;
destination.y += 16;
destination.z = tileElement->base_height * 8 + 16;
CoordsXYZ destination = { location.x * 32 + 16, location.y * 32 + 16, tileElement->base_height * 8 + 16 };
if (!map_is_location_owned(location.x * 32, location.y * 32, destination.z))
if (!map_is_location_owned(destination))
{
gGameCommandErrorTitle = STR_ERR_CANT_PLACE_PERSON_HERE;
return false;
@ -959,7 +955,7 @@ void Peep::UpdateFalling()
return;
}
}
int32_t map_height = tile_element_height(0xFFFF & x, 0xFFFF & y);
int32_t map_height = tile_element_height({ x, y });
if (map_height < z || map_height - 4 > z)
continue;
saved_height = map_height;
@ -2821,7 +2817,7 @@ static void peep_interact_with_path(Peep* peep, int16_t x, int16_t y, TileElemen
}
int16_t z = tile_element->base_height * 8;
if (map_is_location_owned(x, y, z))
if (map_is_location_owned({ x, y, z }))
{
if (peep->outside_of_park == 1)
{
@ -3159,8 +3155,7 @@ void Peep::PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result)
if (type == PEEP_TYPE_STAFF || (GetNextIsSurface()))
{
int16_t height = abs(tile_element_height(newLoc.x, newLoc.y) - z);
int16_t height = abs(tile_element_height(newLoc) - z);
if (height <= 3 || (type == PEEP_TYPE_STAFF && height <= 32))
{
interaction_ride_index = 0xFF;
@ -3176,14 +3171,14 @@ void Peep::PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result)
return;
}
tileElement = map_get_surface_element_at(newLoc);
if (tileElement == nullptr)
auto surfaceElement = map_get_surface_element_at(newLoc);
if (surfaceElement == nullptr)
{
peep_return_to_centre_of_tile(this);
return;
}
int16_t water_height = tileElement->AsSurface()->GetWaterHeight();
int16_t water_height = surfaceElement->GetWaterHeight();
if (water_height)
{
peep_return_to_centre_of_tile(this);
@ -3203,7 +3198,7 @@ void Peep::PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result)
// The peep is on a surface and not on a path
next_x = newLoc.x & 0xFFE0;
next_y = newLoc.y & 0xFFE0;
next_z = tileElement->base_height;
next_z = surfaceElement->base_height;
SetNextFlags(0, false, true);
height = GetZOnSlope(newLoc.x, newLoc.y);
@ -3248,7 +3243,7 @@ int32_t Peep::GetZOnSlope(int32_t tile_x, int32_t tile_y)
if (GetNextIsSurface())
{
return tile_element_height(tile_x, tile_y);
return tile_element_height({ tile_x, tile_y });
}
int32_t height = next_z * 8;

View File

@ -172,7 +172,7 @@ static bool staff_is_location_in_patrol_area(Peep* peep, int32_t x, int32_t y)
bool staff_is_location_in_patrol(Peep* staff, int32_t x, int32_t y)
{
// Check if location is in the park
if (!map_is_location_owned_or_has_rights(x, y))
if (!map_is_location_owned_or_has_rights({ x, y }))
return false;
// Check if staff has patrol area
@ -511,17 +511,17 @@ static uint8_t staff_handyman_direction_to_uncut_grass(Peep* peep, uint8_t valid
{
if (!(peep->GetNextIsSurface()))
{
TileElement* tileElement = map_get_surface_element_at({ peep->next_x, peep->next_y });
auto surfaceElement = map_get_surface_element_at({ peep->next_x, peep->next_y });
if (peep->next_z != tileElement->base_height)
if (peep->next_z != surfaceElement->base_height)
return 0xFF;
if (peep->GetNextIsSloped())
{
if (tileElement->AsSurface()->GetSlope() != PathSlopeToLandSlope[peep->GetNextDirection()])
if (surfaceElement->GetSlope() != PathSlopeToLandSlope[peep->GetNextDirection()])
return 0xFF;
}
else if (tileElement->AsSurface()->GetSlope() != TILE_ELEMENT_SLOPE_FLAT)
else if (surfaceElement->GetSlope() != TILE_ELEMENT_SLOPE_FLAT)
return 0xFF;
}
@ -541,7 +541,7 @@ static uint8_t staff_handyman_direction_to_uncut_grass(Peep* peep, uint8_t valid
if (chosenTile.x > 0x1FFF || chosenTile.y > 0x1FFF)
continue;
auto surfaceElement = map_get_surface_element_at(chosenTile)->AsSurface();
auto surfaceElement = map_get_surface_element_at(chosenTile);
if (surfaceElement != nullptr)
{
if (std::abs(surfaceElement->base_height - peep->next_z) <= 2)
@ -614,12 +614,12 @@ static bool staff_path_finding_handyman(Peep* peep)
}
else
{
TileElement* tileElement = map_get_path_element_at(peep->next_x / 32, peep->next_y / 32, peep->next_z);
auto* pathElement = map_get_path_element_at({ peep->next_x / 32, peep->next_y / 32, peep->next_z });
if (tileElement == nullptr)
if (pathElement == nullptr)
return true;
uint8_t pathDirections = (tileElement->AsPath()->GetEdges() & validDirections) & 0xF;
uint8_t pathDirections = (pathElement->GetEdges() & validDirections) & 0xF;
if (pathDirections == 0)
{
direction = staff_handyman_direction_rand_surface(peep, validDirections);
@ -782,10 +782,10 @@ static uint8_t staff_mechanic_direction_path_rand(Peep* peep, uint8_t pathDirect
*
* rct2: 0x006C0121
*/
static uint8_t staff_mechanic_direction_path(Peep* peep, uint8_t validDirections, TileElement* pathElement)
static uint8_t staff_mechanic_direction_path(Peep* peep, uint8_t validDirections, PathElement* pathElement)
{
uint8_t direction = 0xFF;
uint8_t pathDirections = pathElement->AsPath()->GetEdges();
uint8_t pathDirections = pathElement->GetEdges();
pathDirections &= validDirections;
if (pathDirections == 0)
@ -885,7 +885,7 @@ static bool staff_path_finding_mechanic(Peep* peep)
}
else
{
TileElement* pathElement = map_get_path_element_at(peep->next_x / 32, peep->next_y / 32, peep->next_z);
auto* pathElement = map_get_path_element_at({ peep->next_x / 32, peep->next_y / 32, peep->next_z });
if (pathElement == nullptr)
return true;
@ -917,10 +917,10 @@ static bool staff_path_finding_mechanic(Peep* peep)
*
* rct2: 0x006C050B
*/
static uint8_t staff_direction_path(Peep* peep, uint8_t validDirections, TileElement* pathElement)
static uint8_t staff_direction_path(Peep* peep, uint8_t validDirections, PathElement* pathElement)
{
uint8_t direction = 0xFF;
uint8_t pathDirections = pathElement->AsPath()->GetEdges();
uint8_t pathDirections = pathElement->GetEdges();
if (peep->state != PEEP_STATE_ANSWERING && peep->state != PEEP_STATE_HEADING_TO_INSPECTION)
{
pathDirections &= validDirections;
@ -973,7 +973,7 @@ static bool staff_path_finding_misc(Peep* peep)
}
else
{
TileElement* pathElement = map_get_path_element_at(peep->next_x / 32, peep->next_y / 32, peep->next_z);
auto* pathElement = map_get_path_element_at({ peep->next_x / 32, peep->next_y / 32, peep->next_z });
if (pathElement == nullptr)
return true;
@ -1181,7 +1181,7 @@ void Staff::UpdateMowing()
{
if (auto loc = UpdateAction())
{
int16_t checkZ = tile_element_height((*loc).x, (*loc).y);
int16_t checkZ = tile_element_height(*loc);
MoveTo((*loc).x, (*loc).y, checkZ);
Invalidate();
return;
@ -1206,7 +1206,7 @@ void Staff::UpdateMowing()
if (var_37 != 7)
continue;
auto surfaceElement = map_get_surface_element_at(next_x / 32, next_y / 32)->AsSurface();
auto surfaceElement = map_get_surface_element_at(next_x / 32, next_y / 32);
if (surfaceElement != nullptr && surfaceElement->CanGrassGrow())
{
surfaceElement->SetGrassLength(GRASS_LENGTH_MOWED);
@ -1778,7 +1778,7 @@ static int32_t peep_update_patrolling_find_grass(Peep* peep)
if (!(peep->GetNextIsSurface()))
return 0;
auto surfaceElement = map_get_surface_element_at({ peep->next_x, peep->next_y })->AsSurface();
auto surfaceElement = map_get_surface_element_at({ peep->next_x, peep->next_y });
if (surfaceElement != nullptr && surfaceElement->CanGrassGrow())
{
if ((surfaceElement->GetGrassLength() & 0x7) >= GRASS_LENGTH_CLEAR_1)
@ -1916,11 +1916,11 @@ void Staff::UpdatePatrolling()
if (GetNextIsSurface())
{
TileElement* tile_element = map_get_surface_element_at({ next_x, next_y });
auto surfaceElement = map_get_surface_element_at({ next_x, next_y });
if (tile_element != nullptr)
if (surfaceElement != nullptr)
{
int32_t water_height = tile_element->AsSurface()->GetWaterHeight();
int32_t water_height = surfaceElement->GetWaterHeight();
if (water_height)
{
Invalidate();
@ -2571,7 +2571,7 @@ bool Staff::UpdateFixingFixStationBrakes(bool firstRun, Ride* ride)
if (action_frame == 0x13 || action_frame == 0x19 || action_frame == 0x1F || action_frame == 0x25 || action_frame == 0x2B)
{
audio_play_sound_at_location(SoundId::MechanicFix, x, y, z);
audio_play_sound_at_location(SoundId::MechanicFix, { x, y, z });
}
return false;

View File

@ -3239,28 +3239,17 @@ void ride_check_all_reachable()
/**
*
* rct2: 0x006B7C59
* @return 1 if the coordinate is reachable or has no entrance, 0 otherwise
* @return true if the coordinate is reachable or has no entrance, false otherwise
*/
static int32_t ride_entrance_exit_is_reachable(TileCoordsXYZD coordinates)
static bool ride_entrance_exit_is_reachable(TileCoordsXYZD coordinates)
{
int32_t x, y, z;
if (coordinates.isNull())
return 1;
return true;
x = coordinates.x;
y = coordinates.y;
z = coordinates.z;
uint8_t face_direction = coordinates.direction;
TileCoordsXYZ loc{ coordinates.x, coordinates.y, coordinates.z };
loc -= TileDirectionDelta[coordinates.direction];
x *= 32;
y *= 32;
x -= CoordsDirectionDelta[face_direction].x;
y -= CoordsDirectionDelta[face_direction].y;
x /= 32;
y /= 32;
return map_coord_is_connected(x, y, z, face_direction);
return map_coord_is_connected(loc, coordinates.direction);
}
static void ride_entrance_exit_connected(Ride* ride)
@ -3299,17 +3288,14 @@ static void ride_entrance_exit_connected(Ride* ride)
static void ride_shop_connected(Ride* ride)
{
int32_t x, y, count;
LocationXY8 coordinates = ride->stations[0].Start;
if (coordinates.xy == RCT_XY8_UNDEFINED)
return;
x = coordinates.x;
y = coordinates.y;
TileCoordsXY loc = { coordinates.x, coordinates.y };
TrackElement* trackElement = nullptr;
TileElement* tileElement = map_get_first_element_at(x, y);
TileElement* tileElement = map_get_first_element_at(loc.x, loc.y);
do
{
if (tileElement == nullptr)
@ -3347,11 +3333,7 @@ static void ride_shop_connected(Ride* ride)
if (entrance_directions == 0)
return;
// Turn x, y from tiles into units
x *= 32;
y *= 32;
for (count = 0; entrance_directions != 0; count++)
for (auto count = 0; entrance_directions != 0; count++)
{
if (!(entrance_directions & 1))
{
@ -3363,10 +3345,10 @@ static void ride_shop_connected(Ride* ride)
// Flip direction north<->south, east<->west
uint8_t face_direction = direction_reverse(count);
int32_t y2 = y - CoordsDirectionDelta[face_direction].y;
int32_t x2 = x - CoordsDirectionDelta[face_direction].x;
int32_t y2 = loc.y - TileDirectionDelta[face_direction].y;
int32_t x2 = loc.x - TileDirectionDelta[face_direction].x;
if (map_coord_is_connected(x2 / 32, y2 / 32, tileElement->base_height, face_direction))
if (map_coord_is_connected({ x2, y2, tileElement->base_height }, face_direction))
return;
}
@ -7661,8 +7643,8 @@ StationObject* ride_get_station_object(const Ride* ride)
LocationXY16 ride_get_rotated_coords(int16_t x, int16_t y, int16_t z)
{
CoordsXYZ coords3d = { x, y, z };
CoordsXY coords2d = translate_3d_to_2d_with_z(get_current_rotation(), coords3d);
LocationXY16 rotatedCoords = { (int16_t)coords2d.x, (int16_t)coords2d.y };
auto screenCoords = translate_3d_to_2d_with_z(get_current_rotation(), coords3d);
LocationXY16 rotatedCoords = { (int16_t)screenCoords.x, (int16_t)screenCoords.y };
return rotatedCoords;
}

View File

@ -1409,7 +1409,7 @@ static int32_t ride_ratings_get_scenery_score(Ride* ride)
y = location.y;
}
int32_t z = tile_element_height(x * 32, y * 32);
int32_t z = tile_element_height({ x * 32, y * 32 });
// Check if station is underground, returns a fixed mediocre score since you can't have scenery underground
if (z > ride->stations[i].Height * 8)

View File

@ -1137,15 +1137,15 @@ static bool TrackDesignPlaceSceneryElement(
return true;
}
TileElement* tile_element = map_get_path_element_at(mapCoord.x / 32, mapCoord.y / 32, z);
auto* pathElement = map_get_path_element_at({ mapCoord.x / 32, mapCoord.y / 32, z });
if (tile_element == nullptr)
if (pathElement == nullptr)
{
return true;
}
footpath_queue_chain_reset();
footpath_remove_edges_at(mapCoord.x, mapCoord.y, tile_element);
footpath_remove_edges_at(mapCoord.x, mapCoord.y, reinterpret_cast<TileElement*>(pathElement));
flags = GAME_COMMAND_FLAG_APPLY;
if (_trackDesignPlaceOperation == PTD_OPERATION_PLACE_TRACK_PREVIEW)
@ -1158,7 +1158,7 @@ static bool TrackDesignPlaceSceneryElement(
| GAME_COMMAND_FLAG_GHOST;
}
footpath_connect_edges(mapCoord.x, mapCoord.y, tile_element, flags);
footpath_connect_edges(mapCoord.x, mapCoord.y, reinterpret_cast<TileElement*>(pathElement), flags);
footpath_update_queue_chains();
return true;
}
@ -1233,7 +1233,7 @@ static int32_t track_design_place_maze(TrackDesign* td6, int16_t x, int16_t y, i
gMapSelectionTiles.clear();
gMapSelectArrowPosition.x = x;
gMapSelectArrowPosition.y = y;
gMapSelectArrowPosition.z = tile_element_height(x, y);
gMapSelectArrowPosition.z = tile_element_height({ x, y });
gMapSelectArrowDirection = _currentTrackPieceDirection;
}
@ -1393,20 +1393,20 @@ static int32_t track_design_place_maze(TrackDesign* td6, int16_t x, int16_t y, i
continue;
}
TileElement* tile_element = map_get_surface_element_at(mapCoord);
int16_t map_height = tile_element->base_height * 8;
if (tile_element->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
auto surfaceElement = map_get_surface_element_at(mapCoord);
int16_t map_height = surfaceElement->base_height * 8;
if (surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
{
map_height += 16;
if (tile_element->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
if (surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
{
map_height += 16;
}
}
if (tile_element->AsSurface()->GetWaterHeight() > 0)
if (surfaceElement->GetWaterHeight() > 0)
{
int16_t water_height = tile_element->AsSurface()->GetWaterHeight();
int16_t water_height = surfaceElement->GetWaterHeight();
water_height *= 16;
if (water_height > map_height)
{
@ -1449,7 +1449,7 @@ static bool track_design_place_ride(TrackDesign* td6, int16_t x, int16_t y, int1
gMapSelectionTiles.clear();
gMapSelectArrowPosition.x = x;
gMapSelectArrowPosition.y = y;
gMapSelectArrowPosition.z = tile_element_height(x, y);
gMapSelectArrowPosition.z = tile_element_height({ x, y });
gMapSelectArrowDirection = _currentTrackPieceDirection;
}
@ -1562,23 +1562,23 @@ static bool track_design_place_ride(TrackDesign* td6, int16_t x, int16_t y, int1
continue;
}
TileElement* tileElement = map_get_surface_element_at(tile);
if (tileElement == nullptr)
auto surfaceElement = map_get_surface_element_at(tile);
if (surfaceElement == nullptr)
{
return false;
}
int32_t height = tileElement->base_height * 8;
if (tileElement->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
int32_t height = surfaceElement->base_height * 8;
if (surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
{
height += 16;
if (tileElement->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
if (surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
{
height += 16;
}
}
uint8_t water_height = tileElement->AsSurface()->GetWaterHeight() * 16;
uint8_t water_height = surfaceElement->GetWaterHeight() * 16;
if (water_height > 0 && water_height > height)
{
height = water_height;
@ -2117,7 +2117,7 @@ static money32 place_maze_design(uint8_t flags, Ride* ride, uint16_t mazeEntry,
if (!gCheatsSandboxMode)
{
if (!map_is_location_owned(floor2(x, 32), floor2(y, 32), z))
if (!map_is_location_owned({ x, y, z }))
{
return MONEY32_UNDEFINED;
}
@ -2126,11 +2126,11 @@ static money32 place_maze_design(uint8_t flags, Ride* ride, uint16_t mazeEntry,
// Check support height
if (!gCheatsDisableSupportLimits)
{
TileElement* tileElement = map_get_surface_element_at({ x, y });
auto surfaceElement = map_get_surface_element_at({ x, y });
uint8_t supportZ = (z + 32) >> 3;
if (supportZ > tileElement->base_height)
if (supportZ > surfaceElement->base_height)
{
uint8_t supportHeight = (supportZ - tileElement->base_height) / 2;
uint8_t supportHeight = (supportZ - surfaceElement->base_height) / 2;
uint8_t maxSupportHeight = RideData5[RIDE_TYPE_MAZE].max_height;
if (supportHeight > maxSupportHeight)
{
@ -2184,7 +2184,7 @@ static money32 place_maze_design(uint8_t flags, Ride* ride, uint16_t mazeEntry,
int32_t fx = floor2(x, 32);
int32_t fy = floor2(y, 32);
int32_t fz = z >> 3;
TileElement* tileElement = tile_element_insert(fx >> 5, fy >> 5, fz, 15);
TileElement* tileElement = tile_element_insert({ fx >> 5, fy >> 5, fz }, 15);
tileElement->clearance_height = fz + 4;
tileElement->SetType(TILE_ELEMENT_TYPE_TRACK);
tileElement->AsTrack()->SetTrackType(TRACK_ELEM_MAZE);
@ -2337,12 +2337,12 @@ void track_design_draw_preview(TrackDesign* td6, uint8_t* pixels)
{
gCurrentRotation = i;
CoordsXY pos2d = translate_3d_to_2d_with_z(i, centre);
pos2d.x -= offset.x;
pos2d.y -= offset.y;
auto screenCoords = translate_3d_to_2d_with_z(i, centre);
screenCoords.x -= offset.x;
screenCoords.y -= offset.y;
int32_t left = pos2d.x;
int32_t top = pos2d.y;
int32_t left = screenCoords.x;
int32_t top = screenCoords.y;
int32_t right = left + size_x;
int32_t bottom = top + size_y;

View File

@ -974,10 +974,10 @@ static void vehicle_update_sound_params(rct_vehicle* vehicle)
if (vehicle->x != LOCATION_NULL)
{
TileElement* tile_element = map_get_surface_element_at({ vehicle->x, vehicle->y });
auto surfaceElement = map_get_surface_element_at({ vehicle->x, vehicle->y });
// vehicle underground
if (tile_element != nullptr && tile_element->base_height * 8 > vehicle->z)
if (surfaceElement != nullptr && surfaceElement->base_height * 8 > vehicle->z)
{
soundParam->volume = 0x30;
}
@ -1823,13 +1823,13 @@ static void vehicle_update_measurements(rct_vehicle* vehicle)
return;
}
TileElement* tile_element = map_get_surface_element_at({ x, y });
auto surfaceElement = map_get_surface_element_at({ x, y });
// If vehicle above ground.
if (tile_element != nullptr && tile_element->base_height * 8 <= z)
if (surfaceElement != nullptr && surfaceElement->base_height * 8 <= z)
{
// Set tile_element to first element. Since elements aren't always ordered by base height,
// we must start at the first element and iterate through each tile element.
tile_element = map_get_first_element_at(x / 32, y / 32);
auto tile_element = map_get_first_element_at(x / 32, y / 32);
bool cover_found = false;
do
@ -3230,12 +3230,12 @@ static void vehicle_update_departing(rct_vehicle* vehicle)
{
auto soundId = (rideEntry->vehicles[0].sound_range == 4) ? SoundId::Tram : SoundId::TrainDeparting;
audio_play_sound_at_location(soundId, vehicle->x, vehicle->y, vehicle->z);
audio_play_sound_at_location(soundId, { vehicle->x, vehicle->y, vehicle->z });
}
if (ride->mode == RIDE_MODE_UPWARD_LAUNCH || (ride->mode == RIDE_MODE_DOWNWARD_LAUNCH && vehicle->var_CE > 1))
{
audio_play_sound_at_location(SoundId::RideLaunch2, vehicle->x, vehicle->y, vehicle->z);
audio_play_sound_at_location(SoundId::RideLaunch2, { vehicle->x, vehicle->y, vehicle->z });
}
if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_TESTED))
@ -3442,7 +3442,7 @@ static void vehicle_finish_departing(rct_vehicle* vehicle)
if (vehicle->var_CE >= 1 && (14 << 16) > vehicle->velocity)
return;
audio_play_sound_at_location(SoundId::RideLaunch1, vehicle->x, vehicle->y, vehicle->z);
audio_play_sound_at_location(SoundId::RideLaunch1, { vehicle->x, vehicle->y, vehicle->z });
}
if (ride->mode == RIDE_MODE_UPWARD_LAUNCH)
@ -3450,7 +3450,7 @@ static void vehicle_finish_departing(rct_vehicle* vehicle)
if ((ride->launch_speed << 16) > vehicle->velocity)
return;
audio_play_sound_at_location(SoundId::RideLaunch1, vehicle->x, vehicle->y, vehicle->z);
audio_play_sound_at_location(SoundId::RideLaunch1, { vehicle->x, vehicle->y, vehicle->z });
}
if (ride->mode != RIDE_MODE_RACE && ride->mode != RIDE_MODE_CONTINUOUS_CIRCUIT_BLOCK_SECTIONED
@ -3576,7 +3576,7 @@ static void vehicle_update_collision_setup(rct_vehicle* vehicle)
train->sub_state = 2;
audio_play_sound_at_location(SoundId::Crash, train->x, train->y, train->z);
audio_play_sound_at_location(SoundId::Crash, { train->x, train->y, train->z });
sprite_misc_explosion_cloud_create(train->x, train->y, train->z);
@ -3628,7 +3628,7 @@ static void vehicle_update_crash_setup(rct_vehicle* vehicle)
int32_t num_peeps = vehicle_get_total_num_peeps(vehicle);
if (num_peeps != 0)
{
audio_play_sound_at_location(SoundId::HauntedHouseScream2, vehicle->x, vehicle->y, vehicle->z);
audio_play_sound_at_location(SoundId::HauntedHouseScream2, { vehicle->x, vehicle->y, vehicle->z });
}
int32_t edx = vehicle->velocity >> 10;
@ -4043,7 +4043,7 @@ loc_6D8E36:
if ((ride->mode == RIDE_MODE_UPWARD_LAUNCH || ride->mode == RIDE_MODE_DOWNWARD_LAUNCH) && vehicle->var_CE < 2)
{
audio_play_sound_at_location(SoundId::RideLaunch2, vehicle->x, vehicle->y, vehicle->z);
audio_play_sound_at_location(SoundId::RideLaunch2, { vehicle->x, vehicle->y, vehicle->z });
vehicle->velocity = 0;
vehicle->acceleration = 0;
vehicle->SetState(VEHICLE_STATUS_DEPARTING, 1);
@ -5037,24 +5037,24 @@ static void vehicle_update_haunted_house_operating(rct_vehicle* vehicle)
switch (vehicle->current_time)
{
case 45:
audio_play_sound_at_location(SoundId::HauntedHouseScare, vehicle->x, vehicle->y, vehicle->z);
audio_play_sound_at_location(SoundId::HauntedHouseScare, { vehicle->x, vehicle->y, vehicle->z });
break;
case 75:
vehicle->vehicle_sprite_type = 1;
vehicle->Invalidate();
break;
case 400:
audio_play_sound_at_location(SoundId::HauntedHouseScream1, vehicle->x, vehicle->y, vehicle->z);
audio_play_sound_at_location(SoundId::HauntedHouseScream1, { vehicle->x, vehicle->y, vehicle->z });
break;
case 745:
audio_play_sound_at_location(SoundId::HauntedHouseScare, vehicle->x, vehicle->y, vehicle->z);
audio_play_sound_at_location(SoundId::HauntedHouseScare, { vehicle->x, vehicle->y, vehicle->z });
break;
case 775:
vehicle->vehicle_sprite_type = 1;
vehicle->Invalidate();
break;
case 1100:
audio_play_sound_at_location(SoundId::HauntedHouseScream2, vehicle->x, vehicle->y, vehicle->z);
audio_play_sound_at_location(SoundId::HauntedHouseScream2, { vehicle->x, vehicle->y, vehicle->z });
break;
}
}
@ -5301,7 +5301,7 @@ static void vehicle_crash_on_land(rct_vehicle* vehicle)
}
vehicle->sub_state = 2;
audio_play_sound_at_location(SoundId::Crash, vehicle->x, vehicle->y, vehicle->z);
audio_play_sound_at_location(SoundId::Crash, { vehicle->x, vehicle->y, vehicle->z });
sprite_misc_explosion_cloud_create(vehicle->x, vehicle->y, vehicle->z);
sprite_misc_explosion_flare_create(vehicle->x, vehicle->y, vehicle->z);
@ -5362,7 +5362,7 @@ static void vehicle_crash_on_water(rct_vehicle* vehicle)
}
vehicle->sub_state = 2;
audio_play_sound_at_location(SoundId::Water1, vehicle->x, vehicle->y, vehicle->z);
audio_play_sound_at_location(SoundId::Water1, { vehicle->x, vehicle->y, vehicle->z });
crash_splash_create(vehicle->x, vehicle->y, vehicle->z);
crash_splash_create(vehicle->x - 8, vehicle->y - 9, vehicle->z);
@ -5431,8 +5431,8 @@ static void vehicle_update_crash(rct_vehicle* vehicle)
continue;
}
int16_t z = tile_element_height(curVehicle->x, curVehicle->y);
int16_t waterHeight = tile_element_water_height(curVehicle->x, curVehicle->y);
int16_t z = tile_element_height({ curVehicle->x, curVehicle->y });
int16_t waterHeight = tile_element_water_height({ curVehicle->x, curVehicle->y });
int16_t zDiff;
if (waterHeight != 0)
{
@ -6794,7 +6794,7 @@ static void vehicle_update_block_brakes_open_previous_section(rct_vehicle* vehic
auto ride = get_ride(vehicle->ride);
if (ride != nullptr && ride->IsBlockSectioned())
{
audio_play_sound_at_location(SoundId::BlockBrakeClose, x, y, z);
audio_play_sound_at_location(SoundId::BlockBrakeClose, { x, y, z });
}
}
}
@ -7229,8 +7229,8 @@ static void vehicle_update_spinning_car(rct_vehicle* vehicle)
*/
static void steam_particle_create(int16_t x, int16_t y, int16_t z)
{
TileElement* tileElement = map_get_surface_element_at({ x, y });
if (tileElement != nullptr && z > tileElement->base_height * 8)
auto surfaceElement = map_get_surface_element_at({ x, y });
if (surfaceElement != nullptr && z > surfaceElement->base_height * 8)
{
rct_steam_particle* steam = &create_sprite(SPRITE_IDENTIFIER_MISC)->steam_particle;
if (steam == nullptr)
@ -7412,7 +7412,7 @@ static void vehicle_play_scenery_door_open_sound(rct_vehicle* vehicle, WallEleme
auto soundId = DoorOpenSoundIds[doorSoundType - 1];
if (soundId != SoundId::Null)
{
audio_play_sound_at_location(soundId, vehicle->x, vehicle->track_y, vehicle->track_z);
audio_play_sound_at_location(soundId, { vehicle->track_x, vehicle->track_y, vehicle->track_z });
}
}
}
@ -7430,7 +7430,7 @@ static void vehicle_play_scenery_door_close_sound(rct_vehicle* vehicle, WallElem
auto soundId = DoorCloseSoundIds[doorSoundType - 1];
if (soundId != SoundId::Null)
{
audio_play_sound_at_location(soundId, vehicle->x, vehicle->track_y, vehicle->track_z);
audio_play_sound_at_location(soundId, { vehicle->track_x, vehicle->track_y, vehicle->track_z });
}
}
}
@ -7561,7 +7561,7 @@ static void vehicle_update_play_water_splash_sound()
return;
}
audio_play_sound_at_location(SoundId::WaterSplash, unk_F64E20.x, unk_F64E20.y, unk_F64E20.z);
audio_play_sound_at_location(SoundId::WaterSplash, { unk_F64E20.x, unk_F64E20.y, unk_F64E20.z });
}
/**
@ -7977,7 +7977,7 @@ static bool vehicle_update_track_motion_forwards_get_new_track(
if (!(rideEntry->vehicles[0].flags & VEHICLE_ENTRY_FLAG_POWERED))
{
audio_play_sound_at_location(
SoundId::BlockBrakeRelease, vehicle->track_x, vehicle->track_y, vehicle->track_z);
SoundId::BlockBrakeRelease, { vehicle->track_x, vehicle->track_y, vehicle->track_z });
}
}
map_invalidate_element(vehicle->track_x, vehicle->track_z, tileElement);
@ -8188,7 +8188,7 @@ loc_6DAEB9:
if (_vehicleF64E2C == 0)
{
_vehicleF64E2C++;
audio_play_sound_at_location(SoundId::BrakeRelease, vehicle->x, vehicle->y, vehicle->z);
audio_play_sound_at_location(SoundId::BrakeRelease, { vehicle->x, vehicle->y, vehicle->z });
}
}
}
@ -9917,20 +9917,19 @@ void vehicle_update_crossings(const rct_vehicle* vehicle)
while (true)
{
TileElement* tileElement = map_get_path_element_at(
xyElement.x / 32, xyElement.y / 32, xyElement.element->base_height);
auto* pathElement = map_get_path_element_at({ xyElement.x / 32, xyElement.y / 32, xyElement.element->base_height });
auto ride = get_ride(vehicle->ride);
// Many New Element parks have invisible rides hacked into the path.
// Limit path blocking to Miniature Railway to prevent peeps getting stuck everywhere.
if (tileElement && ride != nullptr && ride->type == RIDE_TYPE_MINIATURE_RAILWAY)
if (pathElement && ride != nullptr && ride->type == RIDE_TYPE_MINIATURE_RAILWAY)
{
if (!playedClaxon && !tileElement->AsPath()->IsBlockedByVehicle())
if (!playedClaxon && !pathElement->IsBlockedByVehicle())
{
vehicle_claxon(vehicle);
}
crossingBonus = 4;
tileElement->AsPath()->SetIsBlockedByVehicle(true);
pathElement->SetIsBlockedByVehicle(true);
}
else
{
@ -9993,11 +9992,10 @@ void vehicle_update_crossings(const rct_vehicle* vehicle)
}
}
TileElement* tileElement = map_get_path_element_at(
xyElement.x / 32, xyElement.y / 32, xyElement.element->base_height);
if (tileElement)
auto* pathElement = map_get_path_element_at({ xyElement.x / 32, xyElement.y / 32, xyElement.element->base_height });
if (pathElement)
{
tileElement->AsPath()->SetIsBlockedByVehicle(false);
pathElement->SetIsBlockedByVehicle(false);
}
}
}
@ -10009,10 +10007,10 @@ void vehicle_claxon(const rct_vehicle* vehicle)
switch (rideEntry->vehicles[vehicle->vehicle_type].sound_range)
{
case SOUND_RANGE_WHISTLE:
audio_play_sound_at_location(SoundId::TrainWhistle, vehicle->x, vehicle->y, vehicle->z);
audio_play_sound_at_location(SoundId::TrainWhistle, { vehicle->x, vehicle->y, vehicle->z });
break;
case SOUND_RANGE_BELL:
audio_play_sound_at_location(SoundId::Tram, vehicle->x, vehicle->y, vehicle->z);
audio_play_sound_at_location(SoundId::Tram, { vehicle->x, vehicle->y, vehicle->z });
break;
}
}

View File

@ -433,7 +433,7 @@ static int32_t scenario_create_ducks()
if (!map_is_location_in_park({ x, y }))
return 0;
centreWaterZ = (tile_element_water_height(x, y));
centreWaterZ = (tile_element_water_height({ x, y }));
if (centreWaterZ == 0)
return 0;
@ -445,7 +445,7 @@ static int32_t scenario_create_ducks()
{
for (j = 0; j < 7; j++)
{
waterZ = (tile_element_water_height(x2, y2));
waterZ = (tile_element_water_height({ x2, y2 }));
if (waterZ == centreWaterZ)
c++;

View File

@ -81,7 +81,7 @@ void rct_balloon::Pop()
{
popped = 1;
frame = 0;
audio_play_sound_at_location(SoundId::BalloonPop, x, y, z);
audio_play_sound_at_location(SoundId::BalloonPop, { x, y, z });
}
void create_balloon(int32_t x, int32_t y, int32_t z, int32_t colour, bool isPopped)

View File

@ -122,8 +122,8 @@ void rct_duck::UpdateFlyToWater()
int32_t newY = y + DuckMoveOffset[direction].y;
int32_t manhattanDistanceN = abs(target_x - newX) + abs(target_y - newY);
TileElement* tileElement = map_get_surface_element_at({ target_x, target_y });
int32_t waterHeight = tileElement->AsSurface()->GetWaterHeight();
auto surfaceElement = map_get_surface_element_at({ target_x, target_y });
int32_t waterHeight = surfaceElement->GetWaterHeight();
if (waterHeight == 0)
{
state = DUCK_STATE::FLY_AWAY;
@ -201,8 +201,8 @@ void rct_duck::UpdateSwim()
else
{
Invalidate();
int16_t landZ = tile_element_height(x, y);
int16_t waterZ = tile_element_water_height(x, y);
int16_t landZ = tile_element_height({ x, y });
int16_t waterZ = tile_element_water_height({ x, y });
if (z < landZ || waterZ == 0)
{
@ -222,8 +222,8 @@ void rct_duck::UpdateSwim()
int32_t direction = sprite_direction >> 3;
int32_t newX = x + DuckMoveOffset[direction].x;
int32_t newY = y + DuckMoveOffset[direction].y;
landZ = tile_element_height(newX, newY);
waterZ = tile_element_water_height(newX, newY);
landZ = tile_element_height({ newX, newY });
waterZ = tile_element_water_height({ newX, newY });
if (z >= landZ && z == waterZ)
{
@ -367,7 +367,7 @@ void duck_update(rct_duck* duck)
void duck_press(rct_duck* duck)
{
audio_play_sound_at_location(SoundId::Quack, duck->x, duck->y, duck->z);
audio_play_sound_at_location(SoundId::Quack, { duck->x, duck->y, duck->z });
}
void duck_remove_all()

View File

@ -292,7 +292,7 @@ void footpath_get_coordinates_from_pos(
{
if (interactionType != VIEWPORT_INTERACTION_ITEM_FOOTPATH)
{
z = tile_element_height(position.x, position.y);
z = tile_element_height({ position.x, position.y });
}
position = viewport_coord_to_map_coord(start_vp_pos.x, start_vp_pos.y, z);
position.x = std::clamp(position.x, minPosition.x, maxPosition.x);
@ -1212,7 +1212,7 @@ void footpath_update_queue_chains()
*/
static void footpath_fix_ownership(int32_t x, int32_t y)
{
const TileElement* surfaceElement = map_get_surface_element_at({ x, y });
const auto* surfaceElement = map_get_surface_element_at({ x, y });
uint16_t ownership;
// Unlikely to be NULL unless deliberate.
@ -1226,7 +1226,7 @@ static void footpath_fix_ownership(int32_t x, int32_t y)
// If the tile is safe to own construction rights of, do not erase contruction rights.
else
{
ownership = surfaceElement->AsSurface()->GetOwnership();
ownership = surfaceElement->GetOwnership();
// You can't own the entrance path.
if (ownership == OWNERSHIP_OWNED || ownership == OWNERSHIP_AVAILABLE)
{
@ -1846,8 +1846,8 @@ void footpath_update_path_wide_flags(int32_t x, int32_t y)
bool footpath_is_blocked_by_vehicle(const TileCoordsXYZ& position)
{
auto pathElement = map_get_path_element_at(position.x, position.y, position.z);
return pathElement != nullptr && pathElement->AsPath()->IsBlockedByVehicle();
auto pathElement = map_get_path_element_at(position);
return pathElement != nullptr && pathElement->IsBlockedByVehicle();
}
/**

View File

@ -55,6 +55,19 @@ assert_struct_size(LocationXYZ16, 6);
constexpr int32_t COORDS_NULL = -1;
struct ScreenCoordsXY
{
int32_t x = 0;
int32_t y = 0;
ScreenCoordsXY() = default;
constexpr ScreenCoordsXY(int32_t _x, int32_t _y)
: x(_x)
, y(_y)
{
}
};
/**
* Tile coordinates use 1 x/y increment per tile and 1 z increment per step.
* Regular ('big', 'sprite') coordinates use 32 x/y increments per tile and 8 z increments per step.
@ -95,7 +108,7 @@ struct CoordsXY
return { rhs.x - x, rhs.y - y };
}
CoordsXY Rotate(int32_t direction)
CoordsXY Rotate(int32_t direction) const
{
CoordsXY rotatedCoords;
switch (direction & 3)
@ -179,23 +192,19 @@ struct TileCoordsXY
int32_t x = 0, y = 0;
};
struct CoordsXYZ
struct CoordsXYZ : public CoordsXY
{
int32_t x = 0;
int32_t y = 0;
int32_t z = 0;
CoordsXYZ() = default;
constexpr CoordsXYZ(int32_t _x, int32_t _y, int32_t _z)
: x(_x)
, y(_y)
: CoordsXY(_x, _y)
, z(_z)
{
}
constexpr CoordsXYZ(CoordsXY c, int32_t _z)
: x(c.x)
, y(c.y)
: CoordsXY(c)
, z(_z)
{
}
@ -229,6 +238,12 @@ struct TileCoordsXYZ
return *this;
}
TileCoordsXYZ& operator-=(const TileCoordsXY rhs)
{
x -= rhs.x;
y -= rhs.y;
return *this;
}
bool operator==(const TileCoordsXYZ& other) const
{
return x == other.x && y == other.y && z == other.z;
@ -266,10 +281,16 @@ typedef uint8_t Direction;
return dir < 4;
}
struct CoordsXYZD
struct CoordsXYZD : public CoordsXYZ
{
int32_t x, y, z;
Direction direction;
Direction direction = 0;
CoordsXYZD() = default;
constexpr CoordsXYZD(int32_t _x, int32_t _y, int32_t _z, Direction _d)
: CoordsXYZ(_x, _y, _z)
, direction(_d)
{
}
bool isNull() const
{

View File

@ -109,8 +109,8 @@ LocationXYZ16 gCommandPosition;
bool gMapLandRightsUpdateSuccess;
static void clear_elements_at(int32_t x, int32_t y);
static void translate_3d_to_2d(int32_t rotation, int32_t* x, int32_t* y);
static void clear_elements_at(const CoordsXY& loc);
static ScreenCoordsXY translate_3d_to_2d(int32_t rotation, const CoordsXY& pos);
void rotate_map_coordinates(int16_t* x, int16_t* y, int32_t rotation)
{
@ -137,35 +137,6 @@ void rotate_map_coordinates(int16_t* x, int16_t* y, int32_t rotation)
}
}
LocationXY16 coordinate_3d_to_2d(const LocationXYZ16* coordinate_3d, int32_t rotation)
{
LocationXY16 coordinate_2d;
switch (rotation)
{
// this function has to use right-shift (... >> 1) since dividing
// by 2 with (... / 2) can differ by -1 and cause issues (see PR #9301)
default:
case 0:
coordinate_2d.x = coordinate_3d->y - coordinate_3d->x;
coordinate_2d.y = ((coordinate_3d->y + coordinate_3d->x) >> 1) - coordinate_3d->z;
break;
case 1:
coordinate_2d.x = -coordinate_3d->y - coordinate_3d->x;
coordinate_2d.y = ((coordinate_3d->y - coordinate_3d->x) >> 1) - coordinate_3d->z;
break;
case 2:
coordinate_2d.x = -coordinate_3d->y + coordinate_3d->x;
coordinate_2d.y = ((-coordinate_3d->y - coordinate_3d->x) >> 1) - coordinate_3d->z;
break;
case 3:
coordinate_2d.x = coordinate_3d->y + coordinate_3d->x;
coordinate_2d.y = ((-coordinate_3d->y + coordinate_3d->x) >> 1) - coordinate_3d->z;
break;
}
return coordinate_2d;
}
void tile_element_iterator_begin(tile_element_iterator* it)
{
it->x = 0;
@ -257,7 +228,7 @@ void map_set_tile_elements(int32_t x, int32_t y, TileElement* elements)
gTileElementTilePointers[x + y * MAXIMUM_MAP_SIZE_TECHNICAL] = elements;
}
TileElement* map_get_surface_element_at(int32_t x, int32_t y)
SurfaceElement* map_get_surface_element_at(int32_t x, int32_t y)
{
TileElement* tileElement = map_get_first_element_at(x, y);
@ -273,17 +244,17 @@ TileElement* map_get_surface_element_at(int32_t x, int32_t y)
tileElement++;
}
return tileElement;
return tileElement->AsSurface();
}
TileElement* map_get_surface_element_at(const CoordsXY coords)
SurfaceElement* map_get_surface_element_at(const CoordsXY& coords)
{
return map_get_surface_element_at(coords.x / 32, coords.y / 32);
}
TileElement* map_get_path_element_at(int32_t x, int32_t y, int32_t z)
PathElement* map_get_path_element_at(const TileCoordsXYZ& loc)
{
TileElement* tileElement = map_get_first_element_at(x, y);
TileElement* tileElement = map_get_first_element_at(loc.x, loc.y);
if (tileElement == nullptr)
return nullptr;
@ -295,10 +266,10 @@ TileElement* map_get_path_element_at(int32_t x, int32_t y, int32_t z)
continue;
if (tileElement->GetType() != TILE_ELEMENT_TYPE_PATH)
continue;
if (tileElement->base_height != z)
if (tileElement->base_height != loc.z)
continue;
return tileElement;
return tileElement->AsPath();
} while (!(tileElement++)->IsLastForTile());
return nullptr;
@ -381,14 +352,14 @@ void map_count_remaining_land_rights()
{
for (int32_t y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++)
{
TileElement* element = map_get_surface_element_at(x, y);
auto* surfaceElement = map_get_surface_element_at(x, y);
// Surface elements are sometimes hacked out to save some space for other map elements
if (element == nullptr)
if (surfaceElement == nullptr)
{
continue;
}
uint8_t flags = element->AsSurface()->GetOwnership();
uint8_t flags = surfaceElement->GetOwnership();
// Do not combine this condition with (flags & OWNERSHIP_AVAILABLE)
// As some RCT1 parks have owned tiles with the 'construction rights available' flag also set
@ -461,29 +432,23 @@ void map_update_tile_pointers()
* dx: return remember to & with 0xFFFF if you don't want water affecting results
* rct2: 0x00662783
*/
int16_t tile_element_height(int32_t x, int32_t y)
int16_t tile_element_height(const CoordsXY& loc)
{
TileElement* tileElement;
// Off the map
if ((unsigned)x >= 8192 || (unsigned)y >= 8192)
if ((unsigned)loc.x >= 8192 || (unsigned)loc.y >= 8192)
return 16;
// Truncate subtile coordinates
int32_t x_tile = x & 0xFFFFFFE0;
int32_t y_tile = y & 0xFFFFFFE0;
// Get the surface element for the tile
tileElement = map_get_surface_element_at({ x_tile, y_tile });
auto surfaceElement = map_get_surface_element_at(loc);
if (tileElement == nullptr)
if (surfaceElement == nullptr)
{
return 16;
}
uint16_t height = (tileElement->base_height << 3);
uint16_t height = (surfaceElement->base_height << 3);
uint32_t slope = tileElement->AsSurface()->GetSlope();
uint32_t slope = surfaceElement->GetSlope();
uint8_t extra_height = (slope & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT) >> 4; // 0x10 is the 5th bit - sets slope to double height
// Remove the extra height bit
slope &= TILE_ELEMENT_SLOPE_ALL_CORNERS_UP;
@ -495,8 +460,8 @@ int16_t tile_element_height(int32_t x, int32_t y)
uint8_t TILE_SIZE = 31;
xl = x & 0x1f;
yl = y & 0x1f;
xl = loc.x & 0x1f;
yl = loc.y & 0x1f;
// Slope logic:
// Each of the four bits in slope represents that corner being raised
@ -613,27 +578,21 @@ int16_t tile_element_height(int32_t x, int32_t y)
return height;
}
int16_t tile_element_water_height(int32_t x, int32_t y)
int16_t tile_element_water_height(const CoordsXY& loc)
{
TileElement* tileElement;
// Off the map
if ((unsigned)x >= 8192 || (unsigned)y >= 8192)
if ((unsigned)loc.x >= 8192 || (unsigned)loc.y >= 8192)
return 0;
// Truncate subtile coordinates
int32_t x_tile = x & 0xFFFFFFE0;
int32_t y_tile = y & 0xFFFFFFE0;
// Get the surface element for the tile
tileElement = map_get_surface_element_at({ x_tile, y_tile });
auto surfaceElement = map_get_surface_element_at(loc);
if (tileElement == nullptr)
if (surfaceElement == nullptr)
{
return 0;
}
uint16_t height = (tileElement->AsSurface()->GetWaterHeight() << 4);
uint16_t height = (surfaceElement->GetWaterHeight() << 4);
return height;
}
@ -642,9 +601,9 @@ int16_t tile_element_water_height(int32_t x, int32_t y)
* Checks if the tile at coordinate at height counts as connected.
* @return 1 if connected, 0 otherwise
*/
bool map_coord_is_connected(int32_t x, int32_t y, int32_t z, uint8_t faceDirection)
bool map_coord_is_connected(const TileCoordsXYZ& loc, uint8_t faceDirection)
{
TileElement* tileElement = map_get_first_element_at(x, y);
TileElement* tileElement = map_get_first_element_at(loc.x, loc.y);
do
{
@ -657,17 +616,17 @@ bool map_coord_is_connected(int32_t x, int32_t y, int32_t z, uint8_t faceDirecti
{
if (slopeDirection == faceDirection)
{
if (z == tileElement->base_height + 2)
if (loc.z == tileElement->base_height + 2)
return true;
}
else if (direction_reverse(slopeDirection) == faceDirection && z == tileElement->base_height)
else if (direction_reverse(slopeDirection) == faceDirection && loc.z == tileElement->base_height)
{
return true;
}
}
else
{
if (z == tileElement->base_height)
if (loc.z == tileElement->base_height)
return true;
}
} while (!(tileElement++)->IsLastForTile());
@ -715,7 +674,7 @@ void map_update_path_wide_flags()
*
* rct2: 0x006A7B84
*/
int32_t map_height_from_slope(const CoordsXY coords, int32_t slope, bool isSloped)
int32_t map_height_from_slope(const CoordsXY& coords, int32_t slope, bool isSloped)
{
if (!isSloped)
return 0;
@ -734,25 +693,25 @@ int32_t map_height_from_slope(const CoordsXY coords, int32_t slope, bool isSlope
return 0;
}
bool map_is_location_valid(const CoordsXY coords)
bool map_is_location_valid(const CoordsXY& coords)
{
const bool is_x_valid = coords.x < (MAXIMUM_MAP_SIZE_TECHNICAL * 32) && coords.x >= 0;
const bool is_y_valid = coords.y < (MAXIMUM_MAP_SIZE_TECHNICAL * 32) && coords.y >= 0;
return is_x_valid && is_y_valid;
}
bool map_is_edge(const CoordsXY coords)
bool map_is_edge(const CoordsXY& coords)
{
return (coords.x < 32 || coords.y < 32 || coords.x >= gMapSizeUnits || coords.y >= gMapSizeUnits);
}
bool map_can_build_at(int32_t x, int32_t y, int32_t z)
bool map_can_build_at(const CoordsXYZ& loc)
{
if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR)
return true;
if (gCheatsSandboxMode)
return true;
if (map_is_location_owned(x, y, z))
if (map_is_location_owned(loc))
return true;
return false;
}
@ -761,21 +720,20 @@ bool map_can_build_at(int32_t x, int32_t y, int32_t z)
*
* rct2: 0x00664F72
*/
bool map_is_location_owned(int32_t x, int32_t y, int32_t z)
bool map_is_location_owned(const CoordsXYZ& loc)
{
// This check is to avoid throwing lots of messages in logs.
if (map_is_location_valid({ x, y }))
if (map_is_location_valid(loc))
{
TileElement* tileElement = map_get_surface_element_at({ x, y });
if (tileElement != nullptr)
auto* surfaceElement = map_get_surface_element_at(loc);
if (surfaceElement != nullptr)
{
if (tileElement->AsSurface()->GetOwnership() & OWNERSHIP_OWNED)
if (surfaceElement->GetOwnership() & OWNERSHIP_OWNED)
return true;
if (tileElement->AsSurface()->GetOwnership() & OWNERSHIP_CONSTRUCTION_RIGHTS_OWNED)
if (surfaceElement->GetOwnership() & OWNERSHIP_CONSTRUCTION_RIGHTS_OWNED)
{
z /= 8;
if (z < tileElement->base_height || z - 2 > tileElement->base_height)
if (loc.z / 8 < surfaceElement->base_height || loc.z / 8 - 2 > surfaceElement->base_height)
return true;
}
}
@ -789,14 +747,14 @@ bool map_is_location_owned(int32_t x, int32_t y, int32_t z)
*
* rct2: 0x00664F2C
*/
bool map_is_location_in_park(const CoordsXY coords)
bool map_is_location_in_park(const CoordsXY& coords)
{
if (map_is_location_valid(coords))
{
TileElement* tileElement = map_get_surface_element_at(coords);
if (tileElement == nullptr)
auto surfaceElement = map_get_surface_element_at(coords);
if (surfaceElement == nullptr)
return false;
if (tileElement->AsSurface()->GetOwnership() & OWNERSHIP_OWNED)
if (surfaceElement->GetOwnership() & OWNERSHIP_OWNED)
return true;
}
@ -804,18 +762,18 @@ bool map_is_location_in_park(const CoordsXY coords)
return false;
}
bool map_is_location_owned_or_has_rights(int32_t x, int32_t y)
bool map_is_location_owned_or_has_rights(const CoordsXY& loc)
{
if (map_is_location_valid({ x, y }))
if (map_is_location_valid(loc))
{
TileElement* tileElement = map_get_surface_element_at({ x, y });
if (tileElement == nullptr)
auto surfaceElement = map_get_surface_element_at(loc);
if (surfaceElement == nullptr)
{
return false;
}
if (tileElement->AsSurface()->GetOwnership() & OWNERSHIP_OWNED)
if (surfaceElement->GetOwnership() & OWNERSHIP_OWNED)
return true;
if (tileElement->AsSurface()->GetOwnership() & OWNERSHIP_CONSTRUCTION_RIGHTS_OWNED)
if (surfaceElement->GetOwnership() & OWNERSHIP_CONSTRUCTION_RIGHTS_OWNED)
return true;
}
return false;
@ -920,54 +878,52 @@ int32_t map_get_corner_height(int32_t z, int32_t slope, int32_t direction)
return z;
}
int32_t tile_element_get_corner_height(const TileElement* tileElement, int32_t direction)
int32_t tile_element_get_corner_height(const SurfaceElement* surfaceElement, int32_t direction)
{
int32_t z = tileElement->base_height;
int32_t slope = tileElement->AsSurface()->GetSlope();
int32_t z = surfaceElement->base_height;
int32_t slope = surfaceElement->GetSlope();
return map_get_corner_height(z, slope, direction);
}
uint8_t map_get_lowest_land_height(int32_t xMin, int32_t xMax, int32_t yMin, int32_t yMax)
uint8_t map_get_lowest_land_height(const MapRange& range)
{
xMin = std::max(xMin, 32);
yMin = std::max(yMin, 32);
xMax = std::min(xMax, (int32_t)gMapSizeMaxXY);
yMax = std::min(yMax, (int32_t)gMapSizeMaxXY);
MapRange validRange = { std::max(range.GetLeft(), 32), std::max(range.GetTop(), 32),
std::min(range.GetRight(), (int32_t)gMapSizeMaxXY),
std::min(range.GetBottom(), (int32_t)gMapSizeMaxXY) };
uint8_t min_height = 0xFF;
for (int32_t yi = yMin; yi <= yMax; yi += 32)
for (int32_t yi = validRange.GetTop(); yi <= validRange.GetBottom(); yi += 32)
{
for (int32_t xi = xMin; xi <= xMax; xi += 32)
for (int32_t xi = validRange.GetLeft(); xi <= validRange.GetRight(); xi += 32)
{
TileElement* tile_element = map_get_surface_element_at({ xi, yi });
if (tile_element != nullptr && min_height > tile_element->base_height)
auto* surfaceElement = map_get_surface_element_at({ xi, yi });
if (surfaceElement != nullptr && min_height > surfaceElement->base_height)
{
min_height = tile_element->base_height;
min_height = surfaceElement->base_height;
}
}
}
return min_height;
}
uint8_t map_get_highest_land_height(int32_t xMin, int32_t xMax, int32_t yMin, int32_t yMax)
uint8_t map_get_highest_land_height(const MapRange& range)
{
xMin = std::max(xMin, 32);
yMin = std::max(yMin, 32);
xMax = std::min(xMax, (int32_t)gMapSizeMaxXY);
yMax = std::min(yMax, (int32_t)gMapSizeMaxXY);
MapRange validRange = { std::max(range.GetLeft(), 32), std::max(range.GetTop(), 32),
std::min(range.GetRight(), (int32_t)gMapSizeMaxXY),
std::min(range.GetBottom(), (int32_t)gMapSizeMaxXY) };
uint8_t max_height = 0;
for (int32_t yi = yMin; yi <= yMax; yi += 32)
for (int32_t yi = validRange.GetTop(); yi <= validRange.GetBottom(); yi += 32)
{
for (int32_t xi = xMin; xi <= xMax; xi += 32)
for (int32_t xi = validRange.GetLeft(); xi <= validRange.GetRight(); xi += 32)
{
TileElement* tile_element = map_get_surface_element_at({ xi, yi });
if (tile_element != nullptr)
auto* surfaceElement = map_get_surface_element_at({ xi, yi });
if (surfaceElement != nullptr)
{
uint8_t base_height = tile_element->base_height;
if (tile_element->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
uint8_t base_height = surfaceElement->base_height;
if (surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
base_height += 2;
if (tile_element->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
if (surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
base_height += 2;
if (max_height < base_height)
max_height = base_height;
@ -977,9 +933,10 @@ uint8_t map_get_highest_land_height(int32_t xMin, int32_t xMax, int32_t yMin, in
return max_height;
}
bool map_is_location_at_edge(int32_t x, int32_t y)
bool map_is_location_at_edge(const CoordsXY& loc)
{
return x < 32 || y < 32 || x >= ((MAXIMUM_MAP_SIZE_TECHNICAL - 1) * 32) || y >= ((MAXIMUM_MAP_SIZE_TECHNICAL - 1) * 32);
return loc.x < 32 || loc.y < 32 || loc.x >= ((MAXIMUM_MAP_SIZE_TECHNICAL - 1) * 32)
|| loc.y >= ((MAXIMUM_MAP_SIZE_TECHNICAL - 1) * 32);
}
/**
@ -1056,51 +1013,31 @@ void map_invalidate_map_selection_tiles()
map_invalidate_tile_full(position.x, position.y);
}
void map_get_bounding_box(
int32_t ax, int32_t ay, int32_t bx, int32_t by, int32_t* left, int32_t* top, int32_t* right, int32_t* bottom)
static void map_get_bounding_box(const MapRange& _range, int32_t* left, int32_t* top, int32_t* right, int32_t* bottom)
{
int32_t x, y;
x = ax;
y = ay;
uint32_t rotation = get_current_rotation();
translate_3d_to_2d(rotation, &x, &y);
*left = x;
*right = x;
*top = y;
*bottom = y;
x = bx;
y = ay;
translate_3d_to_2d(rotation, &x, &y);
if (x < *left)
*left = x;
if (x > *right)
*right = x;
if (y > *bottom)
*bottom = y;
if (y < *top)
*top = y;
x = bx;
y = by;
translate_3d_to_2d(rotation, &x, &y);
if (x < *left)
*left = x;
if (x > *right)
*right = x;
if (y > *bottom)
*bottom = y;
if (y < *top)
*top = y;
x = ax;
y = by;
translate_3d_to_2d(rotation, &x, &y);
if (x < *left)
*left = x;
if (x > *right)
*right = x;
if (y > *bottom)
*bottom = y;
if (y < *top)
*top = y;
std::array<const CoordsXY, 4> corners{ CoordsXY{ _range.GetLeft(), _range.GetTop() },
CoordsXY{ _range.GetRight(), _range.GetTop() },
CoordsXY{ _range.GetRight(), _range.GetBottom() },
CoordsXY{ _range.GetLeft(), _range.GetBottom() } };
*left = std::numeric_limits<int32_t>::max();
*top = std::numeric_limits<int32_t>::max();
*right = std::numeric_limits<int32_t>::min();
*bottom = std::numeric_limits<int32_t>::min();
for (const auto& corner : corners)
{
auto screenCoord = translate_3d_to_2d(rotation, corner);
if (screenCoord.x < *left)
*left = screenCoord.x;
if (screenCoord.x > *right)
*right = screenCoord.x;
if (screenCoord.y > *bottom)
*bottom = screenCoord.y;
if (screenCoord.y < *top)
*top = screenCoord.y;
}
}
/**
@ -1118,7 +1055,7 @@ void map_invalidate_selection_rect()
y0 = gMapSelectPositionA.y + 16;
x1 = gMapSelectPositionB.x + 16;
y1 = gMapSelectPositionB.y + 16;
map_get_bounding_box(x0, y0, x1, y1, &left, &top, &right, &bottom);
map_get_bounding_box({ x0, y0, x1, y1 }, &left, &top, &right, &bottom);
left -= 32;
right += 32;
bottom += 32;
@ -1216,7 +1153,7 @@ bool map_check_free_elements_and_reorganise(int32_t numElements)
*
* rct2: 0x0068B1F6
*/
TileElement* tile_element_insert(int32_t x, int32_t y, int32_t z, int32_t flags)
TileElement* tile_element_insert(const TileCoordsXYZ& loc, int32_t flags)
{
TileElement *originalTileElement, *newTileElement, *insertedElement;
@ -1227,13 +1164,13 @@ TileElement* tile_element_insert(int32_t x, int32_t y, int32_t z, int32_t flags)
}
newTileElement = gNextFreeTileElement;
originalTileElement = gTileElementTilePointers[y * MAXIMUM_MAP_SIZE_TECHNICAL + x];
originalTileElement = gTileElementTilePointers[loc.y * MAXIMUM_MAP_SIZE_TECHNICAL + loc.x];
// Set tile index pointer to point to new element block
gTileElementTilePointers[y * MAXIMUM_MAP_SIZE_TECHNICAL + x] = newTileElement;
gTileElementTilePointers[loc.y * MAXIMUM_MAP_SIZE_TECHNICAL + loc.x] = newTileElement;
// Copy all elements that are below the insert height
while (z >= originalTileElement->base_height)
while (loc.z >= originalTileElement->base_height)
{
// Copy over map element
*newTileElement = *originalTileElement;
@ -1253,9 +1190,9 @@ TileElement* tile_element_insert(int32_t x, int32_t y, int32_t z, int32_t flags)
// Insert new map element
insertedElement = newTileElement;
newTileElement->type = 0;
newTileElement->base_height = z;
newTileElement->base_height = loc.z;
newTileElement->flags = flags;
newTileElement->clearance_height = z;
newTileElement->clearance_height = loc.z;
std::memset(&newTileElement->pad_04, 0, sizeof(newTileElement->pad_04));
newTileElement++;
@ -1551,10 +1488,10 @@ void map_update_tiles()
interleaved_xy >>= 1;
}
TileElement* tileElement = map_get_surface_element_at(x, y);
if (tileElement != nullptr)
auto* surfaceElement = map_get_surface_element_at(x, y);
if (surfaceElement != nullptr)
{
tileElement->AsSurface()->UpdateGrassLength({ x * 32, y * 32 });
surfaceElement->UpdateGrassLength({ x * 32, y * 32 });
scenery_update_tile(x * 32, y * 32);
}
@ -1611,15 +1548,52 @@ void map_remove_out_of_range_elements()
auto surfaceElement = map_get_surface_element_at({ x, y });
if (surfaceElement != nullptr)
{
surfaceElement->AsSurface()->SetOwnership(OWNERSHIP_UNOWNED);
surfaceElement->SetOwnership(OWNERSHIP_UNOWNED);
update_park_fences_around_tile({ x, y });
}
clear_elements_at(x, y);
clear_elements_at({ x, y });
}
}
}
}
static void map_extend_boundary_surface_extend_tile(const SurfaceElement& sourceTile, SurfaceElement& destTile)
{
destTile.SetSurfaceStyle(sourceTile.GetSurfaceStyle());
destTile.SetEdgeStyle(sourceTile.GetEdgeStyle());
destTile.SetGrassLength(sourceTile.GetGrassLength());
destTile.SetOwnership(OWNERSHIP_UNOWNED);
destTile.SetWaterHeight(sourceTile.GetWaterHeight());
auto z = sourceTile.base_height;
auto slope = sourceTile.GetSlope() & TILE_ELEMENT_SLOPE_NW_SIDE_UP;
if (slope == TILE_ELEMENT_SLOPE_NW_SIDE_UP)
{
z += 2;
slope = TILE_ELEMENT_SLOPE_FLAT;
if (sourceTile.GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
{
slope = TILE_ELEMENT_SLOPE_N_CORNER_UP;
if (sourceTile.GetSlope() & TILE_ELEMENT_SLOPE_S_CORNER_UP)
{
slope = TILE_ELEMENT_SLOPE_W_CORNER_UP;
if (sourceTile.GetSlope() & TILE_ELEMENT_SLOPE_E_CORNER_UP)
{
slope = TILE_ELEMENT_SLOPE_FLAT;
}
}
}
}
if (slope & TILE_ELEMENT_SLOPE_N_CORNER_UP)
slope |= TILE_ELEMENT_SLOPE_E_CORNER_UP;
if (slope & TILE_ELEMENT_SLOPE_W_CORNER_UP)
slope |= TILE_ELEMENT_SLOPE_S_CORNER_UP;
destTile.SetSlope(slope);
destTile.base_height = z;
destTile.clearance_height = z;
}
/**
* Copies the terrain and slope from the edge of the map to the new tiles. Used when increasing the size of the map.
* rct2: 0x0068AC15
@ -1627,46 +1601,18 @@ void map_remove_out_of_range_elements()
void map_extend_boundary_surface()
{
SurfaceElement *existingTileElement, *newTileElement;
int32_t x, y, z, slope;
int32_t x, y;
y = gMapSize - 2;
for (x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++)
{
existingTileElement = map_get_surface_element_at(x, y - 1)->AsSurface();
newTileElement = map_get_surface_element_at(x, y)->AsSurface();
newTileElement->SetSurfaceStyle(existingTileElement->GetSurfaceStyle());
newTileElement->SetEdgeStyle(existingTileElement->GetEdgeStyle());
newTileElement->SetGrassLength(existingTileElement->GetGrassLength());
newTileElement->SetOwnership(OWNERSHIP_UNOWNED);
newTileElement->SetWaterHeight(existingTileElement->GetWaterHeight());
existingTileElement = map_get_surface_element_at(x, y - 1);
newTileElement = map_get_surface_element_at(x, y);
z = existingTileElement->base_height;
slope = existingTileElement->GetSlope() & TILE_ELEMENT_SLOPE_NW_SIDE_UP;
if (slope == TILE_ELEMENT_SLOPE_NW_SIDE_UP)
if (existingTileElement && newTileElement)
{
z += 2;
slope = TILE_ELEMENT_SLOPE_FLAT;
if (existingTileElement->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
{
slope = TILE_ELEMENT_SLOPE_N_CORNER_UP;
if (existingTileElement->GetSlope() & TILE_ELEMENT_SLOPE_S_CORNER_UP)
{
slope = TILE_ELEMENT_SLOPE_W_CORNER_UP;
if (existingTileElement->GetSlope() & TILE_ELEMENT_SLOPE_E_CORNER_UP)
{
slope = TILE_ELEMENT_SLOPE_FLAT;
}
}
}
map_extend_boundary_surface_extend_tile(*existingTileElement, *newTileElement);
}
if (slope & TILE_ELEMENT_SLOPE_N_CORNER_UP)
slope |= TILE_ELEMENT_SLOPE_E_CORNER_UP;
if (slope & TILE_ELEMENT_SLOPE_W_CORNER_UP)
slope |= TILE_ELEMENT_SLOPE_S_CORNER_UP;
newTileElement->SetSlope(slope);
newTileElement->base_height = z;
newTileElement->clearance_height = z;
update_park_fences({ x << 5, y << 5 });
}
@ -1674,42 +1620,13 @@ void map_extend_boundary_surface()
x = gMapSize - 2;
for (y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++)
{
existingTileElement = map_get_surface_element_at(x - 1, y)->AsSurface();
newTileElement = map_get_surface_element_at(x, y)->AsSurface();
existingTileElement = map_get_surface_element_at(x - 1, y);
newTileElement = map_get_surface_element_at(x, y);
newTileElement->SetSurfaceStyle(existingTileElement->GetSurfaceStyle());
newTileElement->SetEdgeStyle(existingTileElement->GetEdgeStyle());
newTileElement->SetGrassLength(existingTileElement->GetGrassLength());
newTileElement->SetOwnership(OWNERSHIP_UNOWNED);
newTileElement->SetWaterHeight(existingTileElement->GetWaterHeight());
z = existingTileElement->base_height;
slope = existingTileElement->GetSlope() & TILE_ELEMENT_SLOPE_NE_SIDE_UP;
if (slope == TILE_ELEMENT_SLOPE_NE_SIDE_UP)
if (existingTileElement && newTileElement)
{
z += 2;
slope = TILE_ELEMENT_SLOPE_FLAT;
if (existingTileElement->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
{
slope = TILE_ELEMENT_SLOPE_N_CORNER_UP;
if (existingTileElement->GetSlope() & TILE_ELEMENT_SLOPE_S_CORNER_UP)
{
slope = TILE_ELEMENT_SLOPE_E_CORNER_UP;
if (existingTileElement->GetSlope() & TILE_ELEMENT_SLOPE_W_CORNER_UP)
{
slope = TILE_ELEMENT_SLOPE_FLAT;
}
}
}
map_extend_boundary_surface_extend_tile(*existingTileElement, *newTileElement);
}
if (slope & TILE_ELEMENT_SLOPE_N_CORNER_UP)
slope |= TILE_ELEMENT_SLOPE_W_CORNER_UP;
if (slope & TILE_ELEMENT_SLOPE_E_CORNER_UP)
slope |= TILE_ELEMENT_SLOPE_S_CORNER_UP;
newTileElement->SetSlope(slope);
newTileElement->base_height = z;
newTileElement->clearance_height = z;
update_park_fences({ x << 5, y << 5 });
}
@ -1719,7 +1636,7 @@ void map_extend_boundary_surface()
* Clears the provided element properly from a certain tile, and updates
* the pointer (when needed) passed to this function to point to the next element.
*/
static void clear_element_at(int32_t x, int32_t y, TileElement** elementPtr)
static void clear_element_at(const CoordsXY& loc, TileElement** elementPtr)
{
TileElement* element = *elementPtr;
switch (element->GetType())
@ -1741,24 +1658,23 @@ static void clear_element_at(int32_t x, int32_t y, TileElement** elementPtr)
case TILE_ELEMENT_TYPE_ENTRANCE:
{
int32_t rotation = element->GetDirectionWithOffset(1);
auto seqLoc = loc;
switch (element->AsEntrance()->GetSequenceIndex())
{
case 1:
x += CoordsDirectionDelta[rotation].x;
y += CoordsDirectionDelta[rotation].y;
seqLoc += CoordsDirectionDelta[rotation];
break;
case 2:
x -= CoordsDirectionDelta[rotation].x;
y -= CoordsDirectionDelta[rotation].y;
seqLoc -= CoordsDirectionDelta[rotation];
break;
}
auto parkEntranceRemoveAction = ParkEntranceRemoveAction({ x, y, element->base_height * 8 });
auto parkEntranceRemoveAction = ParkEntranceRemoveAction(CoordsXYZ{ seqLoc, element->base_height * 8 });
GameActions::Execute(&parkEntranceRemoveAction);
break;
}
case TILE_ELEMENT_TYPE_WALL:
{
CoordsXYZD wallLocation = { x, y, element->base_height * 8, element->GetDirection() };
CoordsXYZD wallLocation = { loc.x, loc.y, element->base_height * 8, element->GetDirection() };
auto wallRemoveAction = WallRemoveAction(wallLocation);
GameActions::Execute(&wallRemoveAction);
}
@ -1766,14 +1682,15 @@ static void clear_element_at(int32_t x, int32_t y, TileElement** elementPtr)
case TILE_ELEMENT_TYPE_LARGE_SCENERY:
{
auto removeSceneryAction = LargeSceneryRemoveAction(
{ x, y, element->base_height * 8, element->GetDirection() }, element->AsLargeScenery()->GetSequenceIndex());
{ loc.x, loc.y, element->base_height * 8, element->GetDirection() },
element->AsLargeScenery()->GetSequenceIndex());
GameActions::Execute(&removeSceneryAction);
}
break;
case TILE_ELEMENT_TYPE_BANNER:
{
auto bannerRemoveAction = BannerRemoveAction(
{ x, y, element->base_height * 8, element->AsBanner()->GetPosition() });
{ loc.x, loc.y, element->base_height * 8, element->AsBanner()->GetPosition() });
GameActions::Execute(&bannerRemoveAction);
break;
}
@ -1787,43 +1704,42 @@ static void clear_element_at(int32_t x, int32_t y, TileElement** elementPtr)
* Clears all elements properly from a certain tile.
* rct2: 0x0068AE2A
*/
static void clear_elements_at(int32_t x, int32_t y)
static void clear_elements_at(const CoordsXY& loc)
{
// Remove the spawn point (if there is one in the current tile)
gPeepSpawns.erase(
std::remove_if(
gPeepSpawns.begin(), gPeepSpawns.end(),
[x, y](const auto& spawn) { return floor2(spawn.x, 32) == x && floor2(spawn.y, 32) == y; }),
[x = loc.x, y = loc.y](const auto& spawn) { return floor2(spawn.x, 32) == x && floor2(spawn.y, 32) == y; }),
gPeepSpawns.end());
TileElement* tileElement = map_get_first_element_at(x / 32, y / 32);
TileElement* tileElement = map_get_first_element_at(loc.x / 32, loc.y / 32);
// Remove all elements except the last one
while (!tileElement->IsLastForTile())
clear_element_at(x, y, &tileElement);
clear_element_at(loc, &tileElement);
// Remove the last element
clear_element_at(x, y, &tileElement);
clear_element_at(loc, &tileElement);
}
int32_t map_get_highest_z(int32_t tileX, int32_t tileY)
int32_t map_get_highest_z(const CoordsXY& loc)
{
TileElement* tileElement;
uint32_t z;
tileElement = map_get_surface_element_at(tileX, tileY);
if (tileElement == nullptr)
auto surfaceElement = map_get_surface_element_at(loc);
if (surfaceElement == nullptr)
return -1;
z = tileElement->base_height * 8;
z = surfaceElement->base_height * 8;
// Raise z so that is above highest point of land and water on tile
if ((tileElement->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP) != TILE_ELEMENT_SLOPE_FLAT)
if ((surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP) != TILE_ELEMENT_SLOPE_FLAT)
z += 16;
if ((tileElement->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT) != 0)
if ((surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT) != 0)
z += 16;
z = std::max(z, tileElement->AsSurface()->GetWaterHeight() * 16);
z = std::max(z, surfaceElement->GetWaterHeight() * 16);
return z;
}
@ -2019,60 +1935,16 @@ bool sign_set_colour(
return true;
}
static void translate_3d_to_2d(int32_t rotation, int32_t* x, int32_t* y)
static ScreenCoordsXY translate_3d_to_2d(int32_t rotation, const CoordsXY& pos)
{
int32_t rx, ry;
switch (rotation & 3)
{
default:
case 0:
rx = (*y) - (*x);
ry = (*x) + (*y);
break;
case 1:
rx = -(*x) - (*y);
ry = (*y) - (*x);
break;
case 2:
rx = (*x) - (*y);
ry = -(*x) - (*y);
break;
case 3:
rx = (*x) + (*y);
ry = (*x) - (*y);
break;
}
ry /= 2;
*x = rx;
*y = ry;
return translate_3d_to_2d_with_z(rotation, CoordsXYZ{ pos, 0 });
}
CoordsXY translate_3d_to_2d_with_z(int32_t rotation, CoordsXYZ pos)
ScreenCoordsXY translate_3d_to_2d_with_z(int32_t rotation, const CoordsXYZ& pos)
{
CoordsXY result = {};
switch (rotation & 3)
{
default:
case 0:
result.x = pos.y - pos.x;
result.y = (pos.x + pos.y) / 2 - pos.z;
break;
case 1:
result.x = -pos.x - pos.y;
result.y = (pos.y - pos.x) / 2 - pos.z;
break;
case 2:
result.x = pos.x - pos.y;
result.y = (-pos.x - pos.y) / 2 - pos.z;
break;
case 3:
result.x = pos.x + pos.y;
result.y = (pos.x - pos.y) / 2 - pos.z;
break;
}
return result;
auto rotated = pos.Rotate(rotation);
// Use right shift to avoid issues like #9301
return ScreenCoordsXY{ rotated.y - rotated.x, ((rotated.x + rotated.y) >> 1) - pos.z };
}
static void map_invalidate_tile_under_zoom(int32_t x, int32_t y, int32_t z0, int32_t z1, int32_t maxZoom)
@ -2084,12 +1956,12 @@ static void map_invalidate_tile_under_zoom(int32_t x, int32_t y, int32_t z0, int
x += 16;
y += 16;
translate_3d_to_2d(get_current_rotation(), &x, &y);
auto screenCoord = translate_3d_to_2d(get_current_rotation(), { x, y });
x1 = x - 32;
y1 = y - 32 - z1;
x2 = x + 32;
y2 = y + 32 - z0;
x1 = screenCoord.x - 32;
y1 = screenCoord.y - 32 - z1;
x2 = screenCoord.x + 32;
y2 = screenCoord.y + 32 - z0;
for (int32_t i = 0; i < MAX_VIEWPORT_COUNT; i++)
{
@ -2152,7 +2024,7 @@ void map_invalidate_region(const LocationXY16& mins, const LocationXY16& maxs)
x1 = maxs.x + 16;
y1 = maxs.y + 16;
map_get_bounding_box(x0, y0, x1, y1, &left, &top, &right, &bottom);
map_get_bounding_box({ x0, y0, x1, y1 }, &left, &top, &right, &bottom);
left -= 32;
right += 32;
@ -2189,27 +2061,27 @@ int32_t map_get_tile_quadrant(int32_t mapX, int32_t mapY)
*/
bool map_surface_is_blocked(int16_t x, int16_t y)
{
TileElement* tileElement;
if (x >= 8192 || y >= 8192)
return true;
tileElement = map_get_surface_element_at({ x, y });
auto surfaceElement = map_get_surface_element_at({ x, y });
if (tileElement == nullptr)
if (surfaceElement == nullptr)
{
return true;
}
int16_t water_height = tileElement->AsSurface()->GetWaterHeight();
int16_t water_height = surfaceElement->GetWaterHeight();
water_height *= 2;
if (water_height > tileElement->base_height)
if (water_height > surfaceElement->base_height)
return true;
int16_t base_z = tileElement->base_height;
int16_t clear_z = tileElement->base_height + 2;
if (tileElement->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
int16_t base_z = surfaceElement->base_height;
int16_t clear_z = surfaceElement->base_height + 2;
if (surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
clear_z += 2;
auto tileElement = reinterpret_cast<TileElement*>(surfaceElement);
while (!(tileElement++)->IsLastForTile())
{
if (clear_z >= tileElement->clearance_height)
@ -2242,7 +2114,7 @@ void map_clear_all_elements()
{
for (int32_t x = 0; x < (MAXIMUM_MAP_SIZE_TECHNICAL * 32); x += 32)
{
clear_elements_at(x, y);
clear_elements_at({ x, y });
}
}
}
@ -2512,11 +2384,10 @@ void FixLandOwnershipTiles(std::initializer_list<TileCoordsXY> tiles)
void FixLandOwnershipTilesWithOwnership(std::initializer_list<TileCoordsXY> tiles, uint8_t ownership)
{
TileElement* currentElement;
for (const TileCoordsXY* tile = tiles.begin(); tile != tiles.end(); ++tile)
{
currentElement = map_get_surface_element_at((*tile).x, (*tile).y);
currentElement->AsSurface()->SetOwnership(ownership);
auto surfaceElement = map_get_surface_element_at((*tile).x, (*tile).y);
surfaceElement->SetOwnership(ownership);
update_park_fences_around_tile({ (*tile).x * 32, (*tile).y * 32 });
}
}

View File

@ -141,40 +141,38 @@ void map_update_tile_pointers();
TileElement* map_get_first_element_at(int32_t x, int32_t y);
TileElement* map_get_nth_element_at(int32_t x, int32_t y, int32_t n);
void map_set_tile_elements(int32_t x, int32_t y, TileElement* elements);
int32_t map_height_from_slope(CoordsXY coords, int32_t slope, bool isSloped);
int32_t map_height_from_slope(const CoordsXY& coords, int32_t slope, bool isSloped);
BannerElement* map_get_banner_element_at(int32_t x, int32_t y, int32_t z, uint8_t direction);
TileElement* map_get_surface_element_at(int32_t x, int32_t y);
TileElement* map_get_surface_element_at(CoordsXY coords);
TileElement* map_get_path_element_at(int32_t x, int32_t y, int32_t z);
SurfaceElement* map_get_surface_element_at(int32_t x, int32_t y);
SurfaceElement* map_get_surface_element_at(const CoordsXY& coords);
PathElement* map_get_path_element_at(const TileCoordsXYZ& loc);
WallElement* map_get_wall_element_at(int32_t x, int32_t y, int32_t z, int32_t direction);
SmallSceneryElement* map_get_small_scenery_element_at(int32_t x, int32_t y, int32_t z, int32_t type, uint8_t quadrant);
EntranceElement* map_get_park_entrance_element_at(int32_t x, int32_t y, int32_t z, bool ghost);
EntranceElement* map_get_ride_entrance_element_at(int32_t x, int32_t y, int32_t z, bool ghost);
EntranceElement* map_get_ride_exit_element_at(int32_t x, int32_t y, int32_t z, bool ghost);
int16_t tile_element_height(int32_t x, int32_t y);
int16_t tile_element_water_height(int32_t x, int32_t y);
uint8_t map_get_highest_land_height(int32_t xMin, int32_t xMax, int32_t yMin, int32_t yMax);
uint8_t map_get_lowest_land_height(int32_t xMin, int32_t xMax, int32_t yMin, int32_t yMax);
bool map_coord_is_connected(int32_t x, int32_t y, int32_t z, uint8_t faceDirection);
int16_t tile_element_height(const CoordsXY& loc);
int16_t tile_element_water_height(const CoordsXY& loc);
uint8_t map_get_highest_land_height(const MapRange& range);
uint8_t map_get_lowest_land_height(const MapRange& range);
bool map_coord_is_connected(const TileCoordsXYZ& loc, uint8_t faceDirection);
void map_remove_provisional_elements();
void map_restore_provisional_elements();
void map_update_path_wide_flags();
bool map_is_location_valid(CoordsXY coords);
bool map_is_edge(CoordsXY coords);
bool map_can_build_at(int32_t x, int32_t y, int32_t z);
bool map_is_location_owned(int32_t x, int32_t y, int32_t z);
bool map_is_location_in_park(CoordsXY coords);
bool map_is_location_owned_or_has_rights(int32_t x, int32_t y);
bool map_is_location_valid(const CoordsXY& coords);
bool map_is_edge(const CoordsXY& coords);
bool map_can_build_at(const CoordsXYZ& loc);
bool map_is_location_owned(const CoordsXYZ& loc);
bool map_is_location_in_park(const CoordsXY& coords);
bool map_is_location_owned_or_has_rights(const CoordsXY& loc);
bool map_surface_is_blocked(int16_t x, int16_t y);
void tile_element_remove(TileElement* tileElement);
void map_remove_all_rides();
void map_invalidate_map_selection_tiles();
void map_get_bounding_box(
int32_t ax, int32_t ay, int32_t bx, int32_t by, int32_t* left, int32_t* top, int32_t* right, int32_t* bottom);
void map_invalidate_selection_rect();
void map_reorganise_elements();
bool map_check_free_elements_and_reorganise(int32_t num_elements);
TileElement* tile_element_insert(int32_t x, int32_t y, int32_t z, int32_t flags);
TileElement* tile_element_insert(const TileCoordsXYZ& loc, int32_t flags);
using CLEAR_FUNC = int32_t (*)(TileElement** tile_element, int32_t x, int32_t y, uint8_t flags, money32* price);
@ -185,7 +183,6 @@ bool map_can_construct_with_clear_at(
uint8_t crossingMode);
int32_t map_can_construct_at(int32_t x, int32_t y, int32_t zLow, int32_t zHigh, QuarterTile bl);
void rotate_map_coordinates(int16_t* x, int16_t* y, int32_t rotation);
LocationXY16 coordinate_3d_to_2d(const LocationXYZ16* coordinate_3d, int32_t rotation);
struct tile_element_iterator
{
@ -203,7 +200,7 @@ void tile_element_iterator_restart_for_tile(tile_element_iterator* it);
void wall_remove_intersecting_walls(int32_t x, int32_t y, int32_t z0, int32_t z1, int32_t direction);
void map_update_tiles();
int32_t map_get_highest_z(int32_t tileX, int32_t tileY);
int32_t map_get_highest_z(const CoordsXY& loc);
bool tile_element_wants_path_connection_towards(TileCoordsXYZD coords, const TileElement* const elementToBeRemoved);
@ -225,7 +222,7 @@ void map_invalidate_region(const LocationXY16& mins, const LocationXY16& maxs);
int32_t map_get_tile_side(int32_t mapX, int32_t mapY);
int32_t map_get_tile_quadrant(int32_t mapX, int32_t mapY);
int32_t map_get_corner_height(int32_t z, int32_t slope, int32_t direction);
int32_t tile_element_get_corner_height(const TileElement* tileElement, int32_t direction);
int32_t tile_element_get_corner_height(const SurfaceElement* surfaceElement, int32_t direction);
void map_clear_all_elements();
@ -235,7 +232,7 @@ bool map_large_scenery_get_origin(
LargeSceneryElement** outElement);
void map_offset_with_rotation(int16_t* x, int16_t* y, int16_t offsetX, int16_t offsetY, uint8_t rotation);
CoordsXY translate_3d_to_2d_with_z(int32_t rotation, CoordsXYZ pos);
ScreenCoordsXY translate_3d_to_2d_with_z(int32_t rotation, const CoordsXYZ& pos);
TrackElement* map_get_track_element_at(int32_t x, int32_t y, int32_t z);
TileElement* map_get_track_element_at_of_type(int32_t x, int32_t y, int32_t z, int32_t trackType);
@ -248,7 +245,7 @@ TileElement* map_get_track_element_at_from_ride(int32_t x, int32_t y, int32_t z,
TileElement* map_get_track_element_at_with_direction_from_ride(
int32_t x, int32_t y, int32_t z, int32_t direction, ride_id_t rideIndex);
bool map_is_location_at_edge(int32_t x, int32_t y);
bool map_is_location_at_edge(const CoordsXY& loc);
void map_obstruction_set_error_text(TileElement* tileElement);
uint16_t check_max_allowable_land_rights_for_tile(uint8_t x, uint8_t y, uint8_t base_z);

View File

@ -111,8 +111,6 @@ static void set_height(int32_t x, int32_t y, int32_t height)
void mapgen_generate_blank(mapgen_settings* settings)
{
int32_t x, y;
TileElement* tileElement;
map_clear_all_elements();
map_init(settings->mapSize);
@ -120,11 +118,11 @@ void mapgen_generate_blank(mapgen_settings* settings)
{
for (x = 1; x < settings->mapSize - 1; x++)
{
tileElement = map_get_surface_element_at(x, y);
tileElement->AsSurface()->SetSurfaceStyle(settings->floor);
tileElement->AsSurface()->SetEdgeStyle(settings->wall);
tileElement->base_height = settings->height;
tileElement->clearance_height = settings->height;
auto surfaceElement = map_get_surface_element_at(x, y);
surfaceElement->SetSurfaceStyle(settings->floor);
surfaceElement->SetEdgeStyle(settings->wall);
surfaceElement->base_height = settings->height;
surfaceElement->clearance_height = settings->height;
}
}
@ -134,7 +132,6 @@ void mapgen_generate_blank(mapgen_settings* settings)
void mapgen_generate(mapgen_settings* settings)
{
int32_t x, y, mapSize, floorTexture, wallTexture, waterLevel;
TileElement* tileElement;
mapSize = settings->mapSize;
floorTexture = settings->floor;
@ -169,11 +166,11 @@ void mapgen_generate(mapgen_settings* settings)
{
for (x = 1; x < mapSize - 1; x++)
{
tileElement = map_get_surface_element_at(x, y);
tileElement->AsSurface()->SetSurfaceStyle(floorTexture);
tileElement->AsSurface()->SetEdgeStyle(wallTexture);
tileElement->base_height = settings->height;
tileElement->clearance_height = settings->height;
auto surfaceElement = map_get_surface_element_at(x, y);
surfaceElement->SetSurfaceStyle(floorTexture);
surfaceElement->SetEdgeStyle(wallTexture);
surfaceElement->base_height = settings->height;
surfaceElement->clearance_height = settings->height;
}
}
@ -215,10 +212,10 @@ void mapgen_generate(mapgen_settings* settings)
{
for (x = 1; x < mapSize - 1; x++)
{
tileElement = map_get_surface_element_at(x, y);
auto surfaceElement = map_get_surface_element_at(x, y);
if (tileElement->base_height < waterLevel + 6)
tileElement->AsSurface()->SetSurfaceStyle(beachTexture);
if (surfaceElement->base_height < waterLevel + 6)
surfaceElement->SetSurfaceStyle(beachTexture);
}
}
@ -239,8 +236,8 @@ static void mapgen_place_tree(int32_t type, int32_t x, int32_t y)
return;
}
surfaceZ = tile_element_height(x * 32 + 16, y * 32 + 16) / 8;
tileElement = tile_element_insert(x, y, surfaceZ, (1 | 2 | 4 | 8));
surfaceZ = tile_element_height({ x * 32 + 16, y * 32 + 16 }) / 8;
tileElement = tile_element_insert({ x, y, surfaceZ }, (1 | 2 | 4 | 8));
assert(tileElement != nullptr);
tileElement->clearance_height = surfaceZ + (sceneryEntry->small_scenery.height >> 3);
tileElement->SetType(TILE_ELEMENT_TYPE_SMALL_SCENERY);
@ -312,10 +309,10 @@ static void mapgen_place_trees()
{
for (int32_t x = 1; x < gMapSize - 1; x++)
{
TileElement* tileElement = map_get_surface_element_at(x, y);
auto* surfaceElement = map_get_surface_element_at(x, y);
// Exclude water tiles
if (tileElement->AsSurface()->GetWaterHeight() > 0)
if (surfaceElement->GetWaterHeight() > 0)
continue;
pos.x = x;
@ -346,8 +343,8 @@ static void mapgen_place_trees()
pos = availablePositions[i];
int32_t type = -1;
TileElement* tileElement = map_get_surface_element_at(pos.x, pos.y);
switch (tileElement->AsSurface()->GetSurfaceStyle())
auto* surfaceElement = map_get_surface_element_at(pos.x, pos.y);
switch (surfaceElement->GetSurfaceStyle())
{
case TERRAIN_GRASS:
case TERRAIN_DIRT:
@ -387,7 +384,6 @@ static void mapgen_place_trees()
static void mapgen_set_water_level(int32_t waterLevel)
{
int32_t x, y, mapSize;
TileElement* tileElement;
mapSize = gMapSize;
@ -395,9 +391,9 @@ static void mapgen_set_water_level(int32_t waterLevel)
{
for (x = 1; x < mapSize - 1; x++)
{
tileElement = map_get_surface_element_at(x, y);
if (tileElement->base_height < waterLevel)
tileElement->AsSurface()->SetWaterHeight(waterLevel / 2);
auto surfaceElement = map_get_surface_element_at(x, y);
if (surfaceElement->base_height < waterLevel)
surfaceElement->SetWaterHeight(waterLevel / 2);
}
}
}
@ -441,7 +437,6 @@ static void mapgen_smooth_height(int32_t iterations)
static void mapgen_set_height()
{
int32_t x, y, heightX, heightY, mapSize;
TileElement* tileElement;
mapSize = _heightSize / 2;
for (y = 1; y < mapSize - 1; y++)
@ -458,11 +453,11 @@ static void mapgen_set_height()
uint8_t baseHeight = (q00 + q01 + q10 + q11) / 4;
tileElement = map_get_surface_element_at(x, y);
tileElement->base_height = std::max(2, baseHeight * 2);
tileElement->clearance_height = tileElement->base_height;
auto surfaceElement = map_get_surface_element_at(x, y);
surfaceElement->base_height = std::max(2, baseHeight * 2);
surfaceElement->clearance_height = surfaceElement->base_height;
uint8_t currentSlope = tileElement->AsSurface()->GetSlope();
uint8_t currentSlope = surfaceElement->GetSlope();
if (q00 > baseHeight)
currentSlope |= TILE_ELEMENT_SLOPE_S_CORNER_UP;
@ -473,7 +468,7 @@ static void mapgen_set_height()
if (q11 > baseHeight)
currentSlope |= TILE_ELEMENT_SLOPE_N_CORNER_UP;
tileElement->AsSurface()->SetSlope(currentSlope);
surfaceElement->SetSlope(currentSlope);
}
}
}
@ -817,7 +812,7 @@ void mapgen_generate_from_heightmap(mapgen_settings* settings)
for (uint32_t x = 0; x < _heightMapData.width; x++)
{
// The x and y axis are flipped in the world, so this uses y for x and x for y.
TileElement* const surfaceElement = map_get_surface_element_at(y + 1, x + 1);
auto* const surfaceElement = map_get_surface_element_at(y + 1, x + 1);
// Read value from bitmap, and convert its range
uint8_t value = dest[x + y * _heightMapData.width];
@ -832,7 +827,7 @@ void mapgen_generate_from_heightmap(mapgen_settings* settings)
// Set water level
if (surfaceElement->base_height < settings->water_level)
{
surfaceElement->AsSurface()->SetWaterHeight(settings->water_level / 2);
surfaceElement->SetWaterHeight(settings->water_level / 2);
}
}
}

View File

@ -21,24 +21,23 @@ int32_t map_smooth(int32_t l, int32_t t, int32_t r, int32_t b)
{
int32_t i, x, y, count, doubleCorner, raisedLand = 0;
uint8_t highest, cornerHeights[4];
TileElement *tileElement, *tileElement2;
for (y = t; y < b; y++)
{
for (x = l; x < r; x++)
{
tileElement = map_get_surface_element_at(x, y);
tileElement->AsSurface()->SetSlope(TILE_ELEMENT_SLOPE_FLAT);
auto surfaceElement = map_get_surface_element_at(x, y);
surfaceElement->SetSlope(TILE_ELEMENT_SLOPE_FLAT);
// Raise to edge height - 2
highest = tileElement->base_height;
highest = surfaceElement->base_height;
highest = std::max(highest, map_get_surface_element_at(x - 1, y + 0)->base_height);
highest = std::max(highest, map_get_surface_element_at(x + 1, y + 0)->base_height);
highest = std::max(highest, map_get_surface_element_at(x + 0, y - 1)->base_height);
highest = std::max(highest, map_get_surface_element_at(x + 0, y + 1)->base_height);
if (tileElement->base_height < highest - 2)
if (surfaceElement->base_height < highest - 2)
{
raisedLand = 1;
tileElement->base_height = tileElement->clearance_height = highest - 2;
surfaceElement->base_height = surfaceElement->clearance_height = highest - 2;
}
// Check corners
@ -47,11 +46,11 @@ int32_t map_smooth(int32_t l, int32_t t, int32_t r, int32_t b)
cornerHeights[1] = map_get_surface_element_at(x + 1, y - 1)->base_height;
cornerHeights[2] = map_get_surface_element_at(x + 1, y + 1)->base_height;
cornerHeights[3] = map_get_surface_element_at(x - 1, y + 1)->base_height;
highest = tileElement->base_height;
highest = surfaceElement->base_height;
for (i = 0; i < 4; i++)
highest = std::max(highest, cornerHeights[i]);
if (highest >= tileElement->base_height + 4)
if (highest >= surfaceElement->base_height + 4)
{
count = 0;
int32_t canCompensate = 1;
@ -89,9 +88,9 @@ int32_t map_smooth(int32_t l, int32_t t, int32_t r, int32_t b)
break;
}
if (highestOnLowestSide > tileElement->base_height)
if (highestOnLowestSide > surfaceElement->base_height)
{
tileElement->base_height = tileElement->clearance_height = highestOnLowestSide;
surfaceElement->base_height = surfaceElement->clearance_height = highestOnLowestSide;
raisedLand = 1;
canCompensate = 0;
}
@ -99,9 +98,9 @@ int32_t map_smooth(int32_t l, int32_t t, int32_t r, int32_t b)
if (count == 1 && canCompensate)
{
if (tileElement->base_height < highest - 4)
if (surfaceElement->base_height < highest - 4)
{
tileElement->base_height = tileElement->clearance_height = highest - 4;
surfaceElement->base_height = surfaceElement->clearance_height = highest - 4;
raisedLand = 1;
}
if (cornerHeights[0] == highest && cornerHeights[2] <= cornerHeights[0] - 4)
@ -115,9 +114,9 @@ int32_t map_smooth(int32_t l, int32_t t, int32_t r, int32_t b)
}
else
{
if (tileElement->base_height < highest - 2)
if (surfaceElement->base_height < highest - 2)
{
tileElement->base_height = tileElement->clearance_height = highest - 2;
surfaceElement->base_height = surfaceElement->clearance_height = highest - 2;
raisedLand = 1;
}
}
@ -125,7 +124,7 @@ int32_t map_smooth(int32_t l, int32_t t, int32_t r, int32_t b)
if (doubleCorner != -1)
{
uint8_t slope = tileElement->AsSurface()->GetSlope() | TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT;
uint8_t slope = surfaceElement->GetSlope() | TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT;
switch (doubleCorner)
{
case 0:
@ -141,52 +140,52 @@ int32_t map_smooth(int32_t l, int32_t t, int32_t r, int32_t b)
slope |= TILE_ELEMENT_SLOPE_E_CORNER_DN;
break;
}
tileElement->AsSurface()->SetSlope(slope);
surfaceElement->SetSlope(slope);
}
else
{
uint8_t slope = tileElement->AsSurface()->GetSlope();
uint8_t slope = surfaceElement->GetSlope();
// Corners
tileElement2 = map_get_surface_element_at(x + 1, y + 1);
if (tileElement2->base_height > tileElement->base_height)
auto surfaceElement2 = map_get_surface_element_at(x + 1, y + 1);
if (surfaceElement2->base_height > surfaceElement->base_height)
slope |= TILE_ELEMENT_SLOPE_N_CORNER_UP;
tileElement2 = map_get_surface_element_at(x - 1, y + 1);
if (tileElement2->base_height > tileElement->base_height)
surfaceElement2 = map_get_surface_element_at(x - 1, y + 1);
if (surfaceElement2->base_height > surfaceElement->base_height)
slope |= TILE_ELEMENT_SLOPE_W_CORNER_UP;
tileElement2 = map_get_surface_element_at(x + 1, y - 1);
if (tileElement2->base_height > tileElement->base_height)
surfaceElement2 = map_get_surface_element_at(x + 1, y - 1);
if (surfaceElement2->base_height > surfaceElement->base_height)
slope |= TILE_ELEMENT_SLOPE_E_CORNER_UP;
tileElement2 = map_get_surface_element_at(x - 1, y - 1);
if (tileElement2->base_height > tileElement->base_height)
surfaceElement2 = map_get_surface_element_at(x - 1, y - 1);
if (surfaceElement2->base_height > surfaceElement->base_height)
slope |= TILE_ELEMENT_SLOPE_S_CORNER_UP;
// Sides
tileElement2 = map_get_surface_element_at(x + 1, y + 0);
if (tileElement2->base_height > tileElement->base_height)
surfaceElement2 = map_get_surface_element_at(x + 1, y + 0);
if (surfaceElement2->base_height > surfaceElement->base_height)
slope |= TILE_ELEMENT_SLOPE_NE_SIDE_UP;
tileElement2 = map_get_surface_element_at(x - 1, y + 0);
if (tileElement2->base_height > tileElement->base_height)
surfaceElement2 = map_get_surface_element_at(x - 1, y + 0);
if (surfaceElement2->base_height > surfaceElement->base_height)
slope |= TILE_ELEMENT_SLOPE_SW_SIDE_UP;
tileElement2 = map_get_surface_element_at(x + 0, y - 1);
if (tileElement2->base_height > tileElement->base_height)
surfaceElement2 = map_get_surface_element_at(x + 0, y - 1);
if (surfaceElement2->base_height > surfaceElement->base_height)
slope |= TILE_ELEMENT_SLOPE_SE_SIDE_UP;
tileElement2 = map_get_surface_element_at(x + 0, y + 1);
if (tileElement2->base_height > tileElement->base_height)
surfaceElement2 = map_get_surface_element_at(x + 0, y + 1);
if (surfaceElement2->base_height > surfaceElement->base_height)
slope |= TILE_ELEMENT_SLOPE_NW_SIDE_UP;
// Raise
if (slope == TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
{
slope = TILE_ELEMENT_SLOPE_FLAT;
tileElement->base_height = tileElement->clearance_height += 2;
surfaceElement->base_height = surfaceElement->clearance_height += 2;
}
tileElement->AsSurface()->SetSlope(slope);
surfaceElement->SetSlope(slope);
}
}
}
@ -201,7 +200,7 @@ int32_t map_smooth(int32_t l, int32_t t, int32_t r, int32_t b)
*/
int32_t tile_smooth(int32_t x, int32_t y)
{
TileElement* const surfaceElement = map_get_surface_element_at(x, y);
auto* const surfaceElement = map_get_surface_element_at(x, y);
// +-----+-----+-----+
// | W | NW | N |
@ -240,9 +239,9 @@ int32_t tile_smooth(int32_t x, int32_t y)
continue;
// Get neighbour height. If the element is not valid (outside of map) assume the same height
TileElement* neighbour_element = map_get_surface_element_at(x + x_offset, y + y_offset);
neighbourHeightOffset.baseheight[index] = neighbour_element ? neighbour_element->base_height
: surfaceElement->base_height;
auto* neighbourSurfaceElement = map_get_surface_element_at(x + x_offset, y + y_offset);
neighbourHeightOffset.baseheight[index] = neighbourSurfaceElement ? neighbourSurfaceElement->base_height
: surfaceElement->base_height;
// Make the height relative to the current surface element
neighbourHeightOffset.baseheight[index] -= surfaceElement->base_height;
@ -277,7 +276,7 @@ int32_t tile_smooth(int32_t x, int32_t y)
}
// Check if the calculated slope is the same already
uint8_t currentSlope = surfaceElement->AsSurface()->GetSlope();
uint8_t currentSlope = surfaceElement->GetSlope();
if (currentSlope == slope)
{
return 0;
@ -286,18 +285,18 @@ int32_t tile_smooth(int32_t x, int32_t y)
if ((slope & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP) == TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
{
// All corners are raised, raise the entire tile instead.
surfaceElement->AsSurface()->SetSlope(TILE_ELEMENT_SLOPE_FLAT);
surfaceElement->SetSlope(TILE_ELEMENT_SLOPE_FLAT);
surfaceElement->base_height = (surfaceElement->clearance_height += 2);
uint8_t waterHeight = surfaceElement->AsSurface()->GetWaterHeight() * 2;
uint8_t waterHeight = surfaceElement->GetWaterHeight() * 2;
if (waterHeight <= surfaceElement->base_height)
{
surfaceElement->AsSurface()->SetWaterHeight(0);
surfaceElement->SetWaterHeight(0);
}
}
else
{
// Apply the slope to this tile
surfaceElement->AsSurface()->SetSlope(slope);
surfaceElement->SetSlope(slope);
// Set correct clearance height
if (slope & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)

View File

@ -100,7 +100,7 @@ void rct_money_effect::Create(money32 value)
if (mapPosition.x == LOCATION_NULL)
return;
mapPosition.z = tile_element_height(mapPosition.x, mapPosition.y);
mapPosition.z = tile_element_height({ mapPosition.x, mapPosition.y });
}
mapPosition.z += 10;
CreateAt(-value, mapPosition.x, mapPosition.y, mapPosition.z, false);

View File

@ -107,12 +107,12 @@ void update_park_fences(const CoordsXY coords)
if (map_is_edge(coords))
return;
TileElement* surfaceElement = map_get_surface_element_at(coords);
auto surfaceElement = map_get_surface_element_at(coords);
if (surfaceElement == nullptr)
return;
uint8_t newFences = 0;
if ((surfaceElement->AsSurface()->GetOwnership() & OWNERSHIP_OWNED) == 0)
if ((surfaceElement->GetOwnership() & OWNERSHIP_OWNED) == 0)
{
bool fenceRequired = true;
@ -162,12 +162,12 @@ void update_park_fences(const CoordsXY coords)
}
}
if (surfaceElement->AsSurface()->GetParkFences() != newFences)
if (surfaceElement->GetParkFences() != newFences)
{
int32_t z0 = surfaceElement->base_height * 8;
int32_t z1 = z0 + 16;
map_invalidate_tile(coords.x, coords.y, z0, z1);
surfaceElement->AsSurface()->SetParkFences(newFences);
surfaceElement->SetParkFences(newFences);
}
}

View File

@ -80,13 +80,13 @@ void crashed_vehicle_particle_update(rct_crashed_vehicle_particle* particle)
particle->velocity_z = vz & 0xFFFF;
// Check collision with land / water
int16_t landZ = tile_element_height(x, y);
int16_t waterZ = tile_element_water_height(x, y);
int16_t landZ = tile_element_height({ x, y });
int16_t waterZ = tile_element_water_height({ x, y });
if (waterZ != 0 && particle->z >= waterZ && z <= waterZ)
{
// Splash
audio_play_sound_at_location(SoundId::Water2, particle->x, particle->y, waterZ);
audio_play_sound_at_location(SoundId::Water2, { particle->x, particle->y, waterZ });
crash_splash_create(particle->x, particle->y, waterZ);
sprite_remove((rct_sprite*)particle);
return;

View File

@ -666,12 +666,12 @@ void sprite_move(int16_t x, int16_t y, int16_t z, rct_sprite* sprite)
void sprite_set_coordinates(int16_t x, int16_t y, int16_t z, rct_sprite* sprite)
{
CoordsXYZ coords3d = { x, y, z };
CoordsXY newCoords = translate_3d_to_2d_with_z(get_current_rotation(), coords3d);
auto screenCoords = translate_3d_to_2d_with_z(get_current_rotation(), coords3d);
sprite->generic.sprite_left = newCoords.x - sprite->generic.sprite_width;
sprite->generic.sprite_right = newCoords.x + sprite->generic.sprite_width;
sprite->generic.sprite_top = newCoords.y - sprite->generic.sprite_height_negative;
sprite->generic.sprite_bottom = newCoords.y + sprite->generic.sprite_height_positive;
sprite->generic.sprite_left = screenCoords.x - sprite->generic.sprite_width;
sprite->generic.sprite_right = screenCoords.x + sprite->generic.sprite_width;
sprite->generic.sprite_top = screenCoords.y - sprite->generic.sprite_height_negative;
sprite->generic.sprite_bottom = screenCoords.y + sprite->generic.sprite_height_positive;
sprite->generic.x = x;
sprite->generic.y = y;
sprite->generic.z = z;
@ -707,7 +707,7 @@ static bool litter_can_be_at(int32_t x, int32_t y, int32_t z)
{
TileElement* tileElement;
if (!map_is_location_owned(x & 0xFFE0, y & 0xFFE0, z))
if (!map_is_location_owned({ x, y, z }))
return false;
tileElement = map_get_first_element_at(x >> 5, y >> 5);

View File

@ -22,10 +22,12 @@ struct rct_sprite_common
uint8_t sprite_width;
// Height from centre of sprite to top
uint8_t sprite_height_positive;
// Screen Coordinates of sprite
int16_t sprite_left;
int16_t sprite_top;
int16_t sprite_right;
int16_t sprite_bottom;
uint8_t sprite_direction;
};

View File

@ -89,7 +89,7 @@ GameActionResult::Ptr tile_inspector_insert_corrupt_at(CoordsXY loc, int16_t ele
{
// Create new corrupt element
TileElement* corruptElement = tile_element_insert(
loc.x / 32, loc.y / 32, -1, 0); // Ugly hack: -1 guarantees this to be placed first
{ loc.x / 32, loc.y / 32, -1 }, 0); // Ugly hack: -1 guarantees this to be placed first
if (corruptElement == nullptr)
{
log_warning("Failed to insert corrupt element.");
@ -320,7 +320,7 @@ GameActionResult::Ptr tile_inspector_paste_element_at(CoordsXY loc, TileElement
tile_element_set_banner_index(&element, newBannerIndex);
}
TileElement* const pastedElement = tile_element_insert(loc.x / 32, loc.y / 32, element.base_height, 0);
TileElement* const pastedElement = tile_element_insert({ loc.x / 32, loc.y / 32, element.base_height }, 0);
bool lastForTile = pastedElement->IsLastForTile();
*pastedElement = element;
@ -469,7 +469,7 @@ GameActionResult::Ptr tile_inspector_any_base_height_offset(
GameActionResult::Ptr tile_inspector_surface_show_park_fences(CoordsXY loc, bool showFences, bool isExecuting)
{
TileElement* const surfaceelement = map_get_surface_element_at(loc);
auto* const surfaceelement = map_get_surface_element_at(loc);
// No surface element on tile
if (surfaceelement == nullptr)
@ -478,7 +478,7 @@ GameActionResult::Ptr tile_inspector_surface_show_park_fences(CoordsXY loc, bool
if (isExecuting)
{
if (!showFences)
surfaceelement->AsSurface()->SetParkFences(0);
surfaceelement->SetParkFences(0);
else
update_park_fences(loc);
@ -497,7 +497,7 @@ GameActionResult::Ptr tile_inspector_surface_show_park_fences(CoordsXY loc, bool
GameActionResult::Ptr tile_inspector_surface_toggle_corner(CoordsXY loc, int32_t cornerIndex, bool isExecuting)
{
TileElement* const surfaceElement = map_get_surface_element_at(loc);
auto* const surfaceElement = map_get_surface_element_at(loc);
// No surface element on tile
if (surfaceElement == nullptr)
@ -505,12 +505,12 @@ GameActionResult::Ptr tile_inspector_surface_toggle_corner(CoordsXY loc, int32_t
if (isExecuting)
{
const uint8_t originalSlope = surfaceElement->AsSurface()->GetSlope();
const uint8_t originalSlope = surfaceElement->GetSlope();
const bool diagonal = (originalSlope & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT) >> 4;
uint8_t newSlope = surfaceElement->AsSurface()->GetSlope() ^ (1 << cornerIndex);
surfaceElement->AsSurface()->SetSlope(newSlope);
if (surfaceElement->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
uint8_t newSlope = surfaceElement->GetSlope() ^ (1 << cornerIndex);
surfaceElement->SetSlope(newSlope);
if (surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
{
surfaceElement->clearance_height = surfaceElement->base_height + 2;
}
@ -520,7 +520,7 @@ GameActionResult::Ptr tile_inspector_surface_toggle_corner(CoordsXY loc, int32_t
}
// All corners are raised
if ((surfaceElement->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP) == TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
if ((surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP) == TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
{
uint8_t slope = TILE_ELEMENT_SLOPE_FLAT;
@ -542,7 +542,7 @@ GameActionResult::Ptr tile_inspector_surface_toggle_corner(CoordsXY loc, int32_t
break;
}
}
surfaceElement->AsSurface()->SetSlope(slope);
surfaceElement->SetSlope(slope);
// Update base and clearance heights
surfaceElement->base_height += 2;
@ -564,7 +564,7 @@ GameActionResult::Ptr tile_inspector_surface_toggle_corner(CoordsXY loc, int32_t
GameActionResult::Ptr tile_inspector_surface_toggle_diagonal(CoordsXY loc, bool isExecuting)
{
TileElement* const surfaceElement = map_get_surface_element_at(loc);
auto* const surfaceElement = map_get_surface_element_at(loc);
// No surface element on tile
if (surfaceElement == nullptr)
@ -572,13 +572,13 @@ GameActionResult::Ptr tile_inspector_surface_toggle_diagonal(CoordsXY loc, bool
if (isExecuting)
{
uint8_t newSlope = surfaceElement->AsSurface()->GetSlope() ^ TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT;
surfaceElement->AsSurface()->SetSlope(newSlope);
if (surfaceElement->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
uint8_t newSlope = surfaceElement->GetSlope() ^ TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT;
surfaceElement->SetSlope(newSlope);
if (surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)
{
surfaceElement->clearance_height = surfaceElement->base_height + 4;
}
else if (surfaceElement->AsSurface()->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
else if (surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
{
surfaceElement->clearance_height = surfaceElement->base_height + 2;
}

View File

@ -136,7 +136,7 @@ protected:
static ::testing::AssertionResult AssertIsStartPosition(const char*, const TileCoordsXYZ& location)
{
const uint32_t expectedSurfaceStyle = 11u;
const uint32_t style = map_get_surface_element_at(location.x, location.y)->AsSurface()->GetSurfaceStyle();
const uint32_t style = map_get_surface_element_at(location.x, location.y)->GetSurfaceStyle();
if (style != expectedSurfaceStyle)
return ::testing::AssertionFailure()
@ -151,7 +151,7 @@ protected:
{
const uint32_t forbiddenSurfaceStyle = 8u;
const uint32_t style = map_get_surface_element_at(location.x, location.y)->AsSurface()->GetSurfaceStyle();
const uint32_t style = map_get_surface_element_at(location.x, location.y)->GetSurfaceStyle();
if (style == forbiddenSurfaceStyle)
return ::testing::AssertionFailure()