mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-14 01:39:40 +07:00
replaceAll appears to be a Java 8 feature, so rewrote the queue updating when obsoleting units
Also added sequence changes as per @SomeTroglodyte
This commit is contained in:
@ -33,8 +33,8 @@ allprojects {
|
||||
version = '1.0.1'
|
||||
ext {
|
||||
appName = "Unciv"
|
||||
appCodeNumber = 413
|
||||
appVersion = "3.7.6"
|
||||
appCodeNumber = 414
|
||||
appVersion = "3.7.6-patch1"
|
||||
|
||||
gdxVersion = '1.9.10'
|
||||
roboVMVersion = '2.3.1'
|
||||
|
@ -257,11 +257,18 @@ class TechManager {
|
||||
}
|
||||
|
||||
val obsoleteUnits = getRuleset().units.values.filter { it.obsoleteTech == techName }.map { it.name }
|
||||
for (city in civInfo.cities)
|
||||
for(constructionName in city.cityConstructions.constructionQueue.toList()){ // copy, since we're changing the queue
|
||||
if(constructionName !in obsoleteUnits) continue
|
||||
for (city in civInfo.cities) {
|
||||
// Do not use replaceAll - that's a Java 8 feature and will fail on older phones!
|
||||
val oldQueue = city.cityConstructions.constructionQueue.toList() // copy, since we're changing the queue
|
||||
city.cityConstructions.constructionQueue.clear()
|
||||
for (constructionName in oldQueue) {
|
||||
var newConstructionName = constructionName
|
||||
if (constructionName in obsoleteUnits) {
|
||||
val constructionUnit = city.cityConstructions.getConstruction(constructionName) as BaseUnit
|
||||
city.cityConstructions.constructionQueue.replaceAll { if(it==constructionName) constructionUnit.upgradesTo!! else it }
|
||||
newConstructionName = civInfo.getEquivalentUnit(constructionUnit.upgradesTo!!).name
|
||||
}
|
||||
city.cityConstructions.constructionQueue.add(newConstructionName)
|
||||
}
|
||||
}
|
||||
|
||||
if(techName=="Writing" && civInfo.nation.unique == UniqueAbility.INGENUITY
|
||||
|
@ -80,14 +80,10 @@ open class TileInfo {
|
||||
//region pure functions
|
||||
|
||||
/** Returns military, civilian and air units in tile */
|
||||
fun getUnits(): Sequence<MapUnit> {
|
||||
if(militaryUnit==null && civilianUnit==null && airUnits.isEmpty())
|
||||
return emptySequence() // for performance reasons - costs much less to initialize than an empty ArrayList or list()
|
||||
val list = ArrayList<MapUnit>(2)
|
||||
if(militaryUnit!=null) list.add(militaryUnit!!)
|
||||
if(civilianUnit!=null) list.add(civilianUnit!!)
|
||||
list.addAll(airUnits)
|
||||
return list.asSequence()
|
||||
fun getUnits() = sequence {
|
||||
if (militaryUnit != null) yield(militaryUnit!!)
|
||||
if (civilianUnit != null) yield(civilianUnit!!)
|
||||
if (airUnits.isNotEmpty()) yieldAll(airUnits)
|
||||
}
|
||||
|
||||
fun getCity(): CityInfo? = owningCity
|
||||
@ -115,7 +111,9 @@ open class TileInfo {
|
||||
// This is for performance - since we access the neighbors of a tile ALL THE TIME,
|
||||
// and the neighbors of a tile never change, it's much more efficient to save the list once and for all!
|
||||
@delegate:Transient
|
||||
val neighbors: Sequence<TileInfo> by lazy { getTilesAtDistance(1) }
|
||||
val neighbors: Sequence<TileInfo> by lazy { getTilesAtDistance(1).toList().asSequence() }
|
||||
// We have to .toList() so that the values are stored together once for caching,
|
||||
// and the toSequence so that aggregations (like neighbors.flatMap{it.units} don't take up their own space
|
||||
|
||||
fun getHeight(): Int {
|
||||
if (baseTerrain == Constants.mountain) return 4
|
||||
|
Reference in New Issue
Block a user