summaryrefslogtreecommitdiff
path: root/il_timetable/init_code.lua
blob: 919b0071ec5b512b69dac99d2fc59dda2415cb8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-- init code for LW timetable env

-- stop, scheduled departure every
-- d_int: Departure every n seconds (epoch modulo)
-- d_off: Departure time offset
function F.stop_sd(st_name, doors, departcommand, minstoptime, d_int, d_off)
	if event.train then
		local timenow = os.time()
		local timerdy = timenow + minstoptime
		local wait = d_int - ((timerdy-d_off) % d_int)
   local waitcorr = math.floor(wait*0.66)
		digiline_send("monitor", "Departure scheduled for: | "..os.date("%H:%M:%S", timenow+wait))
		atc_send("B0 W O"..doors.." D"..waitcorr.." OCD1"..departcommand)
	else
		local timenow = os.time()
		digiline_send("monitor", "Time: "..os.date("%H:%M:%S", timenow))
	end
end

function F.stop_sd_sched(st_name, doors, departcommand, minstoptime, d_int, d_off)
	if event.train then
   local time_now = rwt.now()
		local next_dep_time = rwt.next_rpt(rwt.add(time_now, minstoptime), d_int, d_off)
		digiline_send("monitor", "Departure scheduled for: | "..rwt.to_string(next_dep_time, true))
   atc_set_text_inside(st_name.."\nDeparture: "..rwt.to_string(next_dep_time, true))
		atc_send("B0 W O"..doors)
    schedule(next_dep_time, "depart")
  elseif event.schedule then
    atc_send("OCD1"..departcommand)
	  digiline_send("monitor", "Last Departure: | "..rwt.to_string(rwt.now(), true))
    atc_set_text_inside("")
	end
end

function F.timedisplay()
digiline_send("time", "Time: | "..rwt.to_string(rwt.now(),true).." | "..os.date("%H:%M:%S"))
schedule(rwt.next_rpt(rwt.now(),5,0), "")
end