diff --git a/mod/control.lua b/mod/control.lua index 8bab831..5d06650 100644 --- a/mod/control.lua +++ b/mod/control.lua @@ -1,11 +1,20 @@ require "util" - --[[/////////////////// UNIVERSAL FUNCTIONS ///////////////////]] +--compare an item to a table +function contains_item(item, table) + for k, item in ipairs(table) do + if item == table then + return true + else + return false + end + end +end --verify state of entity and call the appropriate functions function entity_placed(event) @@ -22,7 +31,17 @@ function check_cursor_stack(player_index) local cursor_item = player.cursor_stack return cursor_item end + +function add_to_inv(item, entity) +end + +function clear_inv(item.name, player_index) + local player = game.players[player_index] + player.clean_cursor(name) + player.remove_item(name) +end + script.on_event(defines.events.on_built_entity, entity_placed) script.on_event(defines.events.on_robot_built_entity, entity_placed) @@ -41,27 +60,52 @@ function Position.add(pos1, pos2) end function make_target(event) + --change this in order to change the reactor detection range. local range = 1 local offsets = {{0, range}, {range, 0}, {0, -range}, {-range, 0}} local entity = event.created_entity local entity_position = entity.position for _, offset in pairs(offsets) do local adj_pos = {x = entity_position.x + offset.x, y = entity_position.y + offset.y} - local adjacent_reactor = surface.get_tile(adj_pos.x, adj_pos.y) - if adjacent_reactor and adjacent_reactor.name == "nuclear-reactor" then - --true + local adjacent_reactor = surface.get_t(adj_pos.x, adj_pos.y) + local surface = adjacent_reactor. + if adjacent_reactor and adjacent_reactor.type == "reactor" then + game.surfaces[].create_entity() else --false - end + end end return adjacent_tiles end --neutron target - neutron manager -script.on_event(defines.events.on_gui_opened, function(event) if event.entity.name == "neutron-target" then neutron_target_gui_open = true end end) -script.on_event(defines.events.on_gui_closed, function(event) if event.entity.name == "neutron-target" then neutron_target_gui_open = false end end) - -function remove_neutrons() - +function remove_neutrons(player_index) + local remove_neutrons.player_index = player_index + if neutron_target_gui_open == true then + script.events.on_tick(clear_inv("neutron", player_index)) + else + game.players[player_index].print("debug.neutron.gui.closed") + end end script.on_tick(remove_neutrons) + +function generate_neutrons(entity) + +end +script.on_tick(generate_neutrons) + +--gui handler +script.on_event(defines.events.on_gui_opened, function(event) + if event.entity.name == "neutron-target" then + neutron_target_gui_open = true + local player_index = event.player_index + remove_neutrons(player_index) + end +end) + +script.on_event(defines.events.on_gui_closed, function(event) + if event.entity.name == "neutron-target" then + neutron_target_gui_open = false + end +end) +