From 41d68b7145ddf5ac0e7b2fd7f0d22e428b356230 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 14 Feb 2021 17:32:00 +0000 Subject: Correctly follow rails according to wheelbase --- game/vehicles/vehicle.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'game/vehicles/vehicle.cpp') diff --git a/game/vehicles/vehicle.cpp b/game/vehicles/vehicle.cpp index 569063d..f722cff 100644 --- a/game/vehicles/vehicle.cpp +++ b/game/vehicles/vehicle.cpp @@ -24,15 +24,26 @@ LinkHistory::add(const LinkWPtr & l, unsigned char d) } LinkHistory::Return -LinkHistory::getAt(float len) const +LinkHistory::getCurrent() const +{ + return {links.front().first.lock(), links.front().second}; +} + +LinkHistory::Return +LinkHistory::getAt(float len, float * rem) const { auto litr = links.begin(); while (len > 0.F && litr != links.end()) { - len -= litr->first.lock()->length; litr++; + if (litr != links.end()) { + len -= litr->first.lock()->length; + } } if (litr == links.end()) { litr--; } + if (rem) { + *rem = -len; + } return {litr->first.lock(), litr->second}; } -- cgit v1.2.3