diff options
-rw-r--r-- | advtrains/advtrains/couple.lua | 23 | ||||
-rw-r--r-- | advtrains/advtrains/trainlogic.lua | 7 |
2 files changed, 22 insertions, 8 deletions
diff --git a/advtrains/advtrains/couple.lua b/advtrains/advtrains/couple.lua index 8697226..eb1bc72 100644 --- a/advtrains/advtrains/couple.lua +++ b/advtrains/advtrains/couple.lua @@ -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 ]] +local couple_max_dist=3 minetest.register_entity("advtrains:discouple", { visual="sprite", @@ -22,6 +23,7 @@ minetest.register_entity("advtrains:discouple", { on_activate=function(self, staticdata) if staticdata=="DISCOUPLE" then --couple entities have no right to exist further... + atprint("Discouple loaded from staticdata, destroying") self.object:remove() return end @@ -44,6 +46,7 @@ minetest.register_entity("advtrains:discouple", { end end end + atprint("Discouple punched. Splitting train", self.wagon.train_id) advtrains.split_train_at_wagon(self.wagon)--found in trainlogic.lua self.object:remove() elseif self.wagon.lock_couples then @@ -56,10 +59,12 @@ minetest.register_entity("advtrains:discouple", { local t=os.clock() if not self.wagon then self.object:remove() + atprint("Discouple: no wagon, destroying") return end --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 + atprint("Discouple: wagon no longer loaded, destroying") self.object:remove() return end @@ -96,6 +101,7 @@ minetest.register_entity("advtrains:couple", { on_activate=function(self, staticdata) if staticdata=="COUPLE" then --couple entities have no right to exist further... + atprint("Couple loaded from staticdata, destroying") self.object:remove() return end @@ -120,31 +126,38 @@ minetest.register_entity("advtrains:couple", { advtrains.invert_train(id1) advtrains.do_connect_trains(id1, id2, clicker) end + atprint("Coupled trains", id1, id2) self.object:remove() end, on_step=function(self, dtime) 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 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() return 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 if not self.train1_is_backpos then tp1=advtrains.get_real_index_position(train1.path, train1.index) 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 local tp2 if not self.train2_is_backpos then tp2=advtrains.get_real_index_position(train2.path, train2.index) 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 - 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() return else diff --git a/advtrains/advtrains/trainlogic.lua b/advtrains/advtrains/trainlogic.lua index 3f72750..6b9d1aa 100644 --- a/advtrains/advtrains/trainlogic.lua +++ b/advtrains/advtrains/trainlogic.lua @@ -746,7 +746,7 @@ function advtrains.collide_and_spawn_couple(id1, pos, id2, t1_is_backpos) end end if not found then - atprint("Err: pos not in path") + atprint("Err: pos not in path. Not spawning a couple") return 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.train2_is_backpos=t2_is_backpos --find in object_refs + local p_aoi for aoi, compare in pairs(minetest.object_refs) do if compare==obj then if t1_is_backpos then @@ -798,10 +799,10 @@ function advtrains.collide_and_spawn_couple(id1, pos, id2, t1_is_backpos) else train2.couple_eid_front=aoi end + p_aoi=aoi end end - atprint("Couple entity:"..dump(le)) - + atprint("Couple spawned (ActiveObjectID ",p_aoi,")") end --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. |