From 283efc44ce78001ebd17f64555eb795e36b27a61 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Sat, 27 May 2023 12:09:10 +0200 Subject: 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 --- advtrains/path.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'advtrains/path.lua') 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) -- cgit v1.2.3