function ChangeStartingMine takes player p, integer newMine, boolean toTransfer returns nothing
local integer i = 0
local integer id
local real x
local real y
local real lx
local real ly
local real cDist
local real mDist = -1
local unit u
local unit fogu
local location l = GetStartLocationLoc(GetPlayerStartLocation(p))
local group g = CreateGroup()
set lx = GetLocationX(l)
set ly = GetLocationY(l)
call GroupEnumUnitsInRange(g, lx, ly, 2000, null)
loop
set fogu = FirstOfGroup(g)
set id = GetUnitTypeId(fogu)
if id == 'ngol' or id == 'ugol' or id == 'egol' then
set x = GetUnitX(fogu)
set y = GetUnitY(fogu)
set cDist = SquareRoot((lx - x)*(lx - x) + (ly - y)*(ly - y))
if (mDist < 0) or (cDist < mDist) then
set u = fogu
set mDist = cDist
endif
endif
exitwhen fogu == null
call GroupRemoveUnit(g, fogu)
endloop
if u != null then
if toTransfer then
call SetUnitOwner(u, p, true)
endif
set x = GetUnitX(u)
set y = GetUnitY(u)
call RemoveUnit(u)
if toTransfer then
call CreateUnit(p, newMine, x, y, 270)
else
call CreateUnit(Player(15), newMine, x, y, 270)
endif
endif
call RemoveLocation(l)
endfunction