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

[JASS] Region to rect

Status
Not open for further replies.
Level 2
Joined
Jan 31, 2020
Messages
12
I've searched a lot but I could not find any answer for this.
All the answers are region is collection of map cells or it is collection of rects.

JASS:
local region r1 = GetTriggeringRegion()
local rect r2 = ???
How can I turn region to rect?
I don't know why none have asked this before.
All I want to do is
get GetTriggeringRegion()
turn into rect
make a group of units in rect
loop group

is there better way of doing this?
 
Level 39
Joined
Feb 27, 2007
Messages
4,994
When you create the region save a reference to the rect in a hashtable using the region as a key.

What specifically are you trying to accomplish? Unit enters region events can fire (presumably because of unit collision size) before the unit is actually in the region so they may not be reliable.
 
Level 2
Joined
Jan 31, 2020
Messages
12
I don't care triggering unit is in the region/out of region when unit get out/in.
As written above, All I want to do is
GetTriggeringRegion and turn it into rect, get all units in rect(don't care triggering unit is in or not), do some work on unit group.
 
Level 39
Joined
Feb 27, 2007
Messages
4,994
Your best solution is probably to manually check units in all of the rects with a fast periodic timer. When the unit you’re looking for shows up in one of these checks it has just entered the rect and you can do whatever you need to do with other units in that rect.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,511
  • Custom script: local rect r
  • For each (Integer A) from 1 to TotalRegions, do (Actions)
    • Loop - Actions
      • Custom script: set r = udg_Region[bj_forLoopAIndex]
      • Custom script: call SetRect(r, GetRectMinX(r) - 32., GetRectMinY(r) - 32., GetRectMaxX(r) + 32., GetRectMaxY(r) + 32.)
      • Custom script: set r = null
Unrelated to the issue but I figured I'd post this since it was brought up. This fixes issues with Regions and Unit Enters/Leaves Events and the "Region contains Unit/Point" Conditions.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,511
I don't know much about rects and I copied the code from a post from a while back but it seems to work. I have a couple of maps that I use this in and it fixed any issues I was having with triggers like these:
  • Leave Example
    • Events
      • Unit - A unit leaves SomeRegion <gen>
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in SomeRegion <gen>) and do (Actions)
        • Loop - Actions
          • Unit - Kill (Picked unit)
Without the rect fix this trigger would kill the leaving unit, despite the fact that the unit should no longer be in the region. With the rect fix this trigger will NOT kill the leaving unit. Same goes for the boolean to check if a Unit/Point is in a Region.

So I guess it corrects the rects because for whatever reason they're slightly off.
 
Level 18
Joined
Jan 1, 2018
Messages
728
I imagine it's because rect enter/leave events are based on collision size rather than absolute unit XY coordinates.
Collision size doesn't have anything to do with it.
JASS:
function TriggerRegisterEnterRectSimple takes trigger trig, rect r returns event
    local region rectRegion = CreateRegion()
    call RegionAddRect(rectRegion, r)
    return TriggerRegisterEnterRegion(trig, rectRegion, null)
endfunction
function TriggerRegisterLeaveRectSimple takes trigger trig, rect r returns event
    local region rectRegion = CreateRegion()
    call RegionAddRect(rectRegion, r)
    return TriggerRegisterLeaveRegion(trig, rectRegion, null)
endfunction

rects exist that cannot be represented by regions
I think you got your rects and regions mixed up.
 
Level 39
Joined
Feb 27, 2007
Messages
4,994
I’m not saying collision size is part of the BJ functions. I’m saying that internally it might check for the unit colliding/no longer colliding with the rect. The value of -32 seems to correlate with this but there’s no proof I’m aware of.
 
Status
Not open for further replies.
Top