Ardenian
A
Ardenian
Another life-decisive problem:
When I wanted to update my Simple Grid system with an additional function, I noticed there is a mistake in the calculation.
When entering certain integer values, the function gives wrong real values and therefore a wrong point. However, after the first row jump it doesn't work anymore, or at least doesn't do for certain values ( e.g. 10 ( wrong coordinates, wrong GetTilePosition) or 25 ( wrong coordiantes, but correct GetTilePosition)
I already spent hours debugging and trying, but I cannot get it right.
I would appreciate if someone could help me, please. This system is quite important for me.
When I wanted to update my Simple Grid system with an additional function, I noticed there is a mistake in the calculation.
When entering certain integer values, the function gives wrong real values and therefore a wrong point. However, after the first row jump it doesn't work anymore, or at least doesn't do for certain values ( e.g. 10 ( wrong coordinates, wrong GetTilePosition) or 25 ( wrong coordiantes, but correct GetTilePosition)
JASS:
// For simplicity, I merged the previously x and y calculation into a shared point calculation, until the problem is fixed
// The grid and as well the calculation start frmo the top left and run to the bottom right
// Calculates the point based on grid number i and grid position i2
function GridPoint takes integer i, integer i2 returns location
local integer ic = 1 // counts how many tiles we moved already
local real iy = 0 // iy is responsible for calculating how many rows to move down.
local real ix = 1 // ix is responsible for calculating how many tiles to move right
local integer i3 = 1 // i3 checks if a row is full
if i2 > udg_SUG_GridBreadth[i]*udg_SUG_GridLength[i] then // when the entered tile number is higher than the total grid tiles amount
call DisplayTextToForce( GetPlayersAll(), "Searched position exceeds grid's tile count" )
return Location( ix, iy)
endif
loop
exitwhen ic == i2+1 // exitwhen the searched position is reached
if i3 == udg_SUG_GridBreadth[i]+1 then // check if a row jump is required
set ix = 1 // ix = 1 means being on the first x position
set iy = iy - 1 // since we move down, iy - 1
set i3 = 1
else
set ix = ix + 1 // move one x tile to the right
set i3 = i3 + 1
endif
set ic = ic + 1 // + 1 to total tiles counted
endloop
set ix = GetLocationX(udg_SUG_StartingPoint[i]) + (ix-1) * udg_SUG_Distance[i] // - 1, since ix = 1 when no x change from the starting point
set iy = GetLocationY(udg_SUG_StartingPoint[i]) + iy * udg_SUG_Distance[i] // row jumps
return Location( ix, iy)
endfunction
// Checks if the point is in the entered grid ( integer i)
function IsInGrid takes integer i, real x, real y returns boolean
local real gx2 = GetLocationX(udg_SUG_StartingPoint[i]) // if x lower than x starting position -> not in grid
local real gy2 = GetLocationY(udg_SUG_StartingPoint[i])
local real gx = gx2 + udg_SUG_Distance[i] * (udg_SUG_GridBreadth[i]-1)
local real gy = gy2 - udg_SUG_Distance[i] * (udg_SUG_GridLength[i]-1)
return not((x > gx) or(x < gx2) or(y < gy) or(y > gy2))
endfunction
// This function kinda works as a debug, it will give an integer based on the location and
// as we previously calculated a point based on an integer, it should be the same
function GetGridPosition takes integer i, location p returns integer
local integer pos
local real x = GetLocationX(p)
local real y = GetLocationY(p)
local real px = GetLocationX(udg_SUG_StartingPoint[i])
local real py = GetLocationY(udg_SUG_StartingPoint[i])
if IsInGrid( i, x, y) == true then
set x = SquareRoot((x-px)*(x-px)) / udg_SUG_Distance[i] // get x distance between starting point x and tile x, then / tile distance of grid
set y = SquareRoot((y-py)*(y-py)) / udg_SUG_Distance[i] // get y distance between starting point y and tile y, then / tile distance of grid
if I2R(R2I(x)) != R2I(x) or I2R(R2I(y)) != R2I(y) then // when the distance matches not the distance between tiles
call DisplayTextToForce( GetPlayersAll(), "Searched point is not a grid point" )
else
set pos = R2I(x+1 + y*udg_SUG_GridBreadth[i]) // calculate grid position of point p
endif
else
call DisplayTextToForce( GetPlayersAll(), "Searched point is not in grid" ) // point is not in grid
endif
return pos
endfunction
I already spent hours debugging and trying, but I cannot get it right.
I would appreciate if someone could help me, please. This system is quite important for me.
Last edited by a moderator: