From 7c47b6eb1e02d049308d769bd6b90ed446ba16ed Mon Sep 17 00:00:00 2001 From: Valansch Date: Wed, 3 Oct 2018 22:56:48 +0200 Subject: [PATCH] added mask config values --- map_gen/Diggy/Config.lua | 6 +++ map_gen/Diggy/Feature/DiggyCaveCollapse.lua | 3 +- map_gen/Diggy/Mask.lua | 43 ++++++++++++++------- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/map_gen/Diggy/Config.lua b/map_gen/Diggy/Config.lua index 096796cd..992a96a8 100644 --- a/map_gen/Diggy/Config.lua +++ b/map_gen/Diggy/Config.lua @@ -56,6 +56,12 @@ local Config = { -- shows the mask on spawn enable_mask_debug = false, + --the size of the mask used + mask_size = 9, + + --how much the mask will effect tiles in the different rings of the mask + mask_relative_ring_weights = {2,3,4}, + -- delay in seconds before the cave collapses collapse_delay_min = 1.5, collapse_delay_max = 3, diff --git a/map_gen/Diggy/Feature/DiggyCaveCollapse.lua b/map_gen/Diggy/Feature/DiggyCaveCollapse.lua index bea6a793..c6f5fb16 100644 --- a/map_gen/Diggy/Feature/DiggyCaveCollapse.lua +++ b/map_gen/Diggy/Feature/DiggyCaveCollapse.lua @@ -259,9 +259,10 @@ end function DiggyCaveCollapse.initialize(global_config) config = global_config.features.DiggyCaveCollapse + Mask.init(config) if (config.enable_mask_debug) then local surface = game.surfaces.nauvis - Mask.disc_blur(0, 0, 1, function (x, y, fraction) + Mask.disc_blur(0, 0, 10, function (x, y, fraction) Debug.print_grid_value(fraction, surface, {x=x, y=y}) end) end diff --git a/map_gen/Diggy/Mask.lua b/map_gen/Diggy/Mask.lua index 290bc8d8..a41c6aac 100644 --- a/map_gen/Diggy/Mask.lua +++ b/map_gen/Diggy/Mask.lua @@ -45,40 +45,53 @@ local Mask = {} {0.000853, 0.001842, 0.003353, 0.005143, 0.006648, 0.007242, 0.006648, 0.005143, 0.003353, 0.001842, 0.000853}, {0.000395, 0.000853, 0.001552, 0.002381, 0.003078, 0.003353, 0.003078, 0.002381, 0.001552, 0.000853, 0.000395} } - local n = 9; - local radius = math.floor(n / 2) - local radius_sq = (radius + 0.2) * (radius + 0.2) - local center_radius_sq = radius_sq / 9 - local disc_radius_sq = radius_sq * 4 / 9 + local n + local radius + local radius_sq + local center_radius_sq + local disc_radius_sq + + local center_weight + local disc_weight + local ring_weight - local middle = radius + 1 local disc_blur_sum = 0 - local points_in_circle = 0 local center_value local disc_value local ring_value - function init() + function Mask.init(config) + n = config.mask_size + + ring_weight = config.mask_relative_ring_weights[1] + disc_weight = config.mask_relative_ring_weights[2] + center_weight = config.mask_relative_ring_weights[3] + + radius = math.floor(n / 2) + radius_sq = (radius + 0.2) * (radius + 0.2) + center_radius_sq = radius_sq / 9 + disc_radius_sq = radius_sq * 4 / 9 + + for x = -radius, radius do for y = -radius, radius do local distance_sq = x * x + y * y if distance_sq <= center_radius_sq then - disc_blur_sum = disc_blur_sum + 1 + disc_blur_sum = disc_blur_sum + center_weight elseif distance_sq <= disc_radius_sq then - disc_blur_sum = disc_blur_sum + 2 /3 + disc_blur_sum = disc_blur_sum + disc_weight elseif distance_sq <= radius_sq then - disc_blur_sum = disc_blur_sum + 1/3 + disc_blur_sum = disc_blur_sum + ring_weight end end end - center_value = 1 / disc_blur_sum - ring_value = center_value / 3 - disc_value = ring_value * 2 + center_value = center_weight / disc_blur_sum + disc_value = disc_weight / disc_blur_sum + ring_value = ring_weight / disc_blur_sum end - init() --[[-- Applies a blur filter.