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 = {
|
ScatteredResources = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
|
|
||||||
-- ==============
|
-- determines how distance is measured
|
||||||
-- Debug settings
|
distance = function (x, y) return math.abs(x) + math.abs(y) end,
|
||||||
-- ==============
|
--distance = function (x, y) return math.sqrt(x * x + y * y) end,
|
||||||
|
|
||||||
-- 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,
|
|
||||||
},
|
|
||||||
|
|
||||||
-- defines the weights of which resource_richness_value to spawn
|
-- defines the weights of which resource_richness_value to spawn
|
||||||
resource_richness_weights = {
|
resource_richness_weights = {
|
||||||
@@ -236,6 +196,19 @@ local Config = {
|
|||||||
['jackpot'] = {2001, 5000},
|
['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
|
-- Scattered mode settings
|
||||||
-- =======================
|
-- =======================
|
||||||
@@ -244,60 +217,53 @@ local Config = {
|
|||||||
scattered_mode = true,
|
scattered_mode = true,
|
||||||
|
|
||||||
-- defines the increased chance of spawning resources
|
-- defines the increased chance of spawning resources
|
||||||
-- calculated_probability = resource_probability + ((distance / distance_probability_modifier) / 100)
|
-- calculated_probability = resource_probability + ((distance / scattered_distance_probability_modifier) / 100)
|
||||||
distance_probability_modifier = 10,
|
-- 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
|
-- 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 chance of spawning resources based on resource_probability + calculated scattered_distance_probability_modifier
|
||||||
max_resource_probability = 0.30,
|
scattered_max_probability = 0.10,
|
||||||
|
|
||||||
-- =====================
|
-- percentage of resource added to the sum. 100 tiles means
|
||||||
-- Cluster mode settings
|
-- 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,
|
||||||
|
|
||||||
|
-- multiplies probability only if cluster mode is enabled
|
||||||
|
scattered_cluster_probability_multiplier = 0.5,
|
||||||
|
|
||||||
|
-- multiplies yield only if cluster mode is enabled
|
||||||
|
scattered_cluster_yield_multiplier = 1.7,
|
||||||
|
|
||||||
|
-- weights per resource of spawning
|
||||||
|
scattered_resource_weights = {
|
||||||
|
['coal'] = 160,
|
||||||
|
['copper-ore'] = 215,
|
||||||
|
['iron-ore'] = 389,
|
||||||
|
['stone'] = 212,
|
||||||
|
['uranium-ore'] = 21,
|
||||||
|
['crude-oil'] = 3,
|
||||||
|
},
|
||||||
|
|
||||||
-- creates clusters of ore with higher yields and frequency instead of evenly scattered ore
|
-- minimum distance from the spawn point required before it spawns
|
||||||
-- lowers max resource max_resource_probability to 50% of the original value
|
scattered_minimum_resource_distance = {
|
||||||
cluster_mode = true,
|
['coal'] = 16,
|
||||||
|
['copper-ore'] = 18,
|
||||||
-- value between -1 and 1, higher value means stronger variance between coordinates
|
['iron-ore'] = 18,
|
||||||
-- (this means smaller, more frequent ore patches)
|
['stone'] = 15,
|
||||||
noise_variance = 0.04,
|
['uranium-ore'] = 86,
|
||||||
|
['crude-oil'] = 57,
|
||||||
-- 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,
|
|
||||||
|
|
||||||
-- raw multiplier for ore content in cluster mode
|
|
||||||
cluster_yield_multiplier = 1.7,
|
|
||||||
|
|
||||||
-- ==============================
|
-- ==============================
|
||||||
-- Compound cluster mode settings
|
-- Compound cluster mode settings
|
||||||
-- ==============================
|
-- ==============================
|
||||||
|
|
||||||
-- creates compound clusters of ores defined by a layered ore-gen
|
-- creates compound clusters of ores defined by a layered ore-gen
|
||||||
compound_cluster_mode = false,
|
cluster_mode = true,
|
||||||
|
|
||||||
-- 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},
|
|
||||||
},
|
|
||||||
|
|
||||||
-- in compound cluster mode, final ore quantities are generated by the following procedure:
|
-- in compound cluster mode, final ore quantities are generated by the following procedure:
|
||||||
-- iterate through each cluster checking the following conditions
|
-- iterate through each cluster checking the following conditions
|
||||||
@@ -309,29 +275,49 @@ local Config = {
|
|||||||
-- if distance < distances[resource_type], check the next cluster
|
-- if distance < distances[resource_type], check the next cluster
|
||||||
-- a range of values is selected from richness_values based on richness_weights
|
-- 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
|
-- 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%
|
-- this means every distance_richness tiles, the quantity increases by 1%
|
||||||
-- if the resource_type has an entry in the type_scalar
|
-- if the resource_type has an entry in the type_scalar
|
||||||
-- then the amount is multiplied by the scalar
|
-- then the amount is multiplied by the scalar
|
||||||
-- the resource is then generated and no further clusters are checked
|
-- 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
|
-- defines all ore patches to be generated. Add as many clusters as
|
||||||
-- needed. Clusters listed first have a higher placement priority over
|
-- needed. Clusters listed first have a higher placement priority over
|
||||||
-- the latter clusters
|
-- the latter clusters
|
||||||
compound_clusters = {
|
--
|
||||||
|
-- noise types:
|
||||||
{variance=0.04,
|
-- cluster: same as vanilla factorio generation
|
||||||
threshold=0.40,
|
-- skip: skips this cluster
|
||||||
yield=1.7,
|
-- 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
|
||||||
|
|
||||||
|
---[[ Single clusters
|
||||||
|
{
|
||||||
|
yield=1.0,
|
||||||
min_distance=30,
|
min_distance=30,
|
||||||
distance_richness=7,
|
distance_richness=7,
|
||||||
noise="perlin",
|
noise_settings = {
|
||||||
|
type = "cluster",
|
||||||
|
threshold = 0.40,
|
||||||
|
sources = {
|
||||||
|
{variance=25, weight = 1, offset = 000, type="perlin"},
|
||||||
|
}
|
||||||
|
},
|
||||||
weights = {
|
weights = {
|
||||||
['coal'] = 160,
|
['coal'] = 160,
|
||||||
['copper-ore'] = 215,
|
['copper-ore'] = 215,
|
||||||
@@ -348,23 +334,240 @@ local Config = {
|
|||||||
['uranium-ore'] = 86,
|
['uranium-ore'] = 86,
|
||||||
['crude-oil'] = 57,
|
['crude-oil'] = 57,
|
||||||
}, },
|
}, },
|
||||||
|
--]]
|
||||||
-- { variance=0.04,
|
|
||||||
-- threshold=0.40,
|
-- start the next line with 3 dashes to enable default tendril mode
|
||||||
-- yield=1.7,
|
-- or with 2 dashes to disable it
|
||||||
-- min_distance=18,
|
|
||||||
-- distance_richness=7,
|
--[[ Tendril clusters
|
||||||
-- noise="perlin",
|
{ -- tendril default large
|
||||||
-- weights = {
|
yield=1.5,
|
||||||
-- ['copper-ore'] = 1,
|
min_distance=30,
|
||||||
-- ['iron-ore'] = 2,
|
distance_richness=7,
|
||||||
-- ['skip'] = 2,
|
noise_settings = {
|
||||||
-- },
|
type = "connected_tendril",
|
||||||
-- distances = {
|
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
|
-- controls the alien spawning mechanic
|
||||||
|
@@ -41,86 +41,72 @@ function ScatteredResources.register(config)
|
|||||||
-- '-1' is reserved for cluster mode
|
-- '-1' is reserved for cluster mode
|
||||||
-- compound clusters use as many indexes as needed > 1
|
-- compound clusters use as many indexes as needed > 1
|
||||||
local base_seed
|
local base_seed
|
||||||
local function seeded_noise(surface, x, y, index, cluster_variance, noise_type)
|
local function seeded_noise(surface, x, y, index, sources)
|
||||||
base_seed = base_seed or surface.map_gen_settings.seed + surface.index + 400
|
base_seed = base_seed or surface.map_gen_settings.seed + surface.index + 4000
|
||||||
noise_type = noise_type or "perlin"
|
local noise = 0
|
||||||
if noise_type == "perlin" then
|
for _, settings in ipairs(sources) do
|
||||||
return Perlin.noise(x * cluster_variance, y * cluster_variance, base_seed + 200 * index)
|
settings.type = settings.type or 'perlin'
|
||||||
elseif noise_type == "simplex" then
|
settings.offset = settings.offset or 0
|
||||||
return Simplex.d2(x * cluster_variance, y * cluster_variance, base_seed + 200 * index)
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
return noise
|
||||||
end
|
end
|
||||||
|
|
||||||
-- cluster and scattered spawning
|
-- 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 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
|
local resource_richness_weights_sum = 0
|
||||||
for _, weight in pairs(resource_richness_weights) do
|
for _, weight in pairs(resource_richness_weights) do
|
||||||
resource_richness_weights_sum = resource_richness_weights_sum + weight
|
resource_richness_weights_sum = resource_richness_weights_sum + weight
|
||||||
end
|
end
|
||||||
|
local resource_richness_values = config.resource_richness_values
|
||||||
local function spawn_resource(surface, x, y, distance)
|
local resource_type_scalar = config.resource_type_scalar
|
||||||
local resource_name = get_name_by_weight(resource_weights, resource_weights_sum)
|
|
||||||
|
-- scattered config values
|
||||||
if (minimum_resource_distance[resource_name] > distance) then
|
local s_mode = config.scattered_mode
|
||||||
return
|
local s_dist_mod = config.scattered_distance_probability_modifier
|
||||||
end
|
local s_min_prob = config.scattered_min_probability
|
||||||
|
local s_max_prob = config.scattered_max_probability
|
||||||
local min_max = resource_richness_values[get_name_by_weight(resource_richness_weights, resource_richness_weights_sum)]
|
local s_dist_richness = config.scattered_distance_richness_modifier
|
||||||
local amount = ceil(random(min_max[1], min_max[2]) * (1 + ((distance / distance_richness_modifier) * 0.01)))
|
local s_cluster_prob = config.scattered_cluster_probability_multiplier
|
||||||
|
local s_cluster_mult = config.scattered_cluster_yield_multiplier
|
||||||
if liquid_value_modifiers[resource_name] then
|
|
||||||
amount = amount * liquid_value_modifiers[resource_name]
|
local s_resource_weights = config.scattered_resource_weights
|
||||||
end
|
local s_resource_weights_sum = 0
|
||||||
|
for _, weight in pairs(s_resource_weights) do
|
||||||
if (cluster_mode) then
|
s_resource_weights_sum = s_resource_weights_sum + weight
|
||||||
amount = amount * cluster_yield_multiplier
|
|
||||||
end
|
|
||||||
|
|
||||||
local position = {x = x, y = y}
|
|
||||||
|
|
||||||
Template.resources(surface, {{name = resource_name, position = position, amount = amount}})
|
|
||||||
end
|
end
|
||||||
|
local s_min_dist = config.scattered_minimum_resource_distance
|
||||||
|
|
||||||
|
-- cluster config values
|
||||||
|
local cluster_mode = config.cluster_mode
|
||||||
|
|
||||||
-- compound cluster spawning
|
-- compound cluster spawning
|
||||||
|
local c_mode = config.cluster_mode
|
||||||
local cc_mode = config.compound_cluster_mode
|
local c_clusters = config.clusters
|
||||||
local cc_richness_weights = config.compound_cluster_richness_weights
|
local c_count = 0
|
||||||
local cc_richness_values = config.compound_cluster_richness_values
|
for _, cluster in ipairs(c_clusters) do
|
||||||
local cc_type_scalar = config.compound_cluster_type_scalar
|
c_count = c_count + 1
|
||||||
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
|
|
||||||
cluster.weights_sum = 0
|
cluster.weights_sum = 0
|
||||||
for _, weight in pairs(cluster.weights) do
|
for _, weight in pairs(cluster.weights) do
|
||||||
cluster.weights_sum = cluster.weights_sum + weight
|
cluster.weights_sum = cluster.weights_sum + weight
|
||||||
end
|
end
|
||||||
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 distance = sqrt(x * x + y * y)
|
||||||
local resource_name = get_name_by_weight(cluster.weights, cluster.weights_sum)
|
local resource_name = get_name_by_weight(cluster.weights, cluster.weights_sum)
|
||||||
if resource_name == 'skip' then
|
if resource_name == 'skip' then
|
||||||
@@ -132,32 +118,19 @@ function ScatteredResources.register(config)
|
|||||||
end
|
end
|
||||||
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])
|
local amount = random(range[1], range[2])
|
||||||
amount = amount * (1 + ((distance / cluster.distance_richness) * 0.01))
|
amount = amount * (1 + ((distance / cluster.distance_richness) * 0.01))
|
||||||
|
amount = amount * cluster.yield
|
||||||
|
|
||||||
if cc_type_scalar[resource_name] then
|
if resource_type_scalar[resource_name] then
|
||||||
amount = amount * cc_type_scalar[resource_name]
|
amount = amount * resource_type_scalar[resource_name]
|
||||||
end
|
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
|
return true
|
||||||
end
|
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 registration
|
||||||
Event.add(Template.events.on_void_removed, function (event)
|
Event.add(Template.events.on_void_removed, function (event)
|
||||||
local position = event.position
|
local position = event.position
|
||||||
@@ -165,67 +138,101 @@ function ScatteredResources.register(config)
|
|||||||
local y = position.y
|
local y = position.y
|
||||||
local surface = event.surface
|
local surface = event.surface
|
||||||
|
|
||||||
local distance = sqrt(x * x + y * y)
|
local distance = config.distance(x, y)
|
||||||
|
|
||||||
if cc_mode then
|
if c_mode then
|
||||||
if (spawn_compound_clusters(surface, x, y, distance)) then
|
for index,cluster in ipairs(c_clusters) do
|
||||||
return
|
if distance >= cluster.min_distance and cluster.noise_settings.type ~= 'skip' then
|
||||||
end
|
if cluster.noise_settings.type == "connected_tendril" then
|
||||||
end
|
local noise = seeded_noise(surface, x, y, index, cluster.noise_settings.sources)
|
||||||
distance = floor(distance)
|
if -1 * cluster.noise_settings.threshold < noise and noise < cluster.noise_settings.threshold then
|
||||||
|
if spawn_cluster_resource(surface, x, y, index, cluster) then
|
||||||
if (cluster_mode and seeded_noise(surface, x, y, -1, noise_variance) > noise_resource_threshold) then
|
return -- resource spawned
|
||||||
spawn_resource(surface, x, y, distance)
|
end
|
||||||
return
|
end
|
||||||
end
|
elseif cluster.noise_settings.type == "fragmented_tendril" then
|
||||||
|
local noise1 = seeded_noise(surface, x, y, index, cluster.noise_settings.sources)
|
||||||
if not scattered_mode then
|
local noise2 = seeded_noise(surface, x, y, index, cluster.noise_settings.discriminator)
|
||||||
return
|
if -1 * cluster.noise_settings.threshold < noise1 and noise1 < cluster.noise_settings.threshold
|
||||||
end
|
and -1 * cluster.noise_settings.discriminator_threshold < noise2
|
||||||
|
and noise2 < cluster.noise_settings.discriminator_threshold then
|
||||||
local calculated_probability = resource_probability + ((distance / distance_probability_modifier) * 0.01)
|
if spawn_cluster_resource(surface, x, y, index, cluster) then
|
||||||
local probability = max_resource_probability
|
return -- resource spawned
|
||||||
|
end
|
||||||
if (calculated_probability < probability) then
|
end
|
||||||
probability = calculated_probability
|
else
|
||||||
end
|
local noise = seeded_noise(surface, x, y, index, cluster.noise_settings.sources)
|
||||||
|
if noise >= cluster.noise_settings.threshold then
|
||||||
-- cluster mode reduces the max probability to reduce max spread
|
if spawn_cluster_resource(surface, x, y, index, cluster) then
|
||||||
if (cluster_mode) then
|
return -- resource spawned
|
||||||
probability = probability * 0.5
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if (probability > random()) then
|
|
||||||
spawn_resource(surface, x, y, distance)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
if (config.display_resource_fields) 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
|
|
||||||
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)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end
|
||||||
end
|
|
||||||
|
if s_mode then
|
||||||
|
local probability = math.min(s_max_prob, s_min_prob + 0.01 * (distance / s_dist_mod))
|
||||||
|
|
||||||
|
if (cluster_mode) then
|
||||||
|
probability = probability * s_cluster_prob
|
||||||
|
end
|
||||||
|
|
||||||
|
if (probability > random()) then
|
||||||
|
-- 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_compound_ore_locations) then
|
if (config.display_ore_clusters) then
|
||||||
|
local color = {}
|
||||||
Event.add(defines.events.on_chunk_generated, function (event)
|
Event.add(defines.events.on_chunk_generated, function (event)
|
||||||
local surface = event.surface
|
local surface = event.surface
|
||||||
local area = event.area
|
local area = event.area
|
||||||
|
|
||||||
for x = area.left_top.x, area.left_top.x + 31 do
|
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 y = area.left_top.y, area.left_top.y + 31 do
|
||||||
for index,cluster in ipairs(cc_clusters) do
|
for index,cluster in ipairs(c_clusters) do
|
||||||
if seeded_noise(surface, x, y, index, cluster.variance,
|
if cluster.noise_settings.type == "connected_tendril" then
|
||||||
cluster.noise or 'perlin') >= cluster.threshold then
|
local noise = seeded_noise(surface, x, y, index, cluster.noise_settings.sources)
|
||||||
Debug.print_grid_value('o' .. index, surface, {x = x, y = y}, nil, nil, true)
|
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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user