[JASS] Question About Rects and Regions

Level 17
Joined
Feb 11, 2011
Messages
1,860
Hi guys,

I am working on a map and I am having a problem. I have a region (made with the Region Palette), and when a unit enters the region I want to move the region to a random point within another region (Arena). It works when the unit enters the region the first time, but when it enters the newly moved region it doesn't trigger. Any ideas? What am I doing wrong? Here is my script:

  • Variable Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set AI_Search[1] = AI 1 Move <gen>
      • Set AI_Search[2] = AI 2 Move <gen>
      • Set AI_Search[3] = AI 3 Move <gen>
      • Set AI_Search[4] = AI 4 Move <gen>
  • AI Search New
    • Events
      • Unit - A unit enters AI 1 Move <gen>
      • Unit - A unit enters AI 2 Move <gen>
      • Unit - A unit enters AI 3 Move <gen>
      • Unit - A unit enters AI 4 Move <gen>
    • Conditions
    • Actions
      • Custom script: call AI_Search_New(GetTriggerUnit())
JASS:
function AI_Search_New takes unit u returns nothing
    local real x
    local real y
    set x = GetRandomReal(GetRectMinX(gg_rct_Arena), GetRectMaxX(gg_rct_Arena))
    set y = GetRandomReal(GetRectMinY(gg_rct_Arena), GetRectMaxY(gg_rct_Arena))
    call MoveRectTo(udg_AI_Search[GetConvertedPlayerId(GetOwningPlayer(u))], x, y) //Moving the owning player's region.
    set u = null
endfunction
To Simplify: I move the region 'belonging' to the owner of the entering unit (each player has their own region that triggers for their hero only).

If something isn't clear, ask me. Thanks!
 
Level 17
Joined
Jan 21, 2006
Messages
2,545
JASS:
function TriggerRegisterEnterRectSimple takes trigger trig, rect r returns event
    local region rectRegion = CreateRegion()
    call RegionAddRect(rectRegion, r)
    return TriggerRegisterEnterRegion(trig, rectRegion, null)
endfunction

This is what's called when you have a "Unit enters regions" event. Notice how it creates a region and uses an event with that.

When you move your rect to the new area (the arena) you will have to register the event again, because the first region will only be where you've created it at first (you only move the rect, not the region associated with it).

The API for regions is limited, though. You cannot move regions. You can only move rects. I suppose you may have to add events to a new trigger in order to detect when the new region has been entered.

You can add cells though. You could add both rects to the region and then determine which rect the unit is in to determine "which" region (they're the same region, in different places) the event should take place in.
 
Level 17
Joined
Feb 11, 2011
Messages
1,860
Hmmm, sounds complicated :/

Even if I try this, it doesn't work:
  • AI Search New
    • Events
      • Unit - A unit enters AI 1 Move <gen>
      • Unit - A unit enters AI 2 Move <gen>
      • Unit - A unit enters AI 3 Move <gen>
      • Unit - A unit enters AI 4 Move <gen>
    • Conditions
    • Actions
      • Set Temp_Point = (Random point in Arena <gen>)
      • Region - Center AI_Search[(Player number of (Triggering player))] on Temp_Point
      • Custom script: call RemoveLocation(udg_Temp_Point)
 
Level 17
Joined
Jan 21, 2006
Messages
2,545
The action:
  • Region - Center AI_Search[(Player number of (Triggering player))] on Temp_Point
Is moving the rect, not the region. Convert it to custom code to see. The region is created behind the scenes, you never actually have access to it.

Try doing something like this:
  • Actions
    • Region - Center AI_Search[(Player number of (Triggering player))] on (Center of (Playable map area))
    • Trigger - Add to (This trigger) the event (Unit - A unit enters AI_Search[(Player number of (Triggering player))])
Instead of using "Center of (Playable map area)" you would use your arena rect, and instead of "This trigger" you would use another trigger where you want to catch the event of the unit entering the new region.

----
Depending on how you use the region/rect, it may be easier for you to just have two separate rects. One of them would be the initial rect the player's unit has to enter and the other would be the randomly generated rect in the arena.
 
Top