unit.getMatchingUniques()

This commit is contained in:
Yair Morgenstern 2020-08-24 09:48:33 +03:00
parent d4b8aae84a
commit 21c8336563
6 changed files with 10 additions and 90 deletions

View file

@ -174,82 +174,6 @@ Lost ability =
National ability =
[firstValue] vs [secondValue] =
# Nations
Receive free Great Scientist when you discover Writing, Earn Great Scientists 50% faster =
Ingenuity =
City-State Influence degrades at half and recovers at twice the normal rate =
Hellenic League =
Great general provides double combat bonus, and spawns 50% faster =
Art of War =
+20% production towards Wonder construction =
Monument Builders =
+2 movement for all naval units =
Sun Never Sets =
+2 Culture per turn from cities before discovering Steam Power =
Ancien Régime =
Strategic Resources provide +1 Production, and Horses, Iron and Uranium Resources provide double quantity =
Siberian Riches =
+25% Production towards any buildings that already exist in the Capital =
The Glory of Rome =
+1 Gold from each Trade Route, Oil resources provide double quantity =
Trade Caravans =
All land military units have +1 sight, 50% discount when purchasing tiles =
Manifest Destiny =
Units fight as though they were at full strength even when damaged =
Bushido =
67% chance to earn 25 Gold and recruit a Barbarian unit from a conquered encampment, -25% land units maintenance. =
Furor Teutonicus =
Unhappiness from number of Cities doubled, Unhappiness from number of Citizens halved. =
Population Growth =
Pay only one third the usual cost for naval unit maintenance. Melee naval units have a 1/3 chance to capture defeated naval units. =
Barbary Corsairs =
+2 Science for all specialists and Great Person tile improvements =
Scholars of the Jade Hall =
All units move through Forest and Jungle Tiles in friendly territory as if they have roads. These tiles can be used to establish City Connections upon researching the Wheel. =
The Great Warpath =
Golden Ages last 50% longer. During a Golden Age, units receive +1 Movement and +10% Strength =
Achaemenid Legacy =
Can embark and move over Coasts and Oceans immediately. +1 Sight when embarked. +10% Combat Strength bonus if within 2 tiles of a Moai. =
Wayfinding =
Food and Culture from Friendly City-States are increased by 50% =
Father Governs Children =
Receive triple Gold from Barbarian encampments and pillaging Cities. Embarked units can defend themselves. =
River Warlord =
100 Gold for discovering a Natural Wonder (bonus enhanced to 500 Gold if first to discover it). Culture, Happiness and tile yields from Natural Wonders doubled. =
Seven Cities of Gold =
Combat Strength +30% when fighting City-State units or attacking a City-State itself. All mounted units have +1 Movement. =
Mongol Terror =
Units ignore terrain costs when moving into any tile with Hills. No maintenance costs for improvements in Hills; half cost elsewhere. =
Great Andean Road =
+1 Movement to all embarked units, units pay only 1 movement point to embark and disembark. Melee units pay no movement cost to pillage. =
Viking Fury =
Gain Culture for the empire from each enemy unit killed =
Sacrificial Captives =
# New game screen

View file

@ -195,8 +195,7 @@ object SpecificUnitAutomation {
fun automateImprovementPlacer(unit: MapUnit) {
if (unit.getTile().militaryUnit == null) return // Don't move until you're accompanied by a military unit
val improvementName = unit.getUniques().first { it.placeholderText == "Can construct []" }
.params[0]
val improvementName = unit.getMatchingUniques("Can construct []").first().params[0]
val improvement = unit.civInfo.gameInfo.ruleSet.tileImprovements[improvementName]!!
val relatedStat = improvement.toHashMap().maxBy { it.value }!!.key

View file

@ -103,7 +103,7 @@ object UnitAutomation {
if (unit.name == Constants.greatGeneral || unit.baseUnit.replaces == Constants.greatGeneral)
return SpecificUnitAutomation.automateGreatGeneral(unit)
if (unit.getUniques().any { it.placeholderText == "Can construct []" })
if (unit.hasUnique("Can construct []"))
return SpecificUnitAutomation.automateImprovementPlacer(unit) // includes great people plus moddable units
return // The AI doesn't know how to handle unknown civilian units

View file

@ -146,11 +146,9 @@ object Battle {
if (defender.isDefeated()
&& defender is MapUnitCombatant
&& attacker is MapUnitCombatant) {
for (unique in attacker.unit.getUniques()) {
if(unique.placeholderText == "Heals [] damage if it kills a unit"){
val amountToHeal = unique.params[0].toInt()
attacker.unit.healBy(amountToHeal)
}
for (unique in attacker.unit.getMatchingUniques("Heals [] damage if it kills a unit")) {
val amountToHeal = unique.params[0].toInt()
attacker.unit.healBy(amountToHeal)
}
}
}
@ -424,10 +422,6 @@ object Battle {
// the diverging base chance is coded into the effect string as (133%) for now, with 50% as default
if (attacker !is MapUnitCombatant) return false // allow simple access to unit property
if (defender !is MapUnitCombatant) return false
// if (!attacker.isMelee()) return false // checked in attack()
// Embarked units should never use the ability
// I see this as a rule detail, therefore I did not move the check outside this function
if (defender.unit.isEmbarked()) return false
// Calculate success chance: Base chance from json, then ratios of *base* strength and mobility
// Promotions have no effect as per what I could find in available documentation

View file

@ -128,6 +128,9 @@ class MapUnit {
return tempUniques
}
fun getMatchingUniques(placeholderText:String): Sequence<Unique>
= tempUniques.asSequence().filter { it.placeholderText == placeholderText }
fun updateUniques(){
val uniques = ArrayList<Unique>()
val baseUnit = baseUnit()
@ -146,7 +149,7 @@ class MapUnit {
}
fun hasUnique(unique:String): Boolean {
return getUniques().any { it.text == unique }
return getUniques().any { it.placeholderText == unique }
}
fun updateVisibleTiles() {

View file

@ -364,7 +364,7 @@ object UnitActions {
fun getImprovementConstructionActions(unit: MapUnit, tile: TileInfo): ArrayList<UnitAction> {
val finalActions = ArrayList<UnitAction>()
for (unique in unit.getUniques().filter { it.placeholderText == "Can construct []" }) {
for (unique in unit.getMatchingUniques("Can construct []")) {
val improvementName = unique.params[0]
finalActions += UnitAction(
type = UnitActionType.Create,