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:
Yair Morgenstern
2018-06-11 18:27:23 +03:00
parent 4b2cefd5f4
commit 02c74ad8ba
7 changed files with 23 additions and 4 deletions

View File

@ -37,6 +37,7 @@
}, },
{ {
name:"Barbarians", 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
} }
] ]

View File

@ -86,6 +86,9 @@ class UnitAutomation{
val enemyTileToAttack = getAttackableEnemies(unit).firstOrNull() val enemyTileToAttack = getAttackableEnemies(unit).firstOrNull()
if (enemyTileToAttack != null) { 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 enemy = Battle().getMapCombatantOfTile(enemyTileToAttack)!!
val damageToAttacker = Battle(unit.civInfo.gameInfo).calculateDamageToAttacker(MapUnitCombatant(unit), enemy) val damageToAttacker = Battle(unit.civInfo.gameInfo).calculateDamageToAttacker(MapUnitCombatant(unit), enemy)

View File

@ -141,7 +141,6 @@ class Battle(val gameInfo:GameInfo=UnCivGame.Current.gameInfo) {
} }
postBattleAction(attacker,defender,attackedTile) postBattleAction(attacker,defender,attackedTile)
} }
private fun postBattleAction(attacker: ICombatant, defender: ICombatant, attackedTile:TileInfo){ 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")) if (attacker.unit.hasUnique("Can move after attacking"))
attacker.unit.currentMovement = max(0f, attacker.unit.currentMovement - 1) attacker.unit.currentMovement = max(0f, attacker.unit.currentMovement - 1)
else attacker.unit.currentMovement = 0f else attacker.unit.currentMovement = 0f
attacker.unit.attacksThisTurn+=1
attacker.unit.action=null // for instance, if it was fortified attacker.unit.action=null // for instance, if it was fortified
} }
} }

View File

@ -18,6 +18,7 @@ class MapUnit {
var currentMovement: Float = 0f var currentMovement: Float = 0f
var health:Int = 100 var health:Int = 100
var action: String? = null // work, automation, fortifying, I dunno what. var action: String? = null // work, automation, fortifying, I dunno what.
var attacksThisTurn = 0
fun getBaseUnit(): Unit = GameBasics.Units[name]!! fun getBaseUnit(): Unit = GameBasics.Units[name]!!
fun getMovementString(): String = DecimalFormat("0.#").format(currentMovement.toDouble()) + "/" + maxMovement fun getMovementString(): String = DecimalFormat("0.#").format(currentMovement.toDouble()) + "/" + maxMovement
@ -169,4 +170,11 @@ class MapUnit {
if (isFortified()) return false if (isFortified()) return false
return true 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
}
} }

View File

@ -119,7 +119,7 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
val attackerCanReachDefender = UnitAutomation().getAttackableEnemies(attacker.unit) val attackerCanReachDefender = UnitAutomation().getAttackableEnemies(attacker.unit)
.contains(defender.getTile()) .contains(defender.getTile())
if(!attackerCanReachDefender || attacker.unit.currentMovement==0f) attackButton.disable() if(!attackerCanReachDefender || !attacker.unit.canAttack()) attackButton.disable()
else { else {
attackButton.addClickListener { attackButton.addClickListener {
if(attacker.isMelee()) if(attacker.isMelee())

View File

@ -2,13 +2,14 @@ package com.unciv.ui.worldscreen.unit
import com.unciv.logic.automation.WorkerAutomation import com.unciv.logic.automation.WorkerAutomation
import com.unciv.logic.map.MapUnit import com.unciv.logic.map.MapUnit
import com.unciv.models.gamebasics.unit.UnitType
import com.unciv.models.gamebasics.Building import com.unciv.models.gamebasics.Building
import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.GameBasics
import com.unciv.models.gamebasics.unit.UnitType
import com.unciv.ui.pickerscreens.ImprovementPickerScreen import com.unciv.ui.pickerscreens.ImprovementPickerScreen
import com.unciv.ui.pickerscreens.TechPickerScreen import com.unciv.ui.pickerscreens.TechPickerScreen
import com.unciv.ui.worldscreen.WorldScreen import com.unciv.ui.worldscreen.WorldScreen
import java.util.* import java.util.*
import kotlin.math.max
class UnitAction(var name: String, var action:()->Unit, var canAct:Boolean) 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") { if (unit.name == "Settler") {
actionList += UnitAction("Found city", actionList += UnitAction("Found city",
{ {

View File

@ -33,6 +33,7 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table(){
"Construct Manufactory" -> return ImageGetter.getImprovementIcon("Manufactory") "Construct Manufactory" -> return ImageGetter.getImprovementIcon("Manufactory")
"Conduct Trade Mission" -> return ImageGetter.getUnitIcon("Great Merchant") "Conduct Trade Mission" -> return ImageGetter.getUnitIcon("Great Merchant")
"Construct Customs House" -> return ImageGetter.getImprovementIcon("Customs house") "Construct Customs House" -> return ImageGetter.getImprovementIcon("Customs house")
"Set up" -> return ImageGetter.getUnitIcon("Catapult")
else -> return ImageGetter.getImage("OtherIcons/Star.png") else -> return ImageGetter.getImage("OtherIcons/Star.png")
} }
} }