aboutsummaryrefslogtreecommitdiff
path: root/advtrains
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2018-10-10 22:41:59 +0200
committerorwell96 <orwell@bleipb.de>2018-10-10 22:41:59 +0200
commit842a85606e4495dd631c2916d09a760d74a0ce13 (patch)
treef28bb815ecd01681f98166578c659aef48082b2a /advtrains
parent33c839b40d48e154f5b03619a9bdce1bed1fc602 (diff)
downloadadvtrains-842a85606e4495dd631c2916d09a760d74a0ce13.tar.gz
advtrains-842a85606e4495dd631c2916d09a760d74a0ce13.tar.bz2
advtrains-842a85606e4495dd631c2916d09a760d74a0ce13.zip
Properly implement invalidate_all_paths, recheck lzb on aspect change
Diffstat (limited to 'advtrains')
-rw-r--r--advtrains/occupation.lua20
-rw-r--r--advtrains/trainlogic.lua29
2 files changed, 32 insertions, 17 deletions
diff --git a/advtrains/occupation.lua b/advtrains/occupation.lua
index dd0235a..568f308 100644
--- a/advtrains/occupation.lua
+++ b/advtrains/occupation.lua
@@ -208,7 +208,7 @@ function o.get_occupations(train, index)
return r, pos
end
-- Gets a mapping of train id's to indexes of trains that stand or drive over
--- returns (table with train_id->index), position
+-- returns (table with train_id->index)
function o.get_trains_at(ppos)
local pos = advtrains.round_vector_floor_y(ppos)
local t = occget(pos)
@@ -226,4 +226,22 @@ function o.get_trains_at(ppos)
return r
end
+-- Gets a mapping of train id's to indexes of trains that have a path
+-- generated over this node
+-- returns (table with train_id->index)
+function o.get_trains_over(ppos)
+ local pos = advtrains.round_vector_floor_y(ppos)
+ local t = occget(pos)
+ if not t then return {} end
+ local r = {}
+ local i = 1
+ while t[i] do
+ local train = advtrains.trains[t[i]]
+ local idx = t[i+1]
+ r[t[i]] = idx
+ i = i + 2
+ end
+ return r
+end
+
advtrains.occ = o
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index f26f7da..7147787 100644
--- a/advtrains/trainlogic.lua
+++ b/advtrains/trainlogic.lua
@@ -1037,26 +1037,23 @@ function advtrains.get_train_at_pos(pos)
end
end
+
+-- ehm... I never adapted this function to the new path system ?!
function advtrains.invalidate_all_paths(pos)
- --if a position is given, only invalidate inside a radius to save performance
- local inv_radius=50
- atprint("invalidating all paths")
- for k,v in pairs(advtrains.trains) do
- local exec=true
- if pos and v.path and v.index and v.end_index then
- --start and end pos of the train
- local cmp1=v.path[atround(v.index)]
- local cmp2=v.path[atround(v.end_index)]
- if vector.distance(pos, cmp1)>inv_radius and vector.distance(pos, cmp2)>inv_radius then
- exec=false
- end
- end
- if exec then
- advtrains.invalidate_path(k)
- end
+ local tab
+ if pos then
+ -- if position given, check occupation system
+ tab = advtrains.occ.get_trains_over(pos)
+ else
+ tab = advtrains.trains
+ end
+
+ for id, _ in pairs(tab) do
+ advtrains.invalidate_path(id)
end
end
function advtrains.invalidate_path(id)
+ atdebug("Path invalidate:",id)
local v=advtrains.trains[id]
if not v then return end
advtrains.path_invalidate(v)