You can actually Bombard! But ai cannot yet.

This commit is contained in:
Duan Tao 2019-01-08 19:55:35 +08:00
parent 7a17779bf4
commit 0f16a25cc6
5 changed files with 43 additions and 24 deletions

View File

@ -20,7 +20,7 @@ class UnCivGame : Game() {
val viewEntireMapForDebug = false val viewEntireMapForDebug = false
// For when you need to test something in an advanced game and don't have time to faff around // For when you need to test something in an advanced game and don't have time to faff around
val superchargedForDebug = false val superchargedForDebug = true
lateinit var worldScreen: WorldScreen lateinit var worldScreen: WorldScreen

View File

@ -85,6 +85,8 @@ class Battle(val gameInfo:GameInfo) {
unit.attacksThisTurn+=1 unit.attacksThisTurn+=1
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) {
attacker.city.attacksThisTurn ++
} }
// XP! // XP!

View File

@ -195,6 +195,7 @@ 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()

View File

@ -32,6 +32,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
val range = 2 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
@ -193,6 +194,7 @@ class CityInfo {
health = min(health + 20, getMaxHealth()) health = min(health + 20, getMaxHealth())
population.unassignExtraPopulation() population.unassignExtraPopulation()
} }
attacksThisTurn = 0
} }
fun destroyCity() { fun destroyCity() {

View File

@ -6,10 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.unciv.UnCivGame import com.unciv.UnCivGame
import com.unciv.logic.automation.UnitAutomation import com.unciv.logic.automation.UnitAutomation
import com.unciv.logic.battle.Battle import com.unciv.logic.battle.*
import com.unciv.logic.battle.BattleDamage
import com.unciv.logic.battle.ICombatant
import com.unciv.logic.battle.MapUnitCombatant
import com.unciv.models.gamebasics.tr import com.unciv.models.gamebasics.tr
import com.unciv.models.gamebasics.unit.UnitType import com.unciv.models.gamebasics.unit.UnitType
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
@ -31,13 +28,15 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
fun update() { fun update() {
val unitTable = worldScreen.bottomBar.unitTable val unitTable = worldScreen.bottomBar.unitTable
if (unitTable.selectedUnit == null val attacker : ICombatant?
|| unitTable.selectedUnit!!.type.isCivilian()){ if (unitTable.selectedUnit != null
hide() && !unitTable.selectedUnit!!.type.isCivilian()) {
return attacker = MapUnitCombatant(unitTable.selectedUnit!!)
} // no attacker } else if (unitTable.selectedCity != null) {
attacker = CityCombatant(unitTable.selectedCity!!)
val attacker = MapUnitCombatant(unitTable.selectedUnit!!) } else {
return // no attacker
}
if (worldScreen.tileMapHolder.selectedTile == null) return if (worldScreen.tileMapHolder.selectedTile == null) return
val selectedTile = worldScreen.tileMapHolder.selectedTile!! val selectedTile = worldScreen.tileMapHolder.selectedTile!!
@ -54,13 +53,15 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
simulateBattle(attacker, defender) simulateBattle(attacker, defender)
} }
fun simulateBattle(attacker: MapUnitCombatant, defender: ICombatant){ fun simulateBattle(attacker: ICombatant, defender: ICombatant){
clear() clear()
defaults().pad(5f) defaults().pad(5f)
println("debuglog simulateBattle")
val attackerNameWrapper = Table() val attackerNameWrapper = Table()
val attackerLabel = Label(attacker.getName(), skin) val attackerLabel = Label(attacker.getName(), skin)
attackerNameWrapper.add(UnitGroup(attacker.unit,25f)).padRight(5f) if(attacker is MapUnitCombatant)
attackerNameWrapper.add(UnitGroup(attacker.unit,25f)).padRight(5f)
attackerNameWrapper.add(attackerLabel) attackerNameWrapper.add(attackerLabel)
add(attackerNameWrapper) add(attackerNameWrapper)
@ -68,7 +69,6 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
val defenderLabel = Label(defender.getName(), skin) val defenderLabel = Label(defender.getName(), skin)
if(defender is MapUnitCombatant) if(defender is MapUnitCombatant)
defenderNameWrapper.add(UnitGroup(defender.unit,25f)).padRight(5f) defenderNameWrapper.add(UnitGroup(defender.unit,25f)).padRight(5f)
defenderNameWrapper.add(defenderLabel) defenderNameWrapper.add(defenderLabel)
add(defenderNameWrapper).row() add(defenderNameWrapper).row()
@ -126,19 +126,33 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
} }
row().pad(5f) row().pad(5f)
val attackButton = TextButton("Attack".tr(), skin).apply { color= Color.RED } val attackText : String = if (attacker is MapUnitCombatant) "Attack" else "Bombard"
val attackButton = TextButton(attackText.tr(), skin).apply { color= Color.RED }
attacker.unit.getDistanceToTiles() var attackableEnemy : UnitAutomation.AttackableTile? = null
var canAttack : Boolean = false
val attackableEnemy = UnitAutomation().getAttackableEnemies(attacker.unit, attacker.unit.getDistanceToTiles()) if (attacker is MapUnitCombatant) {
.firstOrNull{ it.tileToAttack == defender.getTile()} attacker.unit.getDistanceToTiles()
attackableEnemy = UnitAutomation().getAttackableEnemies(attacker.unit, attacker.unit.getDistanceToTiles())
.firstOrNull{ it.tileToAttack == defender.getTile()}
canAttack = (attacker.unit.canAttack() && attackableEnemy != null)
}
else if (attacker is CityCombatant)
{
canAttack = (attacker.city.attacksThisTurn == 0)
&& UnitAutomation().containsBombardableEnemy(defender.getTile(), attacker.city)
}
if(attackableEnemy==null || !attacker.unit.canAttack()) attackButton.disable() if(!canAttack) attackButton.disable()
else { else {
var attackSound = attacker.unit.baseUnit.attackSound //var attackSound = attacker.unit.baseUnit.attackSound
if(attackSound==null) attackSound="click" //if(attackSound==null) attackSound="click"
attackButton.onClick(attackSound) { //attackButton.onClick(attackSound) {
attacker.unit.moveToTile(attackableEnemy.tileToAttackFrom) attackButton.onClick {
if (attacker is MapUnitCombatant) {
attacker.unit.moveToTile(attackableEnemy!!.tileToAttackFrom)
}
battle.attack(attacker, defender) battle.attack(attacker, defender)
worldScreen.shouldUpdate=true worldScreen.shouldUpdate=true
} }