prefer to place new land units on land.
This commit is contained in:
parent
042e295611
commit
c8ec2bcbb7
1 changed files with 11 additions and 4 deletions
|
@ -74,15 +74,22 @@ class TileMap {
|
|||
fun placeUnitNearTile(position: Vector2, unitName: String, civInfo: CivilizationInfo): MapUnit {
|
||||
val unit = GameBasics.Units[unitName]!!.getMapUnit()
|
||||
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
|
||||
val unitToPlaceTile = tilesInDistance.firstOrNull { unit.canMoveTo(it) }
|
||||
if(unitToPlaceTile!=null) {
|
||||
val unitToPlaceTile = tilesInDistance.firstOrNull { unit.canMoveTo(it) && (unit.type.isWaterUnit() || it.isLand()) }
|
||||
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
|
||||
unit.putInTile(unitToPlaceTile)
|
||||
unit.currentMovement = unit.getMaxMovement().toFloat()
|
||||
}
|
||||
else civInfo.removeUnit(unit) // since we added it to the civ units in the previous assignOwner
|
||||
else {
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue