Merge pull request #208 from Cooldude2606/feature/refactor-spawn-area

Refactor of spawn area, now includes water.
This commit is contained in:
Cooldude2606
2021-04-25 20:19:26 +01:00
committed by GitHub
2 changed files with 280 additions and 230 deletions

View File

@@ -2,37 +2,54 @@
-- @config Spawn-Area -- @config Spawn-Area
return { return {
infinite_ammo_turrets = { --- @setting infinite_ammo_turrets These turrets will have they ammo refilled automatically and can not be looted spawn_area = { --- @setting spawn_area Settings relating to the whole spawn area
enabled=true, --- @setting enabled weather the turrets will be created and refilled deconstruction_radius = 20, --- @setting deconstruction_radius All entities within this radius will be removed
ammo_type='uranium-rounds-magazine', --- @setting ammo_type the ammo type that will be used deconstruction_tile = 'concrete', --- @setting deconstruction_tile Tile to be placed in the deconstruction radius, use nil for map gen
locations={ --- @setting locations locations of all turrets, this is default it can be changed during runtime landfill_radius = 50, --- @setting pattern_radius All water within this radius will be land filled
},
turrets = { --- @setting turrets Settings relating to adding turrets to spawn
enabled = true, --- @setting enabled Whether turrets will be added to spawn
ammo_type = 'uranium-rounds-magazine', --- @setting ammo_type The ammo type that will be used during refills
refill_time = 60*60*5, --- @setting refill_time The time in ticks between each refill of the turrets, only change if having lag issues
offset = { x=0, y=0 }, --- @setting offset The position offset to apply to turrets
locations = { --- @setting locations The locations of all turrets, this list can change during runtime
{surface=1,position={x=-3,y=-3}}, {surface=1,position={x=-3,y=-3}},
{surface=1,position={x=3 ,y=-3}}, {surface=1,position={x= 3,y=-3}},
{surface=1,position={x=-3,y=3 }}, {surface=1,position={x=-3,y= 3}},
{surface=1,position={x=3 ,y=3 }} {surface=1,position={x= 3,y= 3}}
} }
}, },
afk_belts = { --- @setting afk_belts setting relating to afk belts round the spawn point afk_belts = { --- @setting afk_belts Settings relating to adding afk belts to spawn
enabled=true, --- @setting enabled weather afk belts will be generated enabled = true, --- @setting enabled Whether afk belts will be added to spawn
locations={ --- @setting locations top left connors of any afk belt loops to be added belt_type = 'transport-belt', --- @setting belt_type The belt to be used as afk belts
{x=-5,y=-5}, protected = true, --- @setting protected Whether belts will be protected from player interaction
{x=5, y=-5}, offset = { x=0, y=0 }, --- @setting offset The position offset to apply to afk belts
{x=-5,y=5 }, locations={ --- @setting locations The locations to spawn afk belts at, given as the top left position
{x=5, y=5 } {-5, -5}, { 5, -5},
{-5, 5}, { 5, 5}
} }
}, },
corrections = { --- @setting corrections Some settings that have no where else to go water = { --- @setting water Settings relating to adding water to spawn
protect_entities=true, --- @setting protect_entities if the spawn entites will be protected enabled = true, --- @setting enabled Whether water tiles will be added to spawn
offset = {x=0,y=-2}, --- @setting offset a global offset value to correct the x and y values of the tables below water_tile = 'water-mud', --- @setting water_tile The tile to be used as the water tile
deconstruction_radius=20, --- @setting deconstruction_radius when the spawn is made this area will have all entities removed first offset = { x=0, y=0 }, --- @setting offset The position offset to apply to water tiles
deconstruction_tile='concrete', --- @setting deconstruction_tile this is the tile that will spawn in the deconstruction radius locations = { --- @setting locations The location of the water tiles {x,y}
pattern_radius = 50, --- @setting pattern_radius this is the radius of the pattern all water in this area will be filled -- Each is a 3x3 with the closest tile to 0,0 removed
pattern_tile = 'stone-path' --- @setting pattern_tile the tile that is used for the pattern { 7, 8}, { 7, 9 }, { 8, 7}, { 8, 8}, { 8, 9 }, { 9, 7}, { 9, 8}, { 9, 9 }, -- Bottom Right
{ 7, -9}, { 7, -10}, { 8, -8}, { 8, -9}, { 8, -10}, { 9, -8}, { 9, -9}, { 9, -10}, -- Top Right
{-8, -9}, {-8, -10}, {-9, -8}, {-9, -9}, {-9, -10}, {-10, -8}, {-10, -9}, {-10, -10}, -- Top Left
{-8, 8}, {-8, 9 }, {-9, 7}, {-9, 8}, {-9, 9 }, {-10, 7}, {-10, 8}, {-10, 9 }, -- Bottom Left
}
}, },
entities = { --- @setting entities All entities that will be created as part of spawn {entity-name,x-pos,y-pos} entities = { --- @setting entities Settings relating to adding entities to spawn
{"stone-wall",-10,-6},{"stone-wall",-10,-5},{"stone-wall",-10,-4},{"stone-wall",-10,-3},{"stone-wall",-10,-2},{"stone-wall",-10,-1},{"stone-wall",-10,0},{"stone-wall",-10,3},{"stone-wall",-10,4},{"stone-wall",-10,5}, enabled = true, --- @setting enabled Whether entities will be added to spawn
{"stone-wall",-10,6},{"stone-wall",-10,7},{"stone-wall",-10,8},{"stone-wall",-10,9},{"stone-wall",-8,-8},{"small-lamp",-8,-4},{"small-lamp",-8,-1},{"iron-chest",-8,0},{"iron-chest",-8,3},{"small-lamp",-8,4}, protected = true, --- @setting protected Whether entities will be protected from player interaction
{"small-lamp",-8,7},{"stone-wall",-8,11},{"stone-wall",-7,-8},{"small-electric-pole",-7,-2},{"iron-chest",-7,0},{"iron-chest",-7,3},{"small-electric-pole",-7,5},{"stone-wall",-7,11},{"stone-wall",-6,-8},{"small-lamp",-6,-6}, operable = true, --- @setting operable Whether entities can be opened by players, must be true if chests are used
offset = { x=0, y=-2 }, --- @setting offset The position offset to apply to entities
locations = { --- @setting locations The location and names of entities {name,x,y}
{"stone-wall",-10,-5},{"stone-wall",-10,-4},{"stone-wall",-10,-3},{"stone-wall",-10,-2},{"stone-wall",-10,-1},{"stone-wall",-10,0},{"stone-wall",-10,3},{"stone-wall",-10,4},{"stone-wall",-10,5},
{"stone-wall",-10,6},{"stone-wall",-10,7},{"stone-wall",-10,8},{"small-lamp",-8,-4},{"small-lamp",-8,-1},{"iron-chest",-8,0},{"iron-chest",-8,3},{"small-lamp",-8,4},
{"small-lamp",-8,7},{"stone-wall",-7,-8},{"small-electric-pole",-7,-2},{"iron-chest",-7,0},{"iron-chest",-7,3},{"small-electric-pole",-7,5},{"stone-wall",-7,11},{"stone-wall",-6,-8},{"small-lamp",-6,-6},
{"iron-chest",-6,0},{"iron-chest",-6,3},{"small-lamp",-6,9},{"stone-wall",-6,11},{"stone-wall",-5,-8},{"small-lamp",-5,-1},{"iron-chest",-5,0},{"iron-chest",-5,3},{"small-lamp",-5,4},{"stone-wall",-5,11}, {"iron-chest",-6,0},{"iron-chest",-6,3},{"small-lamp",-6,9},{"stone-wall",-6,11},{"stone-wall",-5,-8},{"small-lamp",-5,-1},{"iron-chest",-5,0},{"iron-chest",-5,3},{"small-lamp",-5,4},{"stone-wall",-5,11},
{"stone-wall",-4,-8},{"small-electric-pole",-4,-5},{"iron-chest",-4,0},{"iron-chest",-4,3},{"small-electric-pole",-4,8},{"stone-wall",-4,11},{"stone-wall",-3,-8},{"small-lamp",-3,-6},{"small-lamp",-3,-3},{"small-lamp",-3,6}, {"stone-wall",-4,-8},{"small-electric-pole",-4,-5},{"iron-chest",-4,0},{"iron-chest",-4,3},{"small-electric-pole",-4,8},{"stone-wall",-4,11},{"stone-wall",-3,-8},{"small-lamp",-3,-6},{"small-lamp",-3,-3},{"small-lamp",-3,6},
{"small-lamp",-3,9},{"stone-wall",-3,11},{"stone-wall",-2,-8},{"iron-chest",-2,-6},{"iron-chest",-2,-5},{"iron-chest",-2,-4},{"iron-chest",-2,-3},{"iron-chest",-2,-2},{"iron-chest",-2,5},{"iron-chest",-2,6}, {"small-lamp",-3,9},{"stone-wall",-3,11},{"stone-wall",-2,-8},{"iron-chest",-2,-6},{"iron-chest",-2,-5},{"iron-chest",-2,-4},{"iron-chest",-2,-3},{"iron-chest",-2,-2},{"iron-chest",-2,5},{"iron-chest",-2,6},
@@ -41,11 +58,16 @@ return {
{"stone-wall",2,-8},{"small-lamp",2,-6},{"small-lamp",2,-3},{"small-lamp",2,6},{"small-lamp",2,9},{"stone-wall",2,11},{"stone-wall",3,-8},{"small-electric-pole",3,-5},{"iron-chest",3,0},{"iron-chest",3,3}, {"stone-wall",2,-8},{"small-lamp",2,-6},{"small-lamp",2,-3},{"small-lamp",2,6},{"small-lamp",2,9},{"stone-wall",2,11},{"stone-wall",3,-8},{"small-electric-pole",3,-5},{"iron-chest",3,0},{"iron-chest",3,3},
{"small-electric-pole",3,8},{"stone-wall",3,11},{"stone-wall",4,-8},{"small-lamp",4,-1},{"iron-chest",4,0},{"iron-chest",4,3},{"small-lamp",4,4},{"stone-wall",4,11},{"stone-wall",5,-8},{"small-lamp",5,-6}, {"small-electric-pole",3,8},{"stone-wall",3,11},{"stone-wall",4,-8},{"small-lamp",4,-1},{"iron-chest",4,0},{"iron-chest",4,3},{"small-lamp",4,4},{"stone-wall",4,11},{"stone-wall",5,-8},{"small-lamp",5,-6},
{"iron-chest",5,0},{"iron-chest",5,3},{"small-lamp",5,9},{"stone-wall",5,11},{"stone-wall",6,-8},{"small-electric-pole",6,-2},{"iron-chest",6,0},{"iron-chest",6,3},{"small-electric-pole",6,5},{"stone-wall",6,11}, {"iron-chest",5,0},{"iron-chest",5,3},{"small-lamp",5,9},{"stone-wall",5,11},{"stone-wall",6,-8},{"small-electric-pole",6,-2},{"iron-chest",6,0},{"iron-chest",6,3},{"small-electric-pole",6,5},{"stone-wall",6,11},
{"stone-wall",7,-8},{"small-lamp",7,-4},{"small-lamp",7,-1},{"iron-chest",7,0},{"iron-chest",7,3},{"small-lamp",7,4},{"small-lamp",7,7},{"stone-wall",7,11},{"stone-wall",9,-6},{"stone-wall",9,-5}, {"small-lamp",7,-4},{"small-lamp",7,-1},{"iron-chest",7,0},{"iron-chest",7,3},{"small-lamp",7,4},{"small-lamp",7,7},{"stone-wall",9,-5},
{"stone-wall",9,-4},{"stone-wall",9,-3},{"stone-wall",9,-2},{"stone-wall",9,-1},{"stone-wall",9,0},{"stone-wall",9,3},{"stone-wall",9,4},{"stone-wall",9,5},{"stone-wall",9,6},{"stone-wall",9,7}, {"stone-wall",9,-4},{"stone-wall",9,-3},{"stone-wall",9,-2},{"stone-wall",9,-1},{"stone-wall",9,0},{"stone-wall",9,3},{"stone-wall",9,4},{"stone-wall",9,5},{"stone-wall",9,6},{"stone-wall",9,7},
{"stone-wall",9,8},{"stone-wall",9,9} {"stone-wall",9,8}
}
}, },
tiles = { --- @setting tiles The location of the "pattern" tiles {x-pos,y-pos} pattern = {
enabled = true, --- @setting enabled Whether pattern tiles will be added to spawn
pattern_tile = 'stone-path', --- @setting pattern_tile The tile to be used for the pattern
offset = { x=0, y=-2 }, --- @setting offset The position offset to apply to pattern tiles
locations = { --- @setting locations The location of the pattern tiles {x,y}
{-49,-3},{-49,-2},{-49,1},{-49,2},{-49,5},{-49,6},{-48,-4},{-48,-3},{-48,-2},{-48,1},{-48,2},{-48,5},{-48,6},{-48,7},{-47,-7},{-47,-6},{-47,-5},{-47,-4},{-47,-3},{-47,-2},{-47,5},{-47,6},{-47,7},{-47,8},{-47,9},{-47,10},{-46,-8},{-46,-7},{-46,-6},{-46,-5}, {-49,-3},{-49,-2},{-49,1},{-49,2},{-49,5},{-49,6},{-48,-4},{-48,-3},{-48,-2},{-48,1},{-48,2},{-48,5},{-48,6},{-48,7},{-47,-7},{-47,-6},{-47,-5},{-47,-4},{-47,-3},{-47,-2},{-47,5},{-47,6},{-47,7},{-47,8},{-47,9},{-47,10},{-46,-8},{-46,-7},{-46,-6},{-46,-5},
{-46,-4},{-46,-3},{-46,-2},{-46,-1},{-46,4},{-46,5},{-46,6},{-46,7},{-46,8},{-46,9},{-46,10},{-46,11},{-45,-17},{-45,-16},{-45,-15},{-45,-14},{-45,-13},{-45,-12},{-45,-9},{-45,-8},{-45,-7},{-45,-2},{-45,-1},{-45,0},{-45,1},{-45,2},{-45,3},{-45,4},{-45,5},{-45,10}, {-46,-4},{-46,-3},{-46,-2},{-46,-1},{-46,4},{-46,5},{-46,6},{-46,7},{-46,8},{-46,9},{-46,10},{-46,11},{-45,-17},{-45,-16},{-45,-15},{-45,-14},{-45,-13},{-45,-12},{-45,-9},{-45,-8},{-45,-7},{-45,-2},{-45,-1},{-45,0},{-45,1},{-45,2},{-45,3},{-45,4},{-45,5},{-45,10},
{-45,11},{-45,12},{-45,15},{-45,16},{-45,17},{-45,18},{-45,19},{-45,20},{-44,-18},{-44,-17},{-44,-16},{-44,-15},{-44,-14},{-44,-13},{-44,-12},{-44,-9},{-44,-8},{-44,-1},{-44,0},{-44,1},{-44,2},{-44,3},{-44,4},{-44,11},{-44,12},{-44,15},{-44,16},{-44,17},{-44,18},{-44,19}, {-45,11},{-45,12},{-45,15},{-45,16},{-45,17},{-45,18},{-45,19},{-45,20},{-44,-18},{-44,-17},{-44,-16},{-44,-15},{-44,-14},{-44,-13},{-44,-12},{-44,-9},{-44,-8},{-44,-1},{-44,0},{-44,1},{-44,2},{-44,3},{-44,4},{-44,11},{-44,12},{-44,15},{-44,16},{-44,17},{-44,18},{-44,19},
@@ -154,4 +176,5 @@ return {
{44,17},{44,18},{44,19},{44,20},{45,-8},{45,-7},{45,-6},{45,-5},{45,-4},{45,-3},{45,-2},{45,-1},{45,4},{45,5},{45,6},{45,7},{45,8},{45,9},{45,10},{45,11},{46,-7},{46,-6},{46,-5},{46,-4},{46,-3},{46,-2},{46,5},{46,6},{46,7},{46,8}, {44,17},{44,18},{44,19},{44,20},{45,-8},{45,-7},{45,-6},{45,-5},{45,-4},{45,-3},{45,-2},{45,-1},{45,4},{45,5},{45,6},{45,7},{45,8},{45,9},{45,10},{45,11},{46,-7},{46,-6},{46,-5},{46,-4},{46,-3},{46,-2},{46,5},{46,6},{46,7},{46,8},
{46,9},{46,10},{47,-4},{47,-3},{47,-2},{47,1},{47,2},{47,5},{47,6},{47,7},{48,-3},{48,-2},{48,1},{48,2},{48,5},{48,6} {46,9},{46,10},{47,-4},{47,-3},{47,-2},{47,1},{47,2},{47,5},{47,6},{47,7},{48,-3},{48,-2},{48,1},{48,2},{48,5},{48,6}
} }
}
} }

View File

@@ -4,16 +4,23 @@
local Global = require 'utils.global' --- @dep utils.global local Global = require 'utils.global' --- @dep utils.global
local Event = require 'utils.event' --- @dep utils.event local Event = require 'utils.event' --- @dep utils.event
local config = require 'config.spawn_area' --- @dep config.spawn_area local config = require 'config.spawn_area' --- @dep config.spawn_area
local tiles = config.tiles
local entities = config.entities
local belts = config.afk_belts.locations
local turrets = config.infinite_ammo_turrets.locations
local turrets = config.turrets.locations
Global.register(turrets, function(tbl) Global.register(turrets, function(tbl)
turrets = tbl turrets = tbl
end) end)
-- returns the Spawn force or creates it -- Apply an offset to a LuaPosition
local function apply_offset(position, offset)
return { x = position.x + (offset.x or offset[1]), y = position.y + (offset.y or offset[2]) }
end
-- Apply the offset to the turrets default position
for _, turret in ipairs(turrets) do
turret.position = apply_offset(turret.position, config.turrets.offset)
end
-- Get or create the force used for entities in spawn
local function get_spawn_force() local function get_spawn_force()
local force = game.forces['Spawn'] local force = game.forces['Spawn']
if force and force.valid then return force end if force and force.valid then return force end
@@ -23,7 +30,7 @@ local function get_spawn_force()
return force return force
end end
-- protects and entity so players cant do anything to it -- Protects an entity and sets its force to the spawn force
local function protect_entity(entity, set_force) local function protect_entity(entity, set_force)
if entity and entity.valid then if entity and entity.valid then
entity.destructible = false entity.destructible = false
@@ -35,113 +42,133 @@ local function protect_entity(entity, set_force)
end end
end end
-- handles the infinite ammo turrets -- Will spawn all infinite ammo turrets and keep them refilled
local function spawn_turrets() local function spawn_turrets()
if config.infinite_ammo_turrets.enabled then
for _, turret_pos in pairs(turrets) do for _, turret_pos in pairs(turrets) do
local surface = game.surfaces[turret_pos.surface] local surface = game.surfaces[turret_pos.surface]
local pos = turret_pos.position local pos = turret_pos.position
local turret = surface.find_entity('gun-turret', pos) local turret = surface.find_entity('gun-turret', pos)
-- Makes a new turret if it is not found -- Makes a new turret if it is not found
if not turret or not turret.valid then if not turret or not turret.valid then
turret = surface.create_entity{name='gun-turret', position=pos, force='Spawn'} turret = surface.create_entity{name='gun-turret', position=pos, force='Spawn'}
protect_entity(turret, true) protect_entity(turret, true)
end end
-- adds ammo to the turret
-- Adds ammo to the turret
local inv = turret.get_inventory(defines.inventory.turret_ammo) local inv = turret.get_inventory(defines.inventory.turret_ammo)
if inv.can_insert{name=config.infinite_ammo_turrets.ammo_type, count=10} then if inv.can_insert{name=config.turrets.ammo_type, count=10} then
inv.insert{name=config.infinite_ammo_turrets.ammo_type, count=10} inv.insert{name=config.turrets.ammo_type, count=10}
end
end end
end end
end end
-- makes a 2x2 afk belt where set in config -- Makes a 2x2 afk belt at the locations in the config
local function spawn_belts(surface, position) local function spawn_belts(surface, position)
position = apply_offset(position, config.afk_belts.offset)
local belt_type = config.afk_belts.belt_type
local belt_details = {{-0.5, -0.5, 2}, {0.5, -0.5, 4}, {-0.5, 0.5, 0}, {0.5, 0.5, 6}} -- x, y,dir local belt_details = {{-0.5, -0.5, 2}, {0.5, -0.5, 4}, {-0.5, 0.5, 0}, {0.5, 0.5, 6}} -- x, y,dir
for _, belt_set in pairs(belts) do for _, belt_set in pairs(config.afk_belts.locations) do
local o = position local set_position = apply_offset(position, belt_set)
local p = belt_set
for _, belt in pairs(belt_details) do for _, belt in pairs(belt_details) do
local pos = {x=o.x+p.x+belt[1], y=o.y+p.y+belt[2]} local pos = apply_offset(set_position, belt)
local belt_entity = surface.create_entity{name='transport-belt', position=pos, force='neutral', direction=belt[3]} local belt_entity = surface.create_entity{name=belt_type, position=pos, force='neutral', direction=belt[3]}
protect_entity(belt_entity) if config.afk_belts.protected then protect_entity(belt_entity) end
end end
end end
end end
-- generates an area with no water and removes entities in the decon area -- Generates extra tiles in a set pattern as defined in the config
local function spawn_base(surface, position)
local dr = config.corrections.deconstruction_radius
local dr2 = dr^2
local dtile = config.corrections.deconstruction_tile
local pr = config.corrections.pattern_radius
local pr2 = pr^2
local ptile = surface.get_tile(position).name
if ptile == 'deepwater' or ptile == 'water' then ptile = 'grass-1' end
local tiles_to_make = {}
for x = -pr, pr do -- loop over x
local x2 = x^2
for y = -pr, pr do -- loop over y
local y2 = y^2
local prod = x2+y2
local p = {x=position.x+x, y=position.y+y}
if prod < dr2 then
-- if it is inside the decon radius
table.insert(tiles_to_make, {name=dtile, position=p})
local entities_to_remove = surface.find_entities_filtered{area={{p.x-1, p.y-1}, {p.x, p.y}}}
for _, entity in pairs(entities_to_remove) do
if entity.name ~= 'character' then entity.destroy() end
end
elseif prod < pr2 then
-- if it is inside the pattern radius
table.insert(tiles_to_make, {name=ptile, position=p})
end
end
end
surface.set_tiles(tiles_to_make)
end
-- generates the pattern that is in the config
local function spawn_pattern(surface, position) local function spawn_pattern(surface, position)
position = apply_offset(position, config.pattern.offset)
local tiles_to_make = {} local tiles_to_make = {}
local ptile = config.corrections.pattern_tile local pattern_tile = config.pattern.pattern_tile
local o = config.corrections.offset for _, tile in pairs(config.pattern.locations) do
local p = {x=position.x+o.x, y=position.y+o.y} table.insert(tiles_to_make, {name=pattern_tile, position=apply_offset(position, tile)})
for _, tile in pairs(tiles) do
table.insert(tiles_to_make, {name=ptile, position={tile[1]+p.x, tile[2]+p.y}})
end end
surface.set_tiles(tiles_to_make) surface.set_tiles(tiles_to_make)
end end
-- generates the entities that are in the config -- Generates extra water as defined in the config
local function spawn_water(surface, position)
position = apply_offset(position, config.water.offset)
local tiles_to_make = {}
local water_tile = config.water.water_tile
for _, tile in pairs(config.water.locations) do
table.insert(tiles_to_make, {name=water_tile, position=apply_offset(position, tile)})
end
surface.set_tiles(tiles_to_make)
end
-- Generates the entities that are in the config
local function spawn_entities(surface, position) local function spawn_entities(surface, position)
local o = config.corrections.offset position = apply_offset(position, config.entities.offset)
local p = {x=position.x+o.x, y=position.y+o.y} for _, entity in pairs(config.entities.locations) do
for _, entity in pairs(entities) do local pos = apply_offset(position, { x=entity[2], y=entity[3] })
entity = surface.create_entity{name=entity[1], position={entity[2]+p.x, entity[3]+p.y}, force='neutral'} entity = surface.create_entity{name=entity[1], position=pos, force='neutral'}
protect_entity(entity) if config.entities.protected then protect_entity(entity) end
entity.operable = true entity.operable = config.entities.operable
end end
end end
local refill_time = 60*60*5 -- 5 minutes -- Generates an area with no water or entities, no water area is larger
Event.on_nth_tick(refill_time, function() local function spawn_area(surface, position)
local dr = config.spawn_area.deconstruction_radius
local dr2 = dr^2
local decon_tile = config.spawn_area.deconstruction_tile
local fr = config.spawn_area.landfill_radius
local fr2 = fr^2
local fill_tile = surface.get_tile(position).name
-- Make sure a non water tile is used for each tile
if surface.get_tile(position).collides_with('player-layer') then fill_tile = 'landfill' end
if decon_tile == nil then decon_tile = fill_tile end
local tiles_to_make = {}
for x = -fr, fr do -- loop over x
local x2 = (x+0.5)^2
for y = -fr, fr do -- loop over y
local y2 = (y+0.5)^2
local dst = x2+y2
local pos = {x=position.x+x, y=position.y+y}
if dst < dr2 then
-- If it is inside the decon radius always set the tile
table.insert(tiles_to_make, {name=decon_tile, position=pos})
elseif dst < fr2 and surface.get_tile(pos).collides_with('player-layer') then
-- If it is inside the fill radius only set the tile if it is water
table.insert(tiles_to_make, {name=fill_tile, position=pos})
end
end
end
-- Remove entities then set the tiles
local entities_to_remove = surface.find_entities_filtered{position=position, radius=dr, name='character', invert=true}
for _, entity in pairs(entities_to_remove) do entity.destroy() end
surface.set_tiles(tiles_to_make)
end
-- Only add a event handler if the turrets are enabled
if config.turrets.enabled then
Event.on_nth_tick(config.turrets.refill_time, function()
if game.tick < 10 then return end if game.tick < 10 then return end
spawn_turrets() spawn_turrets()
end) end)
end
-- When the first player joins create the spawn area
Event.add(defines.events.on_player_created, function(event) Event.add(defines.events.on_player_created, function(event)
if event.player_index ~= 1 then return end if event.player_index ~= 1 then return end
local player = game.players[event.player_index] local player = game.players[event.player_index]
local p = {x=0, y=0} local p = {x=0, y=0}
local s = player.surface local s = player.surface
spawn_base(s, p)
spawn_pattern(s, p)
get_spawn_force() get_spawn_force()
spawn_entities(s, p) spawn_area(s, p)
spawn_belts(s, p) if config.pattern.enabled then spawn_pattern(s, p) end
spawn_turrets() if config.water.enabled then spawn_water(s, p) end
if config.afk_belts.enabled then spawn_belts(s, p) end
if config.turrets.enabled then spawn_turrets() end
if config.entities.enabled then spawn_entities(s, p) end
player.teleport(p, s) player.teleport(p, s)
end) end)