diff options
author | orwell96 <orwell@bleipb.de> | 2023-05-27 12:09:10 +0200 |
---|---|---|
committer | orwell96 <orwell@bleipb.de> | 2023-05-27 12:09:10 +0200 |
commit | 283efc44ce78001ebd17f64555eb795e36b27a61 (patch) | |
tree | c5be0288a325fa561e544cb0d86b1bfaa4f27adc /advtrains/path.lua | |
parent | bbe3856e3547aea133001f746cb72d439e5ed01d (diff) | |
download | advtrains-283efc44ce78001ebd17f64555eb795e36b27a61.tar.gz advtrains-283efc44ce78001ebd17f64555eb795e36b27a61.tar.bz2 advtrains-283efc44ce78001ebd17f64555eb795e36b27a61.zip |
Add function to get wagon in train from index
Can be used to determine which wagon is at a certain world position
Testing: use debugitems.lua
Diffstat (limited to 'advtrains/path.lua')
-rw-r--r-- | advtrains/path.lua | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/advtrains/path.lua b/advtrains/path.lua index f2b8a13..19387b1 100644 --- a/advtrains/path.lua +++ b/advtrains/path.lua @@ -375,6 +375,19 @@ function advtrains.path_get_index_by_offset(train, index, offset) return c_idx + frac end + +-- The path_dist[] table contains absolute distance values for every whole index. +-- Use this function to retrieve the correct absolute distance for a fractional index value (interpolate between floor and ceil index) +-- returns: absolute distance from path item 0 +function advtrains.path_get_path_dist_fractional(train, index) + local start_index_f = atfloor(index) + local frac = index - start_index_f + -- ensure path exists + advtrains.path_get_adjacent(train, index) + local dist1, dist2 = train.path_dist[start_index_f], train.path_dist[start_index_f+1] + return dist1 + (dist2-dist1)*frac +end + local PATH_CLEAR_KEEP = 4 function advtrains.path_clear_unused(train) |