mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-03-17 20:58:13 +02:00
new module
This commit is contained in:
parent
cd56dd2693
commit
0469ac3de3
@ -199,6 +199,7 @@ event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
|
||||
require "maps.biter_battles_v2.on_tick"
|
||||
require "maps.biter_battles_v2.terrain"
|
||||
require "maps.biter_battles_v2.biters_landfill"
|
||||
require "maps.biter_battles_v2.no_turret_creep"
|
||||
require "maps.biter_battles_v2.chat"
|
||||
require "maps.biter_battles_v2.bb_map_intro"
|
||||
|
67
maps/biter_battles_v2/biters_landfill.lua
Normal file
67
maps/biter_battles_v2/biters_landfill.lua
Normal file
@ -0,0 +1,67 @@
|
||||
-- biters will landfill a tile on death within a certain radius
|
||||
|
||||
local r = 5
|
||||
local vectors = {{0,0}, {1,0}, {0,1}, {-1,0}, {0,-1}}
|
||||
local math_random = math.random
|
||||
|
||||
local function create_particles(surface, position)
|
||||
local m = math_random(8, 12)
|
||||
local m2 = m * 0.005
|
||||
for i = 1, 75, 1 do
|
||||
surface.create_entity({
|
||||
name = "stone-particle",
|
||||
position = position,
|
||||
frame_speed = 0.1,
|
||||
vertical_speed = 0.1,
|
||||
height = 0.1,
|
||||
movement = {m2 - (math_random(0, m) * 0.01), m2 - (math_random(0, m) * 0.01)}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
local function coord_string(x, y)
|
||||
str = tostring(x) .. "_"
|
||||
str = str .. tostring(y)
|
||||
return str
|
||||
end
|
||||
|
||||
local function get_replacement_tile(surface, position)
|
||||
for _, vector in pairs(vectors) do
|
||||
local tile = surface.get_tile({position.x + vector[1], position.y + vector[2]})
|
||||
if not tile.collides_with("resource-layer") then return tile.name end
|
||||
end
|
||||
return "grass-1"
|
||||
end
|
||||
|
||||
local function landfill(surface, entity)
|
||||
local position = {x = math.floor(entity.position.x), y = math.floor(entity.position.y)}
|
||||
local pos_str = coord_string(position.x, position.y)
|
||||
if global.biters_landfill_on_death[pos_str] then return end
|
||||
local tiles = {}
|
||||
for _, tile in pairs(surface.find_tiles_filtered({name = {"water", "deepwater"}, area = {{position.x - r, position.y - r},{position.x + r, position.y + r}}})) do
|
||||
if not is_within_spawn_circle(tile.position) then
|
||||
if not is_horizontal_border_river(tile.position) then
|
||||
tiles[#tiles + 1] = tile
|
||||
end
|
||||
end
|
||||
end
|
||||
if #tiles == 0 then global.biters_landfill_on_death[pos_str] = true return end
|
||||
local p = tiles[math_random(1, #tiles)].position
|
||||
surface.set_tiles({{name = get_replacement_tile(surface, position), position = p}})
|
||||
create_particles(entity.surface, {p.x + 0.5, p.y + 0.5})
|
||||
end
|
||||
|
||||
local function on_entity_died(event)
|
||||
local entity = event.entity
|
||||
if not entity.valid then return end
|
||||
if entity.type ~= "unit" then return end
|
||||
landfill(entity.surface, entity)
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
global.biters_landfill_on_death = {}
|
||||
end
|
||||
|
||||
local event = require 'utils.event'
|
||||
event.on_init(on_init)
|
||||
event.add(defines.events.on_entity_died, on_entity_died)
|
@ -2,7 +2,7 @@ local event = require 'utils.event'
|
||||
local math_random = math.random
|
||||
local simplex_noise = require 'utils.simplex_noise'.d2
|
||||
local create_tile_chain = require "functions.create_tile_chain"
|
||||
local spawn_circle_size = 28
|
||||
local spawn_circle_size = bb_config.border_river_width
|
||||
local ores = {"copper-ore", "iron-ore", "stone", "coal"}
|
||||
|
||||
local function shuffle(tbl)
|
||||
@ -76,7 +76,14 @@ local function draw_noise_ore_patch(position, name, surface, radius, richness)
|
||||
end
|
||||
end
|
||||
|
||||
local function is_horizontal_border_river(surface, pos)
|
||||
function is_within_spawn_circle(pos)
|
||||
if math.abs(pos.x) > spawn_circle_size then return false end
|
||||
if math.abs(pos.y) > spawn_circle_size then return false end
|
||||
if math.sqrt(pos.x ^ 2 + pos.y ^ 2) > spawn_circle_size then return false end
|
||||
return true
|
||||
end
|
||||
|
||||
function is_horizontal_border_river(pos)
|
||||
if pos.y > -5 and pos.x > -5 and pos.x < 5 then return false end
|
||||
if math.floor(bb_config.border_river_width * -0.5) < pos.y + (get_noise(1, pos) * 5) then return true end
|
||||
return false
|
||||
@ -108,7 +115,7 @@ local function generate_circle_spawn(event)
|
||||
end
|
||||
if distance_to_center < 9.5 then tile = "refined-concrete" end
|
||||
if distance_to_center < 7 then tile = "sand-1" end
|
||||
if distance_to_center + noise < r - 24 and distance_to_center > spawn_circle_size and not is_horizontal_border_river(surface, pos) then
|
||||
if distance_to_center + noise < r - 24 and distance_to_center > spawn_circle_size and not is_horizontal_border_river(pos) then
|
||||
local tile_name = surface.get_tile(pos).name
|
||||
if tile_name == "water" or tile_name == "deepwater" then
|
||||
surface.set_tiles({{name = "grass-2", position = pos}}, true)
|
||||
@ -189,7 +196,7 @@ local function generate_river(event)
|
||||
for y = 0, 31, 1 do
|
||||
local pos = {x = left_top_x + x, y = left_top_y + y}
|
||||
local distance_to_center = math.sqrt(pos.x ^ 2 + pos.y ^ 2)
|
||||
if is_horizontal_border_river(surface, pos) then
|
||||
if is_horizontal_border_river(pos) then
|
||||
surface.set_tiles({{name = "deepwater", position = pos}})
|
||||
if math_random(1, 64) == 1 then surface.create_entity({name = "fish", position = pos}) end
|
||||
end
|
||||
@ -351,7 +358,7 @@ local function builders_area_process_entity(e)
|
||||
end
|
||||
|
||||
local function builders_area_process_tile(t, surface)
|
||||
if is_horizontal_border_river(surface, t.position) then return end
|
||||
if is_horizontal_border_river(t.position) then return end
|
||||
if not is_biter_area(t.position) then return end
|
||||
local noise_index = math.floor(math.abs(get_noise(3, t.position)) * 7) + 1
|
||||
if noise_index > 7 then noise_index = 7 end
|
||||
@ -424,7 +431,7 @@ local function restrict_landfill(surface, inventory, tiles)
|
||||
local distance_to_center = math.sqrt(t.position.x ^ 2 + t.position.y ^ 2)
|
||||
local check_position = t.position
|
||||
if check_position.y > 0 then check_position = {x = check_position.x * -1, y = (check_position.y * -1) - 1} end
|
||||
if is_horizontal_border_river(surface, check_position) or distance_to_center < spawn_circle_size then
|
||||
if is_horizontal_border_river(check_position) or distance_to_center < spawn_circle_size then
|
||||
surface.set_tiles({{name = t.old_tile.name, position = t.position}}, true)
|
||||
inventory.insert({name = "landfill", count = 1})
|
||||
end
|
||||
|
60
modules/biters_landfill_on_death.lua
Normal file
60
modules/biters_landfill_on_death.lua
Normal file
@ -0,0 +1,60 @@
|
||||
-- biters will landfill a tile on death within a certain radius
|
||||
|
||||
local r = 6
|
||||
local vectors = {{0,0}, {1,0}, {0,1}, {-1,0}, {0,-1}}
|
||||
local math_random = math.random
|
||||
|
||||
local function create_particles(surface, position)
|
||||
local m = math_random(8, 12)
|
||||
local m2 = m * 0.005
|
||||
for i = 1, 75, 1 do
|
||||
surface.create_entity({
|
||||
name = "stone-particle",
|
||||
position = position,
|
||||
frame_speed = 0.1,
|
||||
vertical_speed = 0.1,
|
||||
height = 0.1,
|
||||
movement = {m2 - (math_random(0, m) * 0.01), m2 - (math_random(0, m) * 0.01)}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
local function coord_string(x, y)
|
||||
str = tostring(x) .. "_"
|
||||
str = str .. tostring(y)
|
||||
return str
|
||||
end
|
||||
|
||||
local function get_replacement_tile(surface, position)
|
||||
for _, vector in pairs(vectors) do
|
||||
local tile = surface.get_tile({position.x + vector[1], position.y + vector[2]})
|
||||
if not tile.collides_with("resource-layer") then return tile.name end
|
||||
end
|
||||
return "grass-1"
|
||||
end
|
||||
|
||||
local function landfill(surface, entity)
|
||||
local position = {x = math.floor(entity.position.x), y = math.floor(entity.position.y)}
|
||||
local pos_str = coord_string(position.x, position.y)
|
||||
if global.biters_landfill_on_death[pos_str] then return end
|
||||
local tiles = surface.find_tiles_filtered({name = {"water", "deepwater"}, area = {{position.x - r, position.y - r},{position.x + r, position.y + r}}})
|
||||
if #tiles == 0 then global.biters_landfill_on_death[pos_str] = true return end
|
||||
local p = tiles[math_random(1, #tiles)].position
|
||||
surface.set_tiles({{name = get_replacement_tile(surface, position), position = p}})
|
||||
create_particles(entity.surface, {p.x + 0.5, p.y + 0.5})
|
||||
end
|
||||
|
||||
local function on_entity_died(event)
|
||||
local entity = event.entity
|
||||
if not entity.valid then return end
|
||||
if entity.type ~= "unit" then return end
|
||||
landfill(entity.surface, entity)
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
global.biters_landfill_on_death = {}
|
||||
end
|
||||
|
||||
local event = require 'utils.event'
|
||||
event.on_init(on_init)
|
||||
event.add(defines.events.on_entity_died, on_entity_died)
|
Loading…
x
Reference in New Issue
Block a user