ARS supports triggering distant signal, other bugfixes

This commit is contained in:
orwell 2024-07-20 18:02:33 +02:00
parent c145e5db74
commit baa50c0392
12 changed files with 87 additions and 48 deletions

View File

@ -48,7 +48,7 @@ local params = {
ZONE_HOLD = 5, -- added on top of ZONE_ROLL
ZONE_VSLOW = 3, -- When speed is <2, still allow accelerating
DST_FACTOR = 1.5,
DST_FACTOR = 3,--1.5,
SHUNT_SPEED_MAX = advtrains.SHUNT_SPEED_MAX,
}

View File

@ -256,7 +256,7 @@ function advtrains.path_get(train, index)
if next_connmap then -- only needs to be done when this track is a turnout (>2 conns)
local origin_conn = train.path_ori_cp[advtrains.encode_pos(adj_pos)]
if origin_conn then
atdebug("Train",train.id,"at",adj_pos,"restoring turnout origin CP",origin_conn,"for path item",index)
--atdebug("Train",train.id,"at",adj_pos,"restoring turnout origin CP",origin_conn,"for path item",index)
mconnid = origin_conn
end
end

View File

@ -288,8 +288,8 @@ minetest.register_craftitem("advtrains:trackworker",{
advtrains.ndb.swap_node(pos, new_node)
end
end,
on_use=function(itemstack, user, pointed_thing)
local name = user:get_player_name()
on_use=function(itemstack, player, pointed_thing)
local name = player:get_player_name()
if not name then
return
end
@ -305,7 +305,7 @@ minetest.register_craftitem("advtrains:trackworker",{
local ndef = minetest.registered_nodes[node.name]
if not ndef.advtrains or not ndef.advtrains.trackworker_next_var then
minetest.chat_send_player(placer:get_player_name(), attrans("This node can't be changed using the trackworker!"))
minetest.chat_send_player(name, attrans("This node can't be changed using the trackworker!"))
return
end
@ -318,7 +318,7 @@ minetest.register_craftitem("advtrains:trackworker",{
if reason then
str = str .. " " .. reason
end
minetest.chat_send_player(placer:get_player_name(), str)
minetest.chat_send_player(name, str)
return
end
end

View File

@ -865,7 +865,7 @@ local function tnc_call_enter_callback(pos, train_id, train, index)
-- check for split points
if mregnode and mregnode.at_conn_map then
-- If this node has >2 conns (and a connmap), remember the connection where we came from to handle split points
atdebug("Train",train_id,"at",pos,"saving turnout origin CP",train.path_cp[index],"for path item",index)
--atdebug("Train",train_id,"at",pos,"saving turnout origin CP",train.path_cp[index],"for path item",index)
train.path_ori_cp[advtrains.encode_pos(pos)] = train.path_cp[index]
end
end
@ -883,7 +883,7 @@ local function tnc_call_leave_callback(pos, train_id, train, index)
-- split points do not matter anymore. clear them
if mregnode and mregnode.at_conn_map then
-- If this node has >2 conns (and a connmap), remember the connection where we came from to handle split points
atdebug("Train",train_id,"at",pos,"removing turnout origin CP for path item",index," because train has left it")
--atdebug("Train",train_id,"at",pos,"removing turnout origin CP for path item",index," because train has left it")
train.path_ori_cp[advtrains.encode_pos(pos)] = nil
end
end
@ -1188,7 +1188,7 @@ function advtrains.invert_train(train_id)
local pos = advtrains.path_get(train, index)
local ok, conns, railheight, connmap = advtrains.get_rail_info_at(pos)
if ok and connmap then
atdebug("Reversing Train",train.id," ori_cp Checks: at",pos,"saving turnout origin CP",train.path_cn[index],"for path item",index)
--atdebug("Reversing Train",train.id," ori_cp Checks: at",pos,"saving turnout origin CP",train.path_cn[index],"for path item",index)
ori_cp_after_flip[advtrains.encode_pos(pos)] = train.path_cn[index]
end
end

View File

@ -64,10 +64,7 @@ advtrains.tnc_register_on_approach(function(pos, id, train, index, has_entered,
-- 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
il.ars_check(sigd, train)
end
il.ars_check(spos, train)
end
--atdebug("trav: ",pos, cn, asp, spos, "travsht=", lzb.travsht)
local lspd

View File

@ -129,9 +129,24 @@ function il.ars_check_rule_match(ars, train)
return nil
end
function advtrains.interlocking.ars_check(sigd, train)
local tcbs = il.db.get_tcbs(sigd)
if not tcbs or not tcbs.routes then return end
function advtrains.interlocking.ars_check(signalpos, train, trig_from_dst)
-- check for distant signal
-- this whole check must be delayed until after the route setting has taken place,
-- because before that the distant signal is yet unknown
if not trig_from_dst then
minetest.after(0.5, function()
-- does signal have dst?
local _, remote = il.signal.get_aspect(signalpos)
if remote then
advtrains.interlocking.ars_check(remote, train, true)
end
end)
end
local sigd = il.db.get_sigd_for_signal(signalpos)
local tcbs = sigd and il.db.get_tcbs(sigd)
-- trigger ARS on this signal
if tcbs and tcbs.routes then
if tcbs.ars_disabled or tcbs.ars_ignore_next then
-- No-ARS mode of signal.
@ -140,6 +155,10 @@ function advtrains.interlocking.ars_check(sigd, train)
tcbs.ars_ignore_next = nil
return
end
if trig_from_dst and tcbs.no_dst_ars_trig then
-- signal not to be triggered from distant
return
end
if tcbs.routeset then
-- ARS is not in effect when a route is already set
@ -154,4 +173,5 @@ function advtrains.interlocking.ars_check(sigd, train)
-- using after here is OK because that gets called on every path recalculation
minetest.after(0, il.route.update_route, sigd, tcbs, rteid, nil)
end
end
end

View File

@ -209,7 +209,7 @@ function advtrains.interlocking.visualize_route(origin, route, context, tmp_lcks
end
-- display locks set by player
for pts, state in pairs(tmp_lcks) do
local pos = minetest.string_to_pos(pts)
local pos = advtrains.decode_pos(pts)
routesprite(context, pos, "fixp"..pts, "at_il_route_lock_edit.png", "Fixed in state '"..state.."' by route "..route.name.." (punch to unfix)",
function() clear_lock(tmp_lcks, pname, pts) end)
end
@ -536,7 +536,7 @@ minetest.register_on_punchnode(function(pos, node, player, pointed_thing)
return
end
if advtrains.is_passive(pos) then
local pts = advtrains.roundfloorpts(pos)
local pts = advtrains.encode_pos(pos)
if rp.tmp_lcks[pts] then
clear_lock(rp.tmp_lcks, pname, pts)
else

View File

@ -92,8 +92,8 @@ function ilrs.set_route(signal, route, try)
end
-- add all from locks, these override the rscache
for lpts,lst in pairs(c_rseg.locks) do
atdebug("Add lock from Routedef:",lp,"->",lst,"overrides",c_locks[lp] or "none")
c_locks[lp] = lst
atdebug("Add lock from Routedef:",lpts,"->",lst,"overrides",c_locks[lpts] or "none")
c_locks[lpts] = lst
end
for lp, state in pairs(c_locks) do

View File

@ -279,7 +279,7 @@ end
function signal.get_aspect(pos)
local aspt = signal.aspects[advtrains.encode_pos(pos)]
local ma,dp = signal.get_aspect_internal(pos, aspt)
return ma, advtrains.decode_pos(dp)
return ma, dp and advtrains.decode_pos(dp)
end
local function cache_mainaspects(ndefat)

View File

@ -645,6 +645,7 @@ function advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte, calle
form = form.."button[0.5,8;2.5,1;smartroute;Smart Route]"
form = form.."button[ 3,8;2.5,1;newroute;New (Manual)]"
form = form..string.format("checkbox[0.5,8.75;ars;Automatic routesetting;%s]", not tcbs.ars_disabled)
form = form..string.format("checkbox[0.5,9.25;dstarstrig;Distant signal triggers ARS;%s]", not tcbs.no_dst_ars_trig)
end
elseif sigd_equal(tcbs.route_origin, sigd) then
-- something has gone wrong: tcbs.routeset should have been set...
@ -669,7 +670,7 @@ end
function advtrains.interlocking.update_player_forms(sigd)
for pname, tsigd in pairs(p_open_sig_form) do
if advtrains.interlocking.sigd_equal(sigd, tsigd) then
advtrains.interlocking.show_signalling_form(sigd, pname, nil)
advtrains.interlocking.show_signalling_form(sigd, pname, nil, true)
end
end
end
@ -761,6 +762,10 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
tcbs.ars_disabled = not minetest.is_yes(fields.ars)
end
if fields.dstarstrig then
tcbs.no_dst_ars_trig = not minetest.is_yes(fields.dstarstrig)
end
if fields.auto then
tcbs.route_auto = true
end

View File

@ -75,7 +75,10 @@ local function setsection(tid, train, ts_id, ts, sigd)
end
-- routes
local tcbs = advtrains.interlocking.db.get_tcbs(sigd)
local tcbs
if sigd then
tcbs = advtrains.interlocking.db.get_tcbs(sigd)
end
-- route setting - clear route state
if ts.route then
@ -90,7 +93,7 @@ local function setsection(tid, train, ts_id, ts, sigd)
end
ts.route = nil
end
if tcbs.signal then
if tcbs and tcbs.signal then
-- Reset route and signal
-- Note that the hit-route case is already handled by cancel_route_from
-- this code only handles signal at entering tcb and also triggers for non-route ts

View File

@ -258,16 +258,16 @@ for _, rtab in ipairs({
-- Vorsignal (NEU!)
for typ, prts in pairs({
-- note: the names are taken from the main signal equivalent so that the same names for the lamp images can be used
slow = {asp = advtrains.interlocking.signal.ASPI_HALT, n = "nextslow", ici=true},
slow = {asp = function(pos) return { dst = 0, shunt = true } end, n = "nextslow", ici=true},
nextslow = {
asp = function(pos)
return { dst = getzs3v(pos) or 6 }
return { dst = getzs3v(pos) or 6, shunt = true }
end,
n = "free"
},
free = {
asp = function(pos)
return { dst = -1 }
return { dst = -1, shunt = true }
end,
n = "slow"
},
@ -399,7 +399,9 @@ for _, rtab in ipairs({
drop = "advtrains_signals_ks:"..prefix.."_"..dtyp.."_0",
inventory_image = inv,
advtrains = {
get_aspect_info = asp
get_aspect_info = asp,
trackworker_next_rot = "advtrains_signals_ks:"..prefix.."_"..typ.."_"..rtab.nextrot,
trackworker_rot_incr_param2 = (rot=="60")
},
on_rightclick = advtrains.interlocking.signal_rc_handler,
can_dig = advtrains.interlocking.signal_can_dig,
@ -506,6 +508,10 @@ for _, rtab in ipairs({
t.mesh = "advtrains_signals_ks_zs_top_smr"..rot..".obj"
t.drop = "advtrains_signals_ks:zs3_off_0"
t.selection_box.fixed[1][5] = 0
t.advtrains = {
trackworker_next_rot = "advtrains_signals_ks:zs3_"..typ.."_"..rtab.nextrot,
trackworker_rot_incr_param2 = (rot=="60")
},
minetest.register_node("advtrains_signals_ks:zs3_"..typ.."_"..rot, t)
--TODO add rotation using trackworker
@ -515,6 +521,10 @@ for _, rtab in ipairs({
t.mesh = "advtrains_signals_ks_zs_bottom_smr"..rot..".obj"
t.drop = "advtrains_signals_ks:zs3v_off_0"
t.tiles[3] = t.tiles[3] .. "^[multiply:yellow"
t.advtrains = {
trackworker_next_rot = "advtrains_signals_ks:zs3v_"..typ.."_"..rtab.nextrot,
trackworker_rot_incr_param2 = (rot=="60")
},
minetest.register_node("advtrains_signals_ks:zs3v_"..typ.."_"..rot, t)
--TODO add rotation using trackworker
end
@ -539,6 +549,10 @@ for _, rtab in ipairs({
not_blocking_trains = 1,
not_in_creative_inventory = (rtab.ici) and 0 or 1,
},
advtrains = {
trackworker_next_rot = "advtrains_signals_ks:mast_mast_"..rtab.nextrot,
trackworker_rot_incr_param2 = (rot=="60")
},
drop = "advtrains_signals_ks:mast_mast_0",
})
--TODO add rotation using trackworker