-
-
Save duizendnegen/e96d91afafaca9a54097a40779ada39e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local ipairs = ipairs | |
function find_access_tag(source,access_tags_hierarchy) | |
for i,v in ipairs(access_tags_hierarchy) do | |
local tag = source:get_value_by_key(v) | |
if tag and tag ~= '' then | |
return tag | |
end | |
end | |
return "" | |
end | |
mainline_speed = 120 | |
electrified_speed = 110 | |
non_electrified_speed = 80 | |
default_speed = 80 | |
service_speed = 50 | |
properties.traffic_signal_penalty = 0 | |
properties.u_turn_penalty = 0 | |
properties.use_turn_restrictions = true | |
properties.continue_straight_at_waypoint = false | |
function way_function(way, result) | |
local railway = way:get_value_by_key("railway") | |
local service = way:get_value_by_key("service") | |
local usage = way:get_value_by_key("usage") | |
local maxspeed = way:get_value_by_key("maxspeed") | |
local electrified = way:get_value_by_key("electrified") | |
-- route only actual railways, no subways or disused pieces | |
if (not railway or railway ~= 'rail') then | |
return | |
end | |
result.forward_mode = mode.train | |
result.backward_mode = mode.train | |
result.type = 1 | |
result.name = 'rail' | |
result.forward_speed = default_speed | |
result.backward_speed = default_speed | |
local maxspeed_as_number = 0 | |
if maxspeed then | |
maxspeed_as_number = tonumber(maxspeed:match("%d*")) | |
if maxspeed_as_number then | |
if string.match(maxspeed, "mph") or string.match(maxspeed, "mp/h") then | |
maxspeed_as_number = (maxspeed_as_number*1609)/1000 | |
end | |
end | |
end | |
if maxspeed_as_number and maxspeed_as_number ~= 0 then | |
result.forward_speed = maxspeed_as_number | |
result.backward_speed = maxspeed_as_number | |
elseif service then | |
result.forward_speed = service_speed | |
result.backward_speed = service_speed | |
elseif (usage and usage == 'main') then | |
result.forward_speed = mainline_speed | |
result.backward_speed = mainline_speed | |
elseif (electrified and electrified == "contact line") then | |
result.forward_speed = electrified_speed | |
result.backward_speed = electrified_speed | |
elseif (electrified and electrified == "no") then | |
result.forward_speed = non_electrified_speed | |
result.backward_speed = non_electrified_speed | |
else | |
result.forward_speed = default_speed | |
result.backward_speed = default_speed | |
end | |
return | |
end | |
function turn_function(angle) | |
return (angle * 2) | |
-- TODO permit angles more leniently in stations | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment