-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.lua
74 lines (41 loc) · 2.07 KB
/
control.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
-- ##############################################################################
-- # Requirements & variables #
-- ##############################################################################
CONST = require("constants")
Helper = require("luaclasses.Helper").new()
Entity = require("luaclasses.Entity")
Visualizer = require("luaclasses.Visualizer").new()
Graph = require("luaclasses.Graph")
Block = require("luaclasses.Block")
BlockNetwork = require("luaclasses.BlockNetwork")
blockNetworks = {}
-- ##############################################################################
-- # events #
-- ##############################################################################
script.on_event(defines.events.on_tick, function(event)
for _,player in pairs(game.connected_players) do
if player.character and player.get_inventory(defines.inventory.player_armor).get_item_count("TA-Armor") >= 1 then
p = player.position
local area = player.surface.find_entities_filtered{area={{p.x-1, p.y-1}, {p.x+1, p.y+1}}, type=CONST.TYPESLIST}
for _,gameEntity in ipairs(area) do
local entity = Entity.new(gameEntity)
if Helper:IsItemInList(entity.type, CONST.TYPESLIST) then
for _,blockNetwork in ipairs(blockNetworks) do
if blockNetwork:ContainsEntity(entity) then return end
end
if Helper:IsItemInList(entity.type, CONST.TYPESLIST) then
local blockNetwork = BlockNetwork.new()
blockNetwork:Scan(entity)
blockNetwork:Label(Visualizer)
table.insert(blockNetworks, blockNetwork)
end
end
end
end
end
end)
script.on_event(defines.events.on_player_pipette, function(event)
game.write_file("debug.log", "")
Visualizer:Clear()
blockNetworks = {}
end)