Apple iPad Best of 2012 Runner Up: Eufloria HD
0 Members and 1 Guest are viewing this topic.
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 for i = 0,100 do a = AddAsteroid(math.random(-10000,10000),math.random(-10000,10000)) if i > 0 and i <= 3 then a.Owner = i a:AddSeedlings(40) else a.Owner = 0 end end AIInit() endfunction LevelLogic() while GameRunning() do AIEngine() coroutine.yield() endendfunction AIInit() --Set the globals correct: Globals.AI.GraceTimer = 9999999 --Create variables needed for the AI --Changeable AI, be sure to change them if you need! AIFaction = {2,3} AINumIterations = 10 AIGraceTime = 5 --Even though this one is here, it doesn't mean all the other normal AI variables work! --Unchangeable, there is no real value to change... AIPriority = {} AINumFactions = 0 AINumRoids = -1 AINeighbour = {} AINumNeighbours = {} Engine = AIEngine() --Run through all possible factions and chack if they are included, this way we can make the matrices for priorities. for i = 1,10 do if AIFaction[i] ~= nil then AINumFactions = AINumFactions + 1 AIPriority[i] = {} else break; end end --Run from 0 to a high number(more than what you would want as asteroids on a map) to find any asteroid. for i = 0,1000 do if GetAsteroid(i) ~= nil then --Set all variables for the asteroids... AINumRoids = AINumRoids + 1 AINumNeighbours[i] = 0 AINeighbour[i] = {} for j = 1,AINumFactions do AIPriority[AIFaction[j]][i] = 1000 end else break; end endendfunction AIEngine() --If the gracetime is over and the AI hasn't checked yet, then the AI must do so! if GetGameTime() > AIGraceTime and AIChecked ~= true then --The AI will run through all of the asteroids twice to find any neighbouring asteroids. for i = 0,AINumRoids do for j = 0,AINumRoids do if i ~= j then local Xd = GetAsteroid(i).position.x-GetAsteroid(j).position.x local Yd = GetAsteroid(i).position.y-GetAsteroid(j).position.y local dist = (Xd^2)+(Yd^2) if dist < GetAsteroid(i).SendDistance+GetAsteroid(j).Radius then --As a match occours, it will make the asteroid a neighbour so the AI understands it. AINumNeighbours[i] = AINumNeighbours[i] + 1 AINeighbour[i][AINumNeighbours[i]] = GetAsteroid(j) end end end end AIChecked = true else --The gracetime is over and the AI has checked, then we iterate the chosen amount of times and... for iteration = 1,AINumIterations do --Choose a random asteroid to check: local roid = GetAsteroid(math.random(0,AINumRoids)) --But also include the ID for simplicity: local roidid = roid.ID --Now run through all of the factions, to allow them to change the priority of the roids for factionid = 1,AINumFactions do local faction = AIFaction[factionid] local ChangedPriority = false --Check wether the faction owns the asteroid or not. if roid.Owner == faction then --Check conditions on the asteroid: if roid:GetNumSeedlingsExcluding(faction) > roid:GetNumSeedlings(faction)/4 then --The AI found out that the asteroid is under attack, so we must set the priority to lowest possible, 0! if AIPriority[faction][roidid] ~= 0 then AIPriority[faction][roidid] = 0 ChangedPriority = true end elseif roid:GetNumSeedlingsExcluding(faction) == 0 then if AIPriority[faction][roidid] == 0 then --We're not under attack, but our priority still says so, let's get rid of that! AIPriority[faction][roidid] = AINumRoids*4 ChangedPriority = true end end if roid:GetNumTrees() < roid.TreeCap then if AIPriority[faction][roidid] > AINumRoids*1 then --We need trees and our priority is high enough to not reset any attack priorities! AIPriority[faction][roidid] = AINumRoids*1 ChangedPriority = true if roid:GetNumSeedlings(faction) >= 10 then roid:PlantDysonTree() end end else if AIPriority[faction][roidid] == AINumRoids*1 then --We don't need trees, but our priority says so, let's get rid of that! AIPriority[faction][roidid] = AINumRoids*4 ChangedPriority = true end end else end if ChangedPriority == true then --If we changed any priority, we have to reset all the other, "meaningless" priorities... for checkedroid = 0,AINumRoids do if AIPriority[faction][checkedroid] ~= 0 and AIPriority[faction][checkedroid] ~= AINumRoids*1 and AIPriority[faction][checkedroid] ~= AINumRoids*2 and AIPriority[faction][checkedroid] ~= AINumRoids*3 then AIPriority[faction][checkedroid] = AINumRoids*4 end end else --if we didn't then we must check the neighbours of all asteroids if they are important. for checked = 0,AINumRoids do local checkedroid = GetAsteroid(i) if checkedroid.Owner == faction then for j = 1,AINumNeighbours[checked] do if AIPriority[faction][AINeighbour[checked][j].ID] < AIPriority[faction][checked] then AIPriority[faction][checked] = AIPriority[faction][AINeighbour[checked][j].ID] + 1 if AIPriority[faction][AINeighbour[checked][j].ID] ~= AINumRoids*3 then if checkedroid:GetNumSeedlings(faction) > 0 then checkedroid:SendSeedlingsToTarget(faction,checkedroid:GetNumSeedlings(faction),AINeighbour[checked][j]) end end end end end end end end end endend
I've never actually played WoW (yes, I mean World of Warcraft), but I have seen the effects of it, viz. lack of any productive work. Minecraft on the other hand...