Code cleanup and bug fix.

This commit is contained in:
Duan Tao
2019-01-09 10:12:00 +08:00
parent a2764d7b91
commit 730111993e
4 changed files with 16 additions and 7 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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) {

View File

@ -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<unit.getMaxHealth()) nameLabelText+=" ("+unit.health+")"
val city = selectedCity!!
var nameLabelText = city.name.tr()
if(city.health<city.getMaxHealth()) nameLabelText+=" ("+city.health+")"
unitNameLabel.setText(nameLabelText)
unitDescriptionTable.clear()
unitDescriptionTable.defaults().pad(2f).padRight(5f)
unitDescriptionTable.add("Strength".tr())
unitDescriptionTable.add(CityCombatant(city).getCityStrength().toString()).row()
selectedUnitHasChanged = true
}
else {