From bbab8621a216d1bf5a1c329eca56cdfa43add3b6 Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Mon, 14 Apr 2025 07:16:06 -0700 Subject: Fixes formatting of control.lua --- control.lua | 250 ++++++++++++++++++++++++++---------------------------------- 1 file changed, 109 insertions(+), 141 deletions(-) (limited to 'control.lua') diff --git a/control.lua b/control.lua index 80affc9..6669beb 100644 --- a/control.lua +++ b/control.lua @@ -1,103 +1,86 @@ local util = require("util") local crash_site = require("crash-site") - local modEnabled = true -local entities = - { - {"substation", {y = 0.5,x = -0.5}, {}}, - {"accumulator", {y = -1.5,x = -0.5}, {}}, - {"accumulator", {y = -1.5,x = 1.5}, {}}, - {"accumulator", {y = 0.5,x = 1.5}, {}}, - {"iron-storage-chest", {y = -2,x = 3}, - { - items = - { - {"roboport", 5}, - {"repair-turret", 15}, - {"electric-mining-drill", 10}, - {"transport-belt", 100}, - {"big-electric-pole", 10}, - {"small-electric-pole", 20}, - {"power-switch", 5}, - {"iron-active-provider-chest", 10}, - {"iron-buffer-chest", 20}, - {"iron-passive-provider-chest", 50}, - {"iron-requester-chest", 50}, - {"iron-storage-chest", 50}, - {"inserter", 50}, - {"stone-furnace", 50} - } - }}, - {"iron-storage-chest", {y = -2,x = 4}, {}}, - {"iron-storage-chest", {y = -2,x = 5}, {}}, - {"roboport", {y = -0.5,x = -3.5}, - { - items = - { - {"early-construction-robot", 20}, - {"early-logistic-robot", 10}, - {"repair-pack", 50} - } - }}, - {"assembling-machine-1", {y = 0,x = 4}, {}}, - {"inserter", {y = -1,x = 6}, {dir = "west"}}, - {"inserter", {y = 1,x = 6}, {dir = "east"}}, - {"iron-passive-provider-chest", {y = -1,x = 7}, {}}, - {"iron-requester-chest", {y = 1,x = 7}, {}}, - {"solar-panel", {y = 3,x = 6}, {}}, - {"solar-panel", {y = 3,x = 3}, {}}, - {"solar-panel", {y = 3,x = 0}, {}}, - {"solar-panel", {y = 3,x = -3}, {}}, - {"solar-panel", {y = 3,x = -6}, {}}, - {"solar-panel", {y = 6,x = 6}, {}}, - {"solar-panel", {y = 6,x = 3}, {}}, - {"solar-panel", {y = 6,x = 0}, {}}, - {"solar-panel", {y = 6,x = -3}, {}}, - {"solar-panel", {y = 6,x = -6}, {}}, - {"solar-panel", {y = 9,x = 6}, {}}, - {"solar-panel", {y = 9,x = 3}, {}}, - {"solar-panel", {y = 9,x = 0}, {}}, - {"solar-panel", {y = 9,x = -3}, {}}, - {"solar-panel", {y = 9,x = -6}, {}}, - {"solar-panel", {y = -4,x = 6}, {}}, - {"solar-panel", {y = -4,x = 3}, {}}, - {"solar-panel", {y = -4,x = 0}, {}}, - {"solar-panel", {y = -4,x = -3}, {}}, - {"solar-panel", {y = -4,x = -6}, {}}, - {"solar-panel", {y = -7,x = 6}, {}}, - {"solar-panel", {y = -7,x = 3}, {}}, - {"solar-panel", {y = -7,x = 0}, {}}, - {"solar-panel", {y = -7,x = -3}, {}}, - {"solar-panel", {y = -7,x = -6}, {}}, - {"accumulator", {y = 0.5,x = -6.5}, {}}, - {"accumulator", {y = -1.5,x = -6.5}, {}} - } ---local entities = -local entities_landing_pad = - { - {"roboport", {y = -6.5,x = 2.5}, - { - items = - { - {"construction-robot", 10} - } - }}, - {"storage-chest", {y = -5,x = 5}, {}}, - {"substation", {y = -3.5,x = 4.5}, {}}, - - } ---local entities_landing_pad_aquilo = +local entities = { + {"substation", {y = 0.5,x = -0.5}, {}}, + {"accumulator", {y = -1.5,x = -0.5}, {}}, + {"accumulator", {y = -1.5,x = 1.5}, {}}, + {"accumulator", {y = 0.5,x = 1.5}, {}}, + {"iron-storage-chest", {y = -2,x = 3}, { + items = { + {"roboport", 5}, + {"repair-turret", 15}, + {"electric-mining-drill", 10}, + {"transport-belt", 100}, + {"big-electric-pole", 10}, + {"small-electric-pole", 20}, + {"power-switch", 5}, + {"iron-active-provider-chest", 10}, + {"iron-buffer-chest", 20}, + {"iron-passive-provider-chest", 50}, + {"iron-requester-chest", 50}, + {"iron-storage-chest", 50}, + {"inserter", 50}, + {"stone-furnace", 50} + } + }}, + {"iron-storage-chest", {y = -2,x = 4}, {}}, + {"iron-storage-chest", {y = -2,x = 5}, {}}, + {"roboport", {y = -0.5,x = -3.5}, { + items = { + {"early-construction-robot", 20}, + {"early-logistic-robot", 10}, + {"repair-pack", 50} + } + }}, + {"assembling-machine-1", {y = 0,x = 4}, {}}, + {"inserter", {y = -1,x = 6}, {dir = "west"}}, + {"inserter", {y = 1,x = 6}, {dir = "east"}}, + {"iron-passive-provider-chest", {y = -1,x = 7}, {}}, + {"iron-requester-chest", {y = 1,x = 7}, {}}, + {"solar-panel", {y = 3,x = 6}, {}}, + {"solar-panel", {y = 3,x = 3}, {}}, + {"solar-panel", {y = 3,x = 0}, {}}, + {"solar-panel", {y = 3,x = -3}, {}}, + {"solar-panel", {y = 3,x = -6}, {}}, + {"solar-panel", {y = 6,x = 6}, {}}, + {"solar-panel", {y = 6,x = 3}, {}}, + {"solar-panel", {y = 6,x = 0}, {}}, + {"solar-panel", {y = 6,x = -3}, {}}, + {"solar-panel", {y = 6,x = -6}, {}}, + {"solar-panel", {y = 9,x = 6}, {}}, + {"solar-panel", {y = 9,x = 3}, {}}, + {"solar-panel", {y = 9,x = 0}, {}}, + {"solar-panel", {y = 9,x = -3}, {}}, + {"solar-panel", {y = 9,x = -6}, {}}, + {"solar-panel", {y = -4,x = 6}, {}}, + {"solar-panel", {y = -4,x = 3}, {}}, + {"solar-panel", {y = -4,x = 0}, {}}, + {"solar-panel", {y = -4,x = -3}, {}}, + {"solar-panel", {y = -4,x = -6}, {}}, + {"solar-panel", {y = -7,x = 6}, {}}, + {"solar-panel", {y = -7,x = 3}, {}}, + {"solar-panel", {y = -7,x = 0}, {}}, + {"solar-panel", {y = -7,x = -3}, {}}, + {"solar-panel", {y = -7,x = -6}, {}}, + {"accumulator", {y = 0.5,x = -6.5}, {}}, + {"accumulator", {y = -1.5,x = -6.5}, {}} +} + +local entities_landing_pad = { + {"roboport", {y = -6.5,x = 2.5}, { + items = { + {"construction-robot", 10} + } + }}, + {"storage-chest", {y = -5,x = 5}, {}}, + {"substation", {y = -3.5,x = 4.5}, {}}, +} local function spawn_entity(entity_name, relative_position, center, surface, extra_options, force) - -- local entity_name = expressions.entity(entity, vars) - - -- if not prototypes[entity_name] then - -- util.debugprint("entity " .. entity_name .. " does not exist") - -- return - -- end - local recipe + if extra_options.recipe then if not game.recipe_prototypes[extra_options.recipe] then util.debugprint("recipe " .. extra_options.recipe .. " does not exist") @@ -115,17 +98,19 @@ local function spawn_entity(entity_name, relative_position, center, surface, ext create_build_effect_smoke = true, recipe = recipe } + if extra_options.items then local items = {} + for _, v in pairs(extra_options.items) do local name = v[1] or v.name - local count = v[2] or v.count if count and count > 0 then items[name] = count end end + util.insert_safe(e, items) end @@ -134,9 +119,11 @@ end function getTableSize(t) local count = 0 + for _, _ in pairs(t) do count = count + 1 end + return count end @@ -148,6 +135,7 @@ function create_power_source(entity) snap_to_grid = false, raise_built = false }) + if(true) then local hi = spawn_entity("clp-heat-interface",{y=-3,x=2},entity.position,entity.surface,{},entity.force) local hp = spawn_entity("clp-heat-pipe",{y=-4,x=2},entity.position,entity.surface,{},entity.force) @@ -160,13 +148,16 @@ end function destroy_power_source(entity) local powerInterface = storage.power_interfaces[entity.unit_number] + if powerInterface ~= nil then powerInterface.destroy({ raise_destroy = false }) storage.power_interfaces[entity.unit_number] = nil end + local heatInterface = storage.heat_intefaces[entity.unit_number] + if heatInterface ~= nil then heatInterface[1].destroy({ raise_destroy = false @@ -179,11 +170,7 @@ function destroy_power_source(entity) end local function clear_area(area, surface) - for _, entity in pairs(surface.find_entities_filtered({ - area = area, - -- type = {"resource"}, - invert = true - })) do + for _, entity in pairs(surface.find_entities_filtered({ area = area, invert = true })) do if (entity.valid) then entity.destroy({ do_cliff_correction = false, @@ -197,15 +184,18 @@ end function on_deconstruction(event) local inventory = event.entity.get_inventory(defines.inventory.cargo_unit) or event.entity.get_inventory(defines.inventory.chest) - - if(inventory == nil) then + + if (inventory == nil) then do return end end + local content = inventory.get_contents() - if(content == nil) then + + if (content == nil) then do return end end - if(inventory.get_item_count("cargo-landing-pad") >= 1 and getTableSize(event.entity.surface.find_entities_filtered({name="cargo-landing-pad"})) == 0) then + + if (inventory.get_item_count("cargo-landing-pad") >= 1 and getTableSize(event.entity.surface.find_entities_filtered({name="cargo-landing-pad"})) == 0) then inventory.remove({name="cargo-landing-pad",count=1}) content = inventory.get_contents() inventory.clear() @@ -218,42 +208,31 @@ function on_deconstruction(event) force.chart(surface,chart) clear_area(area,surface) local clp = spawn_entity("cargo-landing-pad",{x=0,y=0},position,surface,{items=content},force) + for _, v in pairs(entities_landing_pad) do local name = v[1] local pos = v[2] local extra = v[3] spawn_entity(name, pos, clp.position, surface, extra, force) end - - --[[if(surface.name == "aquilo") then - local entity = spawn_entity("clp-heat-interface",{y=-3,x=2},position,surface,{},force) - entity.set_heat_setting{temperature = 1000, mode = "exactly"} - spawn_entity("clp-heat-pipe",{y=-4,x=2},position,surface,{},force) - end]]-- end - end - - local function create_roboport(center, surface, player) for _, v in pairs(entities) do local name = v[1] local pos = v[2] local extra = v[3] local entity = spawn_entity(name, pos, center, surface, extra, player.force) - --[[if(entity.name == "clp-heat-interface" or entity.name == "heat-interface") then - entity.set_heat_setting{temperature = 1000, mode = "exactly"} - end]]-- end end -local function updateInventory () +local function updateInventory() if not modEnabled then return end + for _, pl in pairs(game.players) do - --p = game.get_player(1) local player = game.get_player(pl.name) local inventory = player.get_main_inventory() inventory.clear() @@ -261,9 +240,6 @@ local function updateInventory () end local function on_player_created(event) - -- unregister. we only get called once. - --script.on_event(defines.events.on_player_created, nil) - -- vars the freeplay.lua snippit had local crashed_ship_items = remote.call("freeplay", "get_ship_items") local crashed_debris_items = remote.call("freeplay", "get_debris_items") @@ -294,9 +270,9 @@ local function on_player_created(event) --player.get_main_inventory().resize(0) - local center = player.character.position player.character = nil + if character then character.destroy() end @@ -313,13 +289,6 @@ local function on_player_created(event) util.remove_safe(player, crashed_debris_items) -- player.get_main_inventory().sort_and_merge() - -- player.character.destroy() - -- player.character = nil - -- crash_site.create_cutscene(player, {-5, -4}) - - -- while player.can_insert{name = "inventory-blocker", count = 1} do - -- player.insert{name = "inventory-blocker", count = 1} - -- end updateInventory() local area = {{center.x + 10, center.y + 15}, {center.x - 10, center.y - 15}} clear_area(area, surface) @@ -327,7 +296,6 @@ local function on_player_created(event) end script.on_init(function () - if not remote.interfaces.freeplay then modEnabled = false return @@ -353,11 +321,11 @@ script.on_init(function () end end end) - + script.on_event(defines.events.script_raised_built, function(event) local entity = event.entity or event.created_entity if not entity or not entity.valid then return end - + if (entity.name == "cargo-landing-pad") then create_power_source(entity) end @@ -365,7 +333,7 @@ script.on_init(function () script.on_event(defines.events.on_built_entity, function(event) local entity = event.entity or event.created_entity if not entity or not entity.valid then return end - + if entity.name == "cargo-landing-pad" then create_power_source(entity) end @@ -373,46 +341,46 @@ script.on_init(function () script.on_event(defines.events.on_robot_built_entity, function(event) local entity = event.entity or event.created_entity if not entity or not entity.valid then return end - + if entity.name == "cargo-landing-pad" then create_power_source(entity) end end, filter_built) - + script.on_event(defines.events.on_entity_died, function(event) local entity = event.entity or event.created_entity if not entity or not entity.valid then return end - + if entity.name == "cargo-landing-pad" then destroy_power_source(entity) end end, filter_built) - + ---@param event script_raised_destroy script.on_event(defines.events.script_raised_destroy, function(event) local entity = event.entity or event.created_entity if not entity or not entity.valid then return end - + if entity.name == "cargo-landing-pad" then destroy_power_source(entity) end end, filter_built) - + ---@param event on_player_mined_entity script.on_event(defines.events.on_player_mined_entity, function(event) local entity = event.entity or event.created_entity if not entity or not entity.valid then return end - + if entity.name == "cargo-landing-pad" then destroy_power_source(entity) end end, filter_built) - + ---@param event on_robot_mined_entity script.on_event(defines.events.on_robot_mined_entity, function(event) local entity = event.entity or event.created_entity if not entity or not entity.valid then return end - + if entity.name == "cargo-landing-pad" then destroy_power_source(entity) end -- cgit v1.2.1