aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2020-08-21 15:58:12 +0200
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2020-08-21 15:58:12 +0200
commitb23d346ace0219b1e6c61b85f4a06a90d3a0e962 (patch)
treee4f6ec40b9a0c999bb42f13e608e89b943381d7a
parent36d8c8b7162b3b6ba6cc0a7f98b0dc295024ecd8 (diff)
downloadadvtrains-b23d346ace0219b1e6c61b85f4a06a90d3a0e962.tar.gz
advtrains-b23d346ace0219b1e6c61b85f4a06a90d3a0e962.tar.bz2
advtrains-b23d346ace0219b1e6c61b85f4a06a90d3a0e962.zip
add maximum length parameter to split_at_fc and split_off_locomotive
-rw-r--r--advtrains/trainlogic.lua7
-rw-r--r--advtrains_luaautomation/README.txt23
-rw-r--r--advtrains_luaautomation/atc_rail.lua8
3 files changed, 30 insertions, 8 deletions
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index c39cc7a..cc34b4f 100644
--- a/advtrains/trainlogic.lua
+++ b/advtrains/trainlogic.lua
@@ -892,16 +892,21 @@ function advtrains.spawn_wagons(train_id)
end
end
-function advtrains.split_train_at_fc(train, count_empty)
+function advtrains.split_train_at_fc(train, count_empty, length_limit)
-- splits train at first different current FC by convention,
-- locomotives have empty FC so are ignored
-- count_empty is used to split off locomotives
+ -- length_limit limits the length of the first train to length_limit wagons
local train_id = train.id
local fc = false
local ind = 0
for i = 1, #train.trainparts do
local w_id = train.trainparts[i]
local data = advtrains.wagons[w_id]
+ if length_limit and i > length_limit then
+ ind = i
+ break
+ end
if data then
local wfc = advtrains.get_cur_fc(data)
if wfc ~= "" or count_empty then
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