aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--advtrains/api_doc.txt5
-rw-r--r--advtrains/init.lua7
-rw-r--r--advtrains_interlocking/lzb.lua33
-rw-r--r--advtrains_line_automation/depends.txt2
-rw-r--r--advtrains_line_automation/init.lua17
-rw-r--r--advtrains_line_automation/readme.txt5
-rw-r--r--advtrains_line_automation/stoprail.lua39
-rw-r--r--advtrains_line_automation/textures/advtrains_dtrack_shared_stop.pngbin0 -> 3306 bytes
-rw-r--r--advtrains_line_automation/textures/advtrains_dtrack_stop_placer.pngbin0 -> 1238 bytes
9 files changed, 107 insertions, 1 deletions
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 = <boolean> "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
--- /dev/null
+++ b/advtrains_line_automation/textures/advtrains_dtrack_shared_stop.png
Binary files 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
--- /dev/null
+++ b/advtrains_line_automation/textures/advtrains_dtrack_stop_placer.png
Binary files differ