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

Pick a point with no destructables in range X

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,338
Hi,


Suppose I wish to pick a random point in a region/rect.

I want to also enforce the following constraint:

(i) NO-DEST: There can be no destructables within range X of the point.

How would I do this check at each random point made?
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
You should search all rect horizontally by jumping 750 distance.Like this:

X X X X X


X X X X X


X X X X X


A loop for changing Y coordinate, and a loop inside that for change X coordinate.First X point to check must be at top left point of rect.


If your rect size is smaller than 750 than you only need to check Center of Rect.
 
Level 12
Joined
May 20, 2009
Messages
822
There does not appear to be a "Destructibles in # Range of (Point/Positon/Etc)" things in the editor. So this is an alternative

  • Untitled Trigger 004
    • Events
      • Time - Every # seconds of game time
    • Conditions
    • Actions
      • Set Point = (Random point in (Playable map area))
      • Destructible - Pick every destructible within # of Point and do (Actions)
        • Loop - Actions
          • Unit - Create 1 DUMMY_UNIT for Neutral Passive at (Position of (Picked destructible)) facing (Position of (Picked destructible))
          • Unit Group - Pick every unit in (Units within # of Point) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to DUMMY_UNIT
                • Then - Actions
                  • (Actions)
                • Else - Actions
                  • (Actions)
If any of the picks units within range of point are equal to the created unit type, then you do nothing. If the units are not, then you continue your function.

The Dummy Unit will have Locust by default, so that way the unit can be spawned ontop of destructibles with no problem.

The Dummy unit will also have no model and no shadow.
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
I just need the native that returns true whether a destructible is within X range of a point. The rest of the logic I'm fine with.
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
There's a function to enumerate destructables within a circle around a point. Just return true within enumeration, if there are no destructables, the enumeration won't execute anyway.

  • Zerstörbar - Pick every destructible within 256.00 of (Center of (Playable map area)) and do (Actions)
    • Schleifen - Aktionen
function EnumDestructablesInCircleBJ takes real radius, location loc, code actionFunc returns nothing
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
What do I use for the argument code actionFunc?

And what do you mean the enumeration won't execute if there are no destructables, does it crash?

JASS:
real myRange = N

location randomLoc = //some function that picks our random point

while EnumDestructablesInCircleBj(myRange, randomLoc, ???) then
  repick randomLoc

//now we've got our point

Please advise.
 
Level 12
Joined
Nov 3, 2013
Messages
989
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Picked destructible) Equal to No destructible
    • Then - Actions
      • do stuffs
    • Else - Actions
      • Skip remaining actions
or something I guess
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
Something like this should work
JASS:
library DestructableCheck

    globals
        private integer counter
        private real X
        private real Y
        private real R
    endglobals

    private function Enumerator takes nothing returns nothing
        local destructable d = GetEnumDestructable()
        local real x = GetDestructableX(d) - X
        local real y = GetDestructableY(d) - Y
        if (SquareRoot(x*x + y*y) <= R) then
            counter = counter + 1
        endif
    endfunction

    function DestructableWithinRange takes real x, real y, real radius returns boolean
        local rect r = Rect(x - radius, y - radius, x + radius, y + radius)
    
        counter = 0
        X = x
        Y = y
        R = radius
        
        call EnumDestructablesInRect(r, null, function Enumerator)
        call RemoveRect(r)
        r = null
        
        if (counter > 0) then
            return true
        endif
        return false
    endfunction

endlibrary
I thought it might be better to just avoid locations so I didn't use BJs.
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
I think I understand, but why do you have to do any distance checks?

How do enumerators work? Is it like a for-each statement of every destructable it finds?

e.g. wouldn't this work?

JASS:
globals
  private integer counter = 0
endglobals

private function enum takes nothing returns nothing
  set counter = counter + 1
endfunction

function check takes location whichLoc, real radius returns boolean
  call EnumDestuctablesInCircleBj(whichLoc, radius, enum)
  if counter > 0 then
     return true
  endif
  return false
endfunction
 
Status
Not open for further replies.
Top