Author Topic: What are you working on? :D  (Read 34638 times)

0 Members and 2 Guests are viewing this topic.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #240 on: June 17, 2011, 05:37:17 PM »
It's working fine now it seems, but why is local variables affecting the return? And the error message was very missleading, telling something about that the number had to be non-negative...

Anyways, thanks... Now I can finally code the maps, and I want as many map types as possible :)


DERP!!

It ain't working after all -.-

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #241 on: June 17, 2011, 06:03:32 PM »
I acctually want to add the possability to do maps outside of the lua, doing so it runs from text files instead, much better and cleaner :P

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: What are you working on? :D
« Reply #242 on: June 18, 2011, 01:33:15 AM »
In the morning, I get to coding.  Lets implement this thing !

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #243 on: June 18, 2011, 12:23:09 PM »
just got a cool idea for a map, you do the Solar Conquest map generator, andf then have the capturing alike risks, but not eh spawning... After so, you must plant a fertilizer(custom tree :D) on the asteroid, which then increases the treecap to 3 after time(from 0 to 3!) :)

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #244 on: June 18, 2011, 03:00:30 PM »
I still need help with the loading thing, here is the code:

Code: [Select]
function LevelSetup()

Globals.G.Asteroids=0
Globals.G.EnemyFactionsMin=0
Globals.G.EnemyFactionsMax=0
SetBackdropColour(0,0,0)
Globals.G.GreysProbability = 0
Globals.G.GreysMin=0
Globals.G.GreysMax=0

CreateFolders()

SFXInit()
BasicSaveFolder = "C:\\EufloriaSaves\\"
MissionsDone = 2
CreateMainQuest()
CreateMap()

if AIType == "infected" then
AIinit()
elseif AIType == "alien" then
AAIInit()
end
end

function SFXInit()

NumSFXs = -1

SFXPx = {}
SFXPy = {}
SFXColorAndSize = {}
SFXCurrentChange = {}
SFXChanging = {}
SFXIsActive = {}

end

function CreateSFX(x,y,r,g,b,a,size,rd,gd,bd,ad,sized,rcs,gcs,bcs,acs,scs)

NumSFXs = NumSFXs + 1

--For the matrix: 1 = the base color, 2 = the amount of change possible, 3 = the current amount of change and 4: the speed of change

SFXColorAndSize[NumSFXs] = {}
SFXColorAndSize[NumSFXs][1] = {}
SFXColorAndSize[NumSFXs][2] = {}
SFXColorAndSize[NumSFXs][3] = {}
SFXColorAndSize[NumSFXs][4] = {}
SFXCurrentChange[NumSFXs] = {}

SFXPx[NumSFXs] = x
SFXPy[NumSFXs] = y
SFXColorAndSize[NumSFXs][1][1] = r
SFXColorAndSize[NumSFXs][1][2] = g
SFXColorAndSize[NumSFXs][1][3] = b
SFXColorAndSize[NumSFXs][1][4] = a
SFXColorAndSize[NumSFXs][1][5] = size
SFXColorAndSize[NumSFXs][2][1] = rd
SFXColorAndSize[NumSFXs][2][2] = gd
SFXColorAndSize[NumSFXs][2][3] = bd
SFXColorAndSize[NumSFXs][2][4] = ad
SFXColorAndSize[NumSFXs][2][5] = sized
SFXColorAndSize[NumSFXs][3][1] = r
SFXColorAndSize[NumSFXs][3][2] = g
SFXColorAndSize[NumSFXs][3][3] = b
SFXColorAndSize[NumSFXs][3][4] = a
SFXColorAndSize[NumSFXs][3][5] = size
SFXColorAndSize[NumSFXs][4][1] = rcs
SFXColorAndSize[NumSFXs][4][2] = gcs
SFXColorAndSize[NumSFXs][4][3] = bcs
SFXColorAndSize[NumSFXs][4][4] = acs
SFXColorAndSize[NumSFXs][4][5] = scs
SFXCurrentChange[NumSFXs][1] = 1
SFXCurrentChange[NumSFXs][2] = 1
SFXCurrentChange[NumSFXs][3] = 1
SFXCurrentChange[NumSFXs][4] = 1
SFXCurrentChange[NumSFXs][5] = 1
SFXIsActive[NumSFXs] = true

if SFXColorAndSize[NumSFXs][2][1] ~= nil then
if SFXColorAndSize[NumSFXs][2][2] ~= nil then
if SFXColorAndSize[NumSFXs][2][3] ~= nil then
if SFXColorAndSize[NumSFXs][2][4] ~= nil then
if SFXColorAndSize[NumSFXs][2][5] ~= nil then
SFXChanging[NumSFXs] = true
end
end
end
end
end

end

function ChangeActiveState(id,bool)

SFXIsActive[id] = bool

end

function LevelDraw()

if NumSFXs >= 0 then
for i = 0,NumSFXs do
if SFXIsActive[i] == true then
local r = SFXColorAndSize[i][1][1]
local g = SFXColorAndSize[i][1][2]
local b = SFXColorAndSize[i][1][3]
local a = SFXColorAndSize[i][1][4]
local s = SFXColorAndSize[i][1][5]

if SFXChanging[i] == true then

SFXColorAndSize[i][3][1] = SFXColorAndSize[i][3][1] + SFXColorAndSize[i][4][1]*SFXCurrentChange[i][1]
SFXColorAndSize[i][3][2] = SFXColorAndSize[i][3][2] + SFXColorAndSize[i][4][2]*SFXCurrentChange[i][2]
SFXColorAndSize[i][3][3] = SFXColorAndSize[i][3][3] + SFXColorAndSize[i][4][3]*SFXCurrentChange[i][3]
SFXColorAndSize[i][3][4] = SFXColorAndSize[i][3][4] + SFXColorAndSize[i][4][4]*SFXCurrentChange[i][4]
SFXColorAndSize[i][3][5] = SFXColorAndSize[i][3][5] + SFXColorAndSize[i][4][5]*SFXCurrentChange[i][5]

for j = 1,5 do

if SFXCurrentChange[i][j] == 1 then
if SFXColorAndSize[i][3][j] > SFXColorAndSize[i][1][j]+SFXColorAndSize[i][2][j] then
SFXCurrentChange[i][j] = -1
end
elseif SFXCurrentChange[i][j] == -1 then
if SFXColorAndSize[i][3][j] < SFXColorAndSize[i][1][j]-SFXColorAndSize[i][2][j] then
SFXCurrentChange[i][j] = 1
end
end
end

r = SFXColorAndSize[i][3][1]
g = SFXColorAndSize[i][3][2]
b = SFXColorAndSize[i][3][3]
a = SFXColorAndSize[i][3][4]
s = SFXColorAndSize[i][3][5]

end

if a > 0 then
DrawSprite(1,SFXPx[i],SFXPy[i],r,g,b,a,s)
end
end
end
end
end

function SaveGameStats()

io.output(io.open(BasicSaveFolder .. "\\Adventure\\Adventure.EURI", "w"))
local txt = tostring(MissionsDone) .. "\n"
io.write(txt)
io.close()
end

function GetGameSaveInfo(wline)
if io.open(BasicSaveFolder .. "\\Adventure\\Adventure.EURI", "r") then

local file = assert(io.input(io.open(BasicSaveFolder .. "\\Adventure\\Adventure.EURI", "r")))

local curline = 1

for line in file:lines() do
if curline == wline then
reqline = line
end
curline = curline + 1
end

elseif wline == 1 then

reqline = 0

end

return reqline
end

function CreateMainQuest()

if MissionsDone == 0 then

MissionObjective = "Gather 100 seedlings without dying"
MapType = "classic"

elseif MissionsDone == 1 then

MissionObjective = "Kill all three enemies without dying"
MapType = "triangle"

elseif MissionsDone == 2 then

MissionObjective = "Defend from waves without loosing any asteroids for 5 mins"
MapType = "fortress"

else

MissionObjective = "not determined"
MapType = "random"

end

end

function CreateMap()

if MapType == "classic" then

for i = 0,math.random(10,20) do

a = AddAsteroid(math.random(-10000,10000),math.random(-10000,10000))

if i == 0 then
a.Owner = 1
a:AddDysonTree()
a:AddSeedlings(10)
elseif i == 4 then
a.Owner = 2
a:AddDysonTree()
a:AddSeedlings(10)
else
if math.random() > 0.7 then
a.Owner = math.random(1,2)
a:AddDysonTree()
a:AddSeedlings(10)
else
a.Owner = 0
end
end

end

OpeningText = "You play a classic random map, this one contains nothing of special stuff!\n\nKill the enemy and win, they might have more than you, or less!"
MapTime = nil
Win = "conquest"
AIType = "normal"

elseif MapType == "triangle" then

local owner = 2

for i = 1,3 do

local a = AddAsteroidWithAttribs(math.cos((i/3)*(math.pi*2))*10000,math.sin((i/3)*(math.pi*2))*10000,0.8,0.8,0.8)

a.Owner = owner
a:AddDysonTree()
a:AddSeedlings(50)

owner = owner + 1

end

local numextra = math.random(20,30)

for i = 0,numextra do

local x = math.random(-10000,10000)
local y = math.random(-10000,10000)

local a = AddAsteroid(math.random(-10000,10000),math.random(-10000,10000))

if i == 0 then
a.Owner = 1

a:AddDysonTree()
else
a.Owner = 0
end
a:AddSeedlings(20*a.Owner+math.random(0,10))

end

OpeningText = "Kill the three empires that tries to kill you, be warned as their main asteroid is very highly attributed!"
MapTime = nil
Win = "conquest"
AIType = "normal"

elseif MapType == "fortress" then

local fortx = math.random(-10000,10000)
local forty = math.random(-10000,10000)

local fortsize = math.random(2000,2500)

a = AddAsteroidWithAttribs(fortx,forty,1,1,1)

a.Owner = 1
a.TreeCap = 5
a:AddSeedlings(100)
a:AddDysonTree()
a:AddDysonTree()
a:AddDysonTree()
a:AddDysonTree()
a:AddDysonTree()
a.Moveable = false

for i = 1,5 do

a = AddAsteroidWithAttribs(fortx+math.cos((i/5)*(math.pi*2))*fortsize,forty+math.sin((i/5)*(math.pi*2))*fortsize,0.8,0.8,0.8)
a.Owner = 1
a:AddDysonTree()
a:AddSuperSeedlings(5)
a.TreeCap = 2
a.Moveable = false

end

for i = 1,20 do

a = AddAsteroid(math.random(-10000,10000),math.random(-10000,10000))
a.Owner = 2
a:AddSeedlings(20)
a.TreeCap = 8
a:AddDysonTree()
a:AddDysonTree()
a:AddDysonTree()
a:AddDysonTree()
a:AddDysonTree()
a:AddDysonTree()
a:AddDysonTree()
a:AddDysonTree()

end

OpeningText = "Watch out for incoming attacks on your fort...\n\nCan you stand against the infected AI for five minutes?"
MapTime = 60*5
Win = "timeout"
AIType = "infected"

end
end

function CreateFolders()

os.execute("mkdir " .. BasicSaveFolder .. "\\Adventure")
os.execute("mkdir " .. BasicSaveFolder .. "\\Adventure\\Maps")

end

function LevelLogic()

if MapTime ~= nil then
GameLast = GetGameTime() + MapTime
end

GameTime = GetGameTime()
while GameRunning() do
if GameTime < GetGameTime() then
GameTime = GetGameTime()

SaveGameStats()

if AIType == "infected" then
InfectedAIEngine()
elseif AIType == "alien" then
AAIEngine()
elseif AIType == "both" then
InfectedAIEngine()
AAIEngine()
end

if GameLast < GetGameTime() then
if Win == "timeout" then
DoWin()
else
DoLost()
end
end

end

coroutine.yield()

end
end

function DoLost()

Pause()
MessageBox(LostMessage)
WaitDialog()
Unpause()
Quit(false)

end

function DoWin()

Pause()
MessageBox(LostMessage)
WaitDialog()
Unpause()
MissionsDone = MissionsDone + 1
SaveGameStats()
Quit(true)

end



































function AIinit()
-- *** INFECTED AI V2.3 : INIT ***
-- *** AUTHOR: ANNIKK.EXE ***
-- *** EMAIL: annikk [dot] exe [at] gmail [dot] com ***

Globals.AI.GraceTimer=(99999)

-- Number of times the engine is run per While loop:
numberofiterations = 0
-- Set to 0 for very large maps. (50 asteroids+)
-- Set to 2-4 for small maps for quicker AI response.

metric = {}
currentowner = {}

for i = 0,300 do
metric[i] = 500
end


-- *** END INFECTED AI : INIT ***
end


function InfectedAIEngine()
-- *** INFECTED AI V2.3 : ENGINE ***
-- Author: ANNIKK.EXE [at] GMAIL [dot] COM
numberofasteroids = -1
neighbours = {}

for i = 0, 300 do
if GetAsteroid(i) ~= nil then
if GetAsteroid(i).radius > 10 then
numberofasteroids = numberofasteroids + 1
end
end
end

-- now the variable called "numberofasteroids" accurately represents the number of playable asteroids on the field.

for iterations = 0,numberofiterations do

-- Select an asteroid for checking.
checkedroid = GetAsteroid(math.random(0,numberofasteroids))

-- Record the current asteroid owner
changedowner = false

if currentowner[checkedroid.id] ~= nil then
if currentowner[checkedroid.id] ~= checkedroid.owner then
currentowner[checkedroid.id] = checkedroid.owner
changedowner = true
end
else
currentowner[checkedroid.id] = checkedroid.owner
end

tree = nil
flower = nil

-- flower check !
tree = checkedroid:GetRandomDysonTree()

if tree ~= nil then
flower = tree:GetSuperSeedling()
end

if checkedroid.owner > 1 and flower ~= nil then
flower:Pluck()
end

flower = checkedroid:GetFlower(checkedroid.owner)

if checkedroid.owner > 1 and flower ~= nil then
flower:PlantOnRandomDysonTree()
end

-- calculate which asteroids are a neighbour to checkedroid
numberofneighbours = -1

for i = 0,numberofasteroids do

length = GetAsteroid(i).position.x - checkedroid.position.x
height = GetAsteroid(i).position.y - checkedroid.position.y

distancetoroid = math.sqrt((length * length) + (height * height))
distancetoroid = distancetoroid - GetAsteroid(i).Radius

if distancetoroid < checkedroid.SendDistance then
-- this asteroid is in range.  Add it to the neighbours list, and increment the neighbour count by one.  ALSO ADDS SELF AS NEIGHBOUR!  But we trap for this in the Metric Update section.
numberofneighbours = numberofneighbours + 1
neighbours[numberofneighbours] = GetAsteroid(i)
end
end

-- Metric update
-- did we update from our own status?
updated = false

-- are we under attack?  if so set metric 0
if checkedroid.owner ~= 1 and checkedroid.owner ~= 0 then

if (checkedroid:GetNumSeedlings() - checkedroid:GetNumSeedlings(checkedroid.owner)) > (checkedroid:GetNumTrees() * 5) or checkedroid:GetNumMines(1) > 0 then

-- ok well we own this asteroid, and there are more enemy seeds here than our seeds (or there's a player mine here).  Now, we DO have at least 1 tree worth defending here, right?
if checkedroid:GetNumTrees() > 0 then
-- ok, we're under attack!  METRIC 0!
metric[checkedroid.ID] = 0
updated = true

end
end
end

-- are we maxed on trees?  if not, set metric 100
-- (make sure we don't run this if we are under attack!)
if updated == false then

if checkedroid:GetNumTrees() < checkedroid.TreeCap then
-- we don't have max trees here yet.  Metric 100!
metric[checkedroid.ID] = 100
updated = true
end

end
-- Not under attack, maxed on trees, and ready to contribute to the empire.
-- Check the status of our neighbours first before trying to become a gather point.
-- only run this part of the code if we didn't get our metric from our own status
if updated == false then
-- are we a suitable gather point?

enemydetected = false
frienddetected = false
gatherpointdetected = false
lowermetricsnearby = false

for i = 0, numberofneighbours do

-- check that we're not examining ourself.
if neighbours[i] ~= checkedroid then

if neighbours[i].owner == checkedroid.owner then
-- this asteroid is friendly to us
frienddetected = true
end

if neighbours[i].owner ~= checkedroid.owner and neighbours[i].owner ~= 0 and neighbours[i]:GetNumTrees() > 0 then
-- this asteroid doesn't belong to us or player 0, and has at least 1 tree.  It must be an enemy roid.
enemydetected = true
end

numberofenemies = neighbours[i]:GetNumSeedlings() - neighbours[i]:GetNumSeedlings(checkedroid.owner)

if neighbours[i].owner ~= checkedroid.owner and neighbours[i]:GetNumTrees() == 0 and numberofenemies > 0 then
-- this asteroid doesn't belong to us, has no trees on it, but has enemy seedlings on it.  Treat it as enemy.
enemydetected = true
end

if neighbours[i].owner == checkedroid.owner and metric[neighbours[i].ID] == 200 then
-- this asteroid is friendly to us, and is a gather point.
gatherpointdetected = true
end

if neighbours[i].owner == checkedroid.owner and metric[neighbours[i].id] < 200 then
-- uh-oh, there's an asteroid nearby with a metric lower than 200.  There are Lower Metrics Nearby!
lowermetricsnearby = true
end
if neighbours[i].owner == 0 and metric[neighbours[i].id] < 200 then
-- uh-oh, there's an asteroid nearby with a metric lower than 200.  There are Lower Metrics Nearby!
lowermetricsnearby = true
end
end

end

if enemydetected == true and frienddetected == true and gatherpointdetected == false and lowermetricsnearby == false then
-- the conditions are right for me to become a gather point.
metric[checkedroid.id] = 200
elseif changedowner == true then
-- the asteroid just became mine.  insta-gather point please!
metric[checkedroid.id] = 200
end

-- Find the lowest metric among my neighbours
lowestmetric = metric[checkedroid.ID]

for i = 0, numberofneighbours do

-- check that we're not examining ourself.
if neighbours[i].id ~= checkedroid.id then

if neighbours[i].owner == checkedroid.owner or neighbours[i].owner == 0 then
-- this asteroid belongs to our empire, or it doesn't belong to anyone (and we should therefore follow its metrics)

-- is this neighbour's metric less than mine?  (also, have we just taken this asteroid..?)
if metric[neighbours[i].ID] < lowestmetric and changedowner == false then
-- yes it's lower.
lowestmetric = metric[neighbours[i].ID]
end

end

end
end

-- now we've established what the lowest metric is.  If it's lower than ours, set ours to that +1.  If the lowest metric of a neighbour is the same as our metric, increase ours by 1.
-- UNLESS we are a gather point
if metric[checkedroid.ID] > lowestmetric and metric[checkedroid.ID] ~= 200 and metric[checkedroid.ID] ~= 100 then
metric[checkedroid.ID] = lowestmetric + 5
end

if metric[checkedroid.ID] == lowestmetric and metric[checkedroid.ID] ~= 200 and metric[checkedroid.ID] ~= 100 then
-- if my metric is the same as the lowest metric of my neighbours, i must be 1 step further away than they are.
metric[checkedroid.ID] = metric[checkedroid.ID] + 5
end

-- check for errors, reset metric if necessary

if metric[checkedroid.id] > 500 then
metric[checkedroid.id] = 200
end

if metric[checkedroid.ID] > 0 and metric[checkedroid.ID] < 99 then
stillinneed = false

for i = 0,numberofasteroids do
if GetAsteroid(i).Owner == checkedroid.Owner and metric[i] == 0 then
stillinneed = true
end
end

if stillinneed == false then
for i = 0,numberofasteroids do
if GetAsteroid(i).owner == checkedroid.owner and metric[i] > 0 and metric[i] < 99 then
metric[i] = 500
end
end
end

end

if metric[checkedroid.ID] > 100 and metric[checkedroid.ID] < 199 then
stillinneed = false
for i = 0,numberofasteroids do
if GetAsteroid(i).Owner == checkedroid.Owner or GetAsteroid(i).owner == 0 then
if metric[i] == 100 then
stillinneed = true
end
end
end

if stillinneed == false then
for i = 0,numberofasteroids do
if GetAsteroid(i).owner == checkedroid.owner and metric[i] > 100 and metric[i] < 199 then
metric[i] = 500
end
end
end
end

if metric[checkedroid.ID] > 200 and metric[checkedroid.ID] < 299 then
stillinneed = false
for i = 0,numberofasteroids do
if GetAsteroid(i).Owner == checkedroid.Owner and metric[i] == 200 then
stillinneed = true
end
end

if stillinneed == false then
for i = 0,numberofasteroids do
if GetAsteroid(i).owner == checkedroid.owner and metric[i] > 200 and metric[i] < 299 then
metric[i] = 500
end
end
end
end

end

-- Now to check that if we have metric 0, 100 or 200, we still require that status.

if metric[checkedroid.id] == 0 then
-- ok.  Am I REALLY still under attack?
if checkedroid:GetNumSeedlings() - checkedroid:GetNumSeedlings(checkedroid.owner) > 1 or checkedroid:GetNumMines(1) > 0 then
-- the enemy outnumber us, or there's a player mine here.  Yes, we're really under attack...
else
-- we're not really under attack anymore.  lets reset the metric.
for i = 0, numberofasteroids do
if GetAsteroid(i).owner == checkedroid.owner then
metric[i] = 500
end

end
metric[checkedroid.id] = 200
end
end

if metric[checkedroid.id] == 100 then
-- ok.  Am I REALLY still under construction?
if checkedroid:GetNumTrees() < checkedroid.TreeCap then
-- we do indeed have less trees than the treecap, so we still need seeds.
else
-- we're not really under construction anymore.  lets reset the metric.
metric[checkedroid.id] = 200
end
end

enemydetected = false
frienddetected = false
gatherpointdetected = false
lowermetricsnearby = false

-- ok.  Am I REALLY still a suitable gather point?
for i = 0, numberofneighbours do
-- check that we're not examining ourself.
if metric[checkedroid.ID] == 200 and neighbours[i].ID ~= checkedroid.id and changedowner == false then
if neighbours[i].owner == checkedroid.owner or neighbours[i].owner == 0 then
-- this asteroid is friendly or neutral to us
frienddetected = true
end

if neighbours[i].owner ~= checkedroid.owner and neighbours[i].owner ~= 0 and neighbours[i]:GetNumTrees() > 0 then
-- this asteroid doesn't belong to us or player 0, and has at least 1 tree.  It must be an enemy roid.
enemydetected = true
end

numberofenemies = neighbours[i]:GetNumSeedlings() - neighbours[i]:GetNumSeedlings(checkedroid.owner)

if neighbours[i].owner ~= checkedroid.owner and neighbours[i]:GetNumTrees() == 0 and numberofenemies > 9 then
-- this asteroid doesn't belong to us, has no trees on it, but has enemy seedlings on it.  Treat it as enemy.
enemydetected = true
end

if neighbours[i].owner == checkedroid.owner and metric[neighbours[i].ID] == 200 then
-- this asteroid is friendly to us, and is a gather point.
gatherpointdetected = true
end

if neighbours[i].owner == checkedroid.owner and metric[neighbours[i].id] < 200 then
-- uh-oh, there's an asteroid nearby with a metric lower than 200.  There are Lower Metrics Nearby!
lowermetricsnearby = true
end
if neighbours[i].owner == 0 and metric[neighbours[i].id] < 200 then
-- uh-oh, there's an asteroid nearby with a metric lower than 200.  There are Lower Metrics Nearby!
lowermetricsnearby = true
end
end

end

if metric[checkedroid.id] == 200 and changedowner == false then

if enemydetected == true and gatherpointdetected == false and lowermetricsnearby == false then
-- the conditions are right for me to continue as a gather point.

else
-- the conditions are no longer right.  Best to reset the metric.
metric[checkedroid.id] = 500
end

end

if frienddetected == false and enemydetected == true and checkedroid:GetNumTrees() == checkedroid.TreeCap then
-- we're an orphan with max trees!  lets become a gather point.
metric[checkedroid.id] = 200
end

-- Actions

-- There are 3 different action types.  We must make sure not to use any actions for players 0 and 1!
-- 1.  Plant trees

-- trap for player 0, exclude player 1
if checkedroid.owner == 0 or checkedroid.owner > 1 then
-- so plant one :>
for i = 2,10 do

if metric[checkedroid.id] == 100 and (checkedroid:GetNumSeedlings() - checkedroid:GetNumSeedlings(i)) < 5 and checkedroid:GetNumSeedlings(i) > 9 then
-- this asteroid isn't owned by greys or player, the enemy only has a bit of seedlings here
-- its metric is 100
-- and it has enough seedlings belonging to the asteroid's empire to plant a tree
a = checkedroid:PlantDysonTree(i)
end
end
end

-- 2.  Send seedlings to the next lowest metric

if metric[checkedroid.id] ~= 0 and metric[checkedroid.id] ~= 100 and metric[checkedroid.id] ~= 500 and checkedroid.owner > 1 then

-- we're not under attack or construction.
numberofdestinations = 0

for i = 0,numberofneighbours do
if neighbours[i].owner == checkedroid.owner or neighbours[i].owner == 0 then
-- this neighbour is one of our asteroids, or it's a blank asteroid

if neighbours[i].owner == checkedroid.owner or neighbours[i].owner == 0 then
if metric[neighbours[i].ID] < metric[checkedroid.ID] then
-- we've found a friendly neighbour with a metric lower than ours!
-- add it to the destinations list
numberofdestinations = numberofdestinations + 1
end
end

end
end

if numberofdestinations > 0 then

-- we've found some destinations to send seeds to.  Lets send some.
numberofseedsleft = checkedroid:GetNumSeedlings(checkedroid.owner) - (checkedroid:GetNumSeedlings() - checkedroid:GetNumSeedlings(checkedroid.owner))
numberperdestination = numberofseedsleft / numberofdestinations

for i = 0,numberofneighbours do
if neighbours[i] ~= checkedroid then
if neighbours[i].owner == checkedroid.owner or neighbours[i].owner == 0 then
if metric[neighbours[i].ID] < metric[checkedroid.ID] then
-- this destination has less than our metric.  This is one of the valid destinations.  Send a proportional amount of seeds to it.
if neighbours[i].owner == 0 and numberofseedsleft < 10 then
-- don't bother sending.

elseif neighbours[i].owner == 0 and neighbours[i]:GetNumSeedlings() - neighbours[i]:GetNumSeedlings(checkedroid.owner) > 0 and numberofseedsleft > 9 + (neighbours[i]:GetNumSeedlings() - neighbours[i]:GetNumSeedlings(checkedroid.owner)) then
-- attack the greys!  (or whoever is camping the roid!)
checkedroid:SendSeedlingsToTarget(checkedroid.owner, checkedroid:GetNumSeedlings(checkedroid.owner), neighbours[i])
numberofseedsleft = 0

elseif neighbours[i].owner == 0 and numberofseedsleft > 9 and (neighbours[i]:GetNumSeedlings() - neighbours[i]:GetNumSeedlings(checkedroid.owner)) == 0 then
-- this is the last we can manage.  Send all 10.
checkedroid:SendSeedlingsToTarget(checkedroid.owner, 10, neighbours[i])
numberofseedsleft = numberofseedsleft - 10

elseif neighbours[i].owner == checkedroid.owner then
checkedroid:SendSeedlingsToTarget(checkedroid.owner, numberperdestination, neighbours[i])
numberofseedsleft = numberofseedsleft - numberperdestination
end
end
end
end
end
end

-- 3.  Attack the weakest nearby asteroid

-- Are we a gather point?  Only gather points are allowed to attack.

if metric[checkedroid.id] == 200 then

totalenemies = 0
totalfriendlies = checkedroid:GetNumSeedlings(checkedroid.owner)
weakestamount = 10000
weakestroid = checkedroid
attack = false
orphan = true
numberofenemyroids = 0

for i = 0,numberofneighbours do

if neighbours[i].owner == checkedroid.owner and neighbours[i] ~= checkedroid then
orphan = false
end

if neighbours[i].owner ~= checkedroid.owner and neighbours[i]:GetNumSeedlings() - neighbours[i]:GetNumSeedlings(checkedroid.owner) > 5 then
-- found an attack path
numberofenemyroids = numberofenemyroids + 1
end

for j = 0,10 do
if checkedroid.owner ~= j then
totalenemies = totalenemies + neighbours[i]:GetNumSeedlings(j)

if weakestamount > neighbours[i]:GetNumSeedlings(j) and neighbours[i].owner == j then
-- the owner of this asteroid has a smaller number of seeds than we've seen before...
weakestamount = neighbours[i]:GetNumSeedlings(j)
weakestroid = neighbours[i]
end

end
end

if neighbours[i] ~= checkedroid and neighbours[i].owner ~= checkedroid.owner then
if neighbours[i]:GetNumSeedlings(checkedroid.owner) > (neighbours[i]:GetNumSeedlings() - neighbours[i]:GetNumSeedlings(checkedroid.owner)) then
-- already attacking, and winning.  send reinforcements.
checkedroid:SendSeedlingsToTarget(checkedroid.owner, checkedroid:GetNumSeedlings(checkedroid.owner), neighbours[i])
end
end
end

-- in the first case, we have more seedlings than all the neighbouring asteroids put together.
if totalfriendlies > totalenemies + (weakestroid:GetNumTrees() * 10) then
attack = true
end

split = false

-- in the second case, we have more than 150 seedlings on this roid, and it's time to move out!
if totalfriendlies > 150 then
attack = true
split = true
end

if totalfriendlies >= Globals.Asteroids.SpawnCap and orphan == true then
attack = true
end

if attack == true and checkedroid.owner > 1 and split == false then
-- ok so we're a gather point, we're ready to attack, and we aren't a player or greys asteroid.
-- lets move out.
checkedroid:SendSeedlingsToTarget(checkedroid.owner, totalfriendlies, weakestroid)
elseif attack == true and checkedroid.owner > 1 and split == true then

for i = 0,numberofneighbours do
if neighbours[i].owner ~= checkedroid.owner then
-- attackable path - send proportional amount of seeds.
checkedroid:SendSeedlingsToTarget(checkedroid.owner, totalfriendlies / numberofenemyroids, neighbours[i])
end
end
end
end
end
-- Set asteroid names to whatever their metric is.  Uncomment the
-- line below for testing purposes if the AI shows unexpected behaviours.
-- checkedroid.Name = metric[checkedroid.ID]
end
-- *** END INFECTED AI : ENGINE ***
end

function AAIInit(empire)

Empire = empire --Which AI empire should the AI control?

Globals.AI.GraceTimer = 9999999
AAINumRoids = -1
AAISelectedRoid = 0
AAIPriority = {}
AAINo_Priority = false
AAILastCheckedOwner = {}
AAITakeBack = {}
AAITakeBackTimer = {}
AAIHaveRoots = {}

for i = 0,100000 do
if GetAsteroid(i) ~= nil then

AAINumRoids = AAINumRoids + 1
AAIPriority[i] = 0
AAITakeBack[i] = false
AAILastCheckedOwner[i] = GetAsteroid(i).Owner
AAIHaveRoots[i] = false

else

break

end

end

end

function AAIEngine()

local HighestEnergy = 0
local HighestStr = 0
local HighestSpeed = 0

for i = 0,AAINumRoids do
if GetAsteroid(i).owner ~= Empire then
GetAsteroid(i):SetGraceTime(0)
else
GetAsteroid(i):SetGraceTime(99999)
if GetAsteroid(i).attribs.energy > HighestEnergy then

HighestEnergy = GetAsteroid(i).attribs.energy

end

if GetAsteroid(i).attribs.strength > HighestStr then

HighestStr = GetAsteroid(i).attribs.strength

end

if GetAsteroid(i).attribs.speed > HighestSpeed then

HighestSpeed = GetAsteroid(i).attribs.speed

end
if AAIHaveRoots[i] == false and GetAsteroid(i):GetNumTrees() > 0 then

AAIHaveRoots[i] = true

end
end
end

AAISelectedRoid = math.random(0,AAINumRoids)
local Numneighbours = 0
local Neighbour = {}

local ChangedOwner = false

if GetAsteroid(AAISelectedRoid).Owner ~= AAILastCheckedOwner[AAISelectedRoid] then

ChangedOwner = true

end

if ChangedOwner == true and AAILastCheckedOwner[AAISelectedRoid] == Empire then

AAITakeBack[AAISelectedRoid] = true
AAITakeBackTimer[AAISelectedRoid] = GetGameTime() + 30

end

if ChangedOwner == true and AAITakeBack[AAISelectedRoid] == true and AAILastCheckedOwner[AAISelectedRoid] ~= Empire and GetAsteroid(AAISelectedRoid).Owner == Empire then

AAITakeBack[AAISelectedRoid] = false
AAITakeBackTimer[AAISelectedRoid] = nil

end

if AAITakeBackTimer[AAISelectedRoid] ~= nil then
if GetGameTime() > AAITakeBackTimer[AAISelectedRoid] then
AAITakeBack[AAISelectedRoid] = false
AAITakeBackTimer[AAISelectedRoid] = nil
end
end

--Flowertime :D No seriously -.-

local Tree = GetAsteroid(AAISelectedRoid):GetRandomDysonTree()

if Tree ~= nil then

Flower = Tree:GetSuperSeedling()

end

if Flower ~= nil and GetAsteroid(AAISelectedRoid).Owner == Empire then

Flower:Pluck()

end

local Flower = GetAsteroid(AAISelectedRoid):GetFlower(Empire)

if Flower ~= nil and GetAsteroid(AAISelectedRoid).Owner == Empire then

Flower:PlantOnRandomDysonTree()

end

--Now as we have the selectedroid here, begin making conditions for priorities to be set...
--First if the ERRoid is attacked, what do we do? We set the priority to zero, so the neighbours know that: "OMGosh, that ERRoid is attacked, help it!"
if GetAsteroid(AAISelectedRoid):GetNumSeedlingsExcluding(Empire) > GetAsteroid(AAISelectedRoid):GetNumSeedlings(Empire)/4 and GetAsteroid(AAISelectedRoid).Owner == Empire and AAIPriority[AAISelectedRoid] > 0 then

AAIPriority[AAISelectedRoid] = 0

elseif AAITakeBack[AAISelectedRoid] == true and AAIPriority[AAISelectedRoid] ~= 0 then

AAIPriority[AAISelectedRoid] = 0

end

if GetAsteroid(AAISelectedRoid):GetMine(1) ~= nil then

AAIPriority[AAISelectedRoid] = 0

end

if GetAsteroid(AAISelectedRoid):GetNumTrees() < GetAsteroid(AAISelectedRoid).TreeCap and GetAsteroid(AAISelectedRoid):GetNumTrees() >= 1 and GetAsteroid(AAISelectedRoid).Owner == Empire and AAIPriority[AAISelectedRoid] > AAINumRoids*2 then

AAIPriority[AAISelectedRoid] = AAINumRoids*2

end

if GetAsteroid(AAISelectedRoid):IsVisible(Empire) ~= true and AAIPriority[AAISelectedRoid] > AAINumRoids*4 then

AAIPriority[AAISelectedRoid] = AAINumRoids*4

end

if GetAsteroid(AAISelectedRoid):GetNumTrees() == 0 and AAIHaveRoots[AAISelectedRoid] == false and AAIPriority[AAISelectedRoid] > AAINumRoids*6 then

AAIPriority[AAISelectedRoid] = AAINumRoids*6

end

if GetAsteroid(AAISelectedRoid).Owner ~= Empire and GetAsteroid(AAISelectedRoid):IsVisible(Empire) == true and GetEmpire(Empire).NumSeedlings > GetAsteroid(AAISelectedRoid):GetNumSeedlingsExcluding(Empire)*1.5 and AAIPriority[AAISelectedRoid] > AAINumRoids*8 then

AAIPriority[AAISelectedRoid] = AAINumRoids*8

end

--Now check if all of the priorities are still correct, so we can decide if we want it to refresh or not...

--Are we still attacked?
if AAIPriority[AAISelectedRoid] == 0 and GetAsteroid(AAISelectedRoid):GetNumSeedlingsExcluding(Empire) == 0 and GetAsteroid(AAISelectedRoid).Owner == Empire and AAITakeBack[AAISelectedRoid] == false and GetAsteroid(AAISelectedRoid):GetMine(1) == nil then

AAIPriority[AAISelectedRoid] = AAINumRoids*10

elseif AAIPriority[AAISelectedRoid] == 0 and GetAsteroid(AAISelectedRoid).Owner ~= Empire and AAIPriority[AAISelectedRoid] == 0 and AAITakeBack[AAISelectedRoid] == false then

AAIPriority[AAISelectedRoid] = AAINumRoids*10

end

if AAIPriority[AAISelectedRoid] == AAINumRoids*2 and GetAsteroid(AAISelectedRoid):GetNumTrees() == GetAsteroid(AAISelectedRoid).TreeCap and GetAsteroid(AAISelectedRoid).Owner == Empire then

AAIPriority[AAISelectedRoid] = AAINumRoids*10

end

if AAIPriority[AAISelectedRoid] == AAINumRoids*4 and GetAsteroid(AAISelectedRoid):IsVisible(Empire) == true then

AAIPriority[AAISelectedRoid] = AAINumRoids*10

end

if AAIPriority[AAISelectedRoid] == AAINumRoids*6 and GetAsteroid(AAISelectedRoid):GetNumTrees() > 0 then

AAIPriority[AAISelectedRoid] = AAINumRoids*10

end

if GetAsteroid(AAISelectedRoid).Owner == Empire and AAIPriority[AAISelectedRoid] == AAINumRoids*8 then

AAIPriority[AAISelectedRoid] = AAINumRoids*10

end

if AAIPriority[AAISelectedRoid] == AAINumRoids*2 and GetAsteroid(AAISelectedRoid):GetNumSeedlings(Empire) >= 10 and GetAsteroid(AAISelectedRoid).Owner == Empire then

GetAsteroid(AAISelectedRoid):PlantDysonTree(Empire)

end

if AAIPriority[AAISelectedRoid] == AAINumRoids*6 and GetAsteroid(AAISelectedRoid):GetNumSeedlings(Empire) >= 10 then

local Lowerstats = 0
if GetAsteroid(AAISelectedRoid).attribs.energy < HighestEnergy/2 then

Lowerstats = Lowerstats+1

end

if GetAsteroid(AAISelectedRoid).attribs.strength < HighestStr/2 then

Lowerstats = Lowerstats+1

end

if GetAsteroid(AAISelectedRoid).attribs.speed < HighestSpeed/2 then

Lowerstats = Lowerstats+1

end

if Lowerstats >= 2 then

GetAsteroid(AAISelectedRoid):PlantDefenseTree(Empire)

else

GetAsteroid(AAISelectedRoid):PlantDysonTree(Empire)

end

end

local Yes_Priority = false
AAINo_Priority = false
local LowestPriority = AAINumRoids*10

--Scanning for every empire, so everyone can see the status for the ERRoid...
for i = 0,AAINumRoids do

if AAIPriority[i] < LowestPriority then

LowestPriority = AAIPriority[i]

end

if i ~= AAISelectedRoid then

--Figuring the distance between the two roids...
Xdif = GetAsteroid(AAISelectedRoid).position.X - GetAsteroid(i).position.X
Ydif = GetAsteroid(AAISelectedRoid).position.Y - GetAsteroid(i).position.Y
Dist = math.abs(math.sqrt((Xdif*Xdif)+(Ydif*Ydif)))

if Dist <= GetAsteroid(AAISelectedRoid).SendDistance+GetAsteroid(i).Radius then
--Ok, we have a neighbour, add it to the list so we can check it for several stuff later!
Numneighbours = Numneighbours+1
Neighbour[Numneighbours] = GetAsteroid(i)
end

end
end

for i = 1,Numneighbours do


if AAIPriority[AAISelectedRoid] > AAIPriority[Neighbour[i].ID] and GetAsteroid(AAISelectedRoid).Owner == Empire then

AAIPriority[AAISelectedRoid] = AAIPriority[Neighbour[i].ID]+1
if AAIPriority[Neighbour[i].ID] == AAINumRoids*8 and GetAsteroid(AAISelectedRoid):GetNumSeedlings(Empire)/1.5 > Neighbour[i]:GetNumSeedlings(Neighbour[i].Owner) then
GetAsteroid(AAISelectedRoid):SendSeedlingsToTarget(Empire, GetAsteroid(AAISelectedRoid):GetNumSeedlings(Empire), GetAsteroid(Neighbour[i].ID))
elseif AAIPriority[Neighbour[i].ID] == 0 and GetAsteroid(AAISelectedRoid):GetNumSeedlings(Empire)/1.5 > Neighbour[i]:GetNumSeedlings(Neighbour[i].Owner) then
GetAsteroid(AAISelectedRoid):SendSeedlingsToTarget(Empire, GetAsteroid(AAISelectedRoid):GetNumSeedlings(Empire), GetAsteroid(Neighbour[i].ID))
elseif AAIPriority[Neighbour[i].ID] ~= AAINumRoids*8 then
GetAsteroid(AAISelectedRoid):SendSeedlingsToTarget(Empire, GetAsteroid(AAISelectedRoid):GetNumSeedlings(Empire), GetAsteroid(Neighbour[i].ID))
end
Yes_Priority = true

elseif AAIPriority[AAISelectedRoid]~=0 and AAIPriority[AAISelectedRoid]~=AAINumRoids*2 and AAIPriority[AAISelectedRoid]~=AAINumRoids*4 and AAIPriority[AAISelectedRoid]~=AAINumRoids*6 and AAIPriority[AAISelectedRoid]~=AAINumRoids*8 and AAIPriority[AAISelectedRoid]~=AAINumRoids*10 then

AAINo_Priority = true

end
end

if Yes_Priority == true and AAINo_Priority == true then

AAINo_Priority = false

end

if AAINo_Priority == true and GetAsteroid(AAISelectedRoid).Owner == Empire then

AAIPriority[AAISelectedRoid] = AAINumRoids*10

end

for sum = 1,5 do
if LowestPriority < AAINumRoids*(sum*2) and LowestPriority > AAINumRoids*((sum*2)-2) and LowestPriority ~= AAINumRoids*(sum*2) then

for i = 0,AAINumRoids do

if AAIPriority[AAISelectedRoid] > AAINumRoids*((sum*2)-2) and AAIPriority[AAISelectedRoid] < AAINumRoids*(sum*2) then

AAIPriority[AAISelectedRoid] = AAINumRoids*10

end
end
end
end

AAILastCheckedOwner[AAISelectedRoid] = GetAsteroid(AAISelectedRoid).Owner

--GetAsteroid(AAISelectedRoid).Name = AAIPriority[AAISelectedRoid]

end

I guess the code will get around 4k lines or more :o

And please don't boother other errors like some stuff missing, I was in the middle of the coding... Gonna fix that :)

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #245 on: June 18, 2011, 04:41:22 PM »
I'm soon going to create the loading of levels for my map, so you can create you own :)

Though, you'll need to learn a few stuff, cause it doesn't come out simple!


Or maybe not... unless someone know how to execute a lua styled file from a lua file... Cause it would be hard to have all the flexability without that :/

EDIT: Atlewast I'll need a day of planning, better start now :D

EDIT2:

I guess a mapfile might look a little like this:

Code: [Select]
Open
"hello, boys, calm down!"
Lost
"do nothing no!"
Win
"lol!"
WinType
"conquest"
AI
"infected"

createroid
random
-1000
1000
random
5000
6000

createroidatt
random
-1000
1000
random
5000
6000
0.8
0.3
0.5

createfield
0
0
5
common
x
random
-10000
10000
y
random
-10000
10000
end

EDIT 3:

My guide:

Code: [Select]
First off, make sure the whole thing is installed correctly!!!

Then you can open the example.map file, which has no content strangely...

Then you can start of by writing something like:

Open
"x"

x is your choice of text, since you make a map, you shouldn't be limited by writing anything...

Just remember: as you write texts, lua "laws" still holds, like a new line is \n and not pressing enter!

An actual new line in the file means that you are going to indicate something new... this means that you cannot do

Open
"I went to the
forest to meet my friends"

because it returns illegal.

To explain this much more I'll explain it the next few lines:

The maploader, does only recognize one line at the time, so it you state Open(short for OpeningText, which is what will appear in the messagebox at start...) the computer will automatically make the next line the OpeningText.
Now if you split it in two lines directly(meaning not with \n) you get the error, because after the line below Open, the computer either expect emptyness or a command...

Now that we know that, let's explore the boundaries of what you can do:


Open
We know that Open is the OpeningTEXT


Win
This is WinTEXT, or the text for the messagebox that appears when you've won!


Lost
This is the LoseTEXT, same deal as win, only difference is that it appears when you lose.


WinType
WinType is how to win, examples are:

"conquest" which is to capture all asteroids

"timeout" waiting some time, this is good for survival maps!

"lose" to make things clear on this one, you need to lose all asteroids to win this map.


AI
This is the AI that runs in the game, you can use both "infected" and "alien".


Time (measured in seconds!)
If the win condition is "timeout" then you must set the time, after this time period, the game ends depending on winningconditions...


Note: When text is quoted, that's how it should appear on the document.


When creating the map you can use:

Note: x and y are co-ordinates!


createroid
x
y


createroidatt
x
y
energy
strength
speed


createfield
x
y
number of roids
common(is written common in the document too, common states what is common with the asteroid in the field!)
x
y


change(change is capable of changing every property of the asteroid as yo can think of...)


Example of uses in "change":

NOTE: Value without anything telling what it is, is a number!


treecap
needs one value


owner
needs one value


numseeds
needs one value


numsuperseeds
needs one value


addtree
needs one text value and one value


moving
needs a boolean value (booleans are true/false!!!!!)


Now as you've seen the commands, let's look at the math!

random
Needs two values, like this:

random
600
1200

random acts as random in Lua, meaning that is only runs whole numbers!


cos
Needs one value!


sin
Needs one value


pi
needs no value, can be used in others!


currentinfield
Calls the current roid in the field(NOT THE ID OF THE ASTEROID!!!)


To the arithmetics, even though you might think it is a simple deal like 1-1, it is not:

for doing a simple calculation like 1-1 you must do

minus
1


useable in arithmetics:

plus (adding)

minus (subtract)

divide (dividing)

times (multiplying)

exponent (multiply by self!)

But, this limits the player pretty much :/

How do you make in-game events???

EDIT 3:

Figured alot of stuff out, for example how to make custom values and then importing it :D

You'll do math at the custom values, nothing else though... But does that matter?
« Last Edit: June 18, 2011, 07:57:51 PM by Aino »

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #246 on: June 18, 2011, 09:31:55 PM »
Wooo!

I'm up to 2k lines already...

But now I am fixing the last of what is needed though, the map loader, which is fairly huge o.O

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #247 on: June 18, 2011, 10:19:04 PM »
Now as I am fully done(hopelyfully D:) I need to get one thing fixed, and it is not about the return, it is the MissionsDone var that is unstable x.x

EDIT: I did it!

It's so retarded that I needed to do it to a numbe... DEEERP... r, I needed to add a... Derp?... tonumber() function to convert it from a... derp -.-... string to number :/

This has been troubling me for aslong as I've been doing this code(apr. one day o.O)

Now I need maps, alot of em' guys/girls!

I'll make a guide soon, just gotta test if all the functions work properly :)

EDIT 2:

Arghhh, need help with the loadmap function, it won't work :/

Code: [Select]
function LoadMap(ID)

if io.open(BasicSaveFolder .. "\\Adventure\\Maps\\" .. MapNames[ID] .. ".map", "r") then

assert(io.input(io.open(BasicSaveFolder .. "\\Adventure\\Maps\\" .. MapNames[ID] .. ".map", "r")))

local activation = nil
local activationlast = 0
local gettingvalue = false
local customvalue = {}
local latestid = nil

for line in io.lines() do

if activation ~= nil then
if activation == "Open" then
OpeningText = line
activationlast = activationlast - 1
if activationlast == 0 then
activation = nil
end
elseif activation == "Win" then
WinMessage = line
activationlast = activationlast - 1
if activationlast == 0 then
activation = nil
end
elseif activation == "Lost" then
LostMessage = line
activationlast = activationlast - 1
if activationlast == 0 then
activation = nil
end
elseif activation == "WinType" then
Win = line
activationlast = activationlast - 1
if activationlast == 0 then
activation = nil
end
elseif activation == "AI" then
AIType = line
activationlast = activationlast - 1
if activationlast == 0 then
activation = nil
end
elseif activation == "Time" then
MapTime = tonumber(line)
activationlast = activationlast - 1
if activationlast == 0 then
activation = nil
end
elseif activation == "createroid" then
if activationlast == 2 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local x = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local x = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 1 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local y = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local y = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
end
if activationlast == 0 then
AddAsteroid(x,y)
activation = nil
end
elseif activation == "createroidatt" then
if activationlast == 5 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local x = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local x = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 4 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local y = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local y = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 3 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local e = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local e = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 2 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local st = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local st = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 1 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local sp = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local sp = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
end
if activationlast == 0 then
AddAsteroidWithAttribs(x,y,e,st,sp)
activation = nil
end
elseif activation == "createroidatt" then
if activationlast == 4 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local x = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local x = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 3 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local y = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local y = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 2 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local num = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local num = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 1 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local size = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local size = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
end
if activationlast == 0 then
for i = 1,num do
AddAsteroid(x+math.random(-size,size),y+math.random(-size,size))
end
activation = nil
end
elseif activation == "createvalue" then
if activationlast == 2 then
local id = tonumber(line)
elseif activationlast == 1 then
local val = tonumber(line)
end
activationlast = activationlast - 1
if activationlast == 0 then
customvalue[id] = val
latestid = id
activation = nil
end
elseif activation == "changeid" then
activationlast = activationlast - 1
if activationlast == 0 then
latestid = tonumber(line)
activation = nil
end
elseif activation == "createsfx" then
if activationlast == 17 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local x = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local x = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 16 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local y = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local y = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 15 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local r = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local r = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 14 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local g = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local g = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 13 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local b = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local b = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 12 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local a = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local a = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 11 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local size = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local size = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 10 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local rd = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local rd = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 9 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local gd = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local gd = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 8 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local bd = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local bd = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 7 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local ad = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local ad = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 6 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local sized = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local sized = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 5 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local rcs = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local rcs = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 4 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local gcs = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local gcs = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 3 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local bcs = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local bcs = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 2 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local acs = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local acs = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 1 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local scs = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local scs = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
end
if activationlast == 0 then
CreateSFX(x,y,r,g,b,a,size,rd,gd,bd,ad,sized,rcs,gcs,bcs,acs,scs)
activation = nil
end
elseif activation == "change" then
if activationlast == 3 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local id = tonumber(line)
activationlast = activationlast - 1
else
gettingvalue = true
end
else
local id = customvalue[tonumber(line)]
gettingvalue = false
activationlast = activationlast - 1
end
elseif activationlast == 2 then
local what = tostring(line)
activationlast = activationlast - 1
elseif activationlast == 1 then
local changeto = line
activationlast = activationlast - 1
end
if activationlast == 0 then
if what == "owner" then
GetAsteroid(id).Owner = changeto
elseif what == "treecap" then
GetAsteroid(id).TreeCap = changeto
elseif what == "addseedlings" then
GetAsteroid(id):AddSeedlings(changeto)
elseif what == "addsuperseedlings" then
GetAsteroid(id):AddSuperSeedlings(changeto)
elseif what == "adddysontree" then
GetAsteroid(id):AddDysonTree()
elseif what == "adddefensetree" then
GetAsteroid(id):AddDefenseTree()
elseif what == "moving" then
GetAsteroid(id).Moveable = changeto

end
activation = nil
end
end
if subactivation == "add" then
if gettingvalue ~= true then
if line ~= "getvalue" then
local val = tonumber(line)
subactivationlast = subactivationlast - 1
else
gettingvalue = true
end
else
local val = customvalue[tonumber(line)]
gettingvalue = false
subactivationlast = subactivationlast - 1
end
subactivationlast = subactivationlast - 1
if subactivationlast == 0 then
customvalue[latestid] = customvalue[latestid] + val
subactivation = nil
end
elseif subactivation == "minus" then
if gettingvalue ~= true then
if line ~= "getvalue" then
local val = tonumber(line)
subactivationlast = subactivationlast - 1
else
gettingvalue = true
end
else
local val = customvalue[tonumber(line)]
gettingvalue = false
subactivationlast = subactivationlast - 1
end
subactivationlast = subactivationlast - 1
if subactivationlast == 0 then
customvalue[latestid] = customvalue[latestid] - val
subactivation = nil
end
elseif subactivation == "times" then
if gettingvalue ~= true then
if line ~= "getvalue" then
local val = tonumber(line)
subactivationlast = subactivationlast - 1
else
gettingvalue = true
end
else
local val = customvalue[tonumber(line)]
gettingvalue = false
subactivationlast = subactivationlast - 1
end
subactivationlast = subactivationlast - 1
if subactivationlast == 0 then
customvalue[latestid] = customvalue[latestid] * val
subactivation = nil
end
elseif subactivation == "divide" then
if gettingvalue ~= true then
if line ~= "getvalue" then
local val = tonumber(line)
subactivationlast = subactivationlast - 1
else
gettingvalue = true
end
else
local val = customvalue[tonumber(line)]
gettingvalue = false
subactivationlast = subactivationlast - 1
end
subactivationlast = subactivationlast - 1
if subactivationlast == 0 then
customvalue[latestid] = customvalue[latestid] / val
subactivation = nil
end
elseif subactivation == "expo" then
if gettingvalue ~= true then
if line ~= "getvalue" then
local val = tonumber(line)
subactivationlast = subactivationlast - 1
else
gettingvalue = true
end
else
local val = customvalue[tonumber(line)]
gettingvalue = false
subactivationlast = subactivationlast - 1
end
subactivationlast = subactivationlast - 1
if subactivationlast == 0 then
customvalue[latestid] = customvalue[latestid]^val
subactivation = nil
end
elseif subactivation == "random" then
if actionlast == 3 then
local id = tostring(line)
elseif subactivationlast == 2 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local val1 = tonumber(line)
subactivationlast = subactivationlast - 1
else
gettingvalue = true
end
else
local val1 = customvalue[tonumber(line)]
gettingvalue = false
subactivationlast = subactivationlast - 1
end
elseif subactivationlast == 1 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local val2 = tonumber(line)
subactivationlast = subactivationlast - 1
else
gettingvalue = true
end
else
local val2 = customvalue[tonumber(line)]
gettingvalue = false
subactivationlast = subactivationlast - 1
end
end
subactivationlast = subactivationlast - 1
if subactivationlast == 0 then
customvalue[id] = math.random(val1,val2)
latestid = id
subactivation = nil
end
elseif subactivation == "sin" then
if actionlast == 2 then
local id = tostring(line)
elseif subactivationlast == 1 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local val1 = tonumber(line)
subactivationlast = subactivationlast - 1
else
gettingvalue = true
end
else
local val1 = customvalue[tonumber(line)]
gettingvalue = false
subactivationlast = subactivationlast - 1
end
end
subactivationlast = subactivationlast - 1
if subactivationlast == 0 then
customvalue[id] = math.sin(val1)
latestid = id
subactivation = nil
end
elseif subactivation == "cos" then
if actionlast == 2 then
local id = tostring(line)
elseif subactivationlast == 1 then
if gettingvalue ~= true then
if line ~= "getvalue" then
local val1 = tonumber(line)
subactivationlast = subactivationlast - 1
else
gettingvalue = true
end
else
local val1 = customvalue[tonumber(line)]
gettingvalue = false
subactivationlast = subactivationlast - 1
end
end
subactivationlast = subactivationlast - 1
if subactivationlast == 0 then
customvalue[id] = math.cos(val1)
latestid = id
subactivation = nil
end
end
else
if line == "Open" then
activation = line
activationlast = 1
elseif line == "Win" then
activation = line
activationlast = 1
elseif line == "Lost" then
activation = line
activationlast = 1
elseif line == "WinType" then
activation = line
activationlast = 1
elseif line == "AI" then
activation = line
activationlast = 1
elseif line == "Time" then
activation = line
activationlast = 1
elseif line == "createroid" then
activation = line
activationlast = 2
elseif line == "createroidatt" then
activation = line
activationlast = 5
elseif line == "createvalue" then
activation = line
activationlast = 2
elseif line == "add" or line == "minus" or line == "divide" or line == "times" or line == "expo" then
subactivation = line
subactivationlast = 1
elseif line == "random" then
subactivation = line
subactivationlast = 3
elseif line == "sin" or line == "cos" then
subactivation = line
subactivationlast = 2
elseif line == "changeid" then
activation = line
activationlast = 1
elseif line == "createfield" then
activation = line
activationlast = 4
elseif line == "createsfx" then
activation = line
activationlast = 17
elseif line == "change" then
activation = line
activationlast = 3

end
end
end
end
end

The error I get, comes particularilry from the createvalue activation :P

It is the customvalue[id] = val that causes it :/
« Last Edit: June 19, 2011, 12:57:15 AM by Aino »

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #248 on: June 21, 2011, 08:27:24 PM »
May it be that local variables disappears as the for loop runs again?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: What are you working on? :D
« Reply #249 on: June 21, 2011, 09:08:45 PM »
http://www.lua.org/pil/4.2.html

Think that might be it.  Make them all global and see if it works.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #250 on: June 21, 2011, 09:12:55 PM »
Gonna do, tommorow :)

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #251 on: June 22, 2011, 02:20:50 PM »
I jsut removed the external map loading thing, causing too many problems -.-'

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #252 on: June 23, 2011, 01:04:40 PM »
Next on to-do list, create a new, less system req. CC :)

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #253 on: June 23, 2011, 01:53:55 PM »
A nice little code for thoose who want it:

Code: [Select]
function DrawHollowBox(x1,y1,x2,y2,r1,g1,b1,a1,r2,g2,b2,a2,size,style)

if style == 1 then --Every next colour :D
DrawLine(x1,y1,x2,y1,r1,b1,g1,a1,r2,b2,g2,a2,size)
DrawLine(x2,y1,x2,y2,r2,b2,g2,a2,r1,b1,g1,a1,size)
DrawLine(x2,y2,x1,y2,r1,b1,g1,a1,r2,b2,g2,a2,size)
DrawLine(x1,y2,x1,y1,r2,b2,g2,a2,r1,b1,g1,a1,size)
elseif style == 2 then --Horizontal fade
DrawLine(x1,y1,x2,y1,r1,b1,g1,a1,r2,b2,g2,a2,size)
DrawLine(x2,y1,x2,y2,r2,b2,g2,a2,r2,b2,g2,a2,size)
DrawLine(x2,y2,x1,y2,r2,b2,g2,a2,r1,b1,g1,a1,size)
DrawLine(x1,y2,x1,y1,r1,b1,g1,a1,r1,b1,g1,a1,size)
elseif style == 3 then --Vertical fade
DrawLine(x1,y1,x2,y1,r1,b1,g1,a1,r1,b1,g1,a1,size)
DrawLine(x2,y1,x2,y2,r1,b1,g1,a1,r2,b2,g2,a2,size)
DrawLine(x2,y2,x1,y2,r2,b2,g2,a2,r2,b2,g2,a2,size)
DrawLine(x1,y2,x1,y1,r2,b2,g2,a2,r1,b1,g1,a1,size)
end
end

Very useful for creating boxes that aren't having just one colour and fills the whole box :)
« Last Edit: June 23, 2011, 02:57:02 PM by Aino »

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #254 on: June 23, 2011, 02:26:43 PM »
This time I'll make CC more advanced, but easier to handle :)

If you have tested the last one, you'll see that Defense is affecting all asteroids, well, I'm trying to make it affect the asteroids with enemies nearby, and if you want, the other asteroids can provide the "threatned" ones with seedlings :)

And the global values won't be shown anymore, if you want to see the current values for the asteroid, hover your mouse over and it will display :)