diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 6e78dcd44e..90feaf0f35 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -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); diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 42a87aec40..c08ec1bc4a 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -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; } diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index b1432a9506..571ca0962b 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -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) diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 9eaf214787..418dcc3a1e 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -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; } diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 985bac5048..4d83f6d63d 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -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; } diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 19605ada17..4007c88566 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -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; }