-
Notifications
You must be signed in to change notification settings - Fork 0
/
for_reference_create_combinators.lua
343 lines (280 loc) · 7.64 KB
/
for_reference_create_combinators.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
local ic = nil
script.on_init(function()
local old_version, new_version = nil
local new_version_str = game.active_mods[MOD_NAME]
if new_version_str then
new_version = string.format("%02d.%02d.%02d", string.match(new_version_str, "(%d+).(%d+).(%d+)"))
end
ic = global.programmable_combinator
if not ic.queues then
ic.queues = {{},{},{},{},{},{},{},{}}
end
end)
local function make_entity(context, combinator_type)
-- local context =
-- {
-- position = {0,0}
-- ,player = game.players[1]
-- ,force = game.players[1].force
-- }
local prefix = ""
if combinator_type == "d" then -- decider
local c3 = surface.create_entity({
name = prefix.."decider-combinator",
position = context.position,
force = context.force,
})
c3.get_control_behavior().parameters = {parameters={
first_signal = {type="virtual",name="signal-red"}
,constant = 10
,comparator = ">"
,output_signal = {type="virtual",name="signal-blue"}
,copy_count_from_input = false
}}
local c4 = surface.create_entity({
name = prefix.."decider-combinator",
position = context.position,
force = context.force,
})
c4.get_control_behavior().parameters = {parameters={
first_signal = {type="virtual",name="signal-red"}
,constant = 12
,comparator = ">"
,output_signal = {type="virtual",name="signal-yellow"}
,copy_count_from_input = false
}}
elseif combinator_type == "a" then -- arithmetic
local c2 = surface.create_entity({
name = prefix.."arithmetic-combinator",
position = test_positions[2],
force = player.force,
})
c2.get_control_behavior().parameters = {parameters={
first_signal = {type="virtual",name="signal-green"}
-- ,second_signal = {type="virtual",name="signal-green"}
,second_constant = 3
,operation = "+"
,output_signal = {type="virtual",name="signal-red"}
}}
elseif combinator_type == "c" then -- constant
local c1 = surface.create_entity({
name = prefix.."constant-combinator",
position = test_positions[1],
force = player.force,
})
c1.get_control_behavior().parameters = {parameters={{index = 1, signal = {type="virtual",name="signal-green"}, count = 15 }}}
elseif combinator_type == "s" then -- power-switch
end
c1.connect_neighbour({
wire = defines.wire_type.red,
target_entity = c2,
source_circuit_id = 1,
target_circuit_id = 1,
})
c1.connect_neighbour({
wire = defines.wire_type.red,
target_entity = poles[1],
source_circuit_id = 1,
target_circuit_id = 1,
})
c2.connect_neighbour({
wire = defines.wire_type.red,
target_entity = c3,
source_circuit_id = 2,
target_circuit_id = 1,
})
c2.connect_neighbour({
wire = defines.wire_type.red,
target_entity = poles[2],
source_circuit_id = 2,
target_circuit_id = 1,
})
c3.connect_neighbour({
wire = defines.wire_type.red,
target_entity = poles[3],
source_circuit_id = 2,
target_circuit_id = 1,
})
c2.connect_neighbour({
wire = defines.wire_type.green,
target_entity = c4,
source_circuit_id = 2,
target_circuit_id = 1,
})
c4.connect_neighbour({
wire = defines.wire_type.red,
target_entity = poles[4],
source_circuit_id = 2,
target_circuit_id = 1,
})
end
function lo_assert(condition)
if not condition then
game.players[1].print("Assertion failed!")
end
end
function on_tick_handler(event)
local surface = game.surfaces.nauvis
local player = game.players[1]
local entities = surface.find_entities({{-100, -100},{100, 100}} )
for _,entity in pairs(entities) do
if entity.name == "medium-electric-pole" then
return
end
end
for _,entity in pairs(entities) do
if not(entity.name == "player") then
player.print("entity.name="..entity.name)
entity.destroy()
end
end
player.print("Creating test")
surface.create_entity({
name = "solar-panel",
position = {-3,0},
force = player.force,
})
local poles = {
surface.create_entity({
name = "medium-electric-pole",
position = {0,0},
force = player.force,
}),
surface.create_entity({
name = "medium-electric-pole",
position = {3,0},
force = player.force,
}),
surface.create_entity({
name = "medium-electric-pole",
position = {6,0},
force = player.force,
}),
surface.create_entity({
name = "medium-electric-pole",
position = {9,0},
force = player.force,
}),
surface.create_entity({
name = "medium-electric-pole",
position = {0,8},
force = player.force,
}),
surface.create_entity({
name = "medium-electric-pole",
position = {3,8},
force = player.force,
}),
surface.create_entity({
name = "medium-electric-pole",
position = {6,8},
force = player.force,
}),
surface.create_entity({
name = "medium-electric-pole",
position = {9,8},
force = player.force,
}),
}
local test_positions = {{0,2},{3,2},{6,2},{9,2}}
local prefix = ""
local do_test = 0
if do_test then
prefix = "invisible-"
test_positions = {{3,2},{3,2},{3,2},{3,2}}
end
local c1 = surface.create_entity({
name = test_prefix.."constant-combinator",
position = test_positions[1],
force = player.force,
})
c1.get_control_behavior().parameters = {parameters={{index = 1, signal = {type="virtual",name="signal-green"}, count = 15 }}}
local c2 = surface.create_entity({
name = test_prefix.."arithmetic-combinator",
position = test_positions[2],
force = player.force,
})
c2.get_control_behavior().parameters = {parameters={
first_signal = {type="virtual",name="signal-green"}
-- ,second_signal = {type="virtual",name="signal-green"}
,second_constant = 3
,operation = "+"
,output_signal = {type="virtual",name="signal-red"}
}}
local c3 = surface.create_entity({
name = test_prefix.."decider-combinator",
position = test_positions[3],
force = player.force,
})
c3.get_control_behavior().parameters = {parameters={
first_signal = {type="virtual",name="signal-red"}
,constant = 10
,comparator = ">"
,output_signal = {type="virtual",name="signal-blue"}
,copy_count_from_input = false
}}
local c4 = surface.create_entity({
name = test_prefix.."decider-combinator",
position = test_positions[4],
force = player.force,
})
c4.get_control_behavior().parameters = {parameters={
first_signal = {type="virtual",name="signal-red"}
,constant = 12
,comparator = ">"
,output_signal = {type="virtual",name="signal-yellow"}
,copy_count_from_input = false
}}
c1.connect_neighbour({
wire = defines.wire_type.red,
target_entity = c2,
source_circuit_id = 1,
target_circuit_id = 1,
})
c1.connect_neighbour({
wire = defines.wire_type.red,
target_entity = poles[1],
source_circuit_id = 1,
target_circuit_id = 1,
})
c2.connect_neighbour({
wire = defines.wire_type.red,
target_entity = c3,
source_circuit_id = 2,
target_circuit_id = 1,
})
c2.connect_neighbour({
wire = defines.wire_type.red,
target_entity = poles[2],
source_circuit_id = 2,
target_circuit_id = 1,
})
c3.connect_neighbour({
wire = defines.wire_type.red,
target_entity = poles[3],
source_circuit_id = 2,
target_circuit_id = 1,
})
c2.connect_neighbour({
wire = defines.wire_type.green,
target_entity = c4,
source_circuit_id = 2,
target_circuit_id = 1,
})
c4.connect_neighbour({
wire = defines.wire_type.red,
target_entity = poles[4],
source_circuit_id = 2,
target_circuit_id = 1,
})
end
local function enter_editor()
-- Create a surface
-- Teleport player there
-- Save inventory, quickbar, weapon and tools
-- Clean inventory, quickbar, weapon and tools
-- Generate inventory
end
local function exit_editor()
end
script.on_event(defines.events.on_tick, on_tick_handler) --subscribe ticker when train stops exist