Author Topic: Fluffy's Comet (level)  (Read 6657 times)

0 Members and 1 Guest are viewing this topic.

RadMan

  • Seed
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
Re: Fluffy's Comet (level)
« Reply #15 on: June 19, 2010, 05:57:54 AM »
Moderatly hard, but very good...

Keep it up!

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Fluffy's Comet (level)
« Reply #16 on: June 19, 2010, 12:32:24 PM »
Thanks :>  And welcome!

Ytaker

  • Tester
  • Seedling
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 33
Re: Fluffy's Comet (level)
« Reply #17 on: July 31, 2010, 07:09:51 PM »
That was a very cool level. I love the moving asteroid thing. It adds a lot of strategy, forces you to be fast.

The five mines thing was cool too. A lot of power.

One question. I conquered the home systems, and then built up a huge force to attack the enemy. I attacked, killed off the mines, and had about 300 seeds. It then span off screen, and when it came back, had 600. No enemies attacked it. How did you get it to add seeds?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Fluffy's Comet (level)
« Reply #18 on: August 01, 2010, 01:52:23 PM »
Thanks for your comments.  :>


In answer to your question:

The way it does it is, it checks if the player can see the comet.  When they can't see it anymore, the new batch of seedlings is added.  This also sets a special flag to prevent seedlings being added repeatedly every time it checks.

That special flag is returned to its default state when the comet becomes visible to the player again.



If you send seedlings to the comet (the level is designed to make it very hard to do this) then no further seedlings will be added, unless you move all your seedlings off again.

Jeheace

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • Jeheace's Art
Re: Fluffy's Comet (level)
« Reply #19 on: August 03, 2010, 10:27:33 PM »
The comet only made one pass before I had all the roids.... From reading every thing, I mistakenly thought I had to TAKE the comet, but was very surprised when I got the ^-^ you won! message after only one pass...

Good level!

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Fluffy's Comet (level)
« Reply #20 on: August 04, 2010, 02:33:54 PM »
Tried playing Infinity? :>

Jeheace

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • Jeheace's Art
Re: Fluffy's Comet (level)
« Reply #21 on: August 04, 2010, 07:36:49 PM »
Indeed! ^-^ That was the first map from the map pack that I tried. Took me about tree attempts before I managed to defeat that map... I decided to play the first set of roids that you start on aggressively, then go back and plant. ^-^

Jazz Ad

  • Sapling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 52
Re: Fluffy's Comet (level)
« Reply #22 on: August 06, 2010, 01:32:48 AM »
Much like with Infinity, I can't seem to make any progress in this level. I tried different approaches but always get slayed at 3rd wave.
Right now it is more frustrating than fun to play.  :-\

Ytaker

  • Tester
  • Seedling
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 33
Re: Fluffy's Comet (level)
« Reply #23 on: August 06, 2010, 11:13:37 PM »
Planet by planet strategy.

1. Take the far right planet, plant one tree.

2. Take the far right planet, plant one tree, move any troops produced to the front line.

3. Repeat for the planet upish and right. I had 44 troops when this was done.

4. Attack the planet to the north with everything. Continue to send everything you have to this planet.

5. Ignore the comet, take the planet. When I had 130 energy to go, I sent 10 seedlings to add a dyson to the lower planet.

6. I captured the planet, and colonised the lower one fully, 4 dysons.. Kept sending my troops forward, moved all troops back to planet with 1 dyson- planet seedling cap can stop spawning.

7. Held up the spawning and collecting on planet till comet was close. Gathered all seedlings on corner planet.

8. After a long fight, won. Endless seedlings beat super seedlings. Sent troops to colonize lowermost planet, up to 4. It's a strong planet. Left 9 troops on upper planet at all time- at this point the AI likes to launch an attack. 9 troops will delay destruction.

9. Fluffy's comet returns again. My troops destroy them, at the cost of nearly all their lives. Upper planet faces an assault from 90 troops. I send everything I have up to them. We're gonna take the left planet soon.

10 Enemy is defeated. 60 seeds sent to purple top left planet. More troops we have, the faster they go down, the faster they produce seeds for us. Plus, with lots of troops, we won't lose many and we'll have good defences.

11. Note. We could take all planets before fluffy comes back. But where's the fun in that?

Crush invasion force, do whatever you want. Win.

BC wins

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
Re: Fluffy's Comet (level)
« Reply #24 on: August 16, 2010, 02:24:54 PM »
anik could you send the code cause i can't seem to be able to download the lvl :(

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Fluffy's Comet (level)
« Reply #25 on: August 17, 2010, 01:56:38 PM »
BC,


Here is the code:


Code: [Select]
function LevelSetup()


SetBackdropColour(0,0,0)

Globals.Agents.MaxSpeed=1000
Globals.Agents.MinSpeed=500

Globals.Mines.MinSpeed=1200
Globals.Mines.MaxSpeed=1200
Globals.Mines.MinHealth=2000
Globals.Mines.MaxHealth=2000

Globals.Asteroids.MaxTrees=3
Globals.Asteroids.MinRadius=125
    Globals.Asteroids.MaxRadius=725
    Globals.Asteroids.RadiusPowerRule=1.5
Globals.Asteroids.MinCoreHealth=50
Globals.Asteroids.MaxCoreHealth=900
Globals.Asteroids.CoreHealthPower=1
    Globals.Asteroids.MinSendDistance=60000
    Globals.Asteroids.MaxSendDistance=60000
    Globals.Asteroids.SendPowerRule=1.4
Globals.Asteroids.SpawnCap=40
Globals.Asteroids.SeedlingCap=1000
Globals.G.Asteroids=(0)

Globals.AI.GraceTimer=(9999999)


Globals.G.EnemyFactionsMin=(0)
Globals.G.EnemyFactionsMax=(0)
Globals.G.MinAsteroidSeparation=100
Globals.G.MaxAsteroidNeighbourDist=60000
Globals.G.GreysProbability=0

Globals.Structures.FlowerProbability=(0.1)

SetVignetteAlpha(0)
SetFlowerDefenseButtonAvailable(false)

AccelerationX = {}
AccelerationY = {}
MomentumX = {}
MomentumY = {}
density = {}
CoordX = {}
CoordY = {}
roidradius = {}

G = 0.1



-- ****************************************
-- **********Asteroid Creation*************
-- ****************************************
--




-- ***
-- 1.  THE BELOW ASTEROIDS HAVE A GRAVITY WELL BUT DO NOT THEMSELVES MOVE
-- ***


-- Asteroid 0 - THE SUN!!
-- gravity variables
roid = 0
AccelerationX[roid] = 0
AccelerationY[roid] = 0
MomentumX[roid] = 0
MomentumY[roid] = 0
density[roid] = 1
CoordX[roid] = 0
CoordY[roid] = 0
roidradius[roid] = 1750

-- Creation
a = AddAsteroidWithAttribs(CoordX[roid],CoordY[roid],0.5,0.5,1)
a.Owner = 3
a.TreeCap = 0
a:SetRadius(roidradius[roid])
a:Reveal(1)
a.Moveable = False
a.MaxCoreHealth = 10000











wellonlythreshold = roid + 1
-- ***
-- 2.  THE BELOW ASTEROIDS HAVE A GRAVITY WELL, AND MOVE
-- ***


-- Asteroid 1 - THE COMET!!
-- gravity variables
roid = 1
AccelerationX[roid] = 0
AccelerationY[roid] = 0
MomentumX[roid] = 0
MomentumY[roid] = 2.1
density[roid] = 0.8
CoordX[roid] = 30000
CoordY[roid] = -20000
roidradius[roid] = 350

-- Creation
a = AddAsteroidWithAttribs(CoordX[roid],CoordY[roid],0.1,1,1)
a.Owner = 2
a.TreeCap = 0
a:SetRadius(roidradius[roid])
a:Reveal(1)
a.Moveable = False
a:AddSeedlings(75, 2,1,1,2)
a:AddMine(2)
a:AddMine(2)
a:AddMine(2)
a:AddMine(2)
a:AddMine(2)










gravroidsthreshold = roid
-- 3.  THE BELOW ASTEROIDS DO NOT MOVE AND DO NOT HAVE A GRAVITY WELL

-- Asteroid 2
-- gravity variables
roid = 2
AccelerationX[roid] = 0
AccelerationY[roid] = 0
MomentumX[roid] = 0
MomentumY[roid] = 0
density[roid] = 0.1
CoordX[roid] = -1200
CoordY[roid] = -3700
roidradius[roid] = 475

-- Creation
a = AddAsteroidWithAttribs(CoordX[roid],CoordY[roid],0.85,0.3,0.77)
a.Owner = 2
a.TreeCap = 4
a:SetRadius(roidradius[roid])
a:Reveal(1)
a.Moveable = False



-- Asteroid 3
-- gravity variables
roid = 3
AccelerationX[roid] = 0
AccelerationY[roid] = 0
MomentumX[roid] = 0
MomentumY[roid] = 0
density[roid] = 0.1
CoordX[roid] = 7000
CoordY[roid] = -2650
roidradius[roid] = 425

-- Creation
a = AddAsteroidWithAttribs(CoordX[roid],CoordY[roid],0.8,0.6,0.85)
a.Owner = 2
a.TreeCap = 6
a:SetRadius(roidradius[roid])
a:Reveal(1)
a.Moveable = False
a.MaxCoreHealth = 2125
a.CoreHealth = 750


-- Asteroid 4
-- gravity variables
roid = 4
AccelerationX[roid] = 0
AccelerationY[roid] = 0
MomentumX[roid] = 0
MomentumY[roid] = 0
density[roid] = 0.1
CoordX[roid] = 8500
CoordY[roid] = 6050
roidradius[roid] = 675

-- Creation
a = AddAsteroidWithAttribs(CoordX[roid],CoordY[roid],0.7,0.9,0.3)
a.Owner = 2
a.TreeCap = 4
a:SetRadius(roidradius[roid])
a:Reveal(1)
a.Moveable = False





-- Asteroid 5
-- gravity variables
roid = 5
AccelerationX[roid] = 0
AccelerationY[roid] = 0
MomentumX[roid] = 0
MomentumY[roid] = 0
density[roid] = 0.1
CoordX[roid] = -2000
CoordY[roid] = 10050
roidradius[roid] = 500

-- Creation
a = AddAsteroidWithAttribs(CoordX[roid],CoordY[roid],0.2,0.3,0.55)
a.Owner = 2
a.TreeCap = 3
a:SetRadius(roidradius[roid])
a:Reveal(1)
a.Moveable = False


-- Asteroid 6
-- gravity variables
roid = 6
AccelerationX[roid] = 0
AccelerationY[roid] = 0
MomentumX[roid] = 0
MomentumY[roid] = 0
density[roid] = 0.1
CoordX[roid] = -12000
CoordY[roid] = 8050
roidradius[roid] = 800

-- Creation
a = AddAsteroidWithAttribs(CoordX[roid],CoordY[roid],0.8,0.3,0.7)
a.Owner = 2
a.TreeCap = 4
a:SetRadius(roidradius[roid])
a:Reveal(1)
a.Moveable = False



-- Asteroid 7
-- gravity variables
roid = 7
AccelerationX[roid] = 0
AccelerationY[roid] = 0
MomentumX[roid] = 0
MomentumY[roid] = 0
density[roid] = 0.1
CoordX[roid] = -17000
CoordY[roid] = 19050
roidradius[roid] = 725

-- Creation
a = AddAsteroidWithAttribs(CoordX[roid],CoordY[roid],0.7,0.6,0.5)
a.Owner = 2
a.TreeCap = 5
a:SetRadius(roidradius[roid])
a:Reveal(1)
a.Moveable = False



-- Asteroid 8
-- gravity variables
roid = 8
AccelerationX[roid] = 0
AccelerationY[roid] = 0
MomentumX[roid] = 0
MomentumY[roid] = 0
density[roid] = 0.1
CoordX[roid] = -21175
CoordY[roid] = 9050
roidradius[roid] = 600

-- Creation
a = AddAsteroidWithAttribs(CoordX[roid],CoordY[roid],0.4,0.6,0.65)
a.Owner = 2
a.TreeCap = 3
a:SetRadius(roidradius[roid])
a:Reveal(1)
a.Moveable = False




-- Asteroid 9
-- gravity variables
roid = 9
AccelerationX[roid] = 0
AccelerationY[roid] = 0
MomentumX[roid] = 0
MomentumY[roid] = 0
density[roid] = 0.1
CoordX[roid] = -25350
CoordY[roid] = 4300
roidradius[roid] = 925

-- Creation
a = AddAsteroidWithAttribs(CoordX[roid],CoordY[roid],0.9,0.6,1)
a.Owner = 1
a.TreeCap = 4
a:SetRadius(roidradius[roid])
a:Reveal(1)
a.Moveable = False
a:AddSeedlings(70)
s = a:AddDysonTree()
s:LevelUp()
s:LevelUp()
s:LevelUp()
s:AddFlower()
s = a:AddDysonTree()
s:LevelUp()
s:LevelUp()
s:LevelUp()
s:AddFlower()
s = a:AddDysonTree()
s:LevelUp()
s:LevelUp()
s:LevelUp()
s = a:AddDysonTree()
s:LevelUp()
s:LevelUp()
s:LevelUp()



-- spacer
a = AddAsteroidWithAttribs(55000,5000,0.5,0.5,0.5)
a.Owner = 3
a.TreeCap = 4
a:SetRadius(1)
a.Moveable = False



roidnumber = roid
-- END ASTEROID CREATION


-- Set the properties for your asteroids by first declaring all
-- the properties that are declared in gravity variables:
--
-- AccelerationX[ID] = 0
-- AccelerationY[ID] = 0
-- MomentumX[ID] = 0
-- MomentumY[ID] = 0
-- density[ID] = 1
-- CoordX[ID] = x-coordinate of the asteroid
-- CoordY[ID] = y-coordinate of the asteroid
-- roidradius[ID] = radius of the asteroid
--
-- These are the "default" values.  If you set density to 0,
-- the asteroid will not be included in gravity calculations.
-- If you set the density very high, and your asteroid's
-- radius is extremely small, you are creating a black hole.
-- Once you have set these, use a = AddAsteroidWithAttribs
-- below it, and plug the variables in, rather than numbers.





-- START AI ENGINE INITIALISATION

rcolour = 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 AI ENGINE INITIALISATION










--SetCameraPositionToAsteroidID(9)
SetCameraZoomNow(1)





end


function LevelLogic()

SetCameraZoom(7)
SetCameraPosition(((CoordX[9] * -1) - 1500),((CoordY[9] * -1) - 1500))
-- SET ASTEROID SEND DISTANCES

for sendy = 2, 9 do
--GetAsteroid(sendy).SendDistance = 12500
GetAsteroid(sendy).SendDistance = 6750 + roidradius[sendy] * 8
GetAsteroid(sendy):Reveal(2)
GetAsteroid(sendy):Hide(1)
end

GetAsteroid(0).SendDistance = 8000
GetAsteroid(1).SendDistance = 8000
GetAsteroid(3).SendDistance = 20500
GetAsteroid(5).SendDistance = 13000
GetAsteroid(9):Reveal(1)
GetAsteroid(2):Reveal(1)

-- INITIALISE VARIABLES
Timer = GetGameTime()

purgetimer = GetGameTime()


GetAsteroid(2):AddSeedlings(61)


while GetGameTime() < 4 do

coroutine.yield()
end

MessageBox("Capture all habitable asteroids to win.  Defeat occurs when you lose all your asteroids.  Mines are disabled.  The Sun's core foretell's Fluffy's arrival.")


while GameRunning() do



-- START SUN-COMET CORE DISTANCE METER

cometdistance = math.sqrt((CoordX[1] * CoordX[1]) + (CoordY[1] * CoordY[1]))
cometdistance = cometdistance / 100
cometdistance = cometdistance - 34
GetAsteroid(0).CoreHealth = cometdistance

-- END SUN-COMET CORE DISTANCE METER




-- START GRAVITY ENGINE



-- RATE LIMITER - has sufficient time for a new calculation period elapsed ?
-- this is an attempt to provide the same "speed" of gravity on all computers
-- and it sucks, so i set it to 0.  bite me.

if GetGameTime() > Timer + 0.0 then

Timer = GetGameTime()

for i = 0, gravroidsthreshold do



for j = i + 1, gravroidsthreshold do
-- calculate Fgx and Fgy between i and j, then...


Fgx = (G * ((roidradius[i] * roidradius[i]) * math.pi * density[i]) * ((roidradius[j] * roidradius[j]) * math.pi * density[j])) / ((CoordX[j] - CoordX[i])^2 + (CoordY[j] - CoordY[i])^2)
Fgy = (G * ((roidradius[i] * roidradius[i]) * math.pi * density[i]) * ((roidradius[j] * roidradius[j]) * math.pi * density[j])) / ((CoordX[j] - CoordX[i])^2 + (CoordY[j] - CoordY[i])^2)

-- now we have the force of gravity x and y, as a scalar.  we must find the direction to point in:
xdiff = CoordX[j] - CoordX[i]
ydiff = CoordY[j] - CoordY[i]


-- find the length of the vector..

vectorlength = math.sqrt(xdiff^2 + ydiff^2)

-- divide the vectors by the length to normalise

NormalisedVectorX = xdiff / vectorlength
NormalisedVectorY = ydiff / vectorlength

-- these normalised vectors are values between 0 and 1 that give us a direction :>


-- a^2 = b^2 + c^2.... i know b^2 and c^2...  seed im only getting the acceleration as a scalar :S  i need it as coordinates !  + or - ...

-- ..add the appropriate amount of acceleration
AccelerationX[i] = AccelerationX[i] + (NormalisedVectorX * Fgx / ((roidradius[i] * roidradius[i]) * math.pi) * density[i])
AccelerationY[i] = AccelerationY[i] + (NormalisedVectorY * Fgy / ((roidradius[i] * roidradius[i]) * math.pi) * density[i])

xdiff = CoordX[i] - CoordX[j]
ydiff = CoordY[i] - CoordY[j]

NormalisedVectorX = xdiff / vectorlength
NormalisedVectorY = ydiff / vectorlength

AccelerationX[j] = AccelerationX[j] + (NormalisedVectorX * Fgx / ((roidradius[j] * roidradius[j]) * math.pi) * density[j])
AccelerationY[j] = AccelerationY[j] + (NormalisedVectorY * Fgy / ((roidradius[j] * roidradius[j]) * math.pi) * density[j])




end
end


for pass = wellonlythreshold,gravroidsthreshold do

MomentumX[pass] = MomentumX[pass] + AccelerationX[pass]

MomentumY[pass] = MomentumY[pass] + AccelerationY[pass]

-- MOVE GETASTEROID(PASS) by MomentumX and MomentumY

CoordX[pass] = CoordX[pass] + MomentumX[pass]
CoordY[pass] = CoordY[pass] + MomentumY[pass]

GetAsteroid(pass):MoveTo(CoordX[pass], CoordY[pass])


AccelerationX[pass] = 0
AccelerationY[pass] = 0


end

end




-- END GRAVITY ENGINE









-- START AI ENGINE




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() == 1 and GetGameTime() > 5 then

Pause()
MessageBox("Win! ^_^")
WaitDialog()
Unpause()
Quit(true)
end

--AI

checkedroid = GetAI(2):GetRandomAsteroid()

if checkedroid.ID == 1 then

if GetAsteroid(1):IsVisible(1) == true then

targetA = GetEmpire(1):GetRandomAsteroid()
targetB = GetAI(2):GetRandomAsteroid()

if targetA.ID < 5 then
checkedroid:SendSeedlingsToTarget(2,50,targetA)
end

if targetB.ID < 6 then
checkedroid:SendSeedlingsToTarget(2,50,targetB)
end

end

checkedroid = GetAsteroid(2)

end





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

-- MINE CHECK NOT REQUIRED IN THIS MAP

--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 = 2,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() < checkedroid.TreeCap 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() == checkedroid.TreeCap then
-- max 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() < GetAsteroid(o).TreeCap 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() < checkedroid.TreeCap 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() == checkedroid.TreeCap 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




-- END AI ENGINE









-- START LEVEL-SPECIFIC SCRIPTS


-- is the comet far away ?  if so, hide it from the player...assuming the player doesnt have seeds on it...  add a new wave when it's time.

addnewwave = 0

if GetAsteroid(1):GetNumSeedlings(1) > 0 then

GetAsteroid(1):Reveal(1)

else

if math.sqrt((MomentumX[1] * MomentumX[1]) + (MomentumY[1] * MomentumY[1])) > 5 then

GetAsteroid(1):Reveal(1)

else

GetAsteroid(1):Hide(1)
addnewwave = 1

end




end

if addnewwave == 1 and GetAsteroid(1):GetNumSeedlings(2) < 10 then

addnewwave = 0
GetAsteroid(1):AddSuperSeedlings(300,2,0.5,0.3,2)

end


-- STOP LEVEL-SPECIFIC SCRIPTS


coroutine.yield()
end


end