- Joined
- Oct 9, 2015
- Messages
- 721
How can I pick units that are between point1 and point2 ?
Thanks in advice!
Thanks in advice!
Could you elabote more, if Nichilus's post haven't already helped you?pick units that are between point1 and point2
Yes. The functioncan it support a "line size" or something ?
GroupEnumUnitsInRangeOfSegment
that is provided by that system takes a distance
paramter which determines how far from the line do units get picked.call GroupEnumUnitsInRangeOfSegmentLoc( udg_TempGroup, udg_Loc1, udg_Loc2, 10.0, null )
function GroupEnumUnitsInRangeOfSegment takes group whichgroup, real Ax, real Ay, real Bx, real By, real distance, boolexpr filter returns nothing
local real dx = Bx-Ax
local real dy = By-Ay
local real L = ((dx)*(dx) + (dy)*(dy)) // Get quasi length
local real r = SquareRoot(dx*dx+dy*dy)/2+distance + 400.0 // replace 400.0 with the max collision size in your map
local unit u
call GroupClear(whichgroup)
call GroupEnumUnitsInRange(udg_LineTempGroup, Ax+(dx/2), Ay+(dy/2), r, filter)
loop
set u = FirstOfGroup(udg_LineTempGroup)
exitwhen u == null
if L == 0 and IsUnitInRangeXY(u, Ax, Ay, distance) then // seg is actually a point so lets return the point
call GroupAddUnit(whichgroup, u)
else
set r = ((GetUnitX(u)-Ax)*(dx) + (GetUnitY(u)-Ay)*(dy))/(L) // get the ratio
if r > 1 then // split if/thens so that it exists properly
if IsUnitInRangeXY(u, Bx, By, distance) then // closests point is past seg, so return end point B
call GroupAddUnit(whichgroup, u)
endif
elseif r < 0 then
if IsUnitInRangeXY(u, Ax, Ay, distance) then // same as B, but at A instead
call GroupAddUnit(whichgroup, u)
endif
elseif IsUnitInRangeXY(u, Ax+r*(dx), Ay+r*(dy), distance) then // In the middle of A and B so use the ratio to find the point
call GroupAddUnit(whichgroup, u)
endif
endif
call GroupRemoveUnit(udg_LineTempGroup, u)
endloop
set u = null
endfunction
function GroupEnumUnitsInRangeOfSegmentLoc takes group whichgroup, location A, location B, real distance, boolexpr filter returns nothing
call GroupEnumUnitsInRangeOfSegment(whichgroup, GetLocationX(A), GetLocationY(A), GetLocationX(B), GetLocationY(B), distance, filter)
endfunction
IsUnitInRangeXY
check which does consider unit collision size.IsUnitInRangeXY
check which takes unit collision size into account, however when calculating how far away to look for units to run this check on it was relying on another library to tell it what the maximum unit collision size is and if that library wasn't present it just used 0. I changed it so that it uses the value 400.0 instead, which is larger than any building collision size, however if your spell can't hit buildings then you can reduce this to improve performance (since fewer units will need to be checked if the search range is lower).I didn't clearly understand your trigger and what does it do, Ease, can you enlight me on it, please ? How can I adapt it to my functions ?
set r = ((GetUnitX(u)-Ax)*(dx) + (GetUnitY(u)-Ay)*(dy))/(L) // get the ratio
if r > 1 then // split if/thens so that it exists properly
if IsUnitInRangeXY(u, Bx, By, distance) then // closests point is past seg, so return end point B
call GroupAddUnit(whichgroup, u)
endif
elseif r < 0 then
if IsUnitInRangeXY(u, Ax, Ay, distance) then // same as B, but at A instead
call GroupAddUnit(whichgroup, u)
endif
Inefficient, inaccurate and scales badly. Also does not factor in unit collision size. Can be sufficient though and is how HotS and SC2 implement many of their skills, but they do have searches which do factor in collision size which let them do this.All you need to do is "get" the distance between your two points. Then loop the number of time needed for the distance. For example, if the distance is 1000, we divide it by 100 which equals 10. Then we loop 10 times and create circles every 100 distance. The circles are 150 so they overlap. Then we select all the units inside the circles. Now we have all the units between two points. You can narrow the circles and close the distance between them if you like. That way you get a narrower line.
Or you can use Anitarf cryptic JASS implementation which will do it more accurately and more efficient.I tried reading the thread but it got confusing. I don't really understand what you want to do beyond, just picking all units in a line. The GUI above will pick all units in a line. How you determine what Tempp1 and Tempp2 are is up to you.