Add autocouple mode

The shunting mode no longer makes trains couple, since it was meant
for other purposes. For autocoupling, the new autocoupling mode is
used. If trains are in autocouple mode, they couple when they collide
with another train.
master
Gabriel Pérez-Cerezo 2020-06-29 01:30:27 +02:00
parent f458f39fde
commit 0b14d8ddb1
4 changed files with 21 additions and 12 deletions

View File

@ -392,7 +392,7 @@ advtrains.avt_save = function(remove_players_from_wagons)
"trainparts", "recently_collided_with_env",
"atc_brake_target", "atc_wait_finish", "atc_command", "atc_delay", "door_open",
"text_outside", "text_inside", "line", "routingcode",
"il_sections", "speed_restriction", "is_shunt", "points_split",
"il_sections", "speed_restriction", "is_shunt", "points_split", "autocouple"
})
--then save it
tmp_trains[id]=v

View File

@ -906,7 +906,7 @@ function advtrains.split_train_at_index(train, index)
atwarn("Train",train_id,"is not initialized! Operation aborted!")
return
end
train.is_shunt = nil -- prevent immediate recoupling
local p_index=advtrains.path_get_index_by_offset(train, train.index, - data.pos_in_train + wagon.wagon_span)
local pos, connid, frac = advtrains.path_getrestore(train, p_index)
local tp = {}
@ -944,10 +944,10 @@ local CPL_ZONE = 2
local function createcouple(pos, train1, t1_is_front, train2, t2_is_front)
local id1 = train1.id
local id2 = train2.id
if train1.is_shunt or train2.is_shunt then
if train1.autocouple or train2.autocouple then
-- couple trains
train1.is_shunt = nil
train2.is_shunt = nil
train1.autocouple = nil
train2.autocouple = nil
minetest.after(0, advtrains.safe_couple_trains, id1, id2, t1_is_front, t2_is_front, false, false, train1.velocity, train2.velocity)
return
end

View File

@ -203,10 +203,12 @@ 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.
set_shunt()
Sets the train into shunting mode
unset_shunt()
Sets the train into normal mode
set_autocouple()
Sets the train into autocouple mode
unset_autocouple()
Unsets autocouple mode
set_shunt(), unset_shunt()
deprecated aliases for set_autocouple() and unset_autocouple(), will be removed from a later release.
# Operator panel
This simple node executes its actions when punched. It can be used to change a switch and update the corresponding signals or similar applications.

View File

@ -67,13 +67,20 @@ function r.fire_event(pos, evtdata)
return false
end,
set_shunt = function()
-- enable shunting mode
if not train_id then return false end
train.is_shunt = true
train.autocouple = true
end,
unset_shunt = function()
if not train_id then return false end
train.is_shunt = nil
train.autocouple = nil
end,
set_autcouple = function ()
if not train_id then return false end
train.autocouple = true
end,
unset_autocouple = function ()
if not train_id then return false end
train.autocouple = nil
end,
set_line = function(line)
if type(line)~="string" and type(line)~="number" then