aboutsummaryrefslogtreecommitdiff
path: root/control.lua
diff options
context:
space:
mode:
Diffstat (limited to 'control.lua')
-rw-r--r--control.lua421
1 files changed, 421 insertions, 0 deletions
diff --git a/control.lua b/control.lua
new file mode 100644
index 0000000..80affc9
--- /dev/null
+++ b/control.lua
@@ -0,0 +1,421 @@
+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 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")
+ 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,
+ -- type = {"resource"},
+ 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
+
+ --[[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 ()
+ 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()
+ end
+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")
+
+ 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()
+
+ -- 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)
+ 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)
+
+ if(script.active_mods["space-age"]) then
+ local filter_built = {{filter = "name", name = "cargo-landing-pad"}}
+ storage = {
+ power_interfaces = {},
+ heat_intefaces = {}
+ }
+ script.on_event(defines.events.on_marked_for_deconstruction,on_deconstruction,{{filter = "name", name = "cargo-pod-container"}})
+ script.on_event(defines.events.on_space_platform_changed_state, function (event)
+ if(event.platform.state == defines.space_platform_state.waiting_at_station) then
+ local surface = game.get_surface(event.platform.space_location.name)
+ if(surface) then
+ event.platform.force.chart(surface, {{-50, -50}, {50, 50}})
+ 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
+ end, filter_built)
+ 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
+ end, filter_built)
+ 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
+ end, filter_built)
+ end
+end)