mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-10 07:16:54 +07:00
Add trigger from building improvements and trigger conditional for building improvements (#10644)
* Add trigger from building improvements and trigger conditional for building improvements * Classic case of the forgotten import * Fix improvement triggerables saying they aren't allowed and move the trigger to its own function * include the tile in the civ trigger * Update core/src/com/unciv/models/ruleset/unique/UniqueType.kt --------- Co-authored-by: Yair Morgenstern <yairm210@hotmail.com>
This commit is contained in:
parent
c142d1508c
commit
f8315de414
@ -170,7 +170,7 @@ class UnitTurnManager(val unit: MapUnit) {
|
||||
UncivGame.Current.settings.addCompletedTutorialTask("Construct an improvement")
|
||||
|
||||
val improvementInProgress = tile.improvementInProgress ?: return
|
||||
tile.changeImprovement(improvementInProgress, unit.civ)
|
||||
tile.changeImprovement(improvementInProgress, unit.civ, unit)
|
||||
|
||||
tile.improvementInProgress = null
|
||||
tile.getCity()?.updateCitizens = true
|
||||
|
@ -306,8 +306,8 @@ open class Tile : IsPartOfGameInfoSerialization {
|
||||
fun removeImprovement() =
|
||||
improvementFunctions.changeImprovement(null)
|
||||
|
||||
fun changeImprovement(improvementStr: String, civToHandleCompletion:Civilization? = null) =
|
||||
improvementFunctions.changeImprovement(improvementStr, civToHandleCompletion)
|
||||
fun changeImprovement(improvementStr: String, civToHandleCompletion: Civilization? = null, unit: MapUnit? = null) =
|
||||
improvementFunctions.changeImprovement(improvementStr, civToHandleCompletion, unit)
|
||||
|
||||
// function handling when adding a road to the tile
|
||||
fun addRoad(roadType: RoadStatus, creatingCivInfo: Civilization?) {
|
||||
|
@ -6,8 +6,10 @@ import com.unciv.logic.civilization.LocationAction
|
||||
import com.unciv.logic.civilization.NotificationCategory
|
||||
import com.unciv.logic.civilization.NotificationIcon
|
||||
import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers
|
||||
import com.unciv.logic.map.mapunit.MapUnit
|
||||
import com.unciv.models.ruleset.tile.TileImprovement
|
||||
import com.unciv.models.ruleset.unique.StateForConditionals
|
||||
import com.unciv.models.ruleset.unique.UniqueTriggerActivation
|
||||
import com.unciv.models.ruleset.unique.UniqueType
|
||||
|
||||
|
||||
@ -187,7 +189,7 @@ class TileInfoImprovementFunctions(val tile: Tile) {
|
||||
|
||||
fun changeImprovement(improvementName: String?,
|
||||
/** For road assignment and taking over tiles - DO NOT pass when simulating improvement effects! */
|
||||
civToActivateBroaderEffects:Civilization? = null) {
|
||||
civToActivateBroaderEffects: Civilization? = null, unit: MapUnit? = null) {
|
||||
val improvementObject = tile.ruleset.tileImprovements[improvementName]
|
||||
|
||||
when {
|
||||
@ -223,6 +225,9 @@ class TileInfoImprovementFunctions(val tile: Tile) {
|
||||
)
|
||||
takeOverTilesAround(civToActivateBroaderEffects, tile)
|
||||
|
||||
if (civToActivateBroaderEffects != null && improvementObject != null)
|
||||
triggerImprovementUniques(improvementObject, civToActivateBroaderEffects, unit)
|
||||
|
||||
val city = tile.owningCity
|
||||
if (city != null) {
|
||||
city.cityStats.update()
|
||||
@ -233,6 +238,29 @@ class TileInfoImprovementFunctions(val tile: Tile) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun triggerImprovementUniques(
|
||||
improvement: TileImprovement,
|
||||
civ: Civilization,
|
||||
unit: MapUnit? = null
|
||||
) {
|
||||
for (unique in improvement.uniqueObjects.filter { !it.hasTriggerConditional() })
|
||||
if (unit != null) {
|
||||
UniqueTriggerActivation.triggerUnitwideUnique(unique, unit)
|
||||
}
|
||||
else UniqueTriggerActivation.triggerCivwideUnique(unique, civ, tile = tile)
|
||||
|
||||
if (unit != null){
|
||||
for (unique in unit.getTriggeredUniques(UniqueType.TriggerUponBuildingImprovement)
|
||||
.filter { improvement.matchesFilter(it.params[0]) })
|
||||
UniqueTriggerActivation.triggerUnitwideUnique(unique, unit)
|
||||
}
|
||||
|
||||
for (unique in civ.getMatchingUniques(
|
||||
UniqueType.TriggerUponBuildingImprovement, StateForConditionals(civInfo = civ, unit = unit))
|
||||
.filter { improvement.matchesFilter(it.params[0]) })
|
||||
UniqueTriggerActivation.triggerCivwideUnique(unique, civ, tile = tile)
|
||||
}
|
||||
|
||||
private fun adtivateRemovalImprovement(
|
||||
improvementName: String,
|
||||
civToActivateBroaderEffects: Civilization?
|
||||
|
@ -48,7 +48,7 @@ enum class UniqueTarget(
|
||||
|
||||
// Tile-specific
|
||||
Terrain,
|
||||
Improvement,
|
||||
Improvement(inheritsFrom = Triggerable),
|
||||
Resource(inheritsFrom = Global),
|
||||
Ruins(inheritsFrom = UnitTriggerable),
|
||||
|
||||
|
@ -756,6 +756,7 @@ enum class UniqueType(
|
||||
/** Can be placed upon both units and as global */
|
||||
TriggerUponConqueringCity("upon conquering a city", UniqueTarget.TriggerCondition, UniqueTarget.UnitTriggerCondition),
|
||||
TriggerUponFoundingCity("upon founding a city", UniqueTarget.TriggerCondition),
|
||||
TriggerUponBuildingImprovement("upon building a [improvementFilter] improvement", UniqueTarget.TriggerCondition, UniqueTarget.UnitTriggerCondition),
|
||||
TriggerUponDiscoveringNaturalWonder("upon discovering a Natural Wonder", UniqueTarget.TriggerCondition),
|
||||
TriggerUponConstructingBuilding("upon constructing [buildingFilter]", UniqueTarget.TriggerCondition),
|
||||
// We have a separate trigger to include the cityFilter, since '[in all cities]' can be read '*only* if it's in all cities'
|
||||
|
@ -40,7 +40,7 @@ object UnitActionsFromUniques {
|
||||
|
||||
return UnitAction(UnitActionType.Create, "Create [$improvementName]",
|
||||
action = {
|
||||
tile.changeImprovement(improvementName, unit.civ)
|
||||
tile.changeImprovement(improvementName, unit.civ, unit)
|
||||
unit.destroy() // Modders may wish for a nondestructive way, but that should be another Unique
|
||||
}.takeIf { unit.currentMovement > 0 })
|
||||
}
|
||||
@ -255,7 +255,7 @@ object UnitActionsFromUniques {
|
||||
),
|
||||
action = {
|
||||
val unitTile = unit.getTile()
|
||||
unitTile.changeImprovement(improvementName, unit.civ)
|
||||
unitTile.changeImprovement(improvementName, unit.civ, unit)
|
||||
|
||||
// without this the world screen won't show the improvement because it isn't the 'last seen improvement'
|
||||
unit.civ.cache.updateViewableTiles()
|
||||
|
Loading…
Reference in New Issue
Block a user