Split 6 tiles visible unique into its parts, making it more moddable (#6389)

* Split sight unique into its parts, making it more moddable

* Standardized unique ordering
This commit is contained in:
Xander Lenstra 2022-03-21 20:03:33 +01:00 committed by GitHub
parent 3374bb15d5
commit 1df49749f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 42 additions and 27 deletions

View File

@ -59,7 +59,7 @@
{
"name": "Fighter",
"movementType": "Air",
"uniques": ["Aircraft", "6 tiles in every direction always visible"]
"uniques": ["Aircraft", "[+4] Sight", "Can see over obstacles"]
},
{
"name": "Bomber",

View File

@ -1589,7 +1589,7 @@
"cost": 425,
"requiredTech": "Stealth",
"requiredResource": "Aluminum",
"uniques": ["Damage taken from interception reduced by [100]%", "Cannot be carried by [Carrier] units", "6 tiles in every direction always visible"],
"uniques": ["Damage taken from interception reduced by [100]%", "Cannot be carried by [Carrier] units", "[+4] Sight", "Can see over obstacles"],
"attackSound": "bombing"
},

View File

@ -59,7 +59,7 @@
{
"name": "Fighter",
"movementType": "Air",
"uniques": ["Aircraft", "6 tiles in every direction always visible"]
"uniques": ["Aircraft", "[+4] Sight", "Can see over obstacles"]
},
{
"name": "Bomber",

View File

@ -1265,7 +1265,7 @@
"cost": 425,
"requiredTech": "Stealth",
"requiredResource": "Aluminum",
"uniques": ["Damage taken from interception reduced by [100]%", "Cannot be carried by [Carrier] units", "6 tiles in every direction always visible"],
"uniques": ["Damage taken from interception reduced by [100]%", "Cannot be carried by [Carrier] units", "[+4] Sight", "Can see over obstacles"],
"attackSound": "bombing"
},

View File

@ -376,16 +376,14 @@ class MapUnit {
val conditionalState = StateForConditionals(civInfo = civInfo, unit = this)
if (isEmbarked() && !hasUnique(UniqueType.NormalVisionWhenEmbarked, conditionalState)
&& !civInfo.hasUnique(UniqueType.NormalVisionWhenEmbarked, conditionalState)) {
if (isEmbarked() && !hasUnique(UniqueType.NormalVisionWhenEmbarked, conditionalState, checkCivInfoUniques = true)) {
return 1
}
visibilityRange += getMatchingUniques(UniqueType.Sight, conditionalState, checkCivInfoUniques = true)
.sumOf { it.params[0].toInt() }
visibilityRange += getTile().getAllTerrains()
.flatMap { it.getMatchingUniques(UniqueType.Sight, conditionalState) }
visibilityRange += getTile().getMatchingUniques(UniqueType.Sight, conditionalState)
.sumOf { it.params[0].toInt() }
if (visibilityRange < 1) visibilityRange = 1
@ -399,13 +397,13 @@ class MapUnit {
fun updateVisibleTiles(updateCivViewableTiles:Boolean = true) {
val oldViewableTiles = viewableTiles
if (baseUnit.isAirUnit()) {
viewableTiles = if (hasUnique(UniqueType.SixTilesAlwaysVisible))
getTile().getTilesInDistance(6).toHashSet() // it's that simple
else HashSet(0) // bomber units don't do recon
} else {
viewableTiles = getTile().getViewableTilesList(getVisibilityRange()).toHashSet()
viewableTiles = when {
hasUnique(UniqueType.NoSight) -> hashSetOf()
hasUnique(UniqueType.CanSeeOverObstacles) ->
getTile().getTilesInDistance(getVisibilityRange()).toHashSet() // it's that simple
else -> getTile().getViewableTilesList(getVisibilityRange()).toHashSet()
}
// Set equality automatically determines if anything changed - https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-abstract-set/equals.html
if (updateCivViewableTiles && oldViewableTiles != viewableTiles)
civInfo.updateViewableTiles() // for the civ

View File

@ -11,6 +11,7 @@ import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.models.ruleset.tile.*
import com.unciv.models.ruleset.unique.StateForConditionals
import com.unciv.models.ruleset.unique.Unique
import com.unciv.models.stats.Stats
import com.unciv.models.translations.tr
import com.unciv.ui.civilopedia.FormattedLine
@ -242,6 +243,9 @@ open class TileInfo {
fun isRoughTerrain() = getAllTerrains().any{ it.isRough() }
fun hasUnique(uniqueType: UniqueType) = getAllTerrains().any { it.hasUnique(uniqueType) }
fun getMatchingUniques(uniqueType: UniqueType, stateForConditionals: StateForConditionals = StateForConditionals(tile=this) ): Sequence<Unique> {
return getAllTerrains().flatMap { it.getMatchingUniques(uniqueType, stateForConditionals) }
}
fun getWorkingCity(): CityInfo? {
val civInfo = getOwner() ?: return null

View File

@ -436,6 +436,9 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
AttackFromSea("Eliminates combat penalty for attacking from the sea", UniqueTarget.Unit),
AttackAcrossCoast("Eliminates combat penalty for attacking across a coast", UniqueTarget.Unit),
NoSight("No Sight", UniqueTarget.Unit),
CanSeeOverObstacles("Can see over obstacles", UniqueTarget.Unit),
@Deprecated("as of 3.19.19", ReplaceWith("[+4] Sight\", \"Can see over obstacles"))
SixTilesAlwaysVisible("6 tiles in every direction always visible", UniqueTarget.Unit),
CarryAirUnits("Can carry [amount] [mapUnitFilter] units", UniqueTarget.Unit),

View File

@ -377,14 +377,16 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
private fun getDeprecatedReplaceableUniques(mod:Ruleset): HashMap<String, String> {
val objectsToCheck = sequenceOf(
mod.units,
mod.beliefs,
mod.buildings,
mod.nations,
mod.policies,
mod.technologies,
mod.terrains,
mod.tileImprovements,
mod.unitPromotions,
mod.buildings,
mod.policies,
mod.nations,
mod.beliefs,
mod.technologies,
mod.unitTypes,
mod.units,
)
val allDeprecatedUniques = HashSet<String>()
val deprecatedUniquesToReplacementText = HashMap<String, String>()
@ -442,15 +444,20 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
private fun autoUpdateUniques(mod: Ruleset, replaceableUniques: HashMap<String, String>, ) {
if (mod.name.contains("mod"))
println("mod")
val filesToReplace = listOf(
"Units.json",
"Beliefs.json",
"Buildings.json",
"Nations.json",
"Policies.json",
"Techs.json",
"Terrains.json",
"TileImprovements.json",
"UnitPromotions.json",
"Buildings.json",
"Policies.json",
"Nations.json",
"Beliefs.json",
"Techs.json",
"UnitTypes.json",
"Units.json",
)
val jsonFolder = mod.folderLocation!!.child("jsons")

View File

@ -1017,7 +1017,10 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
??? example "Eliminates combat penalty for attacking across a coast"
Applicable to: Unit
??? example "6 tiles in every direction always visible"
??? example "No Sight"
Applicable to: Unit
??? example "Can see over obstacles"
Applicable to: Unit
??? example "Can carry [amount] [mapUnitFilter] units"