summaryrefslogtreecommitdiff
path: root/durt/init_code.lua
diff options
context:
space:
mode:
Diffstat (limited to 'durt/init_code.lua')
-rw-r--r--durt/init_code.lua57
1 files changed, 56 insertions, 1 deletions
diff --git a/durt/init_code.lua b/durt/init_code.lua
index c264a3a..af89c7c 100644
--- a/durt/init_code.lua
+++ b/durt/init_code.lua
@@ -11,4 +11,59 @@ S.M27_tracking = {}
-- -3602,18,-3961 Willow Tunnel <-> Djnc -- -3602.18.-3961 Djnc<->Dcaves
-- -2345,15,-1336 Tanh Depot -- -1986,13,-1699 x2 Foundry entry
-F.M27_tracking = function(id) if not event.train then return end local rc = get_rc() or "" if not rc:match("M27_tracking") then return end S.M27_tracking.last = S.M27_tracking.now S.M27_tracking.now = id end --------------------------------------------------------------------- --defining the functions F.arrive = function(stn_code,dir,line) S.lines[line].monitoring[dir][stn_code] = atc_id atc_send("B0 W O"..S.lines[line].stations[stn_code].doors) atc_set_text_inside("Arrived at:\n"..S.lines[line].stations[stn_code].name.."\n \nNext Station:\n"..S.lines[line].stations[S.lines[line].stations[stn_code].next_station[dir]].name) end F.depart = function(stn_code,dir,line) local pos = stn_code..dir local inside_text = "Next Stop:\n"..S.lines[line].stations[S.lines[line].stations[stn_code].next_station[dir]].name if can_set_route(pos,stn_code.."->"..S.lines[line].stations[stn_code].next_station[dir]) then set_route(pos,stn_code.."->"..S.lines[line].stations[stn_code].next_station[dir]) atc_send("OC SM") S.lines[line].monitoring[dir][stn_code] = nil S.lines[line].monitoring[dir][S.lines[line].stations[stn_code].next_station[dir]] = atc_id else -- Wait another 5s before trying again inside_text = inside_text.."\nWaiting to depart..." interrupt(5, "depart") end atc_set_text_inside(inside_text) end F.set_desto = function(dir, line) atc_set_text_outside("LINE " .. line .."\n---> " .. S.lines[line].stations[S.lines[line].termini[dir]].name) end --------------------------------------------------------------------- --LuaATC track functions F.station = function(stn_code,dir,line) -- temp until all SF LuaAtc tracks are changed------------------------- if line == nil or line == "1" then line = "U21" end --------------------------------------------------------------------- if event.train then F.arrive(stn_code,dir,line) interrupt(10,"depart") elseif event.int and event.msg=="depart" then F.depart(stn_code,dir,line) end end F.terminus = function(stn_code, newdir, line) if event.train then S.lines[line].monitoring[newdir][stn_code] = atc_id atc_send("B0 W R O"..S.lines[line].stations[stn_code].doors) atc_set_text_inside("Arrived at:\n"..S.lines[line].stations[stn_code].name.."\n \nNext Station:\n"..S.lines[line].stations[S.lines[line].stations[stn_code].next_station[newdir]].name) atc_set_text_outside("LINE " .. line .."\n---> " .. S.lines[line].stations[S.lines[line].termini[newdir]].name) interrupt(10, "depart") end if event.int and event.msg == "depart" then F.depart(stn_code, newdir,line) end end \ No newline at end of file
+F.M27_tracking = function(id) if not event.train then return end local rc = get_rc() or "" if not rc:match("M27_tracking") then return end S.M27_tracking.last = S.M27_tracking.now S.M27_tracking.now = id end
+
+--Atlac Yard Operations
+if event.init then
+ local list_of_yards = {
+ ["WOA"] = {}
+ }
+ S.yards = S.yards or list_of_yards
+end
+
+F.yard_road_count = function(yard,section_id,monitoring_light) if not S.yards[yard][section_id] then S.yards[yard][section_id] = {['car_count'] = 0} end local car_count = S.yards[yard][section_id].car_count if event.train then if atc_arrow then --arrow points into section, add to length car_count = car_count + train_length() else -- subtract from car_count = car_count - train_length() end if car_count > 0 then -- light = on setstate(monitoring_light,"on") else car_count = 0 setstate(monitoring_light,"off") end S.yards[yard][section_id].car_count = car_count end end
+
+
+--stats counter from subway/il_timetable
+F.stat=function(line, init)
+--statistics
+-- init
+if init then
+reftrain = atc_id
+a_tbt = 30
+a_tbtmax = 30
+a_rtt = 500
+a_not = 0
+c_not = 0
+c_tbtmax = 0
+time_lt = os.time()
+time_rt=os.time()
+end
+if not a_tbtmax then a_tbtmax = 30 end
+if not c_tbtmax then c_tbtmax = 0 end
+--real code
+if event.train then
+local time = os.time()
+c_not = c_not + 1
+a_tbt = (a_tbt + (time - time_lt)) / 2
+c_tbtmax = math.max(c_tbtmax, (time - time_lt))
+if atc_id == reftrain then
+ a_rtt = (a_rtt*0.2 + (time - time_rt)*0.8)
+ a_not = c_not
+ c_not = 0
+ a_tbtmax = (a_tbtmax + c_tbtmax) / 2
+ c_tbtmax = 0
+end
+ digiline_send("stats", "Stat: "..line..
+ " NoT:"..a_not.."("..c_not..")"..
+ " TbT:"..math.floor(a_tbt).."("..(time-time_lt)..")"..
+ " Tmx:"..math.floor(a_tbtmax).."("..c_tbtmax..")"..
+ " R:"..math.floor(a_rtt).."("..(time - time_rt)..")"
+ )
+time_lt = time
+if atc_id == reftrain then
+ time_rt = time
+end
+end
+end
+ --------------------------------------------------------------------- --defining the functions F.arrive = function(stn_code,dir,line) S.lines[line].monitoring[dir][stn_code] = atc_id atc_send("B0 W O"..S.lines[line].stations[stn_code].doors) atc_set_text_inside("Arrived at:\n"..S.lines[line].stations[stn_code].name.."\n \nNext Station:\n"..S.lines[line].stations[S.lines[line].stations[stn_code].next_station[dir]].name) end F.depart = function(stn_code,dir,line) local pos = stn_code..dir local inside_text = "Next Stop:\n"..S.lines[line].stations[S.lines[line].stations[stn_code].next_station[dir]].name if can_set_route(pos,stn_code.."->"..S.lines[line].stations[stn_code].next_station[dir]) then set_route(pos,stn_code.."->"..S.lines[line].stations[stn_code].next_station[dir]) atc_send("OC SM") S.lines[line].monitoring[dir][stn_code] = nil S.lines[line].monitoring[dir][S.lines[line].stations[stn_code].next_station[dir]] = atc_id else -- Wait another 5s before trying again inside_text = inside_text.."\nWaiting to depart..." interrupt(5, "depart") end atc_set_text_inside(inside_text) end F.set_desto = function(dir, line) atc_set_text_outside("LINE " .. line .."\n---> " .. S.lines[line].stations[S.lines[line].termini[dir]].name) end --------------------------------------------------------------------- --LuaATC track functions F.station = function(stn_code,dir,line) -- temp until all SF LuaAtc tracks are changed------------------------- if line == nil or line == "1" then line = "U21" end --------------------------------------------------------------------- if event.train then F.arrive(stn_code,dir,line) interrupt(10,"depart") elseif event.int and event.msg=="depart" then F.depart(stn_code,dir,line) end end F.terminus = function(stn_code, newdir, line) if event.train then S.lines[line].monitoring[newdir][stn_code] = atc_id atc_send("B0 W R O"..S.lines[line].stations[stn_code].doors) atc_set_text_inside("Arrived at:\n"..S.lines[line].stations[stn_code].name.."\n \nNext Station:\n"..S.lines[line].stations[S.lines[line].stations[stn_code].next_station[newdir]].name) atc_set_text_outside("LINE " .. line .."\n---> " .. S.lines[line].stations[S.lines[line].termini[newdir]].name) interrupt(10, "depart") end if event.int and event.msg == "depart" then F.depart(stn_code, newdir,line) end end \ No newline at end of file