diff options
author | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2020-08-21 15:58:12 +0200 |
---|---|---|
committer | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2020-08-21 15:58:12 +0200 |
commit | b23d346ace0219b1e6c61b85f4a06a90d3a0e962 (patch) | |
tree | e4f6ec40b9a0c999bb42f13e608e89b943381d7a /advtrains_luaautomation | |
parent | 36d8c8b7162b3b6ba6cc0a7f98b0dc295024ecd8 (diff) | |
download | advtrains-b23d346ace0219b1e6c61b85f4a06a90d3a0e962.tar.gz advtrains-b23d346ace0219b1e6c61b85f4a06a90d3a0e962.tar.bz2 advtrains-b23d346ace0219b1e6c61b85f4a06a90d3a0e962.zip |
add maximum length parameter to split_at_fc and split_off_locomotive
Diffstat (limited to 'advtrains_luaautomation')
-rw-r--r-- | advtrains_luaautomation/README.txt | 23 | ||||
-rw-r--r-- | advtrains_luaautomation/atc_rail.lua | 8 |
2 files changed, 24 insertions, 7 deletions
diff --git a/advtrains_luaautomation/README.txt b/advtrains_luaautomation/README.txt index a495a8d..287a0bd 100644 --- a/advtrains_luaautomation/README.txt +++ b/advtrains_luaautomation/README.txt @@ -203,21 +203,38 @@ set_rc(routingcode) split_at_index(index, command) Splits the train at the specified index, into a train with index-1 wagons and a second train starting with the index-th wagon. command specifies an atc command to be sent to the second train after decoupling. -split_at_fc(command) +split_at_fc(command, len) Splits the train in such a way that all cars with non-empty current FC of the first part of the train have the same FC. The command specified is sent to the rear part, as with split_at_index. It returns the fc of the cars of the first part. + The optional argument len specifies the maximum length for the + first part of the train. Say, we have len=3, and the train has "" + "" "foo" "foo" "foo" "bar", then the first train part will be "" + "" "foo". + Example : Train has current FCs "" "" "foo" "bar" "foo" Result: first train: "" "" "foo"; second train: "bar" "foo" The command returns "foo" in this case -split_off_locomotive(command) +split_off_locomotive(command, len) Splits off the locomotives at the front of the train, which are identified by an empty FC. command specifies the command to be executed by the rear half of the train. + + The optional argument len specifies the maximum length for the + first part of the train. Say, we have len=3, and the train has "" + "" "foo" "foo" "foo" "bar", then the first train part will be "" + "" "foo". step_fc() - Steps the FCs of all train cars forward + Steps the FCs of all train cars forward. FCs are composed of codes + separated by exclamation marks (!), for instance + "foo!bar!baz". Each wagon has a current FC, indicating its next + destination. Stepping the freight code forward, selects the next + code after the !. If the end of the string is reached, then the + first code is selected, except if the string ends with a question + mark, then the order is reversed. + train_length() returns the number of cars the train is composed of set_autocouple() diff --git a/advtrains_luaautomation/atc_rail.lua b/advtrains_luaautomation/atc_rail.lua index 758b8f9..6083dfc 100644 --- a/advtrains_luaautomation/atc_rail.lua +++ b/advtrains_luaautomation/atc_rail.lua @@ -66,19 +66,19 @@ function r.fire_event(pos, evtdata) end return false end, - split_at_fc = function(cmd) + split_at_fc = function(cmd, len) assertt(cmd, "string") if not train_id then return false end - local new_id, fc = advtrains.split_train_at_fc(train) + local new_id, fc = advtrains.split_train_at_fc(train, false, len) if new_id then minetest.after(1,advtrains.atc.train_set_command,advtrains.trains[new_id], cmd, atc_arrow) end return fc or "" end, - split_off_locomotive = function(cmd) + split_off_locomotive = function(cmd, len) assertt(cmd, "string") if not train_id then return false end - local new_id, fc = advtrains.split_train_at_fc(train, true) + local new_id, fc = advtrains.split_train_at_fc(train, true, len) if new_id then minetest.after(1,advtrains.atc.train_set_command,advtrains.trains[new_id], cmd, atc_arrow) end |