mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-03-05 15:05:57 +02:00
Merge pull request #329 from Rdjrjqouqcu/dev_ore_weights
ore weights instead of chances
This commit is contained in:
commit
a366d3aaf9
@ -207,15 +207,15 @@ local Config = {
|
||||
|
||||
-- max chance of spawning resources based on resource_probability + calculated distance_probability_modifier
|
||||
max_resource_probability = 0.30,
|
||||
|
||||
-- chances per resource of spawning, sum must be 1.00
|
||||
resource_chances = {
|
||||
['coal'] = 0.16,
|
||||
['copper-ore'] = 0.215,
|
||||
['iron-ore'] = 0.389,
|
||||
['stone'] = 0.212,
|
||||
['uranium-ore'] = 0.021,
|
||||
['crude-oil'] = 0.003,
|
||||
|
||||
-- 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
|
||||
@ -227,15 +227,15 @@ local Config = {
|
||||
['uranium-ore'] = 86,
|
||||
['crude-oil'] = 57,
|
||||
},
|
||||
|
||||
-- defines the chance of which resource_richness_value to spawn, sum must be 1.00
|
||||
resource_richness_probability = {
|
||||
['scarce'] = 0.44,
|
||||
['low'] = 0.35,
|
||||
['sufficient'] = 0.164,
|
||||
['good'] = 0.03,
|
||||
['plenty'] = 0.01,
|
||||
['jackpot'] = 0.006,
|
||||
|
||||
-- defines the weights of which resource_richness_value to spawn
|
||||
resource_richness_weights = {
|
||||
['scarce'] = 440,
|
||||
['low'] = 350,
|
||||
['sufficient'] = 164,
|
||||
['good'] = 30,
|
||||
['plenty'] = 10,
|
||||
['jackpot'] = 6,
|
||||
},
|
||||
|
||||
-- defines the min and max range of ores to spawn
|
||||
|
@ -15,18 +15,19 @@ local floor = math.floor
|
||||
-- this
|
||||
local ScatteredResources = {}
|
||||
|
||||
local function get_name_by_random(collection)
|
||||
local function get_name_by_weight(collection, sum)
|
||||
local pre_calculated = random()
|
||||
local current = 0
|
||||
|
||||
for name, probability in pairs(collection) do
|
||||
current = current + probability
|
||||
if (current >= pre_calculated) then
|
||||
local target = pre_calculated * sum
|
||||
|
||||
for name, weight in pairs(collection) do
|
||||
current = current + weight
|
||||
if (current >= target) then
|
||||
return name
|
||||
end
|
||||
end
|
||||
|
||||
Debug.print('Current \'' .. current .. '\' should be higher or equal to random \'' .. pre_calculated .. '\'')
|
||||
Debug.print('Current \'' .. current .. '\' should be higher or equal to random \'' .. target .. '\'')
|
||||
end
|
||||
|
||||
--[[--
|
||||
@ -39,22 +40,31 @@ function ScatteredResources.register(config)
|
||||
local distance_probability_modifier = config.distance_probability_modifier
|
||||
local resource_probability = config.resource_probability
|
||||
local max_resource_probability = config.max_resource_probability
|
||||
local resource_chances = config.resource_chances
|
||||
local resource_richness_probability = config.resource_richness_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 function spawn_resource(surface, x, y, distance)
|
||||
local resource_name = get_name_by_random(resource_chances)
|
||||
local resource_name = get_name_by_weight(resource_weights, resource_weights_sum)
|
||||
|
||||
if (minimum_resource_distance[resource_name] > distance) then
|
||||
return
|
||||
end
|
||||
|
||||
local min_max = resource_richness_values[get_name_by_random(resource_richness_probability)]
|
||||
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
|
||||
@ -70,31 +80,12 @@ function ScatteredResources.register(config)
|
||||
Template.resources(surface, {{name = resource_name, position = position, amount = amount}})
|
||||
end
|
||||
|
||||
function sum(t)
|
||||
local sum = 0
|
||||
for _, v in pairs(t) do
|
||||
sum = sum + v
|
||||
end
|
||||
|
||||
return sum
|
||||
end
|
||||
|
||||
local seed
|
||||
local function get_noise(surface, x, y)
|
||||
seed = seed or surface.map_gen_settings.seed + surface.index + 200
|
||||
return Perlin.noise(x * noise_variance, y * noise_variance, seed)
|
||||
end
|
||||
|
||||
local resource_sum = sum(config.resource_chances)
|
||||
if (1 ~= resource_sum) then
|
||||
error('Expected a sum of 1.00, got \'' .. resource_sum .. '\' for config.feature.ScatteredResources.resource_chances.')
|
||||
end
|
||||
|
||||
local richness_sum = sum(config.resource_richness_probability)
|
||||
if (1 ~= richness_sum) then
|
||||
error('Expected a sum of 1.00, got \'' .. richness_sum .. '\' for config.feature.ScatteredResources.resource_richness_probability.')
|
||||
end
|
||||
|
||||
Event.add(Template.events.on_void_removed, function (event)
|
||||
local position = event.position
|
||||
local x = position.x
|
||||
|
Loading…
x
Reference in New Issue
Block a user