It's actually my math. I got darkestaxe to write it in pseudocode for me.

Could the formula include obstacles on the Line of Fire?

I would prefer drop of accuracy at the point blank, to give niche for melee attacks. 2 tiles away 95% sounds rad.

The game already includes obstacles in the calculation. My equation is supposed to determine the accuracy value given as the shot is made, just like how the UFO Extender Accuracy works. It'll display roughly your chance to hit if you have an open shot. It's up to you to see that your shot is partly occluded and recognize that your actual chance to hit may be lower.

As for accuracy drop at shorter range, I would like to see the effect be an option you can add to your mod. UFO Extender Accuracy has a minimum range setting, the way it works is that anything between minimum and dropoff has max accuracy, while anything over or under has gradually reduced accuracy based on distance. As my calculation is very different, I should develop an equation for a minimum accuracy function.

My initial thought is to set an optimal close range, and if such a range is set then as target gets closer, accuracy increases only until optimal far range, stays the same from optimal far to optimal close, and goes down from optimal close, reaching zero at zero squares distance (being in the same tile). So then the calculation for the accuracy reduction would be: (TR/OCR)*BSA

TR = Target Range

OCR = Optimal Close Range

BSA = Base Shot Accuracy

So for example, we have a rifle with a snap shot optimal far range of 15 tiles while its optimal close range is 3 tiles. The soldier using this weapon has 60 accuracy and the rifle's snap shot accuracy is 60%. Here's the accuracy at different ranges:

1 tile: 12%

2 tiles: 24%

3 tiles: 36%

5 tiles: 36%

7 tiles: 36%

10 tiles: 36%

15 tiles: 36%

20 tiles: 27%

30 tiles: 18%

45 tiles: 12%

You'll note that the accuracy reaches 36% in a certain range and levels off. An alternative method would be to have accuracy continue to increase as target range decreases, until the halfway point between optimal far and optimal close range at which point it switches to the other calculation and makes accuracy begin to decrease. The halfway point isn't necessarily the median between the two but rather the point at which both calculations reach the same value. In this case, it is ~6.7082 tiles, which you can find by getting the square root of the far divided by the close, and multiply the result by the far range. 15 / 3 = 5, (sqrt)5 = ~2.2361, ~2.2361 * 3 = ~6.7082. Essentially you're just running both calculations and taking the smaller of your two resulting accuracy values. Here's how it would play out:

1 tile: 12%

2 tiles: 24%

3 tiles: 36%

5 tiles: 60%

7 tiles: 77%

10 tiles: 54%

15 tiles: 36%

20 tiles: 27%

30 tiles: 18%

45 tiles: 12%

As you can see, this change only affects values between 3 and 15 tiles. With this equation, the accuracy peaks at around 6 to 7 tiles distance to target.