1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2024-12-30 23:17:53 +02:00

small refactor of duplicated code in dungeons

This commit is contained in:
hanakocz 2022-05-01 20:31:47 +02:00
parent 01f4dab5b8
commit f26efb12c3
3 changed files with 22 additions and 42 deletions

View File

@ -358,6 +358,26 @@ function Public.create_scrap(surface, position)
surface.create_entity({name = scraps[math_random(1, #scraps)], position = position, force = 'neutral'})
end
function Public.on_marked_for_deconstruction(event)
local disabled_for_deconstruction = {
['fish'] = true,
['rock-huge'] = true,
['rock-big'] = true,
['sand-rock-big'] = true,
['crash-site-spaceship-wreck-small-1'] = true,
['crash-site-spaceship-wreck-small-2'] = true,
['crash-site-spaceship-wreck-small-3'] = true,
['crash-site-spaceship-wreck-small-4'] = true,
['crash-site-spaceship-wreck-small-5'] = true,
['crash-site-spaceship-wreck-small-6'] = true
}
if event.entity and event.entity.valid then
if disabled_for_deconstruction[event.entity.name] then
event.entity.cancel_deconstruction(game.players[event.player_index].force.name)
end
end
end
-- old function 0 - 250 floor 0; 250-500 floor 1; 500 floor 2+
-- new function 25 - 75 floor 0; 50-100 floor 1; 75-125 floor 2; ...; 500 floor 19
--

View File

@ -30,19 +30,6 @@ local math_abs = math.abs
local math_floor = math.floor
local math_round = math.round
local disabled_for_deconstruction = {
['fish'] = true,
['rock-huge'] = true,
['rock-big'] = true,
['sand-rock-big'] = true,
['crash-site-spaceship-wreck-small-1'] = true,
['crash-site-spaceship-wreck-small-2'] = true,
['crash-site-spaceship-wreck-small-3'] = true,
['crash-site-spaceship-wreck-small-4'] = true,
['crash-site-spaceship-wreck-small-5'] = true,
['crash-site-spaceship-wreck-small-6'] = true
}
local function get_biome(position)
--if not a then return "concrete" end
if position.x ^ 2 + position.y ^ 2 < 6400 then
@ -359,12 +346,6 @@ local function on_entity_died(event)
expand(entity.surface, entity.position)
end
local function on_marked_for_deconstruction(event)
if disabled_for_deconstruction[event.entity.name] then
event.entity.cancel_deconstruction(game.players[event.player_index].force.name)
end
end
local function on_init()
local dungeontable = DungeonsTable.get_dungeontable()
local force = game.create_force('dungeon')
@ -445,7 +426,7 @@ end
local Event = require 'utils.event'
Event.on_init(on_init)
--Event.add(defines.events.on_tick, on_tick)
Event.add(defines.events.on_marked_for_deconstruction, on_marked_for_deconstruction)
Event.add(defines.events.on_marked_for_deconstruction, Functions.on_marked_for_deconstruction)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
Event.add(defines.events.on_chunk_generated, on_chunk_generated)

View File

@ -41,19 +41,6 @@ Biomes.laboratory = require 'maps.dungeons.biome_laboratory'
local math_random = math.random
local math_round = math.round
local disabled_for_deconstruction = {
['fish'] = true,
['rock-huge'] = true,
['rock-big'] = true,
['sand-rock-big'] = true,
['crash-site-spaceship-wreck-small-1'] = true,
['crash-site-spaceship-wreck-small-2'] = true,
['crash-site-spaceship-wreck-small-3'] = true,
['crash-site-spaceship-wreck-small-4'] = true,
['crash-site-spaceship-wreck-small-5'] = true,
['crash-site-spaceship-wreck-small-6'] = true
}
local function enable_hard_rooms(position, surface_index)
local dungeon_table = DungeonsTable.get_dungeontable()
local floor = surface_index - dungeon_table.original_surface_index
@ -515,14 +502,6 @@ local function on_entity_died(event)
expand(entity.surface, entity.position)
end
local function on_marked_for_deconstruction(event)
if event.entity and event.entity.valid then
if disabled_for_deconstruction[event.entity.name] then
event.entity.cancel_deconstruction(game.players[event.player_index].force.name)
end
end
end
local function get_map_gen_settings()
local settings = {
['seed'] = math_random(1, 1000000),
@ -853,7 +832,7 @@ end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.on_nth_tick(60, on_tick)
Event.add(defines.events.on_marked_for_deconstruction, on_marked_for_deconstruction)
Event.add(defines.events.on_marked_for_deconstruction, Functions.on_marked_for_deconstruction)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
Event.add(defines.events.on_built_entity, on_built_entity)