mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-10 07:16:54 +07:00
Resolved #5641 - unit upgrade check ONLY removes/adds unit if absolutely necessary
This previously was done every time the function was called, leading to updating the civ resources twice per unit check, which is kind of heavy
This commit is contained in:
parent
cda34bf23f
commit
bc5ea2d90a
@ -4,7 +4,7 @@ object BuildConfig {
|
||||
const val kotlinVersion = "1.5.30"
|
||||
const val appName = "Unciv"
|
||||
const val appCodeNumber = 644
|
||||
const val appVersion = "3.17.15"
|
||||
const val appVersion = "3.18.0"
|
||||
|
||||
const val gdxVersion = "1.10.0"
|
||||
const val roboVMVersion = "2.3.1"
|
||||
|
@ -517,6 +517,7 @@ object Battle {
|
||||
capturedUnit.capturedBy(attacker.getCivInfo())
|
||||
attacker.getCivInfo().popupAlerts.add(PopupAlert(AlertType.RecapturedCivilian, capturedUnitTile.position.toString()))
|
||||
}
|
||||
|
||||
// Captured settlers are converted to workers unless captured by barbarians (so they can be returned later).
|
||||
capturedUnit.hasUnique("Founds a new city") && !attacker.getCivInfo().isBarbarian() -> {
|
||||
capturedUnit.destroy()
|
||||
@ -525,9 +526,7 @@ object Battle {
|
||||
capturedUnit.civInfo = attacker.getCivInfo()
|
||||
attacker.getCivInfo().placeUnitNearTile(capturedUnitTile.position, Constants.worker)
|
||||
}
|
||||
else -> {
|
||||
capturedUnit.capturedBy(attacker.getCivInfo())
|
||||
}
|
||||
else -> capturedUnit.capturedBy(attacker.getCivInfo())
|
||||
}
|
||||
|
||||
if (checkDefeat)
|
||||
|
@ -6,6 +6,7 @@ import com.unciv.UncivGame
|
||||
import com.unciv.logic.automation.UnitAutomation
|
||||
import com.unciv.logic.automation.WorkerAutomation
|
||||
import com.unciv.logic.city.CityInfo
|
||||
import com.unciv.logic.city.RejectionReason
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.civilization.LocationAction
|
||||
import com.unciv.logic.civilization.NotificationIcon
|
||||
@ -470,18 +471,23 @@ class MapUnit {
|
||||
* Used for upgrading units via ancient ruins.
|
||||
*/
|
||||
fun canUpgrade(unitToUpgradeTo: BaseUnit = getUnitToUpgradeTo(), ignoreRequired: Boolean = false): Boolean {
|
||||
// We need to remove the unit from the civ for this check,
|
||||
// because if the unit requires, say, horses, and so does its upgrade,
|
||||
// and the civ currently has 0 horses,
|
||||
// if we don't remove the unit before the check it's return false!
|
||||
|
||||
if (name == unitToUpgradeTo.name) return false
|
||||
civInfo.removeUnit(this)
|
||||
val canUpgrade =
|
||||
if (ignoreRequired) unitToUpgradeTo.isBuildableIgnoringTechs(civInfo)
|
||||
else unitToUpgradeTo.isBuildable(civInfo)
|
||||
civInfo.addUnit(this)
|
||||
return canUpgrade
|
||||
val rejectionReasons = unitToUpgradeTo.getRejectionReasons(civInfo)
|
||||
if (rejectionReasons.isEmpty()) return true
|
||||
|
||||
if (rejectionReasons.size == 1 && rejectionReasons.contains(RejectionReason.ConsumesResources)) {
|
||||
// We need to remove the unit from the civ for this check,
|
||||
// because if the unit requires, say, horses, and so does its upgrade,
|
||||
// and the civ currently has 0 horses, we need to see if the upgrade will be buildable
|
||||
// WHEN THE CURRENT UNIT IS NOT HERE
|
||||
civInfo.removeUnit(this)
|
||||
val canUpgrade =
|
||||
if (ignoreRequired) unitToUpgradeTo.isBuildableIgnoringTechs(civInfo)
|
||||
else unitToUpgradeTo.isBuildable(civInfo)
|
||||
civInfo.addUnit(this)
|
||||
return canUpgrade
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun getCostOfUpgrade(): Int {
|
||||
|
Loading…
Reference in New Issue
Block a user