[Vanilla] Hans Lemurson figures out the Combat Formula

<your steam folder>\SteamApps\common\Sid Meier's Civilization VI\Base\Assets\UI\Panels\UnitPanel.lua
It's certainly possible to get some information there but it's a 3729 lines file and from what i've seen looking quickly no code there deals with the actual damage calculation, just how to display the results (or rather the expected result)

Do you guys not know how to use find? it's line 1442 that starts the function.

Download the program everything to find files on your system.
Download WinGrep to search over your civ files
Use Find in sublime text.
Use Goto Line in sublime text to get to the line
 
Do you guys not know how to use find? it's line 1442 that starts the function.
Of course i can use the find function of Notepad++ and i can search in every file and mark every line containing CombatResultParameters and then try to figure where those come from and find references to the unitData table and FilterUnitStatsFromUnitData function and finally track that to ReadUnitData function that uses call methods from the unit object within the dll

Now, i must admit i'm not a professional coder and my Lua is a bit rusted so maybe you can point us to the exact line that actually does the calculation
 
maybe you can point us to the exact line that actually does the calculation

There is no exact line. It goes through the process to display the combat results in the panel, so you can use that to view it. But you have to do the work. It basically confirms what has been said previously utilizing the globals. After that, it's a lot of DLL calls which obviously become opaque to us.
 
Which is almost exactly what i said previously so not sure why you had to be condescending.
 
Which is almost exactly what i said previously so not sure why you had to be condescending.

I wasn't being condescending. I think if you read my response in good faith, you'll find I was just being helpful.
 
Do you guys not know how to use find?
Well, that part looked condescending to me but it's often hard to grasp the tone of someone when you read them on a forum. Modern mass communication platforms sometimes makes communicating much harder. Maybe you were tired when you wrote this, or maybe i was tired when i read it (probably), or maybe both.

Thanks for pointing us to this file anyway, even if it wasn't probably as useful as you thought/hoped it would be. :)
 
Well, that part looked condescending to me but it's often hard to grasp the tone of someone when you read them on a forum. Modern mass communication platforms sometimes makes communicating much harder. Maybe you were tired when you wrote this, or maybe i was tired when i read it (probably), or maybe both.

Thanks for pointing us to this file anyway, even if it wasn't probably as useful as you thought/hoped it would be. :)

It's all good. If you read it in a nice tone, you'll find it's a simple misunderstanding. I'm a professional engineer, and I don't do a particularly good job understanding how my comments will impact others. Will try to do better.

I'm not sure I thought it'd be hugely useful, but there are some interesting parts in there. Like the fact the panel displays half of the randomized combat.

I'm currently working on combat scaling changes for the MP mod I work on, so was just on my mind, and thought I'd add that there is detail there. Sounds like you guys already understand it.
 
Not nearly enough likes on this thread so have another :).

If you have the production/resources the corps/armies and great generals are important boosts. Elite units with these modifiers are devastating.
 
Yay! Other people have taken over the hard work now and I can still take credit! :)

Yeah, given that Corps can be built at 1.5x the cost (with an Academy) and deal 1.5x damage and have 1.5x the effective HP, that is amazingly powerful. +5 Strength (1.22x) on top of that and it's monstrously powerful.

The "combat power" of a unit is it's Firepower * HP. e^(2*1.04*StrengthDiff) will tell you how many lesser units your unit can take on in combat. Every +9 strength doubles the number of enemies that a unit can take on.

I'm not sure this applies to ranged units though, since they don't get attacked as often, so their HP will be less important. I would be more worried about 2 Crossbows than a Crossbow Corps, but a 2 Knights will certainly lose to a Knight Corps (actually it depends on how flanking bonuses come into play, come to think of it).
 
Last edited:
Flanking matters and it can stack (actually great generals can stack too, thought it's impractical to do that usually). GG + flanking + oligarchy is pretty nasty early on, it adds an era basically. 50+ strength classical era units are no joke, and it takes a long time before cities resist that so you wind up having no trouble with a siege tower or even a battering ram.

Artillery armies with grape shot line are actually pretty darned effective, which is good because ranged of later eras starts to suck.
 
You know there is a problem with strategy games where most in-game mechanisms are not explained and you have to guess them...
This is a massive problem with civ 6.... it has always been a problem with civ, but it seems like it has gotten worse with each entry.
 
@Mods : This discussion should be pinned imho.
 
Solved (more or less):

Combat Damage Dealt = exp[ 3.369311+ ( Attacker Strength - Defender Strength) x 0.037637 + U(-.27,.23) ]

U ~ a random sample from the uniform distribution with bounds -.27, +.23 (the uniform distribution)

Yes, I know it's asymmetrical; one of two things is happening. One, the devs are putting 'boxing gloves' on combat, with a modest negative bias to damage dealt to make units slightly harder to kill without HP-inflation. Two, our modest sample just happens to be in that part of the sample space, while the underlying distribution is in fact random.

This is based on analysis of the data set provided by OP, those parameter estimates for base damage (3.36...) and relative strength effect (.037...) might tighten up to a more reasonable number with increased data collection. It's quite possible (based on the standard error for those value estimates) that the base damage factor is actually +/- up to .04 and the strength effect is +/- up to .001. Overall, the model accounts for roughly 90% of the variation within the source data with the base damage and relative strength effects 'highly significant', or in layman's terms, 'mathematically legit'.

Based on this we'll 'reliably' (in 50%+ of cases) see 1-damage for a Strength Difference of -89.52124 (that is, Attacker Strength 89.5 points below Defender Strength, possibly something like -90) and 100-damage for a Strength Difference of 32.83628 (probably 33). In the source data we only saw four 100-damage cases:
Crossbowman wrecks Scout with a 39-point advantage,
Crossbowman wrecks Scout with a 41-point advantage,
Horseman wrecks Barb Horse Archer with a 40-point advantage (taking 6 damage)
Roman Legion wrecks Slinger with a 40-point advantage (taking 6 damage, again, possibly there's a floor on attacker damage for melee?).

Supporting this idea about damage floors, there is the fact that the lowest Defender damage we saw in the data is 13 (double a 6.5 damage attacker floor, perhaps?). There were seven cases of this in the data, four were District City Centers (versus other District City Centers, strangely), with strength differences ranging from -16 to -22. In our data however, we didn't see any "terrible generalship" and the data didn't have late-game units getting attacked by scouts and other trash, so it's not surprising that we didn't see any 1-damage pew-pew nonsense.

The range on the uniform distribution is based on the residuals of the model fit using the parameter estimates above. Those residuals have quartiles:
0%: -0.26960892
25%: -0.10573067
50%: 0.01500539
75%: 0.11655122
100%: 0.22684554

Those are pretty flat (as a uniform distribution should be) and supported by the Quantile/Quantile Plot below (against the aforementioned Uniform distribution). A nice diagonal line between the bottom left and top right corner of the plot indicates a 'good' fit.
QQResid.png


And below we have observed and theoretical ranges of Attacker Damage:
AttackerDmg.png

...and Defender Damage:
DefenderDmg.png


Here we have a plot of the source data, attacker and defender damage shown separately. Notice ranged units chilling at the bottom.
DmgSamp.png

And here we have paired damage outcomes from our source data - notice how few outcomes we see above the 'tie' line (the line indicates attacker damage equal to defender damage, above the line indicates attacker damage higher than defender damage), showing at least that the AI and our intrepid player favors 'winning' battles. (Though I think we all agree that the A.I. could use a little more of the 'lose the battle, win the war' maxim).
DmgOption.png


In any case, more data collection yields better estimates, but I think these give a pretty good understanding of the damage calculation.

Source: Statistician is my day job.
 
That is a good analysis which is well in line with all the other results we have gotten.

The presentation of the formula, though mathematically correct, is a little unintuitive. Most of the Constants are probably calculated outside of the Exponent in the formulation likely used in the game.

exp(3.369) = 29.06 which is close to the reasonable and wholesome number of 30.
exp(0.23) = 1.259 which is close to the reasonable and wholesome ratio of 1.25
exp(-0.27) = 0.763 which is close to the reasonable and wholesome ratio of 0.75

The most likely damage formula (based on values found in the XML) uses a uniform distribution between 24 and 36 which occurs outside of the exponential function.
 
Well, I'm aware of the concept of trying to turn homework into a game and it'll become more enjoyable, but turning a game into homework???? that's a new one for me.

Credit where its due, very good work that i'm sure MANY players (myself included) will find extremely useful.

Thank you.
 
With the math experts on combat here on this thread I have a question.
Very informative :)

I use walls a lot to fight the AI, luring them in my crossfire of cities and encampments.
I know that my wall/garrison strenght goes up with the strongest (melee) unit I have (and had) in my army.

But how about the ranged strenght of the garrisons ?
Does that go up with the highest melee strength of one of my units ?
Or is it determined by the highest range strenght I have in my army ?
 
Top Bottom