Fix enabling map edge mode setting when void edge tiles were not flat

This commit is contained in:
Jonathan G Rennison
2024-01-13 13:33:01 +00:00
parent 8ae1587987
commit 55683c4350
3 changed files with 36 additions and 10 deletions

View File

@@ -474,8 +474,8 @@ void FixSlopes()
} }
} }
extern bool CheckMapEdgesAreWater(); extern bool CheckMapEdgesAreWater(bool allow_non_flat_void);
if (_settings_game.construction.map_edge_mode != 0 && !CheckMapEdgesAreWater()) { if (_settings_game.construction.map_edge_mode != 0 && !CheckMapEdgesAreWater(false)) {
_settings_game.construction.map_edge_mode = 0; _settings_game.construction.map_edge_mode = 0;
} }
} }

View File

@@ -1681,18 +1681,27 @@ static void UpdateFreeformEdges(int32_t new_value)
MarkWholeScreenDirty(); MarkWholeScreenDirty();
} }
bool CheckMapEdgesAreWater() bool CheckMapEdgesAreWater(bool allow_non_flat_void)
{ {
auto check_tile = [&](uint x, uint y) -> bool { auto check_tile = [&](uint x, uint y, Slope inner_edge) -> bool {
int h = 0; int h = 0;
Slope slope = GetTilePixelSlopeOutsideMap(x, y, &h); Slope slope = GetTilePixelSlopeOutsideMap(x, y, &h);
return slope == SLOPE_FLAT && h == 0; if (slope == SLOPE_FLAT && h == 0) return true;
if (allow_non_flat_void && h == 0 && (slope & inner_edge) == 0 && IsTileType(TileXY(x, y), MP_VOID)) return true;
return false;
}; };
for (uint x = 0; x <= MapMaxX(); x++) { check_tile( 0, 0, SLOPE_S);
if (!check_tile(x, 0) || !check_tile(x, MapMaxY())) return false; check_tile( 0, MapMaxY(), SLOPE_W);
check_tile(MapMaxX(), 0, SLOPE_E);
check_tile(MapMaxX(), MapMaxY(), SLOPE_N);
for (uint x = 1; x < MapMaxX(); x++) {
if (!check_tile(x, 0, SLOPE_SE)) return false;
if (!check_tile(x, MapMaxY(), SLOPE_NW)) return false;
} }
for (uint y = 1; y < MapMaxY(); y++) { for (uint y = 1; y < MapMaxY(); y++) {
if (!check_tile(0, y) || !check_tile(MapMaxX(), y)) return false; if (!check_tile(0, y, SLOPE_SW)) return false;
if (!check_tile(MapMaxX(), y, SLOPE_NE)) return false;
} }
return true; return true;
@@ -1702,7 +1711,7 @@ static bool CheckMapEdgeMode(int32_t &new_value)
{ {
if (_game_mode == GM_MENU || !_settings_game.construction.freeform_edges || new_value == 0) return true; if (_game_mode == GM_MENU || !_settings_game.construction.freeform_edges || new_value == 0) return true;
if (!CheckMapEdgesAreWater()) { if (!CheckMapEdgesAreWater(true)) {
ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR); ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
return false; return false;
} }
@@ -1710,6 +1719,22 @@ static bool CheckMapEdgeMode(int32_t &new_value)
return true; return true;
} }
static void MapEdgeModeChanged(int32_t new_value)
{
MarkAllViewportsDirty(new_value);
if (_game_mode == GM_MENU || !_settings_game.construction.freeform_edges || new_value == 0) return;
for (uint x = 0; x <= MapMaxX(); x++) {
SetTileHeight(TileXY(x, 0), 0);
SetTileHeight(TileXY(x, MapMaxY()), 0);
}
for (uint y = 1; y < MapMaxY(); y++) {
SetTileHeight(TileXY(0, y), 0);
SetTileHeight(TileXY(MapMaxX(), y), 0);
}
}
/** /**
* Changing the setting "allow multiple NewGRF sets" is not allowed * Changing the setting "allow multiple NewGRF sets" is not allowed
* if there are vehicles. * if there are vehicles.

View File

@@ -14,6 +14,7 @@ static bool CheckMaxHeightLevel(int32_t &new_value);
static bool CheckFreeformEdges(int32_t &new_value); static bool CheckFreeformEdges(int32_t &new_value);
static void UpdateFreeformEdges(int32_t new_value); static void UpdateFreeformEdges(int32_t new_value);
static bool CheckMapEdgeMode(int32_t &new_value); static bool CheckMapEdgeMode(int32_t &new_value);
static void MapEdgeModeChanged(int32_t new_value);
static void ClimateThresholdModeChanged(int32_t new_value); static void ClimateThresholdModeChanged(int32_t new_value);
static void PublicRoadsSettingChange(int32_t new_value); static void PublicRoadsSettingChange(int32_t new_value);
static void MarkAllViewportsDirty(int32_t new_value); static void MarkAllViewportsDirty(int32_t new_value);
@@ -944,7 +945,7 @@ str = STR_CONFIG_SETTING_MAP_EDGE_MODE
strhelp = STR_CONFIG_SETTING_MAP_EDGE_MODE_HELPTEXT strhelp = STR_CONFIG_SETTING_MAP_EDGE_MODE_HELPTEXT
strval = STR_CONFIG_SETTING_MAP_EDGE_MODE_DEFAULT strval = STR_CONFIG_SETTING_MAP_EDGE_MODE_DEFAULT
pre_cb = CheckMapEdgeMode pre_cb = CheckMapEdgeMode
post_cb = MarkAllViewportsDirty post_cb = MapEdgeModeChanged
cat = SC_ADVANCED cat = SC_ADVANCED
[SDT_VAR] [SDT_VAR]