Allow free unit triggers for any location (#9870)

* Allow free unit triggers for any location

* Almost forgot this was broken

* Fix situation when tile is null, but therebis a city to place at
This commit is contained in:
SeventhM 2023-08-03 01:38:14 -07:00 committed by GitHub
parent fdc891dada
commit 0fe584700b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -76,7 +76,8 @@ class UnitManager(val civInfo:Civilization) {
if (!unique.hasTriggerConditional())
UniqueTriggerActivation.triggerUnitwideUnique(unique, unit, triggerNotificationText = triggerNotificationText)
for (unique in civInfo.getTriggeredUniques(UniqueType.TriggerUponGainingUnit))
if (unit.matchesFilter(unique.params[0]))
if (unique.conditionals.any { it.isOfType(UniqueType.TriggerUponGainingUnit) &&
unit.matchesFilter(unique.params[0]) })
UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo, triggerNotificationText = triggerNotificationText)
if (unit.baseUnit.getResourceRequirementsPerTurn().isNotEmpty())
civInfo.cache.updateCivResources()

View File

@ -53,7 +53,7 @@ object UniqueTriggerActivation {
UniqueType.OneTimeFreeUnit -> {
val unitName = unique.params[0]
val unit = ruleSet.units[unitName]
if (chosenCity == null
if ((chosenCity == null && tile == null)
|| unit == null
|| unit.hasUnique(UniqueType.FoundCity) && civInfo.isOneCityChallenger())
return false
@ -63,7 +63,9 @@ object UniqueTriggerActivation {
if (limit!=null && limit <= civInfo.units.getCivUnits().count { it.name==unitName })
return false
val placedUnit = civInfo.units.addUnit(unitName, chosenCity) ?: return false
val placedUnit = if (city != null || tile == null)
civInfo.units.addUnit(unitName, chosenCity) ?: return false
else civInfo.units.placeUnitNearTile(tile!!.position, unitName) ?: return false
val notificationText = getNotificationText(notification, triggerNotificationText,
"Gained [1] [$unitName] unit(s)")
@ -80,7 +82,7 @@ object UniqueTriggerActivation {
UniqueType.OneTimeAmountFreeUnits -> {
val unitName = unique.params[1]
val unit = ruleSet.units[unitName]
if (chosenCity == null || unit == null || (unit.hasUnique(UniqueType.FoundCity) && civInfo.isOneCityChallenger()))
if ((chosenCity == null && tile == null) || unit == null || (unit.hasUnique(UniqueType.FoundCity) && civInfo.isOneCityChallenger()))
return false
val limit = unit.getMatchingUniques(UniqueType.MaxNumberBuildable)
@ -94,7 +96,8 @@ object UniqueTriggerActivation {
val tilesUnitsWerePlacedOn: MutableList<Vector2> = mutableListOf()
repeat(actualAmount) {
val placedUnit = civInfo.units.addUnit(unitName, chosenCity)
val placedUnit = if (city != null || tile == null) civInfo.units.addUnit(unitName, chosenCity)
else civInfo.units.placeUnitNearTile(tile!!.position, unitName)
if (placedUnit != null)
tilesUnitsWerePlacedOn.add(placedUnit.getTile().position)
}