From 76f0ed3f9e89585f1a90a29b85716c946b3242ed Mon Sep 17 00:00:00 2001 From: jensj12 Date: Tue, 27 Jun 2017 14:28:34 +0200 Subject: [PATCH 01/11] Calculate cost of all affected tiles in smooth_land This makes the mountain tool calculate the cost properly. Fixes #2229, --- src/openrct2/world/map.c | 141 ++++++++++++++++++++++++++++++--------- 1 file changed, 111 insertions(+), 30 deletions(-) diff --git a/src/openrct2/world/map.c b/src/openrct2/world/map.c index aad41425cd..1fca31a73b 100644 --- a/src/openrct2/world/map.c +++ b/src/openrct2/world/map.c @@ -2035,10 +2035,8 @@ void game_command_lower_land(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, ); } -static sint32 map_element_get_corner_height(rct_map_element *mapElement, sint32 direction) +static sint32 map_get_corner_height(sint32 z, sint32 slope, sint32 direction) { - sint32 z = mapElement->base_height; - sint32 slope = mapElement->properties.surface.slope & MAP_ELEMENT_SLOPE_MASK; switch (direction) { case 0: if (slope & 1) { @@ -2076,6 +2074,13 @@ static sint32 map_element_get_corner_height(rct_map_element *mapElement, sint32 return z; } +static sint32 map_element_get_corner_height(rct_map_element *mapElement, sint32 direction) +{ + sint32 z = mapElement->base_height; + sint32 slope = mapElement->properties.surface.slope & MAP_ELEMENT_SLOPE_MASK; + return map_get_corner_height(z, slope, direction); +} + /** * * rct2: 0x0068C3B2 slope 1, style 0 @@ -2155,14 +2160,8 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 } money32 totalCost = 0; - - // First raise / lower the centre tile money32 result; commandType = command < 0x7FFF ? GAME_COMMAND_RAISE_LAND : GAME_COMMAND_LOWER_LAND; - result = game_do_command(centreX, flags, centreY, mapLeftRight, commandType, command & 0x7FFF, mapTopBottom); - if (result != MONEY32_UNDEFINED) { - totalCost += result; - } rct_map_element *mapElement = map_get_surface_element_at(mapLeft >> 5, mapTop >> 5); if (mapElement == NULL) @@ -2179,14 +2178,66 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 network_set_player_last_action_coord(network_get_player_index(game_command_playerid), coord); } - // Flatten the edited part - if (fullTile) { - sint32 slope = mapElement->properties.surface.slope & MAP_ELEMENT_SLOPE_MASK; - if (slope != 0) { - commandType = command > 0x7FFF ? GAME_COMMAND_RAISE_LAND : GAME_COMMAND_LOWER_LAND; - result = game_do_command(centreX, flags, centreY, mapLeftRight, commandType, MAP_SELECT_TYPE_FULL, mapTopBottom); - if (result != MONEY32_UNDEFINED) { - totalCost += result; + uint8 maxHeight = 0; + uint8 minHeight = 0xFF; + uint32 newBaseZ = 0; + uint32 newSlope = 0; + + // Predict the land height for future use + if (fullTile) + { + // Find lowest map element in selection + for (sint32 yi = mapTop; yi <= mapBottom; yi += 32) { + for (sint32 xi = mapLeft; xi <= mapRight; xi += 32) { + rct_map_element *map_element = map_get_surface_element_at(xi / 32, yi / 32); + if (map_element != NULL && minHeight > map_element->base_height) { + minHeight = map_element->base_height; + } + } + } + + // Find highest map element in selection + for (sint32 yi = mapTop; yi <= mapBottom; yi += 32) { + for (sint32 xi = mapLeft; xi <= mapRight; xi += 32) { + rct_map_element *map_element = map_get_surface_element_at(xi / 32, yi / 32); + if (map_element != NULL) { + uint8 base_height = map_element->base_height; + if (map_element->properties.surface.slope & 0xF) + base_height += 2; + if (map_element->properties.surface.slope & 0x10) + base_height += 2; + if (maxHeight < base_height) + maxHeight = base_height; + } + } + } + + if (commandType == GAME_COMMAND_RAISE_LAND) { + minHeight += 2; + maxHeight += 2; + } + else { + maxHeight -= 2; + minHeight -= 2; + } + } + else + { + // One corner tile selected + newBaseZ = mapElement->base_height; + newSlope = mapElement->properties.surface.slope & MAP_ELEMENT_SLOPE_MASK; + if (commandType == GAME_COMMAND_RAISE_LAND) { + newSlope = map_element_raise_styles[command & 0xFF][newSlope]; + if (newSlope & 0x20) { + newBaseZ += 2; + newSlope &= ~0x20; + } + } + else { + newSlope = map_element_lower_styles[command & 0xFF][newSlope]; + if (newSlope & 0x20) { + newBaseZ -= 2; + newSlope &= ~0x20; } } } @@ -2206,7 +2257,9 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 // Corner (North-West) mapElement = map_get_surface_element_at(mapLeft >> 5, mapTop >> 5); - sint32 z = map_element_get_corner_height(mapElement, 2); + sint32 z = clamp(minHeight, map_element_get_corner_height(mapElement, 2), maxHeight); + if (!fullTile) + z = map_get_corner_height(newBaseZ, newSlope, 2); result = smooth_land_tile(0, flags, x, y, z, minZ); if (result != MONEY32_UNDEFINED) { totalCost += result; @@ -2218,7 +2271,9 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 sint32 y2 = clamp(mapTop, y, mapBottom); mapElement = map_get_surface_element_at(mapLeft >> 5, y2 >> 5); if (y >= mapTop) { - z = map_element_get_corner_height(mapElement, 3); + z = clamp(minHeight, map_element_get_corner_height(mapElement, 3), maxHeight); + if (!fullTile) + z = map_get_corner_height(newBaseZ, newSlope, 3); result = smooth_land_tile((y <= mapBottom) ? 0 : 1, flags, x, y, z, minZ); if (result != MONEY32_UNDEFINED) { totalCost += result; @@ -2232,7 +2287,9 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 } } if (y <= mapBottom) { - z = map_element_get_corner_height(mapElement, 2); + z = clamp(minHeight, map_element_get_corner_height(mapElement, 2), maxHeight); + if (!fullTile) + z = map_get_corner_height(newBaseZ, newSlope, 2); result = smooth_land_tile((y >= mapTop) ? 1 : 0, flags, x, y, z, minZ); if (result != MONEY32_UNDEFINED) { totalCost += result; @@ -2244,7 +2301,9 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 // Corner (South-West) mapElement = map_get_surface_element_at(mapLeft >> 5, mapBottom >> 5); - z = map_element_get_corner_height(mapElement, 3); + z = clamp(minHeight, map_element_get_corner_height(mapElement, 3), maxHeight); + if (!fullTile) + z = map_get_corner_height(newBaseZ, newSlope, 3); result = smooth_land_tile(1, flags, x, y, z, minZ); if (result != MONEY32_UNDEFINED) { totalCost += result; @@ -2256,7 +2315,9 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 sint32 x2 = clamp(mapLeft, x, mapRight); mapElement = map_get_surface_element_at(x2 >> 5, mapBottom >> 5); if (x >= mapLeft) { - z = map_element_get_corner_height(mapElement, 0); + z = clamp(minHeight, map_element_get_corner_height(mapElement, 0), maxHeight); + if (!fullTile) + z = map_get_corner_height(newBaseZ, newSlope, 0); result = smooth_land_tile((x <= mapRight) ? 1 : 2, flags, x, y, z, minZ); if (result != MONEY32_UNDEFINED) { totalCost += result; @@ -2270,7 +2331,9 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 } } if (x <= mapRight) { - z = map_element_get_corner_height(mapElement, 3); + z = clamp(minHeight, map_element_get_corner_height(mapElement, 3), maxHeight); + if (!fullTile) + z = map_get_corner_height(newBaseZ, newSlope, 3); result = smooth_land_tile((x >= mapLeft) ? 2 : 1, flags, x, y, z, minZ); if (result != MONEY32_UNDEFINED) { totalCost += result; @@ -2281,7 +2344,9 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 // Corner (South-East) mapElement = map_get_surface_element_at(mapRight >> 5, mapBottom >> 5); - z = map_element_get_corner_height(mapElement, 0); + z = clamp(minHeight, map_element_get_corner_height(mapElement, 0), maxHeight); + if (!fullTile) + z = map_get_corner_height(newBaseZ, newSlope, 0); result = smooth_land_tile(2, flags, x, y, z, minZ); if (result != MONEY32_UNDEFINED) { totalCost += result; @@ -2293,7 +2358,9 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 sint32 y2 = clamp(mapTop, y, mapBottom); mapElement = map_get_surface_element_at(mapRight >> 5, y2 >> 5); if (y <= mapBottom) { - z = map_element_get_corner_height(mapElement, 1); + z = clamp(minHeight, map_element_get_corner_height(mapElement, 1), maxHeight); + if (!fullTile) + z = map_get_corner_height(newBaseZ, newSlope, 1); result = smooth_land_tile((y >= mapTop) ? 2 : 3, flags, x, y, z, minZ); if (result != MONEY32_UNDEFINED) { totalCost += result; @@ -2307,7 +2374,9 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 } } if (y >= mapTop) { - z = map_element_get_corner_height(mapElement, 0); + z = clamp(minHeight, map_element_get_corner_height(mapElement, 0), maxHeight); + if (!fullTile) + z = map_get_corner_height(newBaseZ, newSlope, 0); result = smooth_land_tile((y <= mapBottom) ? 3 : 2, flags, x, y, z, minZ); if (result != MONEY32_UNDEFINED) { totalCost += result; @@ -2319,7 +2388,9 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 // Corner (North-East) mapElement = map_get_surface_element_at(mapRight >> 5, mapTop >> 5); - z = map_element_get_corner_height(mapElement, 1); + z = clamp(minHeight, map_element_get_corner_height(mapElement, 1), maxHeight); + if (!fullTile) + z = map_get_corner_height(newBaseZ, newSlope, 1); result = smooth_land_tile(3, flags, x, y, z, minZ); if (result != MONEY32_UNDEFINED) { totalCost += result; @@ -2331,7 +2402,9 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 sint32 x2 = clamp(mapLeft, x, mapRight); mapElement = map_get_surface_element_at(x2 >> 5, mapTop >> 5); if (x <= mapRight) { - z = map_element_get_corner_height(mapElement, 2); + z = clamp(minHeight, map_element_get_corner_height(mapElement, 2), maxHeight); + if (!fullTile) + z = map_get_corner_height(newBaseZ, newSlope, 2); result = smooth_land_tile((x >= mapLeft) ? 3 : 0, flags, x, y, z, minZ); if (result != MONEY32_UNDEFINED) { totalCost += result; @@ -2345,7 +2418,9 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 } } if (x >= mapLeft) { - z = map_element_get_corner_height(mapElement, 1); + z = clamp(minHeight, map_element_get_corner_height(mapElement, 1), maxHeight); + if (!fullTile) + z = map_get_corner_height(newBaseZ, newSlope, 1); result = smooth_land_tile((x <= mapRight) ? 0 : 3, flags, x, y, z, minZ); if (result != MONEY32_UNDEFINED) { totalCost += result; @@ -2356,11 +2431,17 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 } } + // Finally raise / lower the centre tile + result = game_do_command(centreX, flags, centreY, mapLeftRight, commandType, command & 0x7FFF, mapTopBottom); + if (result != MONEY32_UNDEFINED) { + totalCost += result; + } + gCommandExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING; gCommandPosition.x = centreX; gCommandPosition.y = centreY; gCommandPosition.z = centreZ; - return totalCost * 4; + return totalCost; } /** From 8075d69a684796900c95f5345de867b84f2a5364 Mon Sep 17 00:00:00 2001 From: jensj12 Date: Tue, 27 Jun 2017 14:43:08 +0200 Subject: [PATCH 02/11] Landscaping costs $5 per quarter cell Change the landscaping cost to be $5 per quarter cell changed. This normalizes the cost for the maintain tool. --- src/openrct2/world/map.c | 99 +++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 47 deletions(-) diff --git a/src/openrct2/world/map.c b/src/openrct2/world/map.c index 1fca31a73b..0e85e0621d 100644 --- a/src/openrct2/world/map.c +++ b/src/openrct2/world/map.c @@ -1445,6 +1445,52 @@ static sint32 map_set_land_height_clear_func(rct_map_element** map_element, sint return 1; } +static sint32 map_get_corner_height(sint32 z, sint32 slope, sint32 direction) +{ + switch (direction) { + case 0: + if (slope & 1) { + z += 2; + if (slope == 27) { + z += 2; + } + } + break; + case 1: + if (slope & 2) { + z += 2; + if (slope == 23) { + z += 2; + } + } + break; + case 2: + if (slope & 4) { + z += 2; + if (slope == 30) { + z += 2; + } + } + break; + case 3: + if (slope & 8) { + z += 2; + if (slope == 29) { + z += 2; + } + } + break; + } + return z; +} + +static sint32 map_element_get_corner_height(rct_map_element *mapElement, sint32 direction) +{ + sint32 z = mapElement->base_height; + sint32 slope = mapElement->properties.surface.slope & MAP_ELEMENT_SLOPE_MASK; + return map_get_corner_height(z, slope, direction); +} + static money32 map_set_land_height(sint32 flags, sint32 x, sint32 y, sint32 height, sint32 style, sint32 selectionType) { rct_map_element *mapElement; @@ -1498,7 +1544,6 @@ static money32 map_set_land_height(sint32 flags, sint32 x, sint32 y, sint32 heig if(!gCheatsDisableClearanceChecks) wall_remove_at(x, y, height * 8 - 16, height * 8 + 32); } - cost += MONEY(20, 0); if (!gCheatsDisableClearanceChecks) { //Check for obstructing scenery @@ -1612,6 +1657,12 @@ static money32 map_set_land_height(sint32 flags, sint32 x, sint32 y, sint32 heig } while (!map_element_is_last_for_tile(mapElement++)); } + for (int i = 0; i < 4; i += 1) { + int cornerHeight = map_element_get_corner_height(surfaceElement, i); + cornerHeight -= map_get_corner_height(height, style & MAP_ELEMENT_SLOPE_MASK, i); + cost += MONEY(abs(cornerHeight) * 5 / 2, 0); + } + if(flags & GAME_COMMAND_FLAG_APPLY) { if (gGameCommandNestLevel == 1) { @@ -2035,52 +2086,6 @@ void game_command_lower_land(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, ); } -static sint32 map_get_corner_height(sint32 z, sint32 slope, sint32 direction) -{ - switch (direction) { - case 0: - if (slope & 1) { - z += 2; - if (slope == 27) { - z += 2; - } - } - break; - case 1: - if (slope & 2) { - z += 2; - if (slope == 23) { - z += 2; - } - } - break; - case 2: - if (slope & 4) { - z += 2; - if (slope == 30) { - z += 2; - } - } - break; - case 3: - if (slope & 8) { - z += 2; - if (slope == 29) { - z += 2; - } - } - break; - } - return z; -} - -static sint32 map_element_get_corner_height(rct_map_element *mapElement, sint32 direction) -{ - sint32 z = mapElement->base_height; - sint32 slope = mapElement->properties.surface.slope & MAP_ELEMENT_SLOPE_MASK; - return map_get_corner_height(z, slope, direction); -} - /** * * rct2: 0x0068C3B2 slope 1, style 0 From 2736058912f9fe8eda04db636b0a51cba2643da4 Mon Sep 17 00:00:00 2001 From: jensj12 Date: Fri, 30 Jun 2017 15:55:12 +0200 Subject: [PATCH 03/11] Update text files and network version --- contributors.md | 1 + distribution/changelog.txt | 1 + src/openrct2/network/network.h | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/contributors.md b/contributors.md index cbb61efe92..4b95e247e1 100644 --- a/contributors.md +++ b/contributors.md @@ -66,6 +66,7 @@ The following people are not part of the project team, but have been contributin * Joël Troch (JoelTroch) - Keyboard shortcuts for ride construction. * Thomas Delebo (delebota) - Misc. * Brian Callahan (ibara) - OpenBSD port. +* Jens Heuseveldt (jensj12) - Mountain tool improvements, misc. ## Bug fixes * (halfbro) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index abc8878a32..9575fac328 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -5,6 +5,7 @@ - Feature: [#5877] Allow up to 16 stations to be synchronised - Feature: [#5970] The Bobsleigh Roller Coaster now supports on-ride photos. - Feature: [#5991] Allow all tracked rides that can be tested without guests to the Track Designer +- Fix: [#2127, #2229, #5586] Mountain tool cost calculation - Fix: [#3589] Crash due to invalid footpathEntry in path_paint - Fix: [#4455] Crash in window_sign_invalidate due to original bug - Fix: [#4931] Crash in path_paint - footpathentry was null diff --git a/src/openrct2/network/network.h b/src/openrct2/network/network.h index 5d825c0a36..7373bfefd7 100644 --- a/src/openrct2/network/network.h +++ b/src/openrct2/network/network.h @@ -55,7 +55,7 @@ extern "C" { // This define specifies which version of network stream current build uses. // It is used for making sure only compatible builds get connected, even within // single OpenRCT2 version. -#define NETWORK_STREAM_VERSION "13" +#define NETWORK_STREAM_VERSION "14" #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION #ifdef __cplusplus From 1b69fe485f455d160abd0d4c9c69d14ec98e21c6 Mon Sep 17 00:00:00 2001 From: jensj12 Date: Thu, 13 Jul 2017 17:31:37 +0200 Subject: [PATCH 04/11] Show error if too high/low Behaviour now matches that of the non-mountain land tool. Provide define for min/max land height and fix a bug where the mountain tool would incorrect raise/lower land. --- src/openrct2/world/map.c | 24 ++++++++++++++++++++---- src/openrct2/world/map.h | 3 +++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/openrct2/world/map.c b/src/openrct2/world/map.c index 0e85e0621d..bfc7e927ee 100644 --- a/src/openrct2/world/map.c +++ b/src/openrct2/world/map.c @@ -1512,21 +1512,21 @@ static money32 map_set_land_height(sint32 flags, sint32 x, sint32 y, sint32 heig return MONEY32_UNDEFINED; } - if (height < 2) { + if (height < MINIMUM_LAND_HEIGHT) { gGameCommandErrorText = STR_TOO_LOW; return MONEY32_UNDEFINED; } // Divide by 2 and subtract 7 to get the in-game units. - if (height > 142) { + if (height > MAXIMUM_LAND_HEIGHT) { gGameCommandErrorText = STR_TOO_HIGH; return MONEY32_UNDEFINED; - } else if (height > 140 && (style & 0x1F) != 0) { + } else if (height > MAXIMUM_LAND_HEIGHT - 2 && (style & 0x1F) != 0) { gGameCommandErrorText = STR_TOO_HIGH; return MONEY32_UNDEFINED; } - if (height == 140 && (style & 0x10)) { + if (height == MAXIMUM_LAND_HEIGHT - 2 && (style & 0x10)) { gGameCommandErrorText = STR_TOO_HIGH; return MONEY32_UNDEFINED; } @@ -2220,10 +2220,18 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 if (commandType == GAME_COMMAND_RAISE_LAND) { minHeight += 2; maxHeight += 2; + if (minHeight > MAXIMUM_LAND_HEIGHT) { + gGameCommandErrorText = STR_TOO_HIGH; + return MONEY32_UNDEFINED; + } } else { maxHeight -= 2; minHeight -= 2; + if (maxHeight < MINIMUM_LAND_HEIGHT) { + gGameCommandErrorText = STR_TOO_LOW; + return MONEY32_UNDEFINED; + } } } else @@ -2237,6 +2245,10 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 newBaseZ += 2; newSlope &= ~0x20; } + if (map_get_corner_height(newBaseZ, newSlope, command & 0xFF) > MAXIMUM_LAND_HEIGHT) { + gGameCommandErrorText = STR_TOO_HIGH; + return MONEY32_UNDEFINED; + } } else { newSlope = map_element_lower_styles[command & 0xFF][newSlope]; @@ -2244,6 +2256,10 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 newBaseZ -= 2; newSlope &= ~0x20; } + if (newBaseZ < MINIMUM_LAND_HEIGHT) { + gGameCommandErrorText = STR_TOO_LOW; + return MONEY32_UNDEFINED; + } } } diff --git a/src/openrct2/world/map.h b/src/openrct2/world/map.h index bac15d97ba..487938da0c 100644 --- a/src/openrct2/world/map.h +++ b/src/openrct2/world/map.h @@ -273,6 +273,9 @@ enum #define MAP_ELEM_TRACK_SEQUENCE_SEQUENCE_MASK 0x0F #define MAP_ELEM_TRACK_SEQUENCE_TAKING_PHOTO_MASK 0xF0 +#define MINIMUM_LAND_HEIGHT 2 +#define MAXIMUM_LAND_HEIGHT 142 + #define MINIMUM_MAP_SIZE_TECHNICAL 15 #define MAXIMUM_MAP_SIZE_TECHNICAL 256 #define MINIMUM_MAP_SIZE_PRACTICAL (MINIMUM_MAP_SIZE_TECHNICAL-2) From f2df2c80d25726a140bd0ea55f0007c5d16412bd Mon Sep 17 00:00:00 2001 From: jensj12 Date: Thu, 13 Jul 2017 18:23:58 +0200 Subject: [PATCH 05/11] Use other game commands for error messages Errors in game_command_raise/lower_land will now be passed on in smooth_land. Removes need for error checking elsewhere --- src/openrct2/world/map.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/openrct2/world/map.c b/src/openrct2/world/map.c index bfc7e927ee..be81316e69 100644 --- a/src/openrct2/world/map.c +++ b/src/openrct2/world/map.c @@ -2220,18 +2220,10 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 if (commandType == GAME_COMMAND_RAISE_LAND) { minHeight += 2; maxHeight += 2; - if (minHeight > MAXIMUM_LAND_HEIGHT) { - gGameCommandErrorText = STR_TOO_HIGH; - return MONEY32_UNDEFINED; - } } else { maxHeight -= 2; minHeight -= 2; - if (maxHeight < MINIMUM_LAND_HEIGHT) { - gGameCommandErrorText = STR_TOO_LOW; - return MONEY32_UNDEFINED; - } } } else @@ -2245,10 +2237,6 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 newBaseZ += 2; newSlope &= ~0x20; } - if (map_get_corner_height(newBaseZ, newSlope, command & 0xFF) > MAXIMUM_LAND_HEIGHT) { - gGameCommandErrorText = STR_TOO_HIGH; - return MONEY32_UNDEFINED; - } } else { newSlope = map_element_lower_styles[command & 0xFF][newSlope]; @@ -2256,10 +2244,6 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 newBaseZ -= 2; newSlope &= ~0x20; } - if (newBaseZ < MINIMUM_LAND_HEIGHT) { - gGameCommandErrorText = STR_TOO_LOW; - return MONEY32_UNDEFINED; - } } } @@ -2456,6 +2440,8 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 result = game_do_command(centreX, flags, centreY, mapLeftRight, commandType, command & 0x7FFF, mapTopBottom); if (result != MONEY32_UNDEFINED) { totalCost += result; + } else { + return MONEY32_UNDEFINED; } gCommandExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING; From 208ffbba8975ad74e341fda0ca21dc16aa40bb95 Mon Sep 17 00:00:00 2001 From: jensj12 Date: Fri, 21 Jul 2017 15:23:38 +0200 Subject: [PATCH 06/11] Put copied code in function Saves a few lines of code --- src/openrct2/world/map.c | 110 +++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 63 deletions(-) diff --git a/src/openrct2/world/map.c b/src/openrct2/world/map.c index be81316e69..b6904763bf 100644 --- a/src/openrct2/world/map.c +++ b/src/openrct2/world/map.c @@ -1750,6 +1750,49 @@ void game_command_set_land_ownership(sint32 *eax, sint32 *ebx, sint32 *ecx, sint } } +static uint8 map_get_lowest_land_height(sint32 xMin, sint32 xMax, sint32 yMin, sint32 yMax) +{ + xMin = max(xMin, 32); + yMin = max(yMin, 32); + xMax = min(xMax, gMapSizeMaxXY); + yMax = min(yMax, gMapSizeMaxXY); + + uint8 min_height = 0xFF; + for (sint32 yi = yMin; yi <= yMax; yi += 32) { + for (sint32 xi = xMin; xi <= xMax; xi += 32) { + rct_map_element *map_element = map_get_surface_element_at(xi / 32, yi / 32); + if (map_element != NULL && min_height > map_element->base_height) { + min_height = map_element->base_height; + } + } + } + return min_height; +} + +static uint8 map_get_highest_land_height(sint32 xMin, sint32 xMax, sint32 yMin, sint32 yMax) +{ + xMin = max(xMin, 32); + yMin = max(yMin, 32); + xMax = min(xMax, gMapSizeMaxXY); + yMax = min(yMax, gMapSizeMaxXY); + + uint8 max_height = 0; + for (sint32 yi = yMin; yi <= yMax; yi += 32) { + for (sint32 xi = xMin; xi <= xMax; xi += 32) { + rct_map_element *map_element = map_get_surface_element_at(xi / 32, yi / 32); + if (map_element != NULL) { + uint8 base_height = map_element->base_height; + if (map_element->properties.surface.slope & 0xF) + base_height += 2; + if (map_element->properties.surface.slope & 0x10) + base_height += 2; + if (max_height < base_height) + max_height = base_height; + } + } + } + return max_height; +} static money32 raise_land(sint32 flags, sint32 x, sint32 y, sint32 z, sint32 ax, sint32 ay, sint32 bx, sint32 by, sint32 selectionType) { @@ -1765,22 +1808,7 @@ static money32 raise_land(sint32 flags, sint32 x, sint32 y, sint32 z, sint32 ax, audio_play_sound_at_location(SOUND_PLACE_ITEM, x, y, z); } - uint8 min_height = 0xFF; - - ax = max(ax, 32); - ay = max(ay, 32); - bx = min(bx, gMapSizeMaxXY); - by = min(by, gMapSizeMaxXY); - - // find lowest map element in selection - for (sint32 yi = ay; yi <= by; yi += 32) { - for (sint32 xi = ax; xi <= bx; xi += 32) { - rct_map_element *map_element = map_get_surface_element_at(xi / 32, yi / 32); - if (map_element != NULL && min_height > map_element->base_height) { - min_height = map_element->base_height; - } - } - } + uint8 min_height = map_get_lowest_land_height(ax, bx, ay, by); for (sint32 yi = ay; yi <= by; yi += 32) { for (sint32 xi = ax; xi <= bx; xi += 32) { @@ -1827,28 +1855,7 @@ static money32 lower_land(sint32 flags, sint32 x, sint32 y, sint32 z, sint32 ax, return MONEY32_UNDEFINED; } - uint8 max_height = 0; - - ax = max(ax, 32); - ay = max(ay, 32); - bx = min(bx, gMapSizeMaxXY); - by = min(by, gMapSizeMaxXY); - - // find highest map element in selection - for (sint32 yi = ay; yi <= by; yi += 32) { - for (sint32 xi = ax; xi <= bx; xi += 32) { - rct_map_element *map_element = map_get_surface_element_at(xi / 32, yi / 32); - if (map_element != NULL) { - uint8 base_height = map_element->base_height; - if (map_element->properties.surface.slope & 0xF) - base_height += 2; - if (map_element->properties.surface.slope & 0x10) - base_height += 2; - if (max_height < base_height) - max_height = base_height; - } - } - } + uint8 max_height = map_get_highest_land_height(ax, bx, ay, by); for (sint32 yi = ay; yi <= by; yi += 32) { for (sint32 xi = ax; xi <= bx; xi += 32) { @@ -2191,31 +2198,8 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 // Predict the land height for future use if (fullTile) { - // Find lowest map element in selection - for (sint32 yi = mapTop; yi <= mapBottom; yi += 32) { - for (sint32 xi = mapLeft; xi <= mapRight; xi += 32) { - rct_map_element *map_element = map_get_surface_element_at(xi / 32, yi / 32); - if (map_element != NULL && minHeight > map_element->base_height) { - minHeight = map_element->base_height; - } - } - } - - // Find highest map element in selection - for (sint32 yi = mapTop; yi <= mapBottom; yi += 32) { - for (sint32 xi = mapLeft; xi <= mapRight; xi += 32) { - rct_map_element *map_element = map_get_surface_element_at(xi / 32, yi / 32); - if (map_element != NULL) { - uint8 base_height = map_element->base_height; - if (map_element->properties.surface.slope & 0xF) - base_height += 2; - if (map_element->properties.surface.slope & 0x10) - base_height += 2; - if (maxHeight < base_height) - maxHeight = base_height; - } - } - } + minHeight = map_get_lowest_land_height(mapLeft, mapRight, mapTop, mapBottom); + maxHeight = map_get_highest_land_height(mapLeft, mapRight, mapTop, mapBottom); if (commandType == GAME_COMMAND_RAISE_LAND) { minHeight += 2; From f35b0e6aceeb0279d182e5e7f1451e9d98639675 Mon Sep 17 00:00:00 2001 From: jensj12 Date: Thu, 13 Jul 2017 16:54:37 +0200 Subject: [PATCH 07/11] Replace mountain tool algorithm Fixes #2225. The mountain tool will now stop at land edges. It also improves the performance of the mountain tool. --- src/openrct2/world/map.c | 499 +++++++++++++++++++++------------------ 1 file changed, 269 insertions(+), 230 deletions(-) diff --git a/src/openrct2/world/map.c b/src/openrct2/world/map.c index b6904763bf..6027687fc6 100644 --- a/src/openrct2/world/map.c +++ b/src/openrct2/world/map.c @@ -2093,63 +2093,192 @@ void game_command_lower_land(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, ); } -/** - * - * rct2: 0x0068C3B2 slope 1, style 0 - * rct2: 0x0068C47A slope 2, style 1 - * rct2: 0x0068C222 slope 4, style 2 - * rct2: 0x0068C2EA slope 8, style 3 - */ -static money32 smooth_land_tile(sint32 direction, uint8 flags, sint32 x, sint32 y, sint32 targetBaseZ, sint32 minBaseZ) +static money32 smooth_land_tile(sint32 direction, uint8 flags, sint32 x, sint32 y, rct_map_element * mapElement, bool raiseLand) { - // Check if inside map bounds - if (!map_is_location_valid(x, y)) { - return MONEY32_UNDEFINED; - } - - // Get height of tile - rct_map_element *mapElement = map_get_surface_element_at(x >> 5, y >> 5); - if (mapElement == NULL) - { - log_warning("Invalid coordinates for land smoothing, x = %d, y = %d", x, y); - return MONEY32_UNDEFINED; - } - sint32 baseZ = map_element_get_corner_height(mapElement, direction); - - // Check if tile is same height as target tile - if (baseZ == targetBaseZ) { - // No need to raise or lower - return MONEY32_UNDEFINED; - } - - uint8 style; - if (targetBaseZ <= baseZ) { - baseZ = baseZ - targetBaseZ; - if (baseZ <= minBaseZ) { - return MONEY32_UNDEFINED; - } - targetBaseZ = mapElement->base_height; - sint32 slope = mapElement->properties.surface.slope & MAP_ELEMENT_SLOPE_MASK; - style = map_element_lower_styles[direction][slope]; - if (style & 0x20) { - targetBaseZ -= 2; - style &= ~0x20; - } - } else { - baseZ = targetBaseZ - baseZ; - if (baseZ <= minBaseZ) { - return MONEY32_UNDEFINED; - } - targetBaseZ = mapElement->base_height; - sint32 slope = mapElement->properties.surface.slope & MAP_ELEMENT_SLOPE_MASK; - style = map_element_raise_styles[direction][slope]; - if ((style & 0x20) != 0) { + sint32 targetBaseZ = mapElement->base_height; + sint32 slope = mapElement->properties.surface.slope & MAP_ELEMENT_SLOPE_MASK; + if (raiseLand) { + slope = map_element_raise_styles[direction][slope]; + if (slope & 0x20) { targetBaseZ += 2; - style &= ~0x20; + slope &= ~0x20; } } + else { + slope = map_element_lower_styles[direction][slope]; + if (slope & 0x20) { + targetBaseZ -= 2; + slope &= ~0x20; + } + } + return game_do_command(x, flags, y, targetBaseZ | (slope << 8), GAME_COMMAND_SET_LAND_HEIGHT, 0, 0); +} - return game_do_command(x, flags, y, targetBaseZ | (style << 8), GAME_COMMAND_SET_LAND_HEIGHT, 0, 0); +static money32 smooth_land_row_by_edge(sint32 flags, sint32 x, sint32 y, sint32 expectedLandHeight1, sint32 expectedLandHeight2, sint32 stepX, sint32 stepY, sint32 direction1, sint32 direction2, sint32 checkDirection1, sint32 checkDirection2, bool raiseLand) +{ + bool shouldContinue = true; + sint32 landChangePerTile = raiseLand ? -2 : 2; + rct_map_element *mapElement, *nextMapElement; + money32 totalCost = 0; + money32 result; + + // check if we need to start at all + if (!map_is_location_valid(x, y) || !map_is_location_valid(x + stepX, y + stepY)) { + return 0; + } + mapElement = map_get_surface_element_at(x >> 5, y >> 5); + nextMapElement = map_get_surface_element_at((x + stepX) >> 5, (y + stepY) >> 5); + if (mapElement == NULL || nextMapElement == NULL) { + return 0; + } + if (map_element_get_corner_height(mapElement, checkDirection1) != expectedLandHeight1 + (raiseLand ? -2 : 2)) { + return 0; + } + if (map_element_get_corner_height(mapElement, checkDirection2) != expectedLandHeight2 + (raiseLand ? -2 : 2)) { + return 0; + } + if (map_element_get_corner_height(mapElement, checkDirection1) != map_element_get_corner_height(nextMapElement, direction1)) { + return 0; + } + if (map_element_get_corner_height(mapElement, checkDirection2) != map_element_get_corner_height(nextMapElement, direction2)) { + return 0; + } + while (shouldContinue) + { + x += stepX; + y += stepY; + // check if we need to continue after raising the current tile + // this needs to be checked before the tile is changed + if (!map_is_location_valid(x + stepX, y + stepY)) { + shouldContinue = false; + } + else + { + mapElement = nextMapElement; + nextMapElement = map_get_surface_element_at((x + stepX) >> 5, (y + stepY) >> 5); + if (nextMapElement == NULL) { + shouldContinue = false; + } + if (map_element_get_corner_height(mapElement, direction1) + landChangePerTile != map_element_get_corner_height(mapElement, checkDirection1)) { + shouldContinue = false; + } + if (map_element_get_corner_height(mapElement, direction2) + landChangePerTile != map_element_get_corner_height(mapElement, checkDirection2)) { + if (shouldContinue) + { + //totalCost += smooth_land_row_by_corner(flags, x, y, expectedLandHeight1, stepX, stepY, direction1, checkDirection1, raiseLand, landChangePerTile); + } + shouldContinue = false; + } + if (shouldContinue && map_element_get_corner_height(mapElement, checkDirection1) != map_element_get_corner_height(nextMapElement, direction1)) { + shouldContinue = false; + } + if (shouldContinue && map_element_get_corner_height(mapElement, checkDirection2) != map_element_get_corner_height(nextMapElement, direction2)) { + shouldContinue = false; + } + } + expectedLandHeight1 += landChangePerTile; + // change land of current tile + sint32 targetBaseZ = mapElement->base_height; + sint32 slope = mapElement->properties.surface.slope & MAP_ELEMENT_SLOPE_MASK; + if (raiseLand) { + slope = map_element_raise_styles[direction1][slope]; + if (slope & 0x20) { + targetBaseZ += 2; + slope &= ~0x20; + } + slope = map_element_raise_styles[direction2][slope]; + if (slope & 0x20) { + targetBaseZ += 2; + slope &= ~0x20; + } + } + else + { + slope = map_element_lower_styles[direction1][slope]; + if (slope & 0x20) { + targetBaseZ -= 2; + slope &= ~0x20; + } + slope = map_element_lower_styles[direction2][slope]; + if (slope & 0x20) { + targetBaseZ -= 2; + slope &= ~0x20; + } + } + result = game_do_command(x, flags, y, targetBaseZ | (slope << 8), GAME_COMMAND_SET_LAND_HEIGHT, 0, 0); + if (result != MONEY32_UNDEFINED) { + totalCost += result; + } + } + return totalCost; +} + +static money32 smooth_land_row_by_corner(sint32 flags, sint32 x, sint32 y, sint32 expectedLandHeight, sint32 stepX, sint32 stepY, sint32 direction, sint32 checkDirection, bool raiseLand) +{ + bool shouldContinue = true; + rct_map_element *mapElement, *nextMapElement; + money32 totalCost = 0; + money32 result; + sint32 landChangePerTile; + if (stepX == 0 || stepY == 0) + { + landChangePerTile = raiseLand ? -2 : 2; + } + else + { + landChangePerTile = raiseLand ? -4 : 4; + } + + // check if we need to start at all + if (!map_is_location_valid(x, y) || !map_is_location_valid(x + stepX, y + stepY)) { + return 0; + } + mapElement = map_get_surface_element_at(x >> 5, y >> 5); + nextMapElement = map_get_surface_element_at((x + stepX) >> 5, (y + stepY) >> 5); + if (mapElement == NULL || nextMapElement == NULL) { + return 0; + } + if (map_element_get_corner_height(mapElement, checkDirection) != expectedLandHeight + (raiseLand ? -2 : 2)) { + return 0; + } + if (map_element_get_corner_height(mapElement, checkDirection) != map_element_get_corner_height(nextMapElement, direction)) { + return 0; + } + while (shouldContinue) + { + x += stepX; + y += stepY; + // check if we need to continue after raising the current tile + // this needs to be checked before the tile is changed + if (!map_is_location_valid(x + stepX, y + stepY)) { + shouldContinue = false; + } + else + { + mapElement = nextMapElement; + nextMapElement = map_get_surface_element_at((x + stepX) >> 5, (y + stepY) >> 5); + if (nextMapElement == NULL) { + shouldContinue = false; + } + if (map_element_get_corner_height(mapElement, direction) + landChangePerTile != map_element_get_corner_height(mapElement, checkDirection)) { + shouldContinue = false; + } + if (shouldContinue && map_element_get_corner_height(mapElement, checkDirection) != map_element_get_corner_height(nextMapElement, direction)) { + shouldContinue = false; + } + } + if (stepX*stepY != 0) { + totalCost += smooth_land_row_by_corner(flags, x, y, expectedLandHeight + (landChangePerTile / 2), 0, stepY, direction, (checkDirection + 1)%4, raiseLand); + totalCost += smooth_land_row_by_corner(flags, x, y, expectedLandHeight + (landChangePerTile / 2), stepX, 0, direction, (checkDirection + 3)%4, raiseLand); + } + expectedLandHeight += landChangePerTile; + // change land of current tile + result = smooth_land_tile(direction, flags, x, y, mapElement, raiseLand); + if (result != MONEY32_UNDEFINED) { + totalCost += result; + } + } + return totalCost; } static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 mapLeft, sint32 mapTop, sint32 mapRight, sint32 mapBottom, sint32 command) @@ -2160,7 +2289,8 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 mapRight = clamp(0, mapRight, (MAXIMUM_MAP_SIZE_TECHNICAL - 1) * 32); mapBottom = clamp(0, mapBottom, (MAXIMUM_MAP_SIZE_TECHNICAL - 1) * 32); - sint32 commandType; + bool raiseLand = command < 0x7FFF; + sint32 commandType = raiseLand ? GAME_COMMAND_RAISE_LAND : GAME_COMMAND_LOWER_LAND; sint32 centreZ = map_element_height(centreX, centreY); sint32 mapLeftRight = mapLeft | (mapRight << 16); sint32 mapTopBottom = mapTop | (mapBottom << 16); @@ -2173,7 +2303,6 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 money32 totalCost = 0; money32 result; - commandType = command < 0x7FFF ? GAME_COMMAND_RAISE_LAND : GAME_COMMAND_LOWER_LAND; rct_map_element *mapElement = map_get_surface_element_at(mapLeft >> 5, mapTop >> 5); if (mapElement == NULL) @@ -2231,192 +2360,102 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 } } - sint32 x = mapLeft; - sint32 y = mapTop; - sint32 size = ((mapRight - mapLeft) >> 5) + 1; - sint32 initialMinZ = -2; - // Then do the smoothing - // The coords go in circles around the selected tile(s) - for (; size <= MAXIMUM_MAP_SIZE_TECHNICAL; size += 2) { - initialMinZ += 2; - sint32 minZ = initialMinZ * 2; - x -= 32; - y -= 32; - - // Corner (North-West) - mapElement = map_get_surface_element_at(mapLeft >> 5, mapTop >> 5); + if (fullTile) { sint32 z = clamp(minHeight, map_element_get_corner_height(mapElement, 2), maxHeight); - if (!fullTile) - z = map_get_corner_height(newBaseZ, newSlope, 2); - result = smooth_land_tile(0, flags, x, y, z, minZ); - if (result != MONEY32_UNDEFINED) { - totalCost += result; - } - y += 32; - - // Side (West) - for (sint32 i = 0; i < size; i++) { - sint32 y2 = clamp(mapTop, y, mapBottom); - mapElement = map_get_surface_element_at(mapLeft >> 5, y2 >> 5); - if (y >= mapTop) { - z = clamp(minHeight, map_element_get_corner_height(mapElement, 3), maxHeight); - if (!fullTile) - z = map_get_corner_height(newBaseZ, newSlope, 3); - result = smooth_land_tile((y <= mapBottom) ? 0 : 1, flags, x, y, z, minZ); - if (result != MONEY32_UNDEFINED) { - totalCost += result; - } - } - minZ -= 2; - if (y >= mapTop) { - minZ += 2; - if (y > mapBottom) { - minZ += 2; - } - } - if (y <= mapBottom) { - z = clamp(minHeight, map_element_get_corner_height(mapElement, 2), maxHeight); - if (!fullTile) - z = map_get_corner_height(newBaseZ, newSlope, 2); - result = smooth_land_tile((y >= mapTop) ? 1 : 0, flags, x, y, z, minZ); - if (result != MONEY32_UNDEFINED) { - totalCost += result; - } - } - - y += 32; - } - - // Corner (South-West) + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, -32, -32, 0, 2, raiseLand); mapElement = map_get_surface_element_at(mapLeft >> 5, mapBottom >> 5); z = clamp(minHeight, map_element_get_corner_height(mapElement, 3), maxHeight); - if (!fullTile) - z = map_get_corner_height(newBaseZ, newSlope, 3); - result = smooth_land_tile(1, flags, x, y, z, minZ); - if (result != MONEY32_UNDEFINED) { - totalCost += result; - } - x += 32; - - // Side (South) - for (sint32 i = 0; i < size; i++) { - sint32 x2 = clamp(mapLeft, x, mapRight); - mapElement = map_get_surface_element_at(x2 >> 5, mapBottom >> 5); - if (x >= mapLeft) { - z = clamp(minHeight, map_element_get_corner_height(mapElement, 0), maxHeight); - if (!fullTile) - z = map_get_corner_height(newBaseZ, newSlope, 0); - result = smooth_land_tile((x <= mapRight) ? 1 : 2, flags, x, y, z, minZ); - if (result != MONEY32_UNDEFINED) { - totalCost += result; - } - } - minZ -= 2; - if (x >= mapLeft) { - minZ += 2; - if (x > mapRight) { - minZ += 2; - } - } - if (x <= mapRight) { - z = clamp(minHeight, map_element_get_corner_height(mapElement, 3), maxHeight); - if (!fullTile) - z = map_get_corner_height(newBaseZ, newSlope, 3); - result = smooth_land_tile((x >= mapLeft) ? 2 : 1, flags, x, y, z, minZ); - if (result != MONEY32_UNDEFINED) { - totalCost += result; - } - } - x += 32; - } - - // Corner (South-East) + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapBottom, z, -32, 32, 1, 3, raiseLand); mapElement = map_get_surface_element_at(mapRight >> 5, mapBottom >> 5); z = clamp(minHeight, map_element_get_corner_height(mapElement, 0), maxHeight); - if (!fullTile) - z = map_get_corner_height(newBaseZ, newSlope, 0); - result = smooth_land_tile(2, flags, x, y, z, minZ); - if (result != MONEY32_UNDEFINED) { - totalCost += result; - } - y -= 32; - - // Side (East) - for (sint32 i = 0; i < size; i++) { - sint32 y2 = clamp(mapTop, y, mapBottom); - mapElement = map_get_surface_element_at(mapRight >> 5, y2 >> 5); - if (y <= mapBottom) { - z = clamp(minHeight, map_element_get_corner_height(mapElement, 1), maxHeight); - if (!fullTile) - z = map_get_corner_height(newBaseZ, newSlope, 1); - result = smooth_land_tile((y >= mapTop) ? 2 : 3, flags, x, y, z, minZ); - if (result != MONEY32_UNDEFINED) { - totalCost += result; - } - } - minZ -= 2; - if (y <= mapBottom) { - minZ += 2; - if (y < mapTop) { - minZ += 2; - } - } - if (y >= mapTop) { - z = clamp(minHeight, map_element_get_corner_height(mapElement, 0), maxHeight); - if (!fullTile) - z = map_get_corner_height(newBaseZ, newSlope, 0); - result = smooth_land_tile((y <= mapBottom) ? 3 : 2, flags, x, y, z, minZ); - if (result != MONEY32_UNDEFINED) { - totalCost += result; - } - } - - y -= 32; - } - - // Corner (North-East) + totalCost += smooth_land_row_by_corner(flags, mapRight, mapBottom, z, 32, 32, 2, 0, raiseLand); mapElement = map_get_surface_element_at(mapRight >> 5, mapTop >> 5); z = clamp(minHeight, map_element_get_corner_height(mapElement, 1), maxHeight); - if (!fullTile) - z = map_get_corner_height(newBaseZ, newSlope, 1); - result = smooth_land_tile(3, flags, x, y, z, minZ); - if (result != MONEY32_UNDEFINED) { - totalCost += result; + totalCost += smooth_land_row_by_corner(flags, mapRight, mapTop, z, 32, -32, 3, 1, raiseLand); + + sint32 x = mapLeft; + sint32 y, z2; + for (y = mapTop; y <= mapBottom; y += 32) + { + mapElement = map_get_surface_element_at(x >> 5, y >> 5); + z = clamp(minHeight, map_element_get_corner_height(mapElement, 0), maxHeight); + z2 = clamp(minHeight, map_element_get_corner_height(mapElement, 1), maxHeight); + totalCost += smooth_land_row_by_edge(flags, x, y, z, z2, -32, 0, 0, 1, 3, 2, raiseLand); } - x -= 32; + x = mapRight; + for (y = mapTop; y <= mapBottom; y += 32) + { + mapElement = map_get_surface_element_at(x >> 5, y >> 5); + z = clamp(minHeight, map_element_get_corner_height(mapElement, 2), maxHeight); + z2 = clamp(minHeight, map_element_get_corner_height(mapElement, 3), maxHeight); + totalCost += smooth_land_row_by_edge(flags, x, y, z, z2, 32, 0, 2, 3, 1, 0, raiseLand); + } + y = mapTop; + for (x = mapLeft; x <= mapRight; x += 32) + { + mapElement = map_get_surface_element_at(x >> 5, y >> 5); + z = clamp(minHeight, map_element_get_corner_height(mapElement, 0), maxHeight); + z2 = clamp(minHeight, map_element_get_corner_height(mapElement, 3), maxHeight); + totalCost += smooth_land_row_by_edge(flags, x, y, z, z2, 0, -32, 0, 3, 1, 2, raiseLand); + } + y = mapBottom; + for (x = mapLeft; x <= mapRight; x += 32) + { + mapElement = map_get_surface_element_at(x >> 5, y >> 5); + z = clamp(minHeight, map_element_get_corner_height(mapElement, 1), maxHeight); + z2 = clamp(minHeight, map_element_get_corner_height(mapElement, 2), maxHeight); + totalCost += smooth_land_row_by_edge(flags, x, y, z, z2, 0, 32, 1, 2, 0, 3, raiseLand); + } + } + else // fullTile + { + sint32 z = map_get_corner_height(newBaseZ, newSlope, 2); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, -32, -32, 0, 2, raiseLand); + z = map_get_corner_height(newBaseZ, newSlope, 0); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 32, 32, 2, 0, raiseLand); + z = map_get_corner_height(newBaseZ, newSlope, 3); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, -32, 32, 1, 3, raiseLand); + z = map_get_corner_height(newBaseZ, newSlope, 1); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 32, -32, 3, 1, raiseLand); - // Side (North) - for (sint32 i = 0; i < size; i++) { - sint32 x2 = clamp(mapLeft, x, mapRight); - mapElement = map_get_surface_element_at(x2 >> 5, mapTop >> 5); - if (x <= mapRight) { - z = clamp(minHeight, map_element_get_corner_height(mapElement, 2), maxHeight); - if (!fullTile) - z = map_get_corner_height(newBaseZ, newSlope, 2); - result = smooth_land_tile((x >= mapLeft) ? 3 : 0, flags, x, y, z, minZ); - if (result != MONEY32_UNDEFINED) { - totalCost += result; - } - } - minZ -= 2; - if (x <= mapRight) { - minZ += 2; - if (x < mapLeft) { - minZ += 2; - } - } - if (x >= mapLeft) { - z = clamp(minHeight, map_element_get_corner_height(mapElement, 1), maxHeight); - if (!fullTile) - z = map_get_corner_height(newBaseZ, newSlope, 1); - result = smooth_land_tile((x <= mapRight) ? 0 : 3, flags, x, y, z, minZ); - if (result != MONEY32_UNDEFINED) { - totalCost += result; - } - } - - x -= 32; + switch (command & 0x7FFF) { + case MAP_SELECT_TYPE_CORNER_0: + z = map_get_corner_height(newBaseZ, newSlope, 0); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 32, 0, 3, 0, raiseLand); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 0, 32, 1, 0, raiseLand); + z = map_get_corner_height(newBaseZ, newSlope, 1); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, -32, 0, 0, 1, raiseLand); + z = map_get_corner_height(newBaseZ, newSlope, 3); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 0, -32, 0, 3, raiseLand); + break; + case MAP_SELECT_TYPE_CORNER_1: + z = map_get_corner_height(newBaseZ, newSlope, 1); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 32, 0, 2, 1, raiseLand); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 0, -32, 0, 1, raiseLand); + z = map_get_corner_height(newBaseZ, newSlope, 0); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, -32, 0, 1, 0, raiseLand); + z = map_get_corner_height(newBaseZ, newSlope, 2); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 0, 32, 1, 2, raiseLand); + break; + case MAP_SELECT_TYPE_CORNER_2: + z = map_get_corner_height(newBaseZ, newSlope, 2); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, -32, 0, 1, 2, raiseLand); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 0, -32, 3, 2, raiseLand); + z = map_get_corner_height(newBaseZ, newSlope, 3); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 32, 0, 2, 3, raiseLand); + z = map_get_corner_height(newBaseZ, newSlope, 1); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 0, 32, 2, 1, raiseLand); + break; + case MAP_SELECT_TYPE_CORNER_3: + z = map_get_corner_height(newBaseZ, newSlope, 3); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, -32, 0, 0, 3, raiseLand); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 0, 32, 2, 3, raiseLand); + z = map_get_corner_height(newBaseZ, newSlope, 2); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 32, 0, 3, 2, raiseLand); + z = map_get_corner_height(newBaseZ, newSlope, 0); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 0, -32, 3, 0, raiseLand); + break; } } From 0eb8f632b0eeccaddea29b73c031fca594df6fe2 Mon Sep 17 00:00:00 2001 From: jensj12 Date: Fri, 28 Jul 2017 18:52:56 +0200 Subject: [PATCH 08/11] Fix cases where land would not be smoothed properly --- src/openrct2/world/map.c | 119 +++++++++++++++++++++++---------------- 1 file changed, 69 insertions(+), 50 deletions(-) diff --git a/src/openrct2/world/map.c b/src/openrct2/world/map.c index 6027687fc6..94c122699a 100644 --- a/src/openrct2/world/map.c +++ b/src/openrct2/world/map.c @@ -2116,7 +2116,7 @@ static money32 smooth_land_tile(sint32 direction, uint8 flags, sint32 x, sint32 static money32 smooth_land_row_by_edge(sint32 flags, sint32 x, sint32 y, sint32 expectedLandHeight1, sint32 expectedLandHeight2, sint32 stepX, sint32 stepY, sint32 direction1, sint32 direction2, sint32 checkDirection1, sint32 checkDirection2, bool raiseLand) { - bool shouldContinue = true; + uint8 shouldContinue = 0xF; sint32 landChangePerTile = raiseLand ? -2 : 2; rct_map_element *mapElement, *nextMapElement; money32 totalCost = 0; @@ -2132,77 +2132,90 @@ static money32 smooth_land_row_by_edge(sint32 flags, sint32 x, sint32 y, sint32 return 0; } if (map_element_get_corner_height(mapElement, checkDirection1) != expectedLandHeight1 + (raiseLand ? -2 : 2)) { - return 0; + shouldContinue &= ~0x1; } if (map_element_get_corner_height(mapElement, checkDirection2) != expectedLandHeight2 + (raiseLand ? -2 : 2)) { - return 0; + shouldContinue &= ~0x2; } if (map_element_get_corner_height(mapElement, checkDirection1) != map_element_get_corner_height(nextMapElement, direction1)) { - return 0; + shouldContinue &= ~0x1; } if (map_element_get_corner_height(mapElement, checkDirection2) != map_element_get_corner_height(nextMapElement, direction2)) { - return 0; + shouldContinue &= ~0x2; } - while (shouldContinue) + while ((shouldContinue & 0x3) != 0) { + shouldContinue = ((shouldContinue << 2) | 0x3) & shouldContinue; x += stepX; y += stepY; // check if we need to continue after raising the current tile // this needs to be checked before the tile is changed if (!map_is_location_valid(x + stepX, y + stepY)) { - shouldContinue = false; + shouldContinue &= ~0x3; } else { mapElement = nextMapElement; nextMapElement = map_get_surface_element_at((x + stepX) >> 5, (y + stepY) >> 5); if (nextMapElement == NULL) { - shouldContinue = false; + shouldContinue &= ~0x3; } if (map_element_get_corner_height(mapElement, direction1) + landChangePerTile != map_element_get_corner_height(mapElement, checkDirection1)) { - shouldContinue = false; + shouldContinue &= ~0x1; } if (map_element_get_corner_height(mapElement, direction2) + landChangePerTile != map_element_get_corner_height(mapElement, checkDirection2)) { - if (shouldContinue) - { - //totalCost += smooth_land_row_by_corner(flags, x, y, expectedLandHeight1, stepX, stepY, direction1, checkDirection1, raiseLand, landChangePerTile); - } - shouldContinue = false; + shouldContinue &= ~0x2; } - if (shouldContinue && map_element_get_corner_height(mapElement, checkDirection1) != map_element_get_corner_height(nextMapElement, direction1)) { - shouldContinue = false; + if ((shouldContinue & 0x1) && map_element_get_corner_height(mapElement, checkDirection1) != map_element_get_corner_height(nextMapElement, direction1)) { + shouldContinue &= ~0x1; } - if (shouldContinue && map_element_get_corner_height(mapElement, checkDirection2) != map_element_get_corner_height(nextMapElement, direction2)) { - shouldContinue = false; + if ((shouldContinue & 0x2) && map_element_get_corner_height(mapElement, checkDirection2) != map_element_get_corner_height(nextMapElement, direction2)) { + shouldContinue &= ~0x2; } } expectedLandHeight1 += landChangePerTile; + // change land of current tile sint32 targetBaseZ = mapElement->base_height; sint32 slope = mapElement->properties.surface.slope & MAP_ELEMENT_SLOPE_MASK; + sint32 oldSlope = slope; if (raiseLand) { - slope = map_element_raise_styles[direction1][slope]; - if (slope & 0x20) { - targetBaseZ += 2; - slope &= ~0x20; + if (shouldContinue & 0x4) { + slope = map_element_raise_styles[direction1][slope]; + if (slope & 0x20) { + targetBaseZ += 2; + slope &= ~0x20; + } } - slope = map_element_raise_styles[direction2][slope]; - if (slope & 0x20) { - targetBaseZ += 2; - slope &= ~0x20; + if ((shouldContinue & 0x8) && + map_get_corner_height(mapElement->base_height, oldSlope, direction2) == + map_get_corner_height(targetBaseZ, slope, direction2)) + { + slope = map_element_raise_styles[direction2][slope]; + if (slope & 0x20) { + targetBaseZ += 2; + slope &= ~0x20; + } } } else { - slope = map_element_lower_styles[direction1][slope]; - if (slope & 0x20) { - targetBaseZ -= 2; - slope &= ~0x20; + if (shouldContinue & 0x4) { + slope = map_element_lower_styles[direction1][slope]; + if (slope & 0x20) { + targetBaseZ -= 2; + slope &= ~0x20; + } } - slope = map_element_lower_styles[direction2][slope]; - if (slope & 0x20) { - targetBaseZ -= 2; - slope &= ~0x20; + if ((shouldContinue & 0x8) && + map_get_corner_height(mapElement->base_height, oldSlope, direction2) == + map_get_corner_height(targetBaseZ, slope, direction2)) + { + slope = map_element_lower_styles[direction2][slope]; + if (slope & 0x20) { + targetBaseZ -= 2; + slope &= ~0x20; + } } } result = game_do_command(x, flags, y, targetBaseZ | (slope << 8), GAME_COMMAND_SET_LAND_HEIGHT, 0, 0); @@ -2267,9 +2280,10 @@ static money32 smooth_land_row_by_corner(sint32 flags, sint32 x, sint32 y, sint3 shouldContinue = false; } } - if (stepX*stepY != 0) { - totalCost += smooth_land_row_by_corner(flags, x, y, expectedLandHeight + (landChangePerTile / 2), 0, stepY, direction, (checkDirection + 1)%4, raiseLand); - totalCost += smooth_land_row_by_corner(flags, x, y, expectedLandHeight + (landChangePerTile / 2), stepX, 0, direction, (checkDirection + 3)%4, raiseLand); + if (stepX*stepY != 0) + { + totalCost += smooth_land_row_by_corner(flags, x, y, expectedLandHeight + (landChangePerTile / 2), 0, stepY, direction, checkDirection ^ 3, raiseLand); + totalCost += smooth_land_row_by_corner(flags, x, y, expectedLandHeight + (landChangePerTile / 2), stepX, 0, direction, checkDirection ^ 1, raiseLand); } expectedLandHeight += landChangePerTile; // change land of current tile @@ -2362,6 +2376,7 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 // Then do the smoothing if (fullTile) { + // Smooth the corners sint32 z = clamp(minHeight, map_element_get_corner_height(mapElement, 2), maxHeight); totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, -32, -32, 0, 2, raiseLand); mapElement = map_get_surface_element_at(mapLeft >> 5, mapBottom >> 5); @@ -2374,6 +2389,7 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 z = clamp(minHeight, map_element_get_corner_height(mapElement, 1), maxHeight); totalCost += smooth_land_row_by_corner(flags, mapRight, mapTop, z, 32, -32, 3, 1, raiseLand); + // Smooth the edges sint32 x = mapLeft; sint32 y, z2; for (y = mapTop; y <= mapBottom; y += 32) @@ -2408,8 +2424,10 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 totalCost += smooth_land_row_by_edge(flags, x, y, z, z2, 0, 32, 1, 2, 0, 3, raiseLand); } } - else // fullTile + else { + // One corner tile selected + // Smooth the corners sint32 z = map_get_corner_height(newBaseZ, newSlope, 2); totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, -32, -32, 0, 2, raiseLand); z = map_get_corner_height(newBaseZ, newSlope, 0); @@ -2419,42 +2437,43 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 z = map_get_corner_height(newBaseZ, newSlope, 1); totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 32, -32, 3, 1, raiseLand); + // Smooth the edges switch (command & 0x7FFF) { case MAP_SELECT_TYPE_CORNER_0: z = map_get_corner_height(newBaseZ, newSlope, 0); totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 32, 0, 3, 0, raiseLand); totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 0, 32, 1, 0, raiseLand); - z = map_get_corner_height(newBaseZ, newSlope, 1); - totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, -32, 0, 0, 1, raiseLand); z = map_get_corner_height(newBaseZ, newSlope, 3); - totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 0, -32, 0, 3, raiseLand); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, -32, 0, 0, 3, raiseLand); + z = map_get_corner_height(newBaseZ, newSlope, 1); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 0, -32, 0, 1, raiseLand); break; case MAP_SELECT_TYPE_CORNER_1: z = map_get_corner_height(newBaseZ, newSlope, 1); totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 32, 0, 2, 1, raiseLand); totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 0, -32, 0, 1, raiseLand); - z = map_get_corner_height(newBaseZ, newSlope, 0); - totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, -32, 0, 1, 0, raiseLand); z = map_get_corner_height(newBaseZ, newSlope, 2); - totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 0, 32, 1, 2, raiseLand); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, -32, 0, 1, 2, raiseLand); + z = map_get_corner_height(newBaseZ, newSlope, 0); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 0, 32, 1, 0, raiseLand); break; case MAP_SELECT_TYPE_CORNER_2: z = map_get_corner_height(newBaseZ, newSlope, 2); totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, -32, 0, 1, 2, raiseLand); totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 0, -32, 3, 2, raiseLand); - z = map_get_corner_height(newBaseZ, newSlope, 3); - totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 32, 0, 2, 3, raiseLand); z = map_get_corner_height(newBaseZ, newSlope, 1); - totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 0, 32, 2, 1, raiseLand); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 32, 0, 2, 1, raiseLand); + z = map_get_corner_height(newBaseZ, newSlope, 3); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 0, 32, 2, 3, raiseLand); break; case MAP_SELECT_TYPE_CORNER_3: z = map_get_corner_height(newBaseZ, newSlope, 3); totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, -32, 0, 0, 3, raiseLand); totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 0, 32, 2, 3, raiseLand); - z = map_get_corner_height(newBaseZ, newSlope, 2); - totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 32, 0, 3, 2, raiseLand); z = map_get_corner_height(newBaseZ, newSlope, 0); - totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 0, -32, 3, 0, raiseLand); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 32, 0, 3, 0, raiseLand); + z = map_get_corner_height(newBaseZ, newSlope, 2); + totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, 0, -32, 3, 2, raiseLand); break; } } From 7db8162a44f09f8220a54541a61986db43fe9460 Mon Sep 17 00:00:00 2001 From: jensj12 Date: Sat, 29 Jul 2017 11:58:08 +0200 Subject: [PATCH 09/11] Bugfix --- src/openrct2/world/map.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/openrct2/world/map.c b/src/openrct2/world/map.c index 94c122699a..f7bec0a91c 100644 --- a/src/openrct2/world/map.c +++ b/src/openrct2/world/map.c @@ -2395,32 +2395,32 @@ static money32 smooth_land(sint32 flags, sint32 centreX, sint32 centreY, sint32 for (y = mapTop; y <= mapBottom; y += 32) { mapElement = map_get_surface_element_at(x >> 5, y >> 5); - z = clamp(minHeight, map_element_get_corner_height(mapElement, 0), maxHeight); - z2 = clamp(minHeight, map_element_get_corner_height(mapElement, 1), maxHeight); + z = clamp(minHeight, map_element_get_corner_height(mapElement, 3), maxHeight); + z2 = clamp(minHeight, map_element_get_corner_height(mapElement, 2), maxHeight); totalCost += smooth_land_row_by_edge(flags, x, y, z, z2, -32, 0, 0, 1, 3, 2, raiseLand); } x = mapRight; for (y = mapTop; y <= mapBottom; y += 32) { mapElement = map_get_surface_element_at(x >> 5, y >> 5); - z = clamp(minHeight, map_element_get_corner_height(mapElement, 2), maxHeight); - z2 = clamp(minHeight, map_element_get_corner_height(mapElement, 3), maxHeight); + z = clamp(minHeight, map_element_get_corner_height(mapElement, 1), maxHeight); + z2 = clamp(minHeight, map_element_get_corner_height(mapElement, 0), maxHeight); totalCost += smooth_land_row_by_edge(flags, x, y, z, z2, 32, 0, 2, 3, 1, 0, raiseLand); } y = mapTop; for (x = mapLeft; x <= mapRight; x += 32) { mapElement = map_get_surface_element_at(x >> 5, y >> 5); - z = clamp(minHeight, map_element_get_corner_height(mapElement, 0), maxHeight); - z2 = clamp(minHeight, map_element_get_corner_height(mapElement, 3), maxHeight); + z = clamp(minHeight, map_element_get_corner_height(mapElement, 1), maxHeight); + z2 = clamp(minHeight, map_element_get_corner_height(mapElement, 2), maxHeight); totalCost += smooth_land_row_by_edge(flags, x, y, z, z2, 0, -32, 0, 3, 1, 2, raiseLand); } y = mapBottom; for (x = mapLeft; x <= mapRight; x += 32) { mapElement = map_get_surface_element_at(x >> 5, y >> 5); - z = clamp(minHeight, map_element_get_corner_height(mapElement, 1), maxHeight); - z2 = clamp(minHeight, map_element_get_corner_height(mapElement, 2), maxHeight); + z = clamp(minHeight, map_element_get_corner_height(mapElement, 0), maxHeight); + z2 = clamp(minHeight, map_element_get_corner_height(mapElement, 3), maxHeight); totalCost += smooth_land_row_by_edge(flags, x, y, z, z2, 0, 32, 1, 2, 0, 3, raiseLand); } } From 353c66e19a99da34d390084e28ba809864d2c59d Mon Sep 17 00:00:00 2001 From: jensj12 Date: Sat, 29 Jul 2017 12:00:20 +0200 Subject: [PATCH 10/11] Changelog entry --- distribution/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 9575fac328..d725e11e5e 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -24,6 +24,7 @@ - Fix: [#5998] Staff not getting paid / no loan interest. - Fix: [#6026] 'Select ride to advertise' dropdown does not display all items. - Fix: [#6052] Unable to place entrance/exit on certain ride types. +- Improved: [#2223] Change mountain tool to ignore higher surrounding tiles. - Improved: [#4301] Leading and trailing whitespace in player name is now removed. - Improved: [#5859] OpenGL rendering performance - Improved: [#5863] Switching drawing engines no longer requires the application to restart. From b0f93a08d90596d728e483f9303977483e9238ef Mon Sep 17 00:00:00 2001 From: jensj12 Date: Sat, 29 Jul 2017 23:13:13 +0200 Subject: [PATCH 11/11] Use sint32 instead of int --- src/openrct2/world/map.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openrct2/world/map.c b/src/openrct2/world/map.c index f7bec0a91c..622a8890ce 100644 --- a/src/openrct2/world/map.c +++ b/src/openrct2/world/map.c @@ -1657,8 +1657,8 @@ static money32 map_set_land_height(sint32 flags, sint32 x, sint32 y, sint32 heig } while (!map_element_is_last_for_tile(mapElement++)); } - for (int i = 0; i < 4; i += 1) { - int cornerHeight = map_element_get_corner_height(surfaceElement, i); + for (sint32 i = 0; i < 4; i += 1) { + sint32 cornerHeight = map_element_get_corner_height(surfaceElement, i); cornerHeight -= map_get_corner_height(height, style & MAP_ELEMENT_SLOPE_MASK, i); cost += MONEY(abs(cornerHeight) * 5 / 2, 0); }