summaryrefslogtreecommitdiff
path: root/Crossroads/init_code.lua
diff options
context:
space:
mode:
authorautocommitter <autocommitter@linux-forks.de>2024-04-22 14:51:45 +0200
committerautocommitter <autocommitter@linux-forks.de>2024-04-22 14:51:45 +0200
commit0b14726c5539782a60d2f4beaed2cfca74a50f7a (patch)
tree1de6e16c565f7bb9806552fc587d7eac870b6b00 /Crossroads/init_code.lua
downloadluaatc_envs-0b14726c5539782a60d2f4beaed2cfca74a50f7a.tar.gz
luaatc_envs-0b14726c5539782a60d2f4beaed2cfca74a50f7a.tar.bz2
luaatc_envs-0b14726c5539782a60d2f4beaed2cfca74a50f7a.zip
State at 2019-12-13
Diffstat (limited to 'Crossroads/init_code.lua')
-rw-r--r--Crossroads/init_code.lua224
1 files changed, 224 insertions, 0 deletions
diff --git a/Crossroads/init_code.lua b/Crossroads/init_code.lua
new file mode 100644
index 0000000..aa4e66d
--- /dev/null
+++ b/Crossroads/init_code.lua
@@ -0,0 +1,224 @@
+--[[
+This environment has programs that can be separated to three parts:
+I) Common functions
+II) Common variables
+III) ATL/CRT Bronze Line
+]]
+
+-- I) Common Functions
+if S.trains == nil then S.trains = {} end
+
+-- F.dst - Get summer time
+function F.dst()
+ if os.date().isdst then return "CEST" else return "CET" end
+end
+-- F.error - Send error with error code
+function F.error(errorcode)
+ error(F.errlist[errorcode])
+end
+--[[ F.stnbasic - Basis for all station functions:
+(By default, nil is defined as false or "no changes")
+stn = Station Code
+side = Door opening side
+optime = Length of time before train departs
+reverse = Reverse train before departing
+acc = Departure Speed
+out = Change outside text
+reventry = Allow trains to pass from the reverse direction
+predepart = Function to execute before departure
+postdepart = Function to execute after departure
+next = Next stop
+]]
+function F.stnbasic(stn, side, optime, reverse, acc, out, reventry, predepart, postdepart, next,track)
+ if event.train then
+ if atc_arrow then
+ local cmdstr=""
+ if out~=nil then atc_set_text_outside(out) end
+ if stn==nil then atc_set_text_inside("Unknown Station")
+ else atc_set_text_inside(F.stnlist[stn]) end
+ cmdstr="BBWO"..(side or "R")
+ if predepart~=nil then predepart() end
+ S.trains[atc_id] = "P "..stn.." "..(track or "x")
+ cmdstr=cmdstr.."D"..(optime or 15)
+ cmdstr=cmdstr.."OCD2"
+ if reverse then cmdstr=cmdstr.."R" end
+ cmdstr=cmdstr.."S"..(acc or "M")
+ atc_send(cmdstr)
+ interrupt((optime or 15)+2)
+ else
+ if reventry==nil then F.error("wrong_direction")
+ else
+ if not reventry then F.error("wrong_direction") end
+ end
+ end
+ end
+ if event.int then
+ if atc_id ~= nil then
+ if next == nil then atc_set_text_inside("") else atc_set_text_inside("Next stop: "..F.stnlist[next]) end
+ if postdepart~=nil then postdepart() end
+ end
+ end
+end
+
+-- F.hst - preset function for small stations (Haltestelle)
+function F.hst(cur, nxt, side, spd, out, trk)
+ F.stnbasic(cur, side, 10, false, spd, out, true, nil, nil, nxt, trk)
+end
+
+-- F.bhf - preset function for large stations (Bahnhof)
+function F.bhf(cur, nxt, side, spd, out, trk)
+ F.stnbasic(cur, side, 15, false, spd, out, true, nil, nil, nxt, trk)
+end
+
+-- F.kbhf - preset function for termini
+function F.kbhf(cur, nxt, side, spd, out, trk)
+ F.stnbasic(cur, side, 15, true, spd, out, true, nil, nil, nxt, trk)
+end
+
+-- F.timing - station with timing
+function F.timing(d_off, d_int, cur, nxt, side, spd, out, trk, term, pre, post)
+ local timenow = os.time()
+ local timerdy = timenow + 8
+ local wait = d_int - ((timerdy-d_off) % d_int)
+ local waitcorr = math.floor(wait*0.66)
+ F.stnbasic(cur, side, waitcorr, term, spd, out, true, pre, post, nxt, trk)
+end
+
+-- F.brk(direction) - sends ATC B2 command
+function F.brk(dir)
+ if event.type == "train" then
+ if atc_arrow == dir then
+ atc_send("B2S2")
+ end
+ end
+end
+
+--[[ F.eval - similar to the ? : operator in C
+expr = the expression to evaluate
+rettrue = the value to return if expr is true
+retfalse = the value to return if expr is false
+]]
+function F.eval(expr, rettrue, retfalse)
+ if expr then return rettrue else return retfalse end
+end
+
+function F.checkpoint(name,arrow,opp)
+ if event.train then
+ S.trains[atc_id] = "C "..name.." "
+ if atc_arrow then
+ S.trains[atc_id] = S.trains[atc_id]..arrow
+ else
+ S.trains[atc_id] = S.trains[atc_id]..opp
+ end
+ end
+end
+
+--[[ II) Common Variables
+F.stnlist = List of stations
+F.errlist = List of errors
+F.depint = Departure intervals
+]]
+F.stnlist = {
+ cg = "Colored Grasses",
+ clockwise = "Clockwise Route",
+ counterclockwise = "Counterclockwise Route",
+ cras = "Crossroads ARSE7's Shop",
+ crbfost = "Crossroads Station East",
+ crbfsm = "Crossroads Station St. Central",
+ crbfso = "Crossroads Station St. East",
+ crbfsw = "Crossroads Station St. West",
+ crch = "Crossroads City Hall",
+ crchs = "Crossroads City Hall South",
+ crmtrail = "Crossroads Mountain Railway Termius",
+ crnsw = "CR-North Station St. Ferry (W.)",
+ crrathaus = "Crossroads City Hall",
+ crsmacker = "Crossroads Smacker's Station",
+ crwm = "Crossroads-West Mountains",
+ crzn = "Crossroads-Zentrum/Nordstadt",
+ el = "Erstaziland",
+ elchateau = "Chateau d'Erstazi",
+ elgp = "Erstaziland Greener Pastures",
+ elsf = "Erstaziland Salt Factory",
+ evo = "EVO",
+ mushroom = "Mushroom Land",
+ neverbuild = "Neverbuild",
+ nvbcentral = "Neverbuild Central",
+ nvbold = "Neverbuild Old Termius",
+ nvboutskirts = "Neverbuild Outskirts",
+ oc = "Ocean City",
+ occh = "Ocean City, City Hall",
+ occrt = "Ocean City, CRT Office",
+ ocmushroom = "Ocean City, Mushroom Market",
+ ocoutskirts = "Ocean City Outskirts",
+ phwest = "Personhood, West",
+ scc = "Silver Coast Central",
+ scn = "Silver Coast North",
+ scs = "Silver Coast South",
+}
+F.errlist = {
+ ["runaway_train"] = "Runaway train found!",
+ ["train_disappeared"] = "Train has disappeared!",
+ ["unexpected_train"] = "Train is not expected to pass!",
+ ["wrong_direction"] = "Train passed in wrong direction!",
+}
+F.depint = {
+ ["AB"] = 60,
+ ["AG"] = 120,
+ ["CRT1"] = 30,
+}
+
+-- ATL/CRT Bronze Line
+
+-- Colored Grasses
+F.ab_cgw="--:-- "..F.dst()
+F.ab_cge="--:-- "..F.dst()
+
+F.ab_status = "Irregular operation"
+
+F.cg_disp = function()
+ if event.digiline then
+ if event.digiline then if not event.channel=="upd" then return end end
+ local t=os.date()
+ local cg="Colored Grasses\nATL/CRT Bronze Line\n"
+ local str = string.format("%s\n"..F.ab_status.." \n", os.date("%d %b %Y %H:%M %z",os.time()))
+ local abf = os.date("%H:%M %z",os.time()+60)
+ digiline_send("bstg1-1",cg.."<-- Personhood West\n[1] via The Cube")
+ digiline_send("bstg1-2",string.format("%s%27s\n%27s",str,"Crossroads City Hall -->","via Silver Coast [2]"))
+ digiline_send("bstg2-1",cg.."<-- Crossroads City Hall\n[2] via Silver Coast")
+ digiline_send("bstg2-2",string.format("%s%27s\n%27s",str,"Personhood West -->","via The Cube [1]"))
+ digiline_send("bstg3","Scheduled departure (Track\nScheduled departure (Track")
+ digiline_send("bstg4","1): "..abf.."\n2): "..abf)
+ return
+ end
+ return
+end
+
+function F.cg_stn(gleis)
+ if event.train and atc_arrow then
+ if get_line()~="AB" then atc_send("SM") return end
+ atc_send("B0 W OR")
+ local time=os.date()
+ if time.sec>50 then time.sec=time.sec-11 end
+ local m=""
+ if time.min>58 then
+ m = string.format("%s%02d:%02d", m, F.eval(time.hour > 22, time.hour - 24, time.hour) + 1, time.min - 59)
+ else
+ m = string.format("%s%02d:%02d", m, time.hour, time.min + 1)
+ end
+ m = m .. " " .. F.dst()
+ atc_set_text_inside("Colored Grasses\nThis train will depart at: "..m)
+ interrupt(60-time.sec,"depart")
+ if gleis==1 then F.ab_cgw=m
+ else F.ab_cge=m
+ end
+ end
+ if event.int and event.message=="depart" then
+ atc_set_text_inside("")
+ time = os.date()
+ local nxt = string.format("%02d:%02d %s", F.eval(time.min>58, F.eval(time.hour>22, time.hour-23, time.hour+1), time.hour), F.eval(time.min>58, time.min-59, time.min+1), F.dst())
+ atc_send("OC D1 SM")
+ if gleis==1 then F.ab_cgw=nxt
+ else F.ab_cge=nxt
+ end
+ end
+end \ No newline at end of file