1. The results for Texturing Contest #28 are out! Step by to congratulate our winners!
    Dismiss Notice
  2. Join us in our custom games night on Saturday, July 14. If you'd like to create a map for the night, check out the map challenge!
    Dismiss Notice
  3. Join in on Icon Contest #17 and show your interpretation of a legendary equipment set!
    Dismiss Notice
  4. We've created the Staff Job Openings thread. We're currently in need of icon, video production, and social/multimedia positions to be filled. Thank you!
    Dismiss Notice
  5. Music Contest #10 Retro is out! Join us for some retro/vintage fun!
    Dismiss Notice
  6. Don't be stagnant - embrace change! The time has come to evolve and join the Techtree Contest #12 - Evolution.
    Dismiss Notice
  7. On May 20th a new law about privacy and data processing comes into work in the EU. I am no lawyer and I need help figuring out if we comply and if not, what we must do about it. Please message me if you can provide any assistance. Read more. Ralle
    Dismiss Notice

turn rects into regions

Discussion in 'World Editor Help Zone' started by Death Adder, Jul 14, 2018 at 1:33 AM.

  1. Death Adder

    Death Adder

    Joined:
    Nov 3, 2013
    Messages:
    719
    Resources:
    0
    Resources:
    0
    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

    Code (vJASS):

    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: [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...
     
  2. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    784
    Resources:
    0
    Resources:
    0
    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:
    Code (vJASS):
    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).
     
  3. Death Adder

    Death Adder

    Joined:
    Nov 3, 2013
    Messages:
    719
    Resources:
    0
    Resources:
    0
    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.
     
  4. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    784
    Resources:
    0
    Resources:
    0
    GetTriggeringRegion()

    There's no way to get the rects though.
     
  5. Death Adder

    Death Adder

    Joined:
    Nov 3, 2013
    Messages:
    719
    Resources:
    0
    Resources:
    0
    I need to be able to make some region variable array or something, so I can loop through it.

    if GetTriggeringRegion() == regionVar[i] then
     
  6. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    24,460
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    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.
    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.
    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.
    Code (vJASS):

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

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    784
    Resources:
    0
    Resources:
    0
    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.
     
  8. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    24,460
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    I thought rects can contain fractions of cells because they represent rectangular area and not a collection of cells.