mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-08 14:57:58 +07:00
When choosing a tech to work towards, the order will no longer "jump" over techs
This commit is contained in:
@ -11,6 +11,7 @@ import com.unciv.models.gamebasics.unit.BaseUnit
|
|||||||
import com.unciv.ui.utils.withItem
|
import com.unciv.ui.utils.withItem
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
import kotlin.collections.HashSet
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
|
||||||
@ -95,24 +96,24 @@ class TechManager {
|
|||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
fun getRequiredTechsToDestination(destinationTech: Technology): List<String> {
|
fun getRequiredTechsToDestination(destinationTech: Technology): List<String> {
|
||||||
val prerequisites = Stack<String>()
|
val prerequisites = Stack<Technology>()
|
||||||
val checkPrerequisites = ArrayDeque<String>()
|
|
||||||
checkPrerequisites.add(destinationTech.name)
|
val checkPrerequisites = ArrayDeque<Technology>()
|
||||||
|
checkPrerequisites.add(destinationTech)
|
||||||
|
|
||||||
while (!checkPrerequisites.isEmpty()) {
|
while (!checkPrerequisites.isEmpty()) {
|
||||||
val techNameToCheck = checkPrerequisites.pop()
|
val techToCheck = checkPrerequisites.pop()!!
|
||||||
// future tech can have been researched even when we're researching it,
|
// 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 annything to research. Yeah.
|
// 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 (techNameToCheck!=Constants.futureTech &&
|
if (techToCheck.name!=Constants.futureTech &&
|
||||||
(isResearched(techNameToCheck) || prerequisites.contains(techNameToCheck)) )
|
(isResearched(techToCheck.name) || prerequisites.contains(techToCheck)) )
|
||||||
continue //no need to add or check prerequisites
|
continue //no need to add or check prerequisites
|
||||||
val techToCheck = GameBasics.Technologies[techNameToCheck]
|
for (prerequisite in techToCheck.prerequisites)
|
||||||
for (str in techToCheck!!.prerequisites)
|
checkPrerequisites.add(GameBasics.Technologies[prerequisite]!!)
|
||||||
if (!checkPrerequisites.contains(str)) checkPrerequisites.add(str)
|
prerequisites.add(techToCheck)
|
||||||
prerequisites.add(techNameToCheck)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return prerequisites.reversed()
|
return prerequisites.sortedBy { it.column!!.columnNumber }.map { it.name }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun nextTurn(scienceForNewTurn: Int) {
|
fun nextTurn(scienceForNewTurn: Int) {
|
||||||
|
Reference in New Issue
Block a user