@@ -180,24 +180,111 @@ end
180
180
-- Signals
181
181
182
182
function mesecon :activate (pos , node , rulename )
183
- local effector = mesecon :get_effector (node .name )
184
- if effector and effector .action_on then
185
- effector .action_on (pos , node , rulename )
183
+ if rulename == nil then
184
+ for _ ,rule in ipairs (mesecon :effector_get_rules (node )) do
185
+ mesecon :activate (pos , node , rule )
186
+ end
187
+ return
188
+ end
189
+ if MESECONS_GLOBALSTEP then
190
+ add_action (pos , " on" , rulename )
191
+ else
192
+ local effector = mesecon :get_effector (node .name )
193
+ if effector and effector .action_on then
194
+ effector .action_on (pos , node , rulename )
195
+ end
186
196
end
187
197
end
188
198
189
199
function mesecon :deactivate (pos , node , rulename )
190
- local effector = mesecon :get_effector (node .name )
191
- if effector and effector .action_off then
192
- effector .action_off (pos , node , rulename )
200
+ if rulename == nil then
201
+ for _ ,rule in ipairs (mesecon :effector_get_rules (node )) do
202
+ mesecon :deactivate (pos , node , rule )
203
+ end
204
+ return
205
+ end
206
+ if MESECONS_GLOBALSTEP then
207
+ add_action (pos , " off" , rulename )
208
+ else
209
+ local effector = mesecon :get_effector (node .name )
210
+ if effector and effector .action_off then
211
+ effector .action_off (pos , node , rulename )
212
+ end
193
213
end
194
214
end
195
215
196
216
function mesecon :changesignal (pos , node , rulename , newstate )
197
- local effector = mesecon :get_effector (node .name )
198
- if effector and effector .action_change then
199
- effector .action_change (pos , node , rulename , newstate )
217
+
218
+ newstate = newstate or " on"
219
+ -- rulename = rulename or mesecon.rules.default
220
+ if rulename == nil then
221
+ for _ ,rule in ipairs (mesecon :effector_get_rules (node )) do
222
+ mesecon :changesignal (pos , node , rule , newstate )
223
+ end
224
+ return
225
+ end
226
+ if MESECONS_GLOBALSTEP then
227
+ add_action (pos , " c" .. newstate , rulename )
228
+ else
229
+ local effector = mesecon :get_effector (node .name )
230
+ if effector and effector .action_change then
231
+ effector .action_change (pos , node , rulename , newstate )
232
+ end
233
+ end
234
+ end
235
+
236
+ function execute_actions (dtime )
237
+ local nactions = mesecon .to_update
238
+ mesecon .to_update = {}
239
+ for _ ,i in ipairs (nactions ) do
240
+ node = minetest .env :get_node (i .pos )
241
+ effector = mesecon :get_effector (node .name )
242
+ if i .action == " on" then
243
+ if effector and effector .action_on then
244
+ effector .action_on (i .pos , node , i .rname )
245
+ end
246
+ elseif i .action == " off" then
247
+ if effector and effector .action_off then
248
+ effector .action_off (i .pos , node , i .rname )
249
+ end
250
+ elseif i .action == " con" then
251
+ if effector and effector .action_change then
252
+ effector .action_change (i .pos , node , i .rname , " on" )
253
+ end
254
+ elseif i .action == " coff" then
255
+ if effector and effector .action_change then
256
+ effector .action_change (i .pos , node , i .rname , " off" )
257
+ end
258
+ end
259
+ end
260
+ local nactions = mesecon .r_to_update
261
+ mesecon .r_to_update = {}
262
+ for _ ,i in ipairs (nactions ) do
263
+ if i .action == " on" then
264
+ mesecon :receptor_on_i (i .pos , i .rules )
265
+ else
266
+ mesecon :receptor_off_i (i .pos ,i .rules )
267
+ end
268
+ end
269
+ end
270
+
271
+ minetest .register_globalstep (execute_actions )
272
+
273
+ function add_action (pos , action , rname )
274
+ for _ ,i in ipairs (mesecon .to_update ) do
275
+ if i .pos .x == pos .x and i .pos .y == pos .y and i .pos .z == pos .z and i .rname .x == rname .x and i .rname .y == rname .y and i .rname .z == rname .z then
276
+ if (i .action == " on" and action == " on" ) or (i .action == " off" and action == " off" ) then
277
+ -- nothing
278
+ elseif i .action == " coff" and action == " on" then i .action = " on"
279
+ elseif i .action == " con" and action == " off" then i .action = " off"
280
+ else
281
+ if action == " on" or action == " con" then i .action = " con" end
282
+ if action == " off" or action == " coff" then i .action = " coff" end
283
+ end
284
+ break
285
+ end
200
286
end
287
+ mesecon .to_update [# mesecon .to_update + 1 ] = {pos = pos , action = action , rname = rname }
201
288
end
202
289
203
290
-- Rules
0 commit comments