Organized clone functions

Found one last place where the unit was destroyed manually and not using the destroy() function =\
This commit is contained in:
Yair Morgenstern 2018-08-20 22:36:01 +03:00
parent 040866609e
commit 5e1bccdc47
8 changed files with 30 additions and 24 deletions

View file

@ -21,7 +21,7 @@ android {
applicationId "com.unciv.game"
minSdkVersion 14
targetSdkVersion 26
versionCode 125
versionCode 126
versionName "2.7.10"
}
buildTypes {

View file

@ -97,7 +97,7 @@ class UnitAutomation{
}
fun containsAttackableEnemy(tile: TileInfo, civInfo: CivilizationInfo): Boolean {
val tileCombatant = Battle().getMapCombatantOfTile(tile)
val tileCombatant = Battle(civInfo.gameInfo).getMapCombatantOfTile(tile)
if(tileCombatant==null) return false
return tileCombatant.getCivilization()!=civInfo && civInfo.isAtWarWith(tileCombatant.getCivilization())
}
@ -194,7 +194,7 @@ class UnitAutomation{
// Only take enemies we can fight without dying
.filter {
BattleDamage().calculateDamageToAttacker(MapUnitCombatant(unit),
Battle().getMapCombatantOfTile(it.tileToAttack)!!) < unit.health
Battle(unit.civInfo.gameInfo).getMapCombatantOfTile(it.tileToAttack)!!) < unit.health
}
val cityTilesToAttack = attackableEnemies.filter { it.tileToAttack.isCityCenter() }
@ -209,11 +209,11 @@ class UnitAutomation{
enemyTileToAttack = capturableCity // enter it quickly, top priority!
else if (nonCityTilesToAttack.isNotEmpty()) // second priority, units
enemyTileToAttack = nonCityTilesToAttack.minBy { Battle().getMapCombatantOfTile(it.tileToAttack)!!.getHealth() }
enemyTileToAttack = nonCityTilesToAttack.minBy { Battle(unit.civInfo.gameInfo).getMapCombatantOfTile(it.tileToAttack)!!.getHealth() }
else if (cityWithHealthLeft!=null) enemyTileToAttack = cityWithHealthLeft// third priority, city
if (enemyTileToAttack != null) {
val enemy = Battle().getMapCombatantOfTile(enemyTileToAttack.tileToAttack)!!
val enemy = Battle(unit.civInfo.gameInfo).getMapCombatantOfTile(enemyTileToAttack.tileToAttack)!!
unit.moveToTile(enemyTileToAttack.tileToAttackFrom)
val setupAction = UnitActions().getUnitActions(unit, UnCivGame.Current.worldScreen)
.firstOrNull { it.name == "Set up" }

View file

@ -1,7 +1,6 @@
package com.unciv.logic.battle
import com.badlogic.gdx.graphics.Color
import com.unciv.UnCivGame
import com.unciv.logic.GameInfo
import com.unciv.logic.city.CityInfo
import com.unciv.logic.map.TileInfo
@ -12,7 +11,7 @@ import kotlin.math.max
/**
* Damage calculations according to civ v wiki and https://steamcommunity.com/sharedfiles/filedetails/?id=170194443
*/
class Battle(val gameInfo:GameInfo=UnCivGame.Current.gameInfo) {
class Battle(val gameInfo:GameInfo) {
fun attack(attacker: ICombatant, defender: ICombatant) {
val attackedTile = defender.getTile()
@ -111,7 +110,7 @@ class Battle(val gameInfo:GameInfo=UnCivGame.Current.gameInfo) {
city.moveToCiv(attacker.getCivilization())
city.health = city.getMaxHealth() / 2 // I think that cities recover to half health when conquered?
city.getCenterTile().apply {
militaryUnit = null
if(militaryUnit!=null) militaryUnit!!.destroy()
if(civilianUnit!=null) captureCivilianUnit(attacker,MapUnitCombatant(civilianUnit!!))
}

View file

@ -20,9 +20,9 @@ class CityConstructions {
//region pure functions
fun clone(): CityConstructions {
val toReturn = CityConstructions()
toReturn.currentConstruction=currentConstruction
toReturn.builtBuildings.addAll(builtBuildings)
toReturn.inProgressConstructions.putAll(inProgressConstructions)
toReturn.currentConstruction=currentConstruction
return toReturn
}

View file

@ -66,15 +66,15 @@ class CityInfo {
//region pure functions
fun clone(): CityInfo {
val toReturn = CityInfo()
toReturn.population = population.clone()
toReturn.health=health
toReturn.location=location
toReturn.name=name
toReturn.tiles.addAll(tiles)
toReturn.workedTiles.addAll(workedTiles)
toReturn.health=health
toReturn.population = population.clone()
toReturn.cityConstructions=cityConstructions.clone()
toReturn.expansion = expansion.clone()
toReturn.tiles.addAll(tiles)
toReturn.workedTiles.addAll(workedTiles)
toReturn.isBeingRazed=isBeingRazed
toReturn.location=location
return toReturn
}

View file

@ -50,17 +50,18 @@ class CivilizationInfo {
fun clone(): CivilizationInfo {
val toReturn = CivilizationInfo()
toReturn.exploredTiles=exploredTiles.toHashSet()
toReturn.gold = gold
toReturn.happiness=happiness
toReturn.difficulty=difficulty
toReturn.civName=civName
toReturn.tech = tech.clone()
toReturn.policies = policies.clone()
toReturn.goldenAges = goldenAges.clone()
toReturn.greatPeople=greatPeople.clone()
toReturn.scienceVictory = scienceVictory.clone()
toReturn.diplomacy.putAll(diplomacy.values.map { it.clone() }.associateBy { it.otherCivName })
toReturn.cities.addAll(cities.map { it.clone() })
toReturn.tech = tech.clone()
toReturn.difficulty=difficulty
toReturn.policies = policies.clone()
toReturn.happiness=happiness
toReturn.greatPeople=greatPeople.clone()
toReturn.gold = gold
toReturn.goldenAges = goldenAges.clone()
toReturn.civName=civName
toReturn.exploredTiles.addAll(exploredTiles)
return toReturn
}

View file

@ -13,6 +13,12 @@ class ScienceVictoryManager {
requiredParts.add("SS Statis Chamber", 1)
}
fun clone(): ScienceVictoryManager {
val toReturn = ScienceVictoryManager()
toReturn.currentParts.putAll(currentParts)
return toReturn
}
fun unconstructedParts(): Counter<String> {
val counter = requiredParts.clone()
counter.remove(currentParts)

View file

@ -41,7 +41,7 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
if (worldScreen.tileMapHolder.selectedTile == null) return
val selectedTile = worldScreen.tileMapHolder.selectedTile!!
val defender: ICombatant? = Battle().getMapCombatantOfTile(selectedTile)
val defender: ICombatant? = Battle(worldScreen.gameInfo).getMapCombatantOfTile(selectedTile)
if(defender==null || defender.getCivilization()==worldScreen.civInfo
|| !(attacker.getCivilization().exploredTiles.contains(selectedTile.position) || UnCivGame.Current.viewEntireMapForDebug)) {