aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2021-03-02 19:51:56 +0100
committerorwell96 <orwell@bleipb.de>2021-03-02 19:51:56 +0100
commit6135f8a23b4f507870dab481f4db466e6be0ac7d (patch)
tree29ea2d7912bba4e08c0dcc1c6da85712b45a2962
parentdb9e4429d789b5217a969de34ecd429c385c380b (diff)
downloadadvtrains-6135f8a23b4f507870dab481f4db466e6be0ac7d.tar.gz
advtrains-6135f8a23b4f507870dab481f4db466e6be0ac7d.tar.bz2
advtrains-6135f8a23b4f507870dab481f4db466e6be0ac7d.zip
LuaATC: add sending atc command to train by ID, and getters for in/out text (solves #124 and #166)
-rw-r--r--advtrains_luaautomation/README.md6
-rw-r--r--advtrains_luaautomation/atc_rail.lua8
-rw-r--r--advtrains_luaautomation/environment.lua11
3 files changed, 25 insertions, 0 deletions
diff --git a/advtrains_luaautomation/README.md b/advtrains_luaautomation/README.md
index 5232c22..683e45c 100644
--- a/advtrains_luaautomation/README.md
+++ b/advtrains_luaautomation/README.md
@@ -93,6 +93,9 @@ Removes any pending interrupts of this node.
Make this active component send a digiline message on the specified channel.
Not available in init code.
+ - `atc_send_to_train(<train_id>, <atc_command>)`
+ Sends the specified ATC command to the train specified by its train id. This happens regardless of where the train is in the world, and can be used to remote-control trains. Returns true on success. If the train ID does not exist, returns false and does nothing. See [atc_command.txt](../atc_command.txt) for the ATC command syntax.
+
#### Interlocking Route Management Functions
If `advtrains_interlocking` is enabled, the following aditional functions can be used:
@@ -230,6 +233,9 @@ In addition to the above environment functions, the following functions are avai
- `atc_set_text_inside(text)`
Set text shown to train passengers. Pass nil to show no text. `text` must be a string.
+ - `atc_set_text_inside(text) / atc_set_text_outside(text)`
+ Getters for inside/outside text, return nil when no train is there.
+
- `get_line()`
Returns the "Line" property of the train (a string).
This can be used to distinguish between trains of different lines and route them appropriately.
diff --git a/advtrains_luaautomation/atc_rail.lua b/advtrains_luaautomation/atc_rail.lua
index 0dee0a5..2d6efe5 100644
--- a/advtrains_luaautomation/atc_rail.lua
+++ b/advtrains_luaautomation/atc_rail.lua
@@ -151,6 +151,14 @@ function r.fire_event(pos, evtdata, appr_internal)
advtrains.trains[train_id].text_inside=text
return true
end,
+ atc_get_text_outside = function()
+ if not train_id then return false end
+ return advtrains.trains[train_id].text_outside
+ end,
+ atc_get_text_inside = function(text)
+ if not train_id then return false end
+ return advtrains.trains[train_id].text_inside
+ end,
atc_set_lzb_tsr = function(speed)
if not appr_internal then
error("atc_set_lzb_tsr() can only be used during 'approach' events!")
diff --git a/advtrains_luaautomation/environment.lua b/advtrains_luaautomation/environment.lua
index 9ef320c..63aa68d 100644
--- a/advtrains_luaautomation/environment.lua
+++ b/advtrains_luaautomation/environment.lua
@@ -153,6 +153,17 @@ local static_env = {
local pos=atlatc.pcnaming.resolve_pos(parpos)
atlatc.interrupt.add(0, pos, {type="ext_int", ext_int=true, message=imesg})
end,
+ -- sends an atc command to train regardless of where it is in the world
+ atc_send_to_train = function(train_id, command)
+ assertt(command, "string")
+ local train = advtrains.trains[train_id]
+ if train then
+ advtrains.atc.train_set_command(train, command, true)
+ return true
+ else
+ return false
+ end
+ end,
}
-- If interlocking is present, enable route setting functions