diff options
author | orwell96 <orwell@bleipb.de> | 2021-07-07 22:14:20 +0200 |
---|---|---|
committer | orwell96 <orwell@bleipb.de> | 2021-07-07 22:42:14 +0200 |
commit | 1f3a4c3bfc2a462ff51bd6b391be0d39a6a6c944 (patch) | |
tree | 6b1e9cb33aae90d05e709ea0882dc52a1cda36cc /advtrains/wagons.lua | |
parent | c623a338604a0bd623309314d85e1022edc7f3af (diff) | |
download | advtrains-1f3a4c3bfc2a462ff51bd6b391be0d39a6a6c944.tar.gz advtrains-1f3a4c3bfc2a462ff51bd6b391be0d39a6a6c944.tar.bz2 advtrains-1f3a4c3bfc2a462ff51bd6b391be0d39a6a6c944.zip |
Rework train same-track collision system and deterministic coupling
- Adds a separate collision system for trains sharing a path
- Moved some coupling-related code to couple.lua and refactor it
- Handle coupling in a way that the initiating train always keeps its ID
- As a side effect, engine has its direction reversed after coupling
Diffstat (limited to 'advtrains/wagons.lua')
-rw-r--r-- | advtrains/wagons.lua | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua index e9b6d7a..4093f06 100644 --- a/advtrains/wagons.lua +++ b/advtrains/wagons.lua @@ -1240,70 +1240,6 @@ function wagon:reattach_all() end end -local function check_twagon_owner(train, b_first, pname) - local wtp = b_first and 1 or #train.trainparts - local wid = train.trainparts[wtp] - local wdata = advtrains.wagons[wid] - if wdata then - return advtrains.check_driving_couple_protection(pname, wdata.owner, wdata.whitelist) - end - return false -end - -function advtrains.safe_couple_trains(id1, id2, t1f, t2f, pname, try_run,v1,v2) - - if pname and not minetest.check_player_privs(pname, "train_operator") then - minetest.chat_send_player(pname, "Missing train_operator privilege") - return false - end - - local train1=advtrains.trains[id1] - local train2=advtrains.trains[id2] - - if not advtrains.train_ensure_init(id1, train1) - or not advtrains.train_ensure_init(id2, train2) then - return false - end - 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, v1+v2) - else - advtrains.do_connect_trains(id2, id1, v1+v2) - end - else - if t2f then - advtrains.do_connect_trains(id1, id2, v1+v2) - else - v2 = -v2 - advtrains.invert_train(id2) - advtrains.do_connect_trains(id1, id2, v1+v2) - end - end - return true - else - minetest.chat_send_player(pname, "You must be authorized for at least one wagon.") - return false - end -end - - function advtrains.safe_decouple_wagon(w_id, pname, try_run) if not minetest.check_player_privs(pname, "train_operator") then minetest.chat_send_player(pname, "Missing train_operator privilege") |