Here's a little something I threw together using everyone's ideas.
It requires the latest patch to open. If you can't open it and you're interested I can post the triggers here.
Basic idea:
I use a Hashtable to save information regarding the Player's Regions/Units.
-Each Player's Regions are saved in the Hashtable at 1 to X using their Player Number as the Key
-Each Player's Region State (Region is Occupied/Unoccupied) is saved in the Hashtable at -1 to -X using their Player Number as the Key
-Each Unit's current occupied Region # is saved in the Hashtable at 0 using the Unit as the Key
X = Total number of Regions in a Player's base
So using Kapharna's picture as an example and assuming that is Player
1's base:
The top left Region would be saved as 1 of
1 (Player Number) in the Hashtable
The Region to the right of it would be saved as 2 of
1 (Player Number) in the Hashtable
This pattern continues from left to right, top to bottom.
The bottom right corner Region would be saved as 64 of
1 (Player Number) in the Hashtable.
Whenever a Unit enters a Region I determine which Region it was and save that Region # to the unit.
A unit entering the top left Region of Player 1's base: Save 1 (Region #) as 0 of Key(Triggering Unit) in the Hashtable.
A unit entering the bottom right Region of Player 1's base: Save 64 (Region #) as 0 of Key(Triggering Unit) in the Hashtable
We can always save this data at the 0 Index in the Hashtable since we're saving this information directly to the Unit. This leaves room to use the other Indices for anything else you might like to save directly to the unit.
Duel Arenas:
When a Duel starts I Pick all units owned by a given player and then load those Unit's values in the Hashtable to get their Region #. With this information you can use Point offsets to determine where the units should be created inside the Arena. If a unit's loaded Region # is 1, then we know it was in the top left corner region, therefore when creating it in the Arena it should be in the top left corner as well.
Here's an example of me setting up Player 1's position in the Arena:
-
Actions
-
-------- Setup First Player --------
-
Set VariableSet R_Player = Player 1 (Red)
-
Set VariableSet PN = (Player number of R_Player)
-
-------- Setup points --------
-
Set VariableSet X = 0.00
-
Set VariableSet Y = 0.00
-
Set VariableSet TempPoints[1] = (Center of Duel Top <gen>)
-
For each (Integer R_Loop) from 2 to R_Count, do (Actions)
-
Loop - Actions
-
Set VariableSet X = (X + 128.00)
-
Set VariableSet TempPoints[R_Loop] = (TempPoints[1] offset by (X, Y))
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(R_Loop mod 3) Equal to 0
-
Then - Actions
-
Set VariableSet X = -128.00
-
Set VariableSet Y = (Y - 128.00)
-
Else - Actions
-
-------- Create units --------
-
Unit Group - Pick every unit in P_Units[PN] and do (Actions)
-
Loop - Actions
-
Set VariableSet R_RegionNumber = (Load 0 of (Key (Picked unit).) from R_Hashtable.)
-
Unit - Create 1 (Unit-type of (Picked unit)) for R_Player at TempPoints[R_RegionNumber] facing P_Angle[PN] degrees
-
-------- Clean up point leaks --------
-
For each (Integer R_Loop) from 1 to R_Count, do (Actions)
-
Loop - Actions
-
Custom script: call RemoveLocation (udg_TempPoints[udg_R_Loop])
I'm using a 3x3 setup in my map, so there's
9 (
R_Count) Regions in total per Player's base . That's why I loop from 2 to R_Count (9), and I skip 1 in the Loop since that's the starting point which is already set beforehand. Note that P_Angle is a Real variable that is set for each Player, this determines the Angle that the player's units are facing. This way opposing units in the Arena spawn facing one another.
This line here may confuse some: (R_Loop mod 3) Equal to 0
This is modulo, and it can be used to basically check if a number is a multiple of another number. So i'm checking if R_Loop is a multiple of 3, and if it is, I adjust my X/Y coordinates accordingly since we're now dropping down a Row.
Unit Placement:
My setup is a bit different than Blood Tournament, which I did on purpose. In Blood Tournament, you create Buildings with your Worker inside of your Base, which are then referenced and "recreated" in the Arena as normal Units.
In my example, I figured why use Buildings and have to create an extra version of each Unit (Building Form/Unit Form) when you can just use the Unit form for everything. So you'll see that I made it very simple, just grab one of your units and right click (give it a move order) to some tile in your base, and if that tile is unoccupied, the unit will instantly move there and occupy it.
I didn't bother making a system for creating these Units, but you could easily come up with something. For example, you buy your Units from a Barracks, which moves them to a Unit Pool area. From there, you can select them and right click where you want to place them. This would be A LOT more hands on in my opinion, and would make moving/adjusting the units positions extremely easy.