Add 'collision mercy' to get stuck trains out of walls.
authororwell96 <mono96.mml@gmail.com>
Wed, 18 Jan 2017 19:51:47 +0000 (20:51 +0100)
committerorwell96 <mono96.mml@gmail.com>
Wed, 18 Jan 2017 19:51:47 +0000 (20:51 +0100)
Also change the collision logic so that the collision mercy can't be activated accidentally.

advtrains/advtrains/wagons.lua

index f164335..265a84c 100644 (file)
@@ -377,9 +377,20 @@ function wagon:on_step(dtime)
                        end\r
                end\r
                if collides then\r
-                       gp.recently_collided_with_env=true\r
-                       gp.velocity=-0.5*gp.velocity\r
-                       gp.tarvelocity=0\r
+                       if self.collision_count and self.collision_count>10 then\r
+                               --enable collision mercy to get trains stuck in walls out of walls\r
+                               --actually do nothing except limiting the velocity to 1\r
+                               gp.velocity=math.min(gp.velocity, 1)\r
+                               gp.tarvelocity=math.min(gp.tarvelocity, 1)\r
+                       else\r
+                               gp.recently_collided_with_env=true\r
+                               gp.velocity=2*gp.velocity\r
+                               gp.movedir=-gp.movedir\r
+                               gp.tarvelocity=0\r
+                               self.collision_count=(self.collision_count or 0)+1\r
+                       end\r
+               else\r
+                       self.collision_count=nil\r
                end\r
        end\r
        \r