mirror of
https://github.com/yairm210/Unciv.git
synced 2025-10-02 08:22:08 -04: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:
parent
713086849a
commit
87c6819462
@ -279,7 +279,7 @@ object UnitAutomation {
|
|||||||
.firstOrNull {
|
.firstOrNull {
|
||||||
val tile = it.currentTile
|
val tile = it.currentTile
|
||||||
it.type == UnitType.Civilian &&
|
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)
|
&& tile.militaryUnit == null && unit.movement.canMoveTo(tile) && unit.movement.canReach(tile)
|
||||||
}
|
}
|
||||||
if (settlerOrGreatPersonToAccompany == null) return false
|
if (settlerOrGreatPersonToAccompany == null) return false
|
||||||
|
@ -235,7 +235,7 @@ class CivilizationInfo {
|
|||||||
|
|
||||||
//region Units
|
//region Units
|
||||||
fun getCivUnits(): Sequence<MapUnit> = units.asSequence()
|
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) {
|
fun addUnit(mapUnit: MapUnit, updateCivInfo: Boolean = true) {
|
||||||
val newList = ArrayList(units)
|
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
|
//endregion
|
||||||
|
|
||||||
//region state-changing functions
|
//region state-changing functions
|
||||||
@ -559,7 +563,7 @@ class CivilizationInfo {
|
|||||||
if (!gameInfo.ruleSet.units.containsKey(unitName)) return
|
if (!gameInfo.ruleSet.units.containsKey(unitName)) return
|
||||||
val unit = getEquivalentUnit(unitName)
|
val unit = getEquivalentUnit(unitName)
|
||||||
placeUnitNearTile(cityToAddTo.location, unit.name)
|
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)
|
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
|
val greatPeople = ruleSet.units.values
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.filter { baseUnit -> baseUnit.uniques.any { it.equalsPlaceholderText("Great Person - []") } }
|
.filter { it.isGreatPerson() }
|
||||||
.map { it.getReplacedUnit(ruleSet) }
|
.map { it.getReplacedUnit(ruleSet) }
|
||||||
.distinct()
|
.distinct()
|
||||||
.filter { !challengerGreatPeople.contains(it) && !cityStateGreatPeople.contains(it) }
|
.filter { !challengerGreatPeople.contains(it) && !cityStateGreatPeople.contains(it) }
|
||||||
|
@ -304,6 +304,8 @@ class MapUnit {
|
|||||||
|
|
||||||
fun canGarrison() = type.isMilitary() && type.isLandUnit()
|
fun canGarrison() = type.isMilitary() && type.isLandUnit()
|
||||||
|
|
||||||
|
fun isGreatPerson() = baseUnit.isGreatPerson()
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
//region state-changing functions
|
//region state-changing functions
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.unciv.models.ruleset
|
package com.unciv.models.ruleset
|
||||||
|
|
||||||
import com.unciv.Constants
|
|
||||||
import com.unciv.logic.city.CityInfo
|
import com.unciv.logic.city.CityInfo
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
import com.unciv.models.stats.Stats
|
import com.unciv.models.stats.Stats
|
||||||
@ -59,14 +58,21 @@ object UniqueTriggerActivation {
|
|||||||
"Free Great Person" -> {
|
"Free Great Person" -> {
|
||||||
if (civInfo.isPlayerCivilization()) civInfo.greatPeople.freeGreatPeople++
|
if (civInfo.isPlayerCivilization()) civInfo.greatPeople.freeGreatPeople++
|
||||||
else {
|
else {
|
||||||
|
val greatPeople = civInfo.getGreatPeople()
|
||||||
|
if (greatPeople.isEmpty()) return
|
||||||
|
var greatPerson = civInfo.getGreatPeople().random()
|
||||||
|
|
||||||
val preferredVictoryType = civInfo.victoryType()
|
val preferredVictoryType = civInfo.victoryType()
|
||||||
val greatPerson = when (preferredVictoryType) {
|
if (preferredVictoryType == VictoryType.Cultural) {
|
||||||
VictoryType.Cultural -> "Great Artist"
|
val culturalGP = greatPeople.firstOrNull { it.uniques.contains("Great Person - [Culture]") }
|
||||||
VictoryType.Scientific -> "Great Scientist"
|
if (culturalGP != null) greatPerson = culturalGP
|
||||||
else -> civInfo.gameInfo.ruleSet.units.values
|
|
||||||
.filter { it.uniqueObjects.any { it.placeholderText == "Great Person - []" } }.map { it.name }.random()
|
|
||||||
}
|
}
|
||||||
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" ->
|
"+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
|
if ((filter == "military" || filter == "Military" || filter == "military units") && unitType.isMilitary()) return true
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isGreatPerson() = uniqueObjects.any { it.placeholderText == "Great Person - []" }
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,7 @@ class GreatPersonPickerScreen(val civInfo:CivilizationInfo) : PickerScreen() {
|
|||||||
closeButton.isVisible=false
|
closeButton.isVisible=false
|
||||||
rightSideButton.setText("Choose a free great person".tr())
|
rightSideButton.setText("Choose a free great person".tr())
|
||||||
|
|
||||||
val greatPersonNames = GreatPersonManager().statToGreatPersonMapping.values
|
val greatPersonUnits = civInfo.getGreatPeople()
|
||||||
.union(listOf("Great General"))
|
|
||||||
val greatPersonUnits = greatPersonNames.map { civInfo.getEquivalentUnit(it) }
|
|
||||||
for (unit in greatPersonUnits)
|
for (unit in greatPersonUnits)
|
||||||
{
|
{
|
||||||
val button = Button(skin)
|
val button = Button(skin)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user