```
function SpawnAsteroid takes integer xc, integer yc, integer asize returns nothing
local location apos
local integer array atype
local integer dice
local unit tmpa //temporary asteroid
set atype[0] = 'h003'
set atype[1] = 'h002'
set atype[2] = 'h001'
set atype[3] = 'h000'
set apos = Location(I2R(xc), I2R(yc))
set dice = GetRandomInt(1,10)
if dice>7 and asize == 0 then
set tmpa = CreateUnitAtLoc( Player(8), atype[0], apos, bj_UNIT_FACING )
else
set tmpa = CreateUnitAtLoc( Player(8), atype[asize+1], apos, bj_UNIT_FACING )
endif
call SetUnitUserData(tmpa, udg_UID)
set udg_iron[udg_UID] = GetRandomInt(100,1000)
set udg_copper[udg_UID] = GetRandomInt(50,500)
set udg_gold[udg_UID] = GetRandomInt(10,100)
set udg_water[udg_UID] = GetRandomInt(1,10)
set udg_power[udg_UID] = 0
set udg_UID = udg_UID + 1
//call DisplayTextToForce( GetPlayersAll(),"ASteroid"+I2S(udg_UID)+": "+I2S(xc-startx())+", "+I2S(yc-starty()))
//call TriggerSleepAction(0.10)
//call DisplayTextToForce( GetPlayersAll(), "asteroid")
endfunction
function SetupGrid takes integer xi, integer yi returns nothing
local integer ltimes=5//loop times
local integer rots=0//grid x integer
local real rot=0
local real nring = 0.00 //next ring
local integer next = 0 //next (distance to next)
local integer dist
local integer dice
local integer dbug = 0
set dist = R2I(DistanceBetweenPoints(Location(xi, yi), Location(0, 0))/20000)
set dice = GetRandomInt(dist,10)
if dice>9 then
call SpawnAsteroid(xi,yi,0)
set nring = 128.00
elseif dice>7 then
call SpawnAsteroid(xi,yi,1)
set nring = 64.00
else
call SpawnAsteroid(xi,yi,2)
set nring = 32.00
endif
//call DisplayTextToForce( GetPlayersAll(), "afield, dist="+I2S(dist))
loop
set next = next + GetRandomInt(16,256)
set rot = I2R(360*next)/(2.00*PI()*nring)
//call DisplayTextToForce( GetPlayersAll(), "rot="+R2S(rot)+" nring="+R2S(nring)+" x="+R2S(Cos(rot)*nring))
//call TriggerSleepAction(0.10)
//call DisplayTextToForce( GetPlayersAll(), "next>circle="+I2S(next)+" > "+R2S(2*nring*PI()))
if I2R(next) > 2*nring*PI() then
set next = next - R2I(2*nring*PI())
set nring = nring + 128.00
set rots=rots+1
endif
set dice = GetRandomInt(1,100)
if dice>90 then
call SpawnAsteroid(R2I(Cos(rot)*nring)+xi, R2I(Sin(rot)*nring)+yi, GetRandomInt(1,2))
set next = next + 128
set dbug = dbug + 1
endif
exitwhen rots>ltimes
endloop
//call DisplayTextToForce( GetPlayersAll(), "asteroids planted: "+I2S(dbug) )
endfunction
function Regions takes nothing returns nothing
local integer xsi = 0 //x squares integer
local integer ysi = 0
local integer dice
local integer odds = 99
local integer reducer = 1
local integer maxunits
local integer array asteroid
local integer dbug = 0
set maxunits = udg_UID+200
set asteroid[0] = 'h000'
set asteroid[1] = 'h001'
set asteroid[2] = 'h002'
set asteroid[3] = 'h003'
loop
set dice = GetRandomInt(1,100)
if dice>90 then
call SetupGrid((xsi*grids())-startx(),(ysi*grids())-starty())
// set odds=99
//elseif odds>10 then //22 - 13 = 9
// set odds = odds - 1
endif
if ysi>squares() then
set ysi = 0
set xsi=xsi+1
endif
set ysi=ysi+1
exitwhen xsi>squares()
endloop
endfunction
//===========================================================================
function InitTrig_ARRC takes nothing returns nothing
set gg_trg_ARRC = CreateTrigger( )
call TriggerRegisterTimerEventSingle( gg_trg_ARRC, 1.00 )
call TriggerAddAction( gg_trg_ARRC, function Regions )
endfunction
```