From ec68eaa22975305af3e184bc3c946a253b5504eb Mon Sep 17 00:00:00 2001 From: orwell96 Date: Thu, 29 Nov 2018 17:52:56 +0100 Subject: [PATCH] Added on_train_approach callback, non-permanent external LZB brakepoints and basis for "stop rails" Stop rails ATM use the aforementioned things to add a pointwise "2" speed restriction. Seems to work. --- advtrains/api_doc.txt | 5 +++ advtrains/init.lua | 7 ++++ advtrains_interlocking/lzb.lua | 33 ++++++++++++++- advtrains_line_automation/depends.txt | 2 + advtrains_line_automation/init.lua | 17 ++++++++ advtrains_line_automation/readme.txt | 5 +++ advtrains_line_automation/stoprail.lua | 39 ++++++++++++++++++ .../textures/advtrains_dtrack_shared_stop.png | Bin 0 -> 3306 bytes .../textures/advtrains_dtrack_stop_placer.png | Bin 0 -> 1238 bytes 9 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 advtrains_line_automation/depends.txt create mode 100644 advtrains_line_automation/init.lua create mode 100644 advtrains_line_automation/readme.txt create mode 100644 advtrains_line_automation/stoprail.lua create mode 100644 advtrains_line_automation/textures/advtrains_dtrack_shared_stop.png create mode 100644 advtrains_line_automation/textures/advtrains_dtrack_stop_placer.png diff --git a/advtrains/api_doc.txt b/advtrains/api_doc.txt index 7bd9c44..d16a611 100644 --- a/advtrains/api_doc.txt +++ b/advtrains/api_doc.txt @@ -178,5 +178,10 @@ minetest.register_node(nodename, { ^- called when a train enters the rail on_train_leave=function(pos, train_id) end ^- called when a train leaves the rail + + -- The following function is only in effect when interlocking is enabled: + on_train_approach = function(pos, train_id, train, index) + ^- called when a train is approaching this position, called exactly once for every path recalculation (which can happen at any time) + ^- This is called so that if the train would start braking now, it would come to halt about(wide approx) 5 nodes before the rail. } }) diff --git a/advtrains/init.lua b/advtrains/init.lua index 9d20722..5d1af41 100644 --- a/advtrains/init.lua +++ b/advtrains/init.lua @@ -194,6 +194,9 @@ dofile(advtrains.modpath.."/passive.lua") --load/save +-- backup variables, used if someone should accidentally delete a sub-mod +local MDS_interlocking + advtrains.fpath=minetest.get_worldpath().."/advtrains" dofile(advtrains.modpath.."/log.lua") @@ -219,6 +222,8 @@ function advtrains.avt_load() advtrains.atc.load_data(tbl.atc) if advtrains.interlocking then advtrains.interlocking.db.load(tbl.interlocking) + else + MDS_interlocking = tbl.interlocking end --remove wagon_save entries that are not part of a train local todel=advtrains.merge_tables(advtrains.wagon_save) @@ -318,6 +323,8 @@ advtrains.avt_save = function(remove_players_from_wagons) local il_save if advtrains.interlocking then il_save = advtrains.interlocking.db.save() + else + il_save = MDS_interlocking end local save_tbl={ trains = tmp_trains, diff --git a/advtrains_interlocking/lzb.lua b/advtrains_interlocking/lzb.lua index 16724c5..1746cc0 100644 --- a/advtrains_interlocking/lzb.lua +++ b/advtrains_interlocking/lzb.lua @@ -1,6 +1,18 @@ -- lzb.lua -- Enforced and/or automatic train override control, obeying signals + +local function approach_callback(parpos, train_id, train, index) + local pos = advtrains.round_vector_floor_y(parpos) + + local node=pnode or advtrains.ndb.get_node(pos) + local ndef=minetest.registered_nodes[node.name] + if ndef and ndef.advtrains and ndef.advtrains.on_train_approach then + ndef.advtrains.on_train_approach(pos, train_id, train, index) + end +end + + --[[ Documentation of train.lzb table train.lzb = { @@ -10,9 +22,13 @@ train.lzb = { travwspd = warning speed res. oncoming = table containing oncoming signals, in order of appearance on the path { - pos = position of the signal (not the IP!) + pos = position of the signal (not the IP!). Can be nil idx = where this is on the path spd = speed allowed to pass (determined dynamically) + npr = "No permanent restriction" If true, this is only a punctual restriction. + speed_restriction is not set then, and train can accelerate after passing point + This is (as of Nov 2017) used by "lines" to brake the train down to 2 when approaching a stop + The actual "stop" command is given when the train passes the rail (on_train_enter callback) } } each step, for every item in "oncoming", we need to determine the location to start braking (+ some safety margin) @@ -67,6 +83,9 @@ local function look_ahead(id, train) spd = 0, }) else + -- run callback, if exists + approach_callback(pos, id, train, trav) + -- check for signal local asp, spos = il.db.get_ip_signal_asp(pts, cn) --atdebug("trav: ",pos, cn, asp, spos, "travsht=", lzb.travsht) @@ -207,6 +226,18 @@ function advtrains.interlocking.lzb_invalidate(train) invalidate(train) end +-- Add an (extra) lzb control point that is not a permanent restriction (see above) +-- (permanent restrictions are only to be imposed by signal ip's) +function advtrains.interlocking.lzb_add_oncoming_npr(train, idx, spd) + local lzb = train.lzb + + table.insert(lzb.oncoming, { + idx = idx, + spd = spd, + npr = true, + }) +end + advtrains.te_register_on_new_path(function(id, train) invalidate(train) diff --git a/advtrains_line_automation/depends.txt b/advtrains_line_automation/depends.txt new file mode 100644 index 0000000..53500ee --- /dev/null +++ b/advtrains_line_automation/depends.txt @@ -0,0 +1,2 @@ +advtrains_interlocking +advtrains_train_track \ No newline at end of file diff --git a/advtrains_line_automation/init.lua b/advtrains_line_automation/init.lua new file mode 100644 index 0000000..5521ee9 --- /dev/null +++ b/advtrains_line_automation/init.lua @@ -0,0 +1,17 @@ +-- Advtrains line automation system + +advtrains.lines = {} + + +local modpath = minetest.get_modpath(minetest.get_current_modname()) .. DIR_DELIM + +dofile(modpath.."stoprail.lua") + + +function advtrains.lines.load(data) + +end + +function advtrains.lines.save() + return {} +end diff --git a/advtrains_line_automation/readme.txt b/advtrains_line_automation/readme.txt new file mode 100644 index 0000000..3280ce9 --- /dev/null +++ b/advtrains_line_automation/readme.txt @@ -0,0 +1,5 @@ +== advtrains_line_automation +This mod provides an extension to the interlocking system which allows to automatically operate trains on train lines. + +This extension makes use of the table +advtrains.lines \ No newline at end of file diff --git a/advtrains_line_automation/stoprail.lua b/advtrains_line_automation/stoprail.lua new file mode 100644 index 0000000..a02e501 --- /dev/null +++ b/advtrains_line_automation/stoprail.lua @@ -0,0 +1,39 @@ +-- stoprail.lua +-- adds "stop rail". Recognized by lzb. (part of behavior is implemented there) + + +local adefunc = function(def, preset, suffix, rotation) + return { + after_place_node=function(pos) + + end, + after_dig_node=function(pos) + + end, + on_receive_fields = function(pos, formname, fields, player) + + end, + advtrains = { + on_train_enter = function(pos, train_id) + end, + on_train_approach = function(pos,train_id, train, index) + atdebug("Train approaches stop:",pos,train_id,index) + --TODO conditions + advtrains.interlocking.lzb_add_oncoming_npr(train, index, 2) + end, + }, + } +end + + + +advtrains.register_tracks("default", { + nodename_prefix="advtrains_line_automation:dtrack_stop", + texture_prefix="advtrains_dtrack_stop", + models_prefix="advtrains_dtrack", + models_suffix=".b3d", + shared_texture="advtrains_dtrack_shared_stop.png", + description="Station/Stop Rail", + formats={}, + get_additional_definiton = adefunc, +}, advtrains.trackpresets.t_30deg_straightonly) diff --git a/advtrains_line_automation/textures/advtrains_dtrack_shared_stop.png b/advtrains_line_automation/textures/advtrains_dtrack_shared_stop.png new file mode 100644 index 0000000000000000000000000000000000000000..b6629cf1a26a5903496e6deca074d9b154fed5ce GIT binary patch literal 3306 zcmZ8jXIN9&*52o&lRzRO2|Xl%1PFxQ1VM}vqy$0@fe?x)O|c-&OB0b%^hyy23l~S2 zK}8VDFk&d9qBCQG5d;JagMw0&j>1L!4t)Ob`+n@T_g;Ig_pJBbYd_EV!Q0DKQ9)e+ z0HEk5;ERwsYh~b3h@BlMTmS%m@9p8YSse`k1Q;-^fq^t}Fbe}X7@&s(Is{;Vg$?j1 z6C7X?VIu-yE1)<;z*PWTA}~`xSttN~C16Z~3>AR|5tt~VOcjA82^f)4W=g}|8gQh6ja1lyhI3Q{8`R)UG~hx* zxl*yt>cB}I#Ydd#gw1MTD-GJH0h~3^ThxJzCfKT`;Hm*_(I9Nn0v_sUz7}xN!Z~Uy z3N&FKHJqmg#!U-s)`qtter>XsCJ<;5eKjC2P3#sOuvrJ?L?^pz15ZsQp%&Pxjdi7i zEp)V>Cdxwx_-mrQwILsESfC3$=}>?c##L9*UyJ0c14KF~HwM_s00IWiOBW8*#)@=^ zZVbF19c*S{ed!o?CM4DYLI&Wol!OdakPgn5PV&>mda!^u69m&C4;IRY3EWuE)5XwaR=|e&`b}NSz#3F_;Nx^z(9}eWthQ)fMFcwa%rz~YDi45Q|=Vyct*QW#qN43hb}~QMRN+ z3yoMCT&x4(&b{B4hr#mKr3ZJ0b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IU)1(r zP!$LLPv_gaq-Kw%c}7a|N~q(h_qD3uI@Zf8M*LNXmXf!E{aOB@JyW&b(i8C$R6X~n zq&@Uo{Y8&!&fZ7T(jeyZGPJwrRu8X6v0ML|zldFoYreHl&p*QJRwcOX3gqy-6Dnhl zkL%t!9_oJO-P3SG)w@K$&XS=Qm7Yfm1G<#$1=}jTr4@}Sj1htHHMkMC_SiUgf7^6U zG;a9ZlwJ|;k)y_M-by34Xwr(eiXTFcca5YtTTHVxZK>u=Gr4op)fv3q+M>u?$ERYb zPZ+Epsry8GLd$u{96Qh6?tRV1CDiJKb`Q`dY)h`^d%1cFxxA|m>2Lw_bbiRco+05DT9;=^Z!V=k$`A6AHo zvK3h;Y;U%5tyU}96wS(`R!%9|PwbeJU(uECZ4NIRNz!IStkcCc zTGA<`N$Ka#8cT*}vwNUvk5`vkmzvonRMtbPd7_2cnV6ij2|ziw!el-jl8Ur13Wikv z$)kDL_1ztjBbRoMC+?VQ&;9umH^o!}r)S4z z>MnddJGw5}dFOxMOmtXTc(moDKxxzU6Mh0S#)Ij=4PUDAN?jsasMYt2TNa<6j`9UV z+cVSGpCLi`K}^SiszFX~^}%s@=3m~Vj%|1VHLx;M50$pGIFC6qcHnl|q@-tyoGF7E-+cIDuoDcB?{mtkfAKdgTX8-^I literal 0 HcmV?d00001 diff --git a/advtrains_line_automation/textures/advtrains_dtrack_stop_placer.png b/advtrains_line_automation/textures/advtrains_dtrack_stop_placer.png new file mode 100644 index 0000000000000000000000000000000000000000..0d1c7694ca19be3f4454eeaec1de847c6f700244 GIT binary patch literal 1238 zcmV;{1S$K8P)p|+(PWvk;>@x+ zqmnFy3pB(iX%kzJqr>B%~9Ea7s6jG8PT>K<#ft_8z2P4&;eWL2e4W#n4g=+*|X;m_&b1y8yhh<7hIXZbyW)d zrQQQ#?w5u6e124}Sp$dTMRav`6zwdMZ2o;FL{W&NG>T8Q?8YY_p9TTJw9f~l(TM8m zDuhB|jDL0r?|m^#?pk2mj&j;$(!!u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