1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-08 00:39:30 +02:00

spawn ores

This commit is contained in:
MewMew 2019-03-21 10:06:12 +01:00
parent b566e66770
commit c944d5fca7
7 changed files with 142 additions and 53 deletions

View File

@ -3,14 +3,14 @@ local math_random = math.random
local ai = {}
local threat_values = {
["small-spitter"] = 1.5,
["small-biter"] = 1.5,
["small-spitter"] = 2,
["small-biter"] = 2,
["medium-spitter"] = 4,
["medium-biter"] = 4,
["big-spitter"] = 8,
["big-biter"] = 8,
["behemoth-spitter"] = 32,
["behemoth-biter"] = 32
["behemoth-spitter"] = 24,
["behemoth-biter"] = 24
}
local function shuffle(tbl)
@ -67,7 +67,7 @@ local function select_units_around_spawner(spawner, force_name, biter_force_name
local biters = spawner.surface.find_enemy_units(spawner.position, 160, force_name)
if not biters[1] then return false end
local valid_biters = {}
local size = math_random(2, 6) * 0.1
local size = math_random(2, 5) * 0.1
local threat = global.bb_threat[biter_force_name] * size
for _, biter in pairs(biters) do
if biter.force.name == biter_force_name then

View File

@ -28,6 +28,42 @@ local function destroy_entity(e)
e.die()
end
local function create_kaboom(surface, pos)
surface.create_entity({
name = "explosive-cannon-projectile",
position = pos,
force = "enemy",
target = pos,
speed = 1
})
end
local function annihilate_base_v2(center_pos, surface, force_name)
local positions = {}
for x = -80, 80, 1 do
for y = -80, 80, 1 do
local pos = {x = center_pos.x + x, y = center_pos.y + y}
local distance_to_center = math.ceil(math.sqrt((pos.x - center_pos.x)^2 + (pos.y - center_pos.y)^2))
if distance_to_center < 52 and math.random(1,5) == 1 then
if not positions[distance_to_center] then positions[distance_to_center] = {} end
positions[distance_to_center][#positions[distance_to_center] + 1] = pos
end
end
end
if #positions == 0 then return end
local t = 1
for i1, pos_list in pairs(positions) do
for i2, pos in pairs(pos_list) do
if not global.on_tick_schedule[game.tick + t] then global.on_tick_schedule[game.tick + t] = {} end
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = create_kaboom,
args = {surface, pos}
}
end
t = t + 4
end
end
local function annihilate_base(center_pos, surface, force_name)
local entities = {}
for _, e in pairs(surface.find_entities_filtered({force = force_name, area = {{center_pos.x - 64, center_pos.y - 64},{center_pos.x + 64, center_pos.y + 64}}})) do
@ -274,7 +310,7 @@ local function on_entity_died(event)
global.server_restart_timer = 180
fireworks(event.entity.surface)
annihilate_base(event.entity.position, event.entity.surface, event.entity.force.name)
annihilate_base_v2(event.entity.position, event.entity.surface, event.entity.force.name)
end
end

View File

@ -246,8 +246,9 @@ local function join_team(player, force_name)
game.print("Team " .. player.force.name .. " player " .. player.name .. " is no longer spectating.", {r = 0.98, g = 0.66, b = 0.22})
return
end
player.teleport(surface.find_non_colliding_position("player", game.forces[force_name].get_spawn_position(surface), 3, 1))
local pos = surface.find_non_colliding_position("player", game.forces[force_name].get_spawn_position(surface), 3, 1)
if not pos then pos = game.forces[force_name].get_spawn_position(surface) end
player.teleport(pos)
player.force = game.forces[force_name]
player.character.destructible = true
game.permissions.get_group("Default").add_player(player)

View File

@ -36,7 +36,6 @@ local cliff_orientation_translation = {
}
local function process_entity(surface, entity)
--local new_pos = {x = entity.position.x * -1, y = (entity.position.y * -1) - 1}
local new_pos = {x = entity.position.x * -1, y = entity.position.y * -1}
if entity.type == "tree" then
if not surface.can_place_entity({name = entity.name, position = new_pos}) then return end

View File

@ -51,6 +51,9 @@ local function process_chunk(surface)
if #global.chunk_gen_coords == 0 then
global.map_generation_complete = true
draw_gui()
for _, player in pairs(game.connected_players) do
player.play_sound{path="utility/new_objective", volume_modifier=0.75}
end
return
end

View File

@ -47,7 +47,7 @@ local function get_noise(name, pos)
end
end
local function draw_smoothed_out_ore_circle(position, name, surface, radius, richness)
local function draw_noise_ore_patch(position, name, surface, radius, richness)
if not position then return end
if not name then return end
if not surface then return end
@ -56,19 +56,22 @@ local function draw_smoothed_out_ore_circle(position, name, surface, radius, ric
local math_random = math.random
local noise_seed_add = 25000
local richness_part = richness / radius
for y = radius * -2, radius * 2, 1 do
for x = radius * -2, radius * 2, 1 do
for y = radius * -3, radius * 3, 1 do
for x = radius * -3, radius * 3, 1 do
local pos = {x = x + position.x, y = y + position.y}
local seed = game.surfaces[1].map_gen_settings.seed
local noise_1 = simplex_noise(pos.x * 0.08, pos.y * 0.08, seed)
local noise_1 = simplex_noise(pos.x * 0.0125, pos.y * 0.0125, seed)
seed = seed + noise_seed_add
local noise_2 = simplex_noise(pos.x * 0.15, pos.y * 0.15, seed)
local noise = noise_1 + noise_2 * 0.2
local noise_2 = simplex_noise(pos.x * 0.1, pos.y * 0.1, seed)
local noise = noise_1 + noise_2 * 0.12
local distance_to_center = math.sqrt(x^2 + y^2)
local a = richness - richness_part * distance_to_center
if distance_to_center + ((1 + noise) * 3) < radius and a > 1 then
if distance_to_center < radius - math.abs(noise * radius * 0.85) and a > 1 then
if surface.can_place_entity({name = name, position = pos, amount = a}) then
surface.create_entity{name = name, position = pos, amount = a}
surface.create_entity{name = name, position = pos, amount = a}
local mirror_pos = {x = pos.x * -1, y = pos.y * -1}
surface.create_entity{name = name, position = mirror_pos, amount = a}
end
end
end
@ -125,21 +128,25 @@ local function generate_circle_spawn(event)
end
local function generate_silos(event)
if event.area.left_top.y == -96 and event.area.left_top.x == -96 then
local surface = event.surface
local pos = surface.find_non_colliding_position("rocket-silo", {0,-64}, 32, 1)
if not pos then pos = {x = 0, y = -64} end
global.rocket_silo["north"] = surface.create_entity({
name = "rocket-silo",
position = pos,
force = "north"
})
global.rocket_silo["north"].minable = false
for i = 1, 32, 1 do
create_tile_chain(surface, {name = "stone-path", position = global.rocket_silo["north"].position}, 32, 10)
end
if global.bb_game_won_by_team then return end
if global.rocket_silo["north"] then
if global.rocket_silo["north"].valid then return end
end
local surface = event.surface
local pos = surface.find_non_colliding_position("rocket-silo", {0,-64}, 32, 1)
if not pos then pos = {x = 0, y = -64} end
global.rocket_silo["north"] = surface.create_entity({
name = "rocket-silo",
position = pos,
force = "north"
})
global.rocket_silo["north"].minable = false
for i = 1, 32, 1 do
create_tile_chain(surface, {name = "stone-path", position = global.rocket_silo["north"].position}, 32, 10)
end
end
local function generate_river(event)
@ -188,25 +195,26 @@ local function rainbow_ore_and_ponds(event)
end
local function generate_potential_spawn_ore(event)
if event.area.left_top.y < -128 then return end
if event.area.left_top.x < -128 then return end
if event.area.left_top.x > 128 then return end
local pos = {x = event.area.left_top.x + 16, y = event.area.left_top.y + 16}
local area = {{pos.x - 64, pos.y - 64}, {pos.x + 64, pos.y + 64}}
if event.area.left_top.x ~= -320 then return end
if event.area.left_top.y ~= -320 then return end
local surface = event.surface
local ores = {"iron-ore", "coal"}
ores = shuffle(ores)
if event.area.left_top.y == -96 and event.area.left_top.x == -32 then
if surface.count_entities_filtered({name = ores[1], area = area}) < 40 then
draw_smoothed_out_ore_circle(pos, ores[1], surface, 13, math_random(1500, 2500))
end
end
if event.area.left_top.y == -96 and event.area.left_top.x == 0 then
if surface.count_entities_filtered({name = ores[2], area = area}) < 40 then
draw_smoothed_out_ore_circle(pos, ores[2], surface, 13, math_random(1500, 2500))
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 < 500 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
end
end
draw_noise_ore_patch(pos, ore, surface, math_random(18, 28), math_random(2000, 3000))
end
end
end
@ -224,15 +232,23 @@ local function on_chunk_generated(event)
rainbow_ore_and_ponds(event)
generate_river(event)
generate_circle_spawn(event)
--generate_potential_spawn_ore(event)
generate_potential_spawn_ore(event)
generate_silos(event)
if event.area.left_top.y == -160 and event.area.left_top.x == -160 then
if event.area.left_top.y == -320 and event.area.left_top.x == -320 then
local area = {{-10,-10},{10,10}}
for _, e in pairs(surface.find_entities_filtered({area = area})) do
if e.name ~= "player" then e.destroy() end
end
surface.destroy_decoratives({area = area})
for _, silo in pairs(global.rocket_silo) do
for _, entity in pairs(surface.find_entities({{silo.position.x - 4, silo.position.y - 4}, {silo.position.x + 4, silo.position.y + 4}})) do
if entity.type == "simple-entity" or entity.type == "tree" or entity.type == "resource" then
entity.destroy()
end
end
end
end
end

View File

@ -1,7 +1,7 @@
-- just an empty map for testing thingies
local event = require 'utils.event'
local map_functions = require "tools.map_functions"
require "maps.empty_map_test"
local simplex_noise = require 'utils.simplex_noise'.d2
function dump_boom_layout()
local surface = game.surfaces["empty_map"]
@ -61,6 +61,37 @@ local function on_chunk_generated(event)
surface.set_tiles(tiles,true)
end
local function draw_smoothed_out_ore_circle(position, name, surface, radius, richness)
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
local math_random = math.random
local noise_seed_add = 25000
local richness_part = richness / radius
for y = radius * -3, radius * 3, 1 do
for x = radius * -3, radius * 3, 1 do
local pos = {x = x + position.x, y = y + position.y}
local seed = game.surfaces[1].map_gen_settings.seed
local noise_1 = simplex_noise(pos.x * 0.0125, pos.y * 0.0125, seed)
seed = seed + noise_seed_add
local noise_2 = simplex_noise(pos.x * 0.1, pos.y * 0.1, seed)
local noise = noise_1 + noise_2 * 0.12
local distance_to_center = math.sqrt(x^2 + y^2)
local a = richness - richness_part * distance_to_center
if distance_to_center < radius - math.abs(noise * radius * 0.85) and a > 1 then
if surface.can_place_entity({name = name, position = pos, amount = a}) then
surface.create_entity{name = name, position = pos, amount = a}
local mirror_pos = {x = pos.x * -1, y = pos.y * -1}
surface.create_entity{name = name, position = mirror_pos, amount = a}
end
end
end
end
end
local function on_chunk_charted(event)
if not global.chunks_charted then global.chunks_charted = {} end
local surface = game.surfaces[event.surface_index]
@ -72,7 +103,8 @@ local function on_chunk_charted(event)
if position.x % 4 ~= 0 then return end
if position.y % 4 ~= 0 then return end
--map_functions.draw_rainbow_patch_v2({x = position.x * 32, y = position.y * 32}, surface, 28, 1000)
map_functions.draw_derpy_tile_circle(surface, {x = position.x * 32, y = position.y * 32}, "concrete", 20, 26)
--map_functions.draw_derpy_tile_circle(surface, {x = position.x * 32, y = position.y * 32}, "concrete", 20, 26)
draw_smoothed_out_ore_circle({x = position.x * 32, y = position.y * 32}, "coal", surface, 25, 3000)
end
local function on_player_joined_game(event)
@ -96,6 +128,8 @@ local function on_player_joined_game(event)
game.forces["player"].set_spawn_position({0,0},game.surfaces["empty_map"])
local surface = game.surfaces["empty_map"]
surface.daytime = 1
surface.freeze_daytime = 1
--local radius = 512
--game.forces.player.chart(surface, {{x = -1 * radius, y = -1 * radius}, {x = radius, y = radius}})
global.map_init_done = true