mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-21 13:18:56 +07:00
Can now move multiple units to nearby tiles at the same turn
This commit is contained in:
@ -62,7 +62,7 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
|
|||||||
if (unit == null) return
|
if (unit == null) return
|
||||||
thread {
|
thread {
|
||||||
val canUnitReachTile = unit.movement.canReach(tileGroup.tileInfo)
|
val canUnitReachTile = unit.movement.canReach(tileGroup.tileInfo)
|
||||||
if (canUnitReachTile) moveUnitToTargetTile(unit, tileGroup.tileInfo)
|
if (canUnitReachTile) moveUnitToTargetTile(listOf(unit), tileGroup.tileInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -111,8 +111,17 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun moveUnitToTargetTile(selectedUnit: MapUnit, targetTile:TileInfo) {
|
fun moveUnitToTargetTile(selectedUnits: List<MapUnit>, targetTile:TileInfo) {
|
||||||
// this can take a long time, because of the unit-to-tile calculation needed, so we put it in a different thread
|
// this can take a long time, because of the unit-to-tile calculation needed, so we put it in a different thread
|
||||||
|
// THIS PART IS REALLY ANNOYING
|
||||||
|
// So lets say you have 2 units you want to move in the same direction, right
|
||||||
|
// But if the first one gets there, and the second one was PLANNING on going there, then now it can't and has to rethink
|
||||||
|
// So basically, THE UNIT MOVES HAVE TO BE SEQUENTIAL and not concurrent which is a BITCH
|
||||||
|
// So we do this one at a time by getting the list of units to move, MOVING ONE OF THEM with all the yukky threading,
|
||||||
|
// and then calling the function again but without the unit that moved.
|
||||||
|
|
||||||
|
val selectedUnit = selectedUnits.first()
|
||||||
|
|
||||||
thread(name = "TileToMoveTo") {
|
thread(name = "TileToMoveTo") {
|
||||||
// these are the heavy parts, finding where we want to go
|
// these are the heavy parts, finding where we want to go
|
||||||
// Since this runs in a different thread, even if we check movement.canReach()
|
// Since this runs in a different thread, even if we check movement.canReach()
|
||||||
@ -139,8 +148,11 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
|
|||||||
if (selectedUnit.currentMovement > 0) worldScreen.bottomUnitTable.selectUnit(selectedUnit)
|
if (selectedUnit.currentMovement > 0) worldScreen.bottomUnitTable.selectUnit(selectedUnit)
|
||||||
|
|
||||||
worldScreen.shouldUpdate = true
|
worldScreen.shouldUpdate = true
|
||||||
unitActionOverlay?.remove()
|
if (selectedUnits.size > 1) { // We have more tiles to move
|
||||||
} catch (e: Exception) {}
|
moveUnitToTargetTile(selectedUnits.subList(1, selectedUnits.size), targetTile)
|
||||||
|
} else unitActionOverlay?.remove() //we're done here
|
||||||
|
} catch (e: Exception) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -241,15 +253,15 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
|
|||||||
unitIcon.y = size - unitIcon.height
|
unitIcon.y = size - unitIcon.height
|
||||||
moveHereButton.addActor(unitIcon)
|
moveHereButton.addActor(unitIcon)
|
||||||
|
|
||||||
for (unit in dto.unitToTurnsToDestination.keys) {
|
val unitsThatCanMove = dto.unitToTurnsToDestination.keys.filter { it.currentMovement > 0 }
|
||||||
if (unit.currentMovement > 0)
|
if(unitsThatCanMove.isEmpty()) moveHereButton.color.a = 0.5f
|
||||||
moveHereButton.onClick(UncivSound.Silent) {
|
else {
|
||||||
UncivGame.Current.settings.addCompletedTutorialTask("Move unit")
|
moveHereButton.onClick(UncivSound.Silent) {
|
||||||
if (unit.type.isAirUnit())
|
UncivGame.Current.settings.addCompletedTutorialTask("Move unit")
|
||||||
UncivGame.Current.settings.addCompletedTutorialTask("Move an air unit")
|
if (unitsThatCanMove.any { it.type.isAirUnit() })
|
||||||
moveUnitToTargetTile(unit, dto.tileInfo)
|
UncivGame.Current.settings.addCompletedTutorialTask("Move an air unit")
|
||||||
}
|
moveUnitToTargetTile(unitsThatCanMove, dto.tileInfo)
|
||||||
else moveHereButton.color.a = 0.5f
|
}
|
||||||
}
|
}
|
||||||
return moveHereButton
|
return moveHereButton
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user