Warcraft III resources & community, 2003–2006 · archived

GroupEnumUnitsInAngledRectangle

not rated
Submitted by DaminonFunctions0 downloads
Returns a group containing units in an angled rectangle by giving the angle, lenght, width and a distance from a point.

Source

//Get units in angled rectangle
//***************************************************************************************************
//*
//* Returns a group containing all units in a rectangle with given attributes.
//* 
//*
//*                 A
//*         <-------------->        
//*          ______________
//*     C1  |              | ^
//* <------>|              | |
//* +-------|              | |B
//*         |              | |
//*         |              | v
//*          ¯¯¯¯¯¯¯¯¯¯¯¯¯¯       
//*
//* By Daminon.
//* 
//***************************************************************************************************

function GroupEnumUnitsInAngledRectangle takes real An1, real C1, real A, real B, real X0, real Y0, group G2, boolexpr Fi returns group 
    local unit F
    local real An2
    local real An3
    local real C2
    local real C3 
    local real X1 = C1 * CosBJ(An1) + X0
    local real Y1 = C1 * SinBJ(An1) + Y0
    local real X2 = B / 2 * CosBJ(An1 - 90) + X1
    local real Y2 = B / 2 * SinBJ(An1 - 90) + Y1
    local real X3 = B / 2 * CosBJ(An1 + 90) + X1
    local real Y3 = B / 2 * SinBJ(An1 + 90) + Y1
    local real X4 = A * CosBJ(An1) + X2
    local real Y4 = A * SinBJ(An1) + Y2
    local real X5 = A * CosBJ(An1) + X3
    local real Y5 = A * SinBJ(An1) + Y3
    local real X6
    local real Y6
    local real DX
    local real DY
    local group G1 = CreateGroup()
    local rect R

    if ((An1 >= 0 and An1 <= 90) or (An1 >= 180 and An1 <= 270)) then
        set R = Rect(X3, Y2, X4, Y5)
        //Colsest corner = X3, Y2. Distant corner = X4, Y5.
    else
        set R = Rect(X2, Y3, X5, Y4)
        //Colsest corner = X2, Y3. Distant corner = X5, Y4.
    endif    
       
    call GroupEnumUnitsInRect(G1, R, Fi)
    
    if (ModuloReal(An1, 90) == 0) then
        loop
            set F = FirstOfGroup(G1)
            exitwhen (F == null)
            call GroupAddUnit(G2, F)  
            call GroupRemoveUnit(G1, F)     
        endloop
    else   
        loop
            set F = FirstOfGroup(G1)
            exitwhen (F == null)
            set X6 = GetUnitX(F)
            set Y6 = GetUnitY(F) 
            set An2 = 90 - (Atan2BJ(Y6 - Y1, X6 - X1) - An1)
            if (An2 >= 360) then
                set An2 = An2  - 360                
            endif
            if (An2 <= 180) then
                if (An2 < 90) then
                    set An3 = 90 - (Atan2BJ(Y5 - Y1, X5 - X1) - An1)  
                    if (An3 >= 360) then
                        set An3 = An3  - 360
                    endif
                    if (An2 > An3) then
                        set C2 = A / CosBJ(90 - An2)
                        set DX = X6 - X1
                        set DY = Y6 - Y1
                        set C3 = SquareRoot(DX * DX + DY * DY)
                        if (C3 <= C2) then
                            call GroupAddUnit(G2, F)
                        endif
                    elseif (An2 < An3) then
                        set C2 = (B / 2) / CosBJ(An2)
                        set DX = X6 - X1
                        set DY = Y6 - Y1
                        set C3 = SquareRoot(DX * DX + DY * DY)
                        if (C3 <= C2) then
                            call GroupAddUnit(G2, F) 
                        endif
                    endif
                elseif (An2 > 90) then    
                    set DX = X4 - X1
                    set DY = Y4 - Y1
                    set An3 = 90 - (Atan2BJ(Y4 - Y1, X4 - X1) - An1)
                    if (An3 >= 360) then
                        set An3 = An3  - 360
                    endif
                    if (An2 > An3) then
                        set C2 = (B / 2) / CosBJ(180 - An2)
                        set DX = X6 - X1
                        set DY = Y6 - Y1
                        set C3 = SquareRoot(DX * DX + DY * DY)
                        if (C3 <= C2) then
                            call GroupAddUnit(G2, F)
                        endif
                    elseif (An2 < An3) then
                        set C2 = A / CosBJ(An2 - 90)
                        set DX = X6 - X1
                        set DY = Y6 - Y1
                        set C3 = SquareRoot(DX * DX + DY * DY)
                        if (C3 <= C2) then
                            call GroupAddUnit(G2, F)
                        endif
                    endif
                elseif (An2 == 90) then     
                    set DX = X6 - X1
                    set DY = Y6 - Y1
                    set C3 = SquareRoot(DX * DX - DY * DY)
                    if (C3 <= A) then
                        call GroupAddUnit(G2, F)    
                    endif
                endif
            endif 
            call GroupRemoveUnit(G1, F)           
        endloop
    endif
    
    call DestroyGroup(G1)
    call RemoveRect(R)
    call DestroyBoolExpr(Fi)
    set G1 = null
    set R = null
    set Fi = null
    set F = null

    return G2 
endfunction

Comments

0

No comments.