• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Polar offset region detection

Status
Not open for further replies.

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,201
But there's maybe 1000 destructibles (trees) in my map, if I pick every destructible and check for the unit every 1 sec it's gonna lag horribly.
Which is why you use the "unit enters region" event for the region that is polar offset for each destructible you want to check.

The game should handle regions more efficiently by using scaling area data structures so the performance is likely better than periodically picking units could ever be.
 
Level 12
Joined
May 22, 2015
Messages
1,051
Is this check necessary for all units? If it is a certain ability, looping over the units with the ability and checking for trees in range might work.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,201
How can I check when a unit enters the region for each tree?
By putting a region for each tree and registering an entry event to a trigger. The code would look something like this.

JASS:
globals
    rect udg_rect // some rect goes here representing the area around a tree to register.
    region reg_region // not possible in GUI due to lack of region type, you only have rects in GUI
endglobals

function DesEnumRegionAddRect takes nothing returns nothing
    local destructible des = GetEnumDestructable()

    call MoveRectTo(udg_rect, GetDestructableX(des), GetDestructableY(des))
    call RegionAddRect(reg_region, udg_rect)

    set des = null
endfunction

function DestFilterTree takes nothing returns boolean
    local integer dest = GetDestructableTypeId(GetFilterDestructable())
    return dest == '0000' or dest == '0001' // add all tree tests here
endfunction

// use this function like TriggerRegisterEnterRectSimple, takes trigger and the rect area around each tree
function TriggerRegisterEnterRectNearTree takes trigger trig, rect r returns event
    set udg_rect = r
    set reg_region = CreateRegion()
    call EnumDestructablesInRect(bj_mapInitialPlayableArea, Condition(function DestFilterTree), function DesEnumRegionAddRect)
    return TriggerRegisterEnterRegion(trig, reg_region, null)
endfunction
I am unsure how many destructible it can iterate through but hopefully them all. Also I have no experience with regions so cannot be sure if this works (it should, but WC3 is strange at times).
 
Status
Not open for further replies.
Top