aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2019-08-11 20:16:11 +0200
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2019-08-11 20:16:11 +0200
commit2d8c13885aa33a0f5eb43b16a1131f187fad75e7 (patch)
tree8bddf1888edfa105c613ba38a70aea05c4aa8334
parentef50610f675c85cb0c85eb200018896cefd0cc11 (diff)
downloadadvtrains-2d8c13885aa33a0f5eb43b16a1131f187fad75e7.tar.gz
advtrains-2d8c13885aa33a0f5eb43b16a1131f187fad75e7.tar.bz2
advtrains-2d8c13885aa33a0f5eb43b16a1131f187fad75e7.zip
Shunting mode now couples trains on collision.
Trains now get coupled when one of them is in coupling mode.
-rw-r--r--advtrains/occupation.lua4
-rw-r--r--advtrains/trainlogic.lua25
-rw-r--r--advtrains_luaautomation/atc_rail.lua5
3 files changed, 24 insertions, 10 deletions
diff --git a/advtrains/occupation.lua b/advtrains/occupation.lua
index 66a5a75..f5c7d88 100644
--- a/advtrains/occupation.lua
+++ b/advtrains/occupation.lua
@@ -175,8 +175,8 @@ function o.check_collision(pos, train_id)
--atdebug("checking train",t[i],"index",idx,"<>",train.index,train.end_index)
if train and idx >= train.end_index and idx <= train.index then
- --atdebug("collides.")
- return true
+ --atdebug("collides.")
+ return train -- return train it collided with so we can couple when shunting is enabled
end
end
i = i + 2
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index ee1880d..86f60c1 100644
--- a/advtrains/trainlogic.lua
+++ b/advtrains/trainlogic.lua
@@ -529,11 +529,20 @@ function advtrains.train_step_c(id, train, dtime)
for z=-train.extent_h,train.extent_h do
local testpos=vector.add(rcollpos, {x=x, y=0, z=z})
--- 8a Check collision ---
- if not collided and advtrains.occ.check_collision(testpos, id) then
- --collides
- train.velocity = 0
- advtrains.atc.train_reset_command(train)
- collided = true
+ if not collided then
+
+ local col_tr = advtrains.occ.check_collision(testpos, id)
+ if col_tr then
+ 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
--- 8b damage players ---
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!")
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 = {}
@@ -1047,7 +1056,7 @@ end
--->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]
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)
- first.velocity=0
+ first.velocity= vel or 0
advtrains.update_trainpart_properties(first_id)
advtrains.couple_invalidate(first)
diff --git a/advtrains_luaautomation/atc_rail.lua b/advtrains_luaautomation/atc_rail.lua
index 89cd2c1..1d94a2b 100644
--- a/advtrains_luaautomation/atc_rail.lua
+++ b/advtrains_luaautomation/atc_rail.lua
@@ -66,6 +66,11 @@ function r.fire_event(pos, evtdata)
end
return false
end,
+ set_shunt = function()
+ -- enable shunting mode
+ if not train_id then return false end
+ train.is_shunt = true
+ end,
set_line = function(line)
if type(line)~="string" and type(line)~="number" then
return false