Here's the revised peace logic for the upcoming version 1.1, in great detail. Feel free to suggest how this could be improved.
Wrote this up somewhat hastily so feel free to ask if anything seems unclear.
Wrote this up somewhat hastily so feel free to ask if anything seems unclear.
Code:
[PART 1: INITIAL CHECKS]
1. Peace Blocked
- If game options "Permanent War" or "Permanent War or Peace" are enabled, AI will never make peace with anyone.
- If AI is a human's teammate, they will never make peace with anyone.
- If AI is someone's vassal, they will never make peace with anyone.
- AI can't make peace with vassals.
- AI can't make peace if at war with a major civ for less than 10 turns.
- AI can't make peace if at war with a City-State for less than 1 turn.
- If player captured one of the AI's cities less than 2 turns ago and the AI has more than one combat unit near that player's cities, they can't make peace.
- AI can't make peace with a City-State if at permanent war or at war with the City-State's ally.
- AI can't make peace if locked into war by a trade deal or coop war.
- AI can't make peace if the other player has no capital city.
- AI can't make peace if CvTeam::canChangeWarPeace() returns false for some other reason.
2. Critical State Check
- AI is in a critical state if their empire is Super Unhappy.
- AI is in a critical state if their capital is projected to fall in the next turn, or is at 1/2 HP or less.
- AI is in a critical state if their War State with any major civ is "Nearly Defeated".
- AI immediately peaces out with all valid City-States if in a critical state.
- AI will agree to peace with all valid major civs if in a critical state.
3. Make Peace With City-States
- AI will make peace with all City-States if their War State with any major civ is "Defensive", except if:
a. The City-State's capital OR a city whose original owner is the AI's team is in danger from that AI, and;
b. That city is "under siege" (took damage last turn / is surrounded by enemies) or blockaded.
- AI can only target one City-State for war at a time, updated each turn in DoUpdateMinorCivApproaches(). If the AI is at war with a City-State that isn't their current target, they will make peace unless:
a. The City-State's capital OR a city whose original owner is the AI's team is in danger from that AI, and;
b. That city is "under siege" (took damage last turn / is surrounded by enemies) or blockaded.
- If War State is fine and the City-State is the AI's current target, then the AI won't make peace.
[PART 2: EVALUATE EACH MAJOR CIV]
These steps are repeated for each valid major civ.
1. Determine War Duration
The AI's "war duration" is the number of turns the AI and the player have been at war.
Each time the AI captures a city from the player after the war begins, the war duration resets to 0.
2. Calculate Own City Danger
- Loop through each city that is currently endangered by the player or their allies.
- Add that city's Danger to the AI's total Danger value.
- The "we are in serious danger" flag is initially set to FALSE.
[Evaluation #1]
- City Danger starts at 1.
- Add 1 to City Danger if the city's tactical AI "land zone" is controlled by any of the AI's enemies.
- Add 1 to City Danger if the city's tactical AI "water zone" is controlled by any of the AI's enemies.
If the city is in danger of falling next turn, is "under siege" (took damage last turn / is surrounded by enemies), or is blockaded AND has taken at least 1/4 of its max HP in damage, proceed to Evaluation #2.
[Evaluation #2]
- If the city is in danger of being lost next turn, add 3 to City Danger. Otherwise, add 1 to City Danger.
- If the city meets one of these criteria:
a. Is in danger of being lost next turn
b. Is blockaded AND has taken at least 1/4 of its max HP in damage
c. Has taken at least 1/2 of its max HP in damage
...AND meets one of these criteria:
a. Originally founded by the AI
b. Is an original major capital
c. Is the AI's Holy City
d. Is the other player's Holy City
e. Has World Wonders
f. Has National Wonders
...Then set "we are in serious danger" to TRUE.
[Importance Multiplier]
- If the city is the AI's capital, multiply City Danger by 3.
- Otherwise, if it's an original major capital, the Holy City for the AI or the player, or has World Wonders, multiply City Danger by 2.
- Otherwise, if it's any other player's Holy City or has National Wonders, add 1 to City Danger.
3. Calculate Enemy City Danger
- Loop through each of the enemy's cities that is currently endangered by the AI or their allies.
- Add that city's Danger to the enemy player's total Danger value.
- The "they are in serious danger" and "any of their cities are significantly endangered" flags are initially set to FALSE.
[Evaluation #1]
- City Danger starts at 1.
- Add 1 to City Danger if the city's tactical AI "land zone" is controlled by any of the player's enemies.
- Add 1 to City Danger if the city's tactical AI "water zone" is controlled by any of the player's enemies.
If the city is in danger of falling next turn, is "under siege" (took damage last turn / is surrounded by enemies), or is blockaded AND has taken at least 1/4 of its max HP in damage, proceed to Evaluation #2.
[Evaluation #2]
- If the city is in danger of being lost next turn, add 3 to City Danger. Otherwise, add 1 to City Danger.
- If the city meets one of these criteria:
a. Is in danger of being lost next turn
b. Is blockaded AND has taken at least 1/4 of its max HP in damage
c. Has taken at least 1/2 of its max HP in damage
...Then set "they are in serious danger" flag to TRUE.
["Any Of Their Cities Are Significantly Endangered"]
Set to TRUE here if City Danger is greater than 1.
[Importance Multiplier]
- If the city is the player's capital, multiply City Danger by 3.
- Otherwise, if it's an original major capital, the Holy City for the AI or the player, or has World Wonders, multiply City Danger by 2.
- Otherwise, if it's any other player's Holy City, add 1 to City Danger.
4. Player Is In Serious Danger and AI is Not
- If war duration is less than 40, refuse to make peace.
5. AI's War Score is <= -90 and AI's Danger > 0
- Agree to make peace.
6. AI's War Score is <= -50 and AI Is In Serious Danger
- Agree to make peace.
7. AI Is In Serious Danger And Player Is Not
- Agree to make peace.
8. Phony War
A war is phony if it meets all of these criteria:
- Approach towards this player is not WAR.
- Player hasn't captured any of the AI's cities before.
- War State is "Stalemate" or "Calm".
- War Score is less than 25 and greater than -25.
- AI doesn't "want to conquer" the player.
- AI isn't currently attacking the player with an "operation" of units.
- None of the AI's cities are in danger from the player.
- None of the player's cities are in danger from the AI.
- Player passes the proximity test.
The proximity test:
- If player is the AI's neighbor, they are too close.
- If player is CLOSE to the AI and military aggressive posture is "medium" or military strength is "powerful", they are too close.
- If player is FAR or DISTANT from the AI and military aggressive posture is "high" or military strength is "immense", they are too close.
If a war is phony and the player's danger from the AI *and its war allies* is 0, the AI will agree to make peace.
9. War Progress
Skip this check if "Any Of Their Cities Are Significantly Endangered" is TRUE, unless the war duration is at least 40.
War Progress starts at 100.
Decay per turn: -5 if player is stronger than AI militarily, -4 if Average, -3 if weaker.
Gains:
+10 each time AI captures a civilian (+20 for Settlers and Trade Units)
+10 each time AI pillages an improvement (+20 if it's high value)
+5 each time America AI steals a tile (+20 if it's high value)
+20 each time AI steals territory with a citadel (+40 if high value tiles are stolen)
+20 each time AI kills a combat unit or a Great General/Admiral
+100 each time AI captures a city (+200 for the capital, +150 for the Holy City)
Losses:
-5 each time AI loses a civilian (-10 for Settlers and Trade Units)
-5 each time AI's improvements are pillaged (-10 if it's high value)
-2 each time America steals a tile from the AI (-10 if it's high value)
-10 each time AI's territory is stolen with a citadel (-20 if high value tiles are stolen)
-10 each time AI loses a combat unit or a Great General/Admiral
-50 each time AI loses a city (-100 for the capital, -75 for the Holy City)
Adjustment:
- Subtract 1 for each point of War Weariness.
- CBP: If Happiness < 50%, subtract (50 - Happiness %) * 2.
- CP Only: Subtract 2 for each point of Unhappiness.
- Subtract (5 * total strategic resource deficit), up to -50.
If Adjusted War Progress is 0 or less and the check wasn't skipped, agree to make peace.
10. "Ready For Vassalage" Check
The AI is "ready for vassalage" if all of these criteria are met:
- Vassalage is possible
- War score is at least 75
- Player isn't in possession of the AI's original capital, Holy City, or any city the AI's team originally founded (ignoring cities > 12 tiles away from AI's cities)
- Player isn't in possession of any city that the AI is actively trying to liberate (ignoring cities > 12 tiles away from AI's cities)
- Player isn't close to winning the game
- Player isn't a backstabber
If all of these criteria are met:
- The AI is NOT ready for vassalage
- War State is "Nearly Won"
- Player's proximity is CLOSE or NEIGHBORS
- War duration is less than 30
- Not losing in war overall (with any player)
- Not very unhappy
...then the AI will refuse to make peace, because they're close to winning.
11. Should Peace Be Considered?
Any of these are reasons to consider peace:
- AI is "ready for vassalage"
- AI is in serious danger
- AI is war weary (War Weariness is >= 20% of AI's population)
- AI's approach isn't WAR or HOSTILE
- AI's War State is "Defensive"
- AI is losing in war overall
- AI is very unhappy
- War is phony, but player is in danger from the AI's war allies (not from the AI itself)
- War duration is at least 30
If none of these apply, AI will refuse to consider peace.
12. Peace Score
Peace score starts at 0.
If AI has a Tourism bonus for highest war score with this player, they will deliberately prolong the war (Prolong = TRUE).
12A. War Score
If war score is less than 0, subtract half of it from the peace score (War Score -20: Peace Score +10)
If war score is greater than 0, add 1/5 of it to the peace score (War Score 50: Peace Score +10)
- Don't do this if Prolong = TRUE
12B. War Duration
If Prolong = FALSE:
- Duration Penalty equals the War Duration - 10.
- If War Duration > 15, the Duration Penalty is applied.
If Prolong = TRUE:
- Duration Penalty equals the War Duration - 20.
- If War Duration > 30, the Duration Penalty is applied.
If the Duration Penalty is applied, it is done based on proximity to the AI:
- Proximity NEIGHBORS: Add the Duration Penalty to the peace score.
- Proximity CLOSE: Add 1.5x of the Duration Penalty to the peace score.
- Proximity FAR: Add 2x the Duration Penalty to the peace score.
- Proximity DISTANT: Add 3x the Duration Penalty to the peace score.
12C. War Weariness
- Add 1/4 of War Weariness to the peace score.
- If AI is very unhappy, or unhappy AND war weary (>= 20% of AI's population), add 1/2 of War Weariness to the peace score.
- Otherwise, if AI is unhappy OR war weary, add 1/3 of War Weariness to the peace score.
12D. City Danger
Danger multiplier for the player and the AI start at 1.
If the AI isn't losing in war overall or its war state is "Nearly Won":
- If player is an easy target, add 1 to player's danger multiplier.
- If one of the player's cities is vulnerable to the AI, add 1 to player's danger multiplier.
- If War State is "Nearly Won", add 1 to player's danger multiplier.
If the player isn't losing overall in war:
- If AI is an easy target, add 1 to AI's danger multiplier.
- If one of the AI's cities is vulnerable to the player, add 1 to AI's danger multiplier.
Player Is In Danger, AI Is Not
- If war duration is less than 20 OR player's danger multiplier is at least 3 OR they are in serious danger, subtract (5 * their city danger * their danger multiplier) from the peace score.
- Otherwise, subtract (2 * their city danger * their danger multiplier) from the peace score.
AI Is In Danger, Player Is Not
- If war score is less than -15 OR AI's danger multiplier is 3 OR AI is in serious danger, add (5 * AI's city danger * AI's danger multiplier) to the peace score.
- Otherwise, add (2 * AI's city danger * AI's danger multiplier) to the peace score.
Both Players Are In Danger
- Subtract (2 * their city danger * their danger multiplier) from the peace score.
- Add (2 * AI's city danger * AI's danger multiplier) to the peace score.
12E. Overall War State
What is the AI's overall war state against this player?
"Nearly Won"
- Subtract 0 from the peace score if ready for vassalage, or (10 * player's danger multiplier) if not.
"Offensive"
- Subtract (5 * player's danger multiplier) from the peace score.
"Calm"
- If AI is losing in war overall, add (5 * AI's danger multiplier) to peace score.
- Otherwise, subtract (2 * player's danger multiplier) from the peace score.
"Stalemate"
- If AI is losing in war overall, add (5 * AI's danger multiplier) to peace score.
- Otherwise, add (2 * AI's danger multiplier) to peace score.
"Defensive"
- If AI is losing in war overall, add (10 * AI's danger multiplier) to peace score.
- Otherwise, add (5 * AI's danger multiplier) to peace score.
12F. Special Considerations
- If in an ongoing coop war against this player, subtract 10 from peace score.
- If not ready for vassalage and AI wants to conquer this player, subtract 10 from peace score.
- If the player captured the AI's original capital or Holy City, subtract 15 from peace score.
- If the player is close to winning the game, subtract 20 from peace score.
12G. Peace Score Modifiers
[Losing In War Overall or Very Unhappy]
- If the player hasn't captured any city from the AI, the AI is ready for vassalage, or War State is "Nearly Won", double the peace score.
- If no city was captured AND one of the other two conditions are met, double the peace score again.
[Not Losing In War Overall Or Very Unhappy]
- Check if war score is either above 0, or above -15 with the player's target value being AVERAGE or better and the war state being STALEMATE or better. If neither are true, skip these next modifiers.
If player captured a city from the AI:
- If war score is greater than half the war duration, halve the peace score.
- Otherwise, reduce the peace score by 25%.
If player did not capture a city AND the AI is going for world conquest AND the player has lost their capital (or the AI is ready for vassalage):
- If player's economic strength compared to the AI is WEAK or PATHETIC, or target value is BAD or IMPOSSIBLE, double the peace score.
If neither of the above are true, but the player has captured a city the AI is trying to liberate:
- If AI is diplomatic AND AI's war score is greater than the war duration, halve the peace score.
- If only one of these is true, reduce the peace score by 25%.
[Leader Flavors]
If war score is > 0, multiply the peace score by (100 + ((Diplo Balance - 5) * 10)) and divide it by 100.
If war score is < 0, multiply the peace score by (100 + (((Meanness * -1) + 5) * 10)) and divide it by 100.
12H. Final Decision
AI counts the number of "dangerous" major civs they're at war with and subtracts 1 (minimum 0).
Peace Threshold = 20 - (2 * this number), minimum 1.
If peace score >= peace threshold, then agree to make peace.
Otherwise, don't agree to make peace.
Last edited: