aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--advtrains/trainlogic.lua68
-rw-r--r--advtrains/wagons.lua31
2 files changed, 57 insertions, 42 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 b13b8d8..71d6d51 100644
--- a/advtrains/wagons.lua
+++ b/advtrains/wagons.lua
@@ -1072,9 +1072,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
@@ -1086,27 +1086,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