2018-01-27 17:49:55 +02:00
|
|
|
local Task = require "utils.Task"
|
2017-10-06 02:14:38 +02:00
|
|
|
|
|
|
|
local worms_per_chunk = 50
|
|
|
|
local small_worm_spawn_distance = 100
|
|
|
|
local medium_worm_spawn_distance = 150
|
|
|
|
local big_worm_spawn_distance = 200
|
|
|
|
|
|
|
|
|
2017-10-15 01:54:20 +02:00
|
|
|
worm_names = {"small-worm-turret","medium-worm-turret","big-worm-turret"}
|
|
|
|
function spawn_worm(params)
|
2017-10-06 02:14:38 +02:00
|
|
|
local x = params.x
|
|
|
|
local y = params.y
|
|
|
|
local lvl = params.lvl
|
|
|
|
local worm_id = math.random(1, lvl)
|
|
|
|
if game.surfaces[1].can_place_entity{name = worm_names[worm_id], position = {x,y}} then
|
|
|
|
if math.sqrt(x*x+y*y) > small_worm_spawn_distance then
|
|
|
|
game.surfaces[1].create_entity{name = worm_names[worm_id], position = {x,y}}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function run_terrain_module(event)
|
|
|
|
local top_left = event.area.left_top
|
|
|
|
local distance = math.sqrt(top_left.x*top_left.x+top_left.y*top_left.y)
|
|
|
|
if distance > small_worm_spawn_distance - 32 then
|
|
|
|
local lvl = 1
|
|
|
|
if distance > medium_worm_spawn_distance then lvl = 2 end
|
|
|
|
if distance > big_worm_spawn_distance then lvl = 3 end
|
|
|
|
for i = 1, worms_per_chunk do
|
2018-01-27 17:49:55 +02:00
|
|
|
Task.queue_task("spawn_worm", {x = top_left.x + math.random(0, 31), y = top_left.y + math.random(0, 31), lvl = lvl})
|
2017-10-06 02:14:38 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|