mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-10 07:48:31 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@ -13,6 +13,7 @@ import com.unciv.logic.map.BFS
|
||||
import com.unciv.logic.map.MapUnit
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.logic.trade.*
|
||||
import com.unciv.models.Counter
|
||||
import com.unciv.models.ruleset.Belief
|
||||
import com.unciv.models.ruleset.BeliefType
|
||||
import com.unciv.models.ruleset.ModOptionsConstants
|
||||
@ -22,7 +23,6 @@ import com.unciv.models.ruleset.tile.ResourceType
|
||||
import com.unciv.models.ruleset.unit.BaseUnit
|
||||
import com.unciv.models.stats.Stat
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.pickerscreens.BeliefContainer
|
||||
import com.unciv.ui.victoryscreen.RankingType
|
||||
import kotlin.math.min
|
||||
|
||||
@ -339,35 +339,26 @@ object NextTurnAutomation {
|
||||
)
|
||||
}
|
||||
|
||||
private fun chooseBeliefs(civInfo: CivilizationInfo, beliefContainer: BeliefContainer): HashSet<Belief> {
|
||||
private fun chooseBeliefs(civInfo: CivilizationInfo, beliefsToChoose: Counter<BeliefType>): HashSet<Belief> {
|
||||
val chosenBeliefs = hashSetOf<Belief>()
|
||||
// The `continue`s should never be reached, but just in case I'd rather have the AI have a
|
||||
// belief less than make the game crash. The `continue`s should only be reached whenever
|
||||
// there are not enough beliefs to choose, but there should be, as otherwise we could
|
||||
// not have used a great prophet to found/enhance our religion.
|
||||
for (counter in 0 until beliefContainer.pantheonBeliefCount)
|
||||
chosenBeliefs.add(
|
||||
chooseBeliefOfType(civInfo, BeliefType.Pantheon, chosenBeliefs) ?: continue
|
||||
)
|
||||
for (counter in 0 until beliefContainer.followerBeliefCount)
|
||||
chosenBeliefs.add(
|
||||
chooseBeliefOfType(civInfo, BeliefType.Follower, chosenBeliefs) ?: continue
|
||||
)
|
||||
for (counter in 0 until beliefContainer.founderBeliefCount)
|
||||
chosenBeliefs.add(
|
||||
chooseBeliefOfType(civInfo, BeliefType.Founder, chosenBeliefs) ?: continue
|
||||
)
|
||||
for (counter in 0 until beliefContainer.enhancerBeliefCount)
|
||||
chosenBeliefs.add(
|
||||
chooseBeliefOfType(civInfo, BeliefType.Enhancer, chosenBeliefs) ?: continue
|
||||
)
|
||||
for (belief in BeliefType.values()) {
|
||||
if (belief == BeliefType.None) continue
|
||||
for (counter in 0 until (beliefsToChoose[belief] ?: 0))
|
||||
chosenBeliefs.add(
|
||||
chooseBeliefOfType(civInfo, belief, chosenBeliefs) ?: continue
|
||||
)
|
||||
}
|
||||
return chosenBeliefs
|
||||
}
|
||||
|
||||
private fun chooseBeliefOfType(civInfo: CivilizationInfo, beliefType: BeliefType, additionalBeliefsToExclude: HashSet<Belief> = hashSetOf()): Belief? {
|
||||
return civInfo.gameInfo.ruleSet.beliefs
|
||||
.filter {
|
||||
it.value.type == beliefType
|
||||
(it.value.type == beliefType || beliefType == BeliefType.Any)
|
||||
&& !additionalBeliefsToExclude.contains(it.value)
|
||||
&& !civInfo.gameInfo.religions.values
|
||||
.flatMap { religion -> religion.getBeliefs(beliefType) }.contains(it.value)
|
||||
|
@ -1,10 +1,11 @@
|
||||
package com.unciv.logic.civilization
|
||||
|
||||
import com.unciv.logic.map.MapUnit
|
||||
import com.unciv.models.Counter
|
||||
import com.unciv.models.Religion
|
||||
import com.unciv.models.ruleset.Belief
|
||||
import com.unciv.models.ruleset.BeliefType
|
||||
import com.unciv.ui.pickerscreens.BeliefContainer
|
||||
import com.unciv.models.ruleset.unique.UniqueType
|
||||
import com.unciv.ui.utils.toPercent
|
||||
import kotlin.random.Random
|
||||
|
||||
@ -204,10 +205,23 @@ class ReligionManager {
|
||||
civInfo.religionManager.foundingCityId = prophet.getTile().getCity()!!.id
|
||||
}
|
||||
|
||||
fun getBeliefsToChooseAtFounding(): BeliefContainer {
|
||||
fun getBeliefsToChooseAtFounding(): Counter<BeliefType> {
|
||||
val beliefsToChoose: Counter<BeliefType> = Counter()
|
||||
beliefsToChoose.add(BeliefType.Founder, 1)
|
||||
beliefsToChoose.add(BeliefType.Follower, 1)
|
||||
if (shouldChoosePantheonBelief)
|
||||
return BeliefContainer(pantheonBeliefCount = 1, founderBeliefCount = 1, followerBeliefCount = 1)
|
||||
return BeliefContainer(founderBeliefCount = 1, followerBeliefCount = 1)
|
||||
beliefsToChoose.add(BeliefType.Pantheon, 1)
|
||||
|
||||
for (unique in civInfo.getMatchingUniques(UniqueType.FreeExtraBeliefs)) {
|
||||
if (unique.params[2] != "founding") continue
|
||||
beliefsToChoose.add(BeliefType.valueOf(unique.params[1]), unique.params[0].toInt())
|
||||
}
|
||||
for (unique in civInfo.getMatchingUniques(UniqueType.FreeExtraAnyBeliefs)) {
|
||||
if (unique.params[1] != "founding") continue
|
||||
beliefsToChoose.add(BeliefType.Any, unique.params[0].toInt())
|
||||
}
|
||||
|
||||
return beliefsToChoose
|
||||
}
|
||||
|
||||
fun chooseBeliefs(iconName: String?, religionName: String?, beliefs: List<Belief>) {
|
||||
@ -288,8 +302,21 @@ class ReligionManager {
|
||||
religionState = ReligionState.EnhancingReligion
|
||||
}
|
||||
|
||||
fun getBeliefsToChooseAtEnhancing(): BeliefContainer {
|
||||
return BeliefContainer(followerBeliefCount = 1, enhancerBeliefCount = 1)
|
||||
fun getBeliefsToChooseAtEnhancing(): Counter<BeliefType> {
|
||||
val beliefsToChoose: Counter<BeliefType> = Counter()
|
||||
beliefsToChoose.add(BeliefType.Follower, 1)
|
||||
beliefsToChoose.add(BeliefType.Enhancer, 1)
|
||||
|
||||
for (unique in civInfo.getMatchingUniques(UniqueType.FreeExtraBeliefs)) {
|
||||
if (unique.params[2] != "enhancing") continue
|
||||
beliefsToChoose.add(BeliefType.valueOf(unique.params[1]), unique.params[0].toInt())
|
||||
}
|
||||
for (unique in civInfo.getMatchingUniques(UniqueType.FreeExtraAnyBeliefs)) {
|
||||
if (unique.params[1] != "enhancing") continue
|
||||
beliefsToChoose.add(BeliefType.Any, unique.params[0].toInt())
|
||||
}
|
||||
|
||||
return beliefsToChoose
|
||||
}
|
||||
|
||||
fun enhanceReligion(beliefs: List<Belief>) {
|
||||
|
@ -71,7 +71,8 @@ class Belief : RulesetObject() {
|
||||
enum class BeliefType(val color: String) {
|
||||
None(""),
|
||||
Pantheon("#44c6cc"),
|
||||
Follower("#ccaa44"),
|
||||
Founder("#c00000"),
|
||||
Enhancer("#72cc45")
|
||||
Follower("#ccaa44"),
|
||||
Enhancer("#72cc45"),
|
||||
Any(""),
|
||||
}
|
||||
|
@ -92,6 +92,9 @@ enum class UniqueType(val text:String, vararg targets: UniqueTarget) {
|
||||
ProvidesFreeBuildings("Provides a free [buildingName] [cityFilter]", UniqueTarget.Global),
|
||||
GainFreeBuildings("Gain a free [buildingName] [cityFilter]", UniqueTarget.Global),
|
||||
|
||||
FreeExtraBeliefs("May choose [amount] additional [beliefType] beliefs when [foundingOrEnhancing] a religion", UniqueTarget.Global),
|
||||
FreeExtraAnyBeliefs("May choose [amount] additional of any type when [foundingOrEnhancing] a religion", UniqueTarget.Global),
|
||||
|
||||
// I don't like the fact that currently "city state bonuses" are separate from the "global bonuses",
|
||||
// todo: merge city state bonuses into global bonuses
|
||||
CityStateStatsPerTurn("Provides [stats] per turn", UniqueTarget.CityState), // Should not be Happiness!
|
||||
|
@ -7,6 +7,7 @@ import com.unciv.Constants
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.models.Counter
|
||||
import com.unciv.models.Religion
|
||||
import com.unciv.models.UncivSound
|
||||
import com.unciv.models.ruleset.Belief
|
||||
@ -17,7 +18,7 @@ import com.unciv.ui.utils.*
|
||||
class ReligiousBeliefsPickerScreen (
|
||||
private val choosingCiv: CivilizationInfo,
|
||||
private val gameInfo: GameInfo,
|
||||
private val beliefsContainer: BeliefContainer,
|
||||
private val beliefsToChoose: Counter<BeliefType>,
|
||||
private val pickIconAndName: Boolean
|
||||
): PickerScreen(disableScroll = true) {
|
||||
|
||||
@ -31,6 +32,8 @@ class ReligiousBeliefsPickerScreen (
|
||||
private var previouslySelectedIcon: Button? = null
|
||||
private var displayName: String? = null
|
||||
private var religionName: String? = null
|
||||
|
||||
private val chosenBeliefs: Array<Belief?> = Array(beliefsToChoose.values.sum()) { null }
|
||||
|
||||
init {
|
||||
closeButton.isVisible = true
|
||||
@ -52,14 +55,14 @@ class ReligiousBeliefsPickerScreen (
|
||||
if (pickIconAndName) rightSideButton.label = "Choose a religion".toLabel()
|
||||
else rightSideButton.label = "Enhance [${choosingCiv.religionManager.religion!!.getReligionDisplayName()}]".toLabel()
|
||||
rightSideButton.onClick(UncivSound.Choir) {
|
||||
choosingCiv.religionManager.chooseBeliefs(displayName, religionName, beliefsContainer.chosenBeliefs.map { it!! })
|
||||
choosingCiv.religionManager.chooseBeliefs(displayName, religionName, chosenBeliefs.map { it!! })
|
||||
UncivGame.Current.setWorldScreen()
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkAndEnableRightSideButton() {
|
||||
if (pickIconAndName && (religionName == null || displayName == null)) return
|
||||
if (beliefsContainer.chosenBeliefs.any { it == null }) return
|
||||
if (chosenBeliefs.any { it == null }) return
|
||||
rightSideButton.enable()
|
||||
}
|
||||
|
||||
@ -157,8 +160,8 @@ class ReligiousBeliefsPickerScreen (
|
||||
beliefButton.disable()
|
||||
}
|
||||
|
||||
for (newBelief in beliefsContainer.chosenBeliefs.withIndex()) {
|
||||
addChoosableBeliefButton(newBelief, beliefsContainer.getBeliefTypeFromIndex(newBelief.index))
|
||||
for (newBelief in chosenBeliefs.withIndex()) {
|
||||
addChoosableBeliefButton(newBelief, getBeliefTypeFromIndex(newBelief.index))
|
||||
}
|
||||
}
|
||||
|
||||
@ -166,16 +169,16 @@ class ReligiousBeliefsPickerScreen (
|
||||
rightBeliefsToChoose.clear()
|
||||
val availableBeliefs = gameInfo.ruleSet.beliefs.values
|
||||
.filter {
|
||||
it.type == beliefType
|
||||
(it.type == beliefType || beliefType == BeliefType.Any)
|
||||
&& gameInfo.religions.values.none {
|
||||
religion -> religion.hasBelief(it.name)
|
||||
}
|
||||
&& (it !in beliefsContainer.chosenBeliefs)
|
||||
&& (it !in chosenBeliefs)
|
||||
}
|
||||
for (belief in availableBeliefs) {
|
||||
val beliefButton = convertBeliefToButton(belief)
|
||||
beliefButton.onClick {
|
||||
beliefsContainer.chosenBeliefs[leftButtonIndex] = belief
|
||||
chosenBeliefs[leftButtonIndex] = belief
|
||||
updateLeftTable()
|
||||
checkAndEnableRightSideButton()
|
||||
}
|
||||
@ -204,22 +207,20 @@ class ReligiousBeliefsPickerScreen (
|
||||
|
||||
private fun emptyBeliefButton(beliefType: BeliefType): Button {
|
||||
val contentsTable = Table()
|
||||
contentsTable.add("Choose a [${beliefType.name}] belief!".toLabel())
|
||||
if (beliefType != BeliefType.Any)
|
||||
contentsTable.add("Choose a [${beliefType.name}] belief!".toLabel())
|
||||
else
|
||||
contentsTable.add("Choose any belief!".toLabel())
|
||||
return Button(contentsTable, skin)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
data class BeliefContainer(val pantheonBeliefCount: Int = 0, val founderBeliefCount: Int = 0, val followerBeliefCount: Int = 0, val enhancerBeliefCount: Int = 0) {
|
||||
|
||||
val chosenBeliefs: Array<Belief?> = Array(pantheonBeliefCount + founderBeliefCount + followerBeliefCount + enhancerBeliefCount) { null }
|
||||
|
||||
fun getBeliefTypeFromIndex(index: Int): BeliefType {
|
||||
private fun getBeliefTypeFromIndex(index: Int): BeliefType {
|
||||
return when {
|
||||
index < pantheonBeliefCount -> BeliefType.Pantheon
|
||||
index < pantheonBeliefCount + founderBeliefCount -> BeliefType.Founder
|
||||
index < pantheonBeliefCount + founderBeliefCount + followerBeliefCount -> BeliefType.Follower
|
||||
else -> BeliefType.Enhancer
|
||||
index < beliefsToChoose.filter { it.key <= BeliefType.Pantheon }.values.sum() -> BeliefType.Pantheon
|
||||
index < beliefsToChoose.filter { it.key <= BeliefType.Founder }.values.sum() -> BeliefType.Founder
|
||||
index < beliefsToChoose.filter { it.key <= BeliefType.Follower }.values.sum() -> BeliefType.Follower
|
||||
index < beliefsToChoose.filter { it.key <= BeliefType.Enhancer }.values.sum() -> BeliefType.Enhancer
|
||||
else -> BeliefType.Any
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user