aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--advtrains/trainlogic.lua68
-rw-r--r--advtrains/wagons.lua31
-rw-r--r--advtrains_interlocking/routesetting.lua8
-rw-r--r--advtrains_luaautomation/README.txt4
-rw-r--r--advtrains_luaautomation/atc_rail.lua4
5 files changed, 72 insertions, 43 deletions
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index 3c0d02e..6198c18 100644
--- a/advtrains/trainlogic.lua
+++ b/advtrains/trainlogic.lua
@@ -536,38 +536,34 @@ function advtrains.train_step_c(id, train, dtime)
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
+ advtrains.train_check_couples(train)
+ train.velocity = 0
+ advtrains.atc.train_reset_command(train)
+ collided = true
end
- end
- --- 8b damage players ---
- if is_loaded_area and (setting_overrun_mode=="drop" or setting_overrun_mode=="normal") then
- local testpts = minetest.pos_to_string(testpos)
- local player=advtrains.playersbypts[testpts]
- if player and train.velocity>3 and player:get_hp()>0 and advtrains.is_damage_enabled(player:get_player_name()) then
- --atdebug("damage found",player:get_player_name())
- if setting_overrun_mode=="drop" then
- --instantly kill player
- --drop inventory contents first, to not to spawn bones
- local player_inv=player:get_inventory()
- for i=1,player_inv:get_size("main") do
- minetest.add_item(testpos, player_inv:get_stack("main", i))
- end
- for i=1,player_inv:get_size("craft") do
- minetest.add_item(testpos, player_inv:get_stack("craft", i))
+
+ --- 8b damage players ---
+ if is_loaded_area and train.velocity > 3 and (setting_overrun_mode=="drop" or setting_overrun_mode=="normal") then
+ local testpts = minetest.pos_to_string(testpos)
+ local player=advtrains.playersbypts[testpts]
+ if player and player:get_hp()>0 and advtrains.is_damage_enabled(player:get_player_name()) then
+ --atdebug("damage found",player:get_player_name())
+ if setting_overrun_mode=="drop" then
+ --instantly kill player
+ --drop inventory contents first, to not to spawn bones
+ local player_inv=player:get_inventory()
+ for i=1,player_inv:get_size("main") do
+ minetest.add_item(testpos, player_inv:get_stack("main", i))
+ end
+ for i=1,player_inv:get_size("craft") do
+ minetest.add_item(testpos, player_inv:get_stack("craft", i))
+ end
+ -- empty lists main and craft
+ player_inv:set_list("main", {})
+ player_inv:set_list("craft", {})
end
- -- empty lists main and craft
- player_inv:set_list("main", {})
- player_inv:set_list("craft", {})
+ player:set_hp(0)
end
- player:set_hp(0)
end
end
end
@@ -922,11 +918,21 @@ local CPL_ZONE = 2
-- train.couple_* contain references to ObjectRefs of couple objects, which contain all relevant information
-- These objectRefs will delete themselves once the couples no longer match
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
+ -- couple trains
+ train1.is_shunt = nil
+ train2.is_shunt = nil
+ minetest.after(0, advtrains.safe_couple_trains, id1, id2, t1_is_front, t2_is_front, false, false, train1.velocity, train2.velocity)
+ return
+ end
+
local obj=minetest.add_entity(pos, "advtrains:couple")
if not obj then error("Failed creating couple object!") return end
local le=obj:get_luaentity()
- le.train_id_1=train1.id
- le.train_id_2=train2.id
+ le.train_id_1=id1
+ le.train_id_2=id2
le.t1_is_front=t1_is_front
le.t2_is_front=t2_is_front
--atdebug("created couple between",train1.id,t1_is_front,train2.id,t2_is_front)
diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua
index 3ee4399..c44cd9c 100644
--- a/advtrains/wagons.lua
+++ b/advtrains/wagons.lua
@@ -1101,9 +1101,9 @@ local function check_twagon_owner(train, b_first, pname)
return false
end
-function advtrains.safe_couple_trains(id1, id2, t1f, t2f, pname, try_run)
+function advtrains.safe_couple_trains(id1, id2, t1f, t2f, pname, try_run,v1,v2)
- if not minetest.check_player_privs(pname, "train_operator") then
+ if pname and not minetest.check_player_privs(pname, "train_operator") then
minetest.chat_send_player(pname, "Missing train_operator privilege")
return false
end
@@ -1115,27 +1115,36 @@ function advtrains.safe_couple_trains(id1, id2, t1f, t2f, pname, try_run)
or not advtrains.train_ensure_init(id2, train2) then
return false
end
-
- local wck_t1 = check_twagon_owner(train1, t1f, pname)
- local wck_t2 = check_twagon_owner(train2, t2f, pname)
-
- if wck_t1 or wck_t2 then
+ local wck_t1, wck_t2
+ if pname then
+ wck_t1 = check_twagon_owner(train1, t1f, pname)
+ wck_t2 = check_twagon_owner(train2, t2f, pname)
+ end
+ if (wck_t1 or wck_t2) or not pname then
+ if not v1 then
+ v1 = 0
+ end
+ if not v2 then
+ v2 = 0
+ end
if try_run then
return true
end
if t1f then
if t2f then
+ v1 = -v1
advtrains.invert_train(id1)
- advtrains.do_connect_trains(id1, id2)
+ advtrains.do_connect_trains(id1, id2, v1+v2)
else
- advtrains.do_connect_trains(id2, id1)
+ advtrains.do_connect_trains(id2, id1, v1+v2)
end
else
if t2f then
- advtrains.do_connect_trains(id1, id2)
+ advtrains.do_connect_trains(id1, id2, v1+v2)
else
+ v2 = -v2
advtrains.invert_train(id2)
- advtrains.do_connect_trains(id1, id2)
+ advtrains.do_connect_trains(id1, id2, v1+v2)
end
end
return true
diff --git a/advtrains_interlocking/routesetting.lua b/advtrains_interlocking/routesetting.lua
index 7c4d14c..1c9ee5a 100644
--- a/advtrains_interlocking/routesetting.lua
+++ b/advtrains_interlocking/routesetting.lua
@@ -282,6 +282,7 @@ end
-- cancel: true in combination with newrte=nil causes cancellation of the current route.
function ilrs.update_route(sigd, tcbs, newrte, cancel)
--atdebug("Update_Route for",sigd,tcbs.signal_name)
+ local has_changed_aspect = false
if tcbs.route_origin and not sigd_equal(tcbs.route_origin, sigd) then
--atdebug("Signal not in control, held by",tcbs.signal_name)
return
@@ -293,6 +294,7 @@ function ilrs.update_route(sigd, tcbs, newrte, cancel)
end
tcbs.route_committed = nil
tcbs.aspect = nil
+ has_changed_aspect = true
tcbs.routeset = nil
tcbs.route_auto = nil
tcbs.route_rsn = nil
@@ -320,9 +322,13 @@ function ilrs.update_route(sigd, tcbs, newrte, cancel)
end
else
--atdebug("Committed Route:",tcbs.routeset)
+ has_changed_aspect = true
end
end
- advtrains.interlocking.update_signal_aspect(tcbs)
+ if has_changed_aspect then
+ -- FIX: prevent an minetest.after() loop caused by update_signal_aspect dispatching path invalidation, which in turn calls ARS again
+ advtrains.interlocking.update_signal_aspect(tcbs)
+ end
advtrains.interlocking.update_player_forms(sigd)
end
diff --git a/advtrains_luaautomation/README.txt b/advtrains_luaautomation/README.txt
index 20ef816..c377c1b 100644
--- a/advtrains_luaautomation/README.txt
+++ b/advtrains_luaautomation/README.txt
@@ -203,6 +203,10 @@ 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
# 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.
diff --git a/advtrains_luaautomation/atc_rail.lua b/advtrains_luaautomation/atc_rail.lua
index 1d94a2b..feac8d1 100644
--- a/advtrains_luaautomation/atc_rail.lua
+++ b/advtrains_luaautomation/atc_rail.lua
@@ -71,6 +71,10 @@ function r.fire_event(pos, evtdata)
if not train_id then return false end
train.is_shunt = true
end,
+ unset_shunt = function()
+ if not train_id then return false end
+ train.is_shunt = nil
+ end,
set_line = function(line)
if type(line)~="string" and type(line)~="number" then
return false