1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-03-11 14:49:24 +02:00

map_functions > mixed ore patch function v2

This commit is contained in:
MewMew 2019-03-07 03:09:43 +01:00
parent 410b5dc7d8
commit 206760e6fe
3 changed files with 48 additions and 11 deletions

View File

@ -39,13 +39,15 @@ local function on_chunk_generated(event)
right_bottom = {x = chunk_pos_x + 31, y = chunk_pos_y + 31}
}
surface.destroy_decoratives(area)
surface.destroy_decoratives({area = area})
local decoratives = {}
local entities = surface.find_entities(area)
for _, e in pairs(entities) do
if e.name ~= "player" then
e.destroy()
if e.valid then
if e.name ~= "player" then
e.destroy()
end
end
end
@ -69,7 +71,7 @@ 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({x = position.x * 32, y = position.y * 32}, surface, 28, 1000)
map_functions.draw_rainbow_patch_v2({x = position.x * 32, y = position.y * 32}, surface, 28, 1000)
end
local function on_player_joined_game(event)
@ -86,11 +88,7 @@ local function on_player_joined_game(event)
["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 = "normal", size = "normal", richness = "normal"}
["enemy-base"] = {frequency = "none", size = "none", richness = "none"}
}
game.map_settings.pollution.pollution_restored_per_tree_damage = 0
game.create_surface("empty_map", map_gen_settings)
@ -111,7 +109,6 @@ local function on_player_joined_game(event)
end
if player.online_time < 10 then
player.insert {name = 'raw-fish', count = 3}
player.insert {name = 'iron-axe', count = 1}
player.insert {name = 'light-armor', count = 1}
end
end

View File

@ -318,7 +318,7 @@ local function on_chunk_charted(event)
local size = 5 + math.floor(distance_to_center * 0.0075)
if size > 20 then size = 20 end
local amount = 100 + distance_to_center
map_functions.draw_rainbow_patch(pos, surface, size, amount)
map_functions.draw_rainbow_patch_v2(pos, surface, size, amount)
end
local function on_marked_for_deconstruction(event)

View File

@ -4,6 +4,15 @@ local f = {}
local math_random = math.random
local insert = table.insert
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
f.draw_rainbow_patch = function(position, surface, radius, richness)
if not position then return end
if not surface then return end
@ -34,6 +43,37 @@ f.draw_rainbow_patch = function(position, surface, radius, richness)
end
end
f.draw_rainbow_patch_v2 = function(position, surface, radius, richness)
if not position then return end
if not surface then return end
if not radius then return end
if not richness then return end
local modifier_1 = math_random(2,10)
local modifier_2 = math_random(50,150) * 0.0002
local modifier_3 = math_random(25,100) * 0.0015
local modifier_4 = math_random(15,30) * 0.01
local seed = game.surfaces[1].map_gen_settings.seed
local ores = {"stone", "coal", "iron-ore", "copper-ore"}
ores = shuffle(ores)
local richness_part = richness / (radius * 2)
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 noise = simplex_noise(pos.x * modifier_2, pos.y * modifier_2, seed) + simplex_noise(pos.x * modifier_3, pos.y * modifier_3, seed) * modifier_4
local distance_to_center = math.sqrt(x^2 + y^2)
local ore = ores[(math.ceil(noise * modifier_1) % 4) + 1]
local amount = richness - richness_part * distance_to_center
if amount > 1 then
if surface.can_place_entity({name = ore, position = pos, amount = amount}) then
if distance_to_center + (noise * radius * 0.5) < radius then
surface.create_entity{name = ore, position = pos, amount = amount}
end
end
end
end
end
end
f.draw_entity_circle = function(position, name, surface, radius, check_collision, amount)
if not position then return end
if not name then return end