mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-02-03 13:12:11 +02:00
new module > dynamic_landfill, new map > atoll
This commit is contained in:
parent
2def315fde
commit
11e2b09de1
@ -13,6 +13,7 @@ require "score"
|
||||
--require "maps.tools.map_pregen"
|
||||
--require "maps.modules.hunger"
|
||||
--require "maps.tools.cheat_mode"
|
||||
require "maps.modules.dynamic_landfill"
|
||||
|
||||
---- enable maps here ----
|
||||
--require "maps.biter_battles"
|
||||
@ -25,10 +26,10 @@ require "score"
|
||||
--require "maps.fish_defender"
|
||||
--require "maps.crossing"
|
||||
--require "maps.spooky_forest"
|
||||
--require "maps.atoll"
|
||||
require "maps.atoll"
|
||||
--require "maps.tank_battles"
|
||||
--require "maps.empty_map"
|
||||
require "maps.custom_start"
|
||||
--require "maps.custom_start"
|
||||
-----------------------------
|
||||
|
||||
local Event = require 'utils.event'
|
||||
|
@ -1,5 +1,6 @@
|
||||
--deep jungle-- mewmew made this --
|
||||
--atoll-- mewmew made this --
|
||||
|
||||
require "maps.tools.map_pregen"
|
||||
local simplex_noise = require 'utils.simplex_noise'
|
||||
simplex_noise = simplex_noise.d2
|
||||
local event = require 'utils.event'
|
||||
@ -11,12 +12,17 @@ local function get_noise(name, pos)
|
||||
local seed = game.surfaces[1].map_gen_settings.seed
|
||||
local noise_seed_add = 25000
|
||||
seed = seed + noise_seed_add
|
||||
if name == "islands_1" then
|
||||
if name == "ocean" then
|
||||
local noise = {}
|
||||
noise[1] = simplex_noise(pos.x * 0.01, pos.y * 0.01, seed)
|
||||
noise[1] = simplex_noise(pos.x * 0.005, pos.y * 0.005, seed)
|
||||
seed = seed + noise_seed_add
|
||||
noise[2] = simplex_noise(pos.x * 0.1, pos.y * 0.1, seed)
|
||||
local noise = noise[1] + noise[2] * 0.1
|
||||
noise[2] = simplex_noise(pos.x * 0.01, pos.y * 0.01, seed)
|
||||
seed = seed + noise_seed_add
|
||||
noise[3] = simplex_noise(pos.x * 0.05, pos.y * 0.05, seed)
|
||||
seed = seed + noise_seed_add
|
||||
noise[4] = simplex_noise(pos.x * 0.1, pos.y * 0.1, seed)
|
||||
local noise = noise[1] + noise[2] * 0.3 + noise[3] * 0.2 + noise[4] * 0.1
|
||||
--noise = noise * 0.5
|
||||
return noise
|
||||
end
|
||||
end
|
||||
@ -24,38 +30,15 @@ end
|
||||
local function on_player_joined_game(event)
|
||||
local player = game.players[event.player_index]
|
||||
if not global.map_init_done then
|
||||
local map_gen_settings = {}
|
||||
map_gen_settings.water = "none"
|
||||
map_gen_settings.cliff_settings = {cliff_elevation_interval = 4, cliff_elevation_0 = 0.1}
|
||||
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 = "none", size = "none", richness = "none"},
|
||||
["trees"] = {frequency = "none", size = "none", richness = "none"},
|
||||
["enemy-base"] = {frequency = "none", size = "none", richness = "none"},
|
||||
["grass"] = {frequency = "none", size = "none", richness = "none"},
|
||||
["sand"] = {frequency = "none", size = "none", richness = "none"},
|
||||
["desert"] = {frequency = "none", size = "none", richness = "none"},
|
||||
["dirt"] = {frequency = "none", size = "none", richness = "none"}
|
||||
}
|
||||
game.map_settings.pollution.pollution_restored_per_tree_damage = 0
|
||||
game.create_surface("atoll", map_gen_settings)
|
||||
game.forces["player"].set_spawn_position({0,0},game.surfaces["atoll"])
|
||||
game.forces["player"].technologies["landfill"].researched=true
|
||||
global.map_init_done = true
|
||||
end
|
||||
local surface = game.surfaces["atoll"]
|
||||
if player.online_time < 5 and surface.is_chunk_generated({0,0}) then
|
||||
player.teleport(surface.find_non_colliding_position("player", {0,0}, 2, 1), "atoll")
|
||||
else
|
||||
if player.online_time < 5 then
|
||||
player.teleport({0,0}, "atoll")
|
||||
end
|
||||
end
|
||||
|
||||
if player.online_time < 4 then
|
||||
if player.online_time == 0 then
|
||||
player.insert{name = 'iron-axe', count = 1}
|
||||
player.insert{name = 'landfill', count = 200}
|
||||
player.insert{name = 'iron-plate', count = 32}
|
||||
player.insert{name = 'iron-gear-wheel', count = 16}
|
||||
end
|
||||
end
|
||||
|
||||
@ -65,35 +48,48 @@ local function on_marked_for_deconstruction(event)
|
||||
end
|
||||
end
|
||||
|
||||
local types = {"resource", "simple-entity", "player"}
|
||||
local function on_chunk_generated(event)
|
||||
if event.surface.name ~= "atoll" then return end
|
||||
local surface = event.surface
|
||||
local left_top = event.area.left_top
|
||||
local tiles = {}
|
||||
local valid_resource_spots = {}
|
||||
local entities = {}
|
||||
|
||||
if not global.spawn_generated and left_top.x <= -160 then
|
||||
map_functions.draw_noise_tile_circle({x = 0, y = 0}, "grass-1", surface, 20)
|
||||
map_functions.draw_smoothed_out_ore_circle({x = -32, y = -32}, "copper-ore", surface, 15, 2500)
|
||||
map_functions.draw_smoothed_out_ore_circle({x = -32, y = 32}, "iron-ore", surface, 15, 2500)
|
||||
map_functions.draw_smoothed_out_ore_circle({x = 32, y = 32}, "coal", surface, 15, 2500)
|
||||
map_functions.draw_smoothed_out_ore_circle({x = 32, y = -32}, "stone", surface, 15, 2500)
|
||||
map_functions.draw_oil_circle({x = 0, y = 0}, "crude-oil", surface, 5, 200000)
|
||||
global.spawn_generated = true
|
||||
end
|
||||
|
||||
for x = 0, 31, 1 do
|
||||
for y = 0, 31, 1 do
|
||||
local tile_to_insert = false
|
||||
local pos = {x = left_top.x + x, y = left_top.y + y}
|
||||
local islands_1_noise = get_noise("islands_1", pos)
|
||||
if islands_1_noise > 0.5 then
|
||||
table_insert(tiles, {name = "grass-2", position = pos})
|
||||
local ocean_noise = get_noise("ocean", pos)
|
||||
if ocean_noise > -0.5 then
|
||||
tile_to_insert = "water"
|
||||
if ocean_noise > -0.25 then tile_to_insert = "deepwater" end
|
||||
end
|
||||
if tile_to_insert then
|
||||
local count = surface.count_entities_filtered({area = {{pos.x - 1, pos.y - 1}, {pos.x + 1.99, pos.y + 1.99}}, limit = 1, type = types})
|
||||
if count == 0 then
|
||||
table_insert(tiles, {name = tile_to_insert, position = pos})
|
||||
if math_random(1, 128) == 1 then
|
||||
table_insert(entities, {name = "fish", position = pos})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
surface.set_tiles(tiles, true)
|
||||
|
||||
for _, entity in pairs(entities) do
|
||||
surface.create_entity(entity)
|
||||
end
|
||||
|
||||
if not global.spawn_generated and left_top.x <= -64 then
|
||||
--map_functions.draw_noise_tile_circle({x = 0, y = 0}, "concrete", surface, 5)
|
||||
--map_functions.draw_smoothed_out_ore_circle({x = -32, y = -32}, "copper-ore", surface, 15, 2500)
|
||||
--map_functions.draw_smoothed_out_ore_circle({x = -32, y = 32}, "iron-ore", surface, 15, 2500)
|
||||
--map_functions.draw_smoothed_out_ore_circle({x = 32, y = 32}, "coal", surface, 15, 2500)
|
||||
--map_functions.draw_smoothed_out_ore_circle({x = 32, y = -32}, "stone", surface, 15, 2500)
|
||||
--map_functions.draw_oil_circle({x = 0, y = 0}, "crude-oil", surface, 5, 200000)
|
||||
global.spawn_generated = true
|
||||
end
|
||||
end
|
||||
|
||||
event.add(defines.events.on_entity_died, on_entity_died)
|
||||
|
@ -8,7 +8,7 @@ simplex_noise = simplex_noise.d2
|
||||
local event = require 'utils.event'
|
||||
local unique_rooms = require "maps.labyrinth_unique_rooms"
|
||||
|
||||
local labyrinth_difficulty_curve = 400 --- How much size the labyrinth needs to have the highest difficulty.
|
||||
local labyrinth_difficulty_curve = 333 --- How much size the labyrinth needs to have the highest difficulty.
|
||||
|
||||
local threat_values = {
|
||||
["small-biter"] = 1,
|
||||
@ -813,10 +813,10 @@ local function on_chunk_generated(event)
|
||||
|
||||
if not global.spawn_ores_generated then
|
||||
if event.area.left_top.x > 96 then
|
||||
map_functions.draw_entity_circle({x = 16, y = 16}, "coal", surface, 9, false, 750)
|
||||
map_functions.draw_entity_circle({x = 16, y = 16}, "iron-ore", surface, 9, false, 750)
|
||||
map_functions.draw_entity_circle({x = 16, y = 16}, "copper-ore", surface, 9, false, 750)
|
||||
map_functions.draw_entity_circle({x = 16, y = 16}, "tree-05", surface, 9, true)
|
||||
map_functions.draw_entity_circle({x = 16, y = 16}, "coal", surface, 7, false, 750)
|
||||
map_functions.draw_entity_circle({x = 16, y = 16}, "iron-ore", surface, 7, false, 750)
|
||||
map_functions.draw_entity_circle({x = 16, y = 16}, "copper-ore", surface, 7, false, 750)
|
||||
--map_functions.draw_entity_circle({x = 16, y = 16}, "tree-05", surface, 7, true)
|
||||
--map_functions.draw_smoothed_out_ore_circle({x = 16, y = 8}, "coal", surface, 7, 750)
|
||||
--map_functions.draw_smoothed_out_ore_circle({x = 16, y = 8}, "coal", surface, 7, 750)
|
||||
--map_functions.draw_smoothed_out_ore_circle({x = 8, y = 24}, "iron-ore", surface, 7, 750)
|
||||
|
103
maps/modules/dynamic_landfill.lua
Normal file
103
maps/modules/dynamic_landfill.lua
Normal file
@ -0,0 +1,103 @@
|
||||
-- changes placed landfill tiles, adapting the new tile to adjecant tiles -- by mewmew
|
||||
|
||||
local regenerate_decoratives = true
|
||||
|
||||
local event = require 'utils.event'
|
||||
local math_random = math.random
|
||||
local table_insert = table.insert
|
||||
local water_tile_whitelist = {
|
||||
["water"] = true,
|
||||
["deepwater"] = true,
|
||||
["water-green"] = true
|
||||
}
|
||||
|
||||
local water_tiles = {
|
||||
"water",
|
||||
"deepwater",
|
||||
"water-green"
|
||||
}
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
local function get_chunk_position(position)
|
||||
local chunk_position = {}
|
||||
position.x = math.floor(position.x, 0)
|
||||
position.y = math.floor(position.y, 0)
|
||||
for x = 0, 31, 1 do
|
||||
if (position.x - x) % 32 == 0 then chunk_position.x = (position.x - x) / 32 end
|
||||
end
|
||||
for y = 0, 31, 1 do
|
||||
if (position.y - y) % 32 == 0 then chunk_position.y = (position.y - y) / 32 end
|
||||
end
|
||||
return chunk_position
|
||||
end
|
||||
|
||||
local function regenerate_decoratives(surface, position)
|
||||
local chunk = get_chunk_position(position)
|
||||
surface.destroy_decoratives({{chunk.x * 32, chunk.y * 32}, {chunk.x * 32 + 32, chunk.y * 32 + 32}})
|
||||
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, {chunk})
|
||||
end
|
||||
|
||||
local function is_this_a_valid_source_tile(pos, tiles)
|
||||
for _, tile in pairs(tiles) do
|
||||
if tile.position.x == pos.x and tile.position.y == pos.y then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function place_fitting_tile(position, surface, tiles_placed)
|
||||
local tiles = {}
|
||||
for i = 1, 64, 0.5 do
|
||||
local area = {{position.x - i, position.y - i}, {position.x + i, position.y + i}}
|
||||
for _, found_tile in pairs(surface.find_tiles_filtered({area = area, collision_mask = "ground-tile"})) do
|
||||
|
||||
local valid_source_tile = is_this_a_valid_source_tile(found_tile.position, tiles_placed)
|
||||
if found_tile.name == "out-of-map" then valid_source_tile = false end
|
||||
|
||||
if valid_source_tile then
|
||||
if found_tile.hidden_tile then
|
||||
table_insert(tiles, found_tile.hidden_tile)
|
||||
else
|
||||
table_insert(tiles, found_tile.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
if #tiles > 0 then break end
|
||||
end
|
||||
if #tiles == 0 then return false end
|
||||
tiles = shuffle(tiles)
|
||||
surface.set_tiles({{name = tiles[1], position = position}}, true)
|
||||
end
|
||||
|
||||
local function on_player_built_tile(event)
|
||||
if event.item.name ~= "landfill" then return end
|
||||
local surface = game.surfaces[event.surface_index]
|
||||
|
||||
for _, placed_tile in pairs(event.tiles) do
|
||||
if water_tile_whitelist[placed_tile.old_tile.name] then
|
||||
place_fitting_tile(placed_tile.position, surface, event.tiles)
|
||||
if regenerate_decoratives then
|
||||
if math_random(1, 4) == 1 then
|
||||
regenerate_decoratives(surface, placed_tile.position)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
event.add(defines.events.on_player_built_tile, on_player_built_tile)
|
Loading…
x
Reference in New Issue
Block a user