mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-30 06:39:17 +07:00
Code cleanup and bug fix.
This commit is contained in:
@ -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
|
||||
|
@ -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
|
||||
}
|
@ -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) {
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user