split_at_index where index=1

Splitting at index=1 results in multiple empty trains being created.
Can be prevented by an atc_speed > 0 check by the user, but easier just to return false and do nothing.
This commit is contained in:
Maverick2797 2021-11-08 20:36:01 +08:00 committed by Gabriel Pérez-Cerezo
parent 45e18326e3
commit 4cf9e5283b
2 changed files with 3 additions and 1 deletions

2
advtrains_luaautomation/README.md Normal file → Executable file
View File

@ -260,6 +260,8 @@ There are several functions available especially for shunting operations. Some o
- `split_at_index(index, atc_command)` - `split_at_index(index, atc_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. The `atc_command` specified is sent to the second train after decoupling. `"S0"` or `"B0"` is common to ensure any locomotives in the remaining train don't continue to move. Splits the train at the specified index, into a train with index-1 wagons and a second train starting with the index-th wagon. The `atc_command` specified is sent to the second train after decoupling. `"S0"` or `"B0"` is common to ensure any locomotives in the remaining train don't continue to move.
`index` must be more than 1 to avoid trying to decouple the very front of a train.
Example: train has wagons `"foo","foo","foo","bar","bar","bar"` Example: train has wagons `"foo","foo","foo","bar","bar","bar"`
Command: `split_at_index(4,"S0")` Command: `split_at_index(4,"S0")`
Result: first train (continues at previous speed): `"foo","foo","foo"`, second train (slows at S0): `"bar","bar","bar"` Result: first train (continues at previous speed): `"foo","foo","foo"`, second train (slows at S0): `"bar","bar","bar"`

2
advtrains_luaautomation/atc_rail.lua Normal file → Executable file
View File

@ -56,7 +56,7 @@ function r.fire_event(pos, evtdata, appr_internal)
split_at_index = function(index, cmd) split_at_index = function(index, cmd)
if not train_id then return false end if not train_id then return false end
assertt(cmd, "string") assertt(cmd, "string")
if type(index) ~= "number" then if type(index) ~= "number" or index < 2 then
return false return false
end end
local new_id = advtrains.split_train_at_index(train, index) local new_id = advtrains.split_train_at_index(train, index)