Get notification when pantheon, religion or religion enhancement is made by other civ (#13613)

* notification for when religion is founded

* fix typo with space

* notification for pantheon and enhancement

* actions and notifications don't reveal info

* fix typo with space again

* shorten code

* an unknown civilization!
This commit is contained in:
metablaster 2025-07-15 10:52:28 +02:00 committed by GitHub
parent fa7d075cde
commit 8138a0b9c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 59 additions and 2 deletions

View File

@ -1799,6 +1799,11 @@ Holy City of: [religionName] =
Former Holy City of: [religionName] =
Followers =
Pressure =
[nation] has founded pantheon [belief]! =
[nation] has enhanced [religionName]! =
[nation] has founded [religionName] in [cityName]! =
[nation] has founded [religionName]! =
An unknown civilization =
# Religion overview screen
Religion Name: =

View File

@ -183,12 +183,25 @@ class EspionageAction : NotificationAction {
}
}
/** Open [url] externally in the browser */
class LinkAction(private val url: String = "") : NotificationAction {
override fun execute(worldScreen: WorldScreen) {
if (url.isNotEmpty()) Gdx.net.openURI(url)
}
}
/** Open [EmpireOverviewScreen] on the [Religion][EmpireOverviewCategories.Religion] tab */
class ReligionAction(private val religionName: String? = null) : NotificationAction {
override fun execute(worldScreen: WorldScreen) {
worldScreen.game.pushScreen(EmpireOverviewScreen(worldScreen.selectedCiv, EmpireOverviewCategories.Religion, religionName.orEmpty()))
}
companion object {
fun withLocation(location: Vector2?, religionName: String?): Sequence<NotificationAction> =
LocationAction(location) + ReligionAction(religionName)
}
}
@Suppress("PrivatePropertyName") // These names *must* match their class name, see below
internal class NotificationActionsDeserializer {
/* This exists as trick to leverage readFields for Json deserialization.
@ -213,13 +226,14 @@ internal class NotificationActionsDeserializer {
private val PolicyAction: PolicyAction? = null
private val EspionageAction: EspionageAction? = null
private val LinkAction: LinkAction? = null
private val ReligionAction: ReligionAction? = null
fun read(json: Json, jsonData: JsonValue): List<NotificationAction> {
json.readFields(this, jsonData)
return listOfNotNull(
LocationAction, TechAction, CityAction, DiplomacyAction, MayaLongCountAction,
MapUnitAction, CivilopediaAction, PromoteUnitAction, OverviewAction, PolicyAction,
EspionageAction, LinkAction
EspionageAction, LinkAction, ReligionAction
)
}
}

View File

@ -3,6 +3,9 @@ package com.unciv.logic.civilization.managers
import com.unciv.logic.IsPartOfGameInfoSerialization
import com.unciv.logic.city.City
import com.unciv.logic.civilization.Civilization
import com.unciv.logic.civilization.Notification
import com.unciv.logic.civilization.NotificationIcon
import com.unciv.logic.civilization.ReligionAction
import com.unciv.logic.map.mapunit.MapUnit
import com.unciv.logic.map.tile.Tile
import com.unciv.models.Counter
@ -140,6 +143,15 @@ class ReligionManager : IsPartOfGameInfoSerialization {
civInfo.gameInfo.religions[beliefName] = religion!!
for (city in civInfo.cities)
city.religion.addPressure(beliefName, 200 * city.population.population)
val humanPlayers = civInfo.gameInfo.civilizations.filter { it.isHuman() && it != civInfo }
for (civ in humanPlayers) {
val text = if (civInfo in civ.getKnownCivs()) "[${civInfo.civName}]"
else "[An unknown civilization]"
civ.addNotification(text + " has founded pantheon [${beliefName}]!",
ReligionAction(beliefName), Notification.NotificationCategory.Religion, NotificationIcon.Faith)
}
}
fun greatProphetsEarned(): Int = civInfo.civConstructions.boughtItemsWithIncreasingPrice[getGreatProphetEquivalent()?.name ?: ""]
@ -313,8 +325,20 @@ class ReligionManager : IsPartOfGameInfoSerialization {
}
fun useProphetForEnhancingReligion(prophet: MapUnit) {
if (!mayEnhanceReligionHere(prophet.getTile())) return // How did you do this?
val currentTile = prophet.getTile()
if (!mayEnhanceReligionHere(currentTile)) return // How did you do this?
religionState = ReligionState.EnhancingReligion
val humanPlayers = civInfo.gameInfo.civilizations.filter { it.isHuman() && it != civInfo }
val religion = civInfo.religionManager.religion!!
for (civ in humanPlayers) {
val text = if (civInfo in civ.getKnownCivs()) "[${civInfo.civName}]"
else "[An unknown civilization]"
civ.addNotification(text + " has enhanced [${religion.name}]!",
ReligionAction(religion.name), Notification.NotificationCategory.Religion, NotificationIcon.Faith)
}
}
/**
@ -438,6 +462,20 @@ class ReligionManager : IsPartOfGameInfoSerialization {
for (unit in civInfo.units.getCivUnits())
if (unit.hasUnique(UniqueType.ReligiousUnit) && unit.hasUnique(UniqueType.TakeReligionOverBirthCity))
unit.religion = newReligion.name
val humanPlayers = civInfo.gameInfo.civilizations.filter { it.isHuman() && it != civInfo }
for (civ in humanPlayers) {
if (civInfo in civ.getKnownCivs()) {
if (civ.hasExplored(holyCity.getCenterTile()))
civ.addNotification("[${civInfo.civName}] has founded [$displayName] in [${holyCity.name}]!",
ReligionAction.withLocation(holyCity.location, name),
Notification.NotificationCategory.Religion, NotificationIcon.Faith)
else civ.addNotification("[${civInfo.civName}] has founded [$displayName]!",
ReligionAction(name), Notification.NotificationCategory.Religion, NotificationIcon.Faith)
}
else civ.addNotification("[An unknown civilization] has founded [$displayName]!",
ReligionAction(name), Notification.NotificationCategory.Religion, NotificationIcon.Faith)
}
}
fun maySpreadReligionAtAll(missionary: MapUnit): Boolean {