mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-30 04:30:58 +02:00
4258568c90
* Add creep spread mechanic * Added bot ore islands, use bool flag to turn on. * Added a noise based chest spawning system for artefacts * Added coin loot from biters and mining * Track artefacts launched into space * Add Creepy map preset * Update donators.lua * Add scenario info for crashsite (#291) * Split colors resources from colors code & catchup on donators (#288) * Split colors resources from colors code * Switch back to colors * Added jail button Moved parts of the jail command to report.lua Made jailing possible from a users report. closes #215 * Added sound for new reports Admins now get a sound when a new report is created. Useful for admins that doesn't have Factorio as active window. Currently set the sound_path as utility/tutorial_notice * Split chat triggers from control * Move cheat tracking outside of control.lua * Remove player-specific code * Split donator/on_join messages out of control * Move features into features folder * Indentation fix I aimed to fix the troublesome indentation. * Added a single indent * Make sure biter modifiers are accessible for mods * Consistency change regarding table access * Added NightTime.lua Split the time assignment into a new file NightTime.lua allowing for it to be disabled. (Restore normal day/night cycle) Also added a popup when a player places a solar panel informing that they are purely cosmetic Removed the recipe for portable solar panels because they are useless, but the technology is needed. * Fixed debug print grid value to show non-rounded value * added support for hidden tiles * Add newline to eof * Fixed no newline, indentation and scope of research * crash_site outposts set hidden tile to 'grass-1' * Log items spawned by crafting in cheat mode * Newline to eof * Put responses into table * Use trigger as table key * Change name of lattice to diagonal lattice (#297) * Add Diagonal Ribbon to map presets (#294) * Reorganize control (#312) * Check for config before disabling fish market (#311) * Force diggy biters to spawn, even if there's no space (#308) * Fixed some small things from feedback and issues (#313) * Update fractal_balls.lua * Add ALo's message and color (#314) * Add join message for ALo * Add ALo's color * Typo in donators.lua * fixed tile corruption issus closes #310 (#317) * Update player_list.lua * Update diagonal_ribbon.lua (#322) * Regulars: remove duplicates and sort alphabetically (#320)
150 lines
5.2 KiB
Lua
150 lines
5.2 KiB
Lua
--[[-- info
|
|
Provides the ability to spawn random ores all over the place.
|
|
]]
|
|
|
|
-- dependencies
|
|
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
|
|
local floor = math.floor
|
|
|
|
-- this
|
|
local ScatteredResources = {}
|
|
|
|
local function get_name_by_random(collection)
|
|
local pre_calculated = random()
|
|
local current = 0
|
|
|
|
for name, probability in pairs(collection) do
|
|
current = current + probability
|
|
if (current >= pre_calculated) then
|
|
return name
|
|
end
|
|
end
|
|
|
|
Debug.print('Current \'' .. current .. '\' should be higher or equal to random \'' .. pre_calculated .. '\'')
|
|
end
|
|
|
|
--[[--
|
|
Registers all event handlers.
|
|
]]
|
|
function ScatteredResources.register(config)
|
|
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_chances = config.resource_chances
|
|
local resource_richness_probability = config.resource_richness_probability
|
|
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 function spawn_resource(surface, x, y, distance)
|
|
local resource_name = get_name_by_random(resource_chances)
|
|
|
|
if (minimum_resource_distance[resource_name] > distance) then
|
|
return
|
|
end
|
|
|
|
local min_max = resource_richness_values[get_name_by_random(resource_richness_probability)]
|
|
local amount = ceil(random(min_max[1], min_max[2]) * (1 + ((distance / distance_richness_modifier) * 0.01)))
|
|
|
|
if liquid_value_modifiers[name] then
|
|
amount = amount * modifier
|
|
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
|
|
|
|
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
|
|
local y = position.y
|
|
local surface = event.surface
|
|
|
|
local distance = floor(sqrt(x * x + y * y))
|
|
|
|
if (cluster_mode and get_noise(surface, x, y) > noise_resource_threshold) then
|
|
spawn_resource(surface, x, y, distance)
|
|
return
|
|
end
|
|
|
|
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
|
|
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 get_noise(surface, x, y) >= noise_resource_threshold then
|
|
Debug.print_grid_value('ore', surface, {x = x, y = y}, nil, nil, true)
|
|
end
|
|
end
|
|
end
|
|
end)
|
|
end
|
|
end
|
|
|
|
function ScatteredResources.get_extra_map_info(config)
|
|
return [[Scattered Resources, resources are everywhere!
|
|
Scans of the mine have shown greater amounts of resources to be deeper in the mine]]
|
|
end
|
|
|
|
return ScatteredResources
|