Originally posted by Math Guy
Okay, after examining Johan's code I think I understand the problem. The AA variables do work, but they are very, very nonlinear in the way they work. You have to be careful not to exceed their design limits or weird stuff happens.
First, the AA_batteries variable modifies each point of AA. For example, if you've built techs that give you +10, +10, +10, and +10, you will have a total of +40 % and each point of AA will be worth exactly 1.400. That is the number shown as "AA_efficiency" in the game save file.
Now when AA fires, it computes the chance of getting through the aircraft's surface_defense this way. For each point of surface defense it does a test:
if (rand()%100 < 75-flak), hit = false
flak = (AA_efficiency - 1.000) * 100.0
This is where all the nonlinear weirdness kicks in.
For example if flak = (1.400 - 1.000) * 100.0 = 40.0, then 75-40 = 35 and each point of surface_defense will stop one flak hit 35 % of the time. An average flak hit, by the way, still seems to be worth 3 % damage to the target, plus or minus 2 %.
That seems quite okay, but then if flak = (1.750 - 1.000) * 100.0 = 75.0, then 75-75 = 0 and surface_defense will not stop ANY flak hits. You can have surface_defense = 500 and it won't matter.
Conversely if flak = (0.750 - 1.000) * 100.0 = -25.0, then 75 - (-25) = 100 and surface_defense will stop 100 % of flak hits. So if you have a plane rated surface_defense = 10 or greater, flying into a province where the AA efficiency is 0.750 or lower, the AA will never hit anything even if the province has 10 AA.
In plain language, tweak the AA_efficiency value below 0.75 and it can't hit anything. Tweak it above 1.75 and it can't miss. In between it is possible for both AA_efficiency and surface_defense to have their intended effect.
As the techs in the game allow you to take AA_efficiency well above 2.00, it is easy to get in a position where surface_defense doesn't work any more, and this is what led to my submitting a bug report. Sorry if I confused anyone.
By the way, this way of calculating AA effect leads to some interesting situations. Say you have surface_defense = 1 and you're attacking a province with efficiency 0.800 and AA = 2. The AA gets two shots at you each hour. You have a 95 % chance of stopping the first shot (75-(-20) = 95) but you don't get any chance to stop the second shot.
So it all appears very moddable and I think pretty much any AA environment you may want to create is possible. But you have to watch those limits!
I still have some work to do on this. I want to run tests with a good variety of values just to make sure the equation is exactly as I have described it. The code Johan showed me has a different damage value than the one I observe in the game, so I'm not going to assume anything.
However, I have successfully caused AA to stop having any effect by lowering AA_efficiency, and I've produced the "miss the first, get hit by the second" effect I describe above for planes with surface_defense = 1, so clearly the variables ARE both working.
Many thanks to Johan for giving me the "inside scoop" so I could figure out what was happening.