Fixed combat for embarked units
This commit is contained in:
parent
7cd903c6b9
commit
230031e9f5
5 changed files with 17 additions and 8 deletions
|
@ -21,8 +21,8 @@ android {
|
|||
applicationId "com.unciv.game"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 26
|
||||
versionCode 149
|
||||
versionName "2.9.2"
|
||||
versionCode 150
|
||||
versionName "2.9.3"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
|
|
|
@ -6,7 +6,6 @@ import com.unciv.logic.battle.Battle
|
|||
import com.unciv.logic.battle.BattleDamage
|
||||
import com.unciv.logic.battle.MapUnitCombatant
|
||||
import com.unciv.logic.city.CityInfo
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.civilization.DiplomaticStatus
|
||||
import com.unciv.logic.map.MapUnit
|
||||
import com.unciv.logic.map.TileInfo
|
||||
|
@ -127,17 +126,21 @@ class UnitAutomation{
|
|||
}
|
||||
}
|
||||
|
||||
fun containsAttackableEnemy(tile: TileInfo, civInfo: CivilizationInfo): Boolean {
|
||||
val tileCombatant = Battle(civInfo.gameInfo).getMapCombatantOfTile(tile)
|
||||
fun containsAttackableEnemy(tile: TileInfo, unit: MapUnit): Boolean {
|
||||
if(unit.isEmbarked()){
|
||||
if(unit.baseUnit.unitType.isRanged()) return false
|
||||
if(tile.getBaseTerrain().type==TerrainType.Water) return false // can't attack water units while embarked, only land
|
||||
}
|
||||
val tileCombatant = Battle(unit.civInfo.gameInfo).getMapCombatantOfTile(tile)
|
||||
if(tileCombatant==null) return false
|
||||
return tileCombatant.getCivilization()!=civInfo && civInfo.isAtWarWith(tileCombatant.getCivilization())
|
||||
return tileCombatant.getCivilization()!=unit.civInfo && unit.civInfo.isAtWarWith(tileCombatant.getCivilization())
|
||||
}
|
||||
|
||||
class AttackableTile(val tileToAttackFrom:TileInfo, val tileToAttack:TileInfo)
|
||||
|
||||
fun getAttackableEnemies(unit: MapUnit, unitDistanceToTiles: HashMap<TileInfo, Float>): ArrayList<AttackableTile> {
|
||||
val tilesWithEnemies = unit.civInfo.getViewableTiles()
|
||||
.filter { containsAttackableEnemy(it,unit.civInfo) }
|
||||
.filter { containsAttackableEnemy(it,unit) }
|
||||
|
||||
val rangeOfAttack = unit.getRange()
|
||||
|
||||
|
@ -162,7 +165,7 @@ class UnitAutomation{
|
|||
private fun tryAdvanceTowardsCloseEnemy(unit: MapUnit): Boolean {
|
||||
// this can be sped up if we check each layer separately
|
||||
var closeEnemies = unit.getTile().getTilesInDistance(5)
|
||||
.filter{ containsAttackableEnemy(it, unit.civInfo) && unit.movementAlgs().canReach(it)}
|
||||
.filter{ containsAttackableEnemy(it, unit) && unit.movementAlgs().canReach(it)}
|
||||
if(unit.baseUnit().unitType.isRanged())
|
||||
closeEnemies = closeEnemies.filterNot { it.isCityCenter() && it.getCity()!!.health==1 }
|
||||
|
||||
|
|
|
@ -84,6 +84,9 @@ class BattleDamage{
|
|||
modifiers["Flanking"] = 0.1f * (numberOfAttackersSurroundingDefender-1) //https://www.carlsguides.com/strategy/civilization5/war/combatbonuses.php
|
||||
}
|
||||
|
||||
if(attacker is MapUnitCombatant && attacker.unit.isEmbarked())
|
||||
modifiers["Landing"] = -0.5f
|
||||
|
||||
return modifiers
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ class MapUnitCombatant(val unit: MapUnit) : ICombatant {
|
|||
}
|
||||
|
||||
override fun getDefendingStrength(attacker: ICombatant): Int { // todo remove attacker
|
||||
if(unit.isEmbarked()) return 0
|
||||
return unit.baseUnit().strength
|
||||
}
|
||||
|
||||
|
|
|
@ -158,7 +158,9 @@ class MapUnit {
|
|||
return range
|
||||
}
|
||||
|
||||
|
||||
fun isEmbarked(): Boolean {
|
||||
if(!baseUnit.unitType.isLandUnit()) return false
|
||||
return currentTile.baseTerrain=="Ocean"||currentTile.baseTerrain=="Coast"
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue