aboutsummaryrefslogtreecommitdiff
path: root/advtrains/couple.lua
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains/couple.lua')
-rw-r--r--advtrains/couple.lua43
1 files changed, 31 insertions, 12 deletions
diff --git a/advtrains/couple.lua b/advtrains/couple.lua
index b6a445e..cb325a0 100644
--- a/advtrains/couple.lua
+++ b/advtrains/couple.lua
@@ -18,6 +18,9 @@
-- 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 (see below)
+-- Get current translator
+local S = advtrains.translate
+
advtrains.coupler_types = {}
function advtrains.register_coupler_type(code, name)
@@ -25,9 +28,23 @@ function advtrains.register_coupler_type(code, name)
end
-- Register some default couplers
-advtrains.register_coupler_type("chain", attrans("Buffer and Chain Coupler"))
-advtrains.register_coupler_type("scharfenberg", attrans("Scharfenberg Coupler"))
+advtrains.register_coupler_type("chain", S("Buffer and Chain Coupler"))
+advtrains.register_coupler_type("scharfenberg", S("Scharfenberg Coupler"))
+for _, name in pairs {"couple", "decouple"} do
+ local t = {}
+ local function reg(f)
+ table.insert(t, f)
+ end
+ local function cb(...)
+ for _, f in ipairs(t) do
+ f(...)
+ end
+ end
+ advtrains["te_registered_on_" .. name] = t
+ advtrains["te_register_on_" .. name] = reg
+ advtrains["te_run_callbacks_on_" .. name] = cb
+end
local function create_couple_entity(pos, train1, t1_is_front, train2, t2_is_front)
local id1 = train1.id
@@ -184,8 +201,8 @@ end
function advtrains.safe_couple_trains(train1, t1_is_front, train2, t2_is_front, pname)
if pname and not minetest.check_player_privs(pname, "train_operator") then
- minetest.chat_send_player(pname, "Missing train_operator privilege")
- return false
+ minetest.chat_send_player(pname, S("You are not allowed to couple trains without the train_operator privilege."))
+ return false
end
local wck_t1, wck_t2
@@ -231,10 +248,12 @@ function advtrains.couple_trains(init_train, invert_init_train, stat_train, stat
-- sanity check, prevent coupling if train would be longer than 20 after coupling
local tot_len = init_wagoncnt + stat_wagoncnt
if tot_len > advtrains.TRAIN_MAX_WAGONS then
- atwarn("Cannot couple",stat_train.id,"and",init_train.id,"- train would have length",tot_len,"which is above the limit of",advtrains.TRAIN_MAX_WAGONS)
+ atwarn(S("Cannot couple @1 and @2 - train would have length @3 which is above the limit of @4", stat_train.id, init_train.id, tot_len, advtrains.TRAIN_MAX_WAGONS))
return
end
+ advtrains.te_run_callbacks_on_couple(init_train, stat_train)
+
if stat_train_opposite then
-- insert wagons in inverse order and set their wagon_flipped state
for i=1,stat_wagoncnt do
@@ -319,7 +338,7 @@ function advtrains.check_matching_coupler_types(t1, t1_front, t2, t2_front)
--atdebug("CMCT: t1",t1_cplt,"t2",t2_cplt,"")
-- if at least one of the trains has no couplers table, it always couples (fallback behavior and mode for universal shunters)
- if not t1_cplt or not t2_cplt then
+ if minetest.settings:get_bool("advtrains_universal_couplers", false) or not t1_cplt or not t2_cplt then
return true
end
@@ -335,12 +354,12 @@ function advtrains.check_matching_coupler_types(t1, t1_front, t2, t2_front)
for typ,_ in pairs(t1_cplt) do
table.insert(t1_cplhr, advtrains.coupler_types[typ] or typ)
end
- if #t1_cplhr==0 then t1_cplhr[1]=attrans("<none>") end
+ if #t1_cplhr==0 then t1_cplhr[1]=S("<No coupler>") end
for typ,_ in pairs(t2_cplt) do
table.insert(t2_cplhr, advtrains.coupler_types[typ] or typ)
end
- if #t2_cplhr==0 then t2_cplhr[1]=attrans("<none>") end
- return false, attrans("Can not couple: The couplers of the trains do not match (@1 and @2).", table.concat(t1_cplhr, ","), table.concat(t2_cplhr, ","))
+ if #t2_cplhr==0 then t2_cplhr[1]=S("<No coupler>") end
+ return false, S("Can not couple: The couplers of the trains do not match (@1 and @2).", table.concat(t1_cplhr, ","), table.concat(t2_cplhr, ","))
end
-- DECOUPLING --
@@ -437,7 +456,7 @@ minetest.register_entity("advtrains:discouple", {
self.object:remove()
return
end
- --getyaw seems to be a reliable method to check if an object is loaded...if it returns nil, it is not.
+ --get_yaw seems to be a reliable method to check if an object is loaded...if it returns nil, it is not.
if not self.wagon.object:get_yaw() then
self.object:remove()
return
@@ -484,7 +503,7 @@ minetest.register_entity("advtrains:couple", {
self.object:remove()
end,
on_step=function(self, dtime)
- if advtrains.wagon_outside_range(self.object:getpos()) then
+ if advtrains.wagon_outside_range(self.object:get_pos()) then
--atdebug("Couple Removing outside range")
self.object:remove()
return
@@ -523,7 +542,7 @@ minetest.register_entity("advtrains:couple", {
tp2=advtrains.path_get_interpolated(train2, train2.end_index)
end
local pos_median=advtrains.pos_median(tp1, tp2)
- if not vector.equals(pos_median, self.object:getpos()) then
+ if not vector.equals(pos_median, self.object:get_pos()) then
self.object:set_pos(pos_median)
end
self.position_set=true