diff options
author | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2016-12-17 12:30:29 +0100 |
---|---|---|
committer | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2016-12-17 12:30:29 +0100 |
commit | 2f799655facc799b8073355ece91f3c82f223b63 (patch) | |
tree | 1956d217d415afc2d330c46d7463d1a7f3260d11 /trainlogic.lua | |
parent | 072ca535bf638e474bb6f04e40b809077e6b0b8b (diff) | |
parent | 05ce694decc0653997f45fa4f9a24b40057dbd01 (diff) | |
download | advtrains-2f799655facc799b8073355ece91f3c82f223b63.tar.gz advtrains-2f799655facc799b8073355ece91f3c82f223b63.tar.bz2 advtrains-2f799655facc799b8073355ece91f3c82f223b63.zip |
Merge branch 'master' of https://github.com/orwell96/advtrains
Diffstat (limited to 'trainlogic.lua')
-rw-r--r-- | trainlogic.lua | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/trainlogic.lua b/trainlogic.lua index 11849fd..5e3936f 100644 --- a/trainlogic.lua +++ b/trainlogic.lua @@ -487,8 +487,19 @@ function advtrains.pathpredict(id, train) train.path_dist[-1]=vector.distance(train.last_pos, train.last_pos_prev) end + local pregen_front=2 + local pregen_back=2 + if train.velocity>0 then + if train.movedir>0 then + pregen_front=2+math.ceil(train.velocity*0.15) --assumes server step of 0.1 seconds, +50% tolerance + else + pregen_back=2+math.ceil(train.velocity*0.15) + end + end + + local maxn=advtrains.maxN(train.path) - while (maxn-train.index) < 2 do--pregenerate + while (maxn-train.index) < pregen_front do--pregenerate --print("[advtrains]maxn conway for ",maxn,minetest.pos_to_string(path[maxn]),maxn-1,minetest.pos_to_string(path[maxn-1])) local conway=advtrains.conway(train.path[maxn], train.path[maxn-1], train.traintype) if conway then @@ -505,7 +516,7 @@ function advtrains.pathpredict(id, train) end local minn=advtrains.minN(train.path) - while (train.index-minn) < (train.trainlen or 0) + 2 do --post_generate. has to be at least trainlen. (we let go of the exact calculation here since this would be unuseful here) + while (train.index-minn) < (train.trainlen or 0) + pregen_back do --post_generate. has to be at least trainlen. (we let go of the exact calculation here since this would be unuseful here) --print("[advtrains]minn conway for ",minn,minetest.pos_to_string(path[minn]),minn+1,minetest.pos_to_string(path[minn+1])) local conway=advtrains.conway(train.path[minn], train.path[minn+1], train.traintype) if conway then @@ -664,17 +675,18 @@ function advtrains.try_connect_trains(id1, id2) if not frontpos1 or not frontpos2 or not backpos1 or not backpos2 then return end + local couple_spawnradius=0.7 --case 1 (first train is front) - if vector.distance(frontpos2, backpos1)<0.5 then + if vector.distance(frontpos2, backpos1)<couple_spawnradius then advtrains.spawn_couple_if_neccessary(backpos1, frontpos2, id1, id2, true, false) --case 2 (second train is front) - elseif vector.distance(frontpos1, backpos2)<0.5 then + elseif vector.distance(frontpos1, backpos2)<couple_spawnradius then advtrains.spawn_couple_if_neccessary(backpos2, frontpos1, id2, id1, true, false) --case 3 - elseif vector.distance(backpos2, backpos1)<0.5 then + elseif vector.distance(backpos2, backpos1)<couple_spawnradius then advtrains.spawn_couple_if_neccessary(backpos1, backpos2, id1, id2, true, true) --case 4 - elseif vector.distance(frontpos2, frontpos1)<0.5 then + elseif vector.distance(frontpos2, frontpos1)<couple_spawnradius then advtrains.spawn_couple_if_neccessary(frontpos1, frontpos2, id1, id2, false, false) end end |