Unused regions have boolean value (RegionUsed) set to false, used regions have that value set to true.
In trigger 2 he chooses random number as an index for the RegionUsed array. Then he checks if the boolean value of the array at that index is equal to true. If the value is
True, it means that region is already used, but he wants unused regions. So if the value is equal to true, he re-runs trigger 2 until he gets random unused region (until he gets an index for the array which contains False at that index).
I would use swapping method here tho. Meaning that I have an array of... say 10 regions called simply Regions[] - I will keep the number of regions in an integer variable called MaxIndex, so MaxIndex now contains value 10. I will choose random number between 1 and MaxIndex (in this case, it would be between 1 and 10). Once I chose a number, I would do my stuff with the region Region[chosen_index] and then I will swap that region with the last unused region - which is region indexed at MaxIndex (10) and decrease value of MaxIndex by 1. I would repeat this process each time I chose random region. What I would get is region array Region[] which contains unused regions until MaxIndex value and used region after MaxIndex value.
The advantage of this approach is that you always choose one of the available regions, while Ceday's approach will create an overhead the more used regions he has - imagine you have for example 10 regions. It's easy to choose the first few regions without any problem, but imagine you have for example 9 out of 10 used regions and the trigger he posted would have to randomly select the last region - that means he would have a 10% chance he chose that region, meaning that trigger would run way too many times.
Here are the triggers in question
-
Map Ini
-
Events
-
Conditions
-
Actions
-
Set MaxIndex = 4 //represents the maximum index for the Region array
-
Set Region[1] = *some region*
-
Set Region[2] = *some region*
-
Set Region[3] = *some region*
-
Set Region[4] = *some region*
-
Choose region
-
Events
-
Conditions
-
Actions
-
Set num = (Random integer number between 1 and MaxIndex)
-
Set reg = Region[num]
-
Set loc = (Center of reg)
-
Unit - Create 1 Footman for Player 1 (Red) at loc facing Default building facing degrees
-
Custom script: call RemoveLocation(udg_loc)
-
-------- The code below swaps Region[num] with Region[maxIndex] and decreases maxIndex --------
-
Set Region[num] = Region[MaxIndex]
-
Set Region[MaxIndex] = reg
-
Set MaxIndex = (MaxIndex - 1)