mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-20 04:38:18 +07:00
Organized Modern Era techs
Free techs are added like regular techs - with all the abilities and notifications thereof
This commit is contained in:
@ -60,6 +60,24 @@ class TechManager {
|
||||
|
||||
//endregion
|
||||
|
||||
fun getRequiredTechsToDestination(destinationTech: Technology): List<String> {
|
||||
val prerequisites = Stack<String>()
|
||||
val checkPrerequisites = ArrayDeque<String>()
|
||||
checkPrerequisites.add(destinationTech.name)
|
||||
|
||||
while (!checkPrerequisites.isEmpty()) {
|
||||
val techNameToCheck = checkPrerequisites.pop()
|
||||
if (isResearched(techNameToCheck) || prerequisites.contains(techNameToCheck))
|
||||
continue //no need to add or check prerequisites
|
||||
val techToCheck = GameBasics.Technologies[techNameToCheck]
|
||||
for (str in techToCheck!!.prerequisites)
|
||||
if (!checkPrerequisites.contains(str)) checkPrerequisites.add(str)
|
||||
prerequisites.add(techNameToCheck)
|
||||
}
|
||||
|
||||
return prerequisites.reversed()
|
||||
}
|
||||
|
||||
fun nextTurn(scienceForNewTurn: Int) {
|
||||
val currentTechnology = currentTechnology()
|
||||
if (currentTechnology == null) return
|
||||
@ -67,27 +85,36 @@ class TechManager {
|
||||
if (techsInProgress[currentTechnology]!! < costOfTech(currentTechnology))
|
||||
return
|
||||
|
||||
val previousEra = civInfo.getEra()
|
||||
|
||||
// We finished it!
|
||||
techsInProgress.remove(currentTechnology)
|
||||
if(currentTechnology!="Future Tech")
|
||||
techsToResearch.remove(currentTechnology)
|
||||
techsResearched.add(currentTechnology)
|
||||
addTechnology(currentTechnology)
|
||||
}
|
||||
|
||||
fun getFreeTechnology(techName:String){
|
||||
freeTechs--
|
||||
addTechnology(techName)
|
||||
}
|
||||
|
||||
private fun addTechnology(techName:String) {
|
||||
if(techName!="Future Tech")
|
||||
techsToResearch.remove(techName)
|
||||
|
||||
val previousEra = civInfo.getEra()
|
||||
techsResearched.add(techName)
|
||||
|
||||
// this is to avoid concurrent modification problems
|
||||
researchedTechnologies = researchedTechnologies.withItem(GameBasics.Technologies[currentTechnology]!!)
|
||||
researchedTechnologies = researchedTechnologies.withItem(GameBasics.Technologies[techName]!!)
|
||||
|
||||
civInfo.addNotification("Research of [$currentTechnology] has completed!", null, Color.BLUE)
|
||||
civInfo.addNotification("Research of [$techName] has completed!", null, Color.BLUE)
|
||||
|
||||
val currentEra = civInfo.getEra()
|
||||
if(previousEra < currentEra){
|
||||
civInfo.addNotification("You have entered the [$currentEra] era!".tr(),null,Color.GOLD)
|
||||
GameBasics.PolicyBranches.values.filter { it.era==currentEra }
|
||||
.forEach{civInfo.addNotification("["+it.name+"] policy branch unlocked!".tr(),null,Color.PURPLE)}
|
||||
if (previousEra < currentEra) {
|
||||
civInfo.addNotification("You have entered the [$currentEra] era!".tr(), null, Color.GOLD)
|
||||
GameBasics.PolicyBranches.values.filter { it.era == currentEra }
|
||||
.forEach { civInfo.addNotification("[" + it.name + "] policy branch unlocked!".tr(), null, Color.PURPLE) }
|
||||
}
|
||||
|
||||
val revealedResource = GameBasics.TileResources.values.firstOrNull { currentTechnology == it.revealedBy }
|
||||
val revealedResource = GameBasics.TileResources.values.firstOrNull { techName == it.revealedBy }
|
||||
|
||||
if (revealedResource != null) {
|
||||
for (tileInfo in civInfo.gameInfo.tileMap.values
|
||||
@ -96,22 +123,26 @@ class TechManager {
|
||||
val closestCityTile = tileInfo.getTilesInDistance(4)
|
||||
.firstOrNull { it.isCityCenter() }
|
||||
if (closestCityTile != null) {
|
||||
civInfo.addNotification("{"+revealedResource.name + "} {revealed near} "
|
||||
civInfo.addNotification("{" + revealedResource.name + "} {revealed near} "
|
||||
+ closestCityTile.getCity()!!.name, tileInfo.position, Color.BLUE) // todo change to [] notation
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val obsoleteUnits = GameBasics.Units.values.filter { it.obsoleteTech==currentTechnology }
|
||||
for(city in civInfo.cities)
|
||||
if(city.cityConstructions.getCurrentConstruction() in obsoleteUnits){
|
||||
val obsoleteUnits = GameBasics.Units.values.filter { it.obsoleteTech == techName }
|
||||
for (city in civInfo.cities)
|
||||
if (city.cityConstructions.getCurrentConstruction() in obsoleteUnits) {
|
||||
val currentConstructionUnit = city.cityConstructions.getCurrentConstruction() as BaseUnit
|
||||
city.cityConstructions.currentConstruction = currentConstructionUnit.upgradesTo!!
|
||||
}
|
||||
}
|
||||
|
||||
fun setTransients(){
|
||||
// As of 2.10.16, removed mass media, since our tech tree is like G&K
|
||||
techsResearched.remove("Mass Media")
|
||||
techsToResearch.remove("Mass Media")
|
||||
|
||||
researchedTechnologies.addAll(techsResearched.map { GameBasics.Technologies[it]!! })
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
|
||||
private var isFreeTechPick: Boolean = false
|
||||
private var selectedTech: Technology? = null
|
||||
private var civTech: TechManager = civInfo.tech
|
||||
private var techsToResearch: ArrayList<String>
|
||||
private var tempTechsToResearch: ArrayList<String>
|
||||
|
||||
// All these are to counter performance problems when updating buttons for all techs.
|
||||
private var researchableTechs = GameBasics.Technologies.keys
|
||||
@ -39,7 +39,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
|
||||
init {
|
||||
onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() }
|
||||
|
||||
techsToResearch = ArrayList(civTech.techsToResearch)
|
||||
tempTechsToResearch = ArrayList(civTech.techsToResearch)
|
||||
|
||||
val columns = 17
|
||||
val techMatrix = Array<Array<Technology?>>(columns) { arrayOfNulls(10) } // Divided into columns, then rows
|
||||
@ -68,7 +68,8 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
|
||||
selectTechnology(tech)
|
||||
}
|
||||
topTable.add(techButton)
|
||||
if(eras[j].text.toString()=="") eras[j].setText((tech.era().toString()+" era").tr())
|
||||
if(eras[j].text.toString()=="") // name of era was not yet set
|
||||
eras[j].setText((tech.era().toString()+" era").tr())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -78,13 +79,9 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
|
||||
rightSideButton.setText("Pick a tech".tr())
|
||||
rightSideButton.onClick {
|
||||
if (isFreeTechPick) {
|
||||
civTech.techsResearched.add(selectedTech!!.name)
|
||||
if (civTech.techsToResearch.contains(selectedTech!!.name)) {
|
||||
civTech.techsToResearch.remove(selectedTech!!.name)
|
||||
}
|
||||
civTech.freeTechs -= 1
|
||||
civTech.getFreeTechnology(selectedTech!!.name)
|
||||
} else
|
||||
civTech.techsToResearch = techsToResearch
|
||||
civTech.techsToResearch = tempTechsToResearch
|
||||
game.setWorldScreen()
|
||||
game.worldScreen.shouldUpdate=true
|
||||
dispose()
|
||||
@ -98,8 +95,8 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
|
||||
val techButton = techNameToButton[techName]!!
|
||||
when {
|
||||
civTech.isResearched(techName) && techName!="Future Tech" -> techButton.color = researchedTechColor
|
||||
techsToResearch.isNotEmpty() && techsToResearch.first() == techName -> techButton.color = currentTechColor
|
||||
techsToResearch.contains(techName) -> techButton.color = queuedTechColor
|
||||
tempTechsToResearch.isNotEmpty() && tempTechsToResearch.first() == techName -> techButton.color = currentTechColor
|
||||
tempTechsToResearch.contains(techName) -> techButton.color = queuedTechColor
|
||||
researchableTechs.contains(techName) -> techButton.color = researchableTechColor
|
||||
else -> techButton.color = Color.BLACK
|
||||
}
|
||||
@ -110,8 +107,8 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
|
||||
techButton.color = techButton.color.cpy().lerp(Color.LIGHT_GRAY, 0.5f)
|
||||
}
|
||||
|
||||
if (techsToResearch.contains(techName) && techsToResearch.size > 1) {
|
||||
text += " (" + techsToResearch.indexOf(techName) + ")"
|
||||
if (tempTechsToResearch.contains(techName) && tempTechsToResearch.size > 1) {
|
||||
text += " (" + tempTechsToResearch.indexOf(techName) + ")"
|
||||
}
|
||||
|
||||
if (!civTech.isResearched(techName) || techName=="Future Tech")
|
||||
@ -129,37 +126,22 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
|
||||
return
|
||||
}
|
||||
|
||||
if (civTech.isResearched(tech.name) && tech.name!="Future Tech") {
|
||||
if (civTech.isResearched(tech.name) && tech.name != "Future Tech") {
|
||||
rightSideButton.setText("Pick a tech".tr())
|
||||
rightSideButton.disable()
|
||||
setButtonsInfo()
|
||||
return
|
||||
}
|
||||
|
||||
if (researchableTechs.contains(tech.name)) {
|
||||
techsToResearch.clear()
|
||||
techsToResearch.add(tech.name)
|
||||
} else {
|
||||
val prerequisites = Stack<String>()
|
||||
val checkPrerequisites = ArrayDeque<String>()
|
||||
checkPrerequisites.add(tech.name)
|
||||
while (!checkPrerequisites.isEmpty()) {
|
||||
val techNameToCheck = checkPrerequisites.pop()
|
||||
if (civTech.isResearched(techNameToCheck) || prerequisites.contains(techNameToCheck))
|
||||
continue //no need to add or check prerequisites
|
||||
val techToCheck = GameBasics.Technologies[techNameToCheck]
|
||||
for (str in techToCheck!!.prerequisites)
|
||||
if (!checkPrerequisites.contains(str)) checkPrerequisites.add(str)
|
||||
prerequisites.add(techNameToCheck)
|
||||
}
|
||||
techsToResearch.clear()
|
||||
while (!prerequisites.isEmpty()) techsToResearch.add(prerequisites.pop())
|
||||
}
|
||||
tempTechsToResearch.clear()
|
||||
tempTechsToResearch.addAll(civTech.getRequiredTechsToDestination(tech))
|
||||
|
||||
pick("Research [${techsToResearch[0]}]".tr())
|
||||
pick("Research [${tempTechsToResearch[0]}]".tr())
|
||||
setButtonsInfo()
|
||||
}
|
||||
|
||||
|
||||
|
||||
private fun selectTechnologyForFreeTech(tech: Technology) {
|
||||
if (researchableTechs.contains(tech.name)) {
|
||||
pick("Pick [${selectedTech!!.name}] as free tech".tr())
|
||||
|
Reference in New Issue
Block a user