1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-18 03:21:47 +02:00

changed to new modules system

This commit is contained in:
grilledham 2018-05-10 00:21:12 +01:00
parent 65fe87c1fa
commit 02d6d01b8b
3 changed files with 95 additions and 101 deletions

View File

@ -3,76 +3,54 @@
-- creates a LARGE amount of extra copper from the start. Also a 4:1 ratio for stone is quite heavy.
-- Suggest modifying the sprinkle_factor out of 100% to make for a less game about warehousing ore,
-- to one about picking patches that are mostly the preferred ore, along with a % of the wrong ores.
glitter_debug = false
glitter_ore_module = {}
function run_ores_module_setup()
-- Sets the buffer distance before ores are scrambled
local starting_distance = 125
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 = 20
-- 1-100% chance of sprinkling any individual ore
local sprinkle_factor = 20
-- Sets the buffer distance before ores are scrambled
starting_buffer = 125
local ore_ratios = {
["iron-ore"] = 1.0,
["coal"] = 0.5,
["copper-ore"] = 1,
["stone"] = 0.25
}
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
starting_distance = starting_distance ^ 2
local ore_mix = {}
local 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
run_ores_module_setup()
return function(x, y, world)
local d = world.x * world.x + world.y * world.y
if d <= starting_distance then
return nil
end
--generate ores for entire chunk
function glitter_ore_module.on_chunk_generated(event)
local area = event.area
local surface = event.surface
local pos = {world.x + 0.5, world.y + 0.5}
local entities = world.surface.find_entities_filtered {position = pos, type = "resource"}
if glitter_debug then
game.print("Glitter ore: chunk generation")
end
for _, entity in ipairs(entities) do
if ore_ratios[entity.name] ~= nil then
if sprinkle_factor == 100 or math.random(100) <= sprinkle_factor then
local amount_old = entity.amount
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}
entity.destroy()
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
return {
name = ore_mix[math.random(ore_mix_max)],
position = pos,
amount = amount_old
}
end
end
end
end
return glitter_ore_module

View File

@ -1,34 +1,55 @@
local Task = require "utils.Task"
local Event = require "utils.event"
local mines_factor = 4
--Do not change this:
mines_factor = 16384 / mines_factor
function spawn_row(params)
local x = params.x
local y = params.y
local magic_number = math.floor(mines_factor / params.distance) + 1
for i = 0, 31 do
if math.random(1, magic_number) == 1 then
game.surfaces[1].create_entity{name = "land-mine", position = {x + i,y}, force = "enemy"}
end
end
end
function run_terrain_module(event)
local distance = math.sqrt(event.area.left_top.x*event.area.left_top.x+event.area.left_top.y*event.area.left_top.y)
if distance > 100 then
for i = 0, 31 do
Task.queue_task("spawn_row", {x = event.area.left_top.x, y = event.area.left_top.y + i, distance = distance})
end
end
end
local death_messages = {"Went exploring, and didn't bring a minesweeping kit.","Wandered off, and found that it really is dangerous to go alone.","Found that minesweeper in factorio gives no hints.","And they were only one day away from retirement","Is too old for this s$%t","Ponders the question, 'How might I avoid mines in the future'","Exploded with rage","Thought it was clear, found it was not.","Thought it was clear, was wrong.","Paved the way for expansion!","Sacrificed their body to the greater factory expansion","No longer wonders why nobody else has built here","Just wants to watch the respawn timer window","Like life, mines are unfair, next time bring a helmet","Should’ve thrown a grenade before stepping over there","Is farming the death counter","Fertilized the soil","Found no man's land, also found it applies to them.","Curses the map maker","does not look forward to the death march back to retreive items","Wont be going for a walk again","Really wants a map.", "Forgot his xray goggles","Rather Forgot to bring x-ray goggles","Learned that the biters defend their territory","Mines 1, Ninja skills 0."}
local death_messages = {
"Went exploring, and didn't bring a minesweeping kit.",
"Wandered off, and found that it really is dangerous to go alone.",
"Found that minesweeper in factorio gives no hints.",
"And they were only one day away from retirement",
"Is too old for this s$%t",
"Ponders the question, 'How might I avoid mines in the future'",
"Exploded with rage",
"Thought it was clear, found it was not.",
"Thought it was clear, was wrong.",
"Paved the way for expansion!",
"Sacrificed their body to the greater factory expansion",
"No longer wonders why nobody else has built here",
"Just wants to watch the respawn timer window",
"Like life, mines are unfair, next time bring a helmet",
"Should’ve thrown a grenade before stepping over there",
"Is farming the death counter",
"Fertilized the soil",
"Found no man's land, also found it applies to them.",
"Curses the map maker",
"does not look forward to the death march back to retreive items",
"Wont be going for a walk again",
"Really wants a map.",
"Forgot his xray goggles",
"Rather Forgot to bring x-ray goggles",
"Learned that the biters defend their territory",
"Mines 1, Ninja skills 0."
}
local function player_died()
game.print(death_messages[math.random(1, #death_messages)])
end
Event.add(defines.events.on_player_died, player_died)
return function(x, y, world)
local x, y = world.x, world.y
local distance = math.sqrt(x * x + y * y)
if distance <= 100 then
return nil
end
local magic_number = math.floor(mines_factor / distance) + 1
if math.random(1, magic_number) == 1 then
return {name = "land-mine", position = {x, y}, force = "enemy"}
end
end

View File

@ -5,30 +5,25 @@ local small_worm_spawn_distance = 100
local medium_worm_spawn_distance = 150
local big_worm_spawn_distance = 200
local worm_names = {"small-worm-turret", "medium-worm-turret", "big-worm-turret"}
worm_names = {"small-worm-turret","medium-worm-turret","big-worm-turret"}
function spawn_worm(params)
local x = params.x
local y = params.y
local lvl = params.lvl
local worm_id = math.random(1, lvl)
if game.surfaces[1].can_place_entity{name = worm_names[worm_id], position = {x,y}} then
if math.sqrt(x*x+y*y) > small_worm_spawn_distance then
game.surfaces[1].create_entity{name = worm_names[worm_id], position = {x,y}}
end
end
end
local chance = worms_per_chunk / (32 * 32)
return function(x, y, world)
local x, y = world.x, world.y
local distance = math.sqrt(x * x + y * y)
function run_terrain_module(event)
local top_left = event.area.left_top
local distance = math.sqrt(top_left.x*top_left.x+top_left.y*top_left.y)
if distance > small_worm_spawn_distance - 32 then
local lvl = 1
if distance > medium_worm_spawn_distance then lvl = 2 end
if distance > big_worm_spawn_distance then lvl = 3 end
for i = 1, worms_per_chunk do
Task.queue_task("spawn_worm", {x = top_left.x + math.random(0, 31), y = top_left.y + math.random(0, 31), lvl = lvl})
if distance > medium_worm_spawn_distance then
lvl = 2
end
if distance > big_worm_spawn_distance then
lvl = 3
end
if math.random() < chance then
local worm_id = math.random(1, lvl)
return {name = worm_names[worm_id], position = {x, y}}
end
end
end