aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2020-07-07 14:25:47 +0200
committerorwell96 <orwell@bleipb.de>2020-07-07 14:25:47 +0200
commitf33bb563e78a62cc8fb2e1483a6cb9a2436b708a (patch)
treea3690d6dbc6a04c82e4aad78f3fb5d2f90fa533d
parent96236c04dc790cbcd4d8cb52aee5563f54e736aa (diff)
downloadadvtrains-f33bb563e78a62cc8fb2e1483a6cb9a2436b708a.tar.gz
advtrains-f33bb563e78a62cc8fb2e1483a6cb9a2436b708a.tar.bz2
advtrains-f33bb563e78a62cc8fb2e1483a6cb9a2436b708a.zip
Add "Fallback state" for freed routes, move p_mesecon_iface.lua to core
-rw-r--r--advtrains/init.lua4
-rw-r--r--advtrains/p_mesecon_iface.lua (renamed from advtrains_luaautomation/p_mesecon_iface.lua)5
-rw-r--r--advtrains/passive.lua22
-rw-r--r--advtrains/signals.lua1
-rw-r--r--advtrains_interlocking/routesetting.lua1
-rw-r--r--advtrains_luaautomation/init.lua4
6 files changed, 32 insertions, 5 deletions
diff --git a/advtrains/init.lua b/advtrains/init.lua
index 0036037..28e104e 100644
--- a/advtrains/init.lua
+++ b/advtrains/init.lua
@@ -215,6 +215,10 @@ dofile(advtrains.modpath.."/craft_items.lua")
dofile(advtrains.modpath.."/log.lua")
dofile(advtrains.modpath.."/passive.lua")
+if mesecon then
+ dofile(advtrains.modpath.."/p_mesecon_iface.lua")
+end
+
dofile(advtrains.modpath.."/lzb.lua")
diff --git a/advtrains_luaautomation/p_mesecon_iface.lua b/advtrains/p_mesecon_iface.lua
index 95e5d8a..87e1c6d 100644
--- a/advtrains_luaautomation/p_mesecon_iface.lua
+++ b/advtrains/p_mesecon_iface.lua
@@ -16,7 +16,7 @@ minetest.override_item("mesecons_switch:mesecon_switch_off", {
on_updated_from_nodedb = function(pos, node)
mesecon.receptor_off(pos)
end,
- luaautomation = {
+ advtrains = {
getstate = "off",
setstate = function(pos, node, newstate)
if newstate=="on" then
@@ -41,7 +41,7 @@ minetest.override_item("mesecons_switch:mesecon_switch_on", {
on_updated_from_nodedb = function(pos, node)
mesecon.receptor_on(pos)
end,
- luaautomation = {
+ advtrains = {
getstate = "on",
setstate = function(pos, node, newstate)
if newstate=="off" then
@@ -49,5 +49,6 @@ minetest.override_item("mesecons_switch:mesecon_switch_on", {
mesecon.receptor_off(pos)
end
end,
+ fallback_state = "off",
},
})
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
diff --git a/advtrains/signals.lua b/advtrains/signals.lua
index b3dceca..e144aa6 100644
--- a/advtrains/signals.lua
+++ b/advtrains/signals.lua
@@ -302,6 +302,7 @@ minetest.register_node("advtrains:across_on", {
advtrains.ndb.swap_node(pos, {name = "advtrains:across_off", param2 = node.param2}, true)
end
end,
+ fallback_state = "off",
},
on_rightclick=function(pos, node, player)
if advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then
diff --git a/advtrains_interlocking/routesetting.lua b/advtrains_interlocking/routesetting.lua
index 1c9ee5a..575b053 100644
--- a/advtrains_interlocking/routesetting.lua
+++ b/advtrains_interlocking/routesetting.lua
@@ -206,6 +206,7 @@ function ilrs.free_route_locks_indiv(pts, ts, nocallbacks)
-- TODO use luaautomation timers?
if not nocallbacks then
minetest.after(0, ilrs.update_waiting, "lck", pts)
+ minetest.after(0.5, advtrains.set_fallback_state, minetest.string_to_pos(pts))
end
end
-- frees all route locks, even manual ones set with the tool, at a specific position
diff --git a/advtrains_luaautomation/init.lua b/advtrains_luaautomation/init.lua
index 573a553..eca5633 100644
--- a/advtrains_luaautomation/init.lua
+++ b/advtrains_luaautomation/init.lua
@@ -33,9 +33,7 @@ dofile(mp.."/active_common.lua")
dofile(mp.."/atc_rail.lua")
dofile(mp.."/operation_panel.lua")
dofile(mp.."/pcnaming.lua")
-if mesecon then
- dofile(mp.."/p_mesecon_iface.lua")
-end
+
dofile(mp.."/chatcmds.lua")