mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-09-16 09:16:22 +02:00
Added tendril generation modes, removed old cluster generation method
This commit is contained in:
@@ -172,49 +172,9 @@ local Config = {
|
||||
ScatteredResources = {
|
||||
enabled = true,
|
||||
|
||||
-- ==============
|
||||
-- Debug settings
|
||||
-- ==============
|
||||
|
||||
-- shows the ore locations, only use when debugging (cluster mode)
|
||||
display_resource_fields = false,
|
||||
|
||||
-- shows the ore locations, only use when debugging (compound_cluster_mode)
|
||||
display_compound_ore_locations = false,
|
||||
|
||||
-- ===========================================================
|
||||
-- These settings affects both scattered_mode and cluster_mode
|
||||
-- ===========================================================
|
||||
|
||||
-- percentage of resource added to the sum. 100 tiles means
|
||||
-- 10% more resources with a distance_richness_modifier of 10
|
||||
-- 20% more resources with a distance_richness_modifier of 5
|
||||
distance_richness_modifier = 7,
|
||||
|
||||
-- increases the amount of liquids that need pumping
|
||||
liquid_value_modifiers = {
|
||||
['crude-oil'] = 750,
|
||||
},
|
||||
|
||||
-- weights per resource of spawning
|
||||
resource_weights = {
|
||||
['coal'] = 160,
|
||||
['copper-ore'] = 215,
|
||||
['iron-ore'] = 389,
|
||||
['stone'] = 212,
|
||||
['uranium-ore'] = 21,
|
||||
['crude-oil'] = 3,
|
||||
},
|
||||
|
||||
-- minimum distance from the spawn point required before it spawns
|
||||
minimum_resource_distance = {
|
||||
['coal'] = 16,
|
||||
['copper-ore'] = 18,
|
||||
['iron-ore'] = 18,
|
||||
['stone'] = 15,
|
||||
['uranium-ore'] = 86,
|
||||
['crude-oil'] = 57,
|
||||
},
|
||||
-- determines how distance is measured
|
||||
distance = function (x, y) return math.abs(x) + math.abs(y) end,
|
||||
--distance = function (x, y) return math.sqrt(x * x + y * y) end,
|
||||
|
||||
-- defines the weights of which resource_richness_value to spawn
|
||||
resource_richness_weights = {
|
||||
@@ -236,6 +196,19 @@ local Config = {
|
||||
['jackpot'] = {2001, 5000},
|
||||
},
|
||||
|
||||
-- increases the amount of resources by flat multiplication to initial amount
|
||||
-- highly suggested to use for fluids so their yield is reasonable
|
||||
resource_type_scalar = {
|
||||
['crude-oil'] = 750,
|
||||
},
|
||||
|
||||
-- ==============
|
||||
-- Debug settings
|
||||
-- ==============
|
||||
|
||||
-- shows the ore locations, only use when debugging (compound_cluster_mode)
|
||||
display_ore_clusters = true,
|
||||
|
||||
-- =======================
|
||||
-- Scattered mode settings
|
||||
-- =======================
|
||||
@@ -244,60 +217,53 @@ local Config = {
|
||||
scattered_mode = true,
|
||||
|
||||
-- defines the increased chance of spawning resources
|
||||
-- calculated_probability = resource_probability + ((distance / distance_probability_modifier) / 100)
|
||||
distance_probability_modifier = 10,
|
||||
-- calculated_probability = resource_probability + ((distance / scattered_distance_probability_modifier) / 100)
|
||||
-- this means the chance increases by 1% every DISTANCE tiles up to the max_probability
|
||||
scattered_distance_probability_modifier = 10,
|
||||
|
||||
-- min percentage of chance that resources will spawn after mining
|
||||
resource_probability = 0.01,
|
||||
scattered_min_probability = 0.01,
|
||||
|
||||
-- max chance of spawning resources based on resource_probability + calculated distance_probability_modifier
|
||||
max_resource_probability = 0.30,
|
||||
-- max chance of spawning resources based on resource_probability + calculated scattered_distance_probability_modifier
|
||||
scattered_max_probability = 0.10,
|
||||
|
||||
-- =====================
|
||||
-- Cluster mode settings
|
||||
-- =====================
|
||||
-- percentage of resource added to the sum. 100 tiles means
|
||||
-- 10% more resources with a distance_richness_modifier of 10
|
||||
-- 20% more resources with a distance_richness_modifier of 5
|
||||
scattered_distance_richness_modifier = 7,
|
||||
|
||||
-- creates clusters of ore with higher yields and frequency instead of evenly scattered ore
|
||||
-- lowers max resource max_resource_probability to 50% of the original value
|
||||
cluster_mode = true,
|
||||
-- multiplies probability only if cluster mode is enabled
|
||||
scattered_cluster_probability_multiplier = 0.5,
|
||||
|
||||
-- value between -1 and 1, higher value means stronger variance between coordinates
|
||||
-- (this means smaller, more frequent ore patches)
|
||||
noise_variance = 0.04,
|
||||
-- multiplies yield only if cluster mode is enabled
|
||||
scattered_cluster_yield_multiplier = 1.7,
|
||||
|
||||
-- a value between 0 and 1 that triggers the spawning of resource based on noise
|
||||
-- (lower values have larger patches, 0 means ~50% of the map is ore)
|
||||
noise_resource_threshold = 0.40,
|
||||
-- weights per resource of spawning
|
||||
scattered_resource_weights = {
|
||||
['coal'] = 160,
|
||||
['copper-ore'] = 215,
|
||||
['iron-ore'] = 389,
|
||||
['stone'] = 212,
|
||||
['uranium-ore'] = 21,
|
||||
['crude-oil'] = 3,
|
||||
},
|
||||
|
||||
-- raw multiplier for ore content in cluster mode
|
||||
cluster_yield_multiplier = 1.7,
|
||||
-- minimum distance from the spawn point required before it spawns
|
||||
scattered_minimum_resource_distance = {
|
||||
['coal'] = 16,
|
||||
['copper-ore'] = 18,
|
||||
['iron-ore'] = 18,
|
||||
['stone'] = 15,
|
||||
['uranium-ore'] = 86,
|
||||
['crude-oil'] = 57,
|
||||
},
|
||||
|
||||
-- ==============================
|
||||
-- Compound cluster mode settings
|
||||
-- ==============================
|
||||
|
||||
-- creates compound clusters of ores defined by a layered ore-gen
|
||||
compound_cluster_mode = false,
|
||||
|
||||
-- defines the weights of which resource_richness_value range to spawn
|
||||
compound_cluster_richness_weights = {
|
||||
['scarce'] = 440,
|
||||
['low'] = 350,
|
||||
['sufficient'] = 164,
|
||||
['good'] = 30,
|
||||
['plenty'] = 10,
|
||||
['jackpot'] = 6,
|
||||
},
|
||||
|
||||
-- defines the min and max range of base quantity for ores to spawn
|
||||
compound_cluster_richness_values = {
|
||||
['scarce'] = {1, 200},
|
||||
['low'] = {201, 400},
|
||||
['sufficient'] = {401, 750},
|
||||
['good'] = {751, 1200},
|
||||
['plenty'] = {1201, 2000},
|
||||
['jackpot'] = {2001, 5000},
|
||||
},
|
||||
cluster_mode = true,
|
||||
|
||||
-- in compound cluster mode, final ore quantities are generated by the following procedure:
|
||||
-- iterate through each cluster checking the following conditions
|
||||
@@ -309,29 +275,49 @@ local Config = {
|
||||
-- if distance < distances[resource_type], check the next cluster
|
||||
-- a range of values is selected from richness_values based on richness_weights
|
||||
-- base_amount = a random value from within the selected range of values
|
||||
-- amount is adjusted by 1 + 0.01*(distance / distance_richness)
|
||||
-- amount is multiplied by cluster yield
|
||||
-- amount is multiplied by 1 + 0.01*(distance / distance_richness)
|
||||
-- this means every distance_richness tiles, the quantity increases by 1%
|
||||
-- if the resource_type has an entry in the type_scalar
|
||||
-- then the amount is multiplied by the scalar
|
||||
-- the resource is then generated and no further clusters are checked
|
||||
|
||||
-- increases the amount of ore by flat multiplication to initial amount
|
||||
-- highly suggested to use for fluids so their yield is reasonable
|
||||
compound_cluster_type_scalar = {
|
||||
['crude-oil'] = 750,
|
||||
},
|
||||
|
||||
-- defines all ore patches to be generated. Add as many clusters as
|
||||
-- needed. Clusters listed first have a higher placement priority over
|
||||
-- the latter clusters
|
||||
compound_clusters = {
|
||||
--
|
||||
-- noise types:
|
||||
-- cluster: same as vanilla factorio generation
|
||||
-- skip: skips this cluster
|
||||
-- connected_tendril: long ribbons of ore
|
||||
-- fragmented_tendril: long ribbons of ore that occur when inside another
|
||||
-- region of ribbons
|
||||
--
|
||||
-- noise source types and configurations
|
||||
-- perlin: same as vanilla factorio generation
|
||||
-- variance: increase to make patches closer together and smaller
|
||||
-- note that this is the inverse of the cluster_mode variance
|
||||
-- threshold: increase to shrink size of patches
|
||||
-- simplex: similar to perlin
|
||||
-- zero: does nothing with this source
|
||||
-- one: adds the weight directly to the noise calculation
|
||||
clusters = {
|
||||
-- start the next line with 3 dashes to enable default single cluster mode
|
||||
-- or with 2 dashes to disable it
|
||||
|
||||
{variance=0.04,
|
||||
threshold=0.40,
|
||||
yield=1.7,
|
||||
---[[ Single clusters
|
||||
{
|
||||
yield=1.0,
|
||||
min_distance=30,
|
||||
distance_richness=7,
|
||||
noise="perlin",
|
||||
noise_settings = {
|
||||
type = "cluster",
|
||||
threshold = 0.40,
|
||||
sources = {
|
||||
{variance=25, weight = 1, offset = 000, type="perlin"},
|
||||
}
|
||||
},
|
||||
weights = {
|
||||
['coal'] = 160,
|
||||
['copper-ore'] = 215,
|
||||
@@ -348,23 +334,240 @@ local Config = {
|
||||
['uranium-ore'] = 86,
|
||||
['crude-oil'] = 57,
|
||||
}, },
|
||||
--]]
|
||||
|
||||
-- { variance=0.04,
|
||||
-- threshold=0.40,
|
||||
-- yield=1.7,
|
||||
-- min_distance=18,
|
||||
-- distance_richness=7,
|
||||
-- noise="perlin",
|
||||
-- weights = {
|
||||
-- ['copper-ore'] = 1,
|
||||
-- ['iron-ore'] = 2,
|
||||
-- ['skip'] = 2,
|
||||
-- },
|
||||
-- distances = {
|
||||
-- }, },
|
||||
-- start the next line with 3 dashes to enable default tendril mode
|
||||
-- or with 2 dashes to disable it
|
||||
|
||||
--[[ Tendril clusters
|
||||
{ -- tendril default large
|
||||
yield=1.5,
|
||||
min_distance=30,
|
||||
distance_richness=7,
|
||||
noise_settings = {
|
||||
type = "connected_tendril",
|
||||
threshold = 0.05,
|
||||
sources = {
|
||||
{variance=350*2, weight = 1.000, offset = 000, type="simplex"},
|
||||
{variance=200*2, weight = 0.350, offset = 150, type="simplex"},
|
||||
{variance=050*2, weight = 0.050, offset = 300, type="simplex"},
|
||||
{variance=020*2, weight = 0.015, offset = 450, type="simplex"},
|
||||
}
|
||||
},
|
||||
weights = {
|
||||
['coal'] = 160,
|
||||
['copper-ore'] = 215,
|
||||
['iron-ore'] = 389,
|
||||
['stone'] = 212,
|
||||
['uranium-ore'] = 21,
|
||||
},
|
||||
distances = {
|
||||
['coal'] = 16,
|
||||
['copper-ore'] = 18,
|
||||
['iron-ore'] = 18,
|
||||
['stone'] = 15,
|
||||
['uranium-ore'] = 86,
|
||||
}, },
|
||||
{ -- tendril default small
|
||||
yield=1.0,
|
||||
min_distance=30,
|
||||
distance_richness=7,
|
||||
noise_settings = {
|
||||
type = "connected_tendril",
|
||||
threshold = 0.05,
|
||||
sources = {
|
||||
{variance=120, weight = 1.000, offset = 000, type="simplex"},
|
||||
{variance=060, weight = 0.300, offset = 150, type="simplex"},
|
||||
{variance=040, weight = 0.200, offset = 300, type="simplex"},
|
||||
{variance=020, weight = 0.090, offset = 450, type="simplex"},
|
||||
}
|
||||
},
|
||||
weights = {
|
||||
['coal'] = 160,
|
||||
['copper-ore'] = 215,
|
||||
['iron-ore'] = 389,
|
||||
['stone'] = 212,
|
||||
['uranium-ore'] = 21,
|
||||
},
|
||||
distances = {
|
||||
['coal'] = 16,
|
||||
['copper-ore'] = 18,
|
||||
['iron-ore'] = 18,
|
||||
['stone'] = 15,
|
||||
['uranium-ore'] = 86,
|
||||
},
|
||||
},
|
||||
{ -- tendril default fragments
|
||||
yield=1.0,
|
||||
min_distance=30,
|
||||
distance_richness=7,
|
||||
noise_settings = {
|
||||
--type = "fragmented_tendril",
|
||||
type = 'skip',
|
||||
threshold = 0.05,
|
||||
discriminator_threshold = 0.4,
|
||||
sources = {
|
||||
{variance=050, weight = 1.000, offset = 600, type="simplex"},
|
||||
{variance=030, weight = 0.500, offset = 750, type="simplex"},
|
||||
{variance=020, weight = 0.250, offset = 900, type="simplex"},
|
||||
{variance=010, weight = 0.100, offset =1050, type="simplex"},
|
||||
},
|
||||
discriminator = {
|
||||
{variance=120, weight = 1.000, offset = 000, type="simplex"},
|
||||
{variance=060, weight = 0.300, offset = 150, type="simplex"},
|
||||
{variance=040, weight = 0.200, offset = 300, type="simplex"},
|
||||
{variance=020, weight = 0.090, offset = 450, type="simplex"},
|
||||
},
|
||||
},
|
||||
weights = {
|
||||
['coal'] = 160,
|
||||
['copper-ore'] = 215,
|
||||
['iron-ore'] = 389,
|
||||
['stone'] = 212,
|
||||
['uranium-ore'] = 21,
|
||||
},
|
||||
distances = {
|
||||
['coal'] = 16,
|
||||
['copper-ore'] = 18,
|
||||
['iron-ore'] = 18,
|
||||
['stone'] = 15,
|
||||
['uranium-ore'] = 86,
|
||||
},
|
||||
},
|
||||
{ -- tendril default fragments coal
|
||||
yield=0.25,
|
||||
min_distance=30,
|
||||
distance_richness=7,
|
||||
noise_settings = {
|
||||
type = "fragmented_tendril",
|
||||
threshold = 0.05,
|
||||
discriminator_threshold = 0.4,
|
||||
sources = {
|
||||
{variance=050, weight = 1.000, offset = 600, type="simplex"},
|
||||
{variance=030, weight = 0.500, offset = 750, type="simplex"},
|
||||
{variance=020, weight = 0.250, offset = 900, type="simplex"},
|
||||
{variance=010, weight = 0.100, offset =1050, type="simplex"},
|
||||
},
|
||||
discriminator = {
|
||||
{variance=120, weight = 1.000, offset = 000, type="simplex"},
|
||||
{variance=060, weight = 0.300, offset = 150, type="simplex"},
|
||||
{variance=040, weight = 0.200, offset = 300, type="simplex"},
|
||||
{variance=020, weight = 0.090, offset = 450, type="simplex"},
|
||||
},
|
||||
},
|
||||
weights = {
|
||||
['coal'] = 1,
|
||||
},
|
||||
distances = {
|
||||
['coal'] = 16,
|
||||
},
|
||||
},
|
||||
{ -- tendril default fragments iron
|
||||
yield=0.25,
|
||||
min_distance=30,
|
||||
distance_richness=7,
|
||||
noise_settings = {
|
||||
type = "fragmented_tendril",
|
||||
threshold = 0.05,
|
||||
discriminator_threshold = 0.4,
|
||||
sources = {
|
||||
{variance=050, weight = 1.000, offset = 600, type="simplex"},
|
||||
{variance=030, weight = 0.500, offset = 750, type="simplex"},
|
||||
{variance=020, weight = 0.250, offset = 900, type="simplex"},
|
||||
{variance=010, weight = 0.100, offset =1050, type="simplex"},
|
||||
},
|
||||
discriminator = {
|
||||
{variance=120, weight = 1.000, offset = 000, type="simplex"},
|
||||
{variance=060, weight = 0.300, offset = 150, type="simplex"},
|
||||
{variance=040, weight = 0.200, offset = 300, type="simplex"},
|
||||
{variance=020, weight = 0.090, offset = 450, type="simplex"},
|
||||
},
|
||||
},
|
||||
weights = {
|
||||
['iron-ore'] = 389,
|
||||
},
|
||||
distances = {
|
||||
['coal'] = 16,
|
||||
['iron-ore'] = 18,
|
||||
},
|
||||
},
|
||||
{ -- tendril default fragments copper
|
||||
yield=0.25,
|
||||
min_distance=30,
|
||||
distance_richness=7,
|
||||
noise_settings = {
|
||||
type = "fragmented_tendril",
|
||||
threshold = 0.05,
|
||||
discriminator_threshold = 0.4,
|
||||
sources = {
|
||||
{variance=050, weight = 1.000, offset = 600, type="simplex"},
|
||||
{variance=030, weight = 0.500, offset = 750, type="simplex"},
|
||||
{variance=020, weight = 0.250, offset = 900, type="simplex"},
|
||||
{variance=010, weight = 0.100, offset =1050, type="simplex"},
|
||||
},
|
||||
discriminator = {
|
||||
{variance=120, weight = 1.000, offset = 000, type="simplex"},
|
||||
{variance=060, weight = 0.300, offset = 150, type="simplex"},
|
||||
{variance=040, weight = 0.200, offset = 300, type="simplex"},
|
||||
{variance=020, weight = 0.090, offset = 450, type="simplex"},
|
||||
},
|
||||
},
|
||||
weights = {
|
||||
['copper-ore'] = 215,
|
||||
},
|
||||
distances = {
|
||||
['copper-ore'] = 18,
|
||||
},
|
||||
},
|
||||
{ -- tendril default fragments stone
|
||||
yield=0.25,
|
||||
min_distance=30,
|
||||
distance_richness=7,
|
||||
noise_settings = {
|
||||
type = "fragmented_tendril",
|
||||
threshold = 0.05,
|
||||
discriminator_threshold = 0.4,
|
||||
sources = {
|
||||
{variance=050, weight = 1.000, offset = 600, type="simplex"},
|
||||
{variance=030, weight = 0.500, offset = 750, type="simplex"},
|
||||
{variance=020, weight = 0.250, offset = 900, type="simplex"},
|
||||
{variance=010, weight = 0.100, offset =1050, type="simplex"},
|
||||
},
|
||||
discriminator = {
|
||||
{variance=120, weight = 1.000, offset = 000, type="simplex"},
|
||||
{variance=060, weight = 0.300, offset = 150, type="simplex"},
|
||||
{variance=040, weight = 0.200, offset = 300, type="simplex"},
|
||||
{variance=020, weight = 0.090, offset = 450, type="simplex"},
|
||||
},
|
||||
},
|
||||
weights = {
|
||||
['stone'] = 1,
|
||||
},
|
||||
distances = {
|
||||
['stone'] = 15,
|
||||
},
|
||||
},
|
||||
{ -- crude oil
|
||||
yield=1.7,
|
||||
min_distance=57,
|
||||
distance_richness=7,
|
||||
noise_settings = {
|
||||
type = "cluster",
|
||||
threshold = 0.40,
|
||||
sources = {
|
||||
{variance=25, weight = 1, offset = 000, type="perlin"},
|
||||
},
|
||||
},
|
||||
weights = {
|
||||
['skip'] = 997,
|
||||
['crude-oil'] = 3,
|
||||
},
|
||||
distances = {
|
||||
['crude-oil'] = 57,
|
||||
},
|
||||
},
|
||||
--]]
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
-- controls the alien spawning mechanic
|
||||
|
@@ -41,86 +41,72 @@ function ScatteredResources.register(config)
|
||||
-- '-1' is reserved for cluster mode
|
||||
-- compound clusters use as many indexes as needed > 1
|
||||
local base_seed
|
||||
local function seeded_noise(surface, x, y, index, cluster_variance, noise_type)
|
||||
base_seed = base_seed or surface.map_gen_settings.seed + surface.index + 400
|
||||
noise_type = noise_type or "perlin"
|
||||
if noise_type == "perlin" then
|
||||
return Perlin.noise(x * cluster_variance, y * cluster_variance, base_seed + 200 * index)
|
||||
elseif noise_type == "simplex" then
|
||||
return Simplex.d2(x * cluster_variance, y * cluster_variance, base_seed + 200 * index)
|
||||
end
|
||||
local function seeded_noise(surface, x, y, index, sources)
|
||||
base_seed = base_seed or surface.map_gen_settings.seed + surface.index + 4000
|
||||
local noise = 0
|
||||
for _, settings in ipairs(sources) do
|
||||
settings.type = settings.type or 'perlin'
|
||||
settings.offset = settings.offset or 0
|
||||
if settings.type == 'zero' then
|
||||
noise = noise + 0
|
||||
elseif settings.type == 'one' then
|
||||
noise = noise + settings.weight * 1
|
||||
elseif settings.type == 'perlin' then
|
||||
noise = noise + settings.weight * Perlin.noise(x/settings.variance, y/settings.variance,
|
||||
base_seed + 2000*index + settings.offset)
|
||||
elseif settings.type == 'simplex' then
|
||||
noise = noise + settings.weight * Simplex.d2(x/settings.variance, y/settings.variance,
|
||||
base_seed + 2000*index + settings.offset)
|
||||
else
|
||||
Debug.print('noise type \'' .. settings.type .. '\' not recognized')
|
||||
end
|
||||
|
||||
-- cluster and scattered spawning
|
||||
end
|
||||
return noise
|
||||
end
|
||||
|
||||
-- global config values
|
||||
|
||||
local noise_resource_threshold = config.noise_resource_threshold
|
||||
local noise_variance = config.noise_variance
|
||||
local cluster_mode = config.cluster_mode
|
||||
local distance_probability_modifier = config.distance_probability_modifier
|
||||
local resource_probability = config.resource_probability
|
||||
local max_resource_probability = config.max_resource_probability
|
||||
local resource_weights = config.resource_weights
|
||||
local resource_richness_weights = config.resource_richness_weights
|
||||
local distance_richness_modifier = config.distance_richness_modifier
|
||||
local liquid_value_modifiers = config.liquid_value_modifiers
|
||||
local resource_richness_values = config.resource_richness_values
|
||||
local minimum_resource_distance = config.minimum_resource_distance
|
||||
local cluster_yield_multiplier = config.cluster_yield_multiplier
|
||||
|
||||
local resource_weights_sum = 0
|
||||
for _, weight in pairs(resource_weights) do
|
||||
resource_weights_sum = resource_weights_sum + weight
|
||||
end
|
||||
local resource_richness_weights_sum = 0
|
||||
for _, weight in pairs(resource_richness_weights) do
|
||||
resource_richness_weights_sum = resource_richness_weights_sum + weight
|
||||
end
|
||||
local resource_richness_values = config.resource_richness_values
|
||||
local resource_type_scalar = config.resource_type_scalar
|
||||
|
||||
local function spawn_resource(surface, x, y, distance)
|
||||
local resource_name = get_name_by_weight(resource_weights, resource_weights_sum)
|
||||
-- scattered config values
|
||||
local s_mode = config.scattered_mode
|
||||
local s_dist_mod = config.scattered_distance_probability_modifier
|
||||
local s_min_prob = config.scattered_min_probability
|
||||
local s_max_prob = config.scattered_max_probability
|
||||
local s_dist_richness = config.scattered_distance_richness_modifier
|
||||
local s_cluster_prob = config.scattered_cluster_probability_multiplier
|
||||
local s_cluster_mult = config.scattered_cluster_yield_multiplier
|
||||
|
||||
if (minimum_resource_distance[resource_name] > distance) then
|
||||
return
|
||||
local s_resource_weights = config.scattered_resource_weights
|
||||
local s_resource_weights_sum = 0
|
||||
for _, weight in pairs(s_resource_weights) do
|
||||
s_resource_weights_sum = s_resource_weights_sum + weight
|
||||
end
|
||||
local s_min_dist = config.scattered_minimum_resource_distance
|
||||
|
||||
local min_max = resource_richness_values[get_name_by_weight(resource_richness_weights, resource_richness_weights_sum)]
|
||||
local amount = ceil(random(min_max[1], min_max[2]) * (1 + ((distance / distance_richness_modifier) * 0.01)))
|
||||
|
||||
if liquid_value_modifiers[resource_name] then
|
||||
amount = amount * liquid_value_modifiers[resource_name]
|
||||
end
|
||||
|
||||
if (cluster_mode) then
|
||||
amount = amount * cluster_yield_multiplier
|
||||
end
|
||||
|
||||
local position = {x = x, y = y}
|
||||
|
||||
Template.resources(surface, {{name = resource_name, position = position, amount = amount}})
|
||||
end
|
||||
-- cluster config values
|
||||
local cluster_mode = config.cluster_mode
|
||||
|
||||
-- compound cluster spawning
|
||||
|
||||
local cc_mode = config.compound_cluster_mode
|
||||
local cc_richness_weights = config.compound_cluster_richness_weights
|
||||
local cc_richness_values = config.compound_cluster_richness_values
|
||||
local cc_type_scalar = config.compound_cluster_type_scalar
|
||||
local cc_clusters = config.compound_clusters
|
||||
|
||||
local cc_richness_weights_sum = 0
|
||||
for _, weight in pairs(cc_richness_weights) do
|
||||
cc_richness_weights_sum = cc_richness_weights_sum + weight
|
||||
end
|
||||
local cc_cluster_count = 0
|
||||
for _, cluster in ipairs(cc_clusters) do
|
||||
cc_cluster_count = cc_cluster_count + 1
|
||||
local c_mode = config.cluster_mode
|
||||
local c_clusters = config.clusters
|
||||
local c_count = 0
|
||||
for _, cluster in ipairs(c_clusters) do
|
||||
c_count = c_count + 1
|
||||
cluster.weights_sum = 0
|
||||
for _, weight in pairs(cluster.weights) do
|
||||
cluster.weights_sum = cluster.weights_sum + weight
|
||||
end
|
||||
end
|
||||
|
||||
local function spawn_compound_cluser_resource(surface, x, y, cluster_index, cluster)
|
||||
local function spawn_cluster_resource(surface, x, y, cluster_index, cluster)
|
||||
local distance = sqrt(x * x + y * y)
|
||||
local resource_name = get_name_by_weight(cluster.weights, cluster.weights_sum)
|
||||
if resource_name == 'skip' then
|
||||
@@ -132,32 +118,19 @@ function ScatteredResources.register(config)
|
||||
end
|
||||
end
|
||||
|
||||
local range = cc_richness_values[get_name_by_weight(cc_richness_weights, cc_richness_weights_sum)]
|
||||
local range = resource_richness_values[get_name_by_weight(resource_richness_weights, resource_richness_weights_sum)]
|
||||
local amount = random(range[1], range[2])
|
||||
amount = amount * (1 + ((distance / cluster.distance_richness) * 0.01))
|
||||
amount = amount * cluster.yield
|
||||
|
||||
if cc_type_scalar[resource_name] then
|
||||
amount = amount * cc_type_scalar[resource_name]
|
||||
if resource_type_scalar[resource_name] then
|
||||
amount = amount * resource_type_scalar[resource_name]
|
||||
end
|
||||
|
||||
Template.resources(surface, {{name = resource_name, position = {x = x, y = y}, amount = floor(amount)}})
|
||||
Template.resources(surface, {{name = resource_name, position = {x = x, y = y}, amount = ceil(amount)}})
|
||||
return true
|
||||
end
|
||||
|
||||
local function spawn_compound_clusters(surface, x, y, distance)
|
||||
for index,cluster in ipairs(cc_clusters) do
|
||||
if distance >= cluster.min_distance then
|
||||
if seeded_noise(surface, x, y, index, cluster.variance,
|
||||
cluster.noise or 'perlin') >= cluster.threshold then
|
||||
if spawn_compound_cluser_resource(surface, x, y, index, cluster) then
|
||||
return true -- resource spawned
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return false -- nothing spawned
|
||||
end
|
||||
|
||||
-- event registration
|
||||
Event.add(Template.events.on_void_removed, function (event)
|
||||
local position = event.position
|
||||
@@ -165,67 +138,101 @@ function ScatteredResources.register(config)
|
||||
local y = position.y
|
||||
local surface = event.surface
|
||||
|
||||
local distance = sqrt(x * x + y * y)
|
||||
local distance = config.distance(x, y)
|
||||
|
||||
if cc_mode then
|
||||
if (spawn_compound_clusters(surface, x, y, distance)) then
|
||||
return
|
||||
if c_mode then
|
||||
for index,cluster in ipairs(c_clusters) do
|
||||
if distance >= cluster.min_distance and cluster.noise_settings.type ~= 'skip' then
|
||||
if cluster.noise_settings.type == "connected_tendril" then
|
||||
local noise = seeded_noise(surface, x, y, index, cluster.noise_settings.sources)
|
||||
if -1 * cluster.noise_settings.threshold < noise and noise < cluster.noise_settings.threshold then
|
||||
if spawn_cluster_resource(surface, x, y, index, cluster) then
|
||||
return -- resource spawned
|
||||
end
|
||||
end
|
||||
elseif cluster.noise_settings.type == "fragmented_tendril" then
|
||||
local noise1 = seeded_noise(surface, x, y, index, cluster.noise_settings.sources)
|
||||
local noise2 = seeded_noise(surface, x, y, index, cluster.noise_settings.discriminator)
|
||||
if -1 * cluster.noise_settings.threshold < noise1 and noise1 < cluster.noise_settings.threshold
|
||||
and -1 * cluster.noise_settings.discriminator_threshold < noise2
|
||||
and noise2 < cluster.noise_settings.discriminator_threshold then
|
||||
if spawn_cluster_resource(surface, x, y, index, cluster) then
|
||||
return -- resource spawned
|
||||
end
|
||||
end
|
||||
else
|
||||
local noise = seeded_noise(surface, x, y, index, cluster.noise_settings.sources)
|
||||
if noise >= cluster.noise_settings.threshold then
|
||||
if spawn_cluster_resource(surface, x, y, index, cluster) then
|
||||
return -- resource spawned
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
distance = floor(distance)
|
||||
|
||||
if (cluster_mode and seeded_noise(surface, x, y, -1, noise_variance) > noise_resource_threshold) then
|
||||
spawn_resource(surface, x, y, distance)
|
||||
return
|
||||
end
|
||||
|
||||
if not scattered_mode then
|
||||
return
|
||||
end
|
||||
if s_mode then
|
||||
local probability = math.min(s_max_prob, s_min_prob + 0.01 * (distance / s_dist_mod))
|
||||
|
||||
local calculated_probability = resource_probability + ((distance / distance_probability_modifier) * 0.01)
|
||||
local probability = max_resource_probability
|
||||
|
||||
if (calculated_probability < probability) then
|
||||
probability = calculated_probability
|
||||
end
|
||||
|
||||
-- cluster mode reduces the max probability to reduce max spread
|
||||
if (cluster_mode) then
|
||||
probability = probability * 0.5
|
||||
probability = probability * s_cluster_prob
|
||||
end
|
||||
|
||||
if (probability > random()) then
|
||||
spawn_resource(surface, x, y, distance)
|
||||
-- spawn single resource point for scatter mode
|
||||
local resource_name = get_name_by_weight(s_resource_weights, s_resource_weights_sum)
|
||||
if resource_name == 'skip' or s_min_dist[resource_name] > distance then
|
||||
return
|
||||
end
|
||||
|
||||
local range = resource_richness_values[get_name_by_weight(resource_richness_weights, resource_richness_weights_sum)]
|
||||
local amount = random(range[1], range[2])
|
||||
amount = amount * (1 + ((distance / s_dist_richness) * 0.01))
|
||||
|
||||
if resource_type_scalar[resource_name] then
|
||||
amount = amount * resource_type_scalar[resource_name]
|
||||
end
|
||||
|
||||
if (cluster_mode) then
|
||||
amount = amount * s_cluster_mult
|
||||
end
|
||||
|
||||
Template.resources(surface, {{name = resource_name, position={x=x,y=y}, amount = ceil(amount)}})
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
if (config.display_resource_fields) then
|
||||
if (config.display_ore_clusters) then
|
||||
local color = {}
|
||||
Event.add(defines.events.on_chunk_generated, function (event)
|
||||
local surface = event.surface
|
||||
local area = event.area
|
||||
|
||||
for x = area.left_top.x, area.left_top.x + 31 do
|
||||
for y = area.left_top.y, area.left_top.y + 31 do
|
||||
if seeded_noise(surface, x, y, -1, noise_variance) >= noise_resource_threshold then
|
||||
Debug.print_grid_value('ore', surface, {x = x, y = y}, nil, nil, true)
|
||||
for index,cluster in ipairs(c_clusters) do
|
||||
if cluster.noise_settings.type == "connected_tendril" then
|
||||
local noise = seeded_noise(surface, x, y, index, cluster.noise_settings.sources)
|
||||
if -1 * cluster.noise_settings.threshold < noise and noise < cluster.noise_settings.threshold then
|
||||
color[index] = color[index] or {r=random(), g=random(), b=random()}
|
||||
Debug.print_colored_grid_value('o' .. index, surface, {x = x, y = y}, nil, nil, true, 0, color[index])
|
||||
end
|
||||
elseif cluster.noise_settings.type == "fragmented_tendril" then
|
||||
local noise1 = seeded_noise(surface, x, y, index, cluster.noise_settings.sources)
|
||||
local noise2 = seeded_noise(surface, x, y, index, cluster.noise_settings.discriminator)
|
||||
if -1 * cluster.noise_settings.threshold < noise1 and noise1 < cluster.noise_settings.threshold
|
||||
and -1 * cluster.noise_settings.discriminator_threshold < noise2
|
||||
and noise2 < cluster.noise_settings.discriminator_threshold then
|
||||
color[index] = color[index] or {r=random(), g=random(), b=random()}
|
||||
Debug.print_colored_grid_value('o' .. index, surface, {x = x, y = y}, nil, nil, true, 0, color[index])
|
||||
end
|
||||
elseif cluster.noise_settings.type ~= 'skip' then
|
||||
local noise = seeded_noise(surface, x, y, index, cluster.noise_settings.sources)
|
||||
if noise >= cluster.noise_settings.threshold then
|
||||
color[index] = color[index] or {r=random(), g=random(), b=random()}
|
||||
Debug.print_colored_grid_value('o' .. index, surface, {x = x, y = y}, nil, nil, true, 0, color[index])
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
if (config.display_compound_ore_locations) then
|
||||
Event.add(defines.events.on_chunk_generated, function (event)
|
||||
local surface = event.surface
|
||||
local area = event.area
|
||||
|
||||
for x = area.left_top.x, area.left_top.x + 31 do
|
||||
for y = area.left_top.y, area.left_top.y + 31 do
|
||||
for index,cluster in ipairs(cc_clusters) do
|
||||
if seeded_noise(surface, x, y, index, cluster.variance,
|
||||
cluster.noise or 'perlin') >= cluster.threshold then
|
||||
Debug.print_grid_value('o' .. index, surface, {x = x, y = y}, nil, nil, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user