mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-21 13:18:56 +07:00
"Free great person" can no longer grant great people that are unique to another civ
Unified Great Person recognition Better Great Person AI detection for unique units
This commit is contained in:
@ -279,7 +279,7 @@ object UnitAutomation {
|
||||
.firstOrNull {
|
||||
val tile = it.currentTile
|
||||
it.type == UnitType.Civilian &&
|
||||
(it.hasUnique(Constants.settlerUnique) || unit.name in GreatPersonManager().statToGreatPersonMapping.values)
|
||||
(it.hasUnique(Constants.settlerUnique) || unit.isGreatPerson())
|
||||
&& tile.militaryUnit == null && unit.movement.canMoveTo(tile) && unit.movement.canReach(tile)
|
||||
}
|
||||
if (settlerOrGreatPersonToAccompany == null) return false
|
||||
|
@ -235,7 +235,7 @@ class CivilizationInfo {
|
||||
|
||||
//region Units
|
||||
fun getCivUnits(): Sequence<MapUnit> = units.asSequence()
|
||||
fun getCivGreatPeople(): Sequence<MapUnit> = getCivUnits().filter { mapUnit -> mapUnit.hasUnique("Great Person - []") }
|
||||
fun getCivGreatPeople(): Sequence<MapUnit> = getCivUnits().filter { mapUnit -> mapUnit.isGreatPerson() }
|
||||
|
||||
fun addUnit(mapUnit: MapUnit, updateCivInfo: Boolean = true) {
|
||||
val newList = ArrayList(units)
|
||||
@ -402,6 +402,10 @@ class CivilizationInfo {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun getGreatPeople() = gameInfo.ruleSet.units.values.asSequence()
|
||||
.filter { it.isGreatPerson() }.map { getEquivalentUnit(it.name) }.toHashSet()
|
||||
|
||||
//endregion
|
||||
|
||||
//region state-changing functions
|
||||
@ -559,7 +563,7 @@ class CivilizationInfo {
|
||||
if (!gameInfo.ruleSet.units.containsKey(unitName)) return
|
||||
val unit = getEquivalentUnit(unitName)
|
||||
placeUnitNearTile(cityToAddTo.location, unit.name)
|
||||
if (unit.uniques.any { it.equalsPlaceholderText("Great Person - []") })
|
||||
if (unit.isGreatPerson())
|
||||
addNotification("A [${unit.name}] has been born in [${cityToAddTo.name}]!", cityToAddTo.location, Color.GOLD)
|
||||
}
|
||||
|
||||
|
@ -502,7 +502,7 @@ class QuestManager {
|
||||
|
||||
val greatPeople = ruleSet.units.values
|
||||
.asSequence()
|
||||
.filter { baseUnit -> baseUnit.uniques.any { it.equalsPlaceholderText("Great Person - []") } }
|
||||
.filter { it.isGreatPerson() }
|
||||
.map { it.getReplacedUnit(ruleSet) }
|
||||
.distinct()
|
||||
.filter { !challengerGreatPeople.contains(it) && !cityStateGreatPeople.contains(it) }
|
||||
|
@ -304,6 +304,8 @@ class MapUnit {
|
||||
|
||||
fun canGarrison() = type.isMilitary() && type.isLandUnit()
|
||||
|
||||
fun isGreatPerson() = baseUnit.isGreatPerson()
|
||||
|
||||
//endregion
|
||||
|
||||
//region state-changing functions
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.unciv.models.ruleset
|
||||
|
||||
import com.unciv.Constants
|
||||
import com.unciv.logic.city.CityInfo
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.models.stats.Stats
|
||||
@ -59,14 +58,21 @@ object UniqueTriggerActivation {
|
||||
"Free Great Person" -> {
|
||||
if (civInfo.isPlayerCivilization()) civInfo.greatPeople.freeGreatPeople++
|
||||
else {
|
||||
val greatPeople = civInfo.getGreatPeople()
|
||||
if (greatPeople.isEmpty()) return
|
||||
var greatPerson = civInfo.getGreatPeople().random()
|
||||
|
||||
val preferredVictoryType = civInfo.victoryType()
|
||||
val greatPerson = when (preferredVictoryType) {
|
||||
VictoryType.Cultural -> "Great Artist"
|
||||
VictoryType.Scientific -> "Great Scientist"
|
||||
else -> civInfo.gameInfo.ruleSet.units.values
|
||||
.filter { it.uniqueObjects.any { it.placeholderText == "Great Person - []" } }.map { it.name }.random()
|
||||
if (preferredVictoryType == VictoryType.Cultural) {
|
||||
val culturalGP = greatPeople.firstOrNull { it.uniques.contains("Great Person - [Culture]") }
|
||||
if (culturalGP != null) greatPerson = culturalGP
|
||||
}
|
||||
civInfo.addUnit(greatPerson, chosenCity)
|
||||
if (preferredVictoryType == VictoryType.Scientific) {
|
||||
val scientificGP = greatPeople.firstOrNull { it.uniques.contains("Great Person - [Science]") }
|
||||
if (scientificGP != null) greatPerson = scientificGP
|
||||
}
|
||||
|
||||
civInfo.addUnit(greatPerson.name, chosenCity)
|
||||
}
|
||||
}
|
||||
"+1 population in each city" ->
|
||||
|
@ -223,4 +223,6 @@ class BaseUnit : INamed, IConstruction {
|
||||
if ((filter == "military" || filter == "Military" || filter == "military units") && unitType.isMilitary()) return true
|
||||
return false
|
||||
}
|
||||
|
||||
fun isGreatPerson() = uniqueObjects.any { it.placeholderText == "Great Person - []" }
|
||||
}
|
||||
|
@ -18,9 +18,7 @@ class GreatPersonPickerScreen(val civInfo:CivilizationInfo) : PickerScreen() {
|
||||
closeButton.isVisible=false
|
||||
rightSideButton.setText("Choose a free great person".tr())
|
||||
|
||||
val greatPersonNames = GreatPersonManager().statToGreatPersonMapping.values
|
||||
.union(listOf("Great General"))
|
||||
val greatPersonUnits = greatPersonNames.map { civInfo.getEquivalentUnit(it) }
|
||||
val greatPersonUnits = civInfo.getGreatPeople()
|
||||
for (unit in greatPersonUnits)
|
||||
{
|
||||
val button = Button(skin)
|
||||
|
Reference in New Issue
Block a user