From 730111993e632145842bdcded1dd2bd4ed2b0406 Mon Sep 17 00:00:00 2001 From: Duan Tao Date: Wed, 9 Jan 2019 10:12:00 +0800 Subject: [PATCH] Code cleanup and bug fix. --- core/src/com/unciv/logic/automation/UnitAutomation.kt | 2 +- core/src/com/unciv/logic/city/CityInfo.kt | 5 +++++ .../com/unciv/ui/worldscreen/bottombar/BattleTable.kt | 6 +++--- core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt | 10 +++++++--- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/core/src/com/unciv/logic/automation/UnitAutomation.kt b/core/src/com/unciv/logic/automation/UnitAutomation.kt index 64aca85956..dcb439c8ae 100644 --- a/core/src/com/unciv/logic/automation/UnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/UnitAutomation.kt @@ -289,7 +289,7 @@ class UnitAutomation{ fun tryBombardEnemy(city: CityInfo): Boolean { val target = chooseBombardTarget(city) if (target == null) return false - if (city.attacksThisTurn == 0) { + if (city.canAttack()) { val enemy = Battle(city.civInfo.gameInfo).getMapCombatantOfTile(target)!! Battle(city.civInfo.gameInfo).attack(CityCombatant(city), enemy) return true diff --git a/core/src/com/unciv/logic/city/CityInfo.kt b/core/src/com/unciv/logic/city/CityInfo.kt index 84cbf274ae..9b1b59cfcd 100644 --- a/core/src/com/unciv/logic/city/CityInfo.kt +++ b/core/src/com/unciv/logic/city/CityInfo.kt @@ -85,6 +85,7 @@ class CityInfo { toReturn.workedTiles = workedTiles toReturn.isBeingRazed=isBeingRazed toReturn.isConnectedToCapital = isConnectedToCapital + toReturn.attacksThisTurn = attacksThisTurn return toReturn } @@ -234,5 +235,9 @@ class CityInfo { } return false } + + fun canAttack(): Boolean { + return (attacksThisTurn == 0) + } //endregion } \ No newline at end of file diff --git a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt index 6b1091e78e..cda890b46d 100644 --- a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt +++ b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt @@ -140,14 +140,14 @@ class BattleTable(val worldScreen: WorldScreen): Table() { } else if (attacker is CityCombatant) { - canAttack = (attacker.city.attacksThisTurn == 0) - && UnitAutomation().containsBombardableEnemy(defender.getTile(), attacker.city) + canAttack = (attacker.city.canAttack()) + && UnitAutomation().getBombardTargets(attacker.city).contains(defender.getTile()) } if(!canAttack) attackButton.disable() else { //var attackSound = attacker.unit.baseUnit.attackSound - //if(attackSound==null) attackSound="click" + //if(attackSound==null) attackSound="click"` //attackButton.onClick(attackSound) { attackButton.onClick { if (attacker is MapUnitCombatant) { diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt index 831dae084b..416c44d32a 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt @@ -3,6 +3,7 @@ package com.unciv.ui.worldscreen.unit import com.badlogic.gdx.scenes.scene2d.ui.Image import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.Table +import com.unciv.logic.battle.CityCombatant import com.unciv.logic.city.CityInfo import com.unciv.logic.map.MapUnit import com.unciv.logic.map.TileInfo @@ -103,13 +104,16 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ } else if (selectedCity != null) { separator.isVisible=true - val unit = selectedCity!! - var nameLabelText = unit.name.tr() - if(unit.health