1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2024-12-26 22:56:43 +02:00
ComfyFactorio/maps/rivers.lua

212 lines
7.4 KiB
Lua
Raw Normal View History

2021-03-24 21:14:55 +02:00
--luacheck: ignore
2019-03-31 10:22:20 +02:00
--rivers-- mewmew made this --
2021-03-24 17:46:00 +02:00
require 'modules.satellite_score'
require 'modules.spawners_contain_biters'
require 'modules.dynamic_landfill'
require 'modules.rocks_yield_ore'
2019-03-31 10:22:20 +02:00
2021-03-24 17:46:00 +02:00
local event = require 'utils.event'
2019-03-31 10:22:20 +02:00
local table_insert = table.insert
local math_random = math.random
local simplex_noise = require 'utils.simplex_noise'.d2
2021-03-24 17:46:00 +02:00
local map_functions = require 'tools.map_functions'
2019-03-31 10:22:20 +02:00
local disabled_for_deconstruction = {
2021-03-24 17:46:00 +02:00
['fish'] = true
}
local rock_raffle = {'sand-rock-big', 'sand-rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-huge'}
2019-03-31 10:22:20 +02:00
local tile_replacements = {
2021-03-24 17:46:00 +02:00
['water'] = 'grass-2',
['deepwater'] = 'grass-2',
['dirt-1'] = 'grass-1',
['dirt-2'] = 'grass-2',
['dirt-3'] = 'grass-3',
['dirt-4'] = 'grass-4',
['sand-1'] = 'grass-1',
['sand-2'] = 'grass-2',
['sand-3'] = 'grass-3',
['dry-dirt'] = 'grass-2',
['red-desert-0'] = 'grass-1',
['red-desert-1'] = 'grass-2',
['red-desert-2'] = 'grass-3',
['red-desert-3'] = 'grass-4'
}
2019-03-31 10:22:20 +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-31 10:22:20 +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 == 1 then
noise[1] = simplex_noise(pos.x * 0.007, pos.y * 0.007, seed)
seed = seed + noise_seed_add
noise[2] = simplex_noise(pos.x * 0.05, pos.y * 0.05, seed)
seed = seed + noise_seed_add
noise[3] = simplex_noise(pos.x * 0.1, pos.y * 0.1, seed)
local noise = noise[1] + noise[2] * 0.1 + noise[3] * 0.025
return noise
end
seed = seed + noise_seed_add
seed = seed + noise_seed_add
if name == 2 then
noise[1] = simplex_noise(pos.x * 0.008, pos.y * 0.008, seed)
seed = seed + noise_seed_add
noise[2] = simplex_noise(pos.x * 0.05, pos.y * 0.05, seed)
local noise = noise[1] + noise[2] * 0.05
return noise
end
2019-03-31 10:22:20 +02:00
end
local ore_level = 0.73
local water_level = 0.25
local connections = 0.08
local function process_tiles(surface, pos, noise, noise_2)
2021-03-24 17:46:00 +02:00
local tile = surface.get_tile(pos)
if tile_replacements[tile.name] then
surface.set_tiles({{name = tile_replacements[tile.name], position = pos}}, true)
end
if noise > water_level * -1 and noise < water_level then
if noise_2 < connections * -1 or noise_2 > connections then
surface.set_tiles({{name = 'water', position = pos}}, true)
if math_random(1, 256) == 1 then
surface.create_entity({name = 'fish', position = pos})
end
return
else
if math_random(1, 2) == 1 then
surface.create_entity({name = rock_raffle[math_random(1, #rock_raffle)], position = pos})
end
end
end
2019-03-31 10:22:20 +02:00
end
local function process_entities(surface, pos, noise, noise_2)
2021-03-24 17:46:00 +02:00
if not surface.can_place_entity({name = 'iron-ore', position = pos, amount = 1}) then
return
end
if noise > ore_level then
local distance_to_center = math.sqrt(pos.x ^ 2 + pos.y ^ 2)
local amount = (600 + distance_to_center) * math.abs(noise)
if math.floor(noise * 15) % 3 ~= 0 then
surface.create_entity({name = 'iron-ore', position = pos, amount = amount})
return
else
surface.create_entity({name = 'coal', position = pos, amount = amount})
return
end
end
if noise < ore_level * -1 then
local distance_to_center = math.sqrt(pos.x ^ 2 + pos.y ^ 2)
local amount = (600 + distance_to_center) * math.abs(noise)
if math.floor(noise * 15) % 3 ~= 0 then
surface.create_entity({name = 'copper-ore', position = pos, amount = amount})
return
else
surface.create_entity({name = 'stone', position = pos, amount = amount})
return
end
end
2019-03-31 10:22:20 +02:00
end
local function on_chunk_generated(event)
2021-03-24 17:46:00 +02:00
local surface = event.surface
if surface.name ~= 'rivers' then
return
end
local left_top = event.area.left_top
local tiles = {}
local entities = {}
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local pos = {x = left_top.x + x, y = left_top.y + y}
local noise_1 = get_noise(1, pos)
local noise_2 = get_noise(2, pos)
process_tiles(surface, pos, noise_1, noise_2)
process_entities(surface, pos, noise_1, noise_2)
end
end
local decorative_names = {}
for k, v in pairs(game.decorative_prototypes) do
if v.autoplace_specification then
decorative_names[#decorative_names + 1] = k
end
end
surface.regenerate_decorative(decorative_names, {{left_top.x / 32, left_top.y / 32}})
2019-03-31 10:22:20 +02:00
end
local function init_map()
2021-03-24 17:46:00 +02:00
if game.surfaces['rivers'] then
return
end
local map_gen_settings = {}
map_gen_settings.water = '0'
map_gen_settings.starting_area = '1'
map_gen_settings.cliff_settings = {cliff_elevation_interval = 22, cliff_elevation_0 = 22}
map_gen_settings.autoplace_controls = {
['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 = '4', size = '1', richness = '1'},
['trees'] = {frequency = '4', size = '1', richness = '1'},
['enemy-base'] = {frequency = '50', size = '1.5', richness = '1'}
}
game.create_surface('rivers', map_gen_settings)
local surface = game.surfaces['rivers']
surface.ticks_per_day = game.surfaces['rivers'].ticks_per_day * 1.5
game.map_settings.enemy_expansion.enabled = true
game.map_settings.enemy_expansion.min_expansion_cooldown = 18000
game.map_settings.enemy_expansion.max_expansion_cooldown = 36000
surface.request_to_generate_chunks({0, 0}, 3)
surface.force_generate_chunk_requests()
game.forces.player.research_queue_enabled = true
map_functions.draw_smoothed_out_ore_circle({x = -3, y = -3}, 'iron-ore', surface, 8, 5000)
map_functions.draw_smoothed_out_ore_circle({x = 3, y = 3}, 'copper-ore', surface, 8, 5000)
map_functions.draw_smoothed_out_ore_circle({x = 3, y = -3}, 'stone', surface, 8, 5000)
map_functions.draw_smoothed_out_ore_circle({x = -3, y = 3}, 'coal', surface, 8, 5000)
2019-03-31 10:22:20 +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
player.insert({name = 'iron-plate', count = 32})
player.insert({name = 'iron-gear-wheel', count = 16})
player.teleport(game.surfaces['rivers'].find_non_colliding_position('character', {0, 2}, 50, 0.5), 'rivers')
end
2019-03-31 10:22:20 +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-31 10:22:20 +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)
2021-03-24 17:46:00 +02:00
event.add(defines.events.on_chunk_generated, on_chunk_generated)