Improve debug outputs of couples and increase maximum distance
This commit is contained in:
parent
71ff39637f
commit
272c7b1390
|
@ -10,6 +10,7 @@ wagon
|
||||||
wagons keep their couple entity minetest-internal id inside the field discouple_id. if it refers to nowhere, they will spawn a new one if player is near
|
wagons keep their couple entity minetest-internal id inside the field discouple_id. if it refers to nowhere, they will spawn a new one if player is near
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
local couple_max_dist=3
|
||||||
|
|
||||||
minetest.register_entity("advtrains:discouple", {
|
minetest.register_entity("advtrains:discouple", {
|
||||||
visual="sprite",
|
visual="sprite",
|
||||||
|
@ -22,6 +23,7 @@ minetest.register_entity("advtrains:discouple", {
|
||||||
on_activate=function(self, staticdata)
|
on_activate=function(self, staticdata)
|
||||||
if staticdata=="DISCOUPLE" then
|
if staticdata=="DISCOUPLE" then
|
||||||
--couple entities have no right to exist further...
|
--couple entities have no right to exist further...
|
||||||
|
atprint("Discouple loaded from staticdata, destroying")
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -44,6 +46,7 @@ minetest.register_entity("advtrains:discouple", {
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
atprint("Discouple punched. Splitting train", self.wagon.train_id)
|
||||||
advtrains.split_train_at_wagon(self.wagon)--found in trainlogic.lua
|
advtrains.split_train_at_wagon(self.wagon)--found in trainlogic.lua
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
elseif self.wagon.lock_couples then
|
elseif self.wagon.lock_couples then
|
||||||
|
@ -56,10 +59,12 @@ minetest.register_entity("advtrains:discouple", {
|
||||||
local t=os.clock()
|
local t=os.clock()
|
||||||
if not self.wagon then
|
if not self.wagon then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
atprint("Discouple: no wagon, destroying")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--getyaw seems to be a reliable method to check if an object is loaded...if it returns nil, it is not.
|
--getyaw 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:getyaw() then
|
if not self.wagon.object:getyaw() then
|
||||||
|
atprint("Discouple: wagon no longer loaded, destroying")
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -96,6 +101,7 @@ minetest.register_entity("advtrains:couple", {
|
||||||
on_activate=function(self, staticdata)
|
on_activate=function(self, staticdata)
|
||||||
if staticdata=="COUPLE" then
|
if staticdata=="COUPLE" then
|
||||||
--couple entities have no right to exist further...
|
--couple entities have no right to exist further...
|
||||||
|
atprint("Couple loaded from staticdata, destroying")
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -120,31 +126,38 @@ minetest.register_entity("advtrains:couple", {
|
||||||
advtrains.invert_train(id1)
|
advtrains.invert_train(id1)
|
||||||
advtrains.do_connect_trains(id1, id2, clicker)
|
advtrains.do_connect_trains(id1, id2, clicker)
|
||||||
end
|
end
|
||||||
|
atprint("Coupled trains", id1, id2)
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
end,
|
end,
|
||||||
on_step=function(self, dtime)
|
on_step=function(self, dtime)
|
||||||
local t=os.clock()
|
local t=os.clock()
|
||||||
if not self.train_id_1 or not self.train_id_2 then atprint("wtf no train ids?")return end
|
if not self.train_id_1 or not self.train_id_2 then atprint("Couple: train ids not set!") self.object:remove() return end
|
||||||
local train1=advtrains.trains[self.train_id_1]
|
local train1=advtrains.trains[self.train_id_1]
|
||||||
local train2=advtrains.trains[self.train_id_2]
|
local train2=advtrains.trains[self.train_id_2]
|
||||||
if not train1 or not train2 or not train1.path or not train2.path or not train1.index or not train2.index then
|
if not train1 or not train2 then
|
||||||
|
atprint("Couple: trains missing, destroying")
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
if not train1.path or not train2.path or not train1.index or not train2.index or not train1.end_index or not train2.end_index then
|
||||||
|
atprint("Couple: paths or end_index missing. Might happen when paths got cleared")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local tp1
|
local tp1
|
||||||
if not self.train1_is_backpos then
|
if not self.train1_is_backpos then
|
||||||
tp1=advtrains.get_real_index_position(train1.path, train1.index)
|
tp1=advtrains.get_real_index_position(train1.path, train1.index)
|
||||||
else
|
else
|
||||||
tp1=advtrains.get_real_index_position(train1.path, advtrains.get_train_end_index(train1))
|
tp1=advtrains.get_real_index_position(train1.path, train1.end_index)
|
||||||
end
|
end
|
||||||
local tp2
|
local tp2
|
||||||
if not self.train2_is_backpos then
|
if not self.train2_is_backpos then
|
||||||
tp2=advtrains.get_real_index_position(train2.path, train2.index)
|
tp2=advtrains.get_real_index_position(train2.path, train2.index)
|
||||||
else
|
else
|
||||||
tp2=advtrains.get_real_index_position(train2.path, advtrains.get_train_end_index(train2))
|
tp2=advtrains.get_real_index_position(train2.path, train2.end_index)
|
||||||
end
|
end
|
||||||
if not tp1 or not tp2 or not (vector.distance(tp1,tp2)<2) then
|
if not tp1 or not tp2 or not (vector.distance(tp1,tp2)<couple_max_dist) then
|
||||||
|
atprint("Couple: train end positions too distanced, destroying")
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
|
|
|
@ -746,7 +746,7 @@ function advtrains.collide_and_spawn_couple(id1, pos, id2, t1_is_backpos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not found then
|
if not found then
|
||||||
atprint("Err: pos not in path")
|
atprint("Err: pos not in path. Not spawning a couple")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -786,6 +786,7 @@ function advtrains.collide_and_spawn_couple(id1, pos, id2, t1_is_backpos)
|
||||||
le.train1_is_backpos=t1_is_backpos
|
le.train1_is_backpos=t1_is_backpos
|
||||||
le.train2_is_backpos=t2_is_backpos
|
le.train2_is_backpos=t2_is_backpos
|
||||||
--find in object_refs
|
--find in object_refs
|
||||||
|
local p_aoi
|
||||||
for aoi, compare in pairs(minetest.object_refs) do
|
for aoi, compare in pairs(minetest.object_refs) do
|
||||||
if compare==obj then
|
if compare==obj then
|
||||||
if t1_is_backpos then
|
if t1_is_backpos then
|
||||||
|
@ -798,10 +799,10 @@ function advtrains.collide_and_spawn_couple(id1, pos, id2, t1_is_backpos)
|
||||||
else
|
else
|
||||||
train2.couple_eid_front=aoi
|
train2.couple_eid_front=aoi
|
||||||
end
|
end
|
||||||
|
p_aoi=aoi
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
atprint("Couple entity:"..dump(le))
|
atprint("Couple spawned (ActiveObjectID ",p_aoi,")")
|
||||||
|
|
||||||
end
|
end
|
||||||
--order of trains may be irrelevant in some cases. check opposite cases. TODO does this work?
|
--order of trains may be irrelevant in some cases. check opposite cases. TODO does this work?
|
||||||
--pos1 and pos2 are just needed to form a median.
|
--pos1 and pos2 are just needed to form a median.
|
||||||
|
|
Loading…
Reference in New Issue