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

turn rects into regions

Status
Not open for further replies.
Level 12
Joined
Nov 3, 2013
Messages
989
Is there some simple way to just turn pre-placed rects in the world editor into regions?

Or a proper event response for rects like GetTriggeringRegion()?

I'm not using vJass so I can't declare globals without GUI


Also, the TriggerRegisterEnterRectSimple() seems to be a region, but it's local, so I don't think I can reference it... Right? Honestly my head just starts spinning

JASS:
function TriggerRegisterEnterRectSimple takes trigger trig, rect r returns event
    local region rectRegion = CreateRegion()
    call RegionAddRect(rectRegion, r)
    return TriggerRegisterEnterRegion(trig, rectRegion, null)
endfunction

So what I think I want is to make global region variables for the pre-placed rects (unless there's some event for entering a rect, but it doesn't seem like it), but I can't do it without vJass?

Basically I'm having the same problem as this: [code=jass] - Detecting Entered Region


Edit: Maybe I can make my own event or something? And while I can't make globals in jass I can use that other thing that run at the beginning, which is pretty much globals, but not??? x) Maybe it's going to be simple later when I'm not as tired...
 
Level 39
Joined
Feb 27, 2007
Messages
4,994
A region is a collection of rects. Imagine a rect is a state in the US and the "register" event you're using runs whenever a unit enters "the united states". All that BJ does is make a new region "United States - Nevada" and add the rect to that region, then register units entering the region. Maybe a bad analogy.

Regardless, what you can do is:
JASS:
local region TrigRegion = CreateRegion()
local integer i = 0

loop
    call RegionAddRect(TrigRegion, RegionsToUse[i])
    exitwhen i>MAX_REGIONS
    set i = i+1
endloop

call TriggerRegisterEnterRegion(trig, TrigRegion, null)
And now all the rects will triggger 1 event together whenever a unit enters any of them. repeat for each group of rects. The rects for 1 region event do NOT have to be contiguous (they can be on opposite corners of the map).
 
Level 12
Joined
Nov 3, 2013
Messages
989
A region is a collection of rects. Imagine a rect is a state in the US and the "register" event you're using runs whenever a unit enters "the united states". All that BJ does is make a new region "United States - Nevada" and add the rect to that region, then register units entering the region. Maybe a bad analogy.

Regardless, what you can do is:
JASS:
local region TrigRegion = CreateRegion()
local integer i = 0

loop
    call RegionAddRect(TrigRegion, RegionsToUse[i])
    exitwhen i>MAX_REGIONS
    set i = i+1
endloop

call TriggerRegisterEnterRegion(trig, TrigRegion, null)
And now all the rects will triggger 1 event together whenever a unit enters any of them. repeat for each group of rects. The rects for 1 region event do NOT have to be contiguous (they can be on opposite corners of the map).
Oh yeah, I guess I didn't make myself clear what I wanted.

I want to be able to tell which rect was entered, which is why I want to turn each rect into separate regions, not combine them all into one region.


Basically, I've got an old map I made long ago, in it I made several triggers of "a unit enters a region" and then order the units to attack move to the next region. Basically they've all got the same event (but different rects/regions) and the same actions as well (but different destinations).

So I want to combine them all together into a single trigger, detect which region was entered, and then loop through an array or use a hashtable to find where next to send the entering unit.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
I'm not using vJass so I can't declare globals without GUI
I suggest you just use vJASS. Especially seeing how it will be natively supported by World Edit starting with version 1.30 scheduled for release soonTM.
Also, the
TriggerRegisterEnterRectSimple()
seems to be a region, but it's local, so I don't think I can reference it... Right? Honestly my head just starts spinning
Yes you can reference it with GetTriggeringRegion(). However you probably will not get much sense from it as the region is not coupled to rects in any way.
A region is a collection of rects.
No it is not? A region is a collection of map cells. A region can be bulk filled from cells approximately inside a rect (there is an off by 1 error if I recall).

Anyway @Death Adder

A solution to this without using vJASS is to use hash tables.
JASS:
native SaveRegionHandle takes hashtable table,integer parentKey,integer childKey,region whichRegion returns boolean
native LoadRegionHandle takes hashtable table,integer parentKey,integer childKey returns region
One can make a hashtable into a global storage space for objects. As long as both parent and child keys are structured in such a way that the objects can be accessed usefully.

Of course this is not even required... One can use a hashtable to map a rect to a region's handle ID when creating the region. This way you do not even need to store a global reference to the region. When the trigger fires you get the triggering region and look up the rect used to construct it using the hashtable and the region's handle ID. Hashtable natives are fast, executing only 2-3 times slower than array lookup under normal conditions.
 
Level 39
Joined
Feb 27, 2007
Messages
4,994
If a region is a collection of map cells and a rect is an area that contains map cells... then how is a region not a collection of rects? It's a little roundabout because regions are 32x32 min and can't partially contain cells but they are composed of the same things.
 
Status
Not open for further replies.
Top