function LevelSetup()
-- Set Global Values
if IsiOS() then
Globals():Get("Game"):Set("Asteroids",0)
Globals():Get("Asteroids"):Set("MinSendDistance",0.5)
Globals():Get("Asteroids"):Set("MaxSendDistance",0.5)
Globals():Get("Game"):Set("EnemyFactionsMin",1)
Globals():Get("Game"):Set("EnemyFactionsMax",1)
Globals():Get("Game"):Set("GreysProbability",0)
Globals():Get("AI"):Set("GraceTimer",99999)
Globals():Get("Structures"):Set("FlowerProbability",0.015)
Globals():Get("Asteroids"):Set("MinCoreHealth",150)
Globals():Get("Asteroids"):Set("MaxCoreHealth",300)
Globals():Get("Asteroids"):Set("SpawnCap",100)
Globals():Get("Asteroids"):Set("SeedlingCap",5000)
else
Globals.G.Asteroids=(0)
Globals.Asteroids.MinSendDistance=0.5
Globals.Asteroids.MaxSendDistance=0.5
Globals.G.EnemyFactionsMin=(1)
Globals.G.EnemyFactionsMax=(1)
Globals.G.GreysProbability=0
Globals.AI.GraceTimer=(99999)
Globals.Structures.FlowerProbability=(0.015)
Globals.Asteroids.MinCoreHealth=150
Globals.Asteroids.MaxCoreHealth=300
Globals.Asteroids.SpawnCap=100
Globals.Asteroids.SeedlingCap=5000
end
t = 1600
coordx = {}
coordy = {}
roidradius = {}
roidnumber = 31
for i=0,roidnumber do
x = math.cos(t) * t
y = math.sin(t) * t
s = math.random(3,10) / 10
e = math.random(4,10) / 10
sp = math.random(5,10) / 10
roidradius[i] = 175 + ((i / 21) * (500 * ((s + e + sp) / 3)))
a = AddAsteroidWithAttribs(x,y,e,s,sp)
a.Owner = 2
a.TreeCap = 4
a:SetRadius(roidradius[i])
a:Reveal(2)
a:Reveal(1)
a.Moveable = False
coordx[i] = x
coordy[i] = y
t = t + 294.5
a.SendDistance = (roidradius[i] * 7) + 1500
end
a = GetAsteroid(roidnumber - 16)
a:AddSeedlings(150)
a = GetAsteroid(0)
a.Owner = 1
a.Moveable = False
a = GetAsteroid(27)
a.Owner = 1
a.Moveable = False
s = a:AddDefenseTree()
s:LevelUp()
s:LevelUp()
s:LevelUp()
s = a:AddDysonTree()
s:LevelUp()
s:LevelUp()
s:LevelUp()
--f = s:AddFlower()
a:AddSeedlings(75)
SetCameraZoomNow(0.01)
rcolour = 0
SetBackdropColour(0,0,0)
endfinal = false
finality = false
dangertimer = {}
for dset = 0,roidnumber do
dangertimer[dset] = GetGameTime() - 90
end
danger = {}
torchlit = {}
constructionmetric = {}
gathermetric = {}
gatherexists = 0
gatherpoint = GetAsteroid(0)
end
function LevelLogic()
SetCameraPosition(((coordx[27] * -1) + 500),((coordy[27] * -1) + 500))
SetCameraZoom(4.8)
GetAsteroid(0):ChangeOwner(2)
purgetimer = GetGameTime()
while GameRunning() do
if rcolour > 0 then
rcolour = rcolour - 1
end
SetBackdropColour(rcolour,0,0)
if GetEmpire(1):GetNumOwnedAsteroids() == 0 then
Quit(false)
end
if GetEmpire(2):GetNumOwnedAsteroids() == 0 then
Pause()
MessageBox("you have won.")
WaitDialog()
Unpause()
Quit(true)
end
--AI
checkedroid = GetAI(2):GetRandomAsteroid()
if GetGameTime() > purgetimer + 35 then
purgetimer = 0
end
-- First, find out which asteroids are close enough to travel in 1 jump, and
traversable = {}
pathsavailable = 0
attackable = {}
attackpaths = 0
actiontaken = 0
increasemetricvote = 1
increasegathermetricvote = 1
confirmedzero = 0
confirmedgatherpoint = 0
if GetEmpire(2):OwnsAsteroidID(checkedroid.ID) then
if checkedroid:GetNumSeedlings(1) == 0 and checkedroid:GetNumSeedlings(2) > 5 then
for minecheck = 0,roidnumber do
if GetEmpire(2):OwnsAsteroidID(minecheck) == true and GetAsteroid(minecheck):GetNumMines(1) > 0 and checkedroid:GetNumMines(1) == 0 then
checkedroid:SendSeedlingsToTarget(2,checkedroid:GetNumSeedlings(2),GetAsteroid(minecheck))
end
end
end
for u = 0,roidnumber do
if GetAsteroid(u) ~= checkedroid then
-- only learn about this asteroid if it's not the one being checked
-- can we send seeds to this roid from the checked one?
if (GetAsteroid(checkedroid.ID):GetSendDistance() + roidradius[u]) > math.sqrt(((coordx[u] - coordx[checkedroid.ID])^2) + ((coordy[u] - coordy[checkedroid.ID])^2)) then
-- we can ! Now is this a friendly path or an attackable path?
if GetEmpire(1):OwnsAsteroidID(u) == true or GetAsteroid(u):GetNumSeedlings(1) > 10 and GetAsteroid(u):GetNumTrees() == 0 then
attackable[attackpaths] = GetAsteroid(u)
attackpaths = attackpaths + 1
-- moar aggression ! advantage pressing, etc
if checkedroid:GetNumSeedlings(2) > 120 and GetAsteroid(u):GetNumSeedlings(1) < (checkedroid:GetNumSeedlings(2) / 2) then
checkedroid:SendSeedlingsToTarget(2,checkedroid:GetNumSeedlings(2),GetAsteroid(u))
if rcolour < 105 then
rcolour = rcolour + 150
end
end
end
if GetAI(2):OwnsAsteroidID(u) == true then
traversable[pathsavailable] = GetAsteroid(u)
pathsavailable = pathsavailable + 1
end
end
-- ok, this roid is not in range for us.
end
-- ok, we were trying to check ourselves.
end
-- end of neighbour-checking sequence
-- end of metric checking sequence
else
torchlit[checkedroid.ID] = nil
constructionmetric[checkedroid.ID] = nil
gathermetric[checkedroid.ID] = nil
end
-- we have selected "checkedroid" for checking. We must find out all we can about the asteroid and it's surroundings, and act appropriately.
if GetAI(2):OwnsAsteroidID(checkedroid.ID) == true and checkedroid:GetNumMines(1) > 0 then
-- do buggerysquat.
elseif GetAI(2):OwnsAsteroidID(checkedroid.ID) == true then
-- this roid is ours ! :>
if pathsavailable == 0 then
-- Orphan Control
boltfriendly = GetEmpire(2):GetRandomAsteroid()
letsgo = 0
for iii = 0,attackpaths do
if attackable[iii] ~= nil then
letsgo = letsgo + (attackable[iii]:GetNumSeedlings(1))
end
end
if letsgo > checkedroid:GetNumSeedlings(2) and checkedroid:GetNumSeedlings(2) > 10 and checkedroid:GetNumSeedlings(2) < 39 then
checkedroid:SendSeedlingsToTarget(2,checkedroid:GetNumSeedlings(2),boltfriendly)
elseif letsgo < checkedroid:GetNumSeedlings(2) and checkedroid:GetNumSeedlings(2) > (39 + (attackable[0]:GetNumDysonTrees() * 5) + (attackable[0]:GetNumDefenseTrees() * 15)) then
checkedroid:SendSeedlingsToTarget(2,checkedroid:GetNumSeedlings(2),attackable[0])
if rcolour < 105 then
rcolour = rcolour + 150
end
elseif attackable[0]:GetNumSeedlings(2) > 5 then
checkedroid:SendSeedlingsToTarget(2,checkedroid:GetNumSeedlings(2),attackable[0])
end
end
-- how many player seedlings are here?
-- more than what we have, and enough to be dangerous. Also, we do have at least 1 tree here, right?
if checkedroid:GetNumSeedlings(2) < checkedroid:GetNumSeedlings(1) and checkedroid:GetNumSeedlings(1) > 10 and checkedroid:GetNumTrees() > 0 then
-- *** WE OWN THIS ASTEROID, THE ENEMY OUTNUMBER US. WE HAVE AT LEAST ONE TREE HERE. We are under attack. torchmetric 0! ***
torchlit[checkedroid.ID] = 0
-- ***
-- elseif checkedroid:GetNumSeedlings(2) < checkedroid:GetNumSeedlings(1) and checkedroid:GetNumSeedlings(1) > 10 and checkedroid:GetNumTrees() == 0 then
-- *** ITS A FALSE ALARM....but dont try to build here unless the player leaves. ***
--torchlit[checkedroid.ID] = nil
--constructionmetric[checkedroid.ID] = nil
-- but once we get a bit more powerful, we can have a crack at it :>
-- if purgetimer == 0 then
-- purgetimer = GetGameTime() + 30
-- end
-- if GetGameTime() > purgetimer then
-- torchlit[checkedroid.ID] = 0
--for purge = 0,roidnumber do
-- if GetEmpire(2):OwnsAsteroidID(purge) == true and torchlit[purge] == nil and GetGameTime() > purgetimer + 45 then
--GetAsteroid(purge):SendSeedlingsToTarget(2,checkedroid:GetNumSeedlings(1),checkedroid)
-- if rcolour < 105 then
-- rcolour = rcolour + 150
-- end
-- end
-- end
-- purgetimer = 0
-- end
-- ***
end
-- more than zero but less than what we have
if checkedroid:GetNumSeedlings(1) > 0 and checkedroid:GetNumSeedlings(2) > checkedroid:GetNumSeedlings(1) then
-- *** WE OWN THIS ASTEROID, THERE ARE ENEMIES BUT WE OUTNUMBER THEM. Not elligible for sending reinforcements to other asteroids, but not in serious danger either. ***
-- ***
end
-- No enemies here at all.
if checkedroid:GetNumSeedlings(1) < 1 then
-- how many of our seedlings are here?
if checkedroid:GetNumSeedlings(2) > 1 then
-- 1 or more
--how many trees are here?
if checkedroid:GetNumTrees() < 4 and checkedroid:GetNumSeedlings(2) > 9 then
-- less than four trees
-- *** WE OWN THIS ASTEROID, THERE ARE NO ENEMIES HERE. WE HAVE AT LEAST 10 SEEDLINGS AND LESS THAN 4 TREES. Plant a tree. ***
-- but... is the enemy building up a force nearby, ready to take our freshly built trees..?
danger[checkedroid.ID] = false
for ooo = 0,roidnumber do
if GetEmpire(1):OwnsAsteroidID(ooo) and GetAsteroid(ooo):GetSendDistance() > math.sqrt(((coordx[ooo] - coordx[checkedroid.ID])^2) + ((coordy[ooo] - coordy[checkedroid.ID])^2)) then
if GetAsteroid(ooo):GetNumSeedlings(1) > 35 then
danger[checkedroid.ID] = true
dangertimer[checkedroid.ID] = GetGameTime()
end
end
end
if danger[checkedroid.ID] == true and checkedroid:GetNumSeedlings(2) > 15 then
checkedroid:PlantDysonTree(2)
elseif danger[checkedroid.ID] == false and GetGameTime() > dangertimer[checkedroid.ID] + 30 then
checkedroid:PlantDysonTree(2)
end
-- ***
elseif checkedroid:GetNumTrees() == 4 then
-- four trees. ELLIGIBLE FOR SENDING REINFORCEMENTS!
if constructionmetric[checkedroid.ID] == 0 then
-- we just built the last tree. now we should stop advertising to neighbours that we need more seedlings for construction.
constructionmetric[checkedroid.ID] = nil
end
-- is my torch metric nil?
if torchlit[checkedroid.ID] ~= nil then
-- no, my torch metric is not Nil.
-- is my torch metric 0? Cause, like, I don't have any enemies orbiting me dudez...
if torchlit[checkedroid.ID] == 0 then
-- *** ok, so my torch metric is 0 but there are no enemies here. Switch all torches off....if other roids are under attack they will just switch theirs on again straight away. ***
-- *** this step is needed to prevent the rest of the torch metrics from spiralling upward out of control. ***
for g = 0,roidnumber do
torchlit[g] = nil
end
-- ***
else
-- so my torch IS lit, but it's value is NOT zero. checkedroid is not nil and not 0.
totm = true
for ooo = 0,pathsavailable do
if traversable[ooo] ~= nil then
trav = traversable[ooo]
hopIDint = trav.ID
if torchlit[hopIDint] == 0 and GetGameTime() < 180 then
for emerg = 0,roidnumber do
if GetEmpire(2):OwnsAsteroidID(emerg) == true then
GetAsteroid(emerg):SendSeedlingsToTarget(2,GetAsteroid(emerg):GetNumSeedlings(2),traversable[ooo])
end
end
totm = false
elseif torchlit[hopIDint] == 0 then
-- *** WE HAVE FOUND A NEIGHBOUR THAT HAS A ROUTE TO AN ASTEROID IN NEED OF DEFENCE. Send seedlings ***
if GetAsteroid(hopIDint):GetNumSeedlings(1) < 10 then
checkedroid:SendSeedlingsToTarget(2,checkedroid:GetNumSeedlings(2),traversable[ooo])
elseif GetAsteroid(hopIDint):GetNumSeedlings(2) > GetAsteroid(hopIDint):GetNumSeedlings(1) * 0.6 then
checkedroid:SendSeedlingsToTarget(2,checkedroid:GetNumSeedlings(2),traversable[ooo])
elseif checkedroid:GetNumSeedlings(2) > (GetEmpire(2).NumSeedlings / 20) then
checkedroid:SendSeedlingsToTarget(2,checkedroid:GetNumSeedlings(2),traversable[ooo])
end
totm = false
torchlit[checkedroid.ID] = 1
-- elseif torchlit[checkedroid.ID] == nil then
-- totm = false
-- torchlit[checkedroid.ID] = torchlit[hopIDint] + 1
-- shortestpath = hopIDint
elseif torchlit[hopIDint] == nil then
-- do nothing, maybe there's no more attack and the metric should be turned off.
-- my torch metric is already non-nil, so set mine to be his + 1 if he has a shorter path than me.
elseif torchlit[hopIDint] < torchlit[checkedroid.ID] - 1 then
totm = false
torchlit[checkedroid.ID] = torchlit[hopIDint] + 1
shortestpath = hopIDint
checkedroid:SendSeedlingsToTarget(2,checkedroid:GetNumSeedlings(2),traversable[ooo])
elseif torchlit[hopIDint] == torchlit[checkedroid.ID] - 1 then
totm = false
torchlit[checkedroid.ID] = torchlit[hopIDint] + 1
shortestpath = hopIDint
checkedroid:SendSeedlingsToTarget(2,checkedroid:GetNumSeedlings(2),traversable[ooo])
end
end
end
-- *** WE OWN THIS ASTEROID. THERE ARE NO ENEMIES HERE. WE HAVE AT LEAST 10 SEEDLINGS AND MAXIMUM TREES. OUR TORCH METRIC INDICATES ***
-- *** THAT A NEARBY ASTEROID REQUIRES SEEDLINGS FOR DEFENSE. Find a neighbour with the lower metric and send 10 seedlings there. ***
end
elseif torchlit[checkedroid.ID] == nil then
-- yes my torch metric is nil, now lets see if any neighbours have a torch metric of 0..
totm = true
for ooo = 0,pathsavailable do
if traversable[ooo] ~= nil then
trav = traversable[ooo]
hopIDint = trav.ID
if torchlit[hopIDint] == 0 then
-- *** WE HAVE FOUND A NEIGHBOUR THAT NEEDS MORE SEEDS TO DEFEND WITH. Send 10 seedlings, or more if we have them available. ***
checkedroid:SendSeedlingsToTarget(2,((checkedroid:GetNumSeedlings(2)/pathsavailable) + 10),traversable[ooo])
totm = false
torchlit[checkedroid.ID] = 1
elseif torchlit[hopIDint] ~= nil then
if torchlit[hopIDint] > 0 then
-- seedlings needed in this direction!
-- my torch metric is nil at the moment, so set it to his + 1.
if torchlit[checkedroid.ID] == nil then
totm = false
torchlit[checkedroid.ID] = torchlit[hopIDint] + 1
shortestpath = hopIDint
end
-- my torch metric is already non-nil, so set mine to be his + 1 if he has a shorter path than me.
if torchlit[hopIDint] < torchlit[checkedroid.ID] - 1 then
totm = false
torchlit[checkedroid.ID] = torchlit[hopIDint] + 1
shortestpath = hopIDint
end
end
end
end
end
-- send seeds along the shortest torch path
if torchlit[checkedroid.ID] ~= nil then
if torchlit[checkedroid.ID] > 1 then
checkedroid:SendSeedlingsToTarget(2,((checkedroid:GetNumSeedlings(2)/pathsavailable) + 10),GetAsteroid(shortestpath))
end
end
if totm == true and torchlit[checkedroid.ID] ~= nil then
torchlit[checkedroid.ID] = nil
end
-- check if we are still under attack on any asteroids
stillattacked = false
for o = 0,roidnumber do
if GetAsteroid(o):GetNumTrees() > 0 and GetAI(2):OwnsAsteroidID(o) and GetAsteroid(o):GetNumSeedlings(1) > 1 then
stillattacked = true
end
end
if stillattacked == false then
for l = 0,roidnumber do
torchlit[l] = nil
end
end
-- yes, my torch metric is Nil and so is all my neighbours' - check my construction metric next.
-- turn off construction metric
tocm = true
for cc = 0,pathsavailable do
if traversable[cc] ~= nil then
trav = traversable[cc]
hopIDint = trav.ID
if constructionmetric[hopIDint] == 0 and danger[checkedroid.ID] == false and GetGameTime() > (dangertimer[checkedroid.ID] + 90) and GetAsteroid(hopIDint):GetNumSeedlings(1) < 8 then
-- *** WE HAVE FOUND A NEIGHBOUR THAT NEEDS MORE SEEDS TO BUILD WITH. Send 10 seedlings, or more if we have them available. ***
checkedroid:SendSeedlingsToTarget(2,((checkedroid:GetNumSeedlings(2)/pathsavailable) + 10),traversable[cc])
tocm = false
constructionmetric[checkedroid.ID] = 1
elseif danger[checkedroid.ID] == true or GetGameTime() < (dangertimer[checkedroid.ID] + 90) then
-- *** WAIT A BIT... THERE'S STILL A BIG FORCE NEARBY ***
tocm = false
constructionmetric[checkedroid.ID] = 1
elseif constructionmetric[hopIDint] ~= nil then
if constructionmetric[hopIDint] > 0 then
-- seedlings needed in this direction!
-- my construction metric is nil at the moment, so set it to his + 1.
if constructionmetric[checkedroid.ID] == nil then
tocm = false
constructionmetric[checkedroid.ID] = constructionmetric[hopIDint] + 1
shortestpath = hopIDint
end
-- my construction metric is already non-nil, so set mine to be his + 1 if he has a shorter path than me.
if constructionmetric[hopIDint] < constructionmetric[checkedroid.ID] - 1 then
tocm = false
constructionmetric[checkedroid.ID] = constructionmetric[hopIDint] + 1
shortestpath = hopIDint
end
end
end
end
end
-- send seeds along the shortest construction path
if constructionmetric[checkedroid.ID] ~= nil then
if constructionmetric[checkedroid.ID] > 1 then
checkedroid:SendSeedlingsToTarget(2,((checkedroid:GetNumSeedlings(2)/pathsavailable) + 10),GetAsteroid(shortestpath))
end
end
if tocm == true and constructionmetric[checkedroid.ID] ~= nil then
constructionmetric[checkedroid.ID] = nil
end
-- check if we are finished building trees on all asteroids
stillbuilding = false
for o = 0,roidnumber do
if GetAsteroid(o):GetNumTrees() < 4 and GetAI(2):OwnsAsteroidID(o) then
stillbuilding = true
end
end
if stillbuilding == false then
for l = 0,roidnumber do
constructionmetric[l] = nil
end
end
end
-- ok, we didn't hit on torch metric or construction metric. So lets do some gathering instead.
if torchlit[checkedroid.ID] == nil and constructionmetric[checkedroid.ID] == nil and GetGameTime() > 60 then
-- is there already a gather point?
-- gatherexists = 0
gathertrue = false
for h = 0,roidnumber do
if gathermetric[h] == 0 then
gatherexists = 1
gathertrue = true
end
end
if gathertrue == false then
gatherexists = 0
end
-- there's no gather point at the moment.
if gatherexists == 0 then
-- ok, is there at least one player-owned asteroid and one traversable asteroid within my send distance?
if pathsavailable > 0 and attackpaths > 0 then
-- yep.
-- *** THEN I'M THE NEW GATHER POINT!! Bringin all the seedlings to the yard, y0. ***
gathermetric[checkedroid.ID] = 0
gatherexists = 1
-- MessageBox("new gather point")
--MessageBox(checkedroid.ID)
else
-- nope.
-- *** I CAN'T BE THE GATHER POINT because I am totally surrounded by either all friendly neighbours or all enemy asteroids. ***
end
-- a gather point already exists.
elseif gatherexists == 1 then
-- Am I the gather point?
if gathermetric[checkedroid.ID] == 0 then
-- I AM the gather point! :>
-- is there still at least 1 player asteroid and 1 friendly asteroid nearby?
--validpath = 0
--validattack = 0
--for i = 0,pathsavailable do
-- if traversable[i] ~= nil then
-- travv = traversable[i]
-- travvy = travv.ID
-- if GetAI(2):OwnsAsteroidID(travvy) == true then
-- there's at least one friendly asteroid nearby.
-- validpath = 1
-- end
-- if GetAI(2):OwnsAsteroidID(travvy) == false then
-- there's at least one player asteroid nearby.
-- validattack = 1
-- end
-- end
--end
if attackpaths > 0 and pathsavailable > 0 then
-- yes, there's at least 1 friendly and 1 enemy asteroid nearby.
-- add up all the player seedlings in the nearby enemy systems. Do I have at least that, plus 50?
totalseeds = 50
currentlowest = 9000
attackpaths = attackpaths - 1
for j = 0,attackpaths do
totalseeds = totalseeds + attackable[j]:GetNumSeedlings(1)
-- this bit checks which of the asteroids has the lowest number of seedlings.
if attackable[j]:GetNumSeedlings(1) < currentlowest then
currentlowest = attackable[j]:GetNumSeedlings(1)
RAPETARGET = attackable[j]
end
end
-- "if i have more seeds than the enemy does, then..."
if checkedroid:GetNumSeedlings(2) > totalseeds + (RAPETARGET:GetNumDysonTrees() * 5) + (RAPETARGET:GetNumDefenseTrees() * 23) then
checkedroid:SendSeedlingsToTarget(2,checkedroid:GetNumSeedlings(2),RAPETARGET)
if rcolour < 105 then
rcolour = rcolour + 150
end
--MessageBox("Rape time!")
-- *** RAEP TIEM!!!"!"
elseif checkedroid:GetNumSeedlings(2) > 400 then
-- if i have silly numbers of seeds, just gogo anyway.
checkedroid:SendSeedlingsToTarget(2,checkedroid:GetNumSeedlings(2),RAPETARGET)
if rcolour < 105 then
rcolour = rcolour + 150
end
else
-- *** Hold, precious... we have not enough seeds yet to launch an attack... ***
-- ***
end
-- this bit checks if we have a "Cold War" situation on our hands - if so, we'd be better off moving to a different gather point with less player defenses nearby.
-- if totalseeds > 300 and totalseeds > checkedroid:GetNumSeedlings(2) and GetEmpire(1):GetNumOwnedAsteroids() > attackpaths + 1 then
-- MessageBox("ColdWar Detected - reset gather point")
-- for gathreset = 0,roidnumber do
-- gathermetric[gathreset] = nil
-- end
-- gatherexists = 0
-- end
else
-- *** I AM NO LONGER A SUITABLE GATHER POINT. RESET ALL GATHER POINTS
for r = 0,roidnumber do
gathermetric[r] = nil
end
gatherexists = 0
-- ***
end
else
-- I am not the gather point. :<
-- so send some seedlings to whichever traversable asteroid has the lowest gather metric.
-- ADD SOEM CODE HERE DRUIDS
if gathermetric[checkedroid.ID] ~= nil then
-- no, my gather metric is not Nil.
-- so my torch IS lit, but it's value is NOT zero.
for ddd = 0,pathsavailable do
if traversable[ddd] ~= nil then
trav = traversable[ddd]
hopIDint = trav.ID
if gathermetric[hopIDint] == 0 then
-- *** WE HAVE FOUND A NEIGHBOUR THAT HAS A ROUTE TO AN ASTEROID IN NEED OF SEEDS. Send 10 seedlings, or more if we have them available. ***
checkedroid:SendSeedlingsToTarget(2,((checkedroid:GetNumSeedlings(2)/pathsavailable) + 10),traversable[ddd])
gathermetric[checkedroid.ID] = 1
electiontimer = GetGameTime()
elseif gathermetric[hopIDint] ~= nil then
if gathermetric[hopIDint] > 0 then
-- both checkedroid and the neighbour we are looking at have a gather metric set. Also, the neighbour has a metric of at least 1.
-- seedlings needed in this direction!
-- my gather metric is already non-nil, so set mine to be his + 1 if he has a shorter path than me.
if gathermetric[hopIDint] < gathermetric[checkedroid.ID] - 1 then
gathermetric[checkedroid.ID] = gathermetric[hopIDint] + 1
shortestpath = hopIDint
elseif gathermetric[hopIDint] == gathermetric[checkedroid.ID] - 1 then
if shortestpath == nil then
shortestpath = hopIDint
end
if gathermetric[shortestpath] ~= nil then
if gathermetric[hopIDint] < gathermetric[shortestpath] then
shortestpath = hopIDint
end
end
end
end
end
end
end
checkedroid:SendSeedlingsToTarget(2,((checkedroid:GetNumSeedlings(2)/pathsavailable) + 10),GetAsteroid(shortestpath))
-- *** WE OWN THIS ASTEROID. THERE ARE NO ENEMIES HERE. WE HAVE AT LEAST 10 SEEDLINGS AND MAXIMUM TREES. OUR TORCH METRIC INDICATES ***
-- *** THAT A NEARBY ASTEROID REQUIRES SEEDLINGS FOR DEFENSE. Find a neighbour with the lower metric and send 10 seedlings there. ***
elseif gathermetric[checkedroid.ID] == nil then
-- yes my gather metric is nil, now lets see if any neighbours have a gather metric of 0..
for ddd = 0,pathsavailable do
if traversable[ddd] ~= nil then
trav = traversable[ddd]
hopIDint = trav.ID
if gathermetric[hopIDint] == 0 then
-- *** WE HAVE FOUND A NEIGHBOUR THAT IS A GATHER POINT. Send 10 seedlings, or more if we have them available. ***
checkedroid:SendSeedlingsToTarget(2,((checkedroid:GetNumSeedlings(2)/pathsavailable) + 10),traversable[ddd])
gathermetric[checkedroid.ID] = 1
elseif gathermetric[hopIDint] ~= nil then
if gathermetric[hopIDint] > 0 then
-- seedlings needed in this direction!
-- my gather metric is nil at the moment, so set it to his + 1.
if shortestpath == nil then
shortestpath = hopIDint
end
gathermetric[checkedroid.ID] = gathermetric[hopIDint] + 1
end
end
end
end
end
end
end
end
end
end
-- how many of our seedlings are here?
if checkedroid:GetNumSeedlings(2) < 10 then
-- 9 or less
-- how many trees are here?
if checkedroid:GetNumTrees() < 4 then
-- less than four trees
-- *** WE OWN THIS ASTEROID, THERE ARE NO ENEMIES HERE. WE HAVE LESS THAN 10 SEEDLINGS AND LESS THAN 4 TREES. We need seedlings for more trees! Advertise to neighbours that we need some.
constructionmetric[checkedroid.ID] = 0
-- ***
end
if checkedroid:GetNumTrees() == 4 then
-- four trees
-- constructionmetric[checkedroid.ID] = nil
-- *** WE OWN THIS ASTEROID, THERE ARE NO ENEMIES HERE. WE HAVE LESS THAN 10 SEEDLINGS AND MAXIMUM TREES. Wait until we have more seedlings before we can reinforce.
end
end
end
else
-- *** THIS ROID IS NOT OURS, it's a PLAYER asteroid!! Do nothing with it. :> ***
-- ***
end
if GetEmpire(1):GetNumOwnedAsteroids() < 4 and GetEmpire(2).NumSeedlings > 800 and finality == false then
finality = true
for doom = 0,roidnumber do
if GetEmpire(2):OwnsAsteroidID(doom) then
GetAsteroid(doom):SendSeedlingsToTarget(2,GetAsteroid(doom):GetNumSeedlings(2),GetEmpire(1):GetRandomAsteroid())
end
end
end
if electiontimer ~= nil then
if GetGameTime() > electiontimer + 45 then
-- we haven't managed to send any seedlings to a gather point for 45 seconds now. Lets try resetting all the gather metrics to trigger a new gather point election.
for greset = 0,roidnumber do
gathermetric[greset] = nil
end
--MessageBox("Due to low activity a new gather point election was held")
-- lets see if this helps, and seeds now start moving towards the gather point. if it doesn't, hold a new gather point election in 15 seconds.
electiontimer = electiontimer + 45
gatherexists = 0
end
end
gatherzero = false
for gatherzerocheck = 0,roidnumber do
if gathermetric[gatherzerocheck] == 0 then
gatherzero = true
end
end
if gatherzero == false then
gatherexists = 0
end
if GetEmpire(2).NumSeedlings > 1200 and GetEmpire(2):GetNumOwnedAsteroids() > roidnumber / 2 and endfinal == false then
endfinal = true
for final = 0,roidnumber do
if GetEmpire(2):OwnsAsteroidID(final) then
GetAsteroid(final):SendSeedlingsToTarget(2,GetAsteroid(final):GetNumSeedlings(2),GetEmpire(1):GetRandomAsteroid())
end
end
end
coroutine.yield()
end
end
function OnAsteroidTaken(id,owner)
if owner == 1 then
for reset = 0,roidnumber do
gathermetric[reset] = nil
end
gatherexists = 0
return
end
if owner == 2 then
for reset = 0,roidnumber do
gathermetric[reset] = nil
end
gatherexists = 0
return
end
end
Does this level load on ipad? :>