From 2419c6629e4d8cf277416ea5f406aee754cf3186 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Tue, 4 Aug 2015 16:01:31 +0100 Subject: [PATCH] improve clear scenery tool --- src/localisation/string_ids.h | 2 ++ src/world/map.c | 34 ++++++++++++++++++++++++++-------- src/world/map.h | 1 + 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/localisation/string_ids.h b/src/localisation/string_ids.h index cf642ed4b1..be7173a251 100644 --- a/src/localisation/string_ids.h +++ b/src/localisation/string_ids.h @@ -661,6 +661,8 @@ enum { STR_CANT_OPEN_PARK = 1723, STR_CANT_CLOSE_PARK = 1724, + STR_LAND_NOT_OWNED_BY_PARK = 1729, + STR_BANNER_TEXT = 1731, STR_RIDE_CONSTRUCTION_BUILD = 1732, diff --git a/src/world/map.c b/src/world/map.c index 1fe979725a..3a19955f70 100644 --- a/src/world/map.c +++ b/src/world/map.c @@ -822,7 +822,7 @@ int map_is_location_owned(int x, int y, int z) } } - RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, uint16) = 1729; + RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, uint16) = STR_LAND_NOT_OWNED_BY_PARK; return 0; } @@ -840,10 +840,22 @@ int map_is_location_in_park(int x, int y) return 1; } - RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, uint16) = 1729; + RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, uint16) = STR_LAND_NOT_OWNED_BY_PARK; return 0; } +bool map_is_location_owned_or_has_rights(int x, int y) +{ + rct_map_element *mapElement; + + if (x < (256 * 32) && y < (256 * 32)) { + mapElement = map_get_surface_element_at(x / 32, y / 32); + if (mapElement->properties.surface.ownership & OWNERSHIP_OWNED) return true; + if (mapElement->properties.surface.ownership & OWNERSHIP_CONSTRUCTION_RIGHTS_OWNED) return true; + } + return false; +} + /** * * rct2: 0x006E0E01 @@ -1446,6 +1458,7 @@ money32 map_clear_scenery(int x0, int y0, int x1, int y1, int flags) { int x, y, z; money32 totalCost, cost; + bool noValidTiles; RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_LANDSCAPING * 4; @@ -1461,18 +1474,23 @@ money32 map_clear_scenery(int x0, int y0, int x1, int y1, int flags) x1 = min(x1, RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16)); y1 = min(y1, RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16)); + noValidTiles = true; totalCost = 0; for (y = y0; y <= y1; y += 32) { for (x = x0; x <= x1; x += 32) { - cost = map_clear_scenery_from_tile(x / 32, y / 32, flags); - if (cost == MONEY32_UNDEFINED) - return MONEY32_UNDEFINED; - - totalCost += cost; + if (gCheatsSandboxMode || map_is_location_owned_or_has_rights(x, y)) { + cost = map_clear_scenery_from_tile(x / 32, y / 32, flags); + if (cost != MONEY32_UNDEFINED) { + noValidTiles = false; + totalCost += cost; + } + } else { + RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, uint16) = STR_LAND_NOT_OWNED_BY_PARK; + } } } - return totalCost; + return noValidTiles ? MONEY32_UNDEFINED : totalCost; } /** diff --git a/src/world/map.h b/src/world/map.h index 790306c521..f163b82969 100644 --- a/src/world/map.h +++ b/src/world/map.h @@ -287,6 +287,7 @@ int map_coord_is_connected(int x, int y, int z, uint8 faceDirection); void sub_6A876D(); int map_is_location_owned(int x, int y, int z); int map_is_location_in_park(int x, int y); +bool map_is_location_owned_or_has_rights(int x, int y); bool map_surface_is_blocked(sint16 x, sint16 y); int map_get_station(rct_map_element *mapElement); void map_element_remove(rct_map_element *mapElement);