Combat Explained

Ahh..fighting. Love it or hate it, there will be times it’s part of your Civ-ing career. This article attempts to explain a bit about how combat is figured, discusses some “jump points” where your odds of success change dramatically with a very small change in strength, discuss some odd ways that particular bonuses are calculated, and hopefully generally serve to enlighten you in terms of combat.
Thanks for this article in part to BomberEscort and snepp for their work in another thread [url]http://forums.civfanatics.com/showthread.php?t=137350[/url]. Some credit also due to [url]http://apolyton.net/forums/showthread.php?s=&threadid=140622[/url] for descriptions (even though some are terribly wrong).

[size=”5″]The basics[/size]

You don’t even really need to understand this. You can get this by alt-mouseover or by right-click and dragging to the unit and checking the odds displayed in the lower left corner of the screen. This explains how those numbers are calculated.

[size=”4″]Attacker’s modified strength[/size]

This is calculated first. Apply any bonuses the attacker gets independent of the defender (generic strength promotions only in the default game). Multiply this total by the unit’s hps/100. This gives the attacker’s modified strength.

Example: A swordsman with Combat I, City Raider I, and only 73 hps is lining up to attack a city. His modified strength is 6 * 1.1 (from Combat I) * 73/100 (from hps) = 4.82 (well, 4.818 actually, but I don’t know if Civ4 keeps more than 2 digits of accuracy).

[size=”4″]Defender’s modified strength[/size]

This one is more complicated. Determine the defender’s bonuses from terrain, general strength bonuses, bonuses vs. the type of the attacking unit, fortification bonuses, etc. Sum those up. Now, subtract any bonuses the attacker might have if it attacks this unit. Those would include attacker bonuses against defender combat type, attacker bonuses against a city, attacker bonuses in the terrain type (?). If the overall value is positive, add that percentage to the defender to get its modified strength. If the overall value is negative, the defender’s modified strength is found by taking the original defender’s strength divided by (1-overall_value). [Note: That’s the same as dividing by (1+abs(overall_value)) when overall_value is negative, which is how I think of it.]

Once this value is calculated, the defender’s hps become an issue. This is again a straight multiplication by the number of hps remaining times the modified strength found above.

Example #1: (Both healthy) An archer (str:3) with City Raider I and Combat I promotions is attacking a warrior (str:2) on grassland. The attacker’s modified strength is calculated by simply taking the combat I promotion and getting a value of 3.3 (3 + 3*.1). The defender has no strength bonuses and the grassland defense bonus is 0, so the defender has a modified strength of 2.

Example #2: (Both healthy) A knight (str:10) with Combat I and Cover (+25% vs. archers) promotions is attacking a longbow (str:6) in a forest. The attacker’s modified strength is again simple, using the Combat I promotion of 10%. The knight’s attack value is 11 (10 + .1*10). The longbow has an initial bonus of +50% for the forest. However, the knight’s Cover bonus now affects the defending longbow, giving it a -25%, too. So, the overall bonus for the longbow is +25%. The defender’s modified strength is 7.5 (6 + .25*6).

Example #3: A knight (str:10) with Combat I, Combat II, and City Raider I (+20% attacking a city) but only 73 hps is attacking an axeman (str:5) in a town with a 3% defensive bonus from culture. The attacker’s modified strength is 8.76 (10 + .2*10)*76/100 from the two Combat promotions and the hps. The defender first calculates a +3% defensive strength from the city. Then the attacker’s bonus is kicked in. This gives a -20% to the defender. Thus, the overall value is -17%. The defender’s modified strength is 4.27 (5 / (1+.17) = 5 / 1.17)).

[size=”5″]The actual combat[/size]

We now have the attacker and the defender’s modified strengths. We will call these A and D going forward to help the discussion. If a bit of algebra scares you, just jump ahead to repercussions….

[size=”4″]Round odds[/size]

The odds that the attacker will win each round is given by A/(A+D), so the odds the defender wins a round is D/(A+D).

I’m now going to introduce a new variable – the ratio between the attacker’s and defender’s modified strength. This value is R. It is A/D and it controls all of combat. The greater R is, the better the attacker’s odds of winning.

Each round, the attacker wins with odds R/(1+R) and the defender with odds 1/(R+1).

[size=”4″]Damage per hit[/size]

The attacker and defender both start with their current number of hps (NOT 100 as was previously stated). The attacker’s damage is given by floor(20*(3*A+D)/(3*D+A)). That is, you calculate the value and drop any fractional remainder. The defender’s damage is given by floor(20*(3*D+A)/(3*A+D)).

Going back to R notation, the attacker does floor(20*(3*R+1)/(3+R)) damage and the defender does floor(20*(3+R)/(3*R+1)) damage.

The maximum damage one size can do is 60 per hit. The minimum that can be done is 6. Only those values are possible, regardless of the relative strengths of the units.

Once one side goes below 0 hps remaining, it is destroyed (or retreats). The winner has strength remaining equal to starting_strength*hps/100, but it has fewer hps, so it is more likely to die in further combat. Modified strength no longer matters.

Exact odds can be found at [url]http://c4combat.narod.ru/c4c.htm[/url] [Note: [b]Updated[/b] to include hps — thanks, Ellestar.]

[size=”4″]First Strike[/size]

First strike round(s) are special. The number of them is determined by looking at the number of first strike rounds of the attacker and the defender. Whichever number is greater gets the difference of values in first strike opportunities. For x-y first strikes (possible first strikes), the math is still unproven, but it looks like a 50% likelihood of getting a first strike each “round” possible.

A first strike round is like any other round, except that the first striker is the only one who can do damage. For example, if the attacker has two first strikes and the defender zero, the first two rounds have two possibilities – the attacker wins so the defender loses damage or the defender “wins” and nobody gets hurt. The odds in this round are just like any other. The first striker is just immune to damage.

[size=”4″]Retreat[/size]

Retreat rolls happen when a round ends that would kill the attacker. In that case, a special role is made against the attacker’s retreat chance. If successful, the attacker retreats with the number of hps he had before that final, potentially killing round. The attacker’s chance of winning combat is never decreased by having retreat chances. They only come into play when the attacker would die.

Retreat has a few points. First, any attacker with an X% chance of retreating will always have a strictly greater than X% chance of surviving a combat. He could win (greater than 0), retreat (x*die_percent), or die. The second is that retreat can only occur for the attacker, not the defender. Third, retreat is most valuable when the attacker is less strong than the defender – a catapult attacking a city, for example.

Example: A catapult (str:5) is attacking an archer(str:3) fortified in a city. The archer has +50% defense bonus for the city and 25% fortification bonus. The catapult has a 20% retreat chance (one Promotion). Attacker’s modified strength is 5. Defender’s modified strength is 5.25. Without retreat, the catapult would win 34.7% of the time and die the other 65.3% of the time. With retreat, the odds of winning are still 34.7%, but 20% of that 65.3% is retreat (.2*.653). So, win 34.7%, retreat 13.1%, and die 52.2% (.8*.653) of the time.

[size=”5″]Collateral Damage[/size]

When attacking stacks, siege units have the built-in capability to damage additional units in the stack besides the one attacked. This is called collateral damage.

Collateral damage is done ONLY by an attacker and only to the stack member(s) that aren’t directly defending. The chosen defender will engage the attacking unit in a regular combat.

[size=”4″]Maximum Damage[/size]

Gone are the Civ3 days of completely red-lining a unit. Each unit that can do collateral damage has a limit on the amount of damage it can do. These are given in the Units XML file. For catapults, it is 50; cannons 60; artillery 70. Tanks/panzers and modern armor are capped at 60; Cho-Ko-Nu at 60, and (stealth) bombers at 50. That means a catapult can not damage a unit at or below 50 hps. Similarly, an artillery cannot damage any unit at or below 30 hps. Those are hard caps.

[size=”4″]Number of Targets[/size]

The number of targets is a function of both the attacking unit and the number of potential targets. The number of potential targets is the number of units in the tile which are not defending and who are above the maximum damage threshold.

Example: A catapult is attacking a stack a stack with a 100 hp musket, a 95 hp musket, a 42 hp knight, and a 73 hp axe. The number of potential targets is 2 – the 95 hp musket and the 73 hp axe. The 100 hp musket will defend, so is not a collateral target. The 42 hp knight is below the maximum damage for a catapult.

Each type of unit capable of doing collateral damage is limited in the number of targets it can hit, too. A catapult can only hit 5, a cannon 6, an artillery 7, Cho-Ko-Nu 5, a tank/panzer 5, a modern armor 6, a bomber 5, and a stealth bomber 6. So, even targeting a stack of 12 muskets, a cannon will only hit 7 total (1 directly which defends and 6 with collateral damage).

The number of targets, then, is the lesser of the two numbers – min(potential_targets,max_capable).

[size=”4″]Selecting targets[/size]

The target of each “round” of collateral damage is selected randomly from the list of potential targets, as defined above. I don’t think the list is updated each round (so that a unit at the maximum damage mark could be selected), but I’m not certain.

[size=”4″]Amount of Damage Done[/size]

The damage calculation is similar to the damage calculation for regular combat. However, the modifications to each unit’s strength are done differently.

The only potential attacker strength bonus is Barrage — +20% for Barrage I, another 30% for Barrage II and another 50% for Barrage III. This affects the starting percentage of strength of each unit. The defender gets no strength bonus for anything. Hps are also not used in calculating these relative strengths.

All the regular artillery units (catapults, cannons, artillery, and (stealth) bombers) calculate based off of their full strength. The tanks (tank, panzer, modern armor) calculate based from 0 and the Cho-Ko-Nu starts at 50%.

Example: A Cho-Ko-Nu (str:6) will always have an adjusted strength of 3 (.5 * 6) when figuring collateral damage.

Example: A tank with Barrage I will have an adjusted strength of 5.6 (28 * .2) for collateral damage. With Barrage II, it would be 14 (28 * .5).

Then, the likely damage is half what it would be if the units were fighting directly with those relative strengths. That is, damage = floor(10*(3*A+D)/(3*D+A)). This amount is reduced only if the damage would put the defender past the damage threshold discussed above.

Example: A catapult (with Barrage I and Barrage II) is targeting a longbow with 71 hps in a city on a hill for collateral damage. The catapult’s adjusted strength is 7.5 (5 * 1.5) and the longbow’s adjusted strength is 6 – the hill defense, the city defense, the hps just don’t matter. The catapult does 11 damage to the longbow.

[size=”4″]Putting It All Together[/size]

Then, the siege attack weapon simply loops through the selection and damage phase the number of times equal to the number of targets. Not every potential target gets hit and some may get hit more than once.

Example: A catapult (with Barrage I) attacks a stack with two full-strength muskets, a knight (with Combat I) at 54 hps, a sword at 38 hps, and an elephant at 83 hps. The number of targets is 3. The first random target is the elephant. Adjusted strengths of 6 and 8 means 8 damage to the elephant. Round 2, the knight is picked. Adjusted strengths of 6 and 10 mean 7 damage, but the limit is 4 because of maximum damage. Round 3, the elephant is selected again, and takes another 8 damage. Before combat between the catapult and the first full-strength musket begins, the stack now has two full-strength muskets, a knight with 50 hps, a sword with 38 hps, and an elephant with 67 hps. Then, the attack between the catapult and the musket would resolve as normally (described above).

[size=”5″]Experience Points[/size]

The winner of combat gains experience points. Like most of combat, experience points are determined by the ratio of strengths. The value is floor(iXPValue*opponent_strength/your_strength), where iXPValue comes from the XML file. For all standard units, iXPValue is 4 for an attacking unit and 2 for a defending unit. The minimum number of experience points for a successful fight is 1, however. The strengths are the displayed modified strengths (from bonuses and hps).

Exceptions: A unit which attacks and retreats gains a single experience point in all cases. The defending unit receives no experience points in this case.

Example: A sword (str:6) attacks a spearman (str:4) on flatlands. If the sword won, he would receive 2 (floor(4*4/6)) xps. The spear would gain 3 (floor(2*6/4)) xps if it won.

Example: A modern armor (str:40) attacks a spear (str:4). If the modern armor wins (odds: 99.999999+%), it gains 1 xp, not 0 (floor(4*4/40)). If the spear wins (odds: 6e^-13), it would gain 20 xp (floor(2*40/4)).

[size=”5″]Repercussions[/size]

Now I’ll discuss a bit of strategy. It helps to have understood, at least partially, the way combat works before reading this section, but it’s not absolutely necessary.

[size=”4″]Jump Points[/size]

Because of the nature of the hp damage dealt and the way it divides the attacker and defender’s hps, there are a few natural jump points, where a very small change in R can make a huge difference in relative odds of winning – these are points you should aim to be on the right side of, whether you’re attacking strong and want high odds or are attacking weak and need a best chance.

[size=”3″]Full 100 hp situation[/size]

For ease in explaining, I’m going to describe the case when both the attacker and defender have 100 hps. Then I’ll discuss a bit of how it changes when either or both are injured.

The first is when the defender’s damage drops from 15 to 14. This happens when the attacker is at least 1.8 times as strong as the defender. It means the defender needs 7 hits to kill the attacker instead of 6. Above 1.8 R, the attacker wins 99+% of the time. That’s not to say upsets won’t happen (1% is actually pretty likely), but it does mean the odds are very good.

The second jump point is when attacker’s damage is 25. That means, the attacker needs only 4 rounds to destroy the defender. Doing a little math show that happens when R=11/7. If you are 1.57142857… times as strong as the defender, you win over 95% of the time. Shrink that just a little to only 1.57 times as strong and the odds of success drops all the way to 90%.

The third jump point occurs when the defender’s damage drops from 17 to 16. This is the difference between 6 hits to kill and 7 hits to kill. It happens when R = 43/31, which is approximately 1.387. Above that ratio, the attacker wins over 87.5% of the time. At 1.387 and below, the attacker wins less than 80% of the time. That’s a jump from 5/6 to 4/5. It’s significant. If you can achieve that 1.388 mark, it’s worth doing.

The final jump point is around an even battle. Even a tiny bit of strength makes a HUGE difference. Any stronger unit, by even .01, will have at worst a 62.3% chance of winning the combat. That’s because the stronger unit does 20 damage and the weaker only 19. 5 rounds to kill vs. 6 rounds to kill. That’s all there is to it. Going from a tiny bit stronger to a tiny bit weaker drops your chance of winning from 62.3% to 37.7%. A 40% chance of winning is impossible for fully-healed units(without first strikes).

[CODE][b]Ratio value Odds of winning[/b]
>1.8 99%+
1.58-1.79 95%-98%
1.39-1.57 87%-90%
1.25-1.38 75%-80%
1.01-1.25 62%-75%
1.0 50%
0.80-0.99 25%-38%
0.73-0.79 20%-25%
0.64-0.72 10%-13%
0.56-0.63 2%-5%
<0.56 <1%[/CODE] Obviously, it is to your benefit to just beat one of the jump points up if you can (so get 1.58:1 odds) and to avoid being on the bad end of a jump point. Attacking at 0.73:1 is a LOT better than at 0.72:1 (e.g., 4.4 vs. 6 is a LOT better than 4.3 vs. 6). Probably worth scrolling attackers to get good odds. Note: the 75% spot is NOT a jump point. I just included it for perspective's sake. [size="3"]Wounded Attacker/Defender[/size] If one of the units is wounded, then the jump points situation will change. There will still be jump points, however. Those points will occur at the points when one side’s damage crosses a jump point. The jump points can be found by looking at ceiling(remaining_hps/n) where n is any number (but, in reality, only n up to 8 are very likely to be an issue). The attacker looks at the defender’s remaining hps and the defender looks at the attacker’s remaining hps. Example: A 64 hp unit is attacking a 91 hp unit. Without consideration of strengths, we know that the jump points will occur when the attacker’s damage is 91, 46, 31, 23, 19, 16, 13, 12. Well, damage = 91 is impossible and damage = 46 is very unlikely, so there are jump points at 6 locations based off the defender’s hps. (More explicitly, ceiling (91/1) = 91, ceiling (91/2) = 46, ceiling (91/3) = 31, ..., ceiling (91/8) = 12.) There will be jump points for the defender, too. Those jump points occur at fractions of 64 – so 64, 32, 22, 16, 13, 11, 10, and 8. 64 is impossible and 8 is very unlikely. That leaves 32, 22, 16, 13, 11, and 10. So, the critical R values (from the attacker perspective) are 2.52, 1.32, 0.90, 0.64, 0.40, 0.32, 0.37, 0.83, 1.57, 2.47, 3.77, and 5.00. Those come from the attacker’s damage needed and the defender’s damage needed respectively (so that 0.90 corresponds to 19 attacker damage and 1.57 to 16 defender damage). The R values needed to do a certain amount of damage (or to prevent it being done to you) are summarized in this table (all figures rounded to the nearest hundredth). Min ratio to do x damage: [code][b] R 1/R damage[/b] 1/5 (0.20) 5/1 (5.00) 10 13/49 (0.27) 49/13 (3.77) 11 1/3 (0.33) 3/1 (3.00) 12 19/47 (0.40) 47/19 (2.47) 13 11/23 (0.48) 23/11 (2.09) 14 5/9 (0.55) 9/5 (1.8) 15 7/11 (0.64) 11/7 (1.57) 16 31/43 (0.72) 43/31 (1.39) 17 17/21 (0.81) 21/17 (1.24) 18 37/41 (0.90) 41/37 (1.11) 19 1/1 (1.00) 1/1 (1.00) 20 43/39 (1.10) 39/43 (0.91) 21 23/19 (1.21) 23/19 (0.83) 22 49/37 (1.32) 37/49 (0.76) 23 13/9 (1.44) 9/13 (0.69) 24 11/7 (1.57) 7/11 (0.64) 25 29/17 (1.71) 17/29 (0.59) 26 61/33 (1.85) 33/61 (0.54) 27 2/1 (2.00) 1/2 (0.50) 28 67/31 (2.16) 31/67 (0.46) 29 7/3 (2.33) 3/7 (0.43) 30 73/29 (2.52) 29/73 (0.40) 31 19/7 (2.71) 7/19 (0.37) 32 79/27 (2.93) 27/79 (0.34) 33 43/13 (3.15) 13/43 (0.32) 34[/code] So, for all R between 1.10 and 1.21, 21 damage is done by the attacker. Example: A 64 hp axeman attacks a 91 hp spear, with no bonuses or terrain modifications. The axeman’s adjusted strength is 5 * 1.5 * 64/100 = 4.80, and the spear’s adjusted strength is 4 * 91/100 = 3.64. R = 1.32 (just below). The spear wins 48% of the time and the axe just 52%, despite a rather significant advantage in R. Example: Same as before, but now the axeman has 65 hps, instead of 64. Axeman’s adjusted strength is 4.87, so R = 1.34. The spear now only wins 34.4% of the time and the axe 65.6%. [size="3"]How to Handle Jump Points[/size] One problem with this is that hps are not displayed. I’ve not found any way to determine a unit’s hps other than to keep track of them from the Combat log window. Of course, for units strength 10 and higher, you can look at their remaining strength and determine exact hps. Either way is quite tedious. Another problem is that the above table is rather long and complicated. I can generate it easily enough but there’s no way I can memorize it. The table for healthy units is easier – 7/5 is a good estimate for 1.39 and I can calculate that in my head. But figuring the jump points for injured units and then thinking 1.85? Hard to do. The problem is that it matters. It matters in the order in which you attack. It matters in what your goals are. It matters in all kinds of things that insanely motivated Civers (like that guy I see in the mirror) care about. Example: Two axemen, one with 64 hps and one with 55 hps absolutely, positively have to kill two spearmen (with 91 and 89) hps this turn. They’re on the only metal in my empire, for example. I have two choices. Attack with the stronger first and then the weaker? Or the semi-counterintuitive and attack with the weaker first? Well, attacker stronger then weaker gives me a 23.2% chance of killing both, whereas attacking weaker then stronger gives a 28.5% chance of killing both. Example: Same as above, but my stronger axeman has 65 hps. Weaker then stronger is now a bit better, 28.8%. BUT, stronger then weaker is an even better 29.2%. Because of the jump points. And, depending on how the computer rounds things ending in .x5, I might not be able to tell the difference between a 64 hp axeman and a 65 hp axeman by looking – one is strength 3.20 and one is strength 3.25 (which may well round to 3.2). Keeping track of hps, which aren’t even displayed, could make significant differences in outcomes. What tedious micromanagement – it’s creeping back in again. [size="4"]Bonus Peculiarities[/size] Because of the way situation-dependent bonuses are applied to the defender instead of the attacker, some care needs to be taken in their use. The difference between a 25% bonus to yourself and a 25% penalty to the foe can be quite significant. Example: Consider a unit with 3.7 strength (injured sword or whatever) with a 25% Cover promotion (or just any 25% bonus against archer units) attacking an archer in the woods. I'd expect from reading the +25% strength promotion to have 3.7*1.25=4.6 strength attacking 4.5 (3*1.5), so I would hope to have the odds in my favor (almost 64% of the time). BUT because of the bonus peculiarity, it'd be my 3.7 against their 3.8 (3*1.25). So, in actuality, the odds would be against me (36% chance of success)!] Now, the correct numbers are displayed, but a clever player wants to know which units to use when. Reaching a jump point is nice, but the bonus peculiarity can be used (dis)advantageously as well. If the defending unit has no bonuses (from terrain or fortification or against the attacker), then the R value is unchanged. So, there’s no real area of gain to play against. It’s only when the defender has some defensive strength that the peculiarity makes a noticeable difference. If the expected attacker bonus that is eventually subtracted from the defender’s bonus is greater than the defender’s bonus, the peculiarity helps the attacker (i.e., when overall value for the defender bonus is negative). That is, both the attacker and the defender have bonuses, but the attacker’s bonus is larger than the defender’s. So, a lot of bonuses will be more valuable than expected if they overcome defender’s bonus. If you’re attacking fortified units in cities, for example, that don’t have a city defense bonus, the specific promotion for that scenario will be worth a little more than its listed percentage value. Example: A sword (str:6) with City Raider I, II, and III is attacking a pike (str:6) defending a city. The city has a 30% defensive bonus. The attacker’s strength is just 6, but the defender’s strength is 6/(1+1.1-.3) = 3.33, for an attack ratio of 1.80. The “right” way of doing things would have a strength 12.6 unit attacking a 7.8 unit, for a ratio of 1.62. So, here, the bonus peculiarity is helping the attacker. If the expected attacker bonus does not overcome the defender’s bonus (i.e., when overall value for the defender bonus is positive), the targeted promotion is providing less than its promised weight. That is, your 25% bonus against archery units may only be providing 22% in this case. You’d probably be better off just defending, all other things being equal. (See the earlier example) [size="4"]First Strike[/size] First strikes make the most dramatic difference to pure winning percentage when the two fighting units are very close in strength. Two units with identical strength and equal first strikes each have a 50% chance of winning (YAY! Something that finally makes sense in this mess of math). Give 1 a single first strike, though, and the odds of that unit winning goes up to 56.8%. That’s a tremendous difference. Take somebody at the 1.39:1 level and a first strike only matters a few percentage points (from 87.6% to 90.8% and still 84.5% if the weaker unit has the first strike). More than one first strike are similarly weighted towards mattering most for units close in strength. Raw strength is still VERY important, though. A unit with 3.3 strength and no first strikes will still kill a unit with 3 strength and 2 first strikes more often (~56% of the time). The other thing, though, is that units with first strike are less likely to be wounded. First strike helps preserve hit points, so that a unit which won will be healthier. Back to the 3.3 vs. 3 with 2 first strikes example. The stronger unit wins more, but it deals, on average, 78.6 hps damage, while the first strike unit deals, on average, 79.8 hps damage. And the first striker is more than twice as likely to walk away uninjured as the stronger unit. If your unit is barely stronger with first-strike or barely weaker without first strike, then the first strike promotion is better than a strength promotion. This appears true out to about the 1.38/1.39 strength ratio barrier. If the strength ratio is outside 1.38, strength beats first strike. And if strength would change which unit is stronger, strength wins out. Exact calculations on this may come later. One thing to note -- Combat I doesn't always give 10% to modified strength. An archer defending a city on a hill, for example, gains far less than 10% modified strength with Combat I (6 vs. 6.3). In cases with lots of bonuses, Drill might be the better promotion, potentially even over a 20/25% bonus. Work is still in progress on this. [CENTER][b]Graph of Win Percentages[/b][/CENTER] [img]http://www.civfanatics.net/uploads10/Civ4_Combat_Win_Percent.jpg[/img] R = attacker's strength/defender's strength Green -- attacker has 2 extra first strikes Blue -- attacker has 1 extra first strike Black -- attacker/defender even on first strikes Orange -- defender has 1 extra first strike Red -- defender has 2 extra first strikes (sorry for the messiness -- I drew it by hand) [url=http://forums.civfanatics.com/showthread.php?t=137615]Discuss this article on the forum[/url]