aboutsummaryrefslogtreecommitdiff
path: root/advtrains/passive.lua
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2018-08-16 19:18:03 +0200
committerorwell96 <orwell@bleipb.de>2018-08-16 19:18:03 +0200
commit05cb6090ac9537650a900b64768bf3ed959cebed (patch)
tree11b7e3ab4bb846ab069fc10832b07cb36d6eb6dd /advtrains/passive.lua
parent5fad61e9c981115a183527ffe58a7bbe26fea4e7 (diff)
downloadadvtrains-05cb6090ac9537650a900b64768bf3ed959cebed.tar.gz
advtrains-05cb6090ac9537650a900b64768bf3ed959cebed.tar.bz2
advtrains-05cb6090ac9537650a900b64768bf3ed959cebed.zip
Move passive API to the advtrains core
to remove dependency of interlocking on luaautomation
Diffstat (limited to 'advtrains/passive.lua')
-rw-r--r--advtrains/passive.lua99
1 files changed, 99 insertions, 0 deletions
diff --git a/advtrains/passive.lua b/advtrains/passive.lua
new file mode 100644
index 0000000..07cab42
--- /dev/null
+++ b/advtrains/passive.lua
@@ -0,0 +1,99 @@
+-- passive.lua
+-- API to passive components, as described in passive_api.txt of advtrains_luaautomation
+-- This has been moved to the advtrains core in turn with the interlocking system,
+-- to prevent a dependency on luaautomation.
+
+local deprecation_warned = {}
+
+function advtrains.getstate(parpos, pnode)
+ local pos
+ if atlatc then
+ pos = atlatc.pcnaming.resolve_pos(parpos)
+ else
+ pos = advtrains.round_vector_floor_y(parpos)
+ end
+ if type(pos)~="table" or (not pos.x or not pos.y or not pos.z) then
+ debug.sethook()
+ error("Invalid position supplied to getstate")
+ end
+ 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.getstate then
+ st=ndef.advtrains.getstate
+ elseif ndef and ndef.luaautomation and ndef.luaautomation.getstate then
+ if not deprecation_warned[node.name] then
+ minetest.log("warning", node.name.." uses deprecated definition of ATLATC functions in the 'luaautomation' field. Please move them to the 'advtrains' field!")
+ end
+ st=ndef.luaautomation.getstate
+ else
+ return nil
+ end
+ if type(st)=="function" then
+ return st(pos, node)
+ else
+ return st
+ end
+end
+
+function advtrains.setstate(parpos, newstate, pnode)
+ local pos
+ if atlatc then
+ pos = atlatc.pcnaming.resolve_pos(parpos)
+ else
+ pos = advtrains.round_vector_floor_y(parpos)
+ end
+ if type(pos)~="table" or (not pos.x or not pos.y or not pos.z) then
+ debug.sethook()
+ error("Invalid position supplied to getstate")
+ end
+ 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 then
+ st=ndef.advtrains.setstate
+ elseif ndef and ndef.luaautomation and ndef.luaautomation.setstate then
+ if not deprecation_warned[node.name] then
+ minetest.log("warning", node.name.." uses deprecated definition of ATLATC functions in the 'luaautomation' field. Please move them to the 'advtrains' field!")
+ end
+ st=ndef.luaautomation.setstate
+ else
+ return nil
+ end
+
+ 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
+
+ st(pos, node, newstate)
+ return true
+end
+
+function advtrains.is_passive(parpos, pnode)
+ local pos
+ if atlatc then
+ pos = atlatc.pcnaming.resolve_pos(parpos)
+ else
+ pos = advtrains.round_vector_floor_y(parpos)
+ end
+ if type(pos)~="table" or (not pos.x or not pos.y or not pos.z) then
+ debug.sethook()
+ error("Invalid position supplied to getstate")
+ end
+ local node=pnode or advtrains.ndb.get_node(pos)
+ local ndef=minetest.registered_nodes[node.name]
+ if ndef and ndef.advtrains and ndef.advtrains.getstate then
+ return true
+ elseif ndef and ndef.luaautomation and ndef.luaautomation.getstate then
+ if not deprecation_warned[node.name] then
+ minetest.log("warning", node.name.." uses deprecated definition of ATLATC functions in the 'luaautomation' field. Please move them to the 'advtrains' field!")
+ end
+ return true
+ else
+ return false
+ end
+end