Thanks for this article in part to BomberEscort and snepp for their work in another thread http://forums.civfanatics.com/showthread.php?t=137350. Some credit also due to http://apolyton.net/forums/showthread.php?s=&threadid=140622 for descriptions (even though some are terribly wrong).

The basics

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.

Attacker’s modified strength

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).

Defender’s modified strength

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)).

The actual combat

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....

Round odds

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).

Damage per hit

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 http://c4combat.narod.ru/c4c.htm [Note:

**Updated**to include hps -- thanks, Ellestar.]

First Strike

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.

Retreat

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.

Collateral Damage

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.

Maximum Damage

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.

Number of Targets

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).

Selecting targets

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.

Amount of Damage Done

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.

Putting It All Together

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).

Experience Points

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)).

(continued in next post)

Arathorn