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.
This commit is contained in:
parent
01ffee4d58
commit
ec68eaa229
|
@ -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.
|
||||
}
|
||||
})
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
advtrains_interlocking
|
||||
advtrains_train_track
|
|
@ -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
|
|
@ -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
|
|
@ -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)
|
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
Loading…
Reference in New Issue