Enemy civs now adopt policies when they can

This commit is contained in:
Yair Morgenstern 2018-05-06 10:38:45 +03:00
parent 1a6e4d30f8
commit c932fffc32
5 changed files with 31 additions and 26 deletions

View file

@ -129,12 +129,9 @@ class UnCivGame : Game() {
branch.branch = branch.name
for (policy in branch.policies) {
policy.branch = branch.name
if (policy.requires == null) {
policy.requires = ArrayList()
policy.requires!!.add(branch.name)
}
if (policy.requires == null) policy.requires = arrayListOf(branch.name)
}
branch.policies[branch.policies.size - 1].name = branch.name + " Complete"
branch.policies.last().name = branch.name + " Complete"
}
}

View file

@ -47,6 +47,13 @@ class Automation {
civInfo.tech.techsResearched.add(techToResearch!!.name)
}
while(civInfo.policies.canAdoptPolicy()){
val adoptablePolicies = GameBasics.PolicyBranches.values.flatMap { it.policies.union(listOf(it))}
.filter { civInfo.policies.isAdoptable(it) }
val policyToAdopt = adoptablePolicies.getRandom()
civInfo.policies.adopt(policyToAdopt)
}
for (unit in civInfo.getCivUnits()) {
automateUnitMoves(unit)
}

View file

@ -34,15 +34,23 @@ class PolicyManager {
fun isAdopted(policyName: String): Boolean = adoptedPolicies.contains(policyName)
fun canAdoptPolicy(): Boolean = storedCulture >= getCultureNeededForNextPolicy()
fun isAdoptable(policy: Policy) = getAdoptedPolicies().containsAll(policy.requires!!)
fun canAdoptPolicy(): Boolean = freePolicies>0 || storedCulture >= getCultureNeededForNextPolicy()
fun adopt(policy: Policy, branchCompletion: Boolean =false) {
if (freePolicies > 0)
freePolicies--
else
storedCulture -= getCultureNeededForNextPolicy()
fun adopt(policy: Policy) {
adoptedPolicies.add(policy.name)
val branch = GameBasics.PolicyBranches[policy.branch]!!
if (branch.policies.count { isAdopted(it.name) } == branch.policies.size - 1) { // All done apart from branch completion
adopt(branch.policies.last()) // add branch completion!
if(!branchCompletion) {
val branch = GameBasics.PolicyBranches[policy.branch]!!
if (branch.policies.count { isAdopted(it.name) } == branch.policies.size - 1) { // All done apart from branch completion
adopt(branch.policies.last(), true) // add branch completion!
}
}
when(policy.name ) {

View file

@ -4,11 +4,10 @@ import com.unciv.models.stats.INamed
open class Policy : INamed {
override lateinit var name: String
@JvmField var description: String? = null
@JvmField var branch: String? = null
@JvmField var row: Int = 0
@JvmField var column: Int = 0
@JvmField var requires: ArrayList<String>? = null
var description: String? = null
var branch: String? = null
var row: Int = 0
var column: Int = 0
var requires: ArrayList<String>? = null
}

View file

@ -41,12 +41,7 @@ class PolicyPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen(
}
rightSideButton.addClickListener {
if (policies.freePolicies > 0)
policies.freePolicies--
else
policies.storedCulture -= policies.getCultureNeededForNextPolicy()
civInfo.policies.adopt(pickedPolicy!!)
game.screen = PolicyPickerScreen(civInfo)
}
@ -79,7 +74,7 @@ class PolicyPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen(
branchTable.pack()
branchGroup.add(branchTable).height(150f).row()
branchGroup.add(getPolicyButton(branch.policies[branch.policies.size - 1], false)) // finisher
branchGroup.add(getPolicyButton(branch.policies.last(), false)) // finisher
topTable.add(branchGroup)
}
@ -89,7 +84,7 @@ class PolicyPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen(
private fun pickPolicy(policy: Policy) {
if (civInfo.policies.isAdopted(policy.name)
|| policy.name.endsWith("Complete")
|| !civInfo.policies.getAdoptedPolicies().containsAll(policy.requires!!)
|| !civInfo.policies.isAdoptable(policy)
|| !civInfo.policies.canAdoptPolicy()) {
rightSideButton.disable()
} else {
@ -112,8 +107,7 @@ class PolicyPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen(
if (civInfo.policies.isAdopted(policy.name)) { // existing
policyButton.color = Color.GREEN
} else if (!civInfo.policies.
getAdoptedPolicies().containsAll(policy.requires!!))
} else if (!civInfo.policies.isAdoptable(policy))
// non-available
{
policyButton.color = Color.GRAY