Adjacency function can receive civ, for foreign/resource filters

This commit is contained in:
Yair Morgenstern 2024-01-25 00:28:46 +02:00
parent 138d1c64a1
commit 74ca1d43e8
3 changed files with 7 additions and 7 deletions

View File

@ -467,11 +467,11 @@ open class Tile : IsPartOfGameInfoSerialization {
} }
// This should be the only adjacency function // This should be the only adjacency function
fun isAdjacentTo(terrainFilter:String): Boolean { fun isAdjacentTo(terrainFilter:String, observingCiv: Civilization?=null): Boolean {
// Rivers are odd, as they aren't technically part of any specific tile but still count towards adjacency // Rivers are odd, as they aren't technically part of any specific tile but still count towards adjacency
if (terrainFilter == Constants.river) return isAdjacentToRiver() if (terrainFilter == Constants.river) return isAdjacentToRiver()
if (terrainFilter == Constants.freshWater && isAdjacentToRiver()) return true if (terrainFilter == Constants.freshWater && isAdjacentToRiver()) return true
return (neighbors + this).any { neighbor -> neighbor.matchesFilter(terrainFilter) } return (neighbors + this).any { neighbor -> neighbor.matchesFilter(terrainFilter, observingCiv) }
} }
/** Implements [UniqueParameterType.TileFilter][com.unciv.models.ruleset.unique.UniqueParameterType.TileFilter] */ /** Implements [UniqueParameterType.TileFilter][com.unciv.models.ruleset.unique.UniqueParameterType.TileFilter] */
@ -514,7 +514,7 @@ open class Tile : IsPartOfGameInfoSerialization {
"Water resource" -> isWater && observingCiv != null && hasViewableResource(observingCiv) "Water resource" -> isWater && observingCiv != null && hasViewableResource(observingCiv)
"Natural Wonder" -> naturalWonder != null "Natural Wonder" -> naturalWonder != null
"Featureless" -> terrainFeatures.isEmpty() "Featureless" -> terrainFeatures.isEmpty()
Constants.freshWaterFilter -> isAdjacentTo(Constants.freshWater) Constants.freshWaterFilter -> isAdjacentTo(Constants.freshWater, observingCiv)
in terrainFeatures -> true in terrainFeatures -> true
else -> { else -> {

View File

@ -7,9 +7,9 @@ import com.unciv.logic.civilization.Civilization
import com.unciv.models.Counter import com.unciv.models.Counter
import com.unciv.models.ruleset.tile.ResourceType import com.unciv.models.ruleset.tile.ResourceType
import com.unciv.models.ruleset.tile.TileImprovement import com.unciv.models.ruleset.tile.TileImprovement
import com.unciv.models.ruleset.unique.Unique
import com.unciv.models.ruleset.unique.LocalUniqueCache import com.unciv.models.ruleset.unique.LocalUniqueCache
import com.unciv.models.ruleset.unique.StateForConditionals import com.unciv.models.ruleset.unique.StateForConditionals
import com.unciv.models.ruleset.unique.Unique
import com.unciv.models.ruleset.unique.UniqueParameterType import com.unciv.models.ruleset.unique.UniqueParameterType
import com.unciv.models.ruleset.unique.UniqueTarget import com.unciv.models.ruleset.unique.UniqueTarget
import com.unciv.models.ruleset.unique.UniqueType import com.unciv.models.ruleset.unique.UniqueType
@ -271,7 +271,7 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
yield(RejectionReasonType.MustNotBeOnTile.toInstance(unique.text)) yield(RejectionReasonType.MustNotBeOnTile.toInstance(unique.text))
UniqueType.MustBeNextTo -> UniqueType.MustBeNextTo ->
if (!cityCenter.isAdjacentTo(unique.params[0])) if (!cityCenter.isAdjacentTo(unique.params[0], civ))
yield(RejectionReasonType.MustBeNextToTile.toInstance(unique.text)) yield(RejectionReasonType.MustBeNextToTile.toInstance(unique.text))
UniqueType.MustNotBeNextTo -> UniqueType.MustNotBeNextTo ->

View File

@ -318,8 +318,8 @@ class Unique(val text: String, val sourceObjectType: UniqueTarget? = null, val s
relevantTile?.matchesFilter(condition.params[0], state.civInfo) == true relevantTile?.matchesFilter(condition.params[0], state.civInfo) == true
UniqueType.ConditionalInTilesNot -> UniqueType.ConditionalInTilesNot ->
relevantTile?.matchesFilter(condition.params[0], state.civInfo) == false relevantTile?.matchesFilter(condition.params[0], state.civInfo) == false
UniqueType.ConditionalAdjacentTo -> relevantTile?.isAdjacentTo(condition.params[0]) == true UniqueType.ConditionalAdjacentTo -> relevantTile?.isAdjacentTo(condition.params[0], state.civInfo) == true
UniqueType.ConditionalNotAdjacentTo -> relevantTile?.isAdjacentTo(condition.params[0]) == false UniqueType.ConditionalNotAdjacentTo -> relevantTile?.isAdjacentTo(condition.params[0], state.civInfo) == false
UniqueType.ConditionalFightingInTiles -> UniqueType.ConditionalFightingInTiles ->
state.attackedTile?.matchesFilter(condition.params[0], state.civInfo) == true state.attackedTile?.matchesFilter(condition.params[0], state.civInfo) == true
UniqueType.ConditionalInTilesAnd -> UniqueType.ConditionalInTilesAnd ->