2018-11-16 09:13:08 +02:00
|
|
|
-- crossing -- by mewmew --
|
|
|
|
|
2023-10-25 20:59:06 +02:00
|
|
|
local Event = require 'utils.event'
|
2024-01-28 21:42:28 +02:00
|
|
|
local map_functions = require 'utils.tools.map_functions'
|
2024-10-01 16:46:06 +02:00
|
|
|
local simplex_noise = require 'utils.math.simplex_noise'.d2
|
2018-11-16 09:13:08 +02:00
|
|
|
|
|
|
|
local function on_player_joined_game(event)
|
2021-03-24 17:46:00 +02:00
|
|
|
local player = game.players[event.player_index]
|
|
|
|
if player.online_time < 1 then
|
2024-09-24 19:37:11 +02:00
|
|
|
player.insert({ name = 'pistol', count = 1 })
|
|
|
|
player.insert({ name = 'raw-fish', count = 1 })
|
|
|
|
player.insert({ name = 'firearm-magazine', count = 16 })
|
|
|
|
player.insert({ name = 'iron-plate', count = 32 })
|
2021-03-24 17:46:00 +02:00
|
|
|
|
2024-09-24 19:37:11 +02:00
|
|
|
local pos = player.character.surface.find_non_colliding_position('character', { 0, -40 }, 50, 1)
|
|
|
|
game.forces.player.set_spawn_position({ x = pos.x, y = pos.y }, player.character.surface)
|
|
|
|
player.teleport({ x = pos.x, y = pos.y }, player.character.surface)
|
2021-03-24 17:46:00 +02:00
|
|
|
end
|
2018-11-16 09:13:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function on_chunk_generated(event)
|
2021-03-24 17:46:00 +02:00
|
|
|
local surface = game.surfaces[1]
|
|
|
|
local seed = game.surfaces[1].map_gen_settings.seed
|
|
|
|
if event.surface.name ~= surface.name then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local left_top = event.area.left_top
|
|
|
|
|
2024-09-24 19:37:11 +02:00
|
|
|
local entities = surface.find_entities_filtered({ area = event.area, name = { 'iron-ore', 'copper-ore', 'coal', 'stone' } })
|
2021-03-24 17:46:00 +02:00
|
|
|
for _, entity in pairs(entities) do
|
|
|
|
entity.destroy()
|
|
|
|
end
|
|
|
|
|
|
|
|
if left_top.x > 128 then
|
2024-09-24 19:37:11 +02:00
|
|
|
if not storage.spawn_ores_generated then
|
|
|
|
map_functions.draw_noise_tile_circle({ x = 0, y = 0 }, 'water', surface, 24)
|
|
|
|
storage.spawn_ores_generated = true
|
2021-03-24 17:46:00 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if left_top.x < 64 and left_top.x > -64 then
|
|
|
|
for x = 0, 31, 1 do
|
|
|
|
for y = 0, 31, 1 do
|
2024-09-24 19:37:11 +02:00
|
|
|
local pos = { x = left_top.x + x, y = left_top.y + y }
|
2021-03-24 17:46:00 +02:00
|
|
|
local noise_1 = simplex_noise(pos.x * 0.02, pos.y * 0.02, seed)
|
|
|
|
|
|
|
|
if pos.x > -80 + (noise_1 * 8) and pos.x < 80 + (noise_1 * 8) then
|
|
|
|
local tile = surface.get_tile(pos)
|
|
|
|
if tile.name == 'water' or tile.name == 'deepwater' then
|
2024-09-24 19:37:11 +02:00
|
|
|
surface.set_tiles({ { name = 'grass-2', position = pos } })
|
2021-03-24 17:46:00 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if pos.x > -14 + (noise_1 * 8) and pos.x < 14 + (noise_1 * 8) then
|
|
|
|
if pos.y > 0 then
|
2024-09-24 19:37:11 +02:00
|
|
|
surface.create_entity({ name = 'stone', position = pos, amount = 1 + pos.y * 0.5 })
|
2021-03-24 17:46:00 +02:00
|
|
|
else
|
2024-09-24 19:37:11 +02:00
|
|
|
surface.create_entity({ name = 'coal', position = pos, amount = 1 + pos.y * -1 * 0.5 })
|
2021-03-24 17:46:00 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if left_top.y < 64 and left_top.y > -64 then
|
|
|
|
for x = 0, 31, 1 do
|
|
|
|
for y = 0, 31, 1 do
|
2024-09-24 19:37:11 +02:00
|
|
|
local pos = { x = left_top.x + x, y = left_top.y + y }
|
2021-03-24 17:46:00 +02:00
|
|
|
local noise_1 = simplex_noise(pos.x * 0.015, pos.y * 0.015, seed)
|
|
|
|
|
|
|
|
if pos.y > -80 + (noise_1 * 8) and pos.y < 80 + (noise_1 * 8) then
|
|
|
|
local tile = surface.get_tile(pos)
|
|
|
|
if tile.name == 'water' or tile.name == 'deepwater' then
|
2024-09-24 19:37:11 +02:00
|
|
|
surface.set_tiles({ { name = 'grass-2', position = pos } })
|
2021-03-24 17:46:00 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if pos.y > -14 + (noise_1 * 8) and pos.y < 14 + (noise_1 * 8) then
|
|
|
|
if pos.x > 0 then
|
2024-09-24 19:37:11 +02:00
|
|
|
surface.create_entity({ name = 'copper-ore', position = pos, amount = 1 + pos.x * 0.5 })
|
2021-03-24 17:46:00 +02:00
|
|
|
else
|
2024-09-24 19:37:11 +02:00
|
|
|
surface.create_entity({ name = 'iron-ore', position = pos, amount = 1 + pos.x * -1 * 0.5 })
|
2021-03-24 17:46:00 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-11-16 09:13:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local biter_building_inhabitants = {
|
2024-09-24 19:37:11 +02:00
|
|
|
[1] = { { 'small-biter', 8, 16 } },
|
|
|
|
[2] = { { 'small-biter', 12, 24 } },
|
|
|
|
[3] = { { 'small-biter', 8, 16 }, { 'medium-biter', 1, 2 } },
|
|
|
|
[4] = { { 'small-biter', 4, 8 }, { 'medium-biter', 4, 8 } },
|
|
|
|
[5] = { { 'small-biter', 3, 5 }, { 'medium-biter', 8, 12 } },
|
|
|
|
[6] = { { 'small-biter', 3, 5 }, { 'medium-biter', 5, 7 }, { 'big-biter', 1, 2 } },
|
|
|
|
[7] = { { 'medium-biter', 6, 8 }, { 'big-biter', 3, 5 } },
|
|
|
|
[8] = { { 'medium-biter', 2, 4 }, { 'big-biter', 6, 8 } },
|
|
|
|
[9] = { { 'medium-biter', 2, 3 }, { 'big-biter', 7, 9 } },
|
|
|
|
[10] = { { 'big-biter', 4, 8 }, { 'behemoth-biter', 3, 4 } }
|
2018-11-16 09:13:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
local function on_entity_died(event)
|
2021-03-24 17:46:00 +02:00
|
|
|
if event.entity.name == 'biter-spawner' or event.entity.name == 'spitter-spawner' then
|
2023-10-25 20:59:06 +02:00
|
|
|
local e = math.ceil(game.forces.enemy.evolution_factor * 10)
|
2021-03-24 17:46:00 +02:00
|
|
|
for _, t in pairs(biter_building_inhabitants[e]) do
|
2023-10-25 20:59:06 +02:00
|
|
|
for _ = 1, math.random(t[2], t[3]), 1 do
|
2021-03-24 17:46:00 +02:00
|
|
|
local p = event.entity.surface.find_non_colliding_position(t[1], event.entity.position, 6, 1)
|
|
|
|
if p then
|
2024-09-24 19:37:11 +02:00
|
|
|
event.entity.surface.create_entity { name = t[1], position = p }
|
2021-03-24 17:46:00 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-11-16 09:13:08 +02:00
|
|
|
end
|
|
|
|
|
2023-10-25 20:59:06 +02:00
|
|
|
Event.add(defines.events.on_chunk_generated, on_chunk_generated)
|
|
|
|
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
|
|
|
Event.add(defines.events.on_entity_died, on_entity_died)
|