mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-19 20:28:56 +07:00
Added Set Up action for siege units that require it
Unit cannot attack twice a turn even if it can "move after attacking"
This commit is contained in:
@ -37,6 +37,7 @@
|
||||
},
|
||||
{
|
||||
name:"Barbarians",
|
||||
RGB:[200,200,200]
|
||||
RGB:[200,200,200],
|
||||
cities:["Barbar"] // this is to deal with a specific bug where they could capture settlers. They can't anymore and this should be removed by, say, 11.7.18
|
||||
}
|
||||
]
|
@ -86,6 +86,9 @@ class UnitAutomation{
|
||||
val enemyTileToAttack = getAttackableEnemies(unit).firstOrNull()
|
||||
|
||||
if (enemyTileToAttack != null) {
|
||||
val setupAction = UnitActions().getUnitActions(unit, UnCivGame.Current.worldScreen!!).firstOrNull{ it.name == "Set up" }
|
||||
if(setupAction!=null) setupAction.action()
|
||||
|
||||
val enemy = Battle().getMapCombatantOfTile(enemyTileToAttack)!!
|
||||
val damageToAttacker = Battle(unit.civInfo.gameInfo).calculateDamageToAttacker(MapUnitCombatant(unit), enemy)
|
||||
|
||||
|
@ -141,7 +141,6 @@ class Battle(val gameInfo:GameInfo=UnCivGame.Current.gameInfo) {
|
||||
}
|
||||
|
||||
postBattleAction(attacker,defender,attackedTile)
|
||||
|
||||
}
|
||||
|
||||
private fun postBattleAction(attacker: ICombatant, defender: ICombatant, attackedTile:TileInfo){
|
||||
@ -174,6 +173,7 @@ class Battle(val gameInfo:GameInfo=UnCivGame.Current.gameInfo) {
|
||||
if (attacker.unit.hasUnique("Can move after attacking"))
|
||||
attacker.unit.currentMovement = max(0f, attacker.unit.currentMovement - 1)
|
||||
else attacker.unit.currentMovement = 0f
|
||||
attacker.unit.attacksThisTurn+=1
|
||||
attacker.unit.action=null // for instance, if it was fortified
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ class MapUnit {
|
||||
var currentMovement: Float = 0f
|
||||
var health:Int = 100
|
||||
var action: String? = null // work, automation, fortifying, I dunno what.
|
||||
var attacksThisTurn = 0
|
||||
|
||||
fun getBaseUnit(): Unit = GameBasics.Units[name]!!
|
||||
fun getMovementString(): String = DecimalFormat("0.#").format(currentMovement.toDouble()) + "/" + maxMovement
|
||||
@ -169,4 +170,11 @@ class MapUnit {
|
||||
if (isFortified()) return false
|
||||
return true
|
||||
}
|
||||
|
||||
fun canAttack(): Boolean {
|
||||
if(currentMovement==0f) return false
|
||||
if(attacksThisTurn>0) return false
|
||||
if(hasUnique("Must set up to ranged attack") && action != "Set Up") return false
|
||||
return true
|
||||
}
|
||||
}
|
@ -119,7 +119,7 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
|
||||
val attackerCanReachDefender = UnitAutomation().getAttackableEnemies(attacker.unit)
|
||||
.contains(defender.getTile())
|
||||
|
||||
if(!attackerCanReachDefender || attacker.unit.currentMovement==0f) attackButton.disable()
|
||||
if(!attackerCanReachDefender || !attacker.unit.canAttack()) attackButton.disable()
|
||||
else {
|
||||
attackButton.addClickListener {
|
||||
if(attacker.isMelee())
|
||||
|
@ -2,13 +2,14 @@ package com.unciv.ui.worldscreen.unit
|
||||
|
||||
import com.unciv.logic.automation.WorkerAutomation
|
||||
import com.unciv.logic.map.MapUnit
|
||||
import com.unciv.models.gamebasics.unit.UnitType
|
||||
import com.unciv.models.gamebasics.Building
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.unit.UnitType
|
||||
import com.unciv.ui.pickerscreens.ImprovementPickerScreen
|
||||
import com.unciv.ui.pickerscreens.TechPickerScreen
|
||||
import com.unciv.ui.worldscreen.WorldScreen
|
||||
import java.util.*
|
||||
import kotlin.math.max
|
||||
|
||||
class UnitAction(var name: String, var action:()->Unit, var canAct:Boolean)
|
||||
|
||||
@ -65,6 +66,11 @@ class UnitActions {
|
||||
}
|
||||
}
|
||||
|
||||
if(unit.hasUnique("Must set up to ranged attack") && unit.action != "Set Up")
|
||||
actionList+=UnitAction("Set up",
|
||||
{unit.action="Set Up"; unit.currentMovement = max(0f, unit.currentMovement-1)},
|
||||
unit.currentMovement != 0f)
|
||||
|
||||
if (unit.name == "Settler") {
|
||||
actionList += UnitAction("Found city",
|
||||
{
|
||||
|
@ -33,6 +33,7 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table(){
|
||||
"Construct Manufactory" -> return ImageGetter.getImprovementIcon("Manufactory")
|
||||
"Conduct Trade Mission" -> return ImageGetter.getUnitIcon("Great Merchant")
|
||||
"Construct Customs House" -> return ImageGetter.getImprovementIcon("Customs house")
|
||||
"Set up" -> return ImageGetter.getUnitIcon("Catapult")
|
||||
else -> return ImageGetter.getImage("OtherIcons/Star.png")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user