Ardenian
A
Ardenian
After http://www.hiveworkshop.com/forums/triggers-scripts-269/operation-limits-276842/ and http://www.hiveworkshop.com/forums/...hecking-if-point-region-partly-region-276804/,
I would be glad to receive some final help on debugging and finding the mistake in my system.
I spent hours, I would say around six, trying to find a reason why my system does not work.
Basically, I create a random amount of rectangles, 'rooms', and check if a newly created one intersects with formerly created ones.
If so, I randomize the newest one again. If not, I keep it.
However, after the first rectangle is created, the function starts to infinitly loop trying to create the second one, but
calculating every time the second one intersects the first one.
My theory is that the intersect check is wrong, since it does not seem logical to me why the current check should work, since there is only a check for a direction, not a two-dimensional intersection ( or something, I suck at math).
However, several people approved the check for the intersection.
If you enable
and
in the second function, CreateRooms, you see it runs infinite times.
Additionally, it occasionally seems to work appropiatly.
I would be very grateful if you could help me here, I am at a point I would say I am desperate.
I would be glad to receive some final help on debugging and finding the mistake in my system.
I spent hours, I would say around six, trying to find a reason why my system does not work.
Basically, I create a random amount of rectangles, 'rooms', and check if a newly created one intersects with formerly created ones.
If so, I randomize the newest one again. If not, I keep it.
However, after the first rectangle is created, the function starts to infinitly loop trying to create the second one, but
calculating every time the second one intersects the first one.
JASS:
function Overlapcheck takes integer i, real xMin1, real yMin1, real xMax1, real yMax1 returns boolean
local integer overlap = 1
local real yMax2
local real yMin2
local real xMin2
local real xMax2
loop // check if the room overlaps with another
exitwhen overlap == i
//call BJDebugMsg( "Current room overlap check: "+I2S(overlap))
set xMin2 = GetRectMinX(udg_RoomRect[overlap])
set yMin2 = GetRectMinY(udg_RoomRect[overlap])
set xMax2 = GetRectMaxX(udg_RoomRect[overlap])
set yMax2 = GetRectMaxY(udg_RoomRect[overlap])
if xMin1 < xMax2 or xMax1 > xMin2 or yMin1 < yMax2 or yMax1 > yMin2 then
//call BJDebugMsg( "overlap")
return true // there is overlap
endif
set overlap = overlap + 1
endloop
call BJDebugMsg( "no overlap")
return false // there is no overlap
endfunction
function CreateRooms takes nothing returns nothing
local integer i = 1 // i is the number of the room that is created
local real x
local real y
local real breadth
local real length
local boolean xycheck = true
local real x2
local real y2
set udg_RoomCount = GetRandomInt( 3, 8) // total rooms
loop
exitwhen i > udg_RoomCount
set xycheck = true
// intial randomized room data
loop
exitwhen xycheck == false // true = there is intersection
set x = 0 + I2R(GetRandomInt( -41, 25))*128 // x coordinate of the intial room point
//call BJDebugMsg( "Current room X: "+R2S(x))
set y = 0 + I2R(GetRandomInt( -25, 41))*128 // y coordinate of the inital room point
//call BJDebugMsg( "Current room Y: "+R2S(y))
set breadth = I2R(GetRandomInt( 6, 14)) // breadth of the room
set length = I2R(GetRandomInt( 6, 14)) // length of the room
set x2 = x + breadth*128 // last point in the room
set y2 = y - length*128 // last point in the room
set xycheck = Overlapcheck( i, x, y, x2, y2)
endloop
set udg_RoomRect[i] = Rect( x, y, x2, y2)
set udg_RoomX[i] = x
set udg_RoomY[i] = y
set udg_RoomBreadth[i] = breadth
set udg_RoomLength[i] = length
call BJDebugMsg( "current room: "+I2S(i))
set i = i + 1
endloop
endfunction
function InitTrig_CreateRooms takes nothing returns nothing
endfunction
My theory is that the intersect check is wrong, since it does not seem logical to me why the current check should work, since there is only a check for a direction, not a two-dimensional intersection ( or something, I suck at math).
However, several people approved the check for the intersection.
If you enable
JASS:
//call BJDebugMsg( "Current room X: "+R2S(x))
JASS:
//call BJDebugMsg( "Current room Y: "+R2S(y))
Additionally, it occasionally seems to work appropiatly.
I would be very grateful if you could help me here, I am at a point I would say I am desperate.
Last edited by a moderator: