• 🏆 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!

Need help in regions

Level 2
Joined
Nov 27, 2017
Messages
7
1699106283497.png


I wanna know how to make units spawn in the region without overlapping to the inner regions

So my area of battle has three regions: In which the outside has the weakest to the strongest to the center. However, it is common logic that the outermost region(weakest) will spawn any unit all over the map which means the regions inside are also included. I want that the weakest only spawn outside without spawning in the inner regions. I lack understanding in regions yet, especially triggers regarding regions so I want to ask here thanks :)

Additional: How to make circular regions? (if impossible, how to make multiple regions that can be treated as only one region (region 1,2,3 as only one region - like in spawning units))
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
So my area of battle has three regions: In which the outside has the weakest to the strongest to the center. However, it is common logic that the outermost region(weakest) will spawn any unit all over the map which means the regions inside are also included. I want that the weakest only spawn outside without spawning in the inner regions. I lack understanding in regions yet, especially triggers regarding regions so I want to ask here thanks :)
Simplest approach is to test if the random position is within the inner region (JASS/Lua Rect) and if so then generate another random position. As long as the inner regions are reasonably small compared to the outer spawn region, this should be pretty reliable. Even still I would recommend giving up after 20 or so tries and instead spawning in some default known proper but not random location. The fail condition should happen so infrequently that players would likely not notice.

The more complex approach is to break the outer region into multiple, non-overlapping, smaller regions that exclude the inner region. A region to spawn in is then chosen randomly based on the weight of their area, and then the position is selected randomly as normal. This is the most performant and reliable way to spawn a unit randomly under these conditions, but the logic to fragment the outer region is much more complex.

Additional: How to make circular regions? (if impossible, how to make multiple regions that can be treated as only one region (region 1,2,3 as only one region - like in spawning units))
Rect, as their name might indicate, are rectangular. Actual JASS/Lua regions seem to be a collection of map cells, so could represent a discretely sampled circle area. Actual regions do not natively support getting a random position within them, you would need to resort to the first described logic of itterative tries of points within a bounding box.

If you want to spawn units in a circular area then you can write your own logic to do so. Specifically you select a random angle and radius, and then correct the radius to compensate for the distortion of the radius/angle axis. This distortion compensation is fairly trivial to implement, something like R * sqrt(random(0.0, 1.0))), but is required for uniform probability distribution, otherwise points will bias towards the middle of the circle.

StarCraft II added native support to circular, and composite, regions, including logic shapes to remove areas from regions. The random point logic they used is the same as I described originally, they generate a random point in the bounds of the composite shape and then check if it is inside the region, repeating until either the point passes or a try limit is reached causing a null value to be returned.
 
Top