====== Environment-Based Train Information System ======
===== Introduction =====
After the [[digilines]] system was used, a server admin thought it would be nicer to not have ugly blue wires all over the place, so decided to wirelessly transmit signals instead.
The environment system uses the ''S'' table to convey information, which is then formatted locally.
It calculates distance based on Co-ordinates.
===== Explanations =====
Here, the code uses two seperate scripts. This makes the code a lot more bother to setup, but at least it is less bother then using Digilines.
==== Collectors ====
The LuaATC tracks wait for a train to run over them, and check if the distance of the train is less then the previous train (this prevents later trains being registered earlier)
The track extracts information, such as the LuaController's distance from an arbitrary point in the station,the length of the train, or the line.
==== Display ====
The display refreshes every 2 seconds, putting the information with values from the table onto the board. If the information changes, then within 2 seconds the board changes.
The skippingrc is set to the standard on 56i-mtserver, where C stands for "Chronic Skipper", which is a train stoppage class where trains only stop at select interchanges.
===== Code =====
==== LuaATC tracks ====
placeTrack = POS(0,0,0) -- Co-ordinates for the track you are working on
placeStation = POS(0,0,0) -- Co-ordinates for a track of your choice in the station
distance = math.sqrt((placeTrack.x-placeStation.x)^2+(placeTrack.y-placeStation.y)^2+(placeTrack.z-placeStation.z)^2) -- Comment this out if using a different distance calculation and have a raw number
-- distance = xx -- Uncomment this and fill in your number in place of xx if you have a raw number
if event.type == "train" then
if distance < F.tbl.distance then -- Show information for closer trains before further trains
F.tbl = {
distance = distance,
length = train_length(),
line = get_line(),
rc = get_rc(),
}
end
end
==== Displayers ====
channel = "p1" -- Channel of displays for specific platform. Allows station-wide digline systems.
platform = "" -- Platform number
services = "" -- Services for the platform in line names (maybe "IPR, NX2" for Re platform 1 on 56i-mtserver).
skippingrc = "C" -- Put in the RC which means the train skips
interrupt(2) -- Set in environment code.
--[[
{distance = distance, length = length, line = line, rc = rc, skipping = skipping}
Table format for info
Platform 3 - EW services
30 m Away, 6 cars
EW line, RC By
Stopping here
Information shown
]]--
if F.tbl.rc == skippingrc then
stopping = "Skipping Station. Stand back"
else
stopping = "Stopping Here."
end
info = "Platform " .. platform .. " - " .. services .. " services" .. "\n" .. F.tbl.distance .. " m away, " .. F.tbl.length .. " cars" .. "\n" .. F.tbl.line .. " line, " .. F.tbl.rc .. "\n" .. stopping
digiline_send(channel, info)