aboutsummaryrefslogtreecommitdiff
path: root/advtrains/path.lua
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2018-04-23 15:51:50 +0200
committerorwell96 <orwell@bleipb.de>2018-06-14 17:39:42 +0200
commit30e98520e7e6fa17beaf3f1c328fd58e2b19cebc (patch)
tree623e3ae0a06b50423273cfdbbec261b76d0821f4 /advtrains/path.lua
parent064a454117e6f921926f808ad91829e4b73664c0 (diff)
downloadadvtrains-30e98520e7e6fa17beaf3f1c328fd58e2b19cebc.tar.gz
advtrains-30e98520e7e6fa17beaf3f1c328fd58e2b19cebc.tar.bz2
advtrains-30e98520e7e6fa17beaf3f1c328fd58e2b19cebc.zip
Occupation System, new train steps, still incomplete
Diffstat (limited to 'advtrains/path.lua')
-rw-r--r--advtrains/path.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/advtrains/path.lua b/advtrains/path.lua
index 43add95..a98a1b5 100644
--- a/advtrains/path.lua
+++ b/advtrains/path.lua
@@ -183,6 +183,13 @@ function advtrains.path_get(train, index)
train.path_dist[train.path_ext_b] = vector.distance(pos, adj_pos)
end
+ if index < train.path_req_b then
+ train.path_req_b = index
+ end
+ if index > train.path_req_f then
+ train.path_req_f = index
+ end
+
return train.path[index], (index<=train.path_trk_f and index>=train.path_trk_b)
end
@@ -233,3 +240,34 @@ function advtrains.path_get_index_by_offset(train, index, offset)
end
return index
end
+
+local PATH_CLEAR_KEEP = 2
+
+function advtrains.path_clear_unused(train)
+ for i = train.path_ext_b, train.path_req_b - PATH_CLEAR_KEEP do
+ train.path[i] = nil
+ train.path_dist[i] = nil
+ train.path_cp[i] = nil
+ train.path_cn[i] = nil
+ train.path_dir[i] = nil
+ end
+ for i = train.path_req_f + PATH_CLEAR_KEEP, train.path_ext_f do
+ train.path[i] = nil
+ train.path_dist[i-1] = nil
+ train.path_cp[i] = nil
+ train.path_cn[i] = nil
+ train.path_dir[i+1] = nil
+ end
+ train.path_req_f = math.ceil(train.index)
+ train.path_req_b = math.floor(train.end_index or train.index)
+end
+
+function advtrains.path_lookup(train, pos)
+ local cp = advtrains.round_vector_floor_y(pos)
+ for i = train.path_ext_b, train.path_ext_f do
+ if vector.equals(advtrains.round_vector_floor_y(train.path[i]), cp) then
+ return i
+ end
+ end
+ return nil
+end