forked from rosebudai/OpenRCT2-Web
Prefer map_is_location_valid over hardcoded map limits (#10373)
This commit is contained in:
1 parent
18ba9b27a3
commit
af7b364946
6 files changed
+18
-29
No files matched your search
@@ -2420,10 +2420,10 @@ static void sub_6CBCE2(
|
||||
int16_t preserveMapSize = gMapSize;
|
||||
int16_t preserveMapSizeMaxXY = gMapSizeMaxXY;
|
||||
|
||||
gMapSizeUnits = 255 * 32;
|
||||
gMapSizeMinus2 = (255 * 32) + 286;
|
||||
gMapSize = 256;
|
||||
gMapSizeMaxXY = (256 * 32) - 1;
|
||||
gMapSizeUnits = (MAXIMUM_MAP_SIZE_TECHNICAL - 1) * 32;
|
||||
gMapSizeMinus2 = ((MAXIMUM_MAP_SIZE_TECHNICAL - 1) * 32) + 286;
|
||||
gMapSize = MAXIMUM_MAP_SIZE_TECHNICAL;
|
||||
gMapSizeMaxXY = (MAXIMUM_MAP_SIZE_TECHNICAL * 32) - 1;
|
||||
|
||||
auto trackBlock = get_track_def_from_ride(ride, trackType);
|
||||
while (trackBlock->index != 255)
|
||||
@@ -3531,7 +3531,7 @@ void ride_construction_toolupdate_construct(ScreenCoordsXY screenCoords)
|
||||
int32_t highestZ = 0;
|
||||
for (const auto& selectedTile : gMapSelectionTiles)
|
||||
{
|
||||
if (selectedTile.x < (256 * 32) && selectedTile.y < (256 * 32))
|
||||
if (map_is_location_valid(selectedTile))
|
||||
{
|
||||
z = map_get_highest_z(selectedTile);
|
||||
if (z > highestZ)
|
||||
@@ -3757,7 +3757,7 @@ void ride_construction_tooldown_construct(ScreenCoordsXY screenCoords)
|
||||
{
|
||||
for (const auto& selectedTile : gMapSelectionTiles)
|
||||
{
|
||||
if (selectedTile.x >= (256 * 32) || selectedTile.y >= (256 * 32))
|
||||
if (!map_is_location_valid(selectedTile))
|
||||
continue;
|
||||
|
||||
z = map_get_highest_z(selectedTile);
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "../world/Climate.h"
|
||||
#include "../world/Footpath.h"
|
||||
#include "../world/LargeScenery.h"
|
||||
#include "../world/Map.h"
|
||||
#include "../world/Park.h"
|
||||
#include "../world/Scenery.h"
|
||||
#include "../world/Sprite.h"
|
||||
@@ -401,7 +402,7 @@ bool Guest::GuestHasValidXY() const
|
||||
{
|
||||
if (x != LOCATION_NULL)
|
||||
{
|
||||
if (x < (256 * 32) && y < (256 * 32))
|
||||
if (map_is_location_valid({ x, y }))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6258,7 +6258,7 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsX
|
||||
{
|
||||
mapX = entranceExitCoords.x + CoordsDirectionDelta[entranceExitCoords.direction].x;
|
||||
mapY = entranceExitCoords.y + CoordsDirectionDelta[entranceExitCoords.direction].y;
|
||||
if (mapX >= 0 && mapY >= 0 && mapX < (256 * 32) && mapY < (256 * 32))
|
||||
if (map_is_location_valid({ mapX, mapY }))
|
||||
{
|
||||
tileElement = map_get_first_element_at(mapX >> 5, mapY >> 5);
|
||||
if (tileElement == nullptr)
|
||||
|
||||
@@ -1368,19 +1368,7 @@ static int32_t track_design_place_maze(TrackDesign* td6, int16_t x, int16_t y, i
|
||||
|
||||
if (_trackDesignPlaceOperation == PTD_OPERATION_GET_PLACE_Z)
|
||||
{
|
||||
if (mapCoord.x < 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (mapCoord.y < 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (mapCoord.x >= 256 * 32)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (mapCoord.y >= 256 * 32)
|
||||
if (!map_is_location_valid(mapCoord))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -1547,7 +1535,7 @@ static bool track_design_place_ride(TrackDesign* td6, int16_t x, int16_t y, int1
|
||||
for (const rct_preview_track* trackBlock = trackBlockArray[trackType]; trackBlock->index != 0xFF; trackBlock++)
|
||||
{
|
||||
auto tile = CoordsXY{ x, y } + CoordsXY{ trackBlock->x, trackBlock->y }.Rotate(rotation);
|
||||
if (tile.x < 0 || tile.y < 0 || tile.x >= (256 * 32) || tile.y >= (256 * 32))
|
||||
if (!map_is_location_valid(tile))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -2694,7 +2694,7 @@ static rct_synchronised_vehicle* _lastSynchronisedVehicle = nullptr;
|
||||
static bool try_add_synchronised_station(int32_t x, int32_t y, int32_t z)
|
||||
{
|
||||
// make sure we are in map bounds
|
||||
if (x < 0 || y < 0 || (x >> 5) > (MAXIMUM_MAP_SIZE_TECHNICAL - 1) || (y >> 5) > (MAXIMUM_MAP_SIZE_TECHNICAL - 1))
|
||||
if (!map_is_location_valid({ x, y }))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ void tile_element_iterator_restart_for_tile(tile_element_iterator* it)
|
||||
|
||||
TileElement* map_get_first_element_at(int32_t x, int32_t y)
|
||||
{
|
||||
if (x < 0 || y < 0 || x > (MAXIMUM_MAP_SIZE_TECHNICAL - 1) || y > (MAXIMUM_MAP_SIZE_TECHNICAL - 1))
|
||||
if (!map_is_location_valid({ x * 32, y * 32 }))
|
||||
{
|
||||
log_error("Trying to access element outside of range");
|
||||
return nullptr;
|
||||
@@ -195,7 +195,7 @@ 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)
|
||||
{
|
||||
if (x < 0 || y < 0 || x > (MAXIMUM_MAP_SIZE_TECHNICAL - 1) || y > (MAXIMUM_MAP_SIZE_TECHNICAL - 1))
|
||||
if (!map_is_location_valid({ x * 32, y * 32 }))
|
||||
{
|
||||
log_error("Trying to access element outside of range");
|
||||
return;
|
||||
@@ -410,7 +410,7 @@ void map_update_tile_pointers()
|
||||
int16_t tile_element_height(const CoordsXY& loc)
|
||||
{
|
||||
// Off the map
|
||||
if ((unsigned)loc.x >= 8192 || (unsigned)loc.y >= 8192)
|
||||
if (!map_is_location_valid(loc))
|
||||
return 16;
|
||||
|
||||
// Get the surface element for the tile
|
||||
@@ -556,7 +556,7 @@ int16_t tile_element_height(const CoordsXY& loc)
|
||||
int16_t tile_element_water_height(const CoordsXY& loc)
|
||||
{
|
||||
// Off the map
|
||||
if ((unsigned)loc.x >= 8192 || (unsigned)loc.y >= 8192)
|
||||
if (!map_is_location_valid(loc))
|
||||
return 0;
|
||||
|
||||
// Get the surface element for the tile
|
||||
@@ -634,11 +634,11 @@ void map_update_path_wide_flags()
|
||||
|
||||
// Next x, y tile
|
||||
x += 32;
|
||||
if (x >= 8192)
|
||||
if (x >= MAXIMUM_MAP_SIZE_TECHNICAL * 32)
|
||||
{
|
||||
x = 0;
|
||||
y += 32;
|
||||
if (y >= 8192)
|
||||
if (y >= MAXIMUM_MAP_SIZE_TECHNICAL * 32)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user