• 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.

how to pick random unit from region?

Status
Not open for further replies.
Level 3
Joined
Aug 4, 2013
Messages
55
this may help, but this trigger has point leak

  • Cth
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Random 1 units from (Units in (Playable map area))) and do (Actions)
        • Loop - Actions
          • Unit - Kill (Triggering unit)
 
Except for the event that he has in the above trigger that will work for selecting a random unit from a region.
Also this Unit - Kill (Triggering unit) needs to be changed to picked unit.

  • Untitled Trigger 003
    • Events
    • Conditions
    • Actions
      • Set tempGroup = (Units in (Playable map area))
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Random 1 units from tempGroup) and do (Actions)
        • Loop - Actions
          • Unit - Kill (Picked unit)
      • Custom script: call DestroyGroup( udg_tempGroup)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
This only applies to region in the GUI context (JASS Rect). I do not think it is possible to determine units inside a JASS Region efficiently.

The process for getting a random unit in a JASS Region is considerably slower and more complex.
1. Rough enumeration of units in region. This can be as simple as all units on the map but the best fit would be all units in either the smallest bounding circle or Rect that fully contains the Region.
2. Filter rough enumeration to produce group of units in Region. Test each unit if it is inside the Region, discard if not. Best done using destructive loops due to the destructive nature of this filter process.
3. Apply random victim algorithm on Group of units in Region to produce Group of random units. GUI has one, although it may or may not leak.

Since most Region objects are constructed from a simple Rect, try and stick with Rect enumeration for maximum speed.
 
Status
Not open for further replies.
Top