-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol.lua
164 lines (147 loc) · 4.12 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
--[[function is_table_empty(table)
for _, _ in pairs(table) do
return false
end
return true
end
function script_init()
global.locomotives = {}
end
function entity_added(event) end
function entity_removed(event) end
function generate_alerts(event)
for _, player in pairs(game.connected_players) do
if not is_table_empty(global.locomotives) then
for _, entity in pairs(global.locomotives) do
if entity.valid then
player.add_custom_alert(
entity,
{ type = "virtual", name = "no-path" },
{ "description.no-path" },
true
)
end
end
end
end
end
function generate_alts(event)
if not is_table_empty(global.locomotives) then
for _, entity in pairs(global.locomotives) do
if entity.valid then
rendering.draw_sprite()
end
end
end
end
script.on_init(script_init)
script.on_configuration_changed(script_init)
script.on_event(defines.events.on_train_changed_state)
script.on_event({
defines.events.on_built_entity,
defines.events.on_robot_built_entity,
defines.events.script_raised_built,
defines.events.script_raised_revive,
}, entity_added)
script.on_event({
defines.events.on_entity_died,
defines.events.on_player_mined_entity,
defines.events.on_robot_mined_entity,
defines.events.script_raised_destroy,
}, entity_removed)
script.on_nth_tick(600, generate_alerts)
script.on_nth_tick(100, generate_alts)]]
function is_table_empty(table)
for _, _ in pairs(table) do
return false
end
return true
end
function tick_update()
for _, player in pairs(game.connected_players) do
local trains = player.surface.get_trains()
if not is_table_empty(trains) then
for _, train in pairs(trains) do
if train and train.locomotives then
local front_locomotive = train.front_stock and train.front_stock
or train.locomotives.front_movers[1]
if train.state == defines.train_state.no_path then
if settings.get_player_settings(player)["no-path-alert"].value then
player.add_custom_alert(
front_locomotive,
{ type = "virtual", name = "no-path" },
{ "description.no-path" },
true
)
end
rendering.draw_animation({
animation = "no-path-blinking",
target = front_locomotive,
target_offset = { 0, -0.7 },
surface = player.surface,
time_to_live = 62,
})
elseif train.state == defines.train_state.destination_full then
rendering.draw_sprite({
sprite = "destination-full",
target = front_locomotive,
target_offset = { 0, -0.7 },
surface = player.surface,
time_to_live = 62,
only_in_alt_mode = settings.get_player_settings(player)["destination-full-behind-alt"].value,
})
end
end
end
end
end
--[[for _, surface in pairs(game.surfaces) do
local trains = surface.get_trains()
game.print(game.table_to_json(trains))
if trains then
for _, train in pairs(trains) do
if train and trains.locomotives then
game.print(train.state)
end
end
end
end]]
end
script.on_nth_tick(60, tick_update)
--function script_init()
-- --global.locomotives = {}
--end
--player.add_custom_alert(entity, { type = "fluid", name = "no-path" }, { "description.no-path" }, true)
-- /c game.reload_mods()
--script.on_init(script_init)
--script.on_configuration_changed(script_init)
--[[script.on_event(defines.events.on_train_changed_state, function(event)
local train = event.train
game.print("on_train_changed_state")
if train and train.locomotives then
game.print(train.state)
if train.state == defines.train_state.no_path then
game.print("no path")
for _, player in pairs(game.connected_players) do
player.add_custom_alert(
train.locomotives.front_movers[1],
{ type = "virtual", name = "no-path" },
{ "description.no-path" },
true
)
--[[player.add_custom_alert(
train.locomotives.front_movers[1],
{ type = "fluid", name = "no-path" },
{ "description.no-path" },
true
)
end
elseif train.state == defines.train_state.destination_full then
game.print("d full")
--rendering.draw_sprite("destination-full")
else
game.print("else")
--rendering.destroy()
end
end
end)]]