HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Create Unit-Type In A Random Region That Has No Units?

01-19-2008, 09:28 PM#1
Brash
i have 650 small, evenly placed regions that is layed out much like a chess-board.


I have each region set to a region variable [integer a] 1-650

Now, my problem is i want to create 270 of this one kind of unit in 270 of the 650 regions, randomly picked... we'll say he is a Peon unit-type.

Also, there are existing Neutral Creeps on the map to concider, scattered randomly that could be within any given region at any time because they have the "wander" ability. I dont want those regions concidered that have these, or any units already there.

How do i create 1 unique Peon per 1 random region that has no units currently within it...

my problem is that when i do this, it sometimes randomly chooses the same region that already has a peon generated for it.

and when i try a different way to get 1 peon per 1 region it ends up selecting the regions in an orderly fashion .. which i dont want. this needs to be completely random.

Summary:
I want it so that out of 650 regions, 270 of them are randomly chosen to have 1 peon in each and no other unit at the time of creation.
01-19-2008, 09:56 PM#2
Ammorth
Check if the region has a unit in it. If it does, then get a new random region. Rinse and repeat.

You may want to use a boolean array so you don't have to keep checking if a unit exists (which is slower than a boolean check).

If this is related to your random number thread, then use that method instead.
01-20-2008, 06:10 AM#3
Brash
Here is what i have so far.. and it lags like hell because 650 + 270 * 650 = 176150 checks in one trig.. and it tends to stop on the 4th loop on the integera A on the 1-270 checks.

(Note: i switched the peons to barrels)
first i do:

Trigger:
Barrel Create
Collapse Events
Map initialization
Conditions
Collapse Actions
Collapse For each (Integer A) from 1 to 650, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Number of units in (Units in FootSwitch_Region[(Integer A)])) Equal to 0
Collapse Then - Actions
Set BarrelCount = (BarrelCount + 1)
Set Barrel_ReOrderRegion[BarrelCount] = FootSwitch_Region[(Integer A)]
Collapse Else - Actions
Do nothing
-------- -------------------------- --------
Collapse For each (Integer A) from 1 to 270, do (Actions)
Collapse Loop - Actions
Set BarrelCount = (Random integer number between 1 and BarrelCount)
Set Barrel_CreatePosi = (Center of Barrel_ReOrderRegion[BarrelCount])
Unit - Create 1 Barrel (Basic) for Player 11 (Dark Green) at Barrel_CreatePosi facing Default building facing degrees
Set BarrelCount = 0
Collapse For each (Integer B) from 1 to 650, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Number of units in (Units in FootSwitch_Region[(Integer B)])) Equal to 0
Collapse Then - Actions
Set BarrelCount = (BarrelCount + 1)
Set Barrel_ReOrderRegion[BarrelCount] = FootSwitch_Region[(Integer B)]
Collapse Else - Actions
Do Nothing
Custom script: call RemoveLocation( udg_Barrel_CreatePosi )

i do the rechecks with the integer b loop with the intention of it rechecking the newly created barrel (peon). yet it still seems to try to create in too orderly of a fashion and sometimes creates more than one in the same region.
i just dont get it!
01-20-2008, 06:14 AM#4
Tide-Arc Ephemera
I think you're hitting the operator limit and that could be hindering your trigger.