1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-16 02:46:55 +02:00
This commit is contained in:
grilledham 2018-05-24 19:05:32 +01:00
parent dad8841952
commit bbca8c3102
4 changed files with 118 additions and 219 deletions

View File

@ -2,6 +2,7 @@
-- !! ATTENTION !!
-- Use water only in starting area as map setting!!!
local perlin = require 'map_gen.shared.perlin_noise'
local Token = require 'utils.global_token'
local wreck_item_pool = {
{name = 'iron-gear-wheel', count = 32},
@ -33,56 +34,16 @@ local wreck_item_pool = {
{name = 'explosive-rocket', count = 32}
}
local directions = {
defines.direction.north,
defines.direction.east,
defines.direction.south,
defines.direction.west
}
local ship_callback =
Token.register(
function(entity)
entity.health = math.random(entity.health)
local function place_entities(surface, entity_list)
for _, entity in ipairs(entity_list) do
local r = math.random(1, entity.chance)
if r == 1 then
if not entity.force then
entity.force = 'player'
end
local r = math.random(1, 4)
if
surface.can_place_entity {
name = entity.name,
position = entity.pos,
direction = directions[r],
force = entity.force
}
then
local e =
surface.create_entity {
name = entity.name,
position = entity.pos,
direction = directions[r],
force = entity.force
}
if entity.health then
if entity.health == 'low' then
e.health = ((e.health / 1000) * math.random(33, 330))
end
if entity.health == 'medium' then
e.health = ((e.health / 1000) * math.random(333, 666))
end
if entity.health == 'high' then
e.health = ((e.health / 1000) * math.random(666, 999))
end
if entity.health == 'random' then
e.health = ((e.health / 1000) * math.random(1, 1000))
end
end
return true, e
end
end
entity.insert(wreck_item_pool[math.random(#wreck_item_pool)])
entity.insert(wreck_item_pool[math.random(#wreck_item_pool)])
entity.insert(wreck_item_pool[math.random(#wreck_item_pool)])
end
return false
end
)
local clear_types = {'simple-entity', 'tree'}
@ -93,9 +54,40 @@ local function do_clear_entities(world)
end
end
local random_health =
Token.register(
function(e)
e.health = math.random(e.health)
end
)
local medium_health =
Token.register(
function(e)
e.health = math.random(math.floor(e.health * 0.333), math.floor(e.health * 0.666))
end
)
local low_health =
Token.register(
function(e)
e.health = math.random(math.floor(e.health * 0.033), math.floor(e.health * 0.330))
end
)
local turrent_callback =
Token.register(
function(e)
if math.random(1, 3) == 1 then
e.insert('piercing-rounds-magazine')
else
e.insert('firearm-magazine')
end
end
)
return function(x, y, world)
local entities = {}
local decoratives = {}
local area = world.area
local surface = world.surface
@ -105,10 +97,7 @@ return function(x, y, world)
do_clear_entities(world)
end
local pos = {x = world.x, y = world.y}
local tile = surface.get_tile(world.x, world.y)
local tile_to_insert = 'sand-1'
local entity_placed = false
local seed_increment_number = 10000
local seed = surface.map_gen_settings.seed
@ -134,20 +123,12 @@ return function(x, y, world)
local noise_walls = noise_walls_1 + noise_walls_2 * 0.1 + noise_walls_3 * 0.03
if noise_borg_defense > 0.66 then
local entity_list = {}
table.insert(entity_list, {name = 'big-ship-wreck-1', pos = {world.x, world.y}, chance = 25})
table.insert(entity_list, {name = 'big-ship-wreck-2', pos = {world.x, world.y}, chance = 25})
table.insert(entity_list, {name = 'big-ship-wreck-3', pos = {world.x, world.y}, chance = 25})
local b, placed_entity = place_entities(surface, entity_list)
if b == true then
if
placed_entity.name == 'big-ship-wreck-1' or placed_entity.name == 'big-ship-wreck-2' or
placed_entity.name == 'big-ship-wreck-3'
then
placed_entity.insert(wreck_item_pool[math.random(1, #wreck_item_pool)])
placed_entity.insert(wreck_item_pool[math.random(1, #wreck_item_pool)])
placed_entity.insert(wreck_item_pool[math.random(1, #wreck_item_pool)])
end
if math.random(25) == 1 then
table.insert(entities, {name = 'big-ship-wreck-1', force = 'player', callback = ship_callback})
elseif math.random(25) == 1 then
table.insert(entities, {name = 'big-ship-wreck-2', force = 'player', callback = ship_callback})
elseif math.random(25) == 1 then
table.insert(entities, {name = 'big-ship-wreck-3', force = 'player', callback = ship_callback})
end
end
@ -161,116 +142,70 @@ return function(x, y, world)
tile_to_insert = 'stone-path'
end
if noise_borg_defense > 0.65 and noise_borg_defense < 0.66 then
if surface.can_place_entity {name = 'substation', position = {world.x, world.y}, force = 'enemy'} then
surface.create_entity {name = 'substation', position = {world.x, world.y}, force = 'enemy'}
end
table.insert(entities, {name = 'substation', force = 'enemy'})
end
if noise_borg_defense >= 0.54 and noise_borg_defense < 0.65 then
if surface.can_place_entity {name = 'solar-panel', position = {world.x, world.y}, force = 'enemy'} then
surface.create_entity {name = 'solar-panel', position = {world.x, world.y}, force = 'enemy'}
end
table.insert(entities, {name = 'solar-panel', force = 'enemy'})
end
if noise_borg_defense > 0.53 and noise_borg_defense < 0.54 then
if surface.can_place_entity {name = 'substation', position = {world.x, world.y}, force = 'enemy'} then
surface.create_entity {name = 'substation', position = {world.x, world.y}, force = 'enemy'}
end
table.insert(entities, {name = 'substation', force = 'enemy'})
end
if noise_borg_defense >= 0.51 and noise_borg_defense < 0.53 then
if surface.can_place_entity {name = 'accumulator', position = {world.x, world.y}, force = 'enemy'} then
surface.create_entity {name = 'accumulator', position = {world.x, world.y}, force = 'enemy'}
end
table.insert(entities, {name = 'accumulator', force = 'enemy'})
end
if noise_borg_defense >= 0.50 and noise_borg_defense < 0.51 then
if surface.can_place_entity {name = 'substation', position = {world.x, world.y}, force = 'enemy'} then
surface.create_entity {name = 'substation', position = {world.x, world.y}, force = 'enemy'}
end
table.insert(entities, {name = 'substation', force = 'enemy'})
end
if noise_borg_defense >= 0.487 and noise_borg_defense < 0.50 then
if surface.can_place_entity {name = 'laser-turret', position = {world.x, world.y}, force = 'enemy'} then
surface.create_entity {name = 'laser-turret', position = {world.x, world.y}, force = 'enemy'}
end
table.insert(entities, {name = 'laser-turret', force = 'enemy'})
end
if noise_borg_defense >= 0.485 and noise_borg_defense < 0.487 then
if surface.can_place_entity {name = 'substation', position = {world.x, world.y}, force = 'enemy'} then
surface.create_entity {name = 'substation', position = {world.x, world.y}, force = 'enemy'}
end
table.insert(entities, {name = 'substation', force = 'enemy'})
end
if noise_borg_defense >= 0.45 and noise_borg_defense < 0.484 then
if surface.can_place_entity {name = 'stone-wall', position = {world.x, world.y}, force = 'enemy'} then
surface.create_entity {name = 'stone-wall', position = {world.x, world.y}, force = 'enemy'}
end
table.insert(entities, {name = 'stone-wall', force = 'enemy'})
end
if noise_trees > 0.2 and tile_to_insert == 'sand-3' then
if math.random(1, 15) == 1 then
if math.random(1, 5) == 1 then
if surface.can_place_entity {name = 'dry-hairy-tree', position = {world.x, world.y}} then
surface.create_entity {name = 'dry-hairy-tree', position = {world.x, world.y}}
end
table.insert(entities, {name = 'dry-hairy-tree'})
else
if surface.can_place_entity {name = 'dry-tree', position = {world.x, world.y}} then
surface.create_entity {name = 'dry-tree', position = {world.x, world.y}}
end
table.insert(entities, {name = 'dry-tree'})
end
end
end
local entity_list = {}
table.insert(entity_list, {name = 'big-ship-wreck-1', pos = {world.x, world.y}, chance = 35000, health = 'random'})
table.insert(entity_list, {name = 'big-ship-wreck-2', pos = {world.x, world.y}, chance = 45000, health = 'random'})
table.insert(entity_list, {name = 'big-ship-wreck-3', pos = {world.x, world.y}, chance = 55000, health = 'random'})
if noise_walls > -0.03 and noise_walls < 0.03 then
table.insert(entity_list, {name = 'gun-turret', pos = {world.x, world.y}, force = 'enemy', chance = 40})
end
if noise_borg_defense > 0.41 and noise_borg_defense < 0.45 then
table.insert(entity_list, {name = 'gun-turret', pos = {world.x, world.y}, force = 'enemy', chance = 15})
end
table.insert(entity_list, {name = 'pipe-to-ground', pos = {world.x, world.y}, force = 'enemy', chance = 7500})
if tile_to_insert ~= 'stone-path' and tile_to_insert ~= 'concrete' then
table.insert(
entity_list,
{name = 'dead-dry-hairy-tree', pos = {world.x, world.y}, force = 'enemy', chance = 1500}
)
table.insert(entity_list, {name = 'dead-grey-trunk', pos = {world.x, world.y}, force = 'enemy', chance = 1500})
end
table.insert(entity_list, {name = 'medium-ship-wreck', pos = {world.x, world.y}, chance = 25000, health = 'medium'})
table.insert(entity_list, {name = 'small-ship-wreck', pos = {world.x, world.y}, chance = 15000, health = 'medium'})
table.insert(entity_list, {name = 'car', pos = {world.x, world.y}, chance = 150000, health = 'low'})
table.insert(
entity_list,
{name = 'laser-turret', pos = {world.x, world.y}, chance = 100000, force = 'enemy', health = 'low'}
)
table.insert(
entity_list,
{name = 'nuclear-reactor', pos = {world.x, world.y}, chance = 1000000, force = 'enemy', health = 'medium'}
)
local b, placed_entity = place_entities(surface, entity_list)
if b == true then
if
placed_entity.name == 'big-ship-wreck-1' or placed_entity.name == 'big-ship-wreck-2' or
placed_entity.name == 'big-ship-wreck-3'
then
placed_entity.insert(wreck_item_pool[math.random(1, #wreck_item_pool)])
placed_entity.insert(wreck_item_pool[math.random(1, #wreck_item_pool)])
placed_entity.insert(wreck_item_pool[math.random(1, #wreck_item_pool)])
end
if placed_entity.name == 'gun-turret' then
if math.random(1, 3) == 1 then
placed_entity.insert('piercing-rounds-magazine')
else
placed_entity.insert('firearm-magazine')
end
end
if math.random(35000) == 1 then
table.insert(entities, {name = 'big-ship-wreck-1', force = 'player', callback = ship_callback})
elseif math.random(45000) == 1 then
table.insert(entities, {name = 'big-ship-wreck-2', force = 'player', callback = ship_callback})
elseif math.random(55000) == 1 then
table.insert(entities, {name = 'big-ship-wreck-3', force = 'player', callback = ship_callback})
elseif noise_walls > -0.03 and noise_walls < 0.03 and math.random(40) == 1 then
table.insert(entities, {name = 'gun-turret', force = 'enemy', callback = turrent_callback})
elseif noise_borg_defense > 0.41 and noise_borg_defense < 0.45 and math.random(15) == 1 then
table.insert(entities, {name = 'gun-turret', force = 'enemy', callback = turrent_callback})
elseif math.random(7500) == 1 then
table.insert(entities, {name = 'pipe-to-ground', force = 'enemy'})
elseif tile_to_insert ~= 'stone-path' and tile_to_insert ~= 'concrete' and math.random(1500) == 1 then
table.insert(entities, {name = 'dead-dry-hairy-tree'})
elseif tile_to_insert ~= 'stone-path' and tile_to_insert ~= 'concrete' and math.random(1500) == 1 then
table.insert(entities, {name = 'dead-grey-trunk'})
elseif math.random(25000) == 1 then
table.insert(entities, {name = 'medium-ship-wreck', force = 'player', callback = medium_health})
elseif math.random(15000) == 1 then
table.insert(entities, {name = 'small-ship-wreck', force = 'player', callback = medium_health})
elseif math.random(150000) == 1 then
table.insert(entities, {name = 'car', force = 'player', callback = low_health})
elseif math.random(100000) == 1 then
table.insert(entities, {name = 'laser-turret', force = 'enemy', callback = low_health})
elseif math.random(1000000) == 1 then
table.insert(entities, {name = 'nuclear-reactor', force = 'enemy', callback = medium_health})
end
if noise_trees < -0.5 then
if tile_to_insert == 'sand-3' or tile_to_insert == 'sand-1' then
if math.random(1, 15) == 1 then
if surface.can_place_entity {name = 'rock-big', position = {world.x, world.y}} then
surface.create_entity {name = 'rock-big', position = {world.x, world.y}}
end
end
end
if noise_trees < -0.5 and (tile_to_insert == 'sand-3' or tile_to_insert == 'sand-1') and math.random(15) == 1 then
table.insert(entities, {name = 'rock-big'})
end
local noise_water_1 = perlin:noise(((world.x + seed) / 200), ((world.y + seed) / 200), 0)
@ -283,38 +218,28 @@ return function(x, y, world)
seed = seed + seed_increment_number
local noise_water = noise_water_1 + noise_water_2 + noise_water_3 * 0.07 + noise_water_4 * 0.07
local noise_water_1 = perlin:noise(((world.x + seed) / 200), ((world.y + seed) / 200), 0)
noise_water_1 = perlin:noise(((world.x + seed) / 200), ((world.y + seed) / 200), 0)
seed = seed + seed_increment_number
local noise_water_2 = perlin:noise(((world.x + seed) / 100), ((world.y + seed) / 100), 0)
noise_water_2 = perlin:noise(((world.x + seed) / 100), ((world.y + seed) / 100), 0)
seed = seed + seed_increment_number
local noise_water_3 = perlin:noise(((world.x + seed) / 25), ((world.y + seed) / 25), 0)
noise_water_3 = perlin:noise(((world.x + seed) / 25), ((world.y + seed) / 25), 0)
seed = seed + seed_increment_number
local noise_water_4 = perlin:noise(((world.x + seed) / 10), ((world.y + seed) / 10), 0)
noise_water_4 = perlin:noise(((world.x + seed) / 10), ((world.y + seed) / 10), 0)
seed = seed + seed_increment_number
local noise_water_2 = noise_water_1 + noise_water_2 + noise_water_3 * 0.07 + noise_water_4 * 0.07
noise_water_2 = noise_water_1 + noise_water_2 + noise_water_3 * 0.07 + noise_water_4 * 0.07
if tile_to_insert ~= 'stone-path' and tile_to_insert ~= 'concrete' then
if noise_water > -0.15 and noise_water < 0.15 and noise_water_2 > 0.5 then
tile_to_insert = 'water-green'
local a = world.x + 1
table.insert(tiles, {name = tile_to_insert, position = {a, world.y}})
local a = world.y + 1
table.insert(tiles, {name = tile_to_insert, position = {world.x, a}})
local a = world.x - 1
table.insert(tiles, {name = tile_to_insert, position = {a, world.y}})
local a = world.y - 1
table.insert(tiles, {name = tile_to_insert, position = {world.x, a}})
table.insert(tiles, {name = tile_to_insert, position = {world.x, world.y}})
end
if
tile_to_insert ~= 'stone-path' and tile_to_insert ~= 'concrete' and noise_water > -0.15 and noise_water < 0.15 and
noise_water_2 > 0.5
then
tile_to_insert = 'water-green'
end
if noise_borg_defense <= 0.45 and tile_to_insert ~= 'water-green' then
local a = -0.01
local b = 0.01
if noise_walls > a and noise_walls < b then
if surface.can_place_entity {name = 'stone-wall', position = {world.x, world.y}, force = 'enemy'} then
surface.create_entity {name = 'stone-wall', position = {world.x, world.y}, force = 'enemy'}
end
table.insert(entities, {name = 'stone-wall', force = 'enemy'})
end
if noise_walls >= a and noise_walls <= b then
tile_to_insert = 'concrete'
@ -332,21 +257,17 @@ return function(x, y, world)
local noise_decoratives_1 = perlin:noise(((world.x + seed) / 50), ((world.y + seed) / 50), 0)
seed = seed + seed_increment_number
local noise_decoratives_2 = perlin:noise(((world.x + seed) / 15), ((world.y + seed) / 15), 0)
seed = seed + seed_increment_number
local noise_decoratives = noise_decoratives_1 + noise_decoratives_2 * 0.3
local decoratives
if noise_decoratives > 0.3 and noise_decoratives < 0.5 then
if tile_to_insert ~= 'stone-path' and tile_to_insert ~= 'concrete' and tile_to_insert ~= 'water-green' then
if math.random(1, 10) == 1 then
table.insert(decoratives, {name = 'red-desert-bush', position = {world.x, world.y}, amount = 1})
end
if
tile_to_insert ~= 'stone-path' and tile_to_insert ~= 'concrete' and tile_to_insert ~= 'water-green' and
math.random(10) == 1
then
decoratives = {name = 'red-desert-bush', amount = 1}
end
end
table.insert(tiles, {name = tile_to_insert, position = {world.x, world.y}})
surface.set_tiles(tiles, true)
for _, deco in pairs(decoratives) do
surface.create_decoratives {check_collision = false, decoratives = {deco}}
end
return {tile = tile_to_insert, entities = entities, decoratives = decoratives}
end

View File

@ -120,7 +120,7 @@ local function do_place_decoratives(data)
end
local dec = data.decoratives
if dec then
if #dec > 0 then
data.surface.create_decoratives({check_collision = true, decoratives = dec})
end
end

View File

@ -78,7 +78,7 @@ local function do_place_decoratives(data)
end
local dec = data.decoratives
if dec then
if #dec > 0 then
data.surface.create_decoratives({check_collision = true, decoratives = dec})
end
end

View File

@ -4,16 +4,17 @@ You may choose up to one of each type shapes, terrain, ores and misc or one of t
If you want to add your own module, just add it to the others
in this file and your run_*type*_module(event) function will be called.
--]]
local Event = require "utils.event"
local b = require "map_gen.shared.builders"
local b = require 'map_gen.shared.builders'
local shape = nil
local regen_decoratives = false
local tiles_per_tick = 32
--combined--
--shape = require "map_gen.combined.island_resort"
--require "map_gen.combined.red_planet_v2"
--require "map_gen.combined.borg_planet_v2"
--shape = require 'map_gen.combined.borg_planet_v2'
--require "map_gen.combined.dimensions"
--require "map_gen.combined.dagobah_swamp"
--require "map_gen.combined.meteor_strike" --unfinished
@ -85,7 +86,6 @@ local tiles_per_tick = 32
--ores--
--require "map_gen.ores.rso.rso_control"
-- modules that only return max one entity per tile
local entity_modules = {
--require "map_gen.ores.glitter_ores",
@ -98,7 +98,7 @@ local entity_modules = {
--require "map_gen.ores.resource_clustertruck"
}
local terrain_modules ={
local terrain_modules = {
--require "map_gen.misc.tris_chunk_grid",
}
@ -107,43 +107,21 @@ miscs = {}
--require "map_gen.misc.rusky_pvp"
--table.insert(miscs, require("map_gen.misc.rail_grid")) -- used for map_gen.presets.UK
local regen_decoratives = false
if #entity_modules > 0 then
shape = shape or b.full_shape
shape = shape or b.full_shape
shape = b.apply_entities(shape, entity_modules)
shape = b.apply_entities(shape, entity_modules)
end
if #terrain_modules > 0 then
shape = shape or b.full_shape
shape = shape or b.full_shape
for _, m in ipairs(terrain_modules) do
shape = b.overlay_tile_land(shape, m)
end
for _, m in ipairs(terrain_modules) do
shape = b.overlay_tile_land(shape, m)
end
end
if shape then
require ("map_gen.shared.generate")({shape = shape, regen_decoratives = regen_decoratives, tiles_per_tick = tiles_per_tick})
if shape then
require('map_gen.shared.generate')({shape = shape, regen_decoratives = regen_decoratives, tiles_per_tick = tiles_per_tick})
--require ("map_gen.shared.generate_not_threaded")({shape = shape, regen_decoratives = regen_decoratives})
end
--[[ local on_chunk_generated = function(event)
if run_combined_module ~= nil then
run_combined_module(event)
end
if run_shape_module ~= nil then
run_shape_module(event)
end
if run_terrain_module ~= nil then
run_terrain_module(event)
end
if run_ores_module ~= nil then
run_ores_module(event)
end
for _,v in pairs(miscs) do
v.on_chunk_generated(event)
end
end
Event.add(defines.events.on_chunk_generated, on_chunk_generated) ]]