Performing `grep -r core.fov.distance game/` made me realize that many places in the code check range boundaries on their own, and practically
none use the rounding method that this forum topic established. This has in-game consequences too. For example, it is possible to perform a ranged talent that you
think is in range (because targeting uses rounded range), but falls short of that range when actually executed. I think we should define and use a universal "isInRange" function such as the one below. Calling this in the appropriate places in the code is beyond my comfort and confidence levels, because there are many places that appear to need modified and I'm not familiar with any of them.
Code: Select all
-- See if tiles (x,y) and (tx,ty) are within "range" of each other.
-- "range" can be a float. If integer range is desired, then cast to int via "range_int = math.floor(range + 0.5)"
-- Note: 'dx*dx + dy*dy < (r+0.5)*(r+0.5)' is 100% equivalent to
-- 'floor(sqrt(dx*dx + dy*dy) - range + 0.5) <= 0', which was previously used.
function isInRange(x, y, tx, ty, range)
if range < 0 then return false end
if (x-tx)*(x-tx) + (y-ty)*(y-ty) < (range + 0.5)*(range + 0.5) then
return true
end
return false
end
Below is a useful reference for how floating point ranges behave for small range. Note that "[]" are inclusive boundaries, "()" are exclusive boundaries, and "{}" are safe approximate boundaries. The three rows below correspond to ranges (0.5, 1.5], (1.5, 2.5], and (2.5, 3.5], respectively.
Code: Select all
(0.5, sqrt(2)-0.5) [sqrt(2)-0.5, 1.5]
(0.5, 0.914} {0.915, 1.5]
..... .....
..*.. .***.
.*@*. .*@*.
..*.. .***.
..... .....
(1.5, sqrt(5)-0.5) [sqrt(5)-0.5, sqrt(8)-0.5) [sqrt(8)-0.5, 2.5]
(1.5, 1.736} {1.7361, 2.328} {2.329, 2.5]
....... ....... .......
...*... ..***.. .*****.
..***.. .*****. .*****.
.**@**. .**@**. .**@**.
..***.. .*****. .*****.
...*... ..***.. .*****.
....... ....... .......
(2.5, sqrt(10)-0.5) [sqrt(10)-0.5, sqrt(13)-0.5) [sqrt(13)-0.5, 3.5]
(2.5, 2.662} {2.663, 3.105} {3.106, 3.5]
......... ......... .........
....*.... ...***... ..*****..
..*****.. ..*****.. .*******.
..*****.. .*******. .*******.
.***@***. .***@***. .***@***.
..*****.. .*******. .*******.
..*****.. ..*****.. .*******.
....*.... ...***... ..*****..
......... ......... .........
Above 3.5, floating point range behaves pretty smoothly.