aboutsummaryrefslogtreecommitdiff
path: root/trainlogic.lua
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2016-08-21 21:46:16 +0200
committerorwell96 <mono96.mml@gmail.com>2016-08-21 21:46:16 +0200
commit2593b1af1625f9cc3db879541f8425217646b652 (patch)
tree0a779c9bb78026f05bebe8e53266c323490afc72 /trainlogic.lua
parent2ed61efc15322c00863ded46dab722e57316db58 (diff)
downloadadvtrains-2593b1af1625f9cc3db879541f8425217646b652.tar.gz
advtrains-2593b1af1625f9cc3db879541f8425217646b652.tar.bz2
advtrains-2593b1af1625f9cc3db879541f8425217646b652.zip
repairing the trackworker
Diffstat (limited to 'trainlogic.lua')
-rw-r--r--trainlogic.lua6
1 files changed, 3 insertions, 3 deletions
diff --git a/trainlogic.lua b/trainlogic.lua
index dca2863..1ec27e0 100644
--- a/trainlogic.lua
+++ b/trainlogic.lua
@@ -601,15 +601,15 @@ function advtrains.try_connect_trains_and_check_collision(id1, id2)
end
--true when trains are facing each other. needed on colliding.
-- check done by iterating paths and checking their direction
---returns nil when not on the same track at all. this distinction may not always be needed.
+--returns nil when not on the same track at all OR when required path items are not generated. this distinction may not always be needed.
function advtrains.trains_facing(train1, train2)
local sr_pos=train1.path[math.floor(train1.index)]
local sr_pos_p=train1.path[math.floor(train1.index)-1]
for i=advtrains.minN(train2.path), advtrains.maxN(train2.path) do
if vector.equals(sr_pos, train2.path[i]) then
- if vector.equals(sr_pos_p, train2.path[i+1]) then return true end
- if vector.equals(sr_pos_p, train2.path[i-1]) then return false end
+ if train2.path[i+1] and vector.equals(sr_pos_p, train2.path[i+1]) then return true end
+ if train2.path[i-1] and vector.equals(sr_pos_p, train2.path[i-1]) then return false end
return nil
end
end