Removed final vestiges of old Bonus/Penalty effects.

Friendship ended with Regex, now Unique is my best friend.
This commit is contained in:
Yair Morgenstern 2021-06-30 21:02:53 +03:00
parent 3b75f2209e
commit aeceead616
6 changed files with 17 additions and 34 deletions

View File

@ -282,7 +282,7 @@
"requiredResource": "Horses",
"upgradesTo": "Knight",
"obsoleteTech": "Metallurgy",
"uniques": ["Can move after attacking","No defensive terrain bonus","Penalty vs City 33%" ],
"uniques": ["Can move after attacking","No defensive terrain bonus","-[33]% Strength vs [City]" ],
"hurryCostModifier": 20,
"attackSound": "horse"
},
@ -299,7 +299,7 @@
"obsoleteTech": "Metallurgy",
"promotions": ["Great Generals I"],
"requiredResource": "Horses",
"uniques": ["Can move after attacking", "No defensive terrain bonus", "Penalty vs City 33%"],
"uniques": ["Can move after attacking", "No defensive terrain bonus", "-[33]% Strength vs [City]"],
"hurryCostModifier": 20,
"attackSound": "horse"
},
@ -461,7 +461,7 @@
"obsoleteTech": "Military Science",
"upgradesTo": "Cavalry",
"requiredResource": "Horses",
"uniques": ["Can move after attacking","No defensive terrain bonus","Penalty vs City 33%" ],
"uniques": ["Can move after attacking","No defensive terrain bonus","-[33]% Strength vs [City]" ],
"attackSound": "horse"
},
{
@ -509,7 +509,7 @@
"requiredTech": "Chivalry",
"obsoleteTech": "Military Science",
"upgradesTo": "Cavalry",
"uniques": ["Can move after attacking","No defensive terrain bonus","+[50]% Strength vs [Mounted]","Penalty vs City 33%"],
"uniques": ["Can move after attacking","No defensive terrain bonus","+[50]% Strength vs [Mounted]","-[33]% Strength vs [City]"],
"attackSound": "shot"
},
{
@ -795,7 +795,7 @@
"cost": 185,
"requiredTech": "Metallurgy",
"requiredResource": "Horses",
"uniques": ["Can move after attacking","No defensive terrain bonus","Penalty vs City 33%"],
"uniques": ["Can move after attacking","No defensive terrain bonus","-[33]% Strength vs [City]"],
"promotions": ["Formation I"],
"upgradesTo": "Anti-Tank Gun",
"obsoleteTech": "Combined Arms",
@ -811,7 +811,7 @@
"cost": 185,
"requiredTech": "Metallurgy",
"requiredResource": "Horses",
"uniques": ["Can move after attacking","No defensive terrain bonus","Penalty vs City 33%",
"uniques": ["Can move after attacking","No defensive terrain bonus","-[33]% Strength vs [City]",
"[+1] Visibility Range", "No movement cost to pillage"],
"promotions": ["Formation I"],
"upgradesTo": "Anti-Tank Gun",
@ -881,7 +881,7 @@
"obsoleteTech": "Combustion",
"requiredResource": "Horses",
"upgradesTo": "Landship",
"uniques": ["Can move after attacking","No defensive terrain bonus","Penalty vs City 33%" ],
"uniques": ["Can move after attacking","No defensive terrain bonus","-[33]% Strength vs [City]" ],
"attackSound": "horse"
},
{
@ -897,7 +897,7 @@
"requiredResource": "Horses",
"upgradesTo": "Landship",
"uniques": ["Can move after attacking","No defensive terrain bonus",
"Penalty vs City 33%", "+[50]% Strength vs [wounded units]"],
"-[33]% Strength vs [City]", "+[50]% Strength vs [wounded units]"],
"attackSound": "horse"
},
{

View File

@ -27,7 +27,9 @@ object BattleDamage {
if (enemy.matchesCategory(unique.params[1]))
modifiers.add("vs [${unique.params[1]}]", unique.params[0].toInt())
}
for (unique in combatant.unit.getMatchingUniques("-[]% Strength vs []")) {
for (unique in combatant.unit.getMatchingUniques("-[]% Strength vs []")+
civInfo.getMatchingUniques("-[]% Strength vs []")
) {
if (enemy.matchesCategory(unique.params[1]))
modifiers.add("vs [${unique.params[1]}]", -unique.params[0].toInt())
}

View File

@ -165,11 +165,11 @@ class Nation : INamed {
if (!unit.getResourceRequirements().containsKey(resource))
textList += " " + "[$resource] not required".tr()
for (unique in unit.uniques.filterNot { it in originalUnit.uniques })
textList += " " + Translations.translateBonusOrPenalty(unique)
textList += " " + unique.tr()
for (unique in originalUnit.uniques.filterNot { it in unit.uniques })
textList += " " + "Lost ability".tr() + "(" + "vs [${originalUnit.name}]".tr() + "): " + Translations.translateBonusOrPenalty(unique)
textList += " " + "Lost ability".tr() + "(" + "vs [${originalUnit.name}]".tr() + "): " + unique.tr()
for (promotion in unit.promotions.filter { it !in originalUnit.promotions })
textList += " " + promotion.tr() + " (" + Translations.translateBonusOrPenalty(ruleset.unitPromotions[promotion]!!.effect) + ")"
textList += " " + promotion.tr() + " (" + ruleset.unitPromotions[promotion]!!.effect.tr() + ")"
} else if (unit.replaces != null) {
textList += unit.name.tr() + " - " + "Replaces [${unit.replaces}], which is not found in the ruleset!".tr()
} else {

View File

@ -8,8 +8,6 @@ import com.unciv.logic.map.MapUnit
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.Unique
import com.unciv.models.stats.INamed
import com.unciv.models.translations.Translations
import com.unciv.models.translations.getPlaceholderText
import com.unciv.models.translations.tr
import com.unciv.ui.utils.Fonts
import kotlin.math.pow
@ -50,7 +48,7 @@ class BaseUnit : INamed, IConstruction {
infoList += promotion.tr()
if (replacementTextForUniques != "") infoList += replacementTextForUniques
else for (unique in uniques)
infoList += Translations.translateBonusOrPenalty(unique)
infoList += unique.tr()
return infoList.joinToString()
}
@ -76,7 +74,7 @@ class BaseUnit : INamed, IConstruction {
if (replacementTextForUniques != "") sb.appendLine(replacementTextForUniques)
else for (unique in uniques)
sb.appendLine(Translations.translateBonusOrPenalty(unique))
sb.appendLine(unique.tr())
if (promotions.isNotEmpty()) {
sb.append((if (promotions.size == 1) "Free promotion:" else "Free promotions:").tr())

View File

@ -3,7 +3,6 @@ package com.unciv.models.ruleset.unit
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.Unique
import com.unciv.models.stats.INamed
import com.unciv.models.translations.Translations
import com.unciv.models.translations.tr
class Promotion : INamed{
@ -20,7 +19,7 @@ class Promotion : INamed{
val stringBuilder = StringBuilder()
for (unique in uniques + effect) {
stringBuilder.appendLine(Translations.translateBonusOrPenalty(unique))
stringBuilder.appendLine(unique.tr())
}
if(prerequisites.isNotEmpty()) {

View File

@ -179,22 +179,6 @@ class Translations : LinkedHashMap<String, TranslationEntry>(){
val translationFilesTime = System.currentTimeMillis() - startTime
println("Loading percent complete of languages - "+translationFilesTime+"ms")
}
companion object {
// Regex compilation is expensive, best to save it
val bonusOrPenaltyRegex = Regex("""(Bonus|Penalty) vs (.*) (\d*)%""")
fun translateBonusOrPenalty(unique: String): String {
val regexResult = bonusOrPenaltyRegex.matchEntire(unique)
if (regexResult == null) return unique.tr()
else {
var separatorCharacter = " "
if (UncivGame.Current.settings.language == "Simplified_Chinese") separatorCharacter = ""
val start = regexResult.groups[1]!!.value + " vs [" + regexResult.groups[2]!!.value + "]"
val translatedUnique = start.tr() + separatorCharacter + regexResult.groups[3]!!.value + "%"
return translatedUnique
}
}
}
}