Disable ARS train flag and surrounding uses

master
orwell96 2019-12-11 12:25:08 +01:00
parent 74a219937d
commit 816245588d
9 changed files with 66 additions and 19 deletions

View File

@ -256,6 +256,11 @@ local matchptn={
end
return 1
end,
["A([01])"]=function(id, train, match)
if not advtrains.interlocking then return 2 end
advtrains.interlocking.ars_set_disable(train, match=="0")
return 2
end,
}
eval_conditional = function(command, arrow, speed)

View File

@ -464,7 +464,8 @@ advtrains.avt_save = function(remove_players_from_wagons)
"trainparts", "recently_collided_with_env",
"atc_brake_target", "atc_wait_finish", "atc_command", "atc_delay", "door_open",
"text_outside", "text_inside", "line", "routingcode",
"il_sections", "speed_restriction", "is_shunt", "points_split", "autocouple"
"il_sections", "speed_restriction", "is_shunt",
"points_split", "autocouple", "ars_disable",
})
--then save it
tmp_trains[id]=v

View File

@ -999,6 +999,9 @@ function wagon:show_bordcom(pname)
end
i=i+1
end
if train.ars_disable then
form = form .. "button[4.5,7;5,1;ilarsenable;Clear 'Disable ARS' flag]"
end
end
minetest.show_formspec(pname, "advtrains_bordcom_"..self.id, form)
@ -1071,18 +1074,23 @@ function wagon:handle_bordcom_fields(pname, formname, fields)
-- Interlocking functionality: If the interlocking module is loaded, you can set the signal aspect
-- from inside the train
if fields.ilrs and advtrains.interlocking and train.lzb and #train.lzb.oncoming > 0 then
local i=1
while train.lzb.oncoming[i] do
local oci = train.lzb.oncoming[i]
if oci.udata and oci.udata.signal_pos then
local sigd = advtrains.interlocking.db.get_sigd_for_signal(oci.udata.signal_pos)
if sigd then
advtrains.interlocking.show_signalling_form(sigd, pname)
return
if advtrains.interlocking then
if fields.ilrs and train.lzb and #train.lzb.oncoming > 0 then
local i=1
while train.lzb.oncoming[i] do
local oci = train.lzb.oncoming[i]
if oci.udata and oci.udata.signal_pos then
local sigd = advtrains.interlocking.db.get_sigd_for_signal(oci.udata.signal_pos)
if sigd then
advtrains.interlocking.show_signalling_form(sigd, pname)
return
end
end
i=i+1
end
i=i+1
end
if fields.ilarsenable then
advtrains.interlocking.ars_set_disable(train, false)
end
end

View File

@ -50,7 +50,13 @@ advtrains.tnc_register_on_approach(function(pos, id, train, index, lzbdata)
local asp, spos = il.db.get_ip_signal_asp(pts, cn)
-- do ARS if needed
if spos then
local ars_enabled = not train.ars_disable
-- Note on ars_disable:
-- Theoretically, the ars_disable flag would need to behave like the speed restriction field: it should be
-- stored in lzbdata and updated once the train drives over. However, for the sake of simplicity, it is simply
-- a value in the train. In this case, this is sufficient because once a train triggers ARS for the first time,
-- resetting the path does not matter to the set route and ARS doesn't need to be called again.
if spos and ars_enabled then
--atdebug(id,"IL Spos (ARS)",spos,asp)
local sigd = il.db.get_sigd_for_signal(spos)
if sigd then
@ -111,3 +117,14 @@ advtrains.tnc_register_on_approach(function(pos, id, train, index, lzbdata)
lzbdata.travspd = travspd
lzbdata.travwspd = travwspd
end)
-- Set the ars_disable flag to the value passed
-- Triggers a path invalidation if set to false
function advtrains.interlocking.ars_set_disable(train, value)
if value then
train.ars_disable = true
else
train.ars_disable = nil
minetest.after(0, advtrains.path_invalidate, train)
end
end

View File

@ -184,6 +184,7 @@ local adefunc = function(def, preset, suffix, rotation)
local stn = advtrains.lines.stations[stdata.stn]
local stnname = stn and stn.name or "Unknown Station"
train.text_inside = "Next Stop:\n"..stnname
advtrains.interlocking.ars_set_disable(train, true)
end
end
end
@ -201,7 +202,7 @@ local adefunc = function(def, preset, suffix, rotation)
local stnname = stn and stn.name or "Unknown Station"
-- Send ATC command and set text
advtrains.atc.train_set_command(train, "B0 W O"..stdata.doors..(stdata.kick and "K" or "").." D"..stdata.wait.." OC "..(stdata.reverse and "R" or "").."D"..(stdata.ddelay or 1) .. "S" ..(stdata.speed or "M"), true)
advtrains.atc.train_set_command(train, "B0 W O"..stdata.doors..(stdata.kick and "K" or "").." D"..stdata.wait.." OC "..(stdata.reverse and "R" or "").."D"..(stdata.ddelay or 1) .. " A1 S" ..(stdata.speed or "M"), true)
train.text_inside = stnname
if tonumber(stdata.wait) then
minetest.after(tonumber(stdata.wait), function() train.text_inside = "" end)

View File

@ -245,6 +245,11 @@ unset_autocouple()
set_shunt(), unset_shunt()
deprecated aliases for set_autocouple() and unset_autocouple(), will be removed from a later release.
-- This additional function is available when advtrains_interlocking is enabled: --
atc_set_disable_ars(true)
Disables (true) or enables (false) the use of ARS for this train. The train will not trigger ARS (automatic route setting) on signals then.
# Approach callbacks
The LuaATC interface provides a way to hook into the approach callback system, which is for example used in the TSR rails (provided by advtrains_interlocking) or the station tracks (provided by advtrains_lines). However, for compatibility reasons, this behavior needs to be explicitly enabled.

View File

@ -153,6 +153,7 @@ function r.fire_event(pos, evtdata, appr_internal)
if not appr_internal then
error("atc_set_lzb_tsr() can only be used during 'approach' events!")
end
assert(tonumber(speed), "Number expected!")
local index = appr_internal.index
advtrains.lzb_add_checkpoint(train, index, speed, nil)
@ -160,6 +161,12 @@ function r.fire_event(pos, evtdata, appr_internal)
return true
end,
}
-- interlocking specific
if advtrains.interlocking then
customfct.atc_set_ars_disable = function(value)
advtrains.interlocking.ars_set_disable(train, value)
end
end
atlatc.active.run_in_env(pos, evtdata, customfct)

View File

@ -7,7 +7,7 @@ Displays
Mesecon Transmitter
Those passive components can also be used inside interlocking systems.
All passive components have a table called 'advtrains' in their node definition and have the group 'save_in_nodedb' set, so they work in unloaded chunks.
All passive components have a table called 'advtrains' in their node definition and have the group 'save_in_at_nodedb' set, so they work in unloaded chunks.
Example for a switch:
advtrains = {
getstate = function(pos, node)

View File

@ -72,12 +72,15 @@ If the train drives in the 'wrong' direction, stop and reverse; independently ac
I<8 S8 ;
If the train is slower than 8, accelerate to 8.
# ATC controller operation modes
static: Only give 1 static command.
# Interlocking
mesecon: Give 2 different commands depending on if the controller is mesecon-powered or not
digiline: Don't give any commands by itself. When a train passes, a digiline message in the form of "[+/-][speed]" is sent on the set channel (where +/- means the same as with conditions). Any digiline message sent to the controller will be interpreted as ATC command and sent to the train.
** the latter two are not yet implemented.
With advtrains_interlocking, there's one more available command:
A0
Disable ARS on the train.
A1
Enable ARS on the train.
When disabled, the train will not trigger automatic route setting on signals based on ARS.
# Persistence
ATC controllers that are configured as 'static' or 'mesecon' are persistent over mapblock unloads and will even command the train when the mapblock is unloaded. This is not possible with digilines since these do not work in unloaded mapchunks.