Unfinished; work on generate_neutrons.

This commit is contained in:
Peter 2018-07-23 20:08:02 +08:00
parent 46dd4a58f1
commit f135b264ef

View File

@ -1,11 +1,20 @@
require "util" require "util"
--[[/////////////////// --[[///////////////////
UNIVERSAL FUNCTIONS 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 --verify state of entity and call the appropriate functions
function entity_placed(event) function entity_placed(event)
@ -22,7 +31,17 @@ function check_cursor_stack(player_index)
local cursor_item = player.cursor_stack local cursor_item = player.cursor_stack
return cursor_item return cursor_item
end 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_built_entity, entity_placed)
script.on_event(defines.events.on_robot_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 end
function make_target(event) function make_target(event)
--change this in order to change the reactor detection range.
local range = 1 local range = 1
local offsets = {{0, range}, {range, 0}, {0, -range}, {-range, 0}} local offsets = {{0, range}, {range, 0}, {0, -range}, {-range, 0}}
local entity = event.created_entity local entity = event.created_entity
local entity_position = entity.position local entity_position = entity.position
for _, offset in pairs(offsets) do for _, offset in pairs(offsets) do
local adj_pos = {x = entity_position.x + offset.x, y = entity_position.y + offset.y} 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) local adjacent_reactor = surface.get_t(adj_pos.x, adj_pos.y)
if adjacent_reactor and adjacent_reactor.name == "nuclear-reactor" then local surface = adjacent_reactor.
--true if adjacent_reactor and adjacent_reactor.type == "reactor" then
game.surfaces[].create_entity()
else else
--false --false
end end
end end
return adjacent_tiles return adjacent_tiles
end end
--neutron target - neutron manager --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) function remove_neutrons(player_index)
script.on_event(defines.events.on_gui_closed, function(event) if event.entity.name == "neutron-target" then neutron_target_gui_open = false end end) local remove_neutrons.player_index = player_index
if neutron_target_gui_open == true then
function remove_neutrons() script.events.on_tick(clear_inv("neutron", player_index))
else
game.players[player_index].print("debug.neutron.gui.closed")
end
end end
script.on_tick(remove_neutrons) 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)