• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

GroupEnumUnitsInRange and Locus

Status
Not open for further replies.
I know that GroupEnumUnitsInRange doesn't work with units that have 'aloc'. I remove 'aloc' with the following code:
JASS:
function RemoveLocus takes unit U returns nothing
    call ShowUnit(U,false)
    call UnitRemoveAbility(U,'aloc')
    call UnitAddAbility(U,'avul')
    call ShowUnit(U,true)
endfunction
It still renders the unit unselectable, untargetable, invulnerable, and ignore pathing/collision. However, it seems to still make it not work with GroupEnumUnitsInRange. Is there a workaround for this that doesn't change the speed of the loop?
 
AFAIK you can't get the effects of Locust through any other ability... and locust naturally prevents GroupEnumUnitsInRange from working.

So what is the best solution? I would write a custom GroupEnumUnitsInRange() function and use that instead. I would use some unit indexer (or just register when a dummy unit is created/removed) and then I would make a custom function that iterates through them to see if any are in range IsUnitInRangeXY. If you have a lot of dummy units e.g. 30+ at any time, then you may want to consider tracking their movements so that you can reduce the number of iterations when you do your custom GroupEnumUnitsInRange. If you are using your own custom dummy system, it shouldn't be that bad to keep track of that stuff.

tl;dr you have to use either a different function or your own function. And simulating locust through triggers won't help. In multiplayer, the selection event is delayed and it is just a hassle to implement.
 
JASS:
function UnitsInRange takes group G,real X,real Y,real R returns nothing
    // ***** Local variables *****
    local player P=null
    local unit U=null
    local integer I=0
    local group tmp=CreateGroup()
    local real dx
    local real dy
    set R=R*R
    // ***** Loop *****
    loop
        // ***** Loop set-up *****
        set P=Player(I)
        call GroupEnumUnitsOfPlayer(tmp,P,null)
        // ***** Handle player's units *****
        loop
            // ***** Loop set-up *****
            set U=FirstOfGroup(tmp)
            exitwhen U==null
            call GroupRemoveUnit(tmp,U)
            set dx=GetUnitX(U)-X
            set dy=GetUnitY(U)-Y
            if dx*dx+dy*dy<=R then
                call GroupAddUnit(G,U)
            endif
        endloop
        // ***** Loop clean-up *****
        exitwhen I==15
        set I=I+1
    endloop
    // ***** Clean-up *****
    set P=null
    set U=null
    call DestroyGroup(tmp)
    set tmp=null
endfunction

I have this, but looking at the code I cringe from the performance hit.
 
True, that'd be less cpu intensive.
JASS:
function UnitsInRange takes group G real X,real Y,real R returns nothing
    local unit U=null
    local group tmp=CreateGroup()
    local real dx
    local real dy
    call GroupAddGroup(tmp,udg_LocusGroup)
    call GroupEnumUnitsInRange(G,X,Y,R)
    set R=R*R
    loop
        set U=FirstOfGroup(tmp)
        exitwhen U==null
        call GroupRemoveUnit(tmp,U)
        set dx=GetUnitX(U)-X
        set dy=GetUnitY(U)-Y
        if dx*dx+dy*dy<R then
            call GroupAddUnit(G,U)
        endif
        set U=null
    endloop
    call DestroyGroup(tmp)
    set tmp=null
    set U=null
endfunction
 
Status
Not open for further replies.
Top