diff options
author | orwell96 <mono96.mml@gmail.com> | 2016-08-21 21:46:16 +0200 |
---|---|---|
committer | orwell96 <mono96.mml@gmail.com> | 2016-08-21 21:46:16 +0200 |
commit | 2593b1af1625f9cc3db879541f8425217646b652 (patch) | |
tree | 0a779c9bb78026f05bebe8e53266c323490afc72 /trainlogic.lua | |
parent | 2ed61efc15322c00863ded46dab722e57316db58 (diff) | |
download | advtrains-2593b1af1625f9cc3db879541f8425217646b652.tar.gz advtrains-2593b1af1625f9cc3db879541f8425217646b652.tar.bz2 advtrains-2593b1af1625f9cc3db879541f8425217646b652.zip |
repairing the trackworker
Diffstat (limited to 'trainlogic.lua')
-rw-r--r-- | trainlogic.lua | 6 |
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 |