mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 14:24:43 -04:00
Performance: Removed map lookup every time we want to get a unit's type
This commit is contained in:
parent
bfb869f64f
commit
f0ee25dcac
@ -189,7 +189,7 @@ class MapUnit : IsPartOfGameInfoSerialization {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val type: UnitType
|
val type: UnitType
|
||||||
get() = baseUnit.getType()
|
get() = baseUnit.type
|
||||||
|
|
||||||
fun baseUnit(): BaseUnit = baseUnit
|
fun baseUnit(): BaseUnit = baseUnit
|
||||||
fun getMovementString(): String =
|
fun getMovementString(): String =
|
||||||
|
@ -34,7 +34,8 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
|
|||||||
var range: Int = 2
|
var range: Int = 2
|
||||||
var interceptRange = 0
|
var interceptRange = 0
|
||||||
var unitType: String = ""
|
var unitType: String = ""
|
||||||
fun getType() = ruleset.unitTypes[unitType]!!
|
|
||||||
|
val type by lazy { ruleset.unitTypes[unitType]!! }
|
||||||
override var requiredTech: String? = null
|
override var requiredTech: String? = null
|
||||||
private var requiredResource: String? = null
|
private var requiredResource: String? = null
|
||||||
|
|
||||||
@ -296,7 +297,7 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
|
|||||||
"Great Person" -> isGreatPerson()
|
"Great Person" -> isGreatPerson()
|
||||||
"Religious" -> hasUnique(UniqueType.ReligiousUnit)
|
"Religious" -> hasUnique(UniqueType.ReligiousUnit)
|
||||||
else -> {
|
else -> {
|
||||||
if (getType().matchesFilter(filter)) return true
|
if (type.matchesFilter(filter)) return true
|
||||||
if (
|
if (
|
||||||
// Uniques using these kinds of filters should be deprecated and replaced with adjective-only parameters
|
// Uniques using these kinds of filters should be deprecated and replaced with adjective-only parameters
|
||||||
filter.endsWith(" units")
|
filter.endsWith(" units")
|
||||||
@ -313,7 +314,7 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
|
|||||||
|
|
||||||
fun isNuclearWeapon() = hasUnique(UniqueType.NuclearWeapon)
|
fun isNuclearWeapon() = hasUnique(UniqueType.NuclearWeapon)
|
||||||
|
|
||||||
fun movesLikeAirUnits() = getType().getMovementType() == UnitMovementType.Air
|
fun movesLikeAirUnits() = type.getMovementType() == UnitMovementType.Air
|
||||||
|
|
||||||
/** Returns resource requirements from both uniques and requiredResource field */
|
/** Returns resource requirements from both uniques and requiredResource field */
|
||||||
override fun getResourceRequirements(): HashMap<String, Int> = resourceRequirementsInternal
|
override fun getResourceRequirements(): HashMap<String, Int> = resourceRequirementsInternal
|
||||||
@ -333,15 +334,15 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
|
|||||||
fun isMilitary() = isRanged() || isMelee()
|
fun isMilitary() = isRanged() || isMelee()
|
||||||
fun isCivilian() = !isMilitary()
|
fun isCivilian() = !isMilitary()
|
||||||
|
|
||||||
val isLandUnitInternal by lazy { getType().isLandUnit() }
|
val isLandUnitInternal by lazy { type.isLandUnit() }
|
||||||
fun isLandUnit() = isLandUnitInternal
|
fun isLandUnit() = isLandUnitInternal
|
||||||
fun isWaterUnit() = getType().isWaterUnit()
|
fun isWaterUnit() = type.isWaterUnit()
|
||||||
fun isAirUnit() = getType().isAirUnit()
|
fun isAirUnit() = type.isAirUnit()
|
||||||
|
|
||||||
fun isProbablySiegeUnit() =
|
fun isProbablySiegeUnit() =
|
||||||
(
|
(
|
||||||
isRanged()
|
isRanged()
|
||||||
&& (uniqueObjects + getType().uniqueObjects)
|
&& (uniqueObjects + type.uniqueObjects)
|
||||||
.any { it.isOfType(UniqueType.Strength)
|
.any { it.isOfType(UniqueType.Strength)
|
||||||
&& it.params[0].toInt() > 0
|
&& it.params[0].toInt() > 0
|
||||||
&& it.conditionals.any { conditional -> conditional.isOfType(UniqueType.ConditionalVsCity) }
|
&& it.conditionals.any { conditional -> conditional.isOfType(UniqueType.ConditionalVsCity) }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user