City state intrusion anger (#5090)

* move functions, greece UP

* CS influence from killing barbs

* Greece healing in CS territory

* move diplomacy bonuses into CityStateFunctions.kt

* Split filter in Battle.kt, nicer code
This commit is contained in:
SimonCeder
2021-09-05 20:22:02 +02:00
committed by GitHub
parent 2474c6a635
commit c7264556ea
7 changed files with 79 additions and 36 deletions

View File

@ -41,7 +41,7 @@
"leaderName": "Alexander",
"adjective": ["Greek"],
"startBias": ["Coast"],
// "preferredVictoryType":"Diplomatic",
"preferredVictoryType":"Diplomatic",
"startIntroPart1": "May the blessings of the gods be upon you, oh great King Alexander! You are the ruler of the mighty Greek nation. Your people lived for so many years in isolated city-states - legendary cities such as Athens, Sparta, Thebes - where they gave the world many great things, such as democracy, philosophy, tragedy, art and architecture, the very foundation of Western Civilization. Although few in number and often hostile to each other, in the 5th century BC they were able to defeat their much larger neighbor, Persia, on land and sea.",
"startIntroPart2": "Alexander, your people stand ready to march to war, to spread the great Greek culture to millions and to bring you everlasting glory. Are you ready to accept your destiny, King Alexander? Will you lead your people to triumph and greatness? Can you build a civilization that will stand the test of time?",
@ -59,7 +59,7 @@
"outerColor": [181, 232, 232],
"innerColor": [68,142,249],
"uniqueName": "Hellenic League",
"uniques": ["City-State Influence degrades [50]% slower", "City-State Influence recovers at twice the normal rate"],
"uniques": ["City-State Influence degrades [50]% slower", "City-State Influence recovers at twice the normal rate", "City-State territory always counts as friendly territory"],
"cities": ["Athens","Sparta","Corinth","Argos","Knossos","Mycenae","Pharsalos","Ephesus","Halicarnassus","Rhodes",
"Eretria","Pergamon","Miletos","Megara","Phocaea","Sicyon","Tiryns","Samos","Mytilene","Chios",
"Paros","Elis","Syracuse","Herakleia","Gortyn","Chalkis","Pylos","Pella","Naxos","Sicyon",
@ -720,7 +720,7 @@
"leaderName": "Gustavus Adolphus",
"adjective": ["Swedish"],
"startBias": ["Tundra"],
"preferredVictoryType": "Domination",
"preferredVictoryType": "Diplomatic",
"startIntroPart1": "All hail the transcendent King Gustavus Adolphus, founder of the Swedish Empire and her most distinguished military tactician. It was during your reign that Sweden emerged as one of the greatest powers in Europe, due in no small part to your wisdom, both on and off the battlefield. As king, you initiated a number of domestic reforms that ensured the economic stability and prosperity of your people. As the general who came to be known as the \"Lion of the North,\" your visionary designs in warfare gained the admiration of military commanders the world over. Thanks to your triumphs in the Thirty Years' War, you were assured a legacy as one of history's greatest generals.",
"startIntroPart2": "Oh noble King, the people long for your prudent leadership, hopeful that once again they will see your kingdom rise to glory. Will you devise daring new strategies, leading your armies to victory on the theater of war? Will you build a civilization that stands the test of time?",

View File

@ -45,8 +45,8 @@ object NextTurnAutomation {
issueRequests(civInfo)
adoptPolicy(civInfo) // todo can take a second - why?
} else {
getFreeTechForCityStates(civInfo)
updateDiplomaticRelationshipForCityStates(civInfo)
civInfo.getFreeTechForCityState()
civInfo.updateDiplomaticRelationshipForCityState()
}
chooseTechToResearch(civInfo)
@ -238,18 +238,6 @@ object NextTurnAutomation {
}
}
private fun getFreeTechForCityStates(civInfo: CivilizationInfo) {
// City-States automatically get all techs that at least half of the major civs know
val researchableTechs = civInfo.gameInfo.ruleSet.technologies.keys
.filter { civInfo.tech.canBeResearched(it) }
for (tech in researchableTechs) {
val aliveMajorCivs = civInfo.gameInfo.getAliveMajorCivs()
if (aliveMajorCivs.count { it.tech.isResearched(tech) } >= aliveMajorCivs.count() / 2)
civInfo.tech.addTechnology(tech)
}
return
}
private fun chooseTechToResearch(civInfo: CivilizationInfo) {
if (civInfo.tech.techsToResearch.isEmpty()) {
val researchableTechs = civInfo.gameInfo.ruleSet.technologies.values
@ -477,23 +465,6 @@ object NextTurnAutomation {
}
}
private fun updateDiplomaticRelationshipForCityStates(civInfo: CivilizationInfo) {
// Check if city-state invaded by other civs
for (otherCiv in civInfo.getKnownCivs().filter { it.isMajorCiv() }) {
if (civInfo.isAtWarWith(otherCiv)) continue
val diplomacy = civInfo.getDiplomacyManager(otherCiv)
val unitsInBorder = otherCiv.getCivUnits().count { !it.isCivilian() && it.getTile().getOwner() == civInfo }
if (unitsInBorder > 0 && diplomacy.relationshipLevel() < RelationshipLevel.Friend) {
diplomacy.addInfluence(-10f)
if (!diplomacy.hasFlag(DiplomacyFlags.BorderConflict)) {
otherCiv.popupAlerts.add(PopupAlert(AlertType.BorderConflict, civInfo.civName))
diplomacy.setFlag(DiplomacyFlags.BorderConflict, 10)
}
}
}
}
private fun declareWar(civInfo: CivilizationInfo) {
if (civInfo.victoryType() == VictoryType.Cultural) return
if (civInfo.cities.isEmpty() || civInfo.diplomacy.isEmpty()) return

View File

@ -154,6 +154,15 @@ object Battle {
} catch (ex: Exception) {
} // parameter is not a stat
}
// CS friendship from killing barbarians
if (defeatedUnit.matchesCategory("Barbarian") && defeatedUnit.matchesCategory("Military") && civUnit.getCivInfo().isMajorCiv()) {
for (cityState in UncivGame.Current.gameInfo.getAliveCityStates()) {
if (defeatedUnit.unit.threatensCiv(cityState)) {
cityState.threateningBarbarianKilledBy(civUnit.getCivInfo())
}
}
}
}
private fun tryCaptureUnit(attacker: MapUnitCombatant, defender: MapUnitCombatant): Boolean {

View File

@ -344,4 +344,50 @@ class CityStateFunctions(val civInfo: CivilizationInfo) {
return false
}
fun updateDiplomaticRelationshipForCityState() {
// Check if city-state invaded by other civs
if (getNumThreateningBarbarians() > 0) return // Assume any players are there to fight barbarians
for (otherCiv in civInfo.getKnownCivs().filter { it.isMajorCiv() }) {
if (civInfo.isAtWarWith(otherCiv)) continue
if (otherCiv.hasUnique("City-State territory always counts as friendly territory")) continue
val diplomacy = civInfo.getDiplomacyManager(otherCiv)
if (diplomacy.hasFlag(DiplomacyFlags.AngerFreeIntrusion)) continue // They recently helped us
val unitsInBorder = otherCiv.getCivUnits().count { !it.isCivilian() && it.getTile().getOwner() == civInfo }
if (unitsInBorder > 0 && diplomacy.relationshipLevel() < RelationshipLevel.Friend) {
diplomacy.addInfluence(-10f)
if (!diplomacy.hasFlag(DiplomacyFlags.BorderConflict)) {
otherCiv.popupAlerts.add(PopupAlert(AlertType.BorderConflict, civInfo.civName))
diplomacy.setFlag(DiplomacyFlags.BorderConflict, 10)
}
}
}
}
fun getFreeTechForCityState() {
// City-States automatically get all techs that at least half of the major civs know
val researchableTechs = civInfo.gameInfo.ruleSet.technologies.keys
.filter { civInfo.tech.canBeResearched(it) }
for (tech in researchableTechs) {
val aliveMajorCivs = civInfo.gameInfo.getAliveMajorCivs()
if (aliveMajorCivs.count { it.tech.isResearched(tech) } >= aliveMajorCivs.count() / 2)
civInfo.tech.addTechnology(tech)
}
return
}
private fun getNumThreateningBarbarians(): Int {
return civInfo.gameInfo.getBarbarianCivilization().getCivUnits().count { it.threatensCiv(civInfo) }
}
fun threateningBarbarianKilledBy(otherCiv: CivilizationInfo) {
val diplomacy = civInfo.getDiplomacyManager(otherCiv)
diplomacy.addInfluence(12f)
if (diplomacy.hasFlag(DiplomacyFlags.AngerFreeIntrusion))
diplomacy.setFlag(DiplomacyFlags.AngerFreeIntrusion, diplomacy.getFlag(DiplomacyFlags.AngerFreeIntrusion) + 5)
else
diplomacy.setFlag(DiplomacyFlags.AngerFreeIntrusion, 5)
}
}

View File

@ -909,6 +909,15 @@ class CivilizationInfo {
cityStateFunctions.tributeWorker(demandingCiv)
}
fun canGiveStat(statType: Stat) = cityStateFunctions.canGiveStat(statType)
fun updateDiplomaticRelationshipForCityState() {
cityStateFunctions.updateDiplomaticRelationshipForCityState()
}
fun getFreeTechForCityState() {
cityStateFunctions.getFreeTechForCityState()
}
fun threateningBarbarianKilledBy(otherCiv: CivilizationInfo) {
cityStateFunctions.threateningBarbarianKilledBy(otherCiv)
}
fun getAllyCiv() = allyCivName
fun setAllyCiv(newAllyName: String?) { allyCivName = newAllyName }

View File

@ -40,7 +40,8 @@ enum class DiplomacyFlags{
ProvideMilitaryUnit,
EverBeenFriends,
MarriageCooldown,
NotifiedAfraid
NotifiedAfraid,
AngerFreeIntrusion
}
enum class DiplomaticModifiers{
@ -322,7 +323,8 @@ class DiplomacyManager() {
* This includes friendly and allied city-states and the open border treaties.
*/
fun isConsideredFriendlyTerritory(): Boolean {
if (civInfo.isCityState() && relationshipLevel() >= RelationshipLevel.Friend)
if (civInfo.isCityState() &&
(relationshipLevel() >= RelationshipLevel.Friend || otherCiv().hasUnique("City-State territory always counts as friendly territory")))
return true
return hasOpenBorders
}

View File

@ -1037,5 +1037,11 @@ class MapUnit {
return power
}
fun threatensCiv(civInfo: CivilizationInfo): Boolean {
if (getTile().getOwner() == civInfo)
return true
return getTile().neighbors.any { it.getOwner() == civInfo }
}
//endregion
}