mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-12 10:04:40 +02:00
Added noise based cluster resources
This commit is contained in:
parent
87b6690f6e
commit
bee981f367
@ -11,12 +11,15 @@ local Config = {
|
||||
-- a list of features to register and enable
|
||||
-- to disable a feature, change the flag
|
||||
features = {
|
||||
-- creates a starting zone
|
||||
StartingZone = {
|
||||
enabled = true,
|
||||
|
||||
-- initial starting position size, values higher than 30 might break
|
||||
-- initial starting position size, higher values are not recommended
|
||||
starting_size = 8,
|
||||
},
|
||||
|
||||
-- controls setting up the players
|
||||
SetupPlayer = {
|
||||
enabled = true,
|
||||
starting_items = {
|
||||
@ -29,12 +32,16 @@ local Config = {
|
||||
character_running_speed_modifier = 2,
|
||||
},
|
||||
},
|
||||
|
||||
-- core feature
|
||||
DiggyHole = {
|
||||
enabled = true,
|
||||
|
||||
-- enables commands like /clear-void
|
||||
enable_debug_commands = false,
|
||||
},
|
||||
|
||||
-- adds the ability to collapse caves
|
||||
DiggyCaveCollapse = {
|
||||
enabled = true,
|
||||
|
||||
@ -78,9 +85,13 @@ local Config = {
|
||||
'R U N',
|
||||
}
|
||||
},
|
||||
|
||||
-- replaces the chunks with void
|
||||
RefreshMap = {
|
||||
enabled = true,
|
||||
},
|
||||
|
||||
-- automatically opens areas
|
||||
SimpleRoomGenerator = {
|
||||
enabled = true,
|
||||
|
||||
@ -97,9 +108,27 @@ local Config = {
|
||||
{name = 'dirt', min = 0.39, max = 0.53},
|
||||
},
|
||||
},
|
||||
|
||||
-- responsible for resource spawning
|
||||
ScatteredResources = {
|
||||
enabled = true,
|
||||
|
||||
-- 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,
|
||||
|
||||
-- value between 0 and 1, higher value means stronger variance between coordinates
|
||||
noise_variance = 0.04,
|
||||
|
||||
-- a value between 0 and 1 that triggers the spawning of resource based on noise
|
||||
noise_resource_threshold = 0.36,
|
||||
|
||||
-- raw multiplier for ore content in cluster mode
|
||||
cluster_yield_multiplier = 2.3,
|
||||
|
||||
-- adds per tile what the current noise is
|
||||
enable_noise_grid = false,
|
||||
|
||||
-- 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
|
||||
@ -158,6 +187,8 @@ local Config = {
|
||||
['jackpot'] = {2001, 5000},
|
||||
},
|
||||
},
|
||||
|
||||
-- controls the alien spawning mechanic
|
||||
AlienSpawner = {
|
||||
enabled = true,
|
||||
|
||||
@ -167,6 +198,8 @@ local Config = {
|
||||
-- chance of spawning aliens when mining
|
||||
alien_probability = 0.07,
|
||||
},
|
||||
|
||||
-- controls the market and buffs
|
||||
MarketExchange = {
|
||||
enabled = true,
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
local Event = require 'utils.event'
|
||||
local Debug = require 'map_gen.Diggy.Debug'
|
||||
local Template = require 'map_gen.Diggy.Template'
|
||||
local Perlin = require 'map_gen.shared.perlin_noise'
|
||||
local random = math.random
|
||||
local sqrt = math.sqrt
|
||||
local ceil = math.ceil
|
||||
@ -36,12 +37,16 @@ local function spawn_resource(config, surface, x, y, distance)
|
||||
end
|
||||
|
||||
local min_max = config.resource_richness_values[get_name_by_random(config.resource_richness_probability)]
|
||||
local amount = ceil(random(min_max[1], min_max[2]) * (1 + ((distance / config.distance_richness_modifier) / 100)))
|
||||
local amount = ceil(random(min_max[1], min_max[2]) * (1 + ((distance / config.distance_richness_modifier) * 0.01)))
|
||||
|
||||
if ('crude-oil' == resource_name) then
|
||||
amount = amount * config.oil_value_modifier
|
||||
end
|
||||
|
||||
if (config.cluster_mode) then
|
||||
amount = amount * config.cluster_yield_multiplier
|
||||
end
|
||||
|
||||
local position = {x = x, y = y}
|
||||
|
||||
Template.resources(surface, {{name = resource_name, position = position, amount = amount}})
|
||||
@ -60,6 +65,11 @@ function ScatteredResources.register(config)
|
||||
return sum
|
||||
end
|
||||
|
||||
local function get_noise(surface, x, y)
|
||||
local seed = surface.map_gen_settings.seed + surface.index + 100
|
||||
return Perlin.noise(x * config.noise_variance, y * config.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.')
|
||||
@ -73,19 +83,44 @@ function ScatteredResources.register(config)
|
||||
Event.add(Template.events.on_void_removed, function(event)
|
||||
local x = event.old_tile.position.x
|
||||
local y = event.old_tile.position.y
|
||||
local surface = event.surface
|
||||
|
||||
local distance = floor(sqrt(x^2 + y^2))
|
||||
local calculated_probability = config.resource_probability + ((distance / config.distance_probability_modifier) / 100)
|
||||
local distance = floor(sqrt(x * x + y * y))
|
||||
|
||||
if (config.cluster_mode and get_noise(surface, x, y) > config.noise_resource_threshold) then
|
||||
spawn_resource(config, event.surface, x, y, distance)
|
||||
return
|
||||
end
|
||||
|
||||
local calculated_probability = config.resource_probability + ((distance / config.distance_probability_modifier) * 0.01)
|
||||
local probability = config.max_resource_probability
|
||||
|
||||
if (calculated_probability < probability) then
|
||||
probability = calculated_probability
|
||||
end
|
||||
|
||||
-- cluster mode reduces the max probability to reduce max spread
|
||||
if (config.cluster_mode) then
|
||||
probability = probability * 0.5
|
||||
end
|
||||
|
||||
if (probability > random()) then
|
||||
spawn_resource(config, event.surface, x, y, distance)
|
||||
end
|
||||
end)
|
||||
|
||||
if (config.enable_noise_grid) 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
|
||||
Debug.print_grid_value(get_noise(surface, x, y), surface, {x = x, y = y})
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
function ScatteredResources.get_extra_map_info(config)
|
||||
|
@ -9,7 +9,6 @@ local Event = require 'utils.event'
|
||||
local Debug = require'map_gen.Diggy.Debug'
|
||||
local Task = require 'utils.Task'
|
||||
local Token = require 'utils.global_token'
|
||||
local Global = require 'utils.global'
|
||||
|
||||
-- this
|
||||
local SimpleRoomGenerator = {}
|
||||
@ -55,7 +54,7 @@ function SimpleRoomGenerator.register(config)
|
||||
local room_noise_minimum_distance_sq = config.room_noise_minimum_distance * config.room_noise_minimum_distance
|
||||
|
||||
local function get_noise(surface, x, y)
|
||||
local seed = surface.map_gen_settings.seed + surface.index
|
||||
local seed = surface.map_gen_settings.seed + surface.index + 200
|
||||
return Perlin.noise(x * config.noise_variance, y * config.noise_variance, seed)
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user