aboutsummaryrefslogtreecommitdiff
path: root/advtrains_line_automation/init.lua
blob: 2275f4938939a77a6fd55045e255a9889b3ddd34 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
-- Advtrains line automation system

advtrains.lines = {
	-- [station code] = {name=..., owner=...}
	stations = {},
	
	--[[ [new pos hash] = {
		stn = <station code>,
		track = <platform identifier>,
		doors = <door side L,R,C>
		wait = <least wait time>
		reverse = <boolean>
		signal = <position of signal that is the "exit signal" for this platform>
	}]]
	stops = {},
}

if advprofiler then
	advtrains.lines.profiler = advprofiler.new_profiler("advtrains_lines")
else
	advtrains.lines.profiler = {
		count=function() end,
		enter=function() end,
		leave=function() end,
	}
end


local modpath = minetest.get_modpath(minetest.get_current_modname()) .. DIR_DELIM

dofile(modpath.."railwaytime.lua")
dofile(modpath.."scheduler.lua")
dofile(modpath.."stoprail.lua")


function advtrains.lines.load(data)
	if data then
		advtrains.lines.stations = data.stations or {}
		advtrains.lines.stops = data.stops or {}
		advtrains.lines.rwt.set_time(data.rwt_time)
		advtrains.lines.sched.load(data.scheduler_queue)
	end
end

function advtrains.lines.save()
	return {
		stations = advtrains.lines.stations,
		stops = advtrains.lines.stops,
		rwt_time = advtrains.lines.rwt.get_time(),
		scheduler_queue = advtrains.lines.sched.save()
	}
end

function advtrains.lines.step(dtime)
	advtrains.lines.rwt.step(dtime)
	advtrains.lines.sched.run()
end