Untitled diff

Created Diff never expires
6 removals
80 lines
27 additions
101 lines
require "util"
require "util"
require "defines"
require "defines"
require ("config")
require ("config")


script.on_init(function() On_Init() end)
script.on_init(function() On_Init() end)
script.on_configuration_changed(function() On_Init() end)
script.on_configuration_changed(function() On_Init() end)


spawnsPerTick = 3

function On_Init()
function On_Init()
if not global.tick then
if not global.tick then
global.tick = game.tick
global.tick = game.tick
end
if not global.swarmQueue then
global.swarmQueue = {}
end
end
if not global.evoFactorFloor then
if not global.evoFactorFloor then
if game.evolution_factor > 0.995 then
if game.evolution_factor > 0.995 then
global.evoFactorFloor = 10
global.evoFactorFloor = 10
else
else
global.evoFactorFloor = math.floor(game.evolution_factor * 10)
global.evoFactorFloor = math.floor(game.evolution_factor * 10)
end
end
global.tick = global.tick + 1800
global.tick = global.tick + 1800
end
end
if game.entity_prototypes["young-berserk-biter"] then
if game.entity_prototypes["young-berserk-biter"] then
global.DytechDetected = true
global.DytechDetected = true
else
else
global.DytechDetected = false
global.DytechDetected = false
end
end
if game.entity_prototypes["small-biter-Mk2"] then
if game.entity_prototypes["small-biter-Mk2"] then
global.NatEvoDetected = true
global.NatEvoDetected = true
else
else
global.NatEvoDetected = false
global.NatEvoDetected = false
end
end
if game.entity_prototypes["bob-bigger-biter"] then
if game.entity_prototypes["bob-bigger-biter"] then
global.BobsEnemies126Detected = true
global.BobsEnemies126Detected = true
else
else
global.BobsEnemies126Detected = false
global.BobsEnemies126Detected = false
end
end
if game.entity_prototypes["bob-leviathan-biter"] then
if game.entity_prototypes["bob-leviathan-biter"] then
global.BobsEnemies127Detected = true
global.BobsEnemies127Detected = true
else
else
global.BobsEnemies127Detected = false
global.BobsEnemies127Detected = false
end
end
populateTables()
populateTables()
end
end


script.on_event(defines.events.on_entity_died, function(event)
script.on_event(defines.events.on_entity_died, function(event)
if not global.subEnemyNameTable[event.entity.name] then
if not global.subEnemyNameTable[event.entity.name] then
return
return
end
end
if global.tick < event.tick then
if global.tick < event.tick then
if game.evolution_factor > 0.995 then
if game.evolution_factor > 0.995 then
global.evoFactorFloor = 10
global.evoFactorFloor = 10
else
else
global.evoFactorFloor = math.floor(game.evolution_factor * 10)
global.evoFactorFloor = math.floor(game.evolution_factor * 10)
end
end
global.tick = global.tick + 1800
global.tick = global.tick + 1800
end
end
if (unitsSpawnUnitsOnDeath and event.entity.type == "unit") or (spawnersSpawnUnitsOnDeath and event.entity.type == "unit-spawner") then
if (unitsSpawnUnitsOnDeath and event.entity.type == "unit") or (spawnersSpawnUnitsOnDeath and event.entity.type == "unit-spawner") then
spawnSubEnemies(event.entity)
queueSubEnemies(event.entity)
end
end
end)
end)


function spawnSubEnemies(enemy)
function queueSubEnemies(enemy)
local subEnemyName = global.subEnemyNameTable[enemy.name]
local subEnemyName = global.subEnemyNameTable[enemy.name]
if global.subEnemyNameTable[enemy.name][global.evoFactorFloor] then
if global.subEnemyNameTable[enemy.name][global.evoFactorFloor] then
subEnemyName = global.subEnemyNameTable[enemy.name][global.evoFactorFloor]
subEnemyName = global.subEnemyNameTable[enemy.name][global.evoFactorFloor]
end
end
local number = global.subEnemyNumberTable[enemy.name][global.evoFactorFloor]
local number = global.subEnemyNumberTable[enemy.name][global.evoFactorFloor]
for i = 1, number do
for i = 1, number do
local subEnemyPosition = enemy.surface.find_non_colliding_position(subEnemyName, enemy.position, 2 + isSpawner(enemy), 0.5)
table.insert(global.swarmQueue, {surface = enemy.surface, name = subEnemyName, position = enemy.position, force = enemy.force, isspawner = isSpawner(enemy)})
if subEnemyPosition then
-- local subEnemyPosition = enemy.surface.find_non_colliding_position(subEnemyName, enemy.position, 2 + isSpawner(enemy), 0.5)
enemy.surface.create_entity({name = subEnemyName, position = subEnemyPosition, force = enemy.force})
-- if subEnemyPosition then
end
-- enemy.surface.create_entity({name = subEnemyName, position = subEnemyPosition, force = enemy.force})
-- end
end
end
end
end


function isSpawner(enemy)
function isSpawner(enemy)
if enemy.type == "unit-spawner" then
if enemy.type == "unit-spawner" then
return 2
return 2
else
else
return 0
return 0
end
end
end
end

script.on_event(defines.events.on_tick, function(event)
if #(global.swarmQueue) > 0 then
local spawnstodo = math.min(spawnsPerTick, #(global.swarmQueue))
for i = 1, spawnstodo do
newEnemy = table.remove(global.swarmQueue,1)
local subEnemyPosition = newEnemy.surface.find_non_colliding_position(newEnemy.name, newEnemy.position, 2 + newEnemy.isspawner, 0.5)
if subEnemyPosition then
newEnemy.surface.create_entity({name = newEnemy.name, position = subEnemyPosition, force = newEnemy.force})
else
table.insert(global.swarmQueue, {surface = newEnemy.surface, name = newEnemy.name, position = newEnemy.position, force = newEnemy.force, spawner = newEnemy.spawner}) -- we'll try spawning this again later!
end
end
end
end)