From 2a9d89accde974303c121d41229da174ca36cea5 Mon Sep 17 00:00:00 2001 From: Lynn Date: Sat, 1 Dec 2018 17:58:22 +0100 Subject: [PATCH] Using Template for is_diggy_rock --- map_gen/Diggy/Feature/DiggyCaveCollapse.lua | 10 +++++----- map_gen/Diggy/Feature/DiggyHole.lua | 8 ++++---- map_gen/Diggy/Feature/SimpleRoomGenerator.lua | 2 +- map_gen/Diggy/Template.lua | 8 ++++++++ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/map_gen/Diggy/Feature/DiggyCaveCollapse.lua b/map_gen/Diggy/Feature/DiggyCaveCollapse.lua index ad5916af..51b16c03 100644 --- a/map_gen/Diggy/Feature/DiggyCaveCollapse.lua +++ b/map_gen/Diggy/Feature/DiggyCaveCollapse.lua @@ -87,7 +87,7 @@ DiggyCaveCollapse.events = { ]] on_collapse = script.generate_event_name() } -local collapse_rocks = {'sand-rock-big', 'rock-big', 'rock-big'} +local collapse_rocks = Template.diggy_rocks local collapse_rocks_size = #collapse_rocks local function create_collapse_template(positions, surface) @@ -113,7 +113,7 @@ local function create_collapse_template(positions, surface) if do_insert then entity_count = entity_count + 1 - entities[entity_count] = {position = position, name = collapse_rocks[random(1, collapse_rocks_size)]} + entities[entity_count] = {position = position, name = collapse_rocks[random(collapse_rocks_size)]} end end @@ -246,7 +246,7 @@ local function on_mined_entity(event) local strength = support_beam_entities[name] if strength then local player_index - if name ~= 'sand-rock-big' and name ~= 'rock-huge' and name ~= 'rock-big' then + if not Template.is_diggy_rock(name) then player_index = event.player_index end stress_map_add(entity.surface, entity.position, strength, false, player_index) @@ -259,7 +259,7 @@ local function on_entity_died(event) local strength = support_beam_entities[name] if strength then local player_index - if name ~= 'sand-rock-big' and name ~= 'rock-huge' and name ~= 'rock-big' then + if not Template.is_diggy_rock(name) then local cause = event.cause player_index = cause and cause.player and cause.player.index or nil end @@ -369,7 +369,7 @@ function DiggyCaveCollapse.register(cfg) Event.add(defines.events.on_marked_for_deconstruction, function (event) local entity = event.entity local name = entity.name - if name == 'sand-rock-big' or name == 'rock-huge' and name ~= 'rock-big' then + if Template.is_diggy_rock(name) then return end diff --git a/map_gen/Diggy/Feature/DiggyHole.lua b/map_gen/Diggy/Feature/DiggyHole.lua index 04fa845d..51f0904c 100644 --- a/map_gen/Diggy/Feature/DiggyHole.lua +++ b/map_gen/Diggy/Feature/DiggyHole.lua @@ -130,7 +130,7 @@ function DiggyHole.register(config) Event.add(defines.events.on_entity_died, function (event) local entity = event.entity local name = entity.name - if name ~= 'sand-rock-big' and name ~= 'rock-huge' and name ~= 'rock-big' then + if not Template.is_diggy_rock(name) then return end diggy_hole(entity) @@ -147,7 +147,7 @@ function DiggyHole.register(config) return end - if name ~= 'sand-rock-big' and name ~= 'rock-huge' and name ~= 'rock-big' then + if not Template.is_diggy_rock(name) then return end @@ -159,7 +159,7 @@ function DiggyHole.register(config) local entity = event.entity local name = entity.name - if name ~= 'sand-rock-big' and name ~= 'rock-huge' and name ~= 'rock-big' then + if not Template.is_diggy_rock(name) then return end @@ -190,7 +190,7 @@ function DiggyHole.register(config) Event.add(defines.events.on_player_mined_entity, function (event) local entity = event.entity local name = entity.name - if name ~= 'sand-rock-big' and name ~= 'rock-huge' and name ~= 'rock-big' then + if not Template.is_diggy_rock(name) then return end diff --git a/map_gen/Diggy/Feature/SimpleRoomGenerator.lua b/map_gen/Diggy/Feature/SimpleRoomGenerator.lua index 371dd7ee..9e9127a1 100644 --- a/map_gen/Diggy/Feature/SimpleRoomGenerator.lua +++ b/map_gen/Diggy/Feature/SimpleRoomGenerator.lua @@ -18,7 +18,7 @@ local do_spawn_tile = Token.register(function(params) Template.insert(params.surface, {params.tile}, {}) end) -local rocks_lookup = {'sand-rock-big', 'rock-huge', 'rock-big'} +local rocks_lookup = Template.diggy_rocks local do_mine = Token.register(function(params) local surface = params.surface diff --git a/map_gen/Diggy/Template.lua b/map_gen/Diggy/Template.lua index 72c5d1b8..9cffc380 100644 --- a/map_gen/Diggy/Template.lua +++ b/map_gen/Diggy/Template.lua @@ -155,4 +155,12 @@ function Template.resources(surface, resources) end end +Template.diggy_rocks = {'sand-rock-big', 'rock-big', 'rock-big'} + +---Returns true if the entity name is that of a diggy rock. +---@param entity_name string +function Template.is_diggy_rock(entity_name) + return entity_name == 'sand-rock-big' or entity_name == 'rock-big' or entity_name == 'rock-huge' +end + return Template