diff options
author | orwell96 <orwell@bleipb.de> | 2017-10-25 10:31:07 +0200 |
---|---|---|
committer | orwell96 <orwell@bleipb.de> | 2017-10-25 10:33:41 +0200 |
commit | c67770833b772e438f81ac80f10f1c46bbeebcfa (patch) | |
tree | 446bdf2cf44f283dddfa8f52f2a3099b16b1cf64 /advtrains/couple.lua | |
parent | f228e2d30e0d712c6490fb84d4edfadeba8c4cd7 (diff) | |
download | advtrains-c67770833b772e438f81ac80f10f1c46bbeebcfa.tar.gz advtrains-c67770833b772e438f81ac80f10f1c46bbeebcfa.tar.bz2 advtrains-c67770833b772e438f81ac80f10f1c46bbeebcfa.zip |
Fix coupling and collisions in certain cases
If a train moved towards another train, and the other train's step was executed after the first one's, the trains did eventually not collide.
Fix by moving the enter_node and collision check to step_b
Also change some couple behavior
Diffstat (limited to 'advtrains/couple.lua')
-rw-r--r-- | advtrains/couple.lua | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/advtrains/couple.lua b/advtrains/couple.lua index 7bab241..6741de8 100644 --- a/advtrains/couple.lua +++ b/advtrains/couple.lua @@ -154,27 +154,33 @@ minetest.register_entity("advtrains:couple", { 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, 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, train2.end_index) - end - if not tp1 or not tp2 or not (vector.distance(tp1,tp2)<couple_max_dist) then - atprint("Couple: train end positions too distanced, destroying (distance is",vector.distance(tp1,tp2),")") + if train1.velocity>0 or train2.velocity>0 then + if not self.position_set then --ensures that train stands a single time before check fires. Using flag below + return + end + atprint("Couple: train is moving, destroying") self.object:remove() return - else + end + + if not self.position_set then + 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, 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, train2.end_index) + end local pos_median=advtrains.pos_median(tp1, tp2) if not vector.equals(pos_median, self.object:getpos()) then self.object:setpos(pos_median) end + self.position_set=true end atprintbm("couple step", t) advtrains.atprint_context_tid=nil |