Improvements.

This commit is contained in:
Duan Tao 2018-12-14 16:35:10 +08:00
parent c8ec2bcbb7
commit b1d2b13ddd

View File

@ -75,21 +75,16 @@ class TileMap {
val unit = GameBasics.Units[unitName]!!.getMapUnit() val unit = GameBasics.Units[unitName]!!.getMapUnit()
val tilesInDistance = getTilesInDistance(position, 2) val tilesInDistance = getTilesInDistance(position, 2)
unit.assignOwner(civInfo) // both the civ name and actual civ need to be in here in order to calculate the canMoveTo...Darn unit.assignOwner(civInfo) // both the civ name and actual civ need to be in here in order to calculate the canMoveTo...Darn
val unitToPlaceTile = tilesInDistance.firstOrNull { unit.canMoveTo(it) && (unit.type.isWaterUnit() || it.isLand()) } var unitToPlaceTile = tilesInDistance.firstOrNull { unit.canMoveTo(it) && (unit.type.isWaterUnit() || it.isLand()) }
if (unitToPlaceTile==null)
unitToPlaceTile = tilesInDistance.firstOrNull { unit.canMoveTo(it) }
if(unitToPlaceTile!=null) { //see if a land unit can be placed on land. if impossible, put it on water. if(unitToPlaceTile!=null) { //see if a land unit can be placed on land. if impossible, put it on water.
// only once we know the unit can be placed do we add it to the civ's unit list // only once we know the unit can be placed do we add it to the civ's unit list
unit.putInTile(unitToPlaceTile) unit.putInTile(unitToPlaceTile)
unit.currentMovement = unit.getMaxMovement().toFloat() unit.currentMovement = unit.getMaxMovement().toFloat()
} }
else { else civInfo.removeUnit(unit) // since we added it to the civ units in the previous assignOwner
val unitToPlaceTile = tilesInDistance.firstOrNull { unit.canMoveTo(it) }
if(unitToPlaceTile!=null) {
// only once we know the unit can be placed do we add it to the civ's unit list
unit.putInTile(unitToPlaceTile)
unit.currentMovement = unit.getMaxMovement().toFloat()
}
else civInfo.removeUnit(unit) // since we added it to the civ units in the previous assignOwner
}
return unit return unit
} }