Console: city addtile <cityName> takes an optional [radius] parameter

This commit is contained in:
yairm210
2024-06-09 19:34:38 +03:00
parent d61df7fe51
commit b0c70e6ec8
2 changed files with 7 additions and 3 deletions

View File

@ -40,13 +40,17 @@ internal class ConsoleCityCommands : ConsoleCommandNode {
DevConsoleResponse.OK
},
"addtile" to ConsoleAction("city addtile <cityName>") { console, params ->
"addtile" to ConsoleAction("city addtile <cityName> [radius]") { console, params ->
val selectedTile = console.getSelectedTile()
val city = console.getCity(params[0])
if (selectedTile.neighbors.none { it.getCity() == city })
throw ConsoleErrorException("Tile is not adjacent to any tile already owned by the city")
if (selectedTile.isCityCenter()) throw ConsoleErrorException("Cannot transfer city center")
city.expansion.takeOwnership(selectedTile)
val radius = params.getOrNull(1)?.toInt() ?: 0
for (tile in selectedTile.getTilesInDistance(radius)) {
if (tile.getCity() != city && !tile.isCityCenter())
city.expansion.takeOwnership(tile)
}
DevConsoleResponse.OK
},

View File

@ -163,7 +163,7 @@ class DevConsolePopup(val screen: WorldScreen) : Popup(screen) {
}
private fun handleCommand(): DevConsoleResponse {
val params = textField.text.splitToCliInput()
val params = textField.text.trim().splitToCliInput()
return commandRoot.handle(this, params)
}