From 9e163491a56ff4fb8eadc7dd22142c4ee539f24d Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Mon, 14 Apr 2025 07:56:28 -0700 Subject: Adds README and build/install scripts (linux only) --- control.lua | 308 ------------------------------------------------------------ 1 file changed, 308 deletions(-) delete mode 100644 control.lua (limited to 'control.lua') diff --git a/control.lua b/control.lua deleted file mode 100644 index 27e1190..0000000 --- a/control.lua +++ /dev/null @@ -1,308 +0,0 @@ -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_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 recipe - - if extra_options.recipe then - if not game.recipe_prototypes[extra_options.recipe] then - util.debugprint("recipe " .. extra_options.recipe .. " does not exist") - else - recipe = extra_options.recipe - end - end - - local e = surface.create_entity { - name = entity_name, - position = {center.x + relative_position.x, center.y + relative_position.y}, - direction = defines.direction[extra_options.dir] or defines.direction.north, - force = force, - raise_built = true, - 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 - - return e -end - -function getTableSize(t) - local count = 0 - - for _, _ in pairs(t) do - count = count + 1 - end - - return count -end - -function create_power_source(entity) - local powerInterface = entity.surface.create_entity({ - name = "clp-electric-source", - position = entity.position, - force = entity.force, - 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) - hi.set_heat_setting{temperature = 31, mode = "at-least"} - storage.heat_intefaces[entity.unit_number] = {hi,hp} - end - - storage.power_interfaces[entity.unit_number] = powerInterface -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 - }) - heatInterface[2].destroy({ - raise_destroy = false - }) - storage.heat_intefaces[entity.unit_number] = nil - end -end - -local function clear_area(area, surface) - for _, entity in pairs(surface.find_entities_filtered({ area = area, invert = true })) do - if (entity.valid) then - entity.destroy({ - do_cliff_correction = false, - raise_destroy = false - }) - end - end - - return true -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 - do return end - end - - local content = inventory.get_contents() - - 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 - inventory.remove({name="cargo-landing-pad",count=1}) - content = inventory.get_contents() - inventory.clear() - local position = event.entity.position - local surface = event.entity.surface - local force = event.entity.force - local area = {{position.x - 5, position.y - 5}, {position.x + 5, position.y + 5}} - local chart = {{position.x - 50, position.y - 50}, {position.x + 50, position.y + 50}} - event.entity.destroy() - 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 - 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) - end -end - -local function updateInventory() - if not modEnabled then - return - end - - for _, pl in pairs(game.players) do - local player = game.get_player(pl.name) - local inventory = player.get_main_inventory() - inventory.clear() - end -end - -local function on_player_created(event) - -- 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") - - local player = game.get_player(event.player_index) - local character = player.character - - local group = player.permission_group or game.permissions.create_group("NO_INVENTORY") - group.set_allows_action(defines.input_action.craft,false) - --group.set_allows_action(defines.input_action.destroy_item,false) - --group.set_allows_action(defines.input_action.destroy_opened_item,false) - group.set_allows_action(defines.input_action.drop_item,false) - group.set_allows_action(defines.input_action.inventory_transfer,false) - group.set_allows_action(defines.input_action.inventory_split,false) - group.set_allows_action(defines.input_action.cursor_transfer,false) - group.set_allows_action(defines.input_action.cursor_split,false) - group.set_allows_action(defines.input_action.fast_entity_split,false) - group.set_allows_action(defines.input_action.fast_entity_transfer,false) - group.set_allows_action(defines.input_action.stack_split,false) - group.set_allows_action(defines.input_action.stack_transfer,false) - --group.set_allows_action(defines.input_action.use_item,false) - group.set_allows_action(defines.input_action.begin_mining,false) - group.set_allows_action(defines.input_action.begin_mining_terrain,false) - --group.set_allows_action(defines.input_action.smart_pipette,false) - group.name = "NO_INVENTORY" - group.add_player(player) - --player.print(player.permission_group.allows_action(defines.input_action.inventory_transfer)) - - --player.get_main_inventory().resize(0) - - local center = player.character.position - player.character = nil - - if character then - character.destroy() - end - - -- our settings - local disable_crashsite = true - local skip_cutscene = true - - -- add a crash site - local surface = player.surface - -- surface.daytime = 0.7 - crash_site.create_crash_site(surface, {-20, -13}, util.copy(crashed_ship_items), util.copy(crashed_debris_items)) - util.remove_safe(player, crashed_ship_items) - util.remove_safe(player, crashed_debris_items) - -- player.get_main_inventory().sort_and_merge() - - updateInventory() - local area = {{center.x + 10, center.y + 15}, {center.x - 10, center.y - 15}} - clear_area(area, surface) - create_roboport(center, surface, player) -end - -script.on_init(function () - if not remote.interfaces.freeplay then - modEnabled = false - return - end - - remote.call("freeplay", "set_disable_crashsite", true) - script.on_event(defines.events.on_player_created, on_player_created) - - script.on_configuration_changed(updateInventory) -end) -- cgit v1.2.1