Oookay. So. I have a bunch of units spread out in a grid, with their locations stored in a two-dimensional array (struct with an array of another struct).
Here is the function that is annoying me:
Angle comes from the units facing, and that method is supposed to work out what square in the grid it is looking it. It is supposed to return the square directly infront of it, based on its facing.
Here is some data I'm plugging in, and the incorrect results that method is returning:
origin.x = 3
origin.y = 0
angle = 270.000
distance = 1
Output (from that BJDebugMsg):
c = 2
r = 1
Its returning the correct row in the grid, but it is changing the column when it shouldn't be changing it at all. The angle is 270, or directly south, so the column is supposed to be the same as the origin. Its acting like the angle is 225...
Here is the function that is annoying me:
JASS:
function get_target_square takes square origin, real angle, integer distance returns square
local integer c = origin.x
local integer r = origin.y
if (angle < 90.0 or angle > 270.0) then
set c = c + distance
endif
if (angle > 90.0 and angle < 270.0) then
set c = c - distance
endif
if (angle < 180.0 and angle > 0.0) then
set r = r - distance
endif
if (angle > 180.0 and angle < 360.0) then
set r = r + distance
endif
call BJDebugMsg("DEBUG. get_target_square: angle = " + R2S(angle) + ", origin = " + I2S(origin.x) + " " + I2S(origin.y) + ", c = " + I2S(c) + ", r = " + I2S(r))
if (c < 0 or c > 7 or r < 0 or r > 7) then
return null
endif
Here is some data I'm plugging in, and the incorrect results that method is returning:
origin.x = 3
origin.y = 0
angle = 270.000
distance = 1
Output (from that BJDebugMsg):
c = 2
r = 1
Its returning the correct row in the grid, but it is changing the column when it shouldn't be changing it at all. The angle is 270, or directly south, so the column is supposed to be the same as the origin. Its acting like the angle is 225...
if (angle > 90.0 and angle < 270.0) then
is returning true when it shouldn't be... when the angle is 270!