summaryrefslogtreecommitdiff
path: root/game/vehicles
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-03-09 00:28:33 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-03-09 00:28:33 +0000
commitea8ae67d068fc5a1a2229e1ed17c795498024c71 (patch)
treea845feb41885843e68a291886c60fc476f0e9e12 /game/vehicles
parentInitial commit of the orders/activities system (diff)
downloadilt-ea8ae67d068fc5a1a2229e1ed17c795498024c71.tar.bz2
ilt-ea8ae67d068fc5a1a2229e1ed17c795498024c71.tar.xz
ilt-ea8ae67d068fc5a1a2229e1ed17c795498024c71.zip
Push link based movement into Vehicle
I think it's fair to make all vehicles uses links and nodes to navigate... even if those links, nodes are private to that vehicle
Diffstat (limited to 'game/vehicles')
-rw-r--r--game/vehicles/train.cpp29
-rw-r--r--game/vehicles/train.h1
-rw-r--r--game/vehicles/vehicle.cpp34
-rw-r--r--game/vehicles/vehicle.h1
4 files changed, 35 insertions, 30 deletions
diff --git a/game/vehicles/train.cpp b/game/vehicles/train.cpp
index f7b5515..f887be4 100644
--- a/game/vehicles/train.cpp
+++ b/game/vehicles/train.cpp
@@ -5,39 +5,10 @@
#include "gfx/renderable.h"
#include "location.hpp"
#include <algorithm>
-#include <array>
#include <functional>
-#include <glm/glm.hpp>
-#include <iterator>
-#include <maths.h>
-#include <random>
#include <utility>
void
-Train::move(TickDuration dur)
-{
- static std::mt19937 gen(std::random_device {}());
- linkDist += dur.count() * speed;
- auto curLink {linkHist.getCurrent()};
- while (linkDist > curLink.first->length) {
- const auto location = curLink.first->positionAt(curLink.first->length, curLink.second);
- auto nexts {curLink.first->nexts[1 - curLink.second]};
- auto last = std::remove_if(nexts.begin(), nexts.end(), [ang = location.rot.y](const Link::Next & n) {
- return std::abs(normalize(n.first.lock()->ends[n.second].second - ang)) > 0.1F;
- });
- if (last != nexts.begin()) {
- auto off = std::uniform_int_distribution<>(0, std::distance(nexts.begin(), last) - 1)(gen);
- linkDist -= curLink.first->length;
- curLink = linkHist.add(nexts[off].first, nexts[off].second);
- }
- else {
- linkDist = curLink.first->length;
- speed = 0;
- }
- }
-}
-
-void
Train::render(const Shader & shader) const
{
apply(&Renderable::render, shader);
diff --git a/game/vehicles/train.h b/game/vehicles/train.h
index a7d4b1b..fb94102 100644
--- a/game/vehicles/train.h
+++ b/game/vehicles/train.h
@@ -31,7 +31,6 @@ public:
void doActivity(const Go *, TickDuration) override;
void doActivity(const Idle *, TickDuration) override;
- void move(TickDuration dur);
[[nodiscard]] Location getBogiePosition(float linkDist, float dist) const;
};
diff --git a/game/vehicles/vehicle.cpp b/game/vehicles/vehicle.cpp
index d3cae1d..db61564 100644
--- a/game/vehicles/vehicle.cpp
+++ b/game/vehicles/vehicle.cpp
@@ -5,6 +5,16 @@
#include "game/objectives/freeroam.h"
#include "game/orders.h"
#include "game/vehicles/linkHistory.h"
+#include <algorithm>
+#include <array>
+#include <game/worldobject.h>
+#include <glm/glm.hpp>
+#include <iterator>
+#include <location.hpp>
+#include <maths.h>
+#include <random>
+#include <utility>
+#include <vector>
Vehicle::Vehicle(const LinkPtr & l, float ld) : linkDist {ld}
{
@@ -12,3 +22,27 @@ Vehicle::Vehicle(const LinkPtr & l, float ld) : linkDist {ld}
orders.create<FreeRoam>(&orders);
currentActivity = orders.current()->createActivity();
}
+
+void
+Vehicle::move(TickDuration dur)
+{
+ static std::mt19937 gen(std::random_device {}());
+ linkDist += dur.count() * speed;
+ auto curLink {linkHist.getCurrent()};
+ while (linkDist > curLink.first->length) {
+ const auto location = curLink.first->positionAt(curLink.first->length, curLink.second);
+ auto nexts {curLink.first->nexts[1 - curLink.second]};
+ auto last = std::remove_if(nexts.begin(), nexts.end(), [ang = location.rot.y](const Link::Next & n) {
+ return std::abs(normalize(n.first.lock()->ends[n.second].second - ang)) > 0.1F;
+ });
+ if (last != nexts.begin()) {
+ auto off = std::uniform_int_distribution<>(0, std::distance(nexts.begin(), last) - 1)(gen);
+ linkDist -= curLink.first->length;
+ curLink = linkHist.add(nexts[off].first, nexts[off].second);
+ }
+ else {
+ linkDist = curLink.first->length;
+ speed = 0;
+ }
+ }
+}
diff --git a/game/vehicles/vehicle.h b/game/vehicles/vehicle.h
index c4c8beb..1fc8365 100644
--- a/game/vehicles/vehicle.h
+++ b/game/vehicles/vehicle.h
@@ -23,6 +23,7 @@ public:
ActivityPtr currentActivity;
protected:
+ void move(TickDuration dur);
LinkHistory linkHist;
};
using VehicleWPtr = std::weak_ptr<Vehicle>;