getResearchAgreementCost() don't need variable, make some method private (#3832)

This commit is contained in:
lishaoxia1985
2021-04-22 21:59:15 +08:00
committed by GitHub
parent cb9507c76d
commit adf32dcfe2
4 changed files with 20 additions and 24 deletions

View File

@ -293,7 +293,7 @@ object NextTurnAutomation {
// Default setting is 5, this will be changed according to different civ. // Default setting is 5, this will be changed according to different civ.
if ((1..10).random() > 5) continue if ((1..10).random() > 5) continue
val tradeLogic = TradeLogic(civInfo, otherCiv) val tradeLogic = TradeLogic(civInfo, otherCiv)
val cost = civInfo.getResearchAgreementCost(otherCiv) val cost = civInfo.getResearchAgreementCost()
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.researchAgreement, TradeType.Treaty, cost)) tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.researchAgreement, TradeType.Treaty, cost))
tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.researchAgreement, TradeType.Treaty, cost)) tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.researchAgreement, TradeType.Treaty, cost))

View File

@ -118,7 +118,7 @@ class CivilizationInfo {
toReturn.victoryManager = victoryManager.clone() toReturn.victoryManager = victoryManager.clone()
toReturn.allyCivName = allyCivName toReturn.allyCivName = allyCivName
for (diplomacyManager in diplomacy.values.map { it.clone() }) for (diplomacyManager in diplomacy.values.map { it.clone() })
toReturn.diplomacy.put(diplomacyManager.otherCivName, diplomacyManager) toReturn.diplomacy[diplomacyManager.otherCivName] = diplomacyManager
toReturn.cities = cities.map { it.clone() } toReturn.cities = cities.map { it.clone() }
// This is the only thing that is NOT switched out, which makes it a source of ConcurrentModification errors. // This is the only thing that is NOT switched out, which makes it a source of ConcurrentModification errors.
@ -165,7 +165,7 @@ class CivilizationInfo {
fun isAlive(): Boolean = !isDefeated() fun isAlive(): Boolean = !isDefeated()
fun hasEverBeenFriendWith(otherCiv: CivilizationInfo): Boolean = getDiplomacyManager(otherCiv).everBeenFriends() fun hasEverBeenFriendWith(otherCiv: CivilizationInfo): Boolean = getDiplomacyManager(otherCiv).everBeenFriends()
fun hasMetCivTerritory(otherCiv: CivilizationInfo): Boolean = otherCiv.getCivTerritory().any { it in exploredTiles } fun hasMetCivTerritory(otherCiv: CivilizationInfo): Boolean = otherCiv.getCivTerritory().any { it in exploredTiles }
fun getCivTerritory() = cities.asSequence().flatMap { it.tiles.asSequence() } private fun getCivTerritory() = cities.asSequence().flatMap { it.tiles.asSequence() }
fun victoryType(): VictoryType { fun victoryType(): VictoryType {
if (gameInfo.gameParameters.victoryTypes.size == 1) if (gameInfo.gameParameters.victoryTypes.size == 1)
@ -267,7 +267,7 @@ class CivilizationInfo {
fun getIdleUnits() = getCivUnits().filter { it.isIdle() } fun getIdleUnits() = getCivUnits().filter { it.isIdle() }
fun getDueUnits() = getCivUnits().filter { it.due && it.isIdle() } private fun getDueUnits() = getCivUnits().filter { it.due && it.isIdle() }
fun shouldGoToDueUnit() = UncivGame.Current.settings.checkForDueUnits && getDueUnits().any() fun shouldGoToDueUnit() = UncivGame.Current.settings.checkForDueUnits && getDueUnits().any()
@ -334,8 +334,8 @@ class CivilizationInfo {
/** Returns true if the civ was fully initialized and has no cities remaining */ /** Returns true if the civ was fully initialized and has no cities remaining */
fun isDefeated(): Boolean { fun isDefeated(): Boolean {
// Dirty hack: exploredTiles are empty only before starting units are placed // Dirty hack: exploredTiles are empty only before starting units are placed
if (exploredTiles.isEmpty() || isBarbarian() || isSpectator()) return false return if (exploredTiles.isEmpty() || isBarbarian() || isSpectator()) false
else return cities.isEmpty() // No cities else cities.isEmpty() // No cities
&& (citiesCreated > 0 || !getCivUnits().any { it.hasUnique(Constants.settlerUnique) }) && (citiesCreated > 0 || !getCivUnits().any { it.hasUnique(Constants.settlerUnique) })
} }
@ -343,12 +343,11 @@ class CivilizationInfo {
if (gameInfo.ruleSet.technologies.isEmpty()) return "None" if (gameInfo.ruleSet.technologies.isEmpty()) return "None"
if (tech.researchedTechnologies.isEmpty()) if (tech.researchedTechnologies.isEmpty())
return gameInfo.ruleSet.getEras().first() return gameInfo.ruleSet.getEras().first()
val maxEraOfTech = tech.researchedTechnologies return tech.researchedTechnologies
.asSequence() .asSequence()
.map { it.column!! } .map { it.column!! }
.maxByOrNull { it.columnNumber }!! .maxByOrNull { it.columnNumber }!!
.era .era
return maxEraOfTech
} }
fun getEraNumber(): Int = gameInfo.ruleSet.getEraNumber(getEra()) fun getEraNumber(): Int = gameInfo.ruleSet.getEraNumber(getEra())
@ -383,7 +382,7 @@ class CivilizationInfo {
fun canSignResearchAgreementsWith(otherCiv: CivilizationInfo): Boolean { fun canSignResearchAgreementsWith(otherCiv: CivilizationInfo): Boolean {
val diplomacyManager = getDiplomacyManager(otherCiv) val diplomacyManager = getDiplomacyManager(otherCiv)
val cost = getResearchAgreementCost(otherCiv) val cost = getResearchAgreementCost()
return canSignResearchAgreement() && otherCiv.canSignResearchAgreement() return canSignResearchAgreement() && otherCiv.canSignResearchAgreement()
&& diplomacyManager.hasFlag(DiplomacyFlags.DeclarationOfFriendship) && diplomacyManager.hasFlag(DiplomacyFlags.DeclarationOfFriendship)
&& !diplomacyManager.hasFlag(DiplomacyFlags.ResearchAgreement) && !diplomacyManager.hasFlag(DiplomacyFlags.ResearchAgreement)
@ -619,7 +618,7 @@ class CivilizationInfo {
updateStatsForNextTurn() updateStatsForNextTurn()
} }
fun getResearchAgreementCost(otherCiv: CivilizationInfo): Int { fun getResearchAgreementCost(): Int {
// https://forums.civfanatics.com/resources/research-agreements-bnw.25568/ // https://forums.civfanatics.com/resources/research-agreements-bnw.25568/
val basicGoldCostOfSignResearchAgreement = when (getEra()) { val basicGoldCostOfSignResearchAgreement = when (getEra()) {
Constants.medievalEra, Constants.renaissanceEra -> 250 Constants.medievalEra, Constants.renaissanceEra -> 250

View File

@ -1,7 +1,5 @@
package com.unciv.logic.civilization package com.unciv.logic.civilization
import com.badlogic.gdx.graphics.Color
import com.unciv.logic.map.MapSize import com.unciv.logic.map.MapSize
import com.unciv.logic.map.RoadStatus import com.unciv.logic.map.RoadStatus
import com.unciv.models.ruleset.Unique import com.unciv.models.ruleset.Unique
@ -70,7 +68,7 @@ class TechManager {
fun getNumberOfTechsResearched(): Int = techsResearched.size fun getNumberOfTechsResearched(): Int = techsResearched.size
fun getRuleset() = civInfo.gameInfo.ruleSet private fun getRuleset() = civInfo.gameInfo.ruleSet
fun costOfTech(techName: String): Int { fun costOfTech(techName: String): Int {
var techCost = getRuleset().technologies[techName]!!.cost.toFloat() var techCost = getRuleset().technologies[techName]!!.cost.toFloat()
@ -156,7 +154,7 @@ class TechManager {
return (scienceOfLast8Turns.sum() * civInfo.gameInfo.gameParameters.gameSpeed.modifier).toInt() return (scienceOfLast8Turns.sum() * civInfo.gameInfo.gameParameters.gameSpeed.modifier).toInt()
} }
fun addCurrentScienceToScienceOfLast8Turns() { private fun addCurrentScienceToScienceOfLast8Turns() {
// The Science the Great Scientist generates does not include Science from Policies, Trade routes and City-States. // The Science the Great Scientist generates does not include Science from Policies, Trade routes and City-States.
var allCitiesScience = 0f var allCitiesScience = 0f
civInfo.cities.forEach { it -> civInfo.cities.forEach { it ->
@ -167,11 +165,11 @@ class TechManager {
scienceOfLast8Turns[civInfo.gameInfo.turns % 8] = allCitiesScience.toInt() scienceOfLast8Turns[civInfo.gameInfo.turns % 8] = allCitiesScience.toInt()
} }
fun limitOverflowScience(overflowscience: Int): Int { private fun limitOverflowScience(overflowScience: Int): Int {
// http://www.civclub.net/bbs/forum.php?mod=viewthread&tid=123976 // http://www.civclub.net/bbs/forum.php?mod=viewthread&tid=123976
// Apparently yes, we care about the absolute tech cost, not the actual calculated-for-this-player tech cost, // Apparently yes, we care about the absolute tech cost, not the actual calculated-for-this-player tech cost,
// so don't change to costOfTech() // so don't change to costOfTech()
return min(overflowscience, max(civInfo.statsForNextTurn.science.toInt() * 5, return min(overflowScience, max(civInfo.statsForNextTurn.science.toInt() * 5,
getRuleset().technologies[currentTechnologyName()]!!.cost)) getRuleset().technologies[currentTechnologyName()]!!.cost))
} }
@ -280,11 +278,10 @@ class TechManager {
val oldQueue = city.cityConstructions.constructionQueue.toList() // copy, since we're changing the queue val oldQueue = city.cityConstructions.constructionQueue.toList() // copy, since we're changing the queue
city.cityConstructions.constructionQueue.clear() city.cityConstructions.constructionQueue.clear()
for (constructionName in oldQueue) { for (constructionName in oldQueue) {
val newConstructionName = constructionName
if (constructionName in obsoleteUnits) { if (constructionName in obsoleteUnits) {
val text = "[$constructionName] has been obsolete and will be removed from construction queue in [${city.name}]!" val text = "[$constructionName] has been obsolete and will be removed from construction queue in [${city.name}]!"
civInfo.addNotification(text, city.location, NotificationIcon.Construction) civInfo.addNotification(text, city.location, NotificationIcon.Construction)
} else city.cityConstructions.constructionQueue.add(newConstructionName) } else city.cityConstructions.constructionQueue.add(constructionName)
} }
} }
@ -300,7 +297,7 @@ class TechManager {
updateTransientBooleans() updateTransientBooleans()
} }
fun updateTransientBooleans() { private fun updateTransientBooleans() {
wayfinding = civInfo.hasUnique("Can embark and move over Coasts and Oceans immediately") wayfinding = civInfo.hasUnique("Can embark and move over Coasts and Oceans immediately")
unitsCanEmbark = wayfinding || civInfo.hasUnique("Enables embarkation for land units") unitsCanEmbark = wayfinding || civInfo.hasUnique("Enables embarkation for land units")

View File

@ -26,10 +26,10 @@ import com.unciv.ui.utils.AutoScrollPane as ScrollPane
class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
val leftSideTable = Table().apply { defaults().pad(10f) } private val leftSideTable = Table().apply { defaults().pad(10f) }
val rightSideTable = Table() private val rightSideTable = Table()
fun isNotPlayersTurn() = !UncivGame.Current.worldScreen.isPlayersTurn private fun isNotPlayersTurn() = !UncivGame.Current.worldScreen.isPlayersTurn
init { init {
onBackButtonClicked { UncivGame.Current.setWorldScreen() } onBackButtonClicked { UncivGame.Current.setWorldScreen() }
@ -285,7 +285,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
if (viewingCiv.canSignResearchAgreementsWith(otherCiv)) { if (viewingCiv.canSignResearchAgreementsWith(otherCiv)) {
val researchAgreementButton = "Research Agreement".toTextButton() val researchAgreementButton = "Research Agreement".toTextButton()
val requiredGold = viewingCiv.getResearchAgreementCost(otherCiv) val requiredGold = viewingCiv.getResearchAgreementCost()
researchAgreementButton.onClick { researchAgreementButton.onClick {
val tradeTable = setTrade(otherCiv) val tradeTable = setTrade(otherCiv)
val researchAgreement = TradeOffer(Constants.researchAgreement, TradeType.Treaty, requiredGold) val researchAgreement = TradeOffer(Constants.researchAgreement, TradeType.Treaty, requiredGold)
@ -390,7 +390,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
return demandsTable return demandsTable
} }
fun getRelationshipTable(otherCivDiplomacyManager: DiplomacyManager): Table { private fun getRelationshipTable(otherCivDiplomacyManager: DiplomacyManager): Table {
val relationshipTable = Table() val relationshipTable = Table()
val opinionOfUs = if (otherCivDiplomacyManager.civInfo.isCityState()) otherCivDiplomacyManager.influence.toInt() val opinionOfUs = if (otherCivDiplomacyManager.civInfo.isCityState()) otherCivDiplomacyManager.influence.toInt()