mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 14:24:43 -04:00
Code cleanup 2.
This commit is contained in:
parent
57dce317ea
commit
4e77edcec0
@ -281,9 +281,9 @@ class UnitAutomation{
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun tryBombardEnemy(city: CityInfo): Boolean {
|
fun tryBombardEnemy(city: CityInfo): Boolean {
|
||||||
|
if (!city.attackedThisTurn) {
|
||||||
val target = chooseBombardTarget(city)
|
val target = chooseBombardTarget(city)
|
||||||
if (target == null) return false
|
if (target == null) return false
|
||||||
if (city.canAttack()) {
|
|
||||||
val enemy = Battle(city.civInfo.gameInfo).getMapCombatantOfTile(target)!!
|
val enemy = Battle(city.civInfo.gameInfo).getMapCombatantOfTile(target)!!
|
||||||
Battle(city.civInfo.gameInfo).attack(CityCombatant(city), enemy)
|
Battle(city.civInfo.gameInfo).attack(CityCombatant(city), enemy)
|
||||||
return true
|
return true
|
||||||
|
@ -89,7 +89,7 @@ class Battle(val gameInfo:GameInfo) {
|
|||||||
if(unit.isFortified() || unit.action=="Sleep")
|
if(unit.isFortified() || unit.action=="Sleep")
|
||||||
attacker.unit.action=null // but not, for instance, if it's Set Up - then it should definitely keep the action!
|
attacker.unit.action=null // but not, for instance, if it's Set Up - then it should definitely keep the action!
|
||||||
} else if (attacker is CityCombatant) {
|
} else if (attacker is CityCombatant) {
|
||||||
attacker.city.attacksThisTurn ++
|
attacker.city.attackedThisTurn = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// XP!
|
// XP!
|
||||||
|
@ -195,7 +195,6 @@ class BattleDamage{
|
|||||||
|
|
||||||
fun calculateDamageToAttacker(attacker: ICombatant, defender: ICombatant): Int {
|
fun calculateDamageToAttacker(attacker: ICombatant, defender: ICombatant): Int {
|
||||||
if(attacker.isRanged()) return 0
|
if(attacker.isRanged()) return 0
|
||||||
if(attacker is CityCombatant) return 0
|
|
||||||
if(defender.getUnitType().isCivilian()) return 0
|
if(defender.getUnitType().isCivilian()) return 0
|
||||||
val ratio = getDefendingStrength(attacker,defender) / getAttackingStrength(attacker,defender)
|
val ratio = getDefendingStrength(attacker,defender) / getAttackingStrength(attacker,defender)
|
||||||
return (ratio * 30 * getHealthDependantDamageRatio(defender)).toInt()
|
return (ratio * 30 * getHealthDependantDamageRatio(defender)).toInt()
|
||||||
|
@ -14,6 +14,7 @@ class CityCombatant(val city: CityInfo) : ICombatant {
|
|||||||
override fun isDefeated(): Boolean = city.health==1
|
override fun isDefeated(): Boolean = city.health==1
|
||||||
override fun isInvisible(): Boolean = false
|
override fun isInvisible(): Boolean = false
|
||||||
override fun getCivInfo(): CivilizationInfo = city.civInfo
|
override fun getCivInfo(): CivilizationInfo = city.civInfo
|
||||||
|
override fun canAttack(): Boolean = (!city.attackedThisTurn)
|
||||||
|
|
||||||
override fun takeDamage(damage: Int) {
|
override fun takeDamage(damage: Int) {
|
||||||
city.health -= damage
|
city.health -= damage
|
||||||
|
@ -17,6 +17,7 @@ interface ICombatant{
|
|||||||
fun getTile(): TileInfo
|
fun getTile(): TileInfo
|
||||||
fun isInvisible(): Boolean
|
fun isInvisible(): Boolean
|
||||||
fun getCivInfo(): CivilizationInfo
|
fun getCivInfo(): CivilizationInfo
|
||||||
|
fun canAttack(): Boolean
|
||||||
|
|
||||||
fun isMelee(): Boolean {
|
fun isMelee(): Boolean {
|
||||||
return this.getUnitType().isMelee()
|
return this.getUnitType().isMelee()
|
||||||
|
@ -13,6 +13,7 @@ class MapUnitCombatant(val unit: MapUnit) : ICombatant {
|
|||||||
override fun isDefeated(): Boolean = unit.health <= 0
|
override fun isDefeated(): Boolean = unit.health <= 0
|
||||||
override fun isInvisible(): Boolean = unit.isInvisible()
|
override fun isInvisible(): Boolean = unit.isInvisible()
|
||||||
override fun getCivInfo(): CivilizationInfo = unit.civInfo
|
override fun getCivInfo(): CivilizationInfo = unit.civInfo
|
||||||
|
override fun canAttack(): Boolean = unit.canAttack()
|
||||||
|
|
||||||
override fun takeDamage(damage: Int) {
|
override fun takeDamage(damage: Int) {
|
||||||
unit.health -= damage
|
unit.health -= damage
|
||||||
|
@ -18,6 +18,7 @@ class CityInfo {
|
|||||||
@Transient lateinit var civInfo: CivilizationInfo
|
@Transient lateinit var civInfo: CivilizationInfo
|
||||||
@Transient var isConnectedToCapital = false
|
@Transient var isConnectedToCapital = false
|
||||||
@Transient lateinit var ccenterTile:TileInfo // 'cached' for better performance
|
@Transient lateinit var ccenterTile:TileInfo // 'cached' for better performance
|
||||||
|
@Transient val range = 2
|
||||||
|
|
||||||
var location: Vector2 = Vector2.Zero
|
var location: Vector2 = Vector2.Zero
|
||||||
var name: String = ""
|
var name: String = ""
|
||||||
@ -32,8 +33,7 @@ class CityInfo {
|
|||||||
var tiles = HashSet<Vector2>()
|
var tiles = HashSet<Vector2>()
|
||||||
var workedTiles = HashSet<Vector2>()
|
var workedTiles = HashSet<Vector2>()
|
||||||
var isBeingRazed = false
|
var isBeingRazed = false
|
||||||
var attacksThisTurn = 0
|
var attackedThisTurn = false
|
||||||
val range = 2
|
|
||||||
|
|
||||||
constructor() // for json parsing, we need to have a default constructor
|
constructor() // for json parsing, we need to have a default constructor
|
||||||
constructor(civInfo: CivilizationInfo, cityLocation: Vector2) {
|
constructor(civInfo: CivilizationInfo, cityLocation: Vector2) {
|
||||||
@ -85,7 +85,7 @@ class CityInfo {
|
|||||||
toReturn.workedTiles = workedTiles
|
toReturn.workedTiles = workedTiles
|
||||||
toReturn.isBeingRazed=isBeingRazed
|
toReturn.isBeingRazed=isBeingRazed
|
||||||
toReturn.isConnectedToCapital = isConnectedToCapital
|
toReturn.isConnectedToCapital = isConnectedToCapital
|
||||||
toReturn.attacksThisTurn = attacksThisTurn
|
toReturn.attackedThisTurn = attackedThisTurn
|
||||||
return toReturn
|
return toReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ class CityInfo {
|
|||||||
health = min(health + 20, getMaxHealth())
|
health = min(health + 20, getMaxHealth())
|
||||||
population.unassignExtraPopulation()
|
population.unassignExtraPopulation()
|
||||||
}
|
}
|
||||||
attacksThisTurn = 0
|
attackedThisTurn = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun destroyCity() {
|
fun destroyCity() {
|
||||||
@ -236,8 +236,5 @@ class CityInfo {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun canAttack(): Boolean {
|
|
||||||
return (attacksThisTurn == 0)
|
|
||||||
}
|
|
||||||
//endregion
|
//endregion
|
||||||
}
|
}
|
@ -130,18 +130,19 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
|
|||||||
val attackButton = TextButton(attackText.tr(), skin).apply { color= Color.RED }
|
val attackButton = TextButton(attackText.tr(), skin).apply { color= Color.RED }
|
||||||
|
|
||||||
var attackableEnemy : UnitAutomation.AttackableTile? = null
|
var attackableEnemy : UnitAutomation.AttackableTile? = null
|
||||||
var canAttack : Boolean = false
|
var canAttack : Boolean = attacker.canAttack()
|
||||||
|
|
||||||
|
if (canAttack) {
|
||||||
if (attacker is MapUnitCombatant) {
|
if (attacker is MapUnitCombatant) {
|
||||||
attacker.unit.getDistanceToTiles()
|
attacker.unit.getDistanceToTiles()
|
||||||
attackableEnemy = UnitAutomation().getAttackableEnemies(attacker.unit, attacker.unit.getDistanceToTiles())
|
attackableEnemy = UnitAutomation().getAttackableEnemies(attacker.unit, attacker.unit.getDistanceToTiles())
|
||||||
.firstOrNull{ it.tileToAttack == defender.getTile()}
|
.firstOrNull{ it.tileToAttack == defender.getTile()}
|
||||||
canAttack = (attacker.unit.canAttack() && attackableEnemy != null)
|
canAttack = attackableEnemy != null
|
||||||
}
|
}
|
||||||
else if (attacker is CityCombatant)
|
else if (attacker is CityCombatant)
|
||||||
{
|
{
|
||||||
canAttack = (attacker.city.canAttack())
|
canAttack = UnitAutomation().getBombardTargets(attacker.city).contains(defender.getTile())
|
||||||
&& UnitAutomation().getBombardTargets(attacker.city).contains(defender.getTile())
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!canAttack) attackButton.disable()
|
if(!canAttack) attackButton.disable()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user