diff --git a/C7/Game.cs b/C7/Game.cs index 77a56514..526cd965 100644 --- a/C7/Game.cs +++ b/C7/Game.cs @@ -809,11 +809,11 @@ private void ProcessAction(string currentAction) { || terraform == null || !CurrentlySelectedUnit.canPerformTerraformAction(terraform)) return; - TerrainImprovement currentImprovement = CurrentlySelectedUnit.location.overlays.ImprovementAtLayer(terraform); - if (currentImprovement != null && terraform.Improvement.upgradesFrom != currentImprovement) { + TerrainImprovement replacementTarget = CurrentlySelectedUnit.location.overlays.GetReplacementTarget(terraform); + if (replacementTarget != null) { popupOverlay.ShowPopup( new ConfirmationPopup( - $"A previous terrain enhancement ({currentImprovement.key.Capitalize()}) will be replaced \nby this operation. Do you wish to continue?", + $"A previous terrain enhancement ({replacementTarget.key.Capitalize()}) will be replaced \nby this operation. Do you wish to continue?", "Continue.", "Cancel action.", () => { diff --git a/C7Engine/C7GameData/Tile.cs b/C7Engine/C7GameData/Tile.cs index de7deb92..53cf2d44 100644 --- a/C7Engine/C7GameData/Tile.cs +++ b/C7Engine/C7GameData/Tile.cs @@ -772,8 +772,19 @@ public TerrainImprovement ImprovementAtLayer(TerrainImprovement.Layer layer) { return ti; } - public TerrainImprovement ImprovementAtLayer(Terraform terraform) { - return terraform.Improvement == null ? null : ImprovementAtLayer(terraform.Improvement.layer); + // Returns an existing improvement that would be replaced by the given terraform. + // Returns null if there is no such improvement, + // or the new improvement upgrades from the existing one (upgrades don't count as replacements) + public TerrainImprovement GetReplacementTarget(Terraform terraform) { + var newImp = terraform.Improvement; + if (newImp == null) + return null; + + var current = ImprovementAtLayer(newImp.layer); + if (current == null) + return null; + + return newImp.upgradesFrom != current ? current : null; } public bool HasImprovement(TerrainImprovement improvement) {