This repository was archived by the owner on Aug 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRailWorks.lua
More file actions
164 lines (117 loc) · 3.96 KB
/
RailWorks.lua
File metadata and controls
164 lines (117 loc) · 3.96 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
-- Library for interfacing with Train Simulator system calls in a Lua-friendly way.
--
-- @include YoRyan/LibRailWorks/Misc.lua
local P = {}
RailWorks = P
--[[
Script Component
]]
function P.BeginUpdate() Call("BeginUpdate") end
function P.EndUpdate() Call("EndUpdate") end
function P.GetSimulationTime() return Call("GetSimulationTime") end
--[[
Rail Vehicle Component
]]
function P.GetIsPlayer() return Call("GetIsPlayer") == 1 end
function P.GetSpeed() return Call("GetSpeed") end
function P.GetAcceleration() return Call("GetAcceleration") end
function P.GetTotalMass() return Call("GetTotalMass") end
function P.GetConsistLength() return Call("GetConsistLength") end
function P.GetRVNumber() return Call("GetRVNumber") end
function P.Engine_SendConsistMessage(message, argument, direction)
return Call("SendConsistMessage", message, tostring(argument), direction) == 1
end
function P.GetNextRestrictiveSignal(...)
return Call("GetNextRestrictiveSignal", unpack(arg))
end
function P.GetNextSpeedLimit(...) return Call("GetNextSpeedLimit", unpack(arg)) end
function P.GetCurrentSpeedLimit(...)
return Call("GetCurrentSpeedLimit", unpack(arg))
end
--[[
Render Component
]]
function P.ActivateNode(name, activate)
Call("ActivateNode", name, Misc.intbool(activate))
end
function P.AddTime(name, time_s) return Call("AddTime", name, time_s) end
function P.SetTime(name, time_s) return Call("SetTime", name, time_s) end
--[[
Control Container
]]
function P.ControlExists(name, index)
return Call("ControlExists", name, index) == 1
end
function P.GetControlValue(name, index)
return Call("GetControlValue", name, index)
end
function P.SetControlValue(name, index, value)
Call("SetControlValue", name, index, value)
end
function P.GetControlMinimum(name, index)
return Call("GetControlMinimum", name, index)
end
function P.GetControlMaximum(name, index)
return Call("GetControlMaximum", name, index)
end
--[[
Engine
]]
function P.GetTractiveEffort() return Call("GetTractiveEffort") end
function P.GetIsEngineWithKey() return Call("GetIsEngineWithKey") == 1 end
function P.SetPowerProportion(index, value)
Call("SetPowerProportion", index, value)
end
--[[
Signal scripting
]]
P.sigmessage = {
RESET_SIGNAL_STATE = 0,
INITIALISE_SIGNAL_TO_BLOCKED = 1,
JUNCTION_STATE_CHANGE = 2,
INITIALISE_TO_PREPARED = 3,
REQUEST_TO_PASS_DANGER = 4,
OCCUPATION_INCREMENT = 10,
OCCUPATION_DECREMENT = 11,
SIGMSG_CUSTOM = 15
}
P.sigstate = {clear = 0, warning = 1, blocked = 2}
P.sigprostate = {green = 0, yellow = 1, dblyellow = 2, red = 3}
-- Contrary to the SDK documentation, signals *can* receive messages from their
-- own links. In addition, this function will only work from OnConsistPass or
-- OnSignalMessage.
function P.SendSignalMessage(message, argument, direction, link, index)
return Call("SendSignalMessage", message, argument, direction, link, index)
end
function P.Signal_SendConsistMessage(message, argument)
if argument == nil then
Call("SendConsistMessage", message)
else
Call("SendConsistMessage", message, argument)
end
end
function P.GetConnectedLink(index)
local link = Call("GetConnectedLink", nil, nil, index)
if link == -1 then
return nil
else
return link
end
end
function P.GetLinkCount() return Call("GetLinkCount") end
function P.Set2DMapSignalState(state) Call("Set2DMapSignalState", state) end
function P.Set2DMapProSignalState(state) Call("Set2DMapProSignalState", state) end
--[[
Undocumented signal functions - see
https://forums.dovetailgames.com/threads/missing-signaling-functions-in-developer-docs.16740/
]]
function P.GetLinkApproachControl(link)
return Call("GetLinkApproachControl", link) == 1
end
function P.GetLinkLimitedToYellow(link)
return Call("GetLinkLimitedToYellow", link) == 1
end
function P.GetLinkFeatherChar(link) return Call("GetLinkFeatherChar", link) end
function P.GetLinkSpeedLimit(link) return Call("GetLinkSpeedLimit", link) end
function P.GetId() return Call("GetId") end
return P