Huge thanks to Arathorn and his Combat Explained article.This article is basically an updated, less math-intensive version of that.
This document doesn’t have much information about first strikes, experience gained, or collateral damage yet. I’m going to try and get that info in from other posters. I doubt I’ll actively maintain this document for more than a week. I’m also going to try and avoid acronyms to increase readability. Also it’s late and I’m making errors up the kazoo.
By the way, there are parts of this thread that you can use to your advantage. Others will merely reduce your frustration when the game does unrealistic things.
Before I start using numbers, let’s go over the algorithm the game uses (without collateral damage):
- The attacker’s modified strength is calculated.
- The defender’s modified strength is calculated.
- The attacker’s firepower is calculated.
- The defender’s firepower is calculated.
- The attacker’s damage when he hits is calculated, in HPs. (I’ll call this attacker damage.)
- The defender’s damage when he hits is calculated, in HPs. (I’ll call this defender damage.)
- The attacker’s percent chance to win a ROUND is calculated.
- The defender’s percent chance to win a ROUND is calculated.
- Combat Rounds Begin
- First strike rounds occur (I’m skipping this for now.)
- Combat Loop Begins
- A random number is generated to determine who wins each round
- If the attacker wins the round, he does his attacker damage to the defender (in HPs).
- If the defender wins the round, he does his defender damage to the attacker (in HPs).
- Combat Loop Repeats until someone’s HPs reach 0.
- If we ignore retreat, the unit with 0 HPs dies.
HUGE NOTE: Notice that all the math and probabilities are COMPLETELY DETERMINED before combat even begins. The only thing that is different each round of combat is the random number generated to determine who won that round. This is unrealistic and somewhat unintuitive, although I like it for balance reasons. It’s the equivalent of like, two 5,000 men armies running at each other, Army A kills 4,999 men of Army B, yet that one guy in Army B still fights with the entire strength of the original 5,000 man army. We’ll call it the ‘Rambo Factor.’
Ok, what does this mean?
Well, for one thing all rounds of combat are equally important, as opposed to the first round being way more important than all following rounds. Since the way things happen in real-life would be that one side would get a small advantage at the beginning. That advantage would quickly widen as their injured opponent would suffer a decreased strength. So let’s take the frustrating example of when the graphics display the 3 archer cartoons (in your 1 unit) killing two of their archer cartoons (in their 1 unit) in the first round of combat. Then that lone archer cartoon of theirs kills all three of your archers one at a time. In real-life that would be very unlikely…but the way Civ 4 calculates things, it’s not quite as surprising. That lone archer is still fighting with the strength of all 3…but he is closer to death than you are.
Ok, time to bust out the numbers. BTW almost all of these numbers can be checked by selecting a unit and then right-clicking, holding, and then mousing over the enemy unit. Also, the chat/event/COMBAT log is a wonderful thing…press ctrl-tab to bring it up with the default key settings, then click on the ‘combat’ tab. And don’t press alt+tab. 🙂
Oh…ALWAYS round down to 2 decimal places. (e.g. 47.959 => 47.95, not 47.96)
Without further adieu:
Attacker’s Modified Strength:
Very simple. The base strength of the unit multiplied by their +% from COMBAT upgrades only. (The star ones–Combat I, Combat II, Combat III…etc.) Multiply that by the unit’s current hp and divide by 100.
Example 1: I have a swordsman (base strength 6) with city raider 1 (+20% to cities):
6*1.0*100/100 = 6
Example 2: I have a swordsman (base strength 6) with combat 1 (+10% strength):
6*(1 + .1) * 100/100 = 6.6
Example 3: I have an injured swordsman (base strength 6, but 56/100 hp) with every single possible upgrade in the game, including Combat V.
6*(1 + .5) * 56/100 = 5.04
Wondering what happened to that +% you got for raiding cities, attacking archery units, gunpowder units, whatever? Read on…
Defender’s Modified Strength:
This is more complicated and counter-intuitive. You see, the attacker’s +% aren’t actually added to the attacker, they’re kind of deleted from the defender. Kind of.
- Add up the defender’s +% bonuses THAT APPLY against the attacker from all sources…city defense bonuses, innate unit abilities, terrain defense bonuses, fortify bonuses, river defense, Combat I through V, City Garrison, Guerilla, Cover, Pinch, Shock, whatever.
- Add up the attacker’s +% bonuses from upgrades and innate abilities (and anything I forgot) EXCEPT the Combat upgrades.
- If the defender’s +% bonuses are greater than the attacker’s, multiply the defender’s base strength by 1 + the decimal amount that the defender’s bonuses are in excess of the attacker’s bonuses. Multiply the product by the unit’s current HPs divided by 100 for the defender’s modified strength.
- If the attacker’s +% bonuses are greater than the defender’s, things get ugly. You need to divide the unit’s base strength by 1 + the decimal amount that the attacker’s bonuses are in excess of the defender’s bonuses. Multiply the quotient by the defender’s current HPs and divide by 100 for the defender’s modified strength.
Example 1: I have a musketman (base strength 9) with no defense modifiers being attacked by a modern armor with no attack modifiers.
9 * (1 + 0) * 100/100 = 9
Example 2: I have a musketman (base strength 9) being attacked by a modern armor with Combat V (+50% for him) from across a river (+25%). My musketman has the Combat I upgrade (+10%), and the City Garrison I upgrade (+20%) but is not in a city. He is in a forest (+25%) with the Woodsman II upgrade (+50%).
My musketman’s gross applicable upgrades are .25 + .1 + 0 + .25 + .5 = 1.1
The modern armor’s gross applicable upgrades are 0. (As stated, Combat upgrades do NOT count for defender modified strength.)
My musketman’s net applicable upgrades are therefore 1.1.
My musketman’s modified strength is 9 * (1 + 1.1) * 100/100 = 18.9
Example 3: Same as above, but this time the the modern armor has the Pinch upgrade, +25% to gunpowder units. Also, my musketman has 63 HPs.
My musketman’s gross applicable upgrades remain unchanged at 1.1.
The modern armor’s gross applicable upgrades changes to .25.
My musketman’s net applicable upgrades are 1.1-.25 = .85
My musketman’s modified strength is 9 * (1 + .85) * 63 /100 = 10.4895 => 10.48
Example 4: A swordsman with City Raider I, II, and III (total +75%) is attacking my archer (base strength 3) with City Garrison I and II (total +45%). I have no city defense nor a fortify bonus.
My archer’s gross applicable upgrades are .45.
The swordsman’s gross applicable upgrades are .75
The attacker’s bonuses are in excess of mine by .30.
My archer’s modified strength is 3 / (1 + .3) * 100/100 = 2.307692…=>2.30
Example 4 makes sense because the Swordsman has us beat on +% modifiers, this is represented by the archer’s modified strength of 2.30 being less than his base strength of 3.
Also note that this method of removing the attacker’s bonuses from the defender is what causes what Arathorn calls the ‘Bonus Peculiarity’. I might add the math later, but the conclusion is that if the defender has a greater +% than the attacker, the attacker actually gets less than the ‘advertised’ amount of bonus from his upgrade. (Although the combat odds that the game shows you are still correct.) If the attacker has a greater +% than the defender, the attacker gets more than the ‘advertised’ amount of bonus from his upgrades. Why the designers did it this way I don’t know, but I have a hunch it helps keep things more even, especially on uneven matches. I think raw strength would matter more if they did it the ‘advertised’ way and upgrades would actually be less useful.
Attacker Firepower:
This is the big change for 1.61. This concept didn’t exist, and the modified strength was just used in its place instead. This is easy to calculate:
It is the average of the attacker’s modified strength, and the attacker’s modified strength with 100 HPs.
(I believe you count Combat upgrades in this but I don’t believe I truly tested it.)
Example 1:
My pikeman (base strength 6) has Combat I (+10%) and 43 HP.
Modified strength = 6*(1+.1) *43/100= 2.838 => 2.83
Modified strength with 100 HPs is 6*(1+.1)*100/100 = 6.6
The attacker’s firepower is (2.83 + 6.6)/2 = 4.715=> 4.71
Defender Firepower:
The description is exactly the same, although the modified strength is of course calculated differently.
Example 1:
My knight (base strength 10) with Combat 2 (+20%) and 58/100 HPs is being attacked from across a river (+25%) by an injured pikeman with Combat I and an innate +100% vs. mounted units.
Remember the pikeman’s Combat I bonus does not count to defender’s modified strength. Therefore:
Modified strength = 10 / (1 + (1 – .2 – .25)) * 58 /100 = 3.7419 => 3.74
Modified strength with 100 HPs is (10 / (1 + (1 – .2 -.25)) * 100 / 100 = 6.4516 => 6.45
The defender’s firepower is (3.74 + 6.45) / 2 => 5.09
Attacker’s Damage When He Hits (in HPs):
If the attacker’s firepower is AFP and the defender’s firepower is DFP, the equation is:
20 * ( (3 * AFP) + DFP) / ( (3 * DFP) + AFP)
Example 1:
Attacker’s firepower is 6.6, Defender’s firepower is 19.38.
Attacker’s damage when he hits, in HPs, is
20 * ( (3 * 6.6) + 19.38) / ( (3 * 19.38) + 6.6) = 12 HPs for each round of combat won
Defender’s Damage When He Hits:
The equation for this, using AFP as attacker firepower and DFP as defender firepower is:
20 * ( ( 3 * DFP) + AFP) / ( (3 * AFP) + DFP)
Example 1:
Attacker’s firepower is 6.6, Defender’s firepower is 19.38.
Defender’s damage when he hits, in HPs, is
20 * ( ( 3 * 19.38) + 6.6) / ( (3 * 6.6) + 19.38) = 33 HPs for each round of combat won
Ok, the math is mostly over. Note that the ‘jump points’ Arathorn discusses come from the fact that your % chance to win the overall combat changes significantly if you can reduce the number of hits it takes to deal lethal damage to your opponent. Assuming uninjured combatants, 17 damage a hit requires 6 hits to kill, whereas 16 damage a hit requires 7 hits to kill. If you can squeeze out that teeny edge on your opponent to increase your damage per hit to 17 from 16, it makes a sizable difference in your overall % chance to win. Same thing for increasing from 14 damage a hit (you’d need to win 8 rounds) to 15 damage a hit (where you’d need to win 7 rounds).
The last bit of math. Note that this is borrowed totally from Arathorn and I have no easy way to test it. I use his naming convention that attacker’s modified strength is A, and the defender’s modified strength is D. Note that attacker’s % chance to win a round + defender’s % chance to win a round will always equal 100%, as it should. (i.e. There is always exactly 1 unit dealing damage each round.) I believe this is the only calculation you can’t get out of the combat log directly. I do not know exactly how the rounding is done in this case, or how many decimals the computer keeps track of.
Attacker’s % Chance To Win A Round:
The equation is: A / (A + D)
Example 1:
My swordsman’s modified strength (A) is 6.6.
The defender’s catapult’s modified strength (D) is 2.65
My chance to win any round of combat is:
6.6 / (6.6 + 2.65) = 71.35135% ~ 71%
Defender’s Chance to Win A Round:
The equation is: D / (A + D)
Example 1:
My defending catapult’s modified strength is 2.65.
The attacking swordsman’s modified strength is 6.6.
My chance to win any round of combat is:
2.65 / (6.6 + 2.65) = 28.648% ~ 29%
I’m so tired, but that’s really all there is to it. Go back to the top and read the algorithm again now that you know how the numbers are calculated, start posting with the grammatical errors I made and start sending screenshots of the mathematical things I missed!
Also, many of the examples I made up (making them more prone to errors) but I did test over a half dozen complicated combats in game, and was accurately predicting the damage per hit and everything. I can maybe provide the numbers on request, possibly the saved game file. One thing that wouldn’t hurt to test more is heavily upgraded and injured attackers attacking injured defenders with fewer +% modifiers than the attackers.
Very last thing: The chance to win the entire combat is something apparently involving negative binomial distributions or some other probability nonsense that’s over my head. But now that you understand how combat works, you can figure out the number of rounds both sides would need to win in order to deal lethal damage, so even if you can’t calculate it without some stats classes, you’ll at least know what is going into that calculation.