mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 21:35:14 -04:00
You can actually Bombard! But ai cannot yet.
This commit is contained in:
parent
7a17779bf4
commit
0f16a25cc6
@ -20,7 +20,7 @@ class UnCivGame : Game() {
|
||||
val viewEntireMapForDebug = false
|
||||
|
||||
// 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
|
||||
|
||||
|
@ -85,6 +85,8 @@ class Battle(val gameInfo:GameInfo) {
|
||||
unit.attacksThisTurn+=1
|
||||
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!
|
||||
} else if (attacker is CityCombatant) {
|
||||
attacker.city.attacksThisTurn ++
|
||||
}
|
||||
|
||||
// XP!
|
||||
|
@ -195,6 +195,7 @@ class BattleDamage{
|
||||
|
||||
fun calculateDamageToAttacker(attacker: ICombatant, defender: ICombatant): Int {
|
||||
if(attacker.isRanged()) return 0
|
||||
if(attacker is CityCombatant) return 0
|
||||
if(defender.getUnitType().isCivilian()) return 0
|
||||
val ratio = getDefendingStrength(attacker,defender) / getAttackingStrength(attacker,defender)
|
||||
return (ratio * 30 * getHealthDependantDamageRatio(defender)).toInt()
|
||||
|
@ -32,6 +32,7 @@ class CityInfo {
|
||||
var tiles = HashSet<Vector2>()
|
||||
var workedTiles = HashSet<Vector2>()
|
||||
var isBeingRazed = false
|
||||
var attacksThisTurn = 0
|
||||
val range = 2
|
||||
|
||||
constructor() // for json parsing, we need to have a default constructor
|
||||
@ -193,6 +194,7 @@ class CityInfo {
|
||||
health = min(health + 20, getMaxHealth())
|
||||
population.unassignExtraPopulation()
|
||||
}
|
||||
attacksThisTurn = 0
|
||||
}
|
||||
|
||||
fun destroyCity() {
|
||||
|
@ -6,10 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.unciv.UnCivGame
|
||||
import com.unciv.logic.automation.UnitAutomation
|
||||
import com.unciv.logic.battle.Battle
|
||||
import com.unciv.logic.battle.BattleDamage
|
||||
import com.unciv.logic.battle.ICombatant
|
||||
import com.unciv.logic.battle.MapUnitCombatant
|
||||
import com.unciv.logic.battle.*
|
||||
import com.unciv.models.gamebasics.tr
|
||||
import com.unciv.models.gamebasics.unit.UnitType
|
||||
import com.unciv.ui.utils.*
|
||||
@ -31,13 +28,15 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
|
||||
|
||||
fun update() {
|
||||
val unitTable = worldScreen.bottomBar.unitTable
|
||||
if (unitTable.selectedUnit == null
|
||||
|| unitTable.selectedUnit!!.type.isCivilian()){
|
||||
hide()
|
||||
return
|
||||
} // no attacker
|
||||
|
||||
val attacker = MapUnitCombatant(unitTable.selectedUnit!!)
|
||||
val attacker : ICombatant?
|
||||
if (unitTable.selectedUnit != null
|
||||
&& !unitTable.selectedUnit!!.type.isCivilian()) {
|
||||
attacker = MapUnitCombatant(unitTable.selectedUnit!!)
|
||||
} else if (unitTable.selectedCity != null) {
|
||||
attacker = CityCombatant(unitTable.selectedCity!!)
|
||||
} else {
|
||||
return // no attacker
|
||||
}
|
||||
|
||||
if (worldScreen.tileMapHolder.selectedTile == null) return
|
||||
val selectedTile = worldScreen.tileMapHolder.selectedTile!!
|
||||
@ -54,13 +53,15 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
|
||||
simulateBattle(attacker, defender)
|
||||
}
|
||||
|
||||
fun simulateBattle(attacker: MapUnitCombatant, defender: ICombatant){
|
||||
fun simulateBattle(attacker: ICombatant, defender: ICombatant){
|
||||
clear()
|
||||
defaults().pad(5f)
|
||||
println("debuglog simulateBattle")
|
||||
|
||||
val attackerNameWrapper = Table()
|
||||
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)
|
||||
add(attackerNameWrapper)
|
||||
|
||||
@ -68,7 +69,6 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
|
||||
val defenderLabel = Label(defender.getName(), skin)
|
||||
if(defender is MapUnitCombatant)
|
||||
defenderNameWrapper.add(UnitGroup(defender.unit,25f)).padRight(5f)
|
||||
|
||||
defenderNameWrapper.add(defenderLabel)
|
||||
add(defenderNameWrapper).row()
|
||||
|
||||
@ -126,19 +126,33 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
|
||||
}
|
||||
|
||||
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())
|
||||
.firstOrNull{ it.tileToAttack == defender.getTile()}
|
||||
if (attacker is MapUnitCombatant) {
|
||||
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 {
|
||||
var attackSound = attacker.unit.baseUnit.attackSound
|
||||
if(attackSound==null) attackSound="click"
|
||||
attackButton.onClick(attackSound) {
|
||||
attacker.unit.moveToTile(attackableEnemy.tileToAttackFrom)
|
||||
//var attackSound = attacker.unit.baseUnit.attackSound
|
||||
//if(attackSound==null) attackSound="click"
|
||||
//attackButton.onClick(attackSound) {
|
||||
attackButton.onClick {
|
||||
if (attacker is MapUnitCombatant) {
|
||||
attacker.unit.moveToTile(attackableEnemy!!.tileToAttackFrom)
|
||||
}
|
||||
battle.attack(attacker, defender)
|
||||
worldScreen.shouldUpdate=true
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user