summaryrefslogtreecommitdiff
path: root/Crossroads/init_code.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Crossroads/init_code.lua')
-rw-r--r--Crossroads/init_code.lua76
1 files changed, 50 insertions, 26 deletions
diff --git a/Crossroads/init_code.lua b/Crossroads/init_code.lua
index 62840ef..d6fb5f4 100644
--- a/Crossroads/init_code.lua
+++ b/Crossroads/init_code.lua
@@ -7,6 +7,11 @@ function F.dst()
if os.date().isdst then return "CEST" else return "CET" end
end
+function F.pccheck(pos, state)
+ if is_passive(pos) then return true end
+ return (getstate(pos) == state)
+end
+
-- F.error - Send error with error code
function F.error(errorcode)
error(F.errlist[errorcode])
@@ -114,7 +119,6 @@ function F.stn2gen(stn, trk, door, ret, chout)
if not trk then return end
if not door then return end
if door~="L" and door~="R" and door~="C" then return end
- if event.type~="train" then return end
if not atc_arrow then return end
if not F.stndet[stn] then return end
if not F.stndet[stn][trk] then return end
@@ -123,30 +127,46 @@ function F.stn2gen(stn, trk, door, ret, chout)
if #t==0 then return end
local l = get_line()
if (not l) or l==" " then return end
- if (get_rc() or ""):match("FREIGHT") then
+ local rc = get_rc() or ""
+ if rc:match("FREIGHT") then
atc_send (ret and "BBWRSM" or "SM")
return
end
- for i = 1, #t, 1 do
- if t[i][1]==l then
- stop = true
- atc_send("BBWO"..door.."D15OCD1"..(ret and "R" or "").."SM")
- local intext = (F.stnlist[stn] or stn).."\n"..(F.stnlist[t[i][2]] and "Next station: "..F.stnlist[t[i][2]]..(t[i][3] and " (track "..t[i][3]..")" or "") or "End of Line")
- local outtext = string.format("%s (%06d)",F.lines[l].name or l, atc_id)
- if t[i][4] then outtext = outtext.." - "..(F.stnlist[t[i][4]] or t[i][4]) end
- atc_set_text_inside(intext)
- if chout then atc_set_text_outside(outtext) end
- S.trains[atc_id] = {
- v = 2,
- l = (get_line() or ""),
- s = stn,
- t = (trk or "N/A"),
- }
- break
+ if event.type == "train" then
+ for i = 1, #t, 1 do
+ if t[i][1]==l then
+ stop = true
+ atc_send(string.format("BBWO%sD15OCD1%sSM", door, (ret and "R" or "")))
+ local intext_nxt = F.stnlist[t[i][2]] and ("Next station:\n%s\n(Track: %s)"):format(F.stnlist[t[i][2]], t[i][3] or "?") or ""
+ local intext = ("%s\n%s"):format(F.stnlist[stn] or stn, intext_nxt)
+ local outtext = string.format("%s (%06d)",F.lines[l].name or l, atc_id)
+ if t[i][4] then outtext = outtext.." - "..(F.stnlist[t[i][4]] or t[i][4]) end
+ local timenow = os.time()
+ t[i][5] = t[i][5] or (timenow-(F.depint[l] or 300))
+ -- note that the "average" time is weighted
+ t[i][6] = t[i][6] and (t[i][6]+timenow-t[i][5]+30)/2 or (timenow-t[i][5])
+ t[i][5] = timenow
+ atc_set_text_inside(intext)
+ if chout then atc_set_text_outside(outtext) end
+ S.trains[atc_id] = {
+ v = 2,
+ l = (get_line() or ""),
+ s = stn,
+ t = (trk or "N/A"),
+ }
+ schedule_in(15, intext_nxt)
+ break
+ end
+ end
+ if (not stop) then
+ atc_send(ret and "BBWRSM" or "SM")
end
end
- if (not stop) then
- atc_send(ret and "BBWRSM" or "SM")
+ if event.type == "schedule" then
+ if type(event.msg) == "string" then
+ atc_set_text_inside(event.msg)
+ atc_send(ret and "OCD1RSM" or "OCD1SM")
+ end
end
end
@@ -154,7 +174,8 @@ function F.disp2gen(stn)
if not stn then return end
if not F.stndet[stn] then return end
local s = F.stndet[stn]
- local d={{(F.stnlist[stn] or stn).."\nTrack Line\n", os.date("%Y-%m-%d %H:%M %z", os.time()).."\nDestination\n"}}
+ local sn = F.stnlist[stn] or stn
+ local d={{sn.."\nTrack Line\n", (string.sub(sn, 28, 54) or "").." \nDestination\n", " \nEstimated Arrival\n"}}
local c=2
local t={}
for i,_ in pairs(s) do t[#t+1]=i end
@@ -169,6 +190,8 @@ function F.disp2gen(stn)
d[r][1] = d[r][1] .. string.format("%-8s %s\n", tostring(trkname), F.lines[det[1]].name)
d[r][2] = d[r][2] .. (F.lines[det[1]].ring and "Ring Line" or (F.stnlist[det[4]] or det[4] or "")).."\n"
c=c+1
+ local earr = (det[5] or os.time())+(det[6] or F.depint[det[1]] or 600)
+ d[r][3] = d[r][3] .. os.date("%Y-%m-%d %H:%M %Z", earr) .. "\n"
end
end
for i = 1, #d, 1 do
@@ -231,6 +254,7 @@ F.stnlist = {
elgp = "Erstaziland-Greener Pastures",
elsf = "Erstaziland-Salt Factory",
evo = "EVO",
+ grsc = "Grassy Scarp",
mushroom = "Mushroom Land",
neverbuild = "Neverbuild",
nvbcentral = "Neverbuild Central",
@@ -253,14 +277,14 @@ F.lines = {
["AB"] = {
name = "ATL Bronze Line",
ring = false,
- [1] = { {"crch","A1"}, --[[ {"crwm","3"}, ]] {"scs","N"}, {"scc","N"}, {"scn","N"}, {"cg","1"}, {"thecube","4"}, {"phsc","N"}, {"phwest","7"} },
- [2] = { {"phwest","7"}, {"phsc","S"}, {"thecube","1"}, {"cg","2"}, {"scn","S"}, {"scc","S"}, {"scs","S"}, --[[ {"crwm","4"}, ]] {"crch","A1"} },
+ [1] = { {"crch","A1"}, --[[ {"crwm","3"}, ]] {"scs","N2"}, {"scc","N2"}, {"scn","N2"}, {"cg","1"}, {"thecube","4"}, {"phsc","N"}, {"grsc", "4"}, {"phwest","1"} },
+ [2] = { {"phwest","1"}, {"grsc", "3"}, {"phsc","S"}, {"thecube","1"}, {"cg","2"}, {"scn","S2"}, {"scc","S2"}, {"scs","S2"}, --[[ {"crwm","4"}, ]] {"crch","A1"} },
},
["AZ"] = {
name = "ATL Zinc Line",
ring = false,
- [1] = { {"evo","N/A"}, {"scs","N"}, {"scc","N"}, {"scn","N"}, {"oc","N"}, {"elgp","N"}, {"elsf","E"}, {"elchateau","S"} },
- [2] = { {"elchateau","S"}, {"elsf","W"}, {"elgp","S"}, {"oc","S"}, {"scn","S"}, {"scc","S"}, {"scs","S"}, {"evo","N/A"} },
+ [1] = { {"evo","N/A"}, {"scs","N1"}, {"scc","N1"}, {"scn","N1"}, {"oc","N"}, {"elgp","N"}, {"elsf","E"}, {"elchateau","S"} },
+ [2] = { {"elchateau","S"}, {"elsf","W"}, {"elgp","S"}, {"oc","S"}, {"scn","S1"}, {"scc", "S1"}, {"scs","S1"}, {"evo","N/A"} },
},
["CRT1"] = {
name = "CRT 1",
@@ -306,7 +330,7 @@ F.errlist = {
}
F.depint = {
- ["AB"] = 60,
+ ["AB"] = 90,
["AG"] = 120,
["CRT1"] = 30,
}