mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-14 02:34:09 +02:00
update
unit spawners are saved in global biter terrain changes random attack angles removed
This commit is contained in:
parent
4ac13ba721
commit
673b6b81bc
@ -2,6 +2,7 @@ local Public = {}
|
||||
local bb_config = require "maps.biter_battles_v2.config"
|
||||
local math_random = math.random
|
||||
|
||||
--[[
|
||||
local vector_radius = 360
|
||||
local attack_vectors = {}
|
||||
attack_vectors.north = {}
|
||||
@ -16,6 +17,7 @@ for x = vector_radius * -1, vector_radius, 1 do
|
||||
end
|
||||
end
|
||||
local size_of_vectors = #attack_vectors.north
|
||||
]]
|
||||
|
||||
local threat_values = {
|
||||
["small-spitter"] = 1.5,
|
||||
@ -175,23 +177,35 @@ Public.send_near_biters_to_silo = function()
|
||||
})
|
||||
end
|
||||
|
||||
local function get_random_spawner(biter_force_name)
|
||||
local spawners = global.unit_spawners[biter_force_name]
|
||||
local size_of_spawners = #spawners
|
||||
|
||||
for _ = 1, 256, 1 do
|
||||
if size_of_spawners == 0 then return end
|
||||
local index = math_random(1, size_of_spawners)
|
||||
local spawner = spawners[index]
|
||||
if spawner and spawner.valid then
|
||||
return spawner
|
||||
else
|
||||
table.remove(spawners, index)
|
||||
size_of_spawners = size_of_spawners - 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function get_random_close_spawner(surface, biter_force_name)
|
||||
local area = whole_spawner_area
|
||||
-- If south_biters: Mirror area along x-axis
|
||||
if biter_force_name == "south_biters" then
|
||||
area = {left_top = {area.left_top[1], -1*area.right_bottom[2]}, right_bottom = {area.right_bottom[1], -1*area.left_top[2]}}
|
||||
end
|
||||
local nearest_spawner = get_random_spawner(biter_force_name)
|
||||
if not nearest_spawner then return end
|
||||
|
||||
local spawners = surface.find_entities_filtered({type = "unit-spawner", force = biter_force_name, area = area})
|
||||
if not spawners[1] then return false end
|
||||
|
||||
local spawner = spawners[math_random(1,#spawners)]
|
||||
for i = 1, 5, 1 do
|
||||
local spawner_2 = spawners[math_random(1,#spawners)]
|
||||
if spawner_2.position.x ^ 2 + spawner_2.position.y ^ 2 < spawner.position.x ^ 2 + spawner.position.y ^ 2 then spawner = spawner_2 end
|
||||
for _ = 1, 16, 1 do
|
||||
local spawner = get_random_spawner(biter_force_name)
|
||||
if spawner.position.x ^ 2 + spawner.position.y ^ 2 < nearest_spawner.position.x ^ 2 + nearest_spawner.position.y ^ 2 then
|
||||
nearest_spawner = spawner
|
||||
end
|
||||
end
|
||||
|
||||
return spawner
|
||||
return nearest_spawner
|
||||
end
|
||||
|
||||
local function select_units_around_spawner(spawner, force_name, biter_force_name)
|
||||
@ -244,6 +258,7 @@ local function send_group(unit_group, force_name, nearest_player_unit)
|
||||
|
||||
local commands = {}
|
||||
|
||||
--[[
|
||||
local vector = attack_vectors[force_name][math_random(1, size_of_vectors)]
|
||||
local position = {target.x + vector[1], target.y + vector[2]}
|
||||
position = unit_group.surface.find_non_colliding_position("stone-furnace", position, 96, 1)
|
||||
@ -257,6 +272,7 @@ local function send_group(unit_group, force_name, nearest_player_unit)
|
||||
}
|
||||
end
|
||||
end
|
||||
]]
|
||||
|
||||
commands[#commands + 1] = {
|
||||
type = defines.command.attack_area,
|
||||
|
@ -31,7 +31,7 @@ function Public.surface()
|
||||
["uranium-ore"] = {frequency = 2, size = 1, richness = 1},
|
||||
["crude-oil"] = {frequency = 3, size = 1, richness = 0.75},
|
||||
["trees"] = {frequency = math.random(8, 16) * 0.1, size = math.random(8, 16) * 0.1, richness = math.random(2, 10) * 0.1},
|
||||
["enemy-base"] = {frequency = 256, size = 0.61, richness = 1}
|
||||
["enemy-base"] = {frequency = 0, size = 0, richness = 0}
|
||||
}
|
||||
game.create_surface("biter_battles", map_gen_settings)
|
||||
|
||||
@ -140,6 +140,9 @@ function Public.forces()
|
||||
global.spectator_rejoin_delay = {}
|
||||
global.spy_fish_timeout = {}
|
||||
global.force_area = {}
|
||||
global.unit_spawners = {}
|
||||
global.unit_spawners.north_biters = {}
|
||||
global.unit_spawners.south_biters = {}
|
||||
global.active_biters = {}
|
||||
global.unit_groups = {}
|
||||
global.biter_raffle = {}
|
||||
|
@ -61,8 +61,8 @@ local entity_copy_functions = {
|
||||
end,
|
||||
["unit-spawner"] = function(surface, entity, mirror_position)
|
||||
local mirror_entity = {name = entity.name, position = mirror_position, direction = direction_translation[entity.direction], force = "south_biters"}
|
||||
if not surface.can_place_entity(mirror_entity) then return end
|
||||
surface.create_entity(mirror_entity)
|
||||
if not surface.can_place_entity(mirror_entity) then return end
|
||||
table.insert(global.unit_spawners.south_biters, surface.create_entity(mirror_entity))
|
||||
end,
|
||||
["turret"] = function(surface, entity, mirror_position)
|
||||
local mirror_entity = {name = entity.name, position = mirror_position, direction = direction_translation[entity.direction], force = "south_biters"}
|
||||
|
@ -1,5 +1,6 @@
|
||||
local Public = {}
|
||||
local bb_config = require "maps.biter_battles_v2.config"
|
||||
local math_floor = math.floor
|
||||
local math_random = math.random
|
||||
local math_abs = math.abs
|
||||
local simplex_noise = require 'utils.simplex_noise'.d2
|
||||
@ -368,12 +369,23 @@ local worm_turrets = {
|
||||
|
||||
local worm_distance_multiplicator = 4
|
||||
|
||||
|
||||
local scrap_vectors = {}
|
||||
for x = -5, 5, 1 do
|
||||
for y = -5, 5, 1 do
|
||||
if math.sqrt(x^2 + y^2) <= 5 then
|
||||
scrap_vectors[#scrap_vectors + 1] = {x, y}
|
||||
end
|
||||
end
|
||||
end
|
||||
local size_of_scrap_vectors = #scrap_vectors
|
||||
|
||||
local function generate_extra_worm_turrets(surface, left_top)
|
||||
local chunk_distance_to_center = math.sqrt(left_top.x ^ 2 + left_top.y ^ 2)
|
||||
if bb_config.bitera_area_distance * worm_distance_multiplicator > chunk_distance_to_center then return end
|
||||
|
||||
local highest_worm_tier = math.floor((chunk_distance_to_center - bb_config.bitera_area_distance * worm_distance_multiplicator) * 0.0015) + 1
|
||||
if highest_worm_tier > 3 then highest_worm_tier = 3 end
|
||||
local highest_worm_tier = math.floor((chunk_distance_to_center - bb_config.bitera_area_distance * worm_distance_multiplicator) * 0.00125) + 1
|
||||
if highest_worm_tier > 4 then highest_worm_tier = 4 end
|
||||
|
||||
local amount = (chunk_distance_to_center - bb_config.bitera_area_distance * worm_distance_multiplicator) * 0.00025
|
||||
if amount < 0 then return end
|
||||
@ -388,104 +400,87 @@ local function generate_extra_worm_turrets(surface, left_top)
|
||||
local v = chunk_tile_vectors[math_random(1, size_of_chunk_tile_vectors)]
|
||||
local position = surface.find_non_colliding_position(worm_turret_name, {left_top.x + v[1], left_top.y + v[2]}, 8, 1)
|
||||
if position then
|
||||
surface.create_entity({name = worm_turret_name, position = position, force = "north_biters"})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local scrap_vectors = {}
|
||||
for x = -5, 5, 1 do
|
||||
for y = -5, 5, 1 do
|
||||
if math.sqrt(x^2 + y^2) <= 5 then
|
||||
scrap_vectors[#scrap_vectors + 1] = {x, y}
|
||||
end
|
||||
end
|
||||
end
|
||||
local size_of_scrap_vectors = #scrap_vectors
|
||||
|
||||
local function generate_scrap(event)
|
||||
local distance_to_center = math.sqrt(event.area.left_top.x ^ 2 + event.area.left_top.y ^ 2)
|
||||
|
||||
local worms = event.surface.find_entities_filtered({area = event.area, type = "turret"})
|
||||
if #worms == 0 then return end
|
||||
|
||||
for _, e in pairs(worms) do
|
||||
if math_random(1,2) == 1 then
|
||||
for c = 1, math_random(2,12), 1 do
|
||||
local vector = scrap_vectors[math_random(1, #scrap_vectors)]
|
||||
local position = {e.position.x + vector[1], e.position.y + vector[2]}
|
||||
if e.surface.can_place_entity({name = "mineable-wreckage", position = position, force = "neutral"}) then
|
||||
e.surface.create_entity({name = "mineable-wreckage", position = position, force = "neutral"})
|
||||
local worm = surface.create_entity({name = worm_turret_name, position = position, force = "north_biters"})
|
||||
|
||||
-- add some scrap piles
|
||||
if math_random(1,2) == 1 then
|
||||
for c = 1, math_random(2,12), 1 do
|
||||
local vector = scrap_vectors[math_random(1, size_of_scrap_vectors)]
|
||||
local position = {position.x + vector[1], position.y + vector[2]}
|
||||
if surface.can_place_entity({name = "mineable-wreckage", position = position, force = "neutral"}) then
|
||||
surface.create_entity({name = "mineable-wreckage", position = position, force = "neutral"})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local bitera_area_distance = bb_config.bitera_area_distance * -1
|
||||
local function is_biter_area(position)
|
||||
--if position.x + position.y > -352 + (get_noise(3, position) * 16) then return false end
|
||||
if position.y + (get_noise(3, position) * 16) > (bb_config.bitera_area_distance * -1) - (math.abs(position.x) * 0.33) then return false end
|
||||
if position.y - 48 > bitera_area_distance - (math_abs(position.x) * 1.10) then return false end
|
||||
|
||||
if position.y + (get_noise(3, position) * 16) > bitera_area_distance - (math_abs(position.x) * 1.10) then return false end
|
||||
return true
|
||||
end
|
||||
|
||||
local biter_area_entity_functions = {
|
||||
["resource"] = function(entity)
|
||||
entity.destroy()
|
||||
end,
|
||||
["unit-spawner"] = function(entity)
|
||||
local vector = scrap_vectors[math_random(1, size_of_scrap_vectors)]
|
||||
local position = entity.surface.find_non_colliding_position("big-worm-turret", {entity.position.x + vector[1], entity.position.y + vector[2]}, 10, 2)
|
||||
if position then
|
||||
if math_random(1, 3) == 1 then
|
||||
entity.surface.create_entity({name = "medium-worm-turret", position = position, force = "north_biters"})
|
||||
else
|
||||
entity.surface.create_entity({name = "big-worm-turret", position = position, force = "north_biters"})
|
||||
local function draw_biter_area(surface, left_top)
|
||||
local left_top_x = left_top.x
|
||||
local left_top_y = left_top.y
|
||||
|
||||
if left_top_y > bb_config.bitera_area_distance * -1 + 32 then return end
|
||||
|
||||
local out_of_map = {}
|
||||
local tiles = {}
|
||||
local i = 1
|
||||
|
||||
for x = 0, 31, 1 do
|
||||
for y = 0, 31, 1 do
|
||||
local position = {x = left_top_x + x, y = left_top_y + y}
|
||||
if is_biter_area(position) then
|
||||
local noise_index = math_floor(math_abs(get_noise(3, position)) * 7) + 1
|
||||
if noise_index > 7 then noise_index = 7 end
|
||||
out_of_map[i] = {name = "out-of-map", position = position}
|
||||
tiles[i] = {name = "dirt-" .. noise_index, position = position}
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
end,
|
||||
["cliff"] = function(entity)
|
||||
entity.destroy()
|
||||
end,
|
||||
["tree"] = function(entity)
|
||||
local noise = get_noise(3, entity.position)
|
||||
if noise > 0.75 then
|
||||
if math_random(1, 5) ~= 1 then entity.surface.create_entity({name = "rock-big", position = entity.position, force = "neutral"}) end
|
||||
end
|
||||
entity.destroy()
|
||||
end,
|
||||
}
|
||||
|
||||
local function builders_area_process_entity(e)
|
||||
if is_biter_area(e.position) then
|
||||
if biter_area_entity_functions[e.type] then
|
||||
biter_area_entity_functions[e.type](e)
|
||||
end
|
||||
else
|
||||
if e.type == "turret" or e.type == "unit-spawner" then
|
||||
e.destroy()
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function builders_area_process_tile(t, surface)
|
||||
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
|
||||
surface.set_tiles({{name = "dirt-" .. noise_index, position = t.position}})
|
||||
|
||||
if math_random(1, 160) == 1 then
|
||||
if t.position.x ^ 2 + t.position.y ^ 2 < 129600 then return end
|
||||
local spawner_position = surface.find_non_colliding_position("biter-spawner", t.position, 8, 1)
|
||||
if spawner_position then
|
||||
|
||||
surface.set_tiles(out_of_map, false)
|
||||
surface.set_tiles(tiles, true)
|
||||
|
||||
for _ = 1, 4, 1 do
|
||||
local v = chunk_tile_vectors[math_random(1, size_of_chunk_tile_vectors)]
|
||||
local position = {x = left_top_x + v[1], y = left_top_y + v[2]}
|
||||
if is_biter_area(position) and surface.can_place_entity({name = "spitter-spawner", position = position}) then
|
||||
if math_random(1, 4) == 1 then
|
||||
surface.create_entity({name = "spitter-spawner", position = spawner_position, force = "north_biters"})
|
||||
table.insert(global.unit_spawners.north_biters, surface.create_entity({name = "spitter-spawner", position = position, force = "north_biters"}))
|
||||
else
|
||||
surface.create_entity({name = "biter-spawner", position = spawner_position, force = "north_biters"})
|
||||
table.insert(global.unit_spawners.north_biters, surface.create_entity({name = "biter-spawner", position = position, force = "north_biters"}))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local highest_worm_tier = math_floor((math_abs(left_top_y) - bb_config.bitera_area_distance) * 0.0035) + 1
|
||||
if highest_worm_tier > 4 then highest_worm_tier = 4 end
|
||||
for _ = 1, 8, 1 do
|
||||
local v = chunk_tile_vectors[math_random(1, size_of_chunk_tile_vectors)]
|
||||
local position = {x = left_top_x + v[1], y = left_top_y + v[2]}
|
||||
if is_biter_area(position) and surface.can_place_entity({name = "medium-worm-turret", position = position}) then
|
||||
local worm_turret_name = worm_turrets[math_random(1, highest_worm_tier)]
|
||||
surface.create_entity({name = worm_turret_name, position = position, force = "north_biters"})
|
||||
end
|
||||
end
|
||||
|
||||
for _ = 1, 16, 1 do
|
||||
local v = chunk_tile_vectors[math_random(1, size_of_chunk_tile_vectors)]
|
||||
local position = {x = left_top_x + v[1], y = left_top_y + v[2]}
|
||||
if is_biter_area(position) and surface.can_place_entity({name = "mineable-wreckage", position = position}) then
|
||||
surface.create_entity({name = "mineable-wreckage", position = position, force = "neutral"})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function mixed_ore(event)
|
||||
@ -563,7 +558,9 @@ function Public.generate(event)
|
||||
mixed_ore(event)
|
||||
generate_river(event)
|
||||
generate_circle_spawn(event)
|
||||
|
||||
|
||||
draw_biter_area(surface, left_top)
|
||||
--[[
|
||||
if bb_config.builders_area then
|
||||
for _, t in pairs(surface.find_tiles_filtered({area = event.area, name = {"water", "deepwater"}})) do
|
||||
builders_area_process_tile(t, surface)
|
||||
@ -572,13 +569,10 @@ function Public.generate(event)
|
||||
builders_area_process_entity(e)
|
||||
end
|
||||
end
|
||||
|
||||
]]
|
||||
|
||||
generate_extra_worm_turrets(surface, left_top)
|
||||
|
||||
if bb_config.random_scrap then
|
||||
generate_scrap(event)
|
||||
end
|
||||
|
||||
if global.bb_spawn_generated then return end
|
||||
if game.tick > 0 then
|
||||
generate_potential_spawn_ore(surface)
|
||||
|
@ -35,9 +35,6 @@ local function update_score_gui(player)
|
||||
|
||||
local score_value = frame_table.children[2]
|
||||
score_value.caption = global.map_score
|
||||
|
||||
local score_value = frame_table.children[4]
|
||||
score_value.caption = global.daytime
|
||||
end
|
||||
|
||||
function Public.update()
|
||||
|
Loading…
Reference in New Issue
Block a user