[Trigger] Locust Ability and pick all units

Status
Not open for further replies.
native GroupEnumUnitsOfPlayer takes group whichGroup, player whichPlayer, boolexpr filter returns nothing
So it will enumerate all units that a player has, filtered throught the boolexpr. So I guess put a function there that checks for unit type and whether the level of 'Aloc' on them is > 0. If you also need to check for distance, use IsUnitInRange or IsUnitInRangeXY.
 
Last edited:
Level 44
Joined
Feb 27, 2007
Messages
5,474
This works. Brute force though.
JASS:
library LocustUnits initializer init //has optional GroupUtils
    globals
        private boolexpr filt
        private integer ID = 'Aloc'
    endglobals
  
    private function IsLocust takes nothing returns boolean
        return GetUnitAbilityLevel(GetFilterUnit(), ID) > 0
    endfunction
  
    function GroupAddLocustUnitsOfPlayer takes group TarG, player TarP returns nothing
        call GroupEnumUnitsOfPlayer(TarG, TarP, filt)
    endfunction
  
    function GroupAddLocustUnitsInRange takes group TarG, real TarX, real TarY, real R, boolexpr someFilter returns nothing
        local integer i = -1
        local unit u
        local group g
        local real x
        local real y
        set R = R*R
      
        static if LIBRARY_GroupUtils then
            set g = NewGroup()
        else
            set g = CreateGroup()
        endif
      
        loop
            set i = i+1
            exitwhen i > 15
            call GroupEnumUnitsOfPlayer(g,Player(i),filt)
          
            loop
                set u = FirstOfGroup(g)
                exitwhen u == null
                call GroupRemoveUnit(g,u)
              
                set x = TarX-GetUnitX(u)
                set y = TarY-GetUnitY(u)
                if x*x+y*y <= R then
                    call GroupAddUnit(TarG,u)
                endif
            endloop
        endloop

        static if LIBRARY_GroupUtils then
            call ReleaseGroup(g)
        else
            call DestroyGroup(g)
        endif
        set g = null
        set u = null
    endfunction
  
    private function init takes nothing returns nothing
        set filt = Filter(function IsLocust)
    endfunction
endlibrary
 
Level 11
Joined
May 16, 2016
Messages
730
This works. Brute force though.
Thx, but what about this way:
I made dummy group on map initializating and clean it.
When dummy spawns I added it into dummy group.

Does periodic event with "pick every unit in dummy group" causes leaks, if I create this group only once in the map initiliaztion?
I mean usually you use "Set group = blah blah" then "pick every unit in group" then "destroy the group" then repeat, but here only trigger "pick every unit in dummy group" with no "Set = group" and "Destroy group" (of course if locust unit dies I remove it from dummy group)
 
Level 44
Joined
Feb 27, 2007
Messages
5,474
Thx, but what about this way:
I made dummy group on map initializating and clean it.
When dummy spawns I added it into dummy group.

Does periodic event with "pick every unit in dummy group" causes leaks, if I create this group only once in the map initiliaztion?
I mean usually you use "Set group = blah blah" then "pick every unit in group" then "destroy the group" then repeat, but here only trigger "pick every unit in dummy group" with no "Set = group" and "Destroy group" (of course if locust unit dies I remove it from dummy group)
No reason you can't do it that way either, but you will eventually have phantom units in the group if you don't clear it periodically and are using RemoveUnit(). Really just preference unless you're using this functionality a lot. A 'leak' is by definition a bit of memory allocated to the map itself by your computer and it only becomes a leak if it's something you don't intend to keep around for a long time. In this case you'd want the group to be around so you can keep checking all of its units... so it's not really a 'leak'.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,273
If you keep track of a single dummy there is no need for a group, a unit can be referenced directly.

Locusts are exempt from area searches. It appears that the mechanics of locust deregisters them from the game worlds positional structure (probably a quad tree) so they will not show up there. I believe the same applies to hidden units, which share several properties with locust units.

Locust units will still show up in other kinds of non positional searches, such as units owned by player. They also interact with unit groups like all other units do.
 
Status
Not open for further replies.
Top