Resolved #11675 - Unavailable techs work well with tech picker screen

This commit is contained in:
yairm210 2024-05-31 19:06:12 +03:00
parent 834567170e
commit bdb0dcef65
3 changed files with 22 additions and 10 deletions

View File

@ -160,28 +160,35 @@ class TechManager : IsPartOfGameInfoSerialization {
fun isObsolete(unit: BaseUnit): Boolean = unit.techsThatObsoleteThis().any{ obsoleteTech -> isResearched(obsoleteTech) }
fun isUnresearchable(tech: Technology): Boolean {
if (tech.getMatchingUniques(UniqueType.OnlyAvailable, StateForConditionals.IgnoreConditionals).any { !it.conditionalsApply(civInfo) })
return true
if (tech.hasUnique(UniqueType.Unavailable, StateForConditionals(civInfo))) return true
return false
}
fun canBeResearched(techName: String): Boolean {
val tech = getRuleset().technologies[techName]!!
if (tech.getMatchingUniques(UniqueType.OnlyAvailable, StateForConditionals.IgnoreConditionals).any { !it.conditionalsApply(civInfo) })
return false
if (tech.hasUnique(UniqueType.Unavailable, StateForConditionals(civInfo))) return false
if (isResearched(tech.name) && !tech.isContinuallyResearchable())
return false
if (isUnresearchable(tech)) return false
if (isResearched(tech.name) && !tech.isContinuallyResearchable()) return false
return tech.prerequisites.all { isResearched(it) }
}
//endregion
/** Returns empty list if no path exists */
fun getRequiredTechsToDestination(destinationTech: Technology): List<Technology> {
val prerequisites = mutableListOf<Technology>()
val checkPrerequisites = ArrayDeque<Technology>()
if (isUnresearchable(destinationTech)) return listOf()
checkPrerequisites.add(destinationTech)
while (!checkPrerequisites.isEmpty()) {
val techToCheck = checkPrerequisites.removeFirst()
if (isUnresearchable(techToCheck)) return listOf()
// future tech can have been researched even when we're researching it,
// so...if we skip it we'll end up with 0 techs in the "required techs", which will mean that we don't have anything to research. Yeah.
if (!techToCheck.isContinuallyResearchable() &&

View File

@ -416,7 +416,7 @@ class TechPickerScreen(
}
}
if(queue){
if (queue){
for (pathTech in pathToTech) {
if (pathTech.name !in tempTechsToResearch) {
tempTechsToResearch.add(pathTech.name)
@ -427,10 +427,14 @@ class TechPickerScreen(
tempTechsToResearch.addAll(pathToTech.map { it.name })
}
val label = "Research [${tempTechsToResearch[0]}]".tr()
val techProgression = getTechProgressLabel(tempTechsToResearch)
pick("${label}\n${techProgression}")
if (tempTechsToResearch.any()) {
val label = "Research [${tempTechsToResearch[0]}]".tr()
val techProgression = getTechProgressLabel(tempTechsToResearch)
pick("${label}\n${techProgression}")
} else {
rightSideButton.setText("Unavailable".tr())
rightSideButton.disable()
}
setButtonsInfo()
}

View File

@ -1537,6 +1537,7 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
Applicable to: Unit
??? example "Is part of Great Person group [comment]"
Great people in the same group increase teach other's costs when gained. Gaining one will make all others in the same group cost more GPP.
Example: "Is part of Great Person group [comment]"
Applicable to: Unit