mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-22 05:41:11 +07:00
City states no longer gift units that push us over resource limits - #12057
This commit is contained in:
@ -44,7 +44,7 @@ class CityStateFunctions(val civInfo: Civilization) {
|
|||||||
uniqueTypes.addAll(cityStateType.allyBonusUniqueMap.getAllUniques().mapNotNull { it.type })
|
uniqueTypes.addAll(cityStateType.allyBonusUniqueMap.getAllUniques().mapNotNull { it.type })
|
||||||
|
|
||||||
// CS Personality
|
// CS Personality
|
||||||
civInfo.cityStatePersonality = CityStatePersonality.values().random()
|
civInfo.cityStatePersonality = CityStatePersonality.entries.toTypedArray().random()
|
||||||
|
|
||||||
// Mercantile bonus resources
|
// Mercantile bonus resources
|
||||||
|
|
||||||
@ -57,7 +57,8 @@ class CityStateFunctions(val civInfo: Civilization) {
|
|||||||
val possibleUnits = ruleset.units.values.filter {
|
val possibleUnits = ruleset.units.values.filter {
|
||||||
return@filter !it.availableInEra(ruleset, startingEra) // Not from the start era or before
|
return@filter !it.availableInEra(ruleset, startingEra) // Not from the start era or before
|
||||||
&& it.uniqueTo != null && it.uniqueTo in unusedMajorCivs // Must be from a major civ not in the game
|
&& it.uniqueTo != null && it.uniqueTo in unusedMajorCivs // Must be from a major civ not in the game
|
||||||
&& ruleset.unitTypes[it.unitType]!!.isLandUnit() && (it.strength > 0 || it.rangedStrength > 0) // Must be a land military unit
|
&& ruleset.unitTypes[it.unitType]!!.isLandUnit()
|
||||||
|
&& (it.strength > 0 || it.rangedStrength > 0) // Must be a land military unit
|
||||||
}
|
}
|
||||||
if (possibleUnits.isNotEmpty())
|
if (possibleUnits.isNotEmpty())
|
||||||
civInfo.cityStateUniqueUnit = possibleUnits.random().name
|
civInfo.cityStateUniqueUnit = possibleUnits.random().name
|
||||||
@ -150,6 +151,10 @@ class CityStateFunctions(val civInfo: Civilization) {
|
|||||||
fun randomGiftableUnit() =
|
fun randomGiftableUnit() =
|
||||||
city.cityConstructions.getConstructableUnits()
|
city.cityConstructions.getConstructableUnits()
|
||||||
.filter { !it.isCivilian() && it.isLandUnit && it.uniqueTo == null }
|
.filter { !it.isCivilian() && it.isLandUnit && it.uniqueTo == null }
|
||||||
|
// Does not make us go over any resource quota
|
||||||
|
.filter { it.getResourceRequirementsPerTurn(StateForConditionals(civInfo = receivingCiv)).none {
|
||||||
|
it.value > 0 && receivingCiv.getResourceAmount(it.key) < it.value
|
||||||
|
} }
|
||||||
.toList().randomOrNull()
|
.toList().randomOrNull()
|
||||||
val militaryUnit = giftableUniqueUnit() // If the receiving civ has discovered the required tech and not the obsolete tech for our unique, always give them the unique
|
val militaryUnit = giftableUniqueUnit() // If the receiving civ has discovered the required tech and not the obsolete tech for our unique, always give them the unique
|
||||||
?: randomGiftableUnit() // Otherwise pick at random
|
?: randomGiftableUnit() // Otherwise pick at random
|
||||||
|
@ -334,7 +334,8 @@ object DiplomacyTurnManager {
|
|||||||
|
|
||||||
val variance = listOf(-1, 0, 1).random()
|
val variance = listOf(-1, 0, 1).random()
|
||||||
|
|
||||||
val provideMilitaryUnitUniques = civInfo.cityStateFunctions.getCityStateBonuses(otherCiv().cityStateType, relationshipIgnoreAfraid(), UniqueType.CityStateMilitaryUnits)
|
val provideMilitaryUnitUniques = civInfo.cityStateFunctions
|
||||||
|
.getCityStateBonuses(otherCiv().cityStateType, relationshipIgnoreAfraid(), UniqueType.CityStateMilitaryUnits)
|
||||||
.filter { it.conditionalsApply(civInfo) }.toList()
|
.filter { it.conditionalsApply(civInfo) }.toList()
|
||||||
if (provideMilitaryUnitUniques.isEmpty()) removeFlag(DiplomacyFlags.ProvideMilitaryUnit)
|
if (provideMilitaryUnitUniques.isEmpty()) removeFlag(DiplomacyFlags.ProvideMilitaryUnit)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user