aboutsummaryrefslogtreecommitdiff
path: root/advtrains_signals_ks/init.lua
diff options
context:
space:
mode:
authorywang <yw05@forksworld.de>2021-05-30 12:16:09 +0200
committerywang <yw05@forksworld.de>2021-11-05 20:28:38 +0100
commit22994705235dfcdfbdc9966a9ba037d657188b5a (patch)
tree72006d8f6e2569de30b97526ab129d1ce85588dc /advtrains_signals_ks/init.lua
parent8793c8bd48eb37f7807f9f1df942ed7226b934e8 (diff)
downloadadvtrains-22994705235dfcdfbdc9966a9ba037d657188b5a.tar.gz
advtrains-22994705235dfcdfbdc9966a9ba037d657188b5a.tar.bz2
advtrains-22994705235dfcdfbdc9966a9ba037d657188b5a.zip
round speed limit if needed
Diffstat (limited to 'advtrains_signals_ks/init.lua')
-rwxr-xr-xadvtrains_signals_ks/init.lua15
1 files changed, 8 insertions, 7 deletions
diff --git a/advtrains_signals_ks/init.lua b/advtrains_signals_ks/init.lua
index a1f056c..3a2f4d0 100755
--- a/advtrains_signals_ks/init.lua
+++ b/advtrains_signals_ks/init.lua
@@ -4,15 +4,17 @@
-- Note that the group value of advtrains_signal is 2, which means "step 2 of signal capabilities"
-- advtrains_signal=1 is meant for signals that do not implement set_aspect.
-local supported_speed_limits = {
- [4] = true, [6] = true, [8] = true, [12] = true, [16] = true
-}
+local function asp_to_zs3type(asp)
+ local n = tonumber(asp)
+ if not n or n < 4 then return "off" end
+ if n < 8 then return 2*math.floor(n/2) end
+ return math.min(16,4*math.floor(n/4))
+end
local function setzs3(msp, lim, rot)
local pos = {x = msp.x, y = msp.y+1, z = msp.z}
local node = advtrains.ndb.get_node(pos)
- local asp = lim
- if not asp or not supported_speed_limits[lim] then asp = "off" end
+ local asp = asp_to_zs3type(lim)
if node.name:find("^advtrains_signals_ks:zs3_") then
advtrains.ndb.swap_node(pos, {name="advtrains_signals_ks:zs3_"..asp.."_"..rot, param2 = node.param2})
end
@@ -31,8 +33,7 @@ end
local function setzs3v(msp, lim, rot)
local pos = {x = msp.x, y = msp.y-1, z = msp.z}
local node = advtrains.ndb.get_node(pos)
- local asp = lim
- if not asp or not supported_speed_limits[lim] then asp = "off" end
+ local asp = asp_to_zs3type(lim)
if node.name:find("^advtrains_signals_ks:zs3v_") then
advtrains.ndb.swap_node(pos, {name="advtrains_signals_ks:zs3v_"..asp.."_"..rot, param2 = node.param2})
end