File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed
Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -809,11 +809,11 @@ private void ProcessAction(string currentAction) {
809809 || terraform == null || ! CurrentlySelectedUnit . canPerformTerraformAction ( terraform ) )
810810 return ;
811811
812- TerrainImprovement currentImprovement = CurrentlySelectedUnit . location . overlays . ImprovementAtLayer ( terraform ) ;
813- if ( currentImprovement != null && terraform . Improvement . upgradesFrom != currentImprovement ) {
812+ TerrainImprovement replacementTarget = CurrentlySelectedUnit . location . overlays . GetReplacementTarget ( terraform ) ;
813+ if ( replacementTarget != null ) {
814814 popupOverlay . ShowPopup (
815815 new ConfirmationPopup (
816- $ "A previous terrain enhancement ({ currentImprovement . key . Capitalize ( ) } ) will be replaced \n by this operation. Do you wish to continue?",
816+ $ "A previous terrain enhancement ({ replacementTarget . key . Capitalize ( ) } ) will be replaced \n by this operation. Do you wish to continue?",
817817 "Continue." ,
818818 "Cancel action." ,
819819 ( ) => {
Original file line number Diff line number Diff line change @@ -772,8 +772,19 @@ public TerrainImprovement ImprovementAtLayer(TerrainImprovement.Layer layer) {
772772 return ti ;
773773 }
774774
775- public TerrainImprovement ImprovementAtLayer ( Terraform terraform ) {
776- return terraform . Improvement == null ? null : ImprovementAtLayer ( terraform . Improvement . layer ) ;
775+ // Returns an existing improvement that would be replaced by the given terraform.
776+ // Returns null if there is no such improvement,
777+ // or the new improvement upgrades from the existing one (upgrades don't count as replacements)
778+ public TerrainImprovement GetReplacementTarget ( Terraform terraform ) {
779+ var newImp = terraform . Improvement ;
780+ if ( newImp == null )
781+ return null ;
782+
783+ var current = ImprovementAtLayer ( newImp . layer ) ;
784+ if ( current == null )
785+ return null ;
786+
787+ return newImp . upgradesFrom != current ? current : null ;
777788 }
778789
779790 public bool HasImprovement ( TerrainImprovement improvement ) {
You can’t perform that action at this time.
0 commit comments