From e7c12f2ad4fc5dc3cf7d7419c86a46b42f705841 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 23 Jan 2022 01:18:49 +0000 Subject: [PATCH] Fix terraforming not resetting ground type for use land ground objects --- src/object_cmd.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp index f59a99f6bb..026ae8b922 100644 --- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -1146,10 +1146,12 @@ static CommandCost TerraformTile_Object(TileIndex tile, DoCommandFlag flags, int } else if (AutoslopeEnabled() && type != OBJECT_TRANSMITTER && type != OBJECT_LIGHTHOUSE) { const ObjectSpec *spec = ObjectSpec::Get(type); - if (flags & DC_EXEC) { - SetShouldObjectHaveNoFoundation(tile, tileh_new, type, spec); - if (GetObjectGroundType(tile) == OBJECT_GROUND_SHORE) SetObjectGroundTypeDensity(tile, OBJECT_GROUND_GRASS, 0); - } + auto pre_success_checks = [&]() { + if (flags & DC_EXEC) { + SetShouldObjectHaveNoFoundation(tile, tileh_new, type, spec); + if (spec->ctrl_flags & OBJECT_CTRL_FLAG_USE_LAND_GROUND) SetObjectGroundTypeDensity(tile, OBJECT_GROUND_GRASS, 0); + } + }; /* Behaviour: * - Both new and old slope must not be steep. @@ -1167,9 +1169,13 @@ static CommandCost TerraformTile_Object(TileIndex tile, DoCommandFlag flags, int if (HasBit(spec->callback_mask, CBM_OBJ_AUTOSLOPE)) { /* If the callback fails, allow autoslope. */ uint16 res = GetObjectCallback(CBID_OBJECT_AUTOSLOPE, 0, 0, spec, Object::GetByTile(tile), tile); - if (res == CALLBACK_FAILED || !ConvertBooleanCallback(spec->grf_prop.grffile, CBID_OBJECT_AUTOSLOPE, res)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + if (res == CALLBACK_FAILED || !ConvertBooleanCallback(spec->grf_prop.grffile, CBID_OBJECT_AUTOSLOPE, res)) { + pre_success_checks(); + return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + } } else if (spec->enabled) { /* allow autoslope */ + pre_success_checks(); return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); } }