1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-09-16 09:16:22 +02:00

updated to new module system

This commit is contained in:
grilledham
2018-05-10 23:43:11 +01:00
parent 4868a090cd
commit 644784bc1c
2 changed files with 76 additions and 81 deletions

View File

@@ -1,84 +1,78 @@
--Author: MewMew
--Author: MewMew. Liberally reinterpreted by grilledham
require "map_gen.shared.perlin_noise"
local Event = require "utils.event"
function run_combined_module(event)
if not global.resource_cluster_truck then global.resource_cluster_truck = 1 end
local entities = event.surface.find_entities(event.area)
for _, entity in pairs(entities) do
if entity.type == "resource" then
entity.destroy()
end
end
local pos_x = event.area.left_top.x + math.random(10, 20)
local pos_y = event.area.left_top.y + math.random(10, 20)
local radius = 10
local surface = event.surface
local tiles = {}
local center = 15
local ore_spawn = math.random(1,6)
local oil_amount = math.random(10000,150000)
local resource_amount = math.random(400,7000)
if math.random(1,12) == 1 then resource_amount = math.random(7000,150000) end
if global.resource_cluster_truck % 2 == 1 then
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local tile_distance_to_center = nil
local pos_x = event.area.left_top.x + x
local pos_y = event.area.left_top.y + y
center_x = event.area.left_top.x + center
center_y = event.area.left_top.y + center
local a = (pos_x - center_x) * (pos_x - center_x)
local b = (pos_y - center_y) * (pos_y - center_y)
local tile_distance_to_center = math.sqrt(a + b)
if tile_distance_to_center < radius then
if tile_distance_to_center <= 0 then tile_distance_to_center = tile_distance_to_center * -1 end
tile_distance_to_center = tile_distance_to_center + 1
local amount = resource_amount
if tile_distance_to_center < radius / 2 then
amount = resource_amount * 1.5
end
if tile_distance_to_center < radius / 3 then
amount = resource_amount * 2
end
if ore_spawn == 6 then amount = oil_amount end
if ore_spawn == 1 then
if surface.can_place_entity {name="stone", position={x=pos_x,y=pos_y}, amount = amount} then
surface.create_entity {name="stone", position={x=pos_x,y=pos_y}, amount = amount}
end
end
if ore_spawn == 2 then
if surface.can_place_entity {name="iron-ore", position={x=pos_x,y=pos_y}, amount = amount} then
surface.create_entity {name="iron-ore", position={x=pos_x,y=pos_y}, amount = amount}
end
end
if ore_spawn == 3 then
if surface.can_place_entity {name="coal", position={x=pos_x,y=pos_y}, amount = amount} then
surface.create_entity {name="coal", position={x=pos_x,y=pos_y}, amount = amount}
end
end
if ore_spawn == 4 then
if surface.can_place_entity {name="copper-ore", position={x=pos_x,y=pos_y}, amount = amount} then
surface.create_entity {name="copper-ore", position={x=pos_x,y=pos_y}, amount = amount}
end
end
if ore_spawn == 5 then
if surface.can_place_entity {name="uranium-ore", position={x=pos_x,y=pos_y}, amount = amount} then
surface.create_entity {name="uranium-ore", position={x=pos_x,y=pos_y}, amount = amount}
end
end
if ore_spawn == 6 then
if surface.can_place_entity {name="crude-oil", position={x=pos_x,y=pos_y}, amount = amount} then
surface.create_entity {name="crude-oil", position={x=pos_x,y=pos_y}, amount = amount}
end
end
end
end
local function init()
global.resource_cluster_truck = 0
end
Event.on_init(init)
local radius = 10
return function(x, y, world)
local entities = world.surface.find_entities_filtered {position = {world.x + 0.5, world.y + 0.5}, type = "resource"}
for _, e in ipairs(entities) do
e.destroy()
end
if not world.chunk then
world.chunk = true
global.resource_cluster_truck = global.resource_cluster_truck + 1
world.ore_spawn = math.random(1, 6)
if math.random(1, 12) == 1 then
world.resource_amount = math.random(7000, 150000)
else
world.resource_amount = math.random(400, 7000)
end
world.oil_amount = math.random(10000, 150000)
end
if global.resource_cluster_truck % 2 == 0 then
return nil
end
local x = world.x - world.top_x - 16
local y = world.y - world.top_y - 16
local d = math.sqrt(x * x + y * y)
if d < radius then
local ore_spawn = world.ore_spawn
local resource_amount = world.resource_amount
local amount
if ore_spawn == 6 then
amount = world.oil_amount
else
amount = resource_amount
if d < radius / 2 then
amount = resource_amount * 1.5
elseif d < radius / 3 then
amount = resource_amount * 2
end
end
global.resource_cluster_truck = global.resource_cluster_truck + 1
if ore_spawn == 1 then
return {name = "stone", amount = amount}
end
if ore_spawn == 2 then
return {name = "iron-ore", amount = amount}
end
if ore_spawn == 3 then
return {name = "coal", amount = amount}
end
if ore_spawn == 4 then
return {name = "copper-ore", amount = amount}
end
if ore_spawn == 5 then
return {name = "uranium-ore", amount = amount}
end
if ore_spawn == 6 then
return {name = "crude-oil", amount = amount}
end
end
end

View File

@@ -93,6 +93,7 @@ local entity_modules = {
--require "map_gen.ores.neko_crazy_ores",
--require "map_gen.ores.fluffy_rainbows",
--require "map_gen.ores.harmonic_gen",
--require "map_gen.ores.resource_clustertruck"
}
local terrain_modules ={
@@ -119,8 +120,8 @@ if #terrain_modules > 0 then
end
if shape then
--local gen = require "map_gen.shared.generate"
local gen = require "map_gen.shared.generate_not_threaded"
local gen = require "map_gen.shared.generate"
--local gen = require "map_gen.shared.generate_not_threaded"
gen = gen(shape)
Event.add(defines.events.on_chunk_generated, gen)