mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-22 19:08:48 -04:00
Fix endless loop when many units can transfer movement to each other
This commit is contained in:
parent
b0c9724433
commit
61fe6d0eee
@ -308,7 +308,7 @@ class MapUnit : IsPartOfGameInfoSerialization {
|
||||
return false
|
||||
}
|
||||
|
||||
fun getMaxMovement(): Int {
|
||||
fun getMaxMovement(ignoreOtherUnit: Boolean = false): Int {
|
||||
var movement =
|
||||
if (isEmbarked()) 2
|
||||
else baseUnit.movement
|
||||
@ -321,11 +321,14 @@ class MapUnit : IsPartOfGameInfoSerialization {
|
||||
// Hakkapeliitta movement boost
|
||||
// For every double-stacked tile, check if our cohabitant can boost our speed
|
||||
// (a test `count() > 1` is no optimization - two iterations of a sequence instead of one)
|
||||
for (boostingUnit in currentTile.getUnits()) {
|
||||
if (boostingUnit == this) continue
|
||||
if (boostingUnit.getMatchingUniques(UniqueType.TransferMovement)
|
||||
.none { matchesFilter(it.params[0]) }) continue
|
||||
movement = movement.coerceAtLeast(boostingUnit.getMaxMovement())
|
||||
if (!ignoreOtherUnit) { // if both units can boost the other, we avoid an endless loop
|
||||
for (boostingUnit in currentTile.getUnits()) {
|
||||
if (boostingUnit == this) continue
|
||||
if (boostingUnit.getMatchingUniques(UniqueType.TransferMovement)
|
||||
.none { matchesFilter(it.params[0]) }
|
||||
) continue
|
||||
movement = movement.coerceAtLeast(boostingUnit.getMaxMovement(true))
|
||||
}
|
||||
}
|
||||
|
||||
return movement
|
||||
|
@ -150,13 +150,13 @@ class Ruleset {
|
||||
private inline fun <reified T : INamed> createHashmap(items: Array<T>): LinkedHashMap<String, T> {
|
||||
val hashMap = LinkedHashMap<String, T>(items.size)
|
||||
for (item in items) {
|
||||
val name = try { item.name }
|
||||
val itemName = try { item.name }
|
||||
catch (ex: Exception) {
|
||||
throw Exception("${T::class.simpleName} is missing a name!")
|
||||
}
|
||||
|
||||
hashMap[item.name] = item
|
||||
(item as? IRulesetObject)?.originRuleset = name
|
||||
hashMap[itemName] = item
|
||||
(item as? IRulesetObject)?.originRuleset = name // RULESET name
|
||||
}
|
||||
return hashMap
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user