From: "Enrico Weigelt, metux IT consult" <enrico.weig...@gr13.net>

---
 .../client/gui/dialog/SelectDestinationDialog.java | 32 ++++++++++++++--------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/src/net/sf/freecol/client/gui/dialog/SelectDestinationDialog.java 
b/src/net/sf/freecol/client/gui/dialog/SelectDestinationDialog.java
index d482f7837e9..e18fd0f8d3b 100644
--- a/src/net/sf/freecol/client/gui/dialog/SelectDestinationDialog.java
+++ b/src/net/sf/freecol/client/gui/dialog/SelectDestinationDialog.java
@@ -28,7 +28,6 @@ import java.util.Comparator;
 import java.util.List;
 import java.util.Map.Entry;
 import java.util.function.Function;
-import java.util.function.Predicate;
 import java.util.logging.Logger;
 
 import javax.swing.DefaultListModel;
@@ -135,6 +134,25 @@ public final class SelectDestinationDialog extends 
FreeColDialog<Location>
         }
 
         /**
+         * Test whether the unit - or in case of carrier, somebody on
+         * board - can learn from the natives
+         */
+        private boolean unitCanLearn(Unit unit) {
+            if (unit.getUnitChange(UnitChangeType.NATIVES) != null)
+                return true;
+
+            if (!unit.isCarrier())
+                return false;
+
+            for (Unit walk : unit.getUnits()) {
+                if (u.getUnitChange(UnitChangeType.NATIVES) != null)
+                    return true;
+            }
+
+            return false;
+        }
+
+        /**
          * Collected extra annotations of interest to a unit proposing to
          * visit a location.
          *
@@ -180,16 +198,8 @@ public final class SelectDestinationDialog extends 
FreeColDialog<Location>
                     // Show skill if relevant
                     IndianSettlement is = (IndianSettlement)loc;
                     UnitType sk = is.getLearnableSkill();
-                    if (sk != null) {
-                        final Predicate<Unit> upgradePred = u ->
-                            u.getUnitChange(UnitChangeType.NATIVES) != null;
-                        Unit up = (unit.isCarrier())
-                            ? find(unit.getUnits(), upgradePred)
-                            : (upgradePred.test(unit)) ? unit
-                            : null;
-                        if (up != null) {
-                            lb.add("[", Messages.getName(sk), "]");
-                        }
+                    if ((sk != null) && unitCanLearn(unit)) {
+                        lb.add("[", Messages.getName(sk), "]");
                     }
                 }
                 if (!goodsTypes.isEmpty()) {
-- 
2.11.0.rc0.7.gbe5a750


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Freecol-developers mailing list
Freecol-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freecol-developers

Reply via email to