From 02c74ad8ba97cc413f8e2593278acb53c8eea4ed Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 11 Jun 2018 18:27:23 +0300 Subject: [PATCH] Added Set Up action for siege units that require it Unit cannot attack twice a turn even if it can "move after attacking" --- android/assets/jsons/Civilizations.json | 3 ++- core/src/com/unciv/logic/automation/UnitAutomation.kt | 3 +++ core/src/com/unciv/logic/battle/Battle.kt | 2 +- core/src/com/unciv/logic/map/MapUnit.kt | 8 ++++++++ .../src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt | 2 +- core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt | 8 +++++++- .../src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt | 1 + 7 files changed, 23 insertions(+), 4 deletions(-) diff --git a/android/assets/jsons/Civilizations.json b/android/assets/jsons/Civilizations.json index 4c6f0961d1..563214824c 100644 --- a/android/assets/jsons/Civilizations.json +++ b/android/assets/jsons/Civilizations.json @@ -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 } ] \ No newline at end of file diff --git a/core/src/com/unciv/logic/automation/UnitAutomation.kt b/core/src/com/unciv/logic/automation/UnitAutomation.kt index bc830553c8..0037dcfdce 100644 --- a/core/src/com/unciv/logic/automation/UnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/UnitAutomation.kt @@ -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) diff --git a/core/src/com/unciv/logic/battle/Battle.kt b/core/src/com/unciv/logic/battle/Battle.kt index fb1bed444d..57a43bd99e 100644 --- a/core/src/com/unciv/logic/battle/Battle.kt +++ b/core/src/com/unciv/logic/battle/Battle.kt @@ -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 } } diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index efe899424d..5401b485fe 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -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 + } } \ No newline at end of file diff --git a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt index 32da72bced..2d1858d6e5 100644 --- a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt +++ b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt @@ -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()) diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index 49b88980b8..93b5d41a75 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -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", { diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt index 286729dfb0..0ae9a42970 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt @@ -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") } }