From dd8acda4c049a8de9592a5a75e34d01c2c30df52 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 13 Apr 2020 23:01:20 +0300 Subject: [PATCH] Resolved #2406 - land units prefer to be generated in land tiles --- core/src/com/unciv/logic/map/TileMap.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/com/unciv/logic/map/TileMap.kt b/core/src/com/unciv/logic/map/TileMap.kt index c3400fa2d3..a2c6fcec99 100644 --- a/core/src/com/unciv/logic/map/TileMap.kt +++ b/core/src/com/unciv/logic/map/TileMap.kt @@ -144,7 +144,9 @@ class TileMap { var tryCount = 0 var potentialCandidates = getPassableNeighbours(currentTile) while (unitToPlaceTile == null && tryCount++ < 10) { - unitToPlaceTile = potentialCandidates.firstOrNull { unit.movement.canMoveTo(it) } + unitToPlaceTile = potentialCandidates + .sortedByDescending { if(unit.type.isLandUnit()) it.isLand else true } // Land units should prefer to go into land tiles + .firstOrNull { unit.movement.canMoveTo(it) } if (unitToPlaceTile != null) continue // if it's not found yet, let's check their neighbours val newPotentialCandidates = mutableSetOf()