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