From f33bb563e78a62cc8fb2e1483a6cb9a2436b708a Mon Sep 17 00:00:00 2001 From: orwell96 Date: Tue, 7 Jul 2020 14:25:47 +0200 Subject: Add "Fallback state" for freed routes, move p_mesecon_iface.lua to core --- advtrains/passive.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'advtrains/passive.lua') diff --git a/advtrains/passive.lua b/advtrains/passive.lua index 07cab42..fe4790c 100644 --- a/advtrains/passive.lua +++ b/advtrains/passive.lua @@ -97,3 +97,25 @@ function advtrains.is_passive(parpos, pnode) return false end end + +-- switches a node back to fallback state, if defined. Doesn't support pcnaming. +function advtrains.set_fallback_state(pos, pnode) + local node=pnode or advtrains.ndb.get_node(pos) + local ndef=minetest.registered_nodes[node.name] + local st + if ndef and ndef.advtrains and ndef.advtrains.setstate + and ndef.advtrains.fallback_state then + if advtrains.get_train_at_pos(pos) then + return false + end + + if advtrains.interlocking and advtrains.interlocking.route.has_route_lock(minetest.pos_to_string(pos)) then + return false + end + + ndef.advtrains.setstate(pos, node, ndef.advtrains.fallback_state) + return true + end + + +end -- cgit v1.2.3