summaryrefslogtreecommitdiff
path: root/game/vehicles/vehicle.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-02-14 16:44:00 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-02-14 16:44:00 +0000
commit4562557d599fd70d32b15313ffebd976c3ddfa7d (patch)
tree54d0a6798be87fb1f38f2152c12e60b1dc033639 /game/vehicles/vehicle.cpp
parentBroken down Brush47 (diff)
downloadilt-4562557d599fd70d32b15313ffebd976c3ddfa7d.tar.bz2
ilt-4562557d599fd70d32b15313ffebd976c3ddfa7d.tar.xz
ilt-4562557d599fd70d32b15313ffebd976c3ddfa7d.zip
Maintain a history of links traversed
Diffstat (limited to 'game/vehicles/vehicle.cpp')
-rw-r--r--game/vehicles/vehicle.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/game/vehicles/vehicle.cpp b/game/vehicles/vehicle.cpp
index c12181f..569063d 100644
--- a/game/vehicles/vehicle.cpp
+++ b/game/vehicles/vehicle.cpp
@@ -5,6 +5,34 @@
#include <utility>
Vehicle::Vehicle(const LinkPtr & l, const std::string & obj, const std::string & tex) :
- Physical(l->ends.front().first->pos, obj, tex), link(l)
+ Physical(l->ends.front().first->pos, obj, tex)
{
+ linkHist.add(l, 0);
+}
+
+LinkHistory::Return
+LinkHistory::add(const LinkWPtr & l, unsigned char d)
+{
+ links.insert(links.begin(), {l, d});
+ const auto lp = l.lock();
+ totalLen += lp->length;
+ while (totalLen >= 1000.F && !links.empty()) {
+ totalLen -= links.back().first.lock()->length;
+ links.pop_back();
+ }
+ return {lp, d};
+}
+
+LinkHistory::Return
+LinkHistory::getAt(float len) const
+{
+ auto litr = links.begin();
+ while (len > 0.F && litr != links.end()) {
+ len -= litr->first.lock()->length;
+ litr++;
+ }
+ if (litr == links.end()) {
+ litr--;
+ }
+ return {litr->first.lock(), litr->second};
}