1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-04 00:15:45 +02:00
ComfyFactorio/maps/lost.lua

177 lines
5.9 KiB
Lua
Raw Normal View History

2021-03-24 21:14:55 +02:00
--luacheck: ignore
2019-03-28 09:21:08 +02:00
--lost-- mewmew made this --
2021-03-24 17:46:00 +02:00
require 'modules.landfill_reveals_nauvis'
require 'modules.satellite_score'
require 'modules.spawners_contain_biters'
2019-03-28 09:21:08 +02:00
2021-03-24 17:46:00 +02:00
local event = require 'utils.event'
2019-03-28 09:21:08 +02:00
local table_insert = table.insert
local math_random = math.random
local simplex_noise = require 'utils.math.simplex_noise'.d2
2019-03-28 09:21:08 +02:00
local disabled_for_deconstruction = {
2021-03-24 17:46:00 +02:00
['fish'] = true,
2024-09-25 23:25:57 +02:00
['huge-rock'] = true,
['big-rock'] = true,
['big-sand-rock'] = true,
2021-03-24 17:46:00 +02:00
['mineable-wreckage'] = true
}
2019-03-28 09:21:08 +02:00
local function shuffle(tbl)
2021-03-24 17:46:00 +02:00
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-03-28 09:21:08 +02:00
end
2021-03-24 17:46:00 +02:00
local function get_noise(name, pos)
local seed = game.surfaces[1].map_gen_settings.seed
local noise = {}
local noise_seed_add = 25000
if name == 'ocean' then
noise[1] = simplex_noise(pos.x * 0.01, pos.y * 0.01, seed)
seed = seed + noise_seed_add
local noise = noise[1]
return noise
end
2019-03-28 09:21:08 +02:00
end
local function generate_outer_content(event)
2021-03-24 17:46:00 +02:00
local surface = event.surface
local left_top = event.area.left_top
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local tile_to_insert = false
2024-09-25 23:25:57 +02:00
local pos = { x = left_top.x + x, y = left_top.y + y }
2021-03-24 17:46:00 +02:00
local noise = get_noise('ocean', pos)
if math.floor(noise * 8) % 2 == 1 then
2024-09-25 23:25:57 +02:00
surface.set_tiles({ { name = 'deepwater', position = pos } })
2021-03-24 17:46:00 +02:00
else
2024-09-25 23:25:57 +02:00
surface.set_tiles({ { name = 'water', position = pos } })
2021-03-24 17:46:00 +02:00
end
if math_random(1, 256) == 1 then
2024-09-25 23:25:57 +02:00
surface.create_entity({ name = 'fish', position = pos })
2021-03-24 17:46:00 +02:00
end
end
end
2019-03-28 09:21:08 +02:00
end
local function generate_inner_content(event)
2021-03-24 17:46:00 +02:00
local surface = event.surface
local left_top = event.area.left_top
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local tile_to_insert = false
2024-09-25 23:25:57 +02:00
local pos = { x = left_top.x + x, y = left_top.y + y }
2021-03-24 17:46:00 +02:00
if pos.x < 2 and pos.y < 2 and pos.x > -3 and pos.y > -3 then
2024-09-25 23:25:57 +02:00
surface.set_tiles({ { name = 'grass-1', position = pos } })
surface.create_entity({ name = 'stone', position = pos, amount = 999999 })
2021-03-24 17:46:00 +02:00
else
local noise = get_noise('ocean', pos)
if math.floor(noise * 8) % 2 == 1 then
2024-09-25 23:25:57 +02:00
surface.set_tiles({ { name = 'deepwater', position = pos } })
2021-03-24 17:46:00 +02:00
else
2024-09-25 23:25:57 +02:00
surface.set_tiles({ { name = 'water', position = pos } })
2021-03-24 17:46:00 +02:00
end
if math_random(1, 256) == 1 then
2024-09-25 23:25:57 +02:00
surface.create_entity({ name = 'fish', position = pos })
2021-03-24 17:46:00 +02:00
end
end
if pos.x == 0 and pos.y == 0 then
2024-09-25 23:25:57 +02:00
surface.create_entity({ name = 'big-rock', position = pos })
2021-03-24 17:46:00 +02:00
end
end
end
2019-03-28 09:21:08 +02:00
end
local function on_chunk_generated(event)
2021-03-24 17:46:00 +02:00
local surface = event.surface
if surface.name ~= 'lost' then
return
end
local left_top = event.area.left_top
local tiles = {}
local entities = {}
2024-09-25 23:25:57 +02:00
for _, e in pairs(surface.find_entities_filtered({ area = event.area })) do
2021-03-24 17:46:00 +02:00
if e.name ~= 'character' then
e.destroy()
end
end
if event.area.left_top.x < 64 and event.area.left_top.y < 64 and event.area.left_top.x > -64 and event.area.left_top.y > -64 then
generate_inner_content(event)
else
generate_outer_content(event)
end
2019-03-28 09:21:08 +02:00
end
local function init_map()
2021-03-24 17:46:00 +02:00
if game.surfaces['lost'] then
return
end
local map_gen_settings = {}
map_gen_settings.water = 'small'
2024-09-25 23:25:57 +02:00
map_gen_settings.cliff_settings = { cliff_elevation_interval = 22, cliff_elevation_0 = 22 }
2021-03-24 17:46:00 +02:00
map_gen_settings.autoplace_controls = {
2024-09-25 23:25:57 +02:00
['coal'] = { frequency = 'none', size = 'none', richness = 'none' },
['stone'] = { frequency = 'none', size = 'none', richness = 'none' },
['copper-ore'] = { frequency = 'none', size = 'none', richness = 'none' },
['iron-ore'] = { frequency = 'none', size = 'none', richness = 'none' },
['crude-oil'] = { frequency = 'none', size = 'none', richness = 'none' },
['trees'] = { frequency = 'none', size = 'none', richness = 'none' },
['enemy-base'] = { frequency = 'none', size = 'none', richness = 'none' }
2021-03-24 17:46:00 +02:00
}
game.create_surface('lost', map_gen_settings)
game.surfaces['lost'].ticks_per_day = game.surfaces['lost'].ticks_per_day * 2
2024-09-25 23:25:57 +02:00
game.surfaces['lost'].request_to_generate_chunks({ 0, 0 }, 3)
2021-03-24 17:46:00 +02:00
game.surfaces['lost'].force_generate_chunk_requests()
game.forces.player.manual_mining_speed_modifier = 0.5
game.forces['player'].technologies['landfill'].researched = true
2019-03-28 09:21:08 +02:00
end
local function on_player_joined_game(event)
2021-03-24 17:46:00 +02:00
init_map()
local player = game.players[event.player_index]
if player.online_time == 0 then
2024-09-25 23:25:57 +02:00
player.teleport(game.surfaces['lost'].find_non_colliding_position('character', { 0, 2 }, 50, 0.5), 'lost')
2021-03-24 17:46:00 +02:00
end
2019-03-28 09:21:08 +02:00
end
local function on_player_mined_entity(event)
2021-03-24 17:46:00 +02:00
local entity = event.entity
if not entity.valid then
return
end
if entity.type ~= 'simple-entity' then
return
end
if entity.position.x == 0 and entity.position.y == 0 then
2024-09-25 23:25:57 +02:00
entity.surface.create_entity({ name = 'big-rock', position = { 0, 0 } })
2021-03-24 17:46:00 +02:00
end
2019-03-28 09:21:08 +02:00
end
local function on_entity_died(event)
2021-03-24 17:46:00 +02:00
on_player_mined_entity(event)
2019-03-28 09:21:08 +02:00
end
2021-03-24 17:46:00 +02:00
local function on_marked_for_deconstruction(event)
if disabled_for_deconstruction[event.entity.name] then
event.entity.cancel_deconstruction(game.players[event.player_index].force.name)
end
2019-03-28 09:21:08 +02:00
end
event.add(defines.events.on_marked_for_deconstruction, on_marked_for_deconstruction)
event.add(defines.events.on_player_joined_game, on_player_joined_game)
event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
event.add(defines.events.on_entity_died, on_entity_died)
2021-03-24 17:46:00 +02:00
event.add(defines.events.on_chunk_generated, on_chunk_generated)