mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-19 20:28:56 +07:00
Resolved #1820 - Fixed a crashing bug with the AI trying to ally with defeated city states, as well as many other minor bugs
All caused by the fact that getKnownCivs didn't filter out defeated civs Also some minor code cleanup
This commit is contained in:
@ -35,10 +35,10 @@ class NextTurnAutomation{
|
||||
adoptPolicy(civInfo)
|
||||
} else {
|
||||
getFreeTechForCityStates(civInfo)
|
||||
updateDiplomaticRelationshipForCityStates(civInfo)
|
||||
}
|
||||
|
||||
chooseTechToResearch(civInfo)
|
||||
updateDiplomaticRelationship(civInfo)
|
||||
declareWar(civInfo)
|
||||
automateCityBombardment(civInfo)
|
||||
useGold(civInfo)
|
||||
@ -401,20 +401,18 @@ class NextTurnAutomation{
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateDiplomaticRelationship(civInfo: CivilizationInfo) {
|
||||
private fun updateDiplomaticRelationshipForCityStates(civInfo: CivilizationInfo) {
|
||||
// Check if city-state invaded by other civs
|
||||
if (civInfo.isCityState()) {
|
||||
for (otherCiv in civInfo.getKnownCivs().filter { it.isMajorCiv() }) {
|
||||
if(civInfo.isAtWarWith(otherCiv)) continue
|
||||
val diplomacy = civInfo.getDiplomacyManager(otherCiv)
|
||||
for (otherCiv in civInfo.getKnownCivs().filter { it.isMajorCiv() }) {
|
||||
if(civInfo.isAtWarWith(otherCiv)) continue
|
||||
val diplomacy = civInfo.getDiplomacyManager(otherCiv)
|
||||
|
||||
val unitsInBorder = otherCiv.getCivUnits().count { !it.type.isCivilian() && it.getTile().getOwner() == civInfo }
|
||||
if (unitsInBorder > 0 && diplomacy.relationshipLevel() < RelationshipLevel.Friend) {
|
||||
diplomacy.influence -= 10f
|
||||
if (!diplomacy.hasFlag(DiplomacyFlags.BorderConflict)) {
|
||||
otherCiv.popupAlerts.add(PopupAlert(AlertType.BorderConflict,civInfo.civName))
|
||||
diplomacy.setFlag(DiplomacyFlags.BorderConflict,10)
|
||||
}
|
||||
val unitsInBorder = otherCiv.getCivUnits().count { !it.type.isCivilian() && it.getTile().getOwner() == civInfo }
|
||||
if (unitsInBorder > 0 && diplomacy.relationshipLevel() < RelationshipLevel.Friend) {
|
||||
diplomacy.influence -= 10f
|
||||
if (!diplomacy.hasFlag(DiplomacyFlags.BorderConflict)) {
|
||||
otherCiv.popupAlerts.add(PopupAlert(AlertType.BorderConflict,civInfo.civName))
|
||||
diplomacy.setFlag(DiplomacyFlags.BorderConflict,10)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -200,11 +200,9 @@ class CivInfoTransientUpdater(val civInfo: CivilizationInfo){
|
||||
for (city in civInfo.cities) newDetailedCivResources.add(city.getCityResources())
|
||||
|
||||
if (!civInfo.isCityState()) {
|
||||
for (otherCiv in civInfo.getKnownCivs()) {
|
||||
if (otherCiv.getAllyCiv() == civInfo.civName) {
|
||||
for (city in otherCiv.cities) {
|
||||
newDetailedCivResources.add(city.getCityResourcesForAlly())
|
||||
}
|
||||
for (otherCiv in civInfo.getKnownCivs().filter { it.getAllyCiv() == civInfo.civName }) {
|
||||
for (city in otherCiv.cities) {
|
||||
newDetailedCivResources.add(city.getCityResourcesForAlly())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +133,8 @@ class CivilizationInfo {
|
||||
|
||||
fun getDiplomacyManager(civInfo: CivilizationInfo) = getDiplomacyManager(civInfo.civName)
|
||||
fun getDiplomacyManager(civName: String) = diplomacy[civName]!!
|
||||
fun getKnownCivs() = diplomacy.values.map { it.otherCiv() }
|
||||
/** Returns only undefeated civs, aka the ones we care about */
|
||||
fun getKnownCivs() = diplomacy.values.map { it.otherCiv() }.filter { !it.isDefeated() }
|
||||
fun knows(otherCivName: String) = diplomacy.containsKey(otherCivName)
|
||||
fun knows(otherCiv: CivilizationInfo) = knows(otherCiv.civName)
|
||||
|
||||
@ -530,7 +531,9 @@ class CivilizationInfo {
|
||||
fun updateAllyCivForCityState() {
|
||||
var newAllyName = ""
|
||||
if (!isCityState()) return
|
||||
val maxInfluence = diplomacy.filter{ !it.value.otherCiv().isCityState() && !it.value.otherCiv().isDefeated() }.maxBy { it.value.influence }
|
||||
val maxInfluence = diplomacy
|
||||
.filter{ !it.value.otherCiv().isCityState() && !it.value.otherCiv().isDefeated() }
|
||||
.maxBy { it.value.influence }
|
||||
if (maxInfluence != null && maxInfluence.value.influence >= 60) {
|
||||
newAllyName = maxInfluence.key
|
||||
}
|
||||
|
@ -183,7 +183,8 @@ class TechManager {
|
||||
scienceFromResearchAgreements = 0
|
||||
}
|
||||
if (overflowScience != 0){ // https://forums.civfanatics.com/threads/the-mechanics-of-overflow-inflation.517970/
|
||||
val techsResearchedKnownCivs = civInfo.getKnownCivs().count { it.isMajorCiv() && it.tech.isResearched(currentTechnologyName()!!) }
|
||||
val techsResearchedKnownCivs = civInfo.getKnownCivs()
|
||||
.count { it.isMajorCiv() && it.tech.isResearched(currentTechnologyName()!!) }
|
||||
val undefeatedCivs = UncivGame.Current.gameInfo.civilizations.count { it.isMajorCiv() && !it.isDefeated() }
|
||||
techsInProgress[currentTechnology] = techsInProgress[currentTechnology]!! + ((1 + techsResearchedKnownCivs / undefeatedCivs.toFloat() * 0.3f)* overflowScience).toInt()
|
||||
overflowScience = 0
|
||||
|
@ -442,7 +442,6 @@ class DiplomacyManager() {
|
||||
if (!otherCiv.isCityState()) {
|
||||
for (thirdCiv in otherCiv.getKnownCivs()) {
|
||||
if (thirdCiv.isCityState() && thirdCiv.getAllyCiv() == otherCiv.civName
|
||||
&& !thirdCiv.isDefeated()
|
||||
&& thirdCiv.knows(civInfo)
|
||||
&& thirdCiv.getDiplomacyManager(civInfo).canDeclareWar()) {
|
||||
thirdCiv.getDiplomacyManager(civInfo).declareWar()
|
||||
|
@ -290,7 +290,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
||||
private fun updateDiplomacyButton(civInfo: CivilizationInfo) {
|
||||
diplomacyButtonWrapper.clear()
|
||||
if(!civInfo.isDefeated() && civInfo.getKnownCivs()
|
||||
.filterNot { it.isDefeated() || it==viewingCiv || it.isBarbarian() }
|
||||
.filterNot { it==viewingCiv || it.isBarbarian() }
|
||||
.any()) {
|
||||
displayTutorial(Tutorial.OtherCivEncountered)
|
||||
val btn = TextButton("Diplomacy".tr(), skin)
|
||||
|
Reference in New Issue
Block a user