aboutsummaryrefslogtreecommitdiff
path: root/advtrains_line_automation/line_functions.lua
diff options
context:
space:
mode:
authororwell <orwell@bleipb.de>2025-07-21 22:46:06 +0200
committerorwell <orwell@bleipb.de>2025-07-21 22:46:06 +0200
commit615631529ebfe934a66e0a0c57437a89b5d5d2df (patch)
tree55428348c6dae533a66bed08e8e1095a6ff3b2a2 /advtrains_line_automation/line_functions.lua
parent97e5554e34cfaa80716969eebee6577e4c4da000 (diff)
Linevars: Start timetable explicitly via stoprail departure mode, decouple from train line/RC
Diffstat (limited to 'advtrains_line_automation/line_functions.lua')
-rw-r--r--advtrains_line_automation/line_functions.lua93
1 files changed, 35 insertions, 58 deletions
diff --git a/advtrains_line_automation/line_functions.lua b/advtrains_line_automation/line_functions.lua
index 3a369f7..a3be879 100644
--- a/advtrains_line_automation/line_functions.lua
+++ b/advtrains_line_automation/line_functions.lua
@@ -122,16 +122,21 @@ end
--[[
Používá se na *nelinkový* vlak stojící na *neanonymní* zastávce.
Zahájí jízdu na lince nalezené podle kombinace line/stn/rc, nebo vrátí false.
+ chg orwell: added linevar parameter, linevar no longer derived from the line/rc/stn
]]
-local function line_start(train, stn, departure_rwtime)
+local function line_start(train, stn, departure_rwtime, linevar)
+ if not linevar then
+ return false
+ end
assert(train)
assert(stn and stn ~= "")
assert(departure_rwtime)
local ls = al.get_line_status(train)
if ls.linevar ~= nil then
- error("line_start() used on a train that is already on a line: "..dump2({train = train}))
+ -- chg orwell: no longer error here, instead cancel previous linevar
+ al.cancel_linevar(train)
end
- local linevar, linevar_def = al.try_get_linevar(train.line, stn, train.routingcode)
+ local linevar_def = al.try_get_linevar_def(linevar, stn)
if linevar == nil or linevar_def.disabled then
return false
end
@@ -162,11 +167,6 @@ local function should_stop(pos, stdata, train)
if stdata == nil or stdata.stn == nil then
return nil -- neplatná data
end
- local n_trainparts = #assert(train.trainparts)
- -- vyhovuje počet vagonů?
- if not ((stdata.minparts or 0) <= n_trainparts and n_trainparts <= (stdata.maxparts or 128)) then
- return nil
- end
local stn = assert(stdata.stn) -- zastávka stále může být anonymní
local ls, linevar_def = al.get_line_status(train)
local next_index
@@ -194,6 +194,7 @@ local function should_stop(pos, stdata, train)
return "true"
-- TODO: zastávky na znamení
else
+ -- train not on a timetable
local ars = stdata.ars
-- vyhovuje vlak ARS pravidlům?
local result = ars and (ars.default or advtrains.interlocking.ars_check_rule_match(ars, train))
@@ -218,7 +219,7 @@ end
Pokud vlak jede na lince, odebere ho z této linky a vrátí true; jinak vrátí false.
]]
function al.cancel_linevar(train)
- local ls = train.line_status
+ local ls = train.line_status
if ls == nil or ls.linevar == nil then return false end
ls.linevar = nil
ls.linevar_station = nil
@@ -523,40 +524,24 @@ local is_visible_mode = al.is_visible_mode
-- nil, nil
-- Je-li linevar_station == nil, doplní se z linevar. Je-li linevar == nil, vrátí nil, nil.
function al.try_get_linevar_def(linevar, linevar_station)
- if linevar == nil then
+ if linevar == nil then
return nil, nil
end
if linevar_station == nil then
local line
line, linevar_station = al.linevar_decompose(linevar)
- if line == nil then
+ if line == nil then
return nil, nil
end
end
local t = advtrains.lines.stations[linevar_station]
if t ~= nil then
t = t.linevars
- if t ~= nil then
+ if t ~= nil then
return t[linevar], linevar_station
end
end
- return nil, nil
-end
-
---[[
- Vrací:
- a) nil, nil, pokud daná kombinace line/stn/rc nemá definovanou variantu linky
- b) linevar, linevar_def, pokud má
-]]
-function al.try_get_linevar(line, stn, rc)
- if line ~= nil and line ~= "" and stn ~= nil and stn ~= "" then
- local linevar = line.."/"..stn.."/"..(rc or "")
- local result = al.try_get_linevar_def(linevar, stn)
- if result ~= nil then
- return linevar, result
- end
- end
- return nil, nil
+ return nil, nil
end
--[[
@@ -599,19 +584,11 @@ function al.get_line_status(train)
core.log("warning", "Train "..train.id.." put out of linevar '"..ls.linevar.."', because its index "..ls.linevar_index.." became invalid.")
al.cancel_linevar(train)
linevar_def = nil
- else
- local train_line_prefix = (train.line or "").."/"
- if train_line_prefix ~= ls.linevar:sub(1, train_line_prefix:len()) then
- core.log("warning", "Train "..train.id.." put out of linevar '"..ls.linevar.."', because its line changed to '"..tostring(train.line).."'.")
- al.cancel_linevar(train)
- linevar_def = nil
- end
end
return ls, linevar_def
end
-function al.on_train_approach(pos, train_id, train, index, has local occ = {} local occ_chg = {} local function occget(p) local t = occ[p.y] if not t then occ[p.y] = {} t = occ[p.y] end local s = t t = t[p.x] if not t then s[p.x] = {} t = s[p.x] end return t[p.z] end local function occgetcreate(p) local t = occ[p.y] if not t then occ[p.y] = {} t = occ[p.y] end local s = t t = t[p.x] if not t then s[p.x] = {} t = s[p.x] end s = t t = t[p.z] if not t then s[p.z] = {} t = s[p.z] end return t end function o.set_item(train_id, pos, idx) local t = occgetcreate(pos) assert(idx) local i = 1 while t[i] do if t[i]==train_id and t[i+1]==idx then return end i = i + 2 end t[i] = train_id t[i+1] = idx end function o.clear_all_items(train_id, pos) local t