Merge pull request #347 from ninjatao/place_new_unit

prefer to place new land units on land.
This commit is contained in:
yairm210 2018-12-14 12:05:41 +02:00 committed by GitHub
commit b3c79ec299
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -74,10 +74,12 @@ 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) {
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.
// 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()