From 65a9e1fc5d5627b6bb4fc3f1bea5d23ffaaefe19 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Sat, 9 Aug 2025 02:02:23 +0900 Subject: [PATCH] . --- PHI-CL/control.lua | 176 ++++++++++++++++++++++++++------------------- 1 file changed, 101 insertions(+), 75 deletions(-) diff --git a/PHI-CL/control.lua b/PHI-CL/control.lua index bf3ed8c..7604a68 100644 --- a/PHI-CL/control.lua +++ b/PHI-CL/control.lua @@ -178,15 +178,29 @@ script.on_init(function() end end - storage.phi_cl = { - cargo_landing_pad_storage = {}, - combinator = { + if not storage.phi_cl then + storage.phi_cl = {} + end + + if not storage.phi_cl.loop then + storage.phi_cl.loop = { + cargo_landing_pad_storage = false, + combinator = false + } + end + + if not storage.phi_cl.cargo_landing_pad_storage then + storage.phi_cl.cargo_landing_pad_storage = {} + end + + if not storage.phi_cl.combinator then + storage.phi_cl.combinator = { research_set_combinator_count = 0, research_queue = {}, research_queue_set = {}, research_progress = 0 } - } + end end) script.on_configuration_changed(function() @@ -200,71 +214,34 @@ script.on_configuration_changed(function() end end - if storage.phi_cl then - if not storage.phi_cl.cargo_landing_pad_storage then - storage.phi_cl.cargo_landing_pad_storage = {} - end - - if not storage.phi_cl.combinator then - storage.phi_cl.combinator = { - research_set_combinator_count = 0, - research_queue = {}, - research_queue_set = {}, - research_progress = 0 - } - end + if not storage.phi_cl then + storage.phi_cl = {} end + + if not storage.phi_cl.loop then + storage.phi_cl.loop = { + cargo_landing_pad_storage = false, + combinator = false + } + end + + if not storage.phi_cl.cargo_landing_pad_storage then + storage.phi_cl.cargo_landing_pad_storage = {} + end + + if not storage.phi_cl.combinator then + storage.phi_cl.combinator = { + research_set_combinator_count = 0, + research_queue = {}, + research_queue_set = {}, + research_progress = 0 + } + end + + storage.phi_cl.loop.cargo_landing_pad_storage = (settings.startup['PHI-GM'].value and settings.startup['PHI-GM'].value == 'VP') + storage.phi_cl.loop.combinator = (settings.startup['PHI-MI'].value or (settings.startup['PHI-GM'].value and settings.startup['PHI-GM'].value ~= '')) end) -if settings.startup['PHI-GM'].value and settings.startup['PHI-GM'].value == 'VP' then - script.on_nth_tick(1800, function(_) - -- - local ec = game.surfaces[1].find_entities_filtered{type='cargo-landing-pad'} - local ec_count = #ec - - if ec_count <= 1 then - return - end - - local inv = ec[1].get_inventory(defines.inventory.cargo_landing_pad_main) - - if inv then - local item = inv.get_contents() - - for _, v in pairs(item) do - if storage.phi_cl.cargo_landing_pad_storage[v.name] and (storage.phi_cl.cargo_landing_pad_storage[v.name].quality == v.quality) then - storage.phi_cl.cargo_landing_pad_storage[v.name][v.quality] = storage.phi_cl.cargo_landing_pad_storage[v.name] + v.count - - else - storage.phi_cl.cargo_landing_pad_storage[v.name] = {[v.quality] = v.count} - end - end - - inv.clear() - end - - for _, e in pairs(ec) do - local inventory = e.get_inventory(defines.inventory.chest) - local inventory_request_sections = e.get_logistic_sections().sections - - if inventory then - for i = 1, #inventory_request_sections do - for _, v in pairs(inventory_request_sections[i].filters) do - if v.value and v.value.quality then - local request_amount = math.min(v.min - inventory.get_item_count(v.value.name), storage.phi_cl.cargo_landing_pad_storage[v.value.name][v.value.quality]) - - if request_amount > 0 and inventory.can_insert{name = v.value.name, count = request_amount, quality = v.value.quality} then - storage.phi_cl.cargo_landing_pad_storage[v.value.name][v.value.quality] = storage.phi_cl.cargo_landing_pad_storage[v.value.name][v.value.quality] - request_amount - inventory.insert{name = v.value.name, count = request_amount, quality = v.value.quality} - end - end - end - end - end - end - end) -end - if settings.startup['PHI-MI'].value or (settings.startup['PHI-GM'].value and settings.startup['PHI-GM'].value ~= '') then script.on_event(defines.events.on_player_created, function(event) gui_create(game.players[event.player_index]) @@ -319,7 +296,62 @@ if settings.startup['PHI-MI'].value or (settings.startup['PHI-GM'].value and set entity_destroy(event) end) - script.on_nth_tick(1800, function(_) +end + +if settings.startup['PHI-CT'].value then + script.on_event({defines.events.on_player_cheat_mode_enabled, defines.events.on_player_cheat_mode_disabled}, function(event) + hidden_recipe_enable(event) + end) +end + +script.on_nth_tick(1800, function(_) + if storage.phi_cl.loop.cargo_landing_pad_storage then + local ec = game.surfaces[1].find_entities_filtered{type='cargo-landing-pad'} + local ec_count = #ec + + if ec_count <= 1 then + return + end + + local inv = ec[1].get_inventory(defines.inventory.cargo_landing_pad_main) + + if inv then + local item = inv.get_contents() + + for _, v in pairs(item) do + if storage.phi_cl.cargo_landing_pad_storage[v.name] and (storage.phi_cl.cargo_landing_pad_storage[v.name].quality == v.quality) then + storage.phi_cl.cargo_landing_pad_storage[v.name][v.quality] = storage.phi_cl.cargo_landing_pad_storage[v.name][v.quality] + v.count + + else + storage.phi_cl.cargo_landing_pad_storage[v.name] = {[v.quality] = v.count} + end + end + + inv.clear() + end + + for _, e in pairs(ec) do + local inventory = e.get_inventory(defines.inventory.chest) + local inventory_request_sections = e.get_logistic_sections().sections + + if inventory then + for i = 1, #inventory_request_sections do + for _, v in pairs(inventory_request_sections[i].filters) do + if v.value and v.value.quality then + local request_amount = math.min(v.min - inventory.get_item_count(v.value.name), storage.phi_cl.cargo_landing_pad_storage[v.value.name][v.value.quality]) + + if request_amount > 0 and inventory.can_insert{name = v.value.name, count = request_amount, quality = v.value.quality} then + storage.phi_cl.cargo_landing_pad_storage[v.value.name][v.value.quality] = storage.phi_cl.cargo_landing_pad_storage[v.value.name][v.value.quality] - request_amount + inventory.insert{name = v.value.name, count = request_amount, quality = v.value.quality} + end + end + end + end + end + end + end + + if storage.phi_cl.loop.combinator then storage.phi_cl.combinator.research_progress = math.floor(game.forces['player'].research_progress * 100) do @@ -410,11 +442,5 @@ if settings.startup['PHI-MI'].value or (settings.startup['PHI-GM'].value and set -- game.forces['player'].research_queue = storage.phi_cl.combinator.research_queue_set end end - end) -end - -if settings.startup['PHI-CT'].value then - script.on_event({defines.events.on_player_cheat_mode_enabled, defines.events.on_player_cheat_mode_disabled}, function(event) - hidden_recipe_enable(event) - end) -end + end +end)