1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-14 10:13:13 +02:00
RedMew/map_gen/terrain/worms.lua
2018-01-27 15:49:55 +00:00

35 lines
1.1 KiB
Lua

local Task = require "utils.Task"
local worms_per_chunk = 50
local small_worm_spawn_distance = 100
local medium_worm_spawn_distance = 150
local big_worm_spawn_distance = 200
worm_names = {"small-worm-turret","medium-worm-turret","big-worm-turret"}
function spawn_worm(params)
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
Task.queue_task("spawn_worm", {x = top_left.x + math.random(0, 31), y = top_left.y + math.random(0, 31), lvl = lvl})
end
end
end