diff --git a/PHI-CL/control.lua b/PHI-CL/control.lua index bea3064..0382660 100644 --- a/PHI-CL/control.lua +++ b/PHI-CL/control.lua @@ -1,3 +1,6 @@ +local cargo_landing_pad = require('control/cargo-landing-pad') +local cargo_landing_chest = require('control/cargo-landing-chest') +local lab = require('control/lab') local rail_support = require('control/rail-support') local inserter_direction = { @@ -96,47 +99,11 @@ end -- settings.startup['PHI-GM'].value and settings.startup['PHI-GM'].value == 'SAP' local function entity_build(event) + cargo_landing_pad.build(event) + cargo_landing_chest.build(event) + lab.build(event) rail_support.build(event) - if event.entity.type == 'lab' and prototypes.entity['proxy-container'] then - local p = event.entity.surface.create_entity{name = 'proxy-container', position = {event.entity.position.x, event.entity.position.y}, force = 'neutral', quality = event.entity.quality.name} - p.destructible = false - p.proxy_target_entity = event.entity - p.proxy_target_inventory = defines.inventory.lab_input - - return - end - - if event.entity.type == 'proxy-container' and event.entity.name == 'proxy-cargo-landing-chest' and prototypes.entity['cargo-landing-pad'] then - local ec = game.surfaces[event.entity.surface].find_entities_filtered{type='cargo-landing-pad'} - - if not ec then - return - end - - event.entity.proxy_target_entity = ec[1] - event.entity.proxy_target_inventory = defines.inventory.cargo_landing_pad_main - - return - end - - if event.entity.type == 'cargo-landing-pad' and event.entity.name == 'cargo-landing-pad' and prototypes.entity['proxy-cargo-landing-chest'] then - local ec = game.surfaces[event.entity.surface].find_entities_filtered{type='cargo-landing-pad'} - - if #ec > 1 then - return - end - - local ep = game.surfaces[event.entity.surface].find_entities_filtered{type='proxy-container', name='proxy-cargo-landing-chest'} - - for _, v in pairs(ep) do - v.proxy_target_entity = ec[1] - v.proxy_target_inventory = defines.inventory.cargo_landing_pad_main - end - - return - end - if event.entity.type == 'infinity-container' and event.entity.name == 'trash-chest' then event.entity.remove_unfiltered_items = true @@ -145,20 +112,6 @@ local function entity_build(event) end end -local function entity_destroy(event) - rail_support.destroy(event) - - if event.entity.type == 'lab' and prototypes.entity['proxy-container'] then - local p = event.entity.surface.find_entity({name = 'proxy-container', force = 'neutral', quality = event.entity.quality.name}, {event.entity.position.x, event.entity.position.y}) - - if p then - p.destroy() - end - - return - end -end - local function storage_init() if not storage.phi_cl then storage.phi_cl = {} @@ -261,7 +214,8 @@ if settings.startup['PHI-MI'].value or (settings.startup['PHI-GM'].value and set script.on_event({defines.events.on_entity_died, defines.events.on_player_mined_entity, defines.events.on_robot_pre_mined, defines.events.script_raised_destroy}, function(event) - entity_destroy(event) + lab.destroy(event) + rail_support.destroy(event) end) end diff --git a/PHI-CL/control/cargo-landing-chest.lua b/PHI-CL/control/cargo-landing-chest.lua new file mode 100644 index 0000000..5e7e820 --- /dev/null +++ b/PHI-CL/control/cargo-landing-chest.lua @@ -0,0 +1,29 @@ +local main = {} + +function main.build(event) + if event.entity.type ~= 'cargo-landing-pad' then + return + end + + if event.entity.name ~= 'cargo-landing-pad' then + return + end + if not prototypes.entity['proxy-cargo-landing-chest'] then + return + end + + local ec = game.surfaces[event.entity.surface].find_entities_filtered{type='cargo-landing-pad'} + + if #ec > 1 then + return + end + + local ep = game.surfaces[event.entity.surface].find_entities_filtered{type='proxy-container', name='proxy-cargo-landing-chest'} + + for _, v in pairs(ep) do + v.proxy_target_entity = ec[1] + v.proxy_target_inventory = defines.inventory.cargo_landing_pad_main + end +end + +return main diff --git a/PHI-CL/control/cargo-landing-pad.lua b/PHI-CL/control/cargo-landing-pad.lua new file mode 100644 index 0000000..80ae2be --- /dev/null +++ b/PHI-CL/control/cargo-landing-pad.lua @@ -0,0 +1,26 @@ +local main = {} + +function main.build(event) + if event.entity.type ~= 'proxy-container' then + return + end + + if event.entity.name ~= 'proxy-cargo-landing-chest' then + return + end + + if not prototypes.entity['cargo-landing-pad'] then + return + end + + local ec = game.surfaces[event.entity.surface].find_entities_filtered{type='cargo-landing-pad'} + + if not ec then + return + end + + event.entity.proxy_target_entity = ec[1] + event.entity.proxy_target_inventory = defines.inventory.cargo_landing_pad_main +end + +return main diff --git a/PHI-CL/control/lab.lua b/PHI-CL/control/lab.lua new file mode 100644 index 0000000..d81a36f --- /dev/null +++ b/PHI-CL/control/lab.lua @@ -0,0 +1,36 @@ +local main = {} + +function main.build(event) + if event.entity.type ~= 'lab' then + return + end + + if not prototypes.entity['proxy-container'] then + return + end + + local p = event.entity.surface.create_entity{name = 'proxy-container', position = {event.entity.position.x, event.entity.position.y}, force = 'neutral', quality = event.entity.quality.name} + p.destructible = false + p.proxy_target_entity = event.entity + p.proxy_target_inventory = defines.inventory.lab_input +end + +function main.destroy(event) + if event.entity.type ~= 'lab' then + return + end + + if not prototypes.entity['proxy-container'] then + return + end + + local p = event.entity.surface.find_entity({name = 'proxy-container', force = 'neutral', quality = event.entity.quality.name}, {event.entity.position.x, event.entity.position.y}) + + if not p then + return + end + + p.destroy() +end + +return main diff --git a/PHI-CL/control/rail-support.lua b/PHI-CL/control/rail-support.lua index 4c9db6d..3188437 100644 --- a/PHI-CL/control/rail-support.lua +++ b/PHI-CL/control/rail-support.lua @@ -6,31 +6,31 @@ local rail_support_pole = { local main = {} function main.build(event) - if event.entity.type == 'rail-support' then - for _, v in pairs(rail_support_pole) do - if prototypes.entity[v] then - local p = event.entity.surface.create_entity{name = v, position = {event.entity.position.x, event.entity.position.y}, force = 'neutral', quality = event.entity.quality.name} - p.destructible = false - end - end - + if event.entity.type ~= 'rail-support' then return end + + for _, v in pairs(rail_support_pole) do + if prototypes.entity[v] then + local p = event.entity.surface.create_entity{name = v, position = {event.entity.position.x, event.entity.position.y}, force = 'neutral', quality = event.entity.quality.name} + p.destructible = false + end + end end function main.destroy(event) - if event.entity.type == 'rail-support' then - for _, v in pairs(rail_support_pole) do - if prototypes.entity[v] then - local p = event.entity.surface.find_entity({name = v, force = 'neutral', quality = event.entity.quality.name}, {event.entity.position.x, event.entity.position.y}) + if event.entity.type ~= 'rail-support' then + return + end - if p then - p.destroy() - end + for _, v in pairs(rail_support_pole) do + if prototypes.entity[v] then + local p = event.entity.surface.find_entity({name = v, force = 'neutral', quality = event.entity.quality.name}, {event.entity.position.x, event.entity.position.y}) + + if p then + p.destroy() end end - - return end end