Add unique for a promotion to be free (#10015)

* Add unique for a promotion to be free

* Have Ai prefer free promotions

* Allow AI to get multiple promotions each step
This commit is contained in:
SeventhM 2023-09-04 04:37:59 -07:00 committed by GitHub
parent 087c2a0946
commit d19281e0e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 7 deletions

View File

@ -159,13 +159,15 @@ object UnitAutomation {
return
}
if (unit.promotions.canBePromoted() &&
while (unit.promotions.canBePromoted() &&
// Restrict Human automated units from promotions via setting
(UncivGame.Current.settings.automatedUnitsChoosePromotions || unit.civ.isAI())) {
val availablePromotions = unit.promotions.getAvailablePromotions()
.filterNot { it.hasUnique(UniqueType.SkipPromotion) }
if (availablePromotions.any())
unit.promotions.addPromotion(availablePromotions.toList().random().name)
unit.promotions.addPromotion(
availablePromotions.filter { it.hasUnique(UniqueType.FreePromotion) }.toList().randomOrNull()?.name
?: availablePromotions.toList().random().name)
}
//This allows for military units with certain civilian abilities to behave as civilians in peace and soldiers in war

View File

@ -63,17 +63,19 @@ class UnitPromotions : IsPartOfGameInfoSerialization {
}
fun addPromotion(promotionName: String, isFree: Boolean = false){
val ruleset = unit.civ.gameInfo.ruleset
val promotion = ruleset.unitPromotions[promotionName]!!
if (!isFree) {
XP -= xpForNextPromotion()
numberOfPromotions++
if (!promotion.hasUnique(UniqueType.FreePromotion)) {
XP -= xpForNextPromotion()
numberOfPromotions++
}
for (unique in unit.getTriggeredUniques(UniqueType.TriggerUponPromotion))
UniqueTriggerActivation.triggerUnitwideUnique(unique, unit)
}
val ruleset = unit.civ.gameInfo.ruleset
val promotion = ruleset.unitPromotions[promotionName]!!
if (!promotion.hasUnique(UniqueType.SkipPromotion))
promotions.add(promotionName)

View File

@ -713,6 +713,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
OneTimeUnitSpecialUpgrade("This Unit upgrades for free including special upgrades", UniqueTarget.UnitTriggerable),
OneTimeUnitGainPromotion("This Unit gains the [promotion] promotion", UniqueTarget.UnitTriggerable), // Not used in Vanilla
SkipPromotion("Doing so will consume this opportunity to choose a Promotion", UniqueTarget.Promotion),
FreePromotion("This Promotion is free", UniqueTarget.Promotion),
UnitsGainPromotion("[mapUnitFilter] units gain the [promotion] promotion", UniqueTarget.Triggerable), // Not used in Vanilla
FreeStatBuildings("Provides the cheapest [stat] building in your first [amount] cities for free", UniqueTarget.Triggerable), // used in Policy