2020-01-22 09:30:41 +02:00
|
|
|
local Public = {}
|
2020-04-21 15:13:19 +02:00
|
|
|
local LootRaffle = require "functions.loot_raffle"
|
2020-04-13 06:31:39 +02:00
|
|
|
local BiterRaffle = require "functions.biter_raffle"
|
2019-11-23 12:45:43 +02:00
|
|
|
local bb_config = require "maps.biter_battles_v2.config"
|
2020-04-16 11:42:00 +02:00
|
|
|
|
2020-04-17 07:09:33 +02:00
|
|
|
local table_insert = table.insert
|
2020-02-08 10:32:10 +02:00
|
|
|
local math_floor = math.floor
|
2019-03-13 21:22:21 +02:00
|
|
|
local math_random = math.random
|
2019-11-26 05:17:23 +02:00
|
|
|
local math_abs = math.abs
|
2020-04-16 11:42:00 +02:00
|
|
|
local math_sqrt = math.sqrt
|
|
|
|
|
2020-04-17 15:38:16 +02:00
|
|
|
local GetNoise = require "utils.get_noise"
|
2019-03-13 21:22:21 +02:00
|
|
|
local simplex_noise = require 'utils.simplex_noise'.d2
|
2020-04-14 15:21:13 +02:00
|
|
|
local spawn_circle_size = 39
|
2019-09-18 21:56:43 +02:00
|
|
|
local ores = {"copper-ore", "iron-ore", "stone", "coal"}
|
2019-11-26 05:17:23 +02:00
|
|
|
local rocks = {"sand-rock-big","sand-rock-big","rock-big","rock-big","rock-big","rock-big", "rock-huge"}
|
2019-07-14 21:37:12 +02:00
|
|
|
|
2020-01-28 08:28:51 +02:00
|
|
|
local chunk_tile_vectors = {}
|
|
|
|
for x = 0, 31, 1 do
|
|
|
|
for y = 0, 31, 1 do
|
|
|
|
chunk_tile_vectors[#chunk_tile_vectors + 1] = {x, y}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local size_of_chunk_tile_vectors = #chunk_tile_vectors
|
|
|
|
|
2020-04-17 07:09:33 +02:00
|
|
|
local loading_chunk_vectors = {}
|
|
|
|
for k, v in pairs(chunk_tile_vectors) do
|
|
|
|
if v[1] == 0 or v[1] == 31 or v[2] == 0 or v[2] == 31 then table_insert(loading_chunk_vectors, v) end
|
|
|
|
end
|
|
|
|
|
2019-03-16 21:25:21 +02:00
|
|
|
local function shuffle(tbl)
|
|
|
|
local size = #tbl
|
|
|
|
for i = size, 1, -1 do
|
|
|
|
local rand = math_random(size)
|
|
|
|
tbl[i], tbl[rand] = tbl[rand], tbl[i]
|
|
|
|
end
|
|
|
|
return tbl
|
2019-09-18 21:56:43 +02:00
|
|
|
end
|
|
|
|
|
2019-03-24 06:21:55 +02:00
|
|
|
local function get_noise(name, pos)
|
2020-04-21 15:13:19 +02:00
|
|
|
local seed = game.surfaces["bb_source"].map_gen_settings.seed
|
2019-03-13 21:22:21 +02:00
|
|
|
local noise_seed_add = 25000
|
|
|
|
if name == 1 then
|
2019-12-30 23:50:20 +02:00
|
|
|
local noise = simplex_noise(pos.x * 0.0042, pos.y * 0.0042, seed)
|
2019-03-13 21:22:21 +02:00
|
|
|
seed = seed + noise_seed_add
|
2019-12-30 23:50:20 +02:00
|
|
|
noise = noise + simplex_noise(pos.x * 0.031, pos.y * 0.031, seed) * 0.08
|
|
|
|
seed = seed + noise_seed_add
|
|
|
|
noise = noise + simplex_noise(pos.x * 0.1, pos.y * 0.1, seed) * 0.025
|
2019-03-13 21:22:21 +02:00
|
|
|
return noise
|
2019-03-17 22:39:05 +02:00
|
|
|
end
|
2019-12-30 23:50:20 +02:00
|
|
|
|
2019-03-17 22:39:05 +02:00
|
|
|
if name == 2 then
|
2019-12-30 23:50:20 +02:00
|
|
|
local noise = simplex_noise(pos.x * 0.011, pos.y * 0.011, seed)
|
2019-03-17 22:39:05 +02:00
|
|
|
seed = seed + noise_seed_add
|
2019-12-30 23:50:20 +02:00
|
|
|
noise = noise + simplex_noise(pos.x * 0.08, pos.y * 0.08, seed) * 0.2
|
2019-03-17 22:39:05 +02:00
|
|
|
return noise
|
|
|
|
end
|
2019-12-30 23:50:20 +02:00
|
|
|
|
2019-03-18 15:23:12 +02:00
|
|
|
if name == 3 then
|
2020-04-13 06:31:39 +02:00
|
|
|
local noise = simplex_noise(pos.x * 0.005, pos.y * 0.005, seed)
|
|
|
|
noise = noise + simplex_noise(pos.x * 0.02, pos.y * 0.02, seed) * 0.3
|
|
|
|
noise = noise + simplex_noise(pos.x * 0.15, pos.y * 0.15, seed) * 0.025
|
2019-03-18 15:23:12 +02:00
|
|
|
return noise
|
|
|
|
end
|
2019-03-13 21:22:21 +02:00
|
|
|
end
|
|
|
|
|
2020-01-31 06:52:01 +02:00
|
|
|
local function create_mirrored_tile_chain(surface, tile, count, straightness)
|
|
|
|
if not surface then return end
|
|
|
|
if not tile then return end
|
|
|
|
if not count then return end
|
|
|
|
|
|
|
|
local position = {x = tile.position.x, y = tile.position.y}
|
|
|
|
|
|
|
|
local modifiers = {
|
|
|
|
{x = 0, y = -1},{x = -1, y = 0},{x = 1, y = 0},{x = 0, y = 1},
|
|
|
|
{x = -1, y = 1},{x = 1, y = -1},{x = 1, y = 1},{x = -1, y = -1}
|
|
|
|
}
|
|
|
|
modifiers = shuffle(modifiers)
|
|
|
|
|
|
|
|
for a = 1, count, 1 do
|
|
|
|
local tile_placed = false
|
|
|
|
|
2020-04-16 11:42:00 +02:00
|
|
|
if math_random(0, 100) > straightness then modifiers = shuffle(modifiers) end
|
2020-01-31 06:52:01 +02:00
|
|
|
for b = 1, 4, 1 do
|
|
|
|
local pos = {x = position.x + modifiers[b].x, y = position.y + modifiers[b].y}
|
|
|
|
if surface.get_tile(pos).name ~= tile.name then
|
|
|
|
surface.set_tiles({{name = "landfill", position = pos}}, true)
|
|
|
|
surface.set_tiles({{name = tile.name, position = pos}}, true)
|
2020-04-16 11:42:00 +02:00
|
|
|
--surface.set_tiles({{name = "landfill", position = {pos.x * -1, (pos.y * -1) - 1}}}, true)
|
|
|
|
--surface.set_tiles({{name = tile.name, position = {pos.x * -1, (pos.y * -1) - 1}}}, true)
|
2020-01-31 06:52:01 +02:00
|
|
|
position = {x = pos.x, y = pos.y}
|
|
|
|
tile_placed = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if not tile_placed then
|
|
|
|
position = {x = position.x + modifiers[1].x, y = position.y + modifiers[1].y}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-14 03:00:43 +02:00
|
|
|
local function get_replacement_tile(surface, position)
|
|
|
|
for i = 1, 128, 1 do
|
|
|
|
local vectors = {{0, i}, {0, i * -1}, {i, 0}, {i * -1, 0}}
|
|
|
|
table.shuffle_table(vectors)
|
|
|
|
for k, v in pairs(vectors) do
|
|
|
|
local tile = surface.get_tile(position.x + v[1], position.y + v[2])
|
|
|
|
if not tile.collides_with("resource-layer") then
|
|
|
|
if tile.name ~= "stone-path" then
|
|
|
|
return tile.name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return "grass-1"
|
|
|
|
end
|
|
|
|
|
2019-03-21 11:06:12 +02:00
|
|
|
local function draw_noise_ore_patch(position, name, surface, radius, richness)
|
2019-03-16 21:25:21 +02:00
|
|
|
if not position then return end
|
|
|
|
if not name then return end
|
|
|
|
if not surface then return end
|
|
|
|
if not radius then return end
|
|
|
|
if not richness then return end
|
2020-04-21 15:13:19 +02:00
|
|
|
local seed = game.surfaces["bb_source"].map_gen_settings.seed
|
2019-09-18 21:56:43 +02:00
|
|
|
local noise_seed_add = 25000
|
2019-03-16 21:25:21 +02:00
|
|
|
local richness_part = richness / radius
|
2019-03-21 11:06:12 +02:00
|
|
|
for y = radius * -3, radius * 3, 1 do
|
|
|
|
for x = radius * -3, radius * 3, 1 do
|
2019-11-18 00:29:11 +02:00
|
|
|
local pos = {x = x + position.x + 0.5, y = y + position.y + 0.5}
|
2019-03-21 11:06:12 +02:00
|
|
|
local noise_1 = simplex_noise(pos.x * 0.0125, pos.y * 0.0125, seed)
|
2019-11-18 00:29:11 +02:00
|
|
|
local noise_2 = simplex_noise(pos.x * 0.1, pos.y * 0.1, seed + 25000)
|
2019-03-21 11:06:12 +02:00
|
|
|
local noise = noise_1 + noise_2 * 0.12
|
2020-04-16 11:42:00 +02:00
|
|
|
local distance_to_center = math_sqrt(x^2 + y^2)
|
2019-03-16 21:25:21 +02:00
|
|
|
local a = richness - richness_part * distance_to_center
|
2020-04-16 11:42:00 +02:00
|
|
|
if distance_to_center < radius - math_abs(noise * radius * 0.85) and a > 1 then
|
2019-03-16 21:25:21 +02:00
|
|
|
if surface.can_place_entity({name = name, position = pos, amount = a}) then
|
2019-03-21 11:06:12 +02:00
|
|
|
surface.create_entity{name = name, position = pos, amount = a}
|
2019-11-18 00:29:11 +02:00
|
|
|
for _, e in pairs(surface.find_entities_filtered({position = pos, name = {"wooden-chest", "stone-wall", "gun-turret"}})) do
|
|
|
|
e.destroy()
|
|
|
|
end
|
2019-03-16 21:25:21 +02:00
|
|
|
end
|
2019-09-18 21:56:43 +02:00
|
|
|
end
|
2019-03-16 21:25:21 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-08 03:54:02 +02:00
|
|
|
function is_within_spawn_circle(pos)
|
2019-12-15 10:45:53 +02:00
|
|
|
if math_abs(pos.x) > spawn_circle_size then return false end
|
|
|
|
if math_abs(pos.y) > spawn_circle_size then return false end
|
2020-04-16 11:42:00 +02:00
|
|
|
if math_sqrt(pos.x ^ 2 + pos.y ^ 2) > spawn_circle_size then return false end
|
2019-09-18 21:56:43 +02:00
|
|
|
return true
|
2019-09-08 03:54:02 +02:00
|
|
|
end
|
|
|
|
|
2019-09-16 18:14:27 +02:00
|
|
|
local river_y_1 = bb_config.border_river_width * -1.5
|
|
|
|
local river_y_2 = bb_config.border_river_width * 1.5
|
2020-04-16 11:42:00 +02:00
|
|
|
local river_width_half = math_floor(bb_config.border_river_width * -0.5)
|
2019-09-08 03:54:02 +02:00
|
|
|
function is_horizontal_border_river(pos)
|
2019-09-16 18:14:27 +02:00
|
|
|
if pos.y < river_y_1 then return false end
|
|
|
|
if pos.y > river_y_2 then return false end
|
2019-12-15 10:45:53 +02:00
|
|
|
if pos.y >= river_width_half - (math_abs(get_noise(1, pos)) * 4) then return true end
|
2019-09-18 21:56:43 +02:00
|
|
|
return false
|
2019-03-13 22:39:46 +02:00
|
|
|
end
|
|
|
|
|
2019-12-30 20:46:09 +02:00
|
|
|
local function generate_starting_area(pos, distance_to_center, surface)
|
2019-12-30 21:05:46 +02:00
|
|
|
-- assert(distance_to_center >= spawn_circle_size) == true
|
2020-01-05 20:33:51 +02:00
|
|
|
local spawn_wall_radius = 116
|
|
|
|
local noise_multiplier = 15
|
|
|
|
local min_noise = -noise_multiplier * 1.25
|
2019-09-18 21:56:43 +02:00
|
|
|
|
2019-12-30 23:50:20 +02:00
|
|
|
-- Avoid calculating noise, see comment below
|
2020-01-05 20:33:51 +02:00
|
|
|
if (distance_to_center + min_noise - spawn_wall_radius) > 4.5 then
|
2019-12-30 23:50:20 +02:00
|
|
|
return
|
|
|
|
end
|
2019-09-18 21:56:43 +02:00
|
|
|
|
2020-01-05 20:33:51 +02:00
|
|
|
local noise = get_noise(2, pos) * noise_multiplier
|
|
|
|
local distance_from_spawn_wall = distance_to_center + noise - spawn_wall_radius
|
|
|
|
-- distance_from_spawn_wall is the difference between the distance_to_center (with added noise)
|
|
|
|
-- and our spawn_wall radius (spawn_wall_radius=116), i.e. how far are we from the ring with radius spawn_wall_radius.
|
|
|
|
-- The following shows what happens depending on distance_from_spawn_wall:
|
2019-12-30 23:50:20 +02:00
|
|
|
-- min max
|
|
|
|
-- N/A -10 => replace water
|
|
|
|
-- if noise_2 > -0.5:
|
|
|
|
-- -1.75 0 => wall
|
|
|
|
-- else:
|
|
|
|
-- -6 -3 => 1/16 chance of turrent or turret-remnants
|
|
|
|
-- -1.95 0 => wall
|
2020-01-05 20:33:51 +02:00
|
|
|
-- 0 4.5 => chest-remnants with 1/3, chest with 1/(distance_from_spawn_wall+2)
|
2019-12-30 23:50:20 +02:00
|
|
|
--
|
2020-01-05 20:33:51 +02:00
|
|
|
-- => We never do anything for (distance_to_center + min_noise - spawn_wall_radius) > 4.5
|
2019-09-18 21:56:43 +02:00
|
|
|
|
2020-04-13 06:31:39 +02:00
|
|
|
if distance_from_spawn_wall < 0 then
|
|
|
|
if math_random(1, 100) > 23 then
|
|
|
|
for _, tree in pairs(surface.find_entities_filtered({type = "tree", area = {{pos.x, pos.y}, {pos.x + 1, pos.y + 1}}})) do
|
|
|
|
tree.destroy()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-05 20:33:51 +02:00
|
|
|
if distance_from_spawn_wall < -10 and not is_horizontal_border_river(pos) then
|
2019-12-30 20:46:09 +02:00
|
|
|
local tile_name = surface.get_tile(pos).name
|
|
|
|
if tile_name == "water" or tile_name == "deepwater" then
|
|
|
|
surface.set_tiles({{name = get_replacement_tile(surface, pos), position = pos}}, true)
|
|
|
|
end
|
2019-12-30 23:50:20 +02:00
|
|
|
return
|
2019-12-30 20:46:09 +02:00
|
|
|
end
|
2019-09-18 21:56:43 +02:00
|
|
|
|
2019-12-30 20:46:09 +02:00
|
|
|
if surface.can_place_entity({name = "wooden-chest", position = pos}) and surface.can_place_entity({name = "coal", position = pos}) then
|
|
|
|
local noise_2 = get_noise(3, pos)
|
2020-04-21 15:13:19 +02:00
|
|
|
if noise_2 < 0.40 then
|
|
|
|
if noise_2 > -0.40 then
|
2020-01-05 20:33:51 +02:00
|
|
|
if distance_from_spawn_wall > -1.75 and distance_from_spawn_wall < 0 then
|
2020-04-16 11:42:00 +02:00
|
|
|
local e = surface.create_entity({name = "stone-wall", position = pos, force = "neutral"})
|
|
|
|
e.active = false
|
2019-07-26 21:47:59 +02:00
|
|
|
end
|
2019-12-30 20:46:09 +02:00
|
|
|
else
|
2020-01-05 20:33:51 +02:00
|
|
|
if distance_from_spawn_wall > -1.95 and distance_from_spawn_wall < 0 then
|
2020-04-16 11:42:00 +02:00
|
|
|
local e = surface.create_entity({name = "stone-wall", position = pos, force = "neutral"})
|
|
|
|
e.active = false
|
2019-09-18 21:56:43 +02:00
|
|
|
|
2020-01-05 20:33:51 +02:00
|
|
|
elseif distance_from_spawn_wall > 0 and distance_from_spawn_wall < 4.5 then
|
2019-12-30 20:46:09 +02:00
|
|
|
local name = "wooden-chest"
|
2020-04-17 07:09:33 +02:00
|
|
|
local r_max = math_floor(math.abs(distance_from_spawn_wall)) + 2
|
|
|
|
if math_random(1,3) == 1 and not is_horizontal_border_river(pos) then name = name .. "-remnants" end
|
2020-04-16 11:42:00 +02:00
|
|
|
if math_random(1,r_max) == 1 then
|
|
|
|
local e = surface.create_entity({name = name, position = pos, force = "neutral"})
|
|
|
|
e.active = false
|
|
|
|
end
|
2019-09-18 21:56:43 +02:00
|
|
|
|
2020-01-05 20:33:51 +02:00
|
|
|
elseif distance_from_spawn_wall > -6 and distance_from_spawn_wall < -3 then
|
2019-12-30 20:46:09 +02:00
|
|
|
if math_random(1, 16) == 1 then
|
|
|
|
if surface.can_place_entity({name = "gun-turret", position = pos}) then
|
2020-04-16 11:42:00 +02:00
|
|
|
local e = surface.create_entity({name = "gun-turret", position = pos, force = "neutral"})
|
|
|
|
e.insert({name = "firearm-magazine", count = math_random(6,12)})
|
|
|
|
e.active = false
|
2019-11-18 00:29:11 +02:00
|
|
|
end
|
|
|
|
else
|
2020-04-17 07:09:33 +02:00
|
|
|
if math_random(1, 24) == 1 and not is_horizontal_border_river(pos) then
|
2019-12-30 20:46:09 +02:00
|
|
|
if surface.can_place_entity({name = "gun-turret", position = pos}) then
|
2020-04-16 11:42:00 +02:00
|
|
|
surface.create_entity({name = "gun-turret-remnants", position = pos, force = "neutral"})
|
2019-11-18 00:29:11 +02:00
|
|
|
end
|
2019-03-17 22:39:05 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-18 21:56:43 +02:00
|
|
|
end
|
2019-03-14 19:06:39 +02:00
|
|
|
end
|
|
|
|
end
|
2019-12-30 20:46:09 +02:00
|
|
|
end
|
|
|
|
|
2020-04-16 11:42:00 +02:00
|
|
|
local function generate_river(surface, left_top_x, left_top_y)
|
2020-04-21 15:13:19 +02:00
|
|
|
if left_top_y ~= -32 then return end
|
2019-03-14 19:06:39 +02:00
|
|
|
for x = 0, 31, 1 do
|
|
|
|
for y = 0, 31, 1 do
|
|
|
|
local pos = {x = left_top_x + x, y = left_top_y + y}
|
2020-04-16 11:42:00 +02:00
|
|
|
local distance_to_center = math_sqrt(pos.x ^ 2 + pos.y ^ 2)
|
2020-04-17 07:09:33 +02:00
|
|
|
if is_horizontal_border_river(pos) and distance_to_center > spawn_circle_size - 2 then
|
2019-03-15 04:59:43 +02:00
|
|
|
surface.set_tiles({{name = "deepwater", position = pos}})
|
2020-04-16 11:42:00 +02:00
|
|
|
if math_random(1, 64) == 1 then
|
|
|
|
local e = surface.create_entity({name = "fish", position = pos})
|
|
|
|
e.active = false
|
2019-03-21 11:06:12 +02:00
|
|
|
end
|
|
|
|
end
|
2019-03-16 21:25:21 +02:00
|
|
|
end
|
2020-04-21 15:13:19 +02:00
|
|
|
end
|
2019-03-16 21:25:21 +02:00
|
|
|
end
|
|
|
|
|
2020-02-08 10:32:10 +02:00
|
|
|
local scrap_vectors = {}
|
|
|
|
for x = -5, 5, 1 do
|
|
|
|
for y = -5, 5, 1 do
|
2020-04-16 11:42:00 +02:00
|
|
|
if math_sqrt(x^2 + y^2) <= 5 then
|
2020-02-08 10:32:10 +02:00
|
|
|
scrap_vectors[#scrap_vectors + 1] = {x, y}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local size_of_scrap_vectors = #scrap_vectors
|
|
|
|
|
2019-09-17 07:28:36 +02:00
|
|
|
local function generate_extra_worm_turrets(surface, left_top)
|
2020-04-16 11:42:00 +02:00
|
|
|
local chunk_distance_to_center = math_sqrt(left_top.x ^ 2 + left_top.y ^ 2)
|
2020-04-13 06:31:39 +02:00
|
|
|
if bb_config.bitera_area_distance > chunk_distance_to_center then return end
|
2020-01-28 08:28:51 +02:00
|
|
|
|
2020-04-13 06:31:39 +02:00
|
|
|
local amount = (chunk_distance_to_center - bb_config.bitera_area_distance) * 0.0005
|
2020-01-31 06:52:01 +02:00
|
|
|
if amount < 0 then return end
|
2020-04-16 11:42:00 +02:00
|
|
|
local floor_amount = math_floor(amount)
|
2020-01-28 17:29:51 +02:00
|
|
|
local r = math.round(amount - floor_amount, 3) * 1000
|
|
|
|
if math_random(0, 999) <= r then floor_amount = floor_amount + 1 end
|
2020-01-28 08:28:51 +02:00
|
|
|
|
2020-01-28 17:29:51 +02:00
|
|
|
if floor_amount > 64 then floor_amount = 64 end
|
|
|
|
|
|
|
|
for _ = 1, floor_amount, 1 do
|
2020-04-14 15:21:13 +02:00
|
|
|
local worm_turret_name = BiterRaffle.roll("worm", chunk_distance_to_center * 0.00015)
|
2020-01-28 08:28:51 +02:00
|
|
|
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)
|
2019-09-18 21:56:43 +02:00
|
|
|
if position then
|
2020-04-16 11:42:00 +02:00
|
|
|
local worm = surface.create_entity({name = worm_turret_name, position = position, force = "enemy"})
|
|
|
|
worm.active = false
|
2020-02-08 10:32:10 +02:00
|
|
|
|
|
|
|
-- 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
|
2020-04-16 11:42:00 +02:00
|
|
|
local e = surface.create_entity({name = "mineable-wreckage", position = position, force = "neutral"})
|
|
|
|
e.active = false
|
2020-02-08 10:32:10 +02:00
|
|
|
end
|
2019-07-14 10:30:52 +02:00
|
|
|
end
|
|
|
|
end
|
2020-02-08 10:32:10 +02:00
|
|
|
|
2019-09-18 21:56:43 +02:00
|
|
|
end
|
2019-07-18 15:41:17 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-08 10:32:10 +02:00
|
|
|
local bitera_area_distance = bb_config.bitera_area_distance * -1
|
2020-04-13 06:31:39 +02:00
|
|
|
local biter_area_angle = 0.45
|
|
|
|
|
2019-07-23 17:15:32 +02:00
|
|
|
local function is_biter_area(position)
|
2020-04-17 15:38:16 +02:00
|
|
|
local a = bitera_area_distance - (math_abs(position.x) * biter_area_angle)
|
|
|
|
if position.y - 70 > a then return false end
|
|
|
|
if position.y + 70 < a then return true end
|
|
|
|
if position.y + (get_noise(3, position) * 64) > a then return false end
|
2019-07-23 17:15:32 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2020-04-16 11:42:00 +02:00
|
|
|
local function draw_biter_area(surface, left_top_x, left_top_y)
|
2020-04-17 15:38:16 +02:00
|
|
|
if not is_biter_area({x = left_top_x, y = left_top_y - 96}) then return end
|
2020-02-08 10:32:10 +02:00
|
|
|
|
2020-04-21 15:13:19 +02:00
|
|
|
local seed = game.surfaces["bb_source"].map_gen_settings.seed
|
2020-04-17 15:38:16 +02:00
|
|
|
|
2020-02-08 10:32:10 +02:00
|
|
|
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
|
2020-04-17 15:38:16 +02:00
|
|
|
local index = math_floor(GetNoise("bb_biterland", position, seed) * 48) % 7 + 1
|
2020-02-08 10:32:10 +02:00
|
|
|
out_of_map[i] = {name = "out-of-map", position = position}
|
2020-04-17 15:38:16 +02:00
|
|
|
tiles[i] = {name = "dirt-" .. index, position = position}
|
2020-02-08 10:32:10 +02:00
|
|
|
i = i + 1
|
2020-01-05 20:52:24 +02:00
|
|
|
end
|
|
|
|
end
|
2019-07-14 10:30:52 +02:00
|
|
|
end
|
2020-02-08 10:32:10 +02:00
|
|
|
|
|
|
|
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
|
2019-07-18 15:58:37 +02:00
|
|
|
if math_random(1, 4) == 1 then
|
2020-04-16 11:42:00 +02:00
|
|
|
local e = surface.create_entity({name = "spitter-spawner", position = position, force = "enemy"})
|
|
|
|
e.active = false
|
2019-07-18 15:58:37 +02:00
|
|
|
else
|
2020-04-16 11:42:00 +02:00
|
|
|
local e = surface.create_entity({name = "biter-spawner", position = position, force = "enemy"})
|
|
|
|
e.active = false
|
2019-07-18 15:58:37 +02:00
|
|
|
end
|
2019-09-18 21:56:43 +02:00
|
|
|
end
|
2019-07-18 15:58:37 +02:00
|
|
|
end
|
2020-04-13 06:31:39 +02:00
|
|
|
|
|
|
|
local e = (math_abs(left_top_y) - bb_config.bitera_area_distance) * 0.0005
|
|
|
|
for _ = 1, math_random(3, 6), 1 do
|
2020-02-08 10:32:10 +02:00
|
|
|
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]}
|
2020-04-13 06:31:39 +02:00
|
|
|
local worm_turret_name = BiterRaffle.roll("worm", e)
|
|
|
|
if is_biter_area(position) and surface.can_place_entity({name = worm_turret_name, position = position}) then
|
2020-04-16 11:42:00 +02:00
|
|
|
surface.create_entity({name = worm_turret_name, position = position, force = "enemy"})
|
2020-02-08 10:32:10 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-13 06:31:39 +02:00
|
|
|
for _ = 1, math_random(8, 16), 1 do
|
2020-02-08 10:32:10 +02:00
|
|
|
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
|
2019-07-18 15:41:17 +02:00
|
|
|
end
|
|
|
|
|
2020-04-16 11:42:00 +02:00
|
|
|
local function mixed_ore(surface, left_top_x, left_top_y)
|
2020-04-21 15:13:19 +02:00
|
|
|
local seed = game.surfaces["bb_source"].map_gen_settings.seed
|
2020-04-17 15:38:16 +02:00
|
|
|
|
|
|
|
local noise = GetNoise("bb_ore", {x = left_top_x + 16, y = left_top_y + 16}, seed)
|
|
|
|
|
2019-09-17 07:28:36 +02:00
|
|
|
--Draw noise text values to determine which chunks are valid for mixed ore.
|
2020-04-17 15:38:16 +02:00
|
|
|
--rendering.draw_text{text = noise, surface = game.surfaces.biter_battles, target = {x = left_top_x + 16, y = left_top_y + 16}, color = {255, 255, 255}, scale = 2, font = "default-game"}
|
2019-09-18 21:56:43 +02:00
|
|
|
|
2019-09-17 07:28:36 +02:00
|
|
|
--Skip chunks that are too far off the ore noise value.
|
2020-04-21 15:13:19 +02:00
|
|
|
if noise < 0.42 then return end
|
2019-09-18 21:56:43 +02:00
|
|
|
|
2019-09-17 07:28:36 +02:00
|
|
|
--Draw the mixed ore patches.
|
2019-09-16 18:14:27 +02:00
|
|
|
for x = 0, 31, 1 do
|
|
|
|
for y = 0, 31, 1 do
|
|
|
|
local pos = {x = left_top_x + x, y = left_top_y + y}
|
|
|
|
if surface.can_place_entity({name = "iron-ore", position = pos}) then
|
2020-04-17 15:38:16 +02:00
|
|
|
local noise = GetNoise("bb_ore", pos, seed)
|
2020-04-21 15:13:19 +02:00
|
|
|
if noise > 0.71 then
|
2020-04-17 15:38:16 +02:00
|
|
|
local amount = math_random(1250, 1500) + math_sqrt(pos.x ^ 2 + pos.y ^ 2) * 2
|
2020-04-21 15:13:19 +02:00
|
|
|
local i = math_floor(noise * 20 + math_abs(pos.x) * 0.05) % 4 + 1
|
2019-09-18 21:56:43 +02:00
|
|
|
surface.create_entity({name = ores[i], position = pos, amount = amount})
|
2019-09-16 18:14:27 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-04-16 11:42:00 +02:00
|
|
|
|
|
|
|
if left_top_y == -32 and math_abs(left_top_x) <= 32 then
|
|
|
|
for _, e in pairs(surface.find_entities_filtered({area = {{-12, -12},{12, 12}}})) do e.destroy() end
|
|
|
|
end
|
2019-09-16 18:14:27 +02:00
|
|
|
end
|
|
|
|
|
2020-01-22 09:30:41 +02:00
|
|
|
function Public.generate(event)
|
2019-03-14 23:50:09 +02:00
|
|
|
local surface = event.surface
|
2019-09-17 07:28:36 +02:00
|
|
|
local left_top = event.area.left_top
|
2020-04-16 11:42:00 +02:00
|
|
|
local left_top_x = left_top.x
|
|
|
|
local left_top_y = left_top.y
|
2020-02-08 10:32:10 +02:00
|
|
|
|
2020-04-16 11:42:00 +02:00
|
|
|
if surface.name == "biter_battles" then
|
2020-04-17 07:09:33 +02:00
|
|
|
local tiles = {}
|
|
|
|
if math_abs(left_top_x) > 64 or math_abs(left_top_y) > 64 then
|
|
|
|
for k, v in pairs(loading_chunk_vectors) do tiles[k] = {name = "out-of-map", position = {left_top_x + v[1], left_top_y + v[2]}} end
|
|
|
|
end
|
|
|
|
surface.set_tiles(tiles, false)
|
2020-04-16 11:42:00 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if surface.name ~= "bb_source" then return end
|
|
|
|
|
2020-04-21 15:13:19 +02:00
|
|
|
if left_top_y == 0 then
|
|
|
|
local tiles = {}
|
|
|
|
local i = 0
|
|
|
|
for x = 0, 31, 1 do
|
|
|
|
for y = 0, 31, 1 do
|
|
|
|
i = i + 1
|
|
|
|
tiles[i] = {name = "out-of-map", position = {left_top_x + x, left_top_y + y}}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
surface.set_tiles(tiles, false)
|
2020-04-16 11:42:00 +02:00
|
|
|
return
|
2019-07-13 15:21:12 +02:00
|
|
|
end
|
2020-02-08 10:32:10 +02:00
|
|
|
|
2020-04-21 15:13:19 +02:00
|
|
|
if left_top_y > 0 then return end
|
|
|
|
|
2020-04-16 11:42:00 +02:00
|
|
|
mixed_ore(surface, left_top_x, left_top_y)
|
|
|
|
generate_river(surface, left_top_x, left_top_y)
|
|
|
|
draw_biter_area(surface, left_top_x, left_top_y)
|
2019-09-17 07:28:36 +02:00
|
|
|
generate_extra_worm_turrets(surface, left_top)
|
2020-04-16 11:42:00 +02:00
|
|
|
end
|
2019-09-18 21:56:43 +02:00
|
|
|
|
2020-04-16 11:42:00 +02:00
|
|
|
function Public.draw_spawn_circle(surface)
|
2020-04-17 07:09:33 +02:00
|
|
|
local tiles = {}
|
|
|
|
for x = spawn_circle_size * -1, -1, 1 do
|
|
|
|
for y = spawn_circle_size * -1, -1, 1 do
|
2020-04-16 11:42:00 +02:00
|
|
|
local pos = {x = x, y = y}
|
|
|
|
local distance_to_center = math_sqrt(pos.x ^ 2 + pos.y ^ 2)
|
|
|
|
if distance_to_center <= spawn_circle_size then
|
2020-04-17 07:09:33 +02:00
|
|
|
table_insert(tiles, {name = "deepwater", position = pos})
|
|
|
|
|
2020-04-16 11:42:00 +02:00
|
|
|
if distance_to_center < 9.5 then
|
2020-04-17 07:09:33 +02:00
|
|
|
table_insert(tiles, {name = "refined-concrete", position = pos})
|
2020-04-16 11:42:00 +02:00
|
|
|
if distance_to_center < 7 then
|
2020-04-17 07:09:33 +02:00
|
|
|
table_insert(tiles, {name = "sand-1", position = pos})
|
2020-04-16 11:42:00 +02:00
|
|
|
end
|
2020-04-17 07:09:33 +02:00
|
|
|
-- else
|
|
|
|
--
|
2020-04-16 11:42:00 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-04-17 07:09:33 +02:00
|
|
|
|
|
|
|
for i = 1, #tiles, 1 do
|
|
|
|
table_insert(tiles, {name = tiles[i].name, position = {tiles[i].position.x * -1 - 1, tiles[i].position.y}})
|
|
|
|
end
|
|
|
|
|
|
|
|
surface.set_tiles(tiles, true)
|
|
|
|
|
|
|
|
for i = 1, #tiles, 1 do
|
|
|
|
if tiles[i].name == "deepwater" then
|
|
|
|
if math_random(1, 48) == 1 then
|
|
|
|
local e = surface.create_entity({name = "fish", position = tiles[i].position})
|
|
|
|
e.active = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-04-16 11:42:00 +02:00
|
|
|
end
|
2019-09-18 21:56:43 +02:00
|
|
|
|
2020-04-16 11:42:00 +02:00
|
|
|
function Public.draw_spawn_area(surface)
|
|
|
|
local chunk_r = 4
|
|
|
|
local r = chunk_r * 32
|
|
|
|
|
|
|
|
for x = r * -1, r, 1 do
|
2020-04-16 15:26:46 +02:00
|
|
|
for y = r * -1, -4, 1 do
|
2020-04-16 11:42:00 +02:00
|
|
|
local pos = {x = x, y = y}
|
|
|
|
local distance_to_center = math_sqrt(pos.x ^ 2 + pos.y ^ 2)
|
|
|
|
generate_starting_area(pos, distance_to_center, surface)
|
2019-03-14 23:50:09 +02:00
|
|
|
end
|
2020-04-16 11:42:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
surface.destroy_decoratives({})
|
|
|
|
surface.regenerate_decorative()
|
|
|
|
end
|
2019-09-18 21:56:43 +02:00
|
|
|
|
2020-04-16 11:42:00 +02:00
|
|
|
function Public.generate_additional_spawn_ore(surface)
|
|
|
|
local r = 130
|
|
|
|
local area = {{r * -1, r * -1}, {r, 0}}
|
|
|
|
local ores = {}
|
|
|
|
ores["iron-ore"] = surface.count_entities_filtered({name = "iron-ore", area = area})
|
|
|
|
ores["copper-ore"] = surface.count_entities_filtered({name = "copper-ore", area = area})
|
|
|
|
ores["coal"] = surface.count_entities_filtered({name = "coal", area = area})
|
|
|
|
ores["stone"] = surface.count_entities_filtered({name = "stone", area = area})
|
|
|
|
for ore, ore_count in pairs(ores) do
|
|
|
|
if ore_count < 1000 or ore_count == nil then
|
|
|
|
local pos = {}
|
|
|
|
for a = 1, 32, 1 do
|
|
|
|
pos = {x = -96 + math_random(0, 192), y = -20 - math_random(0, 96)}
|
|
|
|
if surface.can_place_entity({name = "coal", position = pos, amount = 1}) then
|
|
|
|
break
|
2019-03-21 11:06:12 +02:00
|
|
|
end
|
|
|
|
end
|
2020-04-16 11:42:00 +02:00
|
|
|
draw_noise_ore_patch(pos, ore, surface, math_random(18, 24), math_random(1500, 2000))
|
2019-03-21 11:06:12 +02:00
|
|
|
end
|
2020-04-16 11:42:00 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Public.generate_silo(surface)
|
|
|
|
local pos = {x = -32 + math_random(0, 64), y = -72}
|
|
|
|
local mirror_position = {x = pos.x * -1, y = pos.y * -1}
|
|
|
|
|
|
|
|
for _, t in pairs(surface.find_tiles_filtered({area = {{pos.x - 6, pos.y - 6},{pos.x + 6, pos.y + 6}}, name = {"water", "deepwater"}})) do
|
|
|
|
surface.set_tiles({{name = get_replacement_tile(surface, t.position), position = t.position}})
|
|
|
|
end
|
|
|
|
for _, t in pairs(surface.find_tiles_filtered({area = {{mirror_position.x - 6, mirror_position.y - 6},{mirror_position.x + 6, mirror_position.y + 6}}, name = {"water", "deepwater"}})) do
|
|
|
|
surface.set_tiles({{name = get_replacement_tile(surface, t.position), position = t.position}})
|
|
|
|
end
|
|
|
|
|
|
|
|
local silo = surface.create_entity({
|
|
|
|
name = "rocket-silo",
|
|
|
|
position = pos,
|
|
|
|
force = "neutral"
|
|
|
|
})
|
|
|
|
silo.minable = false
|
|
|
|
silo.active = false
|
2019-09-18 21:56:43 +02:00
|
|
|
|
2020-04-16 11:42:00 +02:00
|
|
|
for i = 1, 32, 1 do
|
|
|
|
create_mirrored_tile_chain(surface, {name = "stone-path", position = silo.position}, 32, 10)
|
|
|
|
end
|
|
|
|
|
|
|
|
local p = silo.position
|
|
|
|
for _, entity in pairs(surface.find_entities({{p.x - 4, p.y - 4}, {p.x + 4, p.y + 4}})) do
|
|
|
|
if entity.type == "simple-entity" or entity.type == "tree" or entity.type == "resource" then
|
|
|
|
entity.destroy()
|
|
|
|
end
|
2019-03-14 02:00:20 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-21 15:13:19 +02:00
|
|
|
function Public.generate_spawn_goodies(surface)
|
|
|
|
local tiles = surface.find_tiles_filtered({name = "stone-path"})
|
|
|
|
table.shuffle_table(tiles)
|
|
|
|
local budget = 1500
|
|
|
|
local min_roll = 30
|
|
|
|
local max_roll = 600
|
|
|
|
local blacklist = {
|
|
|
|
["automation-science-pack"] = true,
|
|
|
|
["logistic-science-pack"] = true,
|
|
|
|
["military-science-pack"] = true,
|
|
|
|
["chemical-science-pack"] = true,
|
|
|
|
["production-science-pack"] = true,
|
|
|
|
["utility-science-pack"] = true,
|
|
|
|
["space-science-pack"] = true,
|
2020-04-29 11:06:29 +02:00
|
|
|
["loader"] = true,
|
|
|
|
["fast-loader"] = true,
|
|
|
|
["express-loader"] = true,
|
2020-04-21 15:13:19 +02:00
|
|
|
}
|
|
|
|
local container_names = {"wooden-chest", "wooden-chest", "iron-chest"}
|
|
|
|
for k, tile in pairs(tiles) do
|
|
|
|
if budget <= 0 then return end
|
|
|
|
if surface.can_place_entity({name = "wooden-chest", position = tile.position, force = "neutral"}) then
|
|
|
|
local v = math_random(min_roll, max_roll)
|
|
|
|
local item_stacks = LootRaffle.roll(v, 4, blacklist)
|
|
|
|
local container = surface.create_entity({name = container_names[math_random(1, 3)], position = tile.position, force = "neutral"})
|
|
|
|
for _, item_stack in pairs(item_stacks) do container.insert(item_stack) end
|
|
|
|
budget = budget - v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-14 03:26:54 +02:00
|
|
|
--Landfill Restriction
|
2020-01-22 09:30:41 +02:00
|
|
|
function Public.restrict_landfill(surface, inventory, tiles)
|
2019-03-14 02:35:41 +02:00
|
|
|
for _, t in pairs(tiles) do
|
2020-04-16 11:42:00 +02:00
|
|
|
local distance_to_center = math_sqrt(t.position.x ^ 2 + t.position.y ^ 2)
|
2019-03-14 02:35:41 +02:00
|
|
|
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
|
2019-09-18 21:56:43 +02:00
|
|
|
if is_horizontal_border_river(check_position) or distance_to_center < spawn_circle_size then
|
2019-03-14 02:35:41 +02:00
|
|
|
surface.set_tiles({{name = t.old_tile.name, position = t.position}}, true)
|
|
|
|
inventory.insert({name = "landfill", count = 1})
|
2019-09-18 21:56:43 +02:00
|
|
|
end
|
|
|
|
end
|
2019-03-14 02:35:41 +02:00
|
|
|
end
|
2019-03-13 21:22:21 +02:00
|
|
|
|
2019-03-14 03:26:54 +02:00
|
|
|
--Construction Robot Restriction
|
2019-07-13 16:17:17 +02:00
|
|
|
local robot_build_restriction = {
|
|
|
|
["north"] = function(y)
|
|
|
|
if y >= -10 then return true end
|
|
|
|
end,
|
|
|
|
["south"] = function(y)
|
|
|
|
if y <= 10 then return true end
|
2019-03-14 03:26:54 +02:00
|
|
|
end
|
2019-07-13 16:17:17 +02:00
|
|
|
}
|
|
|
|
|
2020-01-22 09:30:41 +02:00
|
|
|
function Public.deny_construction_bots(event)
|
2019-09-18 21:56:43 +02:00
|
|
|
if not robot_build_restriction[event.robot.force.name] then return end
|
2019-07-13 16:17:17 +02:00
|
|
|
if not robot_build_restriction[event.robot.force.name](event.created_entity.position.y) then return end
|
2019-03-14 03:26:54 +02:00
|
|
|
local inventory = event.robot.get_inventory(defines.inventory.robot_cargo)
|
|
|
|
inventory.insert({name = event.created_entity.name, count = 1})
|
|
|
|
event.robot.surface.create_entity({name = "explosion", position = event.created_entity.position})
|
2019-07-13 16:17:17 +02:00
|
|
|
game.print("Team " .. event.robot.force.name .. "'s construction drone had an accident.", {r = 200, g = 50, b = 100})
|
|
|
|
event.created_entity.destroy()
|
2019-03-14 03:26:54 +02:00
|
|
|
end
|
|
|
|
|
2020-01-22 09:30:41 +02:00
|
|
|
return Public
|