From ec68eaa22975305af3e184bc3c946a253b5504eb Mon Sep 17 00:00:00 2001 From: orwell96 Date: Thu, 29 Nov 2018 17:52:56 +0100 Subject: 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 0000000..b6629cf Binary files /dev/null and b/advtrains_line_automation/textures/advtrains_dtrack_shared_stop.png differ 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 0000000..0d1c769 Binary files /dev/null and b/advtrains_line_automation/textures/advtrains_dtrack_stop_placer.png differ -- cgit v1.2.3