mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-22 13:49:54 +07:00
Added a check to see if a policy effect was active - this is an important step towards "different effects for the same policy name", as happens between Vanilla and G&K/BNW
This commit is contained in:
@ -4,6 +4,7 @@ import com.unciv.Constants
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.UniqueAbility
|
||||
import com.unciv.logic.civilization.CityStateType
|
||||
import com.unciv.logic.civilization.PolicyManager
|
||||
import com.unciv.logic.civilization.diplomacy.RelationshipLevel
|
||||
import com.unciv.logic.map.RoadStatus
|
||||
import com.unciv.models.ruleset.Building
|
||||
@ -254,25 +255,25 @@ class CityStats {
|
||||
return stats
|
||||
}
|
||||
|
||||
private fun getStatsFromPolicies(adoptedPolicies: HashSet<String>): Stats {
|
||||
private fun getStatsFromPolicies(adoptedPolicies: PolicyManager): Stats {
|
||||
val stats = Stats()
|
||||
if (adoptedPolicies.contains("Tradition") && cityInfo.isCapital())
|
||||
if (adoptedPolicies.isAdopted("Tradition") && cityInfo.isCapital())
|
||||
stats.culture += 3f
|
||||
if (adoptedPolicies.contains("Landed Elite") && cityInfo.isCapital())
|
||||
if (adoptedPolicies.isAdopted("Landed Elite") && cityInfo.isCapital())
|
||||
stats.food += 2f
|
||||
if (adoptedPolicies.contains("Tradition Complete"))
|
||||
if (adoptedPolicies.isAdopted("Tradition Complete"))
|
||||
stats.food += 2f
|
||||
if (adoptedPolicies.contains("Monarchy") && cityInfo.isCapital())
|
||||
if (adoptedPolicies.isAdopted("Monarchy") && cityInfo.isCapital())
|
||||
stats.gold += (cityInfo.population.population / 2).toFloat()
|
||||
if (adoptedPolicies.contains("Liberty"))
|
||||
if (adoptedPolicies.hasEffect("+1 culture in every city"))
|
||||
stats.culture += 1f
|
||||
if (adoptedPolicies.contains("Republic"))
|
||||
if (adoptedPolicies.isAdopted("Republic"))
|
||||
stats.production += 1f
|
||||
if (adoptedPolicies.contains("Military Caste") && cityInfo.getCenterTile().militaryUnit != null)
|
||||
if (adoptedPolicies.isAdopted("Military Caste") && cityInfo.getCenterTile().militaryUnit != null)
|
||||
stats.culture += 2
|
||||
if (adoptedPolicies.contains("Universal Suffrage"))
|
||||
if (adoptedPolicies.isAdopted("Universal Suffrage"))
|
||||
stats.production += (cityInfo.population.population / 5).toFloat()
|
||||
if (adoptedPolicies.contains("Free Speech"))
|
||||
if (adoptedPolicies.isAdopted("Free Speech"))
|
||||
stats.culture += (cityInfo.population.population / 2).toFloat()
|
||||
|
||||
return stats
|
||||
@ -367,7 +368,7 @@ class CityStats {
|
||||
newBaseStatList["Specialists"] = getStatsFromSpecialists(cityInfo.population.specialists, civInfo.policies.adoptedPolicies)
|
||||
newBaseStatList["Trade routes"] = getStatsFromTradeRoute()
|
||||
newBaseStatList["Buildings"] = cityInfo.cityConstructions.getStats()
|
||||
newBaseStatList["Policies"] = getStatsFromPolicies(civInfo.policies.adoptedPolicies)
|
||||
newBaseStatList["Policies"] = getStatsFromPolicies(civInfo.policies)
|
||||
newBaseStatList["National ability"] = getStatsFromNationUnique()
|
||||
newBaseStatList["City States"] = getStatsFromCityStates()
|
||||
|
||||
|
@ -347,6 +347,7 @@ class CivilizationInfo {
|
||||
policies.civInfo = this
|
||||
if(policies.adoptedPolicies.size>0 && policies.numberOfAdoptedPolicies == 0)
|
||||
policies.numberOfAdoptedPolicies = policies.adoptedPolicies.count { !it.endsWith("Complete") }
|
||||
policies.setTransients()
|
||||
|
||||
if(citiesCreated==0 && cities.any())
|
||||
citiesCreated = cities.filter { it.name in nation.cities }.count()
|
||||
|
@ -11,6 +11,9 @@ import kotlin.math.roundToInt
|
||||
class PolicyManager {
|
||||
|
||||
@Transient lateinit var civInfo: CivilizationInfo
|
||||
// Needs to be separate from the actual adopted policies, so that
|
||||
// in different game versions, policies can have different effects
|
||||
@Transient internal val policyEffects = HashSet<String>()
|
||||
|
||||
var freePolicies = 0
|
||||
var storedCulture = 0
|
||||
@ -33,6 +36,15 @@ class PolicyManager {
|
||||
return toReturn
|
||||
}
|
||||
|
||||
fun setTransients(){
|
||||
val allPolicies = getAllPolicies()
|
||||
val effectsOfCurrentPolicies = adoptedPolicies.map { adoptedPolicy -> allPolicies.first { it.name==adoptedPolicy }.effect }
|
||||
policyEffects.addAll(effectsOfCurrentPolicies)
|
||||
}
|
||||
|
||||
private fun getAllPolicies() = civInfo.gameInfo.ruleSet.policyBranches.values.asSequence()
|
||||
.flatMap { it.policies.asSequence()+sequenceOf(it) }
|
||||
|
||||
fun startTurn() {
|
||||
if (isAdopted("Legalism") && legalismState.size < 4)
|
||||
tryAddLegalismBuildings()
|
||||
@ -68,6 +80,8 @@ class PolicyManager {
|
||||
|
||||
fun isAdopted(policyName: String): Boolean = adoptedPolicies.contains(policyName)
|
||||
|
||||
fun hasEffect(effectName:String) = policyEffects.contains(effectName)
|
||||
|
||||
fun isAdoptable(policy: Policy): Boolean {
|
||||
if(isAdopted(policy.name)) return false
|
||||
if (policy.name.endsWith("Complete")) return false
|
||||
@ -80,8 +94,7 @@ class PolicyManager {
|
||||
if (freePolicies == 0 && storedCulture < getCultureNeededForNextPolicy())
|
||||
return false
|
||||
|
||||
val hasAdoptablePolicies = civInfo.gameInfo.ruleSet.policyBranches.values
|
||||
.flatMap { it.policies.union(listOf(it)) }
|
||||
val hasAdoptablePolicies = getAllPolicies()
|
||||
.any { civInfo.policies.isAdoptable(it) }
|
||||
return hasAdoptablePolicies
|
||||
}
|
||||
@ -100,6 +113,7 @@ class PolicyManager {
|
||||
}
|
||||
|
||||
adoptedPolicies.add(policy.name)
|
||||
policyEffects.add(policy.effect)
|
||||
|
||||
if (!branchCompletion) {
|
||||
val branch = policy.branch
|
||||
|
@ -6,7 +6,7 @@ open class Policy : INamed {
|
||||
lateinit var branch: PolicyBranch // not in json - added in gameBasics
|
||||
|
||||
override lateinit var name: String
|
||||
lateinit var description: String
|
||||
lateinit var effect: String
|
||||
var row: Int = 0
|
||||
var column: Int = 0
|
||||
var requires: ArrayList<String>? = null
|
||||
|
@ -9,7 +9,7 @@ class Promotion : INamed{
|
||||
override lateinit var name: String
|
||||
var prerequisites = listOf<String>()
|
||||
lateinit var effect:String
|
||||
var unitTypes = listOf<String>() // The json parser woulddn't agree to deserialize this as a list of UnitTypes. =(
|
||||
var unitTypes = listOf<String>() // The json parser wouldn't agree to deserialize this as a list of UnitTypes. =(
|
||||
|
||||
fun getDescription(promotionsForUnitType: Collection<Promotion>, forCivilopedia:Boolean=false, ruleSet:Ruleset? = null):String {
|
||||
// we translate it before it goes in to get uniques like "vs units in rough terrain" and after to get "vs city
|
||||
|
@ -93,7 +93,7 @@ class PolicyPickerScreen(val worldScreen: WorldScreen, civInfo: CivilizationInfo
|
||||
rightSideButton.enable()
|
||||
}
|
||||
pickedPolicy = policy
|
||||
var policyText = policy.name.tr() + "\r\n" + policy.description.tr() + "\r\n"
|
||||
var policyText = policy.name.tr() + "\r\n" + policy.effect.tr() + "\r\n"
|
||||
if (!policy.name.endsWith("Complete")){
|
||||
if(policy.requires!!.isNotEmpty())
|
||||
policyText += "{Requires} ".tr() + policy.requires!!.joinToString { it.tr() }
|
||||
|
Reference in New Issue
Block a user