aboutsummaryrefslogtreecommitdiff
path: root/advtrains_interlocking/tsr_rail.lua
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2019-01-24 13:43:22 +0100
committerorwell96 <orwell@bleipb.de>2019-01-24 13:43:22 +0100
commit2976bae4522a1682808db55473d9f824c7155cc6 (patch)
tree18cbfebbbf2d46a005499f8255b902b7e6c5e3da /advtrains_interlocking/tsr_rail.lua
parent1c3ea960415fcbd63c5f1b2cd8a5b25f79d2879f (diff)
downloadadvtrains-2976bae4522a1682808db55473d9f824c7155cc6.tar.gz
advtrains-2976bae4522a1682808db55473d9f824c7155cc6.tar.bz2
advtrains-2976bae4522a1682808db55473d9f824c7155cc6.zip
Point speed restriction rails
Diffstat (limited to 'advtrains_interlocking/tsr_rail.lua')
-rw-r--r--advtrains_interlocking/tsr_rail.lua54
1 files changed, 54 insertions, 0 deletions
diff --git a/advtrains_interlocking/tsr_rail.lua b/advtrains_interlocking/tsr_rail.lua
new file mode 100644
index 0000000..253298c
--- /dev/null
+++ b/advtrains_interlocking/tsr_rail.lua
@@ -0,0 +1,54 @@
+-- tsr_rail.lua
+-- Point speed restriction rails
+-- Simple rail whose only purpose is to place a TSR on the position, as a temporary solution until the timetable system covers everything.
+
+local function updateform(pos)
+ local meta = minetest.get_meta(pos)
+ local pe = advtrains.encode_pos(pos)
+ local npr = advtrains.interlocking.npr_rails[pe] or 2
+
+ meta:set_string("infotext", "Point speed restriction: "..npr)
+ meta:set_string("formspec", "field[npr;Set point speed restriction:;"..npr.."]")
+end
+
+
+local adefunc = function(def, preset, suffix, rotation)
+ return {
+ after_place_node=function(pos)
+ updateform(pos)
+ end,
+ after_dig_node=function(pos)
+ local pe = advtrains.encode_pos(pos)
+ advtrains.interlocking.npr_rails[pe] = nil
+ end,
+ on_receive_fields = function(pos, formname, fields, player)
+ if fields.npr then
+ local pe = advtrains.encode_pos(pos)
+ advtrains.interlocking.npr_rails[pe] = tonumber(fields.npr)
+ updateform(pos)
+ end
+ end,
+ advtrains = {
+ on_train_approach = function(pos,train_id, train, index)
+ if train.path_cn[index] == 1 then
+ local pe = advtrains.encode_pos(pos)
+ local npr = advtrains.interlocking.npr_rails[pe] or 2
+ advtrains.interlocking.lzb_add_oncoming_npr(train, index, npr)
+ end
+ end,
+ },
+ }
+end
+
+
+
+advtrains.register_tracks("default", {
+ nodename_prefix="advtrains_interlocking:dtrack_npr",
+ texture_prefix="advtrains_dtrack_npr",
+ models_prefix="advtrains_dtrack",
+ models_suffix=".b3d",
+ shared_texture="advtrains_dtrack_shared_npr.png",
+ description="Point Speed Restriction Rail",
+ formats={},
+ get_additional_definiton = adefunc,
+}, advtrains.trackpresets.t_30deg_straightonly)