What do distance units mean?
In XCOM configuration files, distances are expressed in some obscure units, that do not translate to grid cells easily.
Example values:
- unit vision radius: 27
- most weapons range: 27
- sniper rifle range: 100
- soldier (and most enemies) run distance: 12
- thin man run distance: 15
- cryssalid run distance: 20
A soldier definitely does not run 12 grid cells straight.
So, what are distance units in grid cells, and how distances are calculated diagonally?
Here is an answer that explains all apparent issues with arithmetic, e.g. the "off by 1" issue, or ghosts of additive modifiers.
The exact conversion factor of tiles/mobility is 0.666. This differs from the intended factor of 1/1.5 (or 2/3), which equals 0.666(6) in decimal, with an infinite number of trailing 6's. Since the game cannot process infinite precision numbers, it truncates it to 0.666, with 3 or more trailing 6's. Because of this, we now have 1/0.666 or 1.5015 mobility points per tile.
For example, with mobility 12 we have:
blue move: 12 * 0.666 = 12/1.5015 = 7.99 => round_down(7.99) = 7 tiles yellow dash: 12 * 0.666 * 2 = 15.98 => round_down(15.98) = 15 tiles
So we get the actual 7/15 tile movement instead of the intended 8/16 tiles for mobility value of 12.
I tested all movements (single/double for straight and diagonal) for all mobility values between 3-30, and have confirmed that the factor of 0.666 correctly predicts 100% of the cases with the assumption that fractional number of tiles are always rounded down.
I've updated the ufopaedia.org page on Movement, and said more about this in the discussion page
This conversion also works for the range and radius of throwables (e.g. grenades). For example, an AP grenade has a blast radius of 5.6 mobility, which equals 5.6 * 0.666 = 3.73 straight tiles, which rounds down to a 3 tiles, and also 5.6*0.666/1.414 = 2.6 diagonal tiles which rounds down to 2 diag tiles.
how distances are calculated diagonally?
They are simply calculated with pythagorian distance equation, rounded.
In A column and 1 row, I put 1 to 15. Then I put this formula in B2, and copy pasted it down and to the right: =ROUND(SQRT($A2*$A2+B$1*B$1),0)
A full move is 15 squares and a half-move is 7 squares (15/2, round down). The diagonal half-move is highlighted red - you can move 5 squares diagonally in a half-move, because that square is 7 units distant from the origin of movement. Obstacles and elevation use some of the 15 unit move allowance, as the soldier no longer moves in a straight line (look at the glow trail before moving).
what are distance units in grid cells
A couple theories are show in the above picture. We can be pretty sure that a config unit is between 90 and 96 fictional units, between 0.625 and 0.667 cells. This might be precise enough to do whatever you want to do with config units. In game with the default ini, the only distance we don't understand is: at what range does a squadspotted sniper rifle shot fail (62-67 cells - approx 4 full moves). All the other distances are verifiable by examination. Embrace the pragmatic - if you want some distance to be longer, increase the value.
My own theory was 0.625... But then I went and asked.
@SolomonJake A tile in XCOM is 96 unreal units squared, which is 1.5m in real world units.
So it is 1.5 meters per cell. But the calculations are trickier. Let's assume config files state meters:
- Single move: 12 meters / 1.5 = 8.
- Double move: 24 meters / 1.5 = 16.
- Vision range: 27 meters / 1.5 = 18.
All values off by one. A ghost of additive modifier is upon us again :-)
After reading Jake's response, I have been laying out calculations and for some reason have set 0,64 as cell-to-config-unit ratio (as if a meter was 64, and a cell was 100 unreal units, which is false). And numbers made sense - 7.68, 15.36, and 17.28, just round down and voila. But it is wrong :-(