Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions C7/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
() => {
Expand Down
15 changes: 13 additions & 2 deletions C7Engine/C7GameData/Tile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down