mirror of
https://github.com/Refactorio/RedMew.git
synced 2026-06-19 22:16:03 +02:00
Fixes to swap local to global
Moved init to a one time call function Fixed bug with mixed ores that caused tiles to be skipped
This commit is contained in:
@@ -1,58 +1,51 @@
|
||||
-- Glittery ores, provide a mix value, and all patches outside uranium will be a full mix.
|
||||
local glitter_debug = false
|
||||
global.glitter_setup = false
|
||||
|
||||
local ore_mix = {}
|
||||
local mix_current = 1
|
||||
local ore_ratios = {
|
||||
["iron-ore"] = 1.0,
|
||||
["coal"] = 0.5,
|
||||
["copper-ore"] = 1,
|
||||
["stone"] = 0.25
|
||||
}
|
||||
-- 1-100% chance of sprinkling any individual ore
|
||||
local sprinkle_factor = 100
|
||||
|
||||
-- Sets the buffer distance before ores are scrambled
|
||||
local starting_buffer = 100
|
||||
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
|
||||
mix_current = mix_current + 1
|
||||
ore_mix[mix_current] = a
|
||||
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)
|
||||
run_ores_module_setup()
|
||||
|
||||
local area = event.area
|
||||
local surface = event.surface
|
||||
local tiles = {}
|
||||
|
||||
if glitter_debug then
|
||||
game.print("Glitter ore: chunk generation")
|
||||
-- game.print (area.left_top)
|
||||
-- game.forces.player.chart(surface,{lefttop = {x = area.left_top.x, y = area.left_top.y}, rightbottom = {x = area.right_bottom.x, y = area.right_bottom.y}})
|
||||
|
||||
end
|
||||
|
||||
-- Buffer ores around the spawn -- 5 chunks
|
||||
|
||||
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 pairs(entities) do
|
||||
if ore_ratios[entity.name] > 0 then
|
||||
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)
|
||||
@@ -64,9 +57,8 @@ function run_ores_module(event)
|
||||
local new_name = nil
|
||||
|
||||
--- Use the ratios to randomly select an ore
|
||||
new_ore_random = math.random(1,mix_current)
|
||||
new_ore_random = math.random(1,ore_mix_max)
|
||||
new_name = ore_mix[new_ore_random]
|
||||
-- game.print(new_name)
|
||||
|
||||
local position_old = entity.position
|
||||
local amount_old = entity.amount
|
||||
@@ -75,6 +67,9 @@ function run_ores_module(event)
|
||||
entity.destroy()
|
||||
local new_entity = surface.create_entity{name = new_name, position = position_old, force="neutral", amount=amount_old}
|
||||
end
|
||||
else
|
||||
-- game.print("Skipping")
|
||||
-- game.print(entity.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user