Warcraft III resources & community, 2003–2006 · archived

ForCircle

not rated
Submitted by KaTTaNaExecution0 downloads
Runs callBack for each point on a circle, offset by interval. Use GetEnumLoc to refer to the current point on the circle. The points will get removed after the first wait, or when the code stops; so clone them before a wait function, or if you store them in a global variable.
callBack is run in a seperate created trigger, so waits will not halt the main thread. Keep in mind that you should not use GetTriggeringTrigger() in callBack.

Parameter explination:
center: Center of the circle.
radius: Radius of the circle.
interval: Distance between each used point in the circle.
startAngle: The angle at which the run starts. If the order of which the points are chosen doesn't matter, this can be set to anything.

If you are using radiuses above 500, I recommend that you keep interval at 64.0 or above.

Source

function GetEnumLoc takes nothing returns location
    return bj_meleeNearestMineToLoc
endfunction

function ForCircle takes location center, real radius, real interval, real startAngle, code callBack returns nothing
    local location loc
    local location old = bj_meleeNearestMineToLoc
    local real x = GetLocationX(center)
    local real y = GetLocationY(center)
    
    local real perimeter = radius*2*bj_PI
    local real angle = startAngle
    local real incAngle 
    
    local trigger trg = CreateTrigger()
    call TriggerAddAction(trg, callBack)
    
    if (interval > 0) and (radius > 0) then
        set incAngle = 360.0 * interval / perimeter
        
        loop
            exitwhen angle >= startAngle+360.0
            
            set loc = Location( x+CosBJ(angle)*radius ,y+SinBJ(angle)*radius )
            set bj_meleeNearestMineToLoc = loc
            call TriggerExecute(trg)
            call RemoveLocation(loc)
            
            set angle = angle + incAngle
        endloop
        
    elseif (radius == 0) then
        set loc = Location(x,y)
        set bj_meleeNearestMineToLoc = loc
        call TriggerExecute(trg)
        call RemoveLocation(loc)
    endif
    
    set bj_meleeNearestMineToLoc = old
    call DestroyTrigger(trg)
    set loc = null
    set old = null
    set trg = null
endfunction

Comments

0

No comments.