Further improve performance of UpgradeContainer
This commit is contained in:
parent
85aecaf79b
commit
67ea3b977b
@ -39,9 +39,9 @@ class UpgradeContainer(
|
||||
}
|
||||
|
||||
override val speedBonus: Double
|
||||
get() = iterator().map { (it.getCapability(MatteryCapability.UPGRADE)?.speedBonus ?: 0.0) * it.count }.reduce(0.0) { a, b -> a + b }
|
||||
get() = if (isEmpty) 0.0 else iterator().map { (it.getCapability(MatteryCapability.UPGRADE)?.speedBonus ?: 0.0) * it.count }.reduce(0.0) { a, b -> a + b }
|
||||
override val processingItems: Int
|
||||
get() = iterator().map { (it.getCapability(MatteryCapability.UPGRADE)?.processingItems ?: 0).coerceAtLeast(0) * it.count }.reduce(0) { a, b -> a + b }
|
||||
get() = if (isEmpty) 0 else iterator().map { (it.getCapability(MatteryCapability.UPGRADE)?.processingItems ?: 0).coerceAtLeast(0) * it.count }.reduce(0) { a, b -> a + b }
|
||||
override val energyStorageFlat: Decimal
|
||||
get() = positiveDecimals(IMatteryUpgrade::energyStorageFlat, Decimal::plus)
|
||||
override val energyStorage: Decimal
|
||||
@ -53,7 +53,7 @@ class UpgradeContainer(
|
||||
override val energyConsumed: Decimal
|
||||
get() = anyDecimals(IMatteryUpgrade::energyConsumed, Decimal::plus)
|
||||
override val failureMultiplier: Double
|
||||
get() = iterator().map { (it.getCapability(MatteryCapability.UPGRADE)?.failureMultiplier ?: 1.0).coerceAtLeast(0.0).pow(it.count.toDouble()) }.reduce(1.0) { a, b -> a * b }
|
||||
get() = if (isEmpty) 1.0 else iterator().map { (it.getCapability(MatteryCapability.UPGRADE)?.failureMultiplier ?: 1.0).coerceAtLeast(0.0).pow(it.count.toDouble()) }.reduce(1.0) { a, b -> a * b }
|
||||
override val energyThroughputFlat: Decimal
|
||||
get() = positiveDecimals(IMatteryUpgrade::energyThroughputFlat, Decimal::plus)
|
||||
override val energyThroughput: Decimal
|
||||
@ -62,24 +62,24 @@ class UpgradeContainer(
|
||||
fun transform(values: EnergyBalanceValues): EnergyBalanceValues {
|
||||
return object : EnergyBalanceValues {
|
||||
override val energyCapacity: Decimal
|
||||
get() = values.energyCapacity * (energyStorage + Decimal.ONE) + energyStorageFlat
|
||||
get() = if (isEmpty) values.energyCapacity else values.energyCapacity * (energyStorage + Decimal.ONE) + energyStorageFlat
|
||||
override val energyThroughput: Decimal
|
||||
get() = values.energyThroughput * (this@UpgradeContainer.energyThroughput + Decimal.ONE) + energyThroughputFlat
|
||||
get() = if (isEmpty) values.energyThroughput else values.energyThroughput * (this@UpgradeContainer.energyThroughput + Decimal.ONE) + energyThroughputFlat
|
||||
}
|
||||
}
|
||||
|
||||
fun transform(values: VerboseEnergyBalanceValues): VerboseEnergyBalanceValues {
|
||||
return object : VerboseEnergyBalanceValues {
|
||||
override val energyCapacity: Decimal
|
||||
get() = values.energyCapacity * (energyStorage + Decimal.ONE) + energyStorageFlat
|
||||
get() = if (isEmpty) values.energyCapacity else values.energyCapacity * (energyStorage + Decimal.ONE) + energyStorageFlat
|
||||
override val maxEnergyReceive: Decimal
|
||||
get() = values.maxEnergyReceive * (energyThroughput + Decimal.ONE) + energyThroughputFlat
|
||||
get() = if (isEmpty) values.maxEnergyReceive else values.maxEnergyReceive * (energyThroughput + Decimal.ONE) + energyThroughputFlat
|
||||
override val maxEnergyExtract: Decimal
|
||||
get() = values.maxEnergyExtract * (energyThroughput + Decimal.ONE) + energyThroughputFlat
|
||||
get() =if (isEmpty) values.maxEnergyExtract else values.maxEnergyExtract * (energyThroughput + Decimal.ONE) + energyThroughputFlat
|
||||
}
|
||||
}
|
||||
|
||||
fun matterCapacity(value: () -> Decimal): () -> Decimal {
|
||||
return { value.invoke() * (matterStorage + Decimal.ONE) + matterStorageFlat }
|
||||
return { if (isEmpty) value.invoke() else value.invoke() * (matterStorage + Decimal.ONE) + matterStorageFlat }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user