Fixed crash when you would melee attack an enemy unit that was in a friendly civ's (unenterable) territory

This commit is contained in:
Yair Morgenstern 2018-08-06 13:08:45 +03:00
parent 13e1d06c8b
commit 99c0abd24d
3 changed files with 12 additions and 8 deletions

View File

@ -21,8 +21,8 @@ android {
applicationId "com.unciv.game"
minSdkVersion 14
targetSdkVersion 26
versionCode 114
versionName "2.7.3"
versionCode 115
versionName "2.7.3.2"
}
buildTypes {
release {

View File

@ -65,11 +65,14 @@ class Battle(val gameInfo:GameInfo=UnCivGame.Current.gameInfo) {
}
// we're a melee unit and we destroyed\captured an enemy unit
else if (attacker.isMelee() && (defender.isDefeated() || defender.getCivilization()==attacker.getCivilization() )) {
else if (attacker.isMelee()
&& (defender.isDefeated() || defender.getCivilization()==attacker.getCivilization() )
// This is so that if we attack e.g. a barbarian in enemy territory that we can't enter, we won't enter it
&& (attacker as MapUnitCombatant).unit.canMoveTo(attackedTile)) {
// we destroyed an enemy military unit and there was a civilian unit in the same tile as well
if(attackedTile.civilianUnit!=null && attackedTile.civilianUnit!!.civInfo != attacker.getCivilization())
captureCivilianUnit(attacker,MapUnitCombatant(attackedTile.civilianUnit!!))
(attacker as MapUnitCombatant).unit.moveToTile(attackedTile)
attacker.unit.moveToTile(attackedTile)
}
if(attacker is MapUnitCombatant) {

View File

@ -114,7 +114,8 @@ class MapUnit {
val distanceToTiles = getDistanceToTiles()
if (!distanceToTiles.containsKey(otherTile))
throw Exception("You can't get there from here!")
if(!canMoveTo(otherTile)) throw Exception("Can't enter this tile!")
if(!canMoveTo(otherTile))
throw Exception("Can't enter this tile!")
if(otherTile.isCityCenter() && otherTile.getOwner()!=civInfo) throw Exception("This is an enemy city, you can't go here!")
currentMovement -= distanceToTiles[otherTile]!!
@ -193,9 +194,9 @@ class MapUnit {
*/
fun canMoveTo(tile: TileInfo): Boolean {
val tileOwner = tile.getOwner()
if(tileOwner!=null && tileOwner.civName!=owner) {
if (tile.isCityCenter() || !civInfo.canEnterTiles(tileOwner)) return false
}
if(tileOwner!=null && tileOwner.civName!=owner
&& (tile.isCityCenter() || !civInfo.canEnterTiles(tileOwner))) return false
if (getBaseUnit().unitType== UnitType.Civilian)
return tile.civilianUnit==null && (tile.militaryUnit==null || tile.militaryUnit!!.owner==owner)
else return tile.militaryUnit==null && (tile.civilianUnit==null || tile.civilianUnit!!.owner==owner)