Shunting mode now couples trains on collision.
Trains now get coupled when one of them is in coupling mode.
This commit is contained in:
parent
ef50610f67
commit
2d8c13885a
|
@ -175,8 +175,8 @@ function o.check_collision(pos, train_id)
|
||||||
|
|
||||||
--atdebug("checking train",t[i],"index",idx,"<>",train.index,train.end_index)
|
--atdebug("checking train",t[i],"index",idx,"<>",train.index,train.end_index)
|
||||||
if train and idx >= train.end_index and idx <= train.index then
|
if train and idx >= train.end_index and idx <= train.index then
|
||||||
--atdebug("collides.")
|
--atdebug("collides.")
|
||||||
return true
|
return train -- return train it collided with so we can couple when shunting is enabled
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
i = i + 2
|
i = i + 2
|
||||||
|
|
|
@ -529,11 +529,20 @@ function advtrains.train_step_c(id, train, dtime)
|
||||||
for z=-train.extent_h,train.extent_h do
|
for z=-train.extent_h,train.extent_h do
|
||||||
local testpos=vector.add(rcollpos, {x=x, y=0, z=z})
|
local testpos=vector.add(rcollpos, {x=x, y=0, z=z})
|
||||||
--- 8a Check collision ---
|
--- 8a Check collision ---
|
||||||
if not collided and advtrains.occ.check_collision(testpos, id) then
|
if not collided then
|
||||||
--collides
|
|
||||||
train.velocity = 0
|
local col_tr = advtrains.occ.check_collision(testpos, id)
|
||||||
advtrains.atc.train_reset_command(train)
|
if col_tr then
|
||||||
collided = true
|
if train.is_shunt or col_tr.is_shunt then
|
||||||
|
train.is_shunt = nil
|
||||||
|
col_tr.is_shunt = nil
|
||||||
|
minetest.after(0,advtrains.do_connect_trains, col_tr.id, train.id, train.velocity)
|
||||||
|
else
|
||||||
|
train.velocity = 0
|
||||||
|
advtrains.atc.train_reset_command(train)
|
||||||
|
collided = true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
--- 8b damage players ---
|
--- 8b damage players ---
|
||||||
if is_loaded_area and (setting_overrun_mode=="drop" or setting_overrun_mode=="normal") then
|
if is_loaded_area and (setting_overrun_mode=="drop" or setting_overrun_mode=="normal") then
|
||||||
|
@ -908,7 +917,7 @@ function advtrains.split_train_at_index(train, index)
|
||||||
atwarn("Train",train_id,"is not initialized! Operation aborted!")
|
atwarn("Train",train_id,"is not initialized! Operation aborted!")
|
||||||
return
|
return
|
||||||
end
|
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 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 pos, connid, frac = advtrains.path_getrestore(train, p_index)
|
||||||
local tp = {}
|
local tp = {}
|
||||||
|
@ -1047,7 +1056,7 @@ end
|
||||||
--->frontpos's will match
|
--->frontpos's will match
|
||||||
|
|
||||||
|
|
||||||
function advtrains.do_connect_trains(first_id, second_id)
|
function advtrains.do_connect_trains(first_id, second_id, vel)
|
||||||
local first, second=advtrains.trains[first_id], advtrains.trains[second_id]
|
local first, second=advtrains.trains[first_id], advtrains.trains[second_id]
|
||||||
|
|
||||||
if not advtrains.train_ensure_init(first_id, first) then
|
if not advtrains.train_ensure_init(first_id, first) then
|
||||||
|
@ -1068,7 +1077,7 @@ function advtrains.do_connect_trains(first_id, second_id)
|
||||||
|
|
||||||
advtrains.remove_train(second_id)
|
advtrains.remove_train(second_id)
|
||||||
|
|
||||||
first.velocity=0
|
first.velocity= vel or 0
|
||||||
|
|
||||||
advtrains.update_trainpart_properties(first_id)
|
advtrains.update_trainpart_properties(first_id)
|
||||||
advtrains.couple_invalidate(first)
|
advtrains.couple_invalidate(first)
|
||||||
|
|
|
@ -66,6 +66,11 @@ function r.fire_event(pos, evtdata)
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end,
|
end,
|
||||||
|
set_shunt = function()
|
||||||
|
-- enable shunting mode
|
||||||
|
if not train_id then return false end
|
||||||
|
train.is_shunt = true
|
||||||
|
end,
|
||||||
set_line = function(line)
|
set_line = function(line)
|
||||||
if type(line)~="string" and type(line)~="number" then
|
if type(line)~="string" and type(line)~="number" then
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Reference in New Issue