Merge pull request #58 from TWLTriston/develop-tris

Glitter Ores Map Generation
This commit is contained in:
Valansch
2017-09-21 11:11:58 +02:00
committed by GitHub
2 changed files with 74 additions and 2 deletions
+72
View File
@@ -0,0 +1,72 @@
-- Glittery ores, provide a mix value, and all patches outside uranium will be a full mix.
glitter_debug = false
function run_ores_module_setup()
if glitter_debug then game.print("Glitter Ore: debug is enabled; module setup;") end
ore_mix = {}
ore_ratios = {
["iron-ore"] = 1.0,
["coal"] = 0.5,
["copper-ore"] = 1,
["stone"] = 0.25
}
-- 1-100% chance of sprinkling any individual ore
sprinkle_factor = 100
-- Sets the buffer distance before ores are scrambled
starting_buffer = 125
ore_mix_max = 0
-- Prime the array
for a,b in pairs(ore_ratios) do
for i=1,(b*1000) do
ore_mix_max = ore_mix_max + 1
ore_mix[ore_mix_max] = a
end
end
end
run_ores_module_setup()
--generate ores for entire chunk
function run_ores_module(event)
local area = event.area
local surface = event.surface
if glitter_debug then
game.print("Glitter ore: chunk generation")
end
local chunk_mid = {(area.left_top.x + area.right_bottom.x) / 2, (area.left_top.y + area.right_bottom.y) / 2}
local distance = math.sqrt(chunk_mid[1] * chunk_mid[1] + chunk_mid[2] * chunk_mid[2])
if distance > starting_buffer then
local entities = surface.find_entities_filtered{type="resource", area=area}
for _, entity in ipairs(entities) do
if ore_ratios[entity.name] ~= nil then
-- Roll to sprinkle_factor
if sprinkle_factor < 100 then
sprinkle_random = math.random(1,100)
should_sprinkle = sprinkle_random <= sprinkle_factor
else
should_sprinkle = true
end
if should_sprinkle then
local new_name = nil
--- Use the ratios to randomly select an ore
new_ore_random = math.random(1,ore_mix_max)
new_name = ore_mix[new_ore_random]
local position_old = entity.position
local amount_old = entity.amount
local surface = entity.surface
entity.destroy()
local new_entity = surface.create_entity{name = new_name, position = position_old, force="neutral", amount=amount_old}
end
end
end
end
end
+2 -2
View File
@@ -34,13 +34,13 @@ in this file and your run_*type*_module(event) function will be called.
--ores--
--require "locale.gen_ores.neko_crazy_ores"
--require "locale.gen_ores.fluffy_rainbows"
--require "locale.gen_ores.glitter_ores"
--everything else. You may use more than one of these, but beware they might not be compatible
miscs = {}
--miscs[1] = require "locale.gen_misc.rail_grid"
local on_chunk_generated = function(event)
if run_combined_module == nil then
if run_shape_module ~= nil then