mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-25 23:29:47 +07:00
Code improvement for city state border conflict.
This commit is contained in:

committed by
Yair Morgenstern

parent
ad54fb3c56
commit
cb867f0066
@ -245,28 +245,15 @@ class NextTurnAutomation{
|
||||
private fun updateDiplomaticRelationship(civInfo: CivilizationInfo) {
|
||||
// Check if city-state invaded by other civs
|
||||
if (civInfo.isCityState()) {
|
||||
var militaryUnitsInBorder = HashMap<String, Int>()
|
||||
for (city in civInfo.cities) {
|
||||
for (tile in city.getTiles()) {
|
||||
val troop = tile.militaryUnit
|
||||
if (troop != null && troop.owner != civInfo.civName) {
|
||||
if (militaryUnitsInBorder.containsKey(troop.owner)) {
|
||||
militaryUnitsInBorder[troop.owner] = militaryUnitsInBorder[troop.owner]!! + 1
|
||||
} else {
|
||||
militaryUnitsInBorder[troop.owner] = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (civ in civInfo.gameInfo.civilizations) {
|
||||
if (civ == civInfo || civ.isBarbarianCivilization()) continue
|
||||
val diplomacy = civInfo.getDiplomacyManager(civ)!!
|
||||
if (diplomacy.diplomaticStatus == DiplomaticStatus.War) continue
|
||||
|
||||
for (otherCivName in militaryUnitsInBorder.filter { it.value > 0 }.keys) {
|
||||
val otherCiv = civInfo.gameInfo.getCivilization(otherCivName)
|
||||
if (!otherCiv.isBarbarianCivilization()) {
|
||||
val diplo = civInfo.getDiplomacyManager(otherCiv)
|
||||
if (diplo.diplomaticStatus != DiplomaticStatus.War) {
|
||||
diplo.influence -= 10f
|
||||
otherCiv.popupAlerts.add(PopupAlert(AlertType.BorderConflict,civInfo.civName))
|
||||
}
|
||||
val unitsInBorder = civ.getCivUnits().count { !it.type.isCivilian() && it.getTile().getOwner() == civInfo }
|
||||
if (unitsInBorder > 0 && diplomacy.influence < 30f) {
|
||||
diplomacy.influence -= 10f
|
||||
civ.popupAlerts.add(PopupAlert(AlertType.BorderConflict,civInfo.civName))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user