diff options
Diffstat (limited to 'advtrains_interlocking/smartroute.lua')
-rw-r--r-- | advtrains_interlocking/smartroute.lua | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/advtrains_interlocking/smartroute.lua b/advtrains_interlocking/smartroute.lua index f697d7b..6479e44 100644 --- a/advtrains_interlocking/smartroute.lua +++ b/advtrains_interlocking/smartroute.lua @@ -110,7 +110,7 @@ function sr.rescan(pname, sigd, tcbs, find_more_than, searching_shunt, pname) found_routes[#found_routes+1] = { tcbseq = ntcbseq, shunt_route = not is_mainsignal, - name = tcbs.signal_name or atil.sigd_to_string(fsigd) + name = tcbs.signal_name or atil.sigd_to_string(nsigd) } -- if this is a main signal and/or we are only searching shunt routes, stop the search here if is_mainsignal or searching_shunt then @@ -224,7 +224,25 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end -- if only one route present and it is newly created (there was no route before, thus sel_rte==1), make default if sel_rte == 1 and #tcbs.routes == 1 then - tcbs.routes[1].ars = {default=true} + local route1 = tcbs.routes[1] + route1.ars = {default=true} + -- if that only route furthermore is a suitable block signal route (1 section with no locks), set it into block signal mode + if #route1 == 1 then + local ts = tcbs.ts_id and advtrains.interlocking.db.get_ts(tcbs.ts_id) + if ts and #ts.tc_breaks == 2 then + -- check for presence of any locks + local epos1 = advtrains.encode_pos(ts.tc_breaks[1].p) + local epos2 = advtrains.encode_pos(ts.tc_breaks[2].p) + local haslocks = + (route1[1].locks and next(route1[1].locks)) -- the route itself has no locks + or (ts.fixed_locks and next(ts.fixed_locks)) -- the section has no fixedlocks + or (ts.rs_cache and ts.rs_cache[epos1] and ts.rs_cache[epos1][epos2] and next(ts.rs_cache[epos1][epos2])) -- the section has no locks in rscache + if not haslocks then + -- yeah, blocksignal! + route1.default_autoworking = true + end + end + end end atdebug("Smartroute done!") advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte) |