diff options
author | orwell <orwell@bleipb.de> | 2025-01-07 21:54:31 +0100 |
---|---|---|
committer | orwell <orwell@bleipb.de> | 2025-01-07 21:54:31 +0100 |
commit | 38acdbbe1d3a9f2c91ced0281cd58b6c29cff401 (patch) | |
tree | 9b68f376872e4e6a142f01aa783d23b6983af6f3 | |
parent | fed637080a4dcfee889bdfa30ca4744018b92e00 (diff) | |
download | advtrains-38acdbbe1d3a9f2c91ced0281cd58b6c29cff401.tar.gz advtrains-38acdbbe1d3a9f2c91ced0281cd58b6c29cff401.tar.bz2 advtrains-38acdbbe1d3a9f2c91ced0281cd58b6c29cff401.zip |
Change logic for pure distant signals: remain assigned even after train clears TCB (mirror real life behavior)
-rw-r--r-- | advtrains_interlocking/database.lua | 2 | ||||
-rw-r--r-- | advtrains_interlocking/signal_api.lua | 14 | ||||
-rwxr-xr-x | advtrains_signals_ks/init.lua | 12 |
3 files changed, 22 insertions, 6 deletions
diff --git a/advtrains_interlocking/database.lua b/advtrains_interlocking/database.lua index 38b1bc8..077e58a 100644 --- a/advtrains_interlocking/database.lua +++ b/advtrains_interlocking/database.lua @@ -1029,7 +1029,7 @@ function ildb.is_ip_at(pos, purge) if purge then -- is there still a signal assigned to it? for connid, sigpos in pairs(influence_points[pts]) do - local asp = advtrains.interlocking.signal.get_aspect(sigpos) + local asp = advtrains.interlocking.signal.get_aspect_info(sigpos) if not asp then atlog("Clearing orphaned signal influence point", pts, "/", connid) ildb.clear_ip_signal(pts, connid) diff --git a/advtrains_interlocking/signal_api.lua b/advtrains_interlocking/signal_api.lua index a7ef724..ae8f6fa 100644 --- a/advtrains_interlocking/signal_api.lua +++ b/advtrains_interlocking/signal_api.lua @@ -330,7 +330,7 @@ function signal.get_aspect_info(pos) local aspt = signal.aspects[advtrains.encode_pos(pos)] local masp, remote, node, ndef = signal.get_aspect_internal(pos, aspt) -- call into ndef - if ndef.advtrains and ndef.advtrains.get_aspect_info then + if ndef and ndef.advtrains and ndef.advtrains.get_aspect_info then local ai = ndef.advtrains.get_aspect_info if type(ai)=="function" then ai = ai(pos, masp) @@ -390,6 +390,12 @@ end -- function signal.update_route_aspect(tcbs, skip_dst_notify) if tcbs.signal then + if not tcbs.route_aspect and signal.get_signal_cap_level(tcbs.signal) == 2 then + return + -- Special behavior for pure-distant signals assigned to TCBs: retain their last assigned main signal + -- and do not fall back to halt. This mirrors real-life, where the distant signal goes back to + -- expect halt only when the main signal falls into halt + end local asp = tcbs.route_aspect or "_halt" local rem = tcbs.route_remote signal.set_aspect(tcbs.signal, asp, rem, skip_dst_notify) @@ -399,7 +405,7 @@ end -- Returns how capable the signal is with regards to aspect setting -- 0: not a signal at all -- 1: signal has get_aspect_info() but the aspect is not variable (e.g. a sign) --- 2: signal has apply_aspect() but does not have main aspects (e.g. a pure distant signal) +-- 2: signal has apply_aspect() and main aspects but has "pure_distant" flag set (cannot be start/endpoint of a route, special behavior that its route aspect is not cleared on train pass) -- 3: signal has main signal role but can only ever display a halt aspect, such as a bumper (can be endpoint, but not startpoint, of a route) -- 4: Full capabilities, signal has main aspects and can be used as main/shunt signal (can be start/endpoint of a route) function signal.get_signal_cap_level(pos) @@ -407,8 +413,8 @@ function signal.get_signal_cap_level(pos) local ndef = node and minetest.registered_nodes[node.name] local ndefat = ndef and ndef.advtrains if ndefat and ndefat.get_aspect_info then - if ndefat.apply_aspect then - if ndefat.main_aspects then + if ndefat.apply_aspect and ndefat.main_aspects then + if not ndefat.pure_distant then -- if the table contains anything, 4, otherwise 3 for _,_ in pairs(ndefat.main_aspects) do return 4 diff --git a/advtrains_signals_ks/init.lua b/advtrains_signals_ks/init.lua index eb23930..7c78dea 100755 --- a/advtrains_signals_ks/init.lua +++ b/advtrains_signals_ks/init.lua @@ -146,6 +146,15 @@ local applyaspectf_distant = function(rot) end end +-- Main aspects distant signal +-- Only one aspect for "expect free". Whether green or yellow lamp is shown and which speed indicator is determined by remote signal +local mainaspects_dst = { + { + name = "expectclear", + description = "Expect Clear", + }, +} + --Rangiersignal local applyaspectf_ra = function(rot) -- we get here the full main_aspect table @@ -313,10 +322,11 @@ for _, rtab in ipairs({ drop = "advtrains_signals_ks:vs_slow_0", inventory_image = "advtrains_signals_ks_vs_inv.png", advtrains = { - -- no mainaspect + main_aspects = mainaspects_dst, apply_aspect = applyaspectf_distant(rot), get_aspect_info = afunc, route_role = "distant", + pure_distant = true, trackworker_next_rot = "advtrains_signals_ks:vs_"..typ.."_"..rtab.nextrot, trackworker_rot_incr_param2 = (rot=="60") }, |