mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-14 10:13:13 +02:00
grilledham+valansch changes without initialize
This commit is contained in:
parent
257313974c
commit
8dbf4e0920
@ -14,7 +14,7 @@ require 'follow'
|
|||||||
require 'autodeconstruct'
|
require 'autodeconstruct'
|
||||||
require 'corpse_util'
|
require 'corpse_util'
|
||||||
--require 'infinite_storage_chest'
|
--require 'infinite_storage_chest'
|
||||||
require 'fish_market'
|
--require 'fish_market'
|
||||||
require 'reactor_meltdown'
|
require 'reactor_meltdown'
|
||||||
require 'train_saviour'
|
require 'train_saviour'
|
||||||
require 'map_gen.shared.perlin_noise'
|
require 'map_gen.shared.perlin_noise'
|
||||||
|
@ -84,12 +84,10 @@ local Config = {
|
|||||||
RefreshMap = {
|
RefreshMap = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
register = require 'map_gen.Diggy.Feature.RefreshMap'.register,
|
register = require 'map_gen.Diggy.Feature.RefreshMap'.register,
|
||||||
initialize = require 'map_gen.Diggy.Feature.RefreshMap'.initialize,
|
|
||||||
},
|
},
|
||||||
SimpleRoomGenerator = {
|
SimpleRoomGenerator = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
register = require 'map_gen.Diggy.Feature.SimpleRoomGenerator'.register,
|
register = require 'map_gen.Diggy.Feature.SimpleRoomGenerator'.register,
|
||||||
initialize = require 'map_gen.Diggy.Feature.SimpleRoomGenerator'.initialize,
|
|
||||||
|
|
||||||
-- value between 0 and 1, higher value means stronger variance between coordinates
|
-- value between 0 and 1, higher value means stronger variance between coordinates
|
||||||
noise_variance = 0.089,
|
noise_variance = 0.089,
|
||||||
@ -109,7 +107,6 @@ local Config = {
|
|||||||
ScatteredResources = {
|
ScatteredResources = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
register = require 'map_gen.Diggy.Feature.ScatteredResources'.register,
|
register = require 'map_gen.Diggy.Feature.ScatteredResources'.register,
|
||||||
initialize = require 'map_gen.Diggy.Feature.ScatteredResources'.initialize,
|
|
||||||
|
|
||||||
-- percentage of resource added to the sum. 100 tiles means
|
-- percentage of resource added to the sum. 100 tiles means
|
||||||
-- 10% more resources with a distance_richness_modifier of 10
|
-- 10% more resources with a distance_richness_modifier of 10
|
||||||
@ -172,7 +169,6 @@ local Config = {
|
|||||||
AlienSpawner = {
|
AlienSpawner = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
register = require 'map_gen.Diggy.Feature.AlienSpawner'.register,
|
register = require 'map_gen.Diggy.Feature.AlienSpawner'.register,
|
||||||
initialize = require 'map_gen.Diggy.Feature.AlienSpawner'.initialize,
|
|
||||||
|
|
||||||
-- minimum distance from spawn before aliens can spawn
|
-- minimum distance from spawn before aliens can spawn
|
||||||
alien_minimum_distance = 35,
|
alien_minimum_distance = 35,
|
||||||
@ -183,7 +179,6 @@ local Config = {
|
|||||||
MiningEfficiency = {
|
MiningEfficiency = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
register = require 'map_gen.Diggy.Feature.MiningEfficiency'.register,
|
register = require 'map_gen.Diggy.Feature.MiningEfficiency'.register,
|
||||||
initialize = require 'map_gen.Diggy.Feature.MiningEfficiency'.initialize,
|
|
||||||
|
|
||||||
-- percentage * mining productivity level gets added to mining speed
|
-- percentage * mining productivity level gets added to mining speed
|
||||||
mining_speed_productivity_multiplier = 15,
|
mining_speed_productivity_multiplier = 15,
|
||||||
@ -194,7 +189,6 @@ local Config = {
|
|||||||
MarketExchange = {
|
MarketExchange = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
register = require 'map_gen.Diggy.Feature.MarketExchange'.register,
|
register = require 'map_gen.Diggy.Feature.MarketExchange'.register,
|
||||||
initialize = require 'map_gen.Diggy.Feature.MarketExchange'.initialize,
|
|
||||||
|
|
||||||
stone_to_surface_amount = 50,
|
stone_to_surface_amount = 50,
|
||||||
currency_item = 'stone',
|
currency_item = 'stone',
|
||||||
|
@ -23,7 +23,7 @@ function Debug.disable_cheats()
|
|||||||
cheats = true
|
cheats = true
|
||||||
end
|
end
|
||||||
|
|
||||||
local message_count = 0
|
global.message_count = 0
|
||||||
|
|
||||||
--[[--
|
--[[--
|
||||||
Shows the given message if _DEBUG == true.
|
Shows the given message if _DEBUG == true.
|
||||||
@ -32,10 +32,11 @@ local message_count = 0
|
|||||||
]]
|
]]
|
||||||
function Debug.print(message)
|
function Debug.print(message)
|
||||||
if type(message) ~= 'string' and type(message) ~= 'number' and type(message) ~= 'boolean' then message = type(message) end
|
if type(message) ~= 'string' and type(message) ~= 'number' and type(message) ~= 'boolean' then message = type(message) end
|
||||||
message_count = message_count + 1
|
global.message_count = global.message_count + 1
|
||||||
if (debug) then
|
if (debug) then
|
||||||
game.print('[' .. message_count .. '] ' .. tostring(message))
|
game.print('[' .. global.message_count .. '] ' .. tostring(message))
|
||||||
log('[' .. message_count .. '] ' .. tostring(message))
|
log('[' .. global.message_count .. '] ' .. tostring(message))
|
||||||
|
game.write_file("desync", '[' .. global.message_count .. '] ' .. tostring(message) .. '\n', true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -49,9 +50,9 @@ end
|
|||||||
function Debug.printPosition(position, message)
|
function Debug.printPosition(position, message)
|
||||||
message = message or ''
|
message = message or ''
|
||||||
if type(message) ~= 'string' and type(message) ~= 'number' and type(message) ~= 'boolean' then message = type(message) end
|
if type(message) ~= 'string' and type(message) ~= 'number' and type(message) ~= 'boolean' then message = type(message) end
|
||||||
message_count = message_count + 1
|
global.message_count = global.message_count + 1
|
||||||
if (debug) then
|
if (debug) then
|
||||||
game.print('[' .. message_count .. '] {x=' .. position.x .. ', y=' .. position.y .. '} ' .. tostring(message))
|
game.print('[' .. global.message_count .. '] {x=' .. position.x .. ', y=' .. position.y .. '} ' .. tostring(message))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -48,13 +48,4 @@ function AlienSpawner.register(cfg)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[--
|
|
||||||
Initializes the Feature.
|
|
||||||
|
|
||||||
@param config Table {@see Diggy.Config}.
|
|
||||||
]]
|
|
||||||
function AlienSpawner.initialize(config)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
return AlienSpawner
|
return AlienSpawner
|
||||||
|
@ -1,15 +1,12 @@
|
|||||||
--[[-- info
|
--[[-- info
|
||||||
Provides the ability to collapse caves when digging.
|
Provides the ability to collapse caves when digging.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
-- dependencies
|
-- dependencies
|
||||||
require 'utils.list_utils'
|
require 'utils.list_utils'
|
||||||
|
|
||||||
local Event = require 'utils.event'
|
local Event = require 'utils.event'
|
||||||
local Template = require 'map_gen.Diggy.Template'
|
local Template = require 'map_gen.Diggy.Template'
|
||||||
local Mask = require 'map_gen.Diggy.Mask'
|
local Debug = require 'map_gen.Diggy.Debug'
|
||||||
local StressMap = require 'map_gen.Diggy.StressMap'
|
|
||||||
local Debug = require'map_gen.Diggy.Debug'
|
|
||||||
local Task = require 'utils.Task'
|
local Task = require 'utils.Task'
|
||||||
local Token = require 'utils.global_token'
|
local Token = require 'utils.global_token'
|
||||||
|
|
||||||
@ -18,6 +15,28 @@ local DiggyCaveCollapse = {}
|
|||||||
|
|
||||||
local config = {}
|
local config = {}
|
||||||
|
|
||||||
|
local n = 9
|
||||||
|
local radius = 0
|
||||||
|
local radius_sq = 0
|
||||||
|
local center_radius_sq = 0
|
||||||
|
local disc_radius_sq = 0
|
||||||
|
|
||||||
|
local center_weight
|
||||||
|
local disc_weight
|
||||||
|
local ring_weight
|
||||||
|
|
||||||
|
local disc_blur_sum = 0
|
||||||
|
|
||||||
|
local center_value = 0
|
||||||
|
local disc_value = 0
|
||||||
|
local ring_value = 0
|
||||||
|
|
||||||
|
local enable_stress_grid = 0
|
||||||
|
local stress_map_blur_add = nil
|
||||||
|
local mask_disc_blur = nil
|
||||||
|
local stress_map_check_stress_in_threshold = nil
|
||||||
|
local support_beam_entities = nil
|
||||||
|
|
||||||
DiggyCaveCollapse.events = {
|
DiggyCaveCollapse.events = {
|
||||||
--[[--
|
--[[--
|
||||||
When stress at certain position is above the collapse threshold
|
When stress at certain position is above the collapse threshold
|
||||||
@ -30,64 +49,76 @@ DiggyCaveCollapse.events = {
|
|||||||
local function create_collapse_template(positions, surface)
|
local function create_collapse_template(positions, surface)
|
||||||
local entities = {}
|
local entities = {}
|
||||||
local tiles = {}
|
local tiles = {}
|
||||||
|
local map = {}
|
||||||
for _, position in pairs(positions) do
|
for _, position in pairs(positions) do
|
||||||
table.insert(entities, {position = {x = position.x, y = position.y - 1}, name = 'sand-rock-big'})
|
map[position.x] = map[position.x] or {}
|
||||||
table.insert(entities, {position = {x = position.x + 1, y = position.y}, name = 'sand-rock-big'})
|
map[position.x][position.y] = map[position.x][position.y] or true
|
||||||
table.insert(entities, {position = {x = position.x, y = position.y + 1}, name = 'sand-rock-big'})
|
|
||||||
table.insert(entities, {position = {x = position.x - 1, y = position.y}, name = 'sand-rock-big'})
|
|
||||||
table.insert(tiles, {position = {x = position.x, y = position.y}, name = 'out-of-map'})
|
table.insert(tiles, {position = {x = position.x, y = position.y}, name = 'out-of-map'})
|
||||||
end
|
end
|
||||||
for _, new_spawn in pairs({entities, tiles}) do
|
|
||||||
for _, tile in pairs(new_spawn) do
|
for x, y_tbl in pairs(map) do
|
||||||
for _, entity in pairs(surface.find_entities_filtered({position = tile.position})) do
|
for y, _ in pairs(y_tbl) do
|
||||||
pcall(function() entity.die() end)
|
if not map[x] or not map[x][y - 1] then
|
||||||
pcall(function() entity.destroy() end)
|
table.insert(entities, {position = {x = x, y = y - 1}, name = 'sand-rock-big'})
|
||||||
|
end
|
||||||
|
if not map[x] or not map[x][y + 1] then
|
||||||
|
table.insert(entities, {position = {x = x, y = y + 1}, name = 'sand-rock-big'})
|
||||||
|
end
|
||||||
|
if not map[x - 1] or not map[x - 1][y] then
|
||||||
|
table.insert(entities, {position = {x = x - 1, y = y}, name = 'sand-rock-big'})
|
||||||
|
end
|
||||||
|
if not map[x + 1] or not map[x + 1][y] then
|
||||||
|
table.insert(entities, {position = {x = x + 1, y = y}, name = 'sand-rock-big'})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for key,entity in pairs(entities) do
|
|
||||||
if not entity.valid then
|
for _, new_spawn in pairs({entities, tiles}) do
|
||||||
entities[key] = nil
|
for _, tile in pairs(new_spawn) do
|
||||||
|
for _, entity in pairs(surface.find_entities_filtered({position = tile.position})) do
|
||||||
|
pcall(
|
||||||
|
function()
|
||||||
|
entity.die()
|
||||||
|
end
|
||||||
|
)
|
||||||
|
pcall(
|
||||||
|
function()
|
||||||
|
entity.destroy()
|
||||||
|
end
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return tiles, entities
|
return tiles, entities
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[--
|
local function collapse(args, surface, position)
|
||||||
@param surface LuaSurface
|
local position = args.position
|
||||||
@param position Position with x and y
|
local surface = args.surface
|
||||||
@param strength positive increases stress, negative decreases stress
|
|
||||||
]]
|
|
||||||
local function update_stress_map(surface, position, strength)
|
|
||||||
local max_value
|
|
||||||
Mask.disc_blur(position.x, position.y, strength, function (x, y, fraction)
|
|
||||||
max_value = max_value or StressMap.add(surface, {x = x, y = y}, fraction)
|
|
||||||
end)
|
|
||||||
|
|
||||||
if max_value then
|
|
||||||
script.raise_event(DiggyCaveCollapse.events.on_collapse_triggered, {surface = surface, position = position})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function collapse(surface, position)
|
|
||||||
local positions = {}
|
local positions = {}
|
||||||
|
mask_disc_blur(
|
||||||
Mask.disc_blur(position.x, position.y, config.collapse_threshold_total_strength, function(x, y, value)
|
position.x,
|
||||||
StressMap.check_stress_in_threshold(surface, {x = x, y = y}, value, function(_, position)
|
position.y,
|
||||||
table.insert(positions, position)
|
config.collapse_threshold_total_strength,
|
||||||
end)
|
function(x, y, value)
|
||||||
|
stress_map_check_stress_in_threshold(
|
||||||
end)
|
surface,
|
||||||
|
{x = x, y = y},
|
||||||
|
value,
|
||||||
|
function(_, position)
|
||||||
|
table.insert(positions, position)
|
||||||
|
end
|
||||||
|
)
|
||||||
|
end
|
||||||
|
)
|
||||||
local tiles, entities = create_collapse_template(positions, surface)
|
local tiles, entities = create_collapse_template(positions, surface)
|
||||||
Template.insert(surface, tiles, entities)
|
Template.insert(surface, tiles, entities)
|
||||||
end
|
end
|
||||||
|
|
||||||
local on_collapse_timeout_finished = Token.register(function(params)
|
local on_collapse_timeout_finished = Token.register(collapse)
|
||||||
collapse(params.surface, params.position)
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
local function spawn_cracking_sound_text(surface, position)
|
||||||
function spawn_cracking_sound_text(surface, position)
|
|
||||||
local text = config.cracking_sounds[math.random(1, #config.cracking_sounds)]
|
local text = config.cracking_sounds[math.random(1, #config.cracking_sounds)]
|
||||||
|
|
||||||
local color = {
|
local color = {
|
||||||
@ -97,14 +128,98 @@ function spawn_cracking_sound_text(surface, position)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i = 1, #text do
|
for i = 1, #text do
|
||||||
local x_offset = (i - #text / 2 - 1) / 3
|
local x_offset = (i - #text / 2 - 1) / 3
|
||||||
local char = text:sub(i, i)
|
local char = text:sub(i, i)
|
||||||
surface.create_entity{
|
surface.create_entity {
|
||||||
name = 'flying-text',
|
name = 'flying-text',
|
||||||
color = color,
|
color = color,
|
||||||
text = char ,
|
text = char,
|
||||||
position = {x = position.x + x_offset, y = position.y - ((i + 1) % 2) / 4}
|
position = {x = position.x + x_offset, y = position.y - ((i + 1) % 2) / 4}
|
||||||
}.active = true
|
}.active = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_collapse_triggered(event)
|
||||||
|
spawn_cracking_sound_text(event.surface, event.position)
|
||||||
|
Task.set_timeout(
|
||||||
|
math.random(config.collapse_delay_min * 10, config.collapse_delay_max * 10) / 10,
|
||||||
|
on_collapse_timeout_finished,
|
||||||
|
{surface = event.surface, position = event.position}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_built_tile(event)
|
||||||
|
local strength = support_beam_entities[event.item.name]
|
||||||
|
|
||||||
|
if strength then
|
||||||
|
local surface = game.surfaces[event.surface_index]
|
||||||
|
for _, tile in pairs(event.tiles) do
|
||||||
|
stress_map_blur_add(surface, tile.position, -1 * strength, 'on_built_tile')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_robot_mined_tile(event)
|
||||||
|
for _, tile in pairs(event.tiles) do
|
||||||
|
local strength = support_beam_entities[tile.old_tile.name]
|
||||||
|
if strength then
|
||||||
|
stress_map_blur_add(event.robot.surface, tile.position, strength, 'on_robot_mined_tile')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_player_mined_tile(event)
|
||||||
|
local surface = game.surfaces[event.surface_index]
|
||||||
|
for _, tile in pairs(event.tiles) do
|
||||||
|
local strength = support_beam_entities[tile.old_tile.name]
|
||||||
|
|
||||||
|
if strength then
|
||||||
|
stress_map_blur_add(surface, tile.position, strength, 'on_player_mined_tile')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_mined_entity(event)
|
||||||
|
local strength = support_beam_entities[event.entity.name]
|
||||||
|
|
||||||
|
if strength then
|
||||||
|
stress_map_blur_add(event.entity.surface, event.entity.position, strength, 'on_mined_entity')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_built_entity(event)
|
||||||
|
local strength = support_beam_entities[event.created_entity.name]
|
||||||
|
|
||||||
|
if strength then
|
||||||
|
stress_map_blur_add(
|
||||||
|
event.created_entity.surface,
|
||||||
|
event.created_entity.position,
|
||||||
|
-1 * strength,
|
||||||
|
'on_built_entity'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_placed_entity(event)
|
||||||
|
local strength = support_beam_entities[event.entity.name]
|
||||||
|
|
||||||
|
if strength then
|
||||||
|
stress_map_blur_add(event.entity.surface, event.entity.position, -1 * strength, 'on_placed_entity')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_void_removed(event)
|
||||||
|
local strength = support_beam_entities['out-of-map']
|
||||||
|
|
||||||
|
if strength then
|
||||||
|
stress_map_blur_add(event.surface, event.old_tile.position, strength, 'on_void_removed')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_void_added(event)
|
||||||
|
local strength = support_beam_entities['out-of-map']
|
||||||
|
if strength then
|
||||||
|
stress_map_blur_add(event.surface, event.old_tile.position, -1 * strength, 'on_void_added')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -115,156 +230,323 @@ end
|
|||||||
]]
|
]]
|
||||||
function DiggyCaveCollapse.register(global_config)
|
function DiggyCaveCollapse.register(global_config)
|
||||||
config = global_config.features.DiggyCaveCollapse
|
config = global_config.features.DiggyCaveCollapse
|
||||||
local support_beam_entities = config.support_beam_entities;
|
support_beam_entities = config.support_beam_entities
|
||||||
|
|
||||||
if (config.enable_stress_grid) then
|
Event.add(DiggyCaveCollapse.events.on_collapse_triggered, on_collapse_triggered)
|
||||||
Event.add(StressMap.events.on_stress_changed, function(event)
|
Event.add(defines.events.on_robot_built_entity, on_built_entity)
|
||||||
Debug.print_grid_value(event.value, event.surface, event.position)
|
Event.add(defines.events.on_robot_built_tile, on_built_tile)
|
||||||
end)
|
Event.add(defines.events.on_player_built_tile, on_built_tile)
|
||||||
|
Event.add(defines.events.on_robot_mined_tile, on_robot_mined_tile)
|
||||||
|
Event.add(defines.events.on_player_mined_tile, on_player_mined_tile)
|
||||||
|
Event.add(defines.events.on_robot_mined_entity, on_mined_entity)
|
||||||
|
Event.add(defines.events.on_built_entity, on_built_entity)
|
||||||
|
Event.add(Template.events.on_placed_entity, on_placed_entity)
|
||||||
|
Event.add(defines.events.on_entity_died, on_mined_entity)
|
||||||
|
Event.add(defines.events.on_player_mined_entity, on_mined_entity)
|
||||||
|
Event.add(Template.events.on_void_removed, on_void_removed)
|
||||||
|
Event.add(Template.events.on_void_added, on_void_added)
|
||||||
|
|
||||||
|
enable_stress_grid = config.enable_stress_grid
|
||||||
|
|
||||||
|
mask_init(config)
|
||||||
|
if (config.enable_mask_debug) then
|
||||||
|
local surface = game.surfaces.nauvis
|
||||||
|
mask_disc_blur(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
10,
|
||||||
|
function(x, y, fraction)
|
||||||
|
Debug.print_grid_value(fraction, surface, {x = x, y = y})
|
||||||
|
end
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--
|
||||||
|
--STRESS MAP
|
||||||
|
--
|
||||||
|
local stress_threshold_causing_collapse = 0.9
|
||||||
|
|
||||||
|
-- main block
|
||||||
|
global.stress_map_storage = {}
|
||||||
|
|
||||||
|
local defaultValue = 0
|
||||||
|
|
||||||
|
--[[--
|
||||||
|
Adds a fraction to a given location on the stress_map. Returns the new
|
||||||
|
fraction value of that position.
|
||||||
|
|
||||||
|
@param stress_map Table of {@see get_stress_map}
|
||||||
|
@param position Table with x and y
|
||||||
|
@param number fraction
|
||||||
|
|
||||||
|
@return number sum of old fraction + new fraction
|
||||||
|
]]
|
||||||
|
local function add_fraction(stress_map, x, y, fraction)
|
||||||
|
local quadrant = 1
|
||||||
|
if x < 0 then
|
||||||
|
quadrant = quadrant + 1
|
||||||
|
x = -x
|
||||||
|
end
|
||||||
|
if y < 0 then
|
||||||
|
quadrant = quadrant + 2
|
||||||
|
y = -y
|
||||||
end
|
end
|
||||||
|
|
||||||
Event.add(DiggyCaveCollapse.events.on_collapse_triggered, function(event)
|
local quad_t = stress_map[quadrant]
|
||||||
spawn_cracking_sound_text(event.surface, event.position)
|
|
||||||
|
|
||||||
Task.set_timeout(
|
local x_t = quad_t[x]
|
||||||
math.random(config.collapse_delay_min * 10, config.collapse_delay_max * 10) / 10,
|
if not x_t then
|
||||||
on_collapse_timeout_finished,
|
x_t = {}
|
||||||
{surface = event.surface, position = event.position}
|
quad_t[x] = x_t
|
||||||
|
end
|
||||||
|
|
||||||
|
local value = x_t[y]
|
||||||
|
if not value then
|
||||||
|
value = defaultValue
|
||||||
|
end
|
||||||
|
|
||||||
|
value = value + fraction
|
||||||
|
|
||||||
|
x_t[y] = value
|
||||||
|
|
||||||
|
if (value > stress_threshold_causing_collapse) then
|
||||||
|
if quadrant > 2 then
|
||||||
|
y = -y
|
||||||
|
end
|
||||||
|
if quadrant % 2 == 0 then
|
||||||
|
x = -x
|
||||||
|
end
|
||||||
|
script.raise_event(
|
||||||
|
DiggyCaveCollapse.events.on_collapse_triggered,
|
||||||
|
{surface = game.surfaces[stress_map.surface_index], position = {x = x, y = y}}
|
||||||
)
|
)
|
||||||
end)
|
end
|
||||||
|
if (enable_stress_grid) then
|
||||||
Event.add(defines.events.on_robot_built_entity, function(event)
|
local surface = game.surfaces[stress_map.surface_index]
|
||||||
local strength = support_beam_entities[event.created_entity.name]
|
if quadrant > 2 then
|
||||||
|
y = -y
|
||||||
if (not strength) then
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
if quadrant % 2 == 0 then
|
||||||
update_stress_map(event.created_entity.surface, event.created_entity.position, -1 * strength)
|
x = -x
|
||||||
end)
|
|
||||||
|
|
||||||
Event.add(defines.events.on_robot_built_tile, function(event)
|
|
||||||
local strength = support_beam_entities[event.item.name]
|
|
||||||
|
|
||||||
if (not strength) then
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
Debug.print_grid_value(value, surface, {x = x, y = y})
|
||||||
|
end
|
||||||
|
return value
|
||||||
|
end
|
||||||
|
|
||||||
for _, tile in pairs(event.tiles) do
|
local function add_fraction_by_quadrant(stress_map, x, y, fraction, quadrant)
|
||||||
update_stress_map(event.robot.surface, tile.position, -1 * strength)
|
local quad_t = stress_map[quadrant]
|
||||||
|
|
||||||
|
local x_t = quad_t[x]
|
||||||
|
if not x_t then
|
||||||
|
x_t = {}
|
||||||
|
quad_t[x] = x_t
|
||||||
|
end
|
||||||
|
|
||||||
|
local value = x_t[y]
|
||||||
|
if not value then
|
||||||
|
value = defaultValue
|
||||||
|
end
|
||||||
|
|
||||||
|
value = value + fraction
|
||||||
|
|
||||||
|
x_t[y] = value
|
||||||
|
|
||||||
|
if (value > stress_threshold_causing_collapse) then
|
||||||
|
if quadrant > 2 then
|
||||||
|
y = -y
|
||||||
end
|
end
|
||||||
end)
|
if quadrant % 2 == 0 then
|
||||||
|
x = -x
|
||||||
Event.add(defines.events.on_player_built_tile, function(event)
|
|
||||||
local strength = support_beam_entities[event.item.name]
|
|
||||||
|
|
||||||
if (not strength) then
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
local surface = game.surfaces[event.surface_index]
|
script.raise_event(
|
||||||
for _, tile in pairs(event.tiles) do
|
DiggyCaveCollapse.events.on_collapse_triggered,
|
||||||
update_stress_map(surface, tile.position, -1 * strength)
|
{surface = game.surfaces[stress_map.surface_index], position = {x = x, y = y}}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
if (enable_stress_grid) then
|
||||||
|
local surface = game.surfaces[stress_map.surface_index]
|
||||||
|
if quadrant > 2 then
|
||||||
|
y = -y
|
||||||
end
|
end
|
||||||
end)
|
if quadrant % 2 == 0 then
|
||||||
|
x = -x
|
||||||
Event.add(defines.events.on_robot_mined_tile, function(event)
|
|
||||||
for _, tile in pairs(event.tiles) do
|
|
||||||
local strength = support_beam_entities[tile.old_tile.name]
|
|
||||||
|
|
||||||
if (strength) then
|
|
||||||
update_stress_map(event.robot.surface, tile.position, strength)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end)
|
Debug.print_grid_value(value, surface, {x = x, y = y})
|
||||||
|
end
|
||||||
Event.add(defines.events.on_player_mined_tile, function(event)
|
return value
|
||||||
local surface = game.surfaces[event.surface_index]
|
|
||||||
for _, tile in pairs(event.tiles) do
|
|
||||||
local strength = support_beam_entities[tile.old_tile.name]
|
|
||||||
|
|
||||||
if (strength) then
|
|
||||||
update_stress_map(surface, tile.position, strength)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
Event.add(defines.events.on_robot_mined_entity, function(event)
|
|
||||||
local strength = support_beam_entities[event.entity.name]
|
|
||||||
|
|
||||||
if (not strength) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
update_stress_map(event.entity.surface, event.entity.position, strength)
|
|
||||||
end)
|
|
||||||
|
|
||||||
Event.add(defines.events.on_built_entity, function(event)
|
|
||||||
local strength = support_beam_entities[event.created_entity.name]
|
|
||||||
|
|
||||||
if (not strength) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
update_stress_map(event.created_entity.surface, event.created_entity.position, -1 * strength)
|
|
||||||
end)
|
|
||||||
|
|
||||||
Event.add(Template.events.on_placed_entity, function(event)
|
|
||||||
local strength = support_beam_entities[event.entity.name]
|
|
||||||
|
|
||||||
if (not strength) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
update_stress_map(event.entity.surface, event.entity.position, -1 * strength)
|
|
||||||
end)
|
|
||||||
|
|
||||||
Event.add(defines.events.on_entity_died, function(event)
|
|
||||||
local strength = support_beam_entities[event.entity.name]
|
|
||||||
|
|
||||||
if (not strength) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
update_stress_map(event.entity.surface, event.entity.position, strength)
|
|
||||||
end)
|
|
||||||
|
|
||||||
Event.add(defines.events.on_player_mined_entity, function(event)
|
|
||||||
local strength = support_beam_entities[event.entity.name]
|
|
||||||
|
|
||||||
if (not strength) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
update_stress_map(event.entity.surface, event.entity.position, strength)
|
|
||||||
end)
|
|
||||||
|
|
||||||
Event.add(Template.events.on_void_removed, function(event)
|
|
||||||
local strength = support_beam_entities['out-of-map']
|
|
||||||
|
|
||||||
update_stress_map(event.surface, event.old_tile.position, strength)
|
|
||||||
end)
|
|
||||||
|
|
||||||
Event.add(Template.events.on_void_added, function(event)
|
|
||||||
local strength = support_beam_entities['out-of-map']
|
|
||||||
|
|
||||||
update_stress_map(event.surface, event.old_tile.position, -1 * strength)
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[--
|
--[[--
|
||||||
Initializes the Feature.
|
Creates a new stress map if it doesn't exist yet and returns it.
|
||||||
|
|
||||||
@param config Table {@see Diggy.Config}.
|
@param surface LuaSurface
|
||||||
|
@return Table [1,2,3,4] containing the quadrants
|
||||||
]]
|
]]
|
||||||
function DiggyCaveCollapse.initialize(global_config)
|
local function get_stress_map(surface)
|
||||||
config = global_config.features.DiggyCaveCollapse
|
if not global.stress_map_storage[surface.index] then
|
||||||
|
global.stress_map_storage[surface.index] = {}
|
||||||
|
|
||||||
Mask.init(config)
|
local map = global.stress_map_storage[surface.index]
|
||||||
if (config.enable_mask_debug) then
|
|
||||||
local surface = game.surfaces.nauvis
|
map['surface_index'] = surface.index
|
||||||
Mask.disc_blur(0, 0, 10, function (x, y, fraction)
|
map[1] = {}
|
||||||
Debug.print_grid_value(fraction, surface, {x=x, y=y})
|
map[2] = {}
|
||||||
end)
|
map[3] = {}
|
||||||
|
map[4] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
return global.stress_map_storage[surface.index]
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[--
|
||||||
|
Checks whether a tile's pressure is within a given threshold and calls the handler if not.
|
||||||
|
@param surface LuaSurface
|
||||||
|
@param position Position with x and y
|
||||||
|
@param number threshold
|
||||||
|
@param callback
|
||||||
|
|
||||||
|
]]
|
||||||
|
stress_map_check_stress_in_threshold = function(surface, position, threshold, callback)
|
||||||
|
local stress_map = get_stress_map(surface)
|
||||||
|
local value = add_fraction(stress_map, position.x, position.y, 0)
|
||||||
|
|
||||||
|
if (value >= stress_threshold_causing_collapse - threshold) then
|
||||||
|
callback(surface, position)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
stress_map_blur_add = function(surface, position, factor, caller)
|
||||||
|
if global.disable_cave_collapse then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
caller = caller or 'unknown'
|
||||||
|
|
||||||
|
--Debug.print(caller .. ' before')
|
||||||
|
local x_start = math.floor(position.x)
|
||||||
|
local y_start = math.floor(position.y)
|
||||||
|
|
||||||
|
local stress_map = get_stress_map(game.surfaces[1])
|
||||||
|
|
||||||
|
if radius > math.abs(x_start) or radius > math.abs(y_start) then
|
||||||
|
for x = -radius, radius do
|
||||||
|
for y = -radius, radius do
|
||||||
|
local value = 0
|
||||||
|
local distance_sq = x * x + y * y
|
||||||
|
if distance_sq <= center_radius_sq then
|
||||||
|
value = center_value
|
||||||
|
elseif distance_sq <= disc_radius_sq then
|
||||||
|
value = disc_value
|
||||||
|
elseif distance_sq <= radius_sq then
|
||||||
|
value = ring_value
|
||||||
|
end
|
||||||
|
if math.abs(value) > 0.001 then
|
||||||
|
add_fraction(stress_map, x + x_start, y + y_start, value * factor)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
--ALL VALUES IN SAME QUADRANT SO WE CAN OPTIMIZE THIS!
|
||||||
|
local quadrant = 1
|
||||||
|
if x_start < 0 then
|
||||||
|
quadrant = quadrant + 1
|
||||||
|
x_start = -x_start
|
||||||
|
end
|
||||||
|
if y_start < 0 then
|
||||||
|
quadrant = quadrant + 2
|
||||||
|
y_start = -y_start
|
||||||
|
end
|
||||||
|
|
||||||
|
for x = -radius, radius do
|
||||||
|
for y = -radius, radius do
|
||||||
|
local value = 0
|
||||||
|
local distance_sq = x * x + y * y
|
||||||
|
if distance_sq <= center_radius_sq then
|
||||||
|
value = center_value
|
||||||
|
elseif distance_sq <= disc_radius_sq then
|
||||||
|
value = disc_value
|
||||||
|
elseif distance_sq <= radius_sq then
|
||||||
|
value = ring_value
|
||||||
|
end
|
||||||
|
if math.abs(value) > 0.001 then
|
||||||
|
add_fraction_by_quadrant(stress_map, x + x_start, y + y_start, value * factor, quadrant)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
--Debug.print(caller .. ' after')
|
||||||
|
end
|
||||||
|
|
||||||
|
DiggyCaveCollapse.stress_map_blur_add = stress_map_blur_add
|
||||||
|
|
||||||
|
--
|
||||||
|
-- MASK
|
||||||
|
--
|
||||||
|
|
||||||
|
function mask_init(config)
|
||||||
|
n = config.mask_size
|
||||||
|
|
||||||
|
ring_weight = config.mask_relative_ring_weights[1]
|
||||||
|
disc_weight = config.mask_relative_ring_weights[2]
|
||||||
|
center_weight = config.mask_relative_ring_weights[3]
|
||||||
|
|
||||||
|
radius = math.floor(n / 2)
|
||||||
|
|
||||||
|
radius_sq = (radius + 0.2) * (radius + 0.2)
|
||||||
|
center_radius_sq = radius_sq / 9
|
||||||
|
disc_radius_sq = radius_sq * 4 / 9
|
||||||
|
|
||||||
|
for x = -radius, radius do
|
||||||
|
for y = -radius, radius do
|
||||||
|
local distance_sq = x * x + y * y
|
||||||
|
if distance_sq <= center_radius_sq then
|
||||||
|
disc_blur_sum = disc_blur_sum + center_weight
|
||||||
|
elseif distance_sq <= disc_radius_sq then
|
||||||
|
disc_blur_sum = disc_blur_sum + disc_weight
|
||||||
|
elseif distance_sq <= radius_sq then
|
||||||
|
disc_blur_sum = disc_blur_sum + ring_weight
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
center_value = center_weight / disc_blur_sum
|
||||||
|
disc_value = disc_weight / disc_blur_sum
|
||||||
|
ring_value = ring_weight / disc_blur_sum
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[--
|
||||||
|
Applies a blur
|
||||||
|
Applies the disc in 3 discs: center, (middle) disc and (outer) ring.
|
||||||
|
The relative weights for tiles in a disc are:
|
||||||
|
center: 3/3
|
||||||
|
disc: 2/3
|
||||||
|
ring: 1/3
|
||||||
|
The sum of all values is 1
|
||||||
|
|
||||||
|
@param x_start number center point
|
||||||
|
@param y_start number center point
|
||||||
|
@param factor the factor to multiply the cell value with (value = cell_value * factor)
|
||||||
|
@param callback function to execute on each tile within the mask callback(x, y, value)
|
||||||
|
]]
|
||||||
|
mask_disc_blur = function(x_start, y_start, factor, callback)
|
||||||
|
x_start = math.floor(x_start)
|
||||||
|
y_start = math.floor(y_start)
|
||||||
|
for x = -radius, radius do
|
||||||
|
for y = -radius, radius do
|
||||||
|
local value = 0
|
||||||
|
local distance_sq = x * x + y * y
|
||||||
|
if distance_sq <= center_radius_sq then
|
||||||
|
value = center_value
|
||||||
|
elseif distance_sq <= disc_radius_sq then
|
||||||
|
value = disc_value
|
||||||
|
elseif distance_sq <= radius_sq then
|
||||||
|
value = ring_value
|
||||||
|
end
|
||||||
|
if math.abs(value) > 0.001 then
|
||||||
|
callback(x_start + x, y_start + y, value * factor)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -92,13 +92,4 @@ function DiggyHole.register(cfg)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[--
|
|
||||||
Initializes the Feature.
|
|
||||||
|
|
||||||
@param config Table {@see Diggy.Config}.
|
|
||||||
]]
|
|
||||||
function DiggyHole.initialize(config)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
return DiggyHole
|
return DiggyHole
|
||||||
|
@ -21,22 +21,7 @@ global.MarketExchange = {
|
|||||||
]]
|
]]
|
||||||
function MarketExchange.register(cfg)
|
function MarketExchange.register(cfg)
|
||||||
local config = cfg.features.MarketExchange
|
local config = cfg.features.MarketExchange
|
||||||
Event.add(defines.events.on_market_item_purchased, function (event)
|
|
||||||
if (1 ~= event.offer_index) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
global.MarketExchange.stone_sent_to_surface = global.MarketExchange.stone_sent_to_surface + config.stone_to_surface_amount
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[--
|
|
||||||
Initializes the Feature.
|
|
||||||
|
|
||||||
@param cfg Table {@see Diggy.Config}.
|
|
||||||
]]
|
|
||||||
function MarketExchange.initialize(cfg)
|
|
||||||
local config = cfg.features.MarketExchange
|
|
||||||
local market_items = {
|
local market_items = {
|
||||||
{price = {{config.currency_item, 50}}, offer = {type = 'nothing', effect_description = 'Send ' .. config.stone_to_surface_amount .. ' stone to the surface'}},
|
{price = {{config.currency_item, 50}}, offer = {type = 'nothing', effect_description = 'Send ' .. config.stone_to_surface_amount .. ' stone to the surface'}},
|
||||||
}
|
}
|
||||||
@ -52,16 +37,24 @@ function MarketExchange.initialize(cfg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local on_market_timeout_finished = Token.register(function(params)
|
local on_market_timeout_finished = Token.register(function(params)
|
||||||
Template.market(params.surface, params.position, params.force, params.currency_item, params.market_items)
|
Template.market(game.surfaces.nauvis, {x = 0, y = -5}, game.forces.player, params.currency_item, params.market_items)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Task.set_timeout_in_ticks(40, on_market_timeout_finished, {
|
Event.on_init(function()
|
||||||
surface = game.surfaces.nauvis,
|
Task.set_timeout_in_ticks(360, on_market_timeout_finished, {
|
||||||
position = {x = 0, y = -5},
|
currency_item = config.currency_item,
|
||||||
force = game.forces.player,
|
market_items = market_items,
|
||||||
currency_item = config.currency_item,
|
})
|
||||||
market_items = market_items,
|
end)
|
||||||
})
|
|
||||||
|
|
||||||
|
Event.add(defines.events.on_market_item_purchased, function (event)
|
||||||
|
if (1 ~= event.offer_index) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
global.MarketExchange.stone_sent_to_surface = global.MarketExchange.stone_sent_to_surface + config.stone_to_surface_amount
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
return MarketExchange
|
return MarketExchange
|
||||||
|
@ -17,16 +17,19 @@ global.MiningEfficiency = {
|
|||||||
|
|
||||||
local function update_mining_speed(player_force)
|
local function update_mining_speed(player_force)
|
||||||
-- recalculate current modifier
|
-- recalculate current modifier
|
||||||
global.MiningEfficiency.current_modifier = global.MiningEfficiency.default_mining_speed + global.MiningEfficiency.research_modifier
|
global.MiningEfficiency.current_modifier =
|
||||||
|
global.MiningEfficiency.default_mining_speed + global.MiningEfficiency.research_modifier
|
||||||
|
|
||||||
-- remove the current buff
|
-- remove the current buff
|
||||||
player_force.manual_mining_speed_modifier = player_force.manual_mining_speed_modifier - global.MiningEfficiency.active_modifier
|
player_force.manual_mining_speed_modifier =
|
||||||
|
player_force.manual_mining_speed_modifier - global.MiningEfficiency.active_modifier
|
||||||
|
|
||||||
-- update the active modifier
|
-- update the active modifier
|
||||||
global.MiningEfficiency.active_modifier = global.MiningEfficiency.current_modifier
|
global.MiningEfficiency.active_modifier = global.MiningEfficiency.current_modifier
|
||||||
|
|
||||||
-- add the new active modifier
|
-- add the new active modifier
|
||||||
player_force.manual_mining_speed_modifier = player_force.manual_mining_speed_modifier + global.MiningEfficiency.active_modifier
|
player_force.manual_mining_speed_modifier =
|
||||||
|
player_force.manual_mining_speed_modifier + global.MiningEfficiency.active_modifier
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[--
|
--[[--
|
||||||
@ -35,25 +38,25 @@ end
|
|||||||
function MiningEfficiency.register(cfg)
|
function MiningEfficiency.register(cfg)
|
||||||
local config = cfg.features.MiningEfficiency
|
local config = cfg.features.MiningEfficiency
|
||||||
|
|
||||||
Event.add(defines.events.on_research_finished, function(event)
|
|
||||||
local player_force = game.forces.player
|
|
||||||
|
|
||||||
global.MiningEfficiency.research_modifier = player_force.mining_drill_productivity_bonus * config.mining_speed_productivity_multiplier / 2
|
|
||||||
|
|
||||||
update_mining_speed(player_force)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[--
|
|
||||||
Initializes the Feature.
|
|
||||||
|
|
||||||
@param config Table {@see Diggy.Config}.
|
|
||||||
]]
|
|
||||||
function MiningEfficiency.initialize(cfg)
|
|
||||||
local config = cfg.features.MiningEfficiency
|
|
||||||
|
|
||||||
global.MiningEfficiency.default_mining_speed = config.default_mining_speed
|
global.MiningEfficiency.default_mining_speed = config.default_mining_speed
|
||||||
update_mining_speed(game.forces.player)
|
|
||||||
|
Event.add(
|
||||||
|
defines.events.on_research_finished,
|
||||||
|
function(event)
|
||||||
|
local player_force = game.forces.player
|
||||||
|
|
||||||
|
global.MiningEfficiency.research_modifier =
|
||||||
|
player_force.mining_drill_productivity_bonus * config.mining_speed_productivity_multiplier / 2
|
||||||
|
|
||||||
|
update_mining_speed(player_force)
|
||||||
|
end
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Event.on_init(
|
||||||
|
function()
|
||||||
|
update_mining_speed(game.forces.player)
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
return MiningEfficiency
|
return MiningEfficiency
|
||||||
|
@ -36,13 +36,4 @@ function RefreshMap.register(config)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[--
|
|
||||||
Initializes the Feature.
|
|
||||||
|
|
||||||
@param config Table {@see Diggy.Config}.
|
|
||||||
]]
|
|
||||||
function RefreshMap.initialize(config)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
return RefreshMap
|
return RefreshMap
|
||||||
|
@ -91,14 +91,7 @@ function ScatteredResources.register(cfg)
|
|||||||
spawn_resource(config, event.surface, x, y, distance)
|
spawn_resource(config, event.surface, x, y, distance)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
|
||||||
|
|
||||||
--[[--
|
|
||||||
Initializes the Feature.
|
|
||||||
|
|
||||||
@param config Table {@see Diggy.Config}.
|
|
||||||
]]
|
|
||||||
function ScatteredResources.initialize(config)
|
|
||||||
global.ScatteredResources.can_spawn_resources = true
|
global.ScatteredResources.can_spawn_resources = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -28,13 +28,4 @@ function SetupPlayer.register(config)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[--
|
|
||||||
Initializes the Feature.
|
|
||||||
|
|
||||||
@param config Table {@see Diggy.Config}.
|
|
||||||
]]
|
|
||||||
function SetupPlayer.initialize(config)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
return SetupPlayer
|
return SetupPlayer
|
||||||
|
@ -90,12 +90,4 @@ function SimpleRoomGenerator.register(cfg)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[--
|
|
||||||
Initializes the Feature.
|
|
||||||
|
|
||||||
@param config Table {@see Diggy.Config}.
|
|
||||||
]]
|
|
||||||
function SimpleRoomGenerator.initialize(config)
|
|
||||||
end
|
|
||||||
|
|
||||||
return SimpleRoomGenerator
|
return SimpleRoomGenerator
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
--[[-- info
|
--[[-- info
|
||||||
Provides the ability to create a pre-configured starting zone.
|
Provides the ability to create a pre-configured starting zone.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
-- dependencies
|
-- dependencies
|
||||||
local Event = require 'utils.event'
|
local Event = require 'utils.event'
|
||||||
local Token = require 'utils.global_token'
|
local Token = require 'utils.global_token'
|
||||||
local Mask = require 'map_gen.Diggy.Mask'
|
|
||||||
local StressMap = require 'map_gen.Diggy.StressMap'
|
|
||||||
local Template = require 'map_gen.Diggy.Template'
|
local Template = require 'map_gen.Diggy.Template'
|
||||||
local Debug = require 'map_gen.Diggy.Debug'
|
local Debug = require 'map_gen.Diggy.Debug'
|
||||||
|
local DiggyCaveCollapse = require 'map_gen.Diggy.Feature.DiggyCaveCollapse'
|
||||||
|
|
||||||
-- this
|
-- this
|
||||||
local StartingZone = {}
|
local StartingZone = {}
|
||||||
|
|
||||||
|
local daytime
|
||||||
|
|
||||||
--[[--
|
--[[--
|
||||||
Registers all event handlers.
|
Registers all event handlers.
|
||||||
]]
|
]]
|
||||||
@ -24,7 +24,7 @@ function StartingZone.register(config)
|
|||||||
local start_point_area = {{-1, -1}, {0, 0}}
|
local start_point_area = {{-1, -1}, {0, 0}}
|
||||||
|
|
||||||
-- hack to figure out whether the important chunks are generated via Diggy.Feature.RefreshMap.
|
-- hack to figure out whether the important chunks are generated via Diggy.Feature.RefreshMap.
|
||||||
if (4 ~= event.surface.count_tiles_filtered({start_point_area, name='lab-dark-1'})) then
|
if (4 ~= event.surface.count_tiles_filtered({start_point_area, name = 'lab-dark-1'})) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -36,23 +36,28 @@ function StartingZone.register(config)
|
|||||||
local tiles = {}
|
local tiles = {}
|
||||||
local rocks = {}
|
local rocks = {}
|
||||||
|
|
||||||
Mask.circle(0, 0, starting_zone_size, function(x, y, tile_distance_to_center)
|
for x = -starting_zone_size, starting_zone_size do
|
||||||
if (tile_distance_to_center > math.floor(starting_zone_size / 2)) then
|
for y = -starting_zone_size, starting_zone_size do
|
||||||
table.insert(tiles, {name = 'dirt-' .. math.random(1, 7), position = {x = x, y = y}})
|
local distance = math.floor(math.sqrt(x * x + y * y))
|
||||||
else
|
|
||||||
table.insert(tiles, {name = 'stone-path', position = {x = x, y = y}})
|
|
||||||
end
|
|
||||||
|
|
||||||
if (tile_distance_to_center > starting_zone_size - 2) then
|
if (distance < starting_zone_size) then
|
||||||
table.insert(rocks, {name = 'sand-rock-big', position = {x = x, y = y}})
|
if (distance > math.floor(starting_zone_size / 2)) then
|
||||||
end
|
table.insert(tiles, {name = 'dirt-' .. math.random(1, 7), position = {x = x, y = y}})
|
||||||
|
else
|
||||||
|
table.insert(tiles, {name = 'stone-path', position = {x = x, y = y}})
|
||||||
|
end
|
||||||
|
|
||||||
if (tile_distance_to_center > math.floor(starting_zone_size / 10)) then
|
if (distance > starting_zone_size - 2) then
|
||||||
Mask.blur(x, y, -0.3, function (x, y, fraction)
|
table.insert(rocks, {name = 'sand-rock-big', position = {x = x, y = y}})
|
||||||
StressMap.add(event.surface, {x = x, y = y}, fraction)
|
end
|
||||||
end)
|
|
||||||
|
-- hack to avoid starting area from collapsing
|
||||||
|
if (distance > math.floor(starting_zone_size / 10)) then
|
||||||
|
DiggyCaveCollapse.stress_map_blur_add(event.surface, {x = x, y = y}, -0.3)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
end
|
||||||
|
|
||||||
Template.insert(event.surface, tiles, rocks)
|
Template.insert(event.surface, tiles, rocks)
|
||||||
|
|
||||||
@ -62,19 +67,17 @@ function StartingZone.register(config)
|
|||||||
callback_token = Token.register(on_chunk_generated)
|
callback_token = Token.register(on_chunk_generated)
|
||||||
|
|
||||||
Event.add_removable(defines.events.on_chunk_generated, callback_token)
|
Event.add_removable(defines.events.on_chunk_generated, callback_token)
|
||||||
|
|
||||||
|
daytime = config.features.StartingZone.daytime
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[--
|
Event.on_init(
|
||||||
Initializes the Feature.
|
function()
|
||||||
|
local surface = game.surfaces.nauvis
|
||||||
|
|
||||||
@param config Table {@see Diggy.Config}.
|
surface.daytime = daytime
|
||||||
]]
|
surface.freeze_daytime = 1
|
||||||
function StartingZone.initialize(config)
|
end
|
||||||
local surface = game.surfaces.nauvis
|
)
|
||||||
|
|
||||||
surface.daytime = config.features.StartingZone.daytime
|
|
||||||
surface.freeze_daytime = 1
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
return StartingZone
|
return StartingZone
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
-- dependencies
|
-- dependencies
|
||||||
local Event = require 'utils.event'
|
|
||||||
local Config = require 'map_gen.Diggy.Config'
|
local Config = require 'map_gen.Diggy.Config'
|
||||||
local Debug = require 'map_gen.Diggy.Debug'
|
local Debug = require 'map_gen.Diggy.Debug'
|
||||||
|
|
||||||
@ -11,8 +10,6 @@ local Scenario = {}
|
|||||||
|
|
||||||
-- private state
|
-- private state
|
||||||
local scenario_registered = false
|
local scenario_registered = false
|
||||||
local scenario_initialized = false
|
|
||||||
|
|
||||||
|
|
||||||
--[[--
|
--[[--
|
||||||
Allows calling a callback for each enabled feature.
|
Allows calling a callback for each enabled feature.
|
||||||
@ -47,53 +44,29 @@ function Scenario.register(debug)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- using the on_player_created to initialize all the features
|
if ('boolean' == type(debug)) then
|
||||||
Event.add(defines.events.on_player_created, function (event)
|
Config.Debug = debug
|
||||||
if ('boolean' == type(debug)) then
|
end
|
||||||
Config.Debug = debug
|
|
||||||
|
if (Config.debug) then
|
||||||
|
Debug.enable_debug()
|
||||||
|
end
|
||||||
|
|
||||||
|
if (Config.cheats) then
|
||||||
|
Debug.enable_cheats()
|
||||||
|
end
|
||||||
|
|
||||||
|
each_enabled_feature(
|
||||||
|
function(feature_name, feature_data)
|
||||||
|
if ('function' ~= type(feature_data.register)) then
|
||||||
|
error('Feature ' .. feature_name .. ' did not define a register function.')
|
||||||
|
end
|
||||||
|
|
||||||
|
feature_data.register(Config)
|
||||||
end
|
end
|
||||||
|
)
|
||||||
if (Config.debug) then
|
|
||||||
Debug.enable_debug()
|
|
||||||
end
|
|
||||||
|
|
||||||
if (Config.cheats) then
|
|
||||||
Debug.enable_cheats()
|
|
||||||
end
|
|
||||||
|
|
||||||
Scenario.initialize(Config)
|
|
||||||
end)
|
|
||||||
|
|
||||||
each_enabled_feature(function(feature_name, feature_data)
|
|
||||||
if ('function' ~= type(feature_data.register)) then
|
|
||||||
error('Feature ' .. feature_name .. ' did not define a register function.')
|
|
||||||
end
|
|
||||||
|
|
||||||
feature_data.register(Config)
|
|
||||||
end)
|
|
||||||
|
|
||||||
scenario_registered = true
|
scenario_registered = true
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[--
|
|
||||||
Initializes the starting position.
|
|
||||||
|
|
||||||
@param config Table {@see Diggy.Config}.
|
|
||||||
]]
|
|
||||||
function Scenario.initialize(config)
|
|
||||||
if scenario_initialized then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
each_enabled_feature(function(feature_name, feature_data)
|
|
||||||
if ('function' ~= type(feature_data.initialize)) then
|
|
||||||
error('Feature ' .. feature_name .. ' did not define an initialize function.')
|
|
||||||
end
|
|
||||||
|
|
||||||
feature_data.initialize(config)
|
|
||||||
end)
|
|
||||||
|
|
||||||
scenario_initialized = true
|
|
||||||
end
|
|
||||||
|
|
||||||
return Scenario
|
return Scenario
|
||||||
|
@ -7,7 +7,7 @@ local Debug = require 'map_gen.Diggy.Debug'
|
|||||||
local Template = {}
|
local Template = {}
|
||||||
|
|
||||||
local tiles_per_call = 5 --how many tiles are inserted with each call of insert_action
|
local tiles_per_call = 5 --how many tiles are inserted with each call of insert_action
|
||||||
local entities_per_call = 5 --how many entities are inserted with each call of insert_action
|
local entities_per_call = 5 --how many entities are inserted with each call of insert_action
|
||||||
|
|
||||||
Template.events = {
|
Template.events = {
|
||||||
--[[--
|
--[[--
|
||||||
@ -37,23 +37,32 @@ local function insert_next_tiles(data)
|
|||||||
local surface = data.surface
|
local surface = data.surface
|
||||||
local tiles = {}
|
local tiles = {}
|
||||||
|
|
||||||
pcall(function() --use pcall to assure tile_iterator is always incremented, to avoid endless loops
|
pcall(
|
||||||
for i = data.tile_iterator, math.min(data.tile_iterator + tiles_per_call - 1, data.tiles_n) do
|
function()
|
||||||
local new_tile = data.tiles[i]
|
--use pcall to assure tile_iterator is always incremented, to avoid endless loops
|
||||||
table.insert(tiles, new_tile)
|
for i = data.tile_iterator, math.min(data.tile_iterator + tiles_per_call - 1, data.tiles_n) do
|
||||||
local current_tile = surface.get_tile(new_tile.position.x, new_tile.position.y)
|
local new_tile = data.tiles[i]
|
||||||
local current_is_void = current_tile.name == 'out-of-map'
|
table.insert(tiles, new_tile)
|
||||||
local new_is_void = new_tile.name == 'out-of-map'
|
local current_tile = surface.get_tile(new_tile.position.x, new_tile.position.y)
|
||||||
|
local current_is_void = current_tile.name == 'out-of-map'
|
||||||
|
local new_is_void = new_tile.name == 'out-of-map'
|
||||||
|
|
||||||
if (current_is_void and not new_is_void) then
|
if (current_is_void and not new_is_void) then
|
||||||
table.insert(void_removed, {surface = surface, old_tile = {name = current_tile.name, position = current_tile.position}})
|
table.insert(
|
||||||
end
|
void_removed,
|
||||||
|
{surface = surface, old_tile = {name = current_tile.name, position = current_tile.position}}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
if (new_is_void and not current_is_void) then
|
if (new_is_void and not current_is_void) then
|
||||||
table.insert(void_added, {surface = surface, old_tile = {name = current_tile.name, position = current_tile.position}})
|
table.insert(
|
||||||
|
void_added,
|
||||||
|
{surface = surface, old_tile = {name = current_tile.name, position = current_tile.position}}
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
)
|
||||||
|
|
||||||
data.tile_iterator = data.tile_iterator + tiles_per_call
|
data.tile_iterator = data.tile_iterator + tiles_per_call
|
||||||
|
|
||||||
@ -72,17 +81,20 @@ local function insert_next_entities(data)
|
|||||||
local created_entities = {}
|
local created_entities = {}
|
||||||
local surface = data.surface
|
local surface = data.surface
|
||||||
|
|
||||||
pcall(function() --use pcall to assure tile_iterator is always incremented, to avoid endless loops
|
pcall(
|
||||||
for i = data.entity_iterator, math.min(data.entity_iterator + entities_per_call - 1, data.entities_n) do
|
function()
|
||||||
local entity = data.entities[i]
|
--use pcall to assure tile_iterator is always incremented, to avoid endless loops
|
||||||
created_entity = surface.create_entity(entity)
|
for i = data.entity_iterator, math.min(data.entity_iterator + entities_per_call - 1, data.entities_n) do
|
||||||
if (nil == created_entity) then
|
local entity = data.entities[i]
|
||||||
error('Failed creating entity ' .. entity.name .. ' on surface.')
|
local created_entity = surface.create_entity(entity)
|
||||||
end
|
if (nil == created_entity) then
|
||||||
|
error('Failed creating entity ' .. entity.name .. ' on surface.')
|
||||||
|
end
|
||||||
|
|
||||||
table.insert(created_entities, created_entity)
|
table.insert(created_entities, created_entity)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
)
|
||||||
|
|
||||||
data.entity_iterator = data.entity_iterator + entities_per_call
|
data.entity_iterator = data.entity_iterator + entities_per_call
|
||||||
|
|
||||||
@ -133,11 +145,11 @@ function Template.insert(surface, tiles, entities)
|
|||||||
}
|
}
|
||||||
|
|
||||||
local continue = true
|
local continue = true
|
||||||
for i=1,4 do
|
for i = 1, 4 do
|
||||||
continue = insert_action(data)
|
continue = insert_action(data)
|
||||||
if not continue then
|
if not continue then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if continue then
|
if continue then
|
||||||
Task.queue_task(insert_token, data, total_calls - 4)
|
Task.queue_task(insert_token, data, total_calls - 4)
|
||||||
@ -162,7 +174,7 @@ function Template.units(surface, units, non_colliding_distance)
|
|||||||
entity.position = position
|
entity.position = position
|
||||||
surface.create_entity(entity)
|
surface.create_entity(entity)
|
||||||
else
|
else
|
||||||
Debug.print('Failed to spawn \'' .. entity.name .. '\' at \'' .. serpent.line(entity.position) .. '\'')
|
Debug.print("Failed to spawn '" .. entity.name .. "' at '" .. serpent.line(entity.position) .. "'")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -20,7 +20,7 @@ local tiles_per_tick = 32
|
|||||||
--require "map_gen.combined.dagobah_swamp"
|
--require "map_gen.combined.dagobah_swamp"
|
||||||
--require "map_gen.combined.meteor_strike" --unfinished
|
--require "map_gen.combined.meteor_strike" --unfinished
|
||||||
--require 'map_gen.combined.cave_miner.cave_miner'
|
--require 'map_gen.combined.cave_miner.cave_miner'
|
||||||
--require "map_gen.combined.diggy"
|
require "map_gen.combined.diggy"
|
||||||
|
|
||||||
|
|
||||||
--presets--
|
--presets--
|
||||||
|
Loading…
Reference in New Issue
Block a user