-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogistic_network.lua
107 lines (85 loc) · 2.97 KB
/
logistic_network.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
require "util" -- I don't know what it does
require "math2d"
function selected_logistic_network_position(player)
if player.selected == nil then
return nil
end
local logistic_network = player.selected.logistic_network
if logistic_network == nil then
--log_to(player, "no logistic_network")
return nil
end
return player.selected.position
end
function selected_logistic_network(player)
if player.selected == nil then
return nil
end
local logistic_network = player.selected.logistic_network
if logistic_network == nil then
--log_to(player, "no logistic_network")
return nil
end
return logistic_network
end
function logistic_network_covered(player, entity)
if entity == nil then
return nil
end
local surface = entity.surface
if surface == nil then
return nil
end
return surface.find_logistic_network_by_position(entity.position, entity.force)
end
function get_logistic_system_storage(player)
return global.logistic_system_storage
end
function get_logistic_system_total_request(player)
return global.logistic_system_total_request
end
function _get_logistic_system_storage(player, logistic_network)
local contents = {}
for _, storage in pairs(logistic_network.storages) do
--log_to(player, storage.get_output_inventory().get_contents())
if storage.name ~= "logistic-chest-passive-provider" then
for name, amount in pairs(storage.get_output_inventory().get_contents()) do
contents[name] = amount + (contents[name] or 0)
end
end
end
for _, provider in pairs(logistic_network.providers) do
local inventory = provider.get_output_inventory()
if inventory ~= nil then
for name, amount in pairs(inventory.get_contents()) do
contents[name] = amount + (contents[name] or 0)
end
elseif provider.type == "player" then
else
log_to(player, "[ERROR] get_output_inventory() returns nil ("..provider.type..")")
end
end
return contents
end
function _get_logistic_system_total_request(player, logistic_network)
local storage_contents = get_logistic_system_storage(player, logistic_network)
for _, requester in pairs(logistic_network.requesters) do
for i, _ in pairs({[1]=1, [2]=2, [3]=3, [4]=4, [5]=5}) do -- ingredientsは5つまで
local slot = requester.get_request_slot(i)
if slot == nil then
break
end
storage_contents[slot.name] = (storage_contents[slot.name] or 0) - slot.count
end
end
for name, _ in pairs(not_requesting_resources) do
storage_contents[name] = nil
end
return storage_contents
end
function seed_position()
return {x=global.logistic_networks[1].x, y=global.logistic_networks[1].y} -- to copy
end
function seed_logistic_network(player)
return player.surface.find_logistic_network_by_position(seed_position(), player.force)
end