summaryrefslogtreecommitdiff
path: root/game/vehicles
diff options
context:
space:
mode:
Diffstat (limited to 'game/vehicles')
-rw-r--r--game/vehicles/train.cpp19
-rw-r--r--game/vehicles/train.h7
-rw-r--r--game/vehicles/vehicle.cpp6
-rw-r--r--game/vehicles/vehicle.h7
4 files changed, 37 insertions, 2 deletions
diff --git a/game/vehicles/train.cpp b/game/vehicles/train.cpp
index e211f16..f7b5515 100644
--- a/game/vehicles/train.cpp
+++ b/game/vehicles/train.cpp
@@ -1,6 +1,7 @@
#include "train.h"
#include "game/vehicles/linkHistory.h"
#include "game/vehicles/railVehicle.h"
+#include "game/vehicles/railVehicleClass.h"
#include "gfx/renderable.h"
#include "location.hpp"
#include <algorithm>
@@ -53,8 +54,26 @@ Train::getBogiePosition(float linkDist, float dist) const
void
Train::tick(TickDuration dur)
{
+ currentActivity->apply(this, dur);
move(dur);
float trailBy {0.F};
apply(&RailVehicle::move, this, std::ref(trailBy));
}
+
+void
+Train::doActivity(const Go *, TickDuration dur)
+{
+ const auto maxSpeed = objects.front()->rvClass->maxSpeed;
+ if (speed != maxSpeed) {
+ speed += ((maxSpeed - speed) * dur.count());
+ }
+}
+
+void
+Train::doActivity(const Idle *, TickDuration dur)
+{
+ if (speed != 0.F) {
+ speed -= std::min(speed, 30.F * dur.count());
+ }
+}
diff --git a/game/vehicles/train.h b/game/vehicles/train.h
index 34a9d28..a7d4b1b 100644
--- a/game/vehicles/train.h
+++ b/game/vehicles/train.h
@@ -1,6 +1,9 @@
#ifndef TRAIN_H
#define TRAIN_H
+#include "game/activities/go.h" // IWYU pragma: keep
+#include "game/activities/idle.h" // IWYU pragma: keep
+#include "game/activity.h"
#include "game/network/link.h"
#include "game/worldobject.h"
#include "railVehicle.h"
@@ -12,7 +15,7 @@
class Shader;
-class Train : public Vehicle, public Collection<RailVehicle, false> {
+class Train : public Vehicle, public Collection<RailVehicle, false>, public Can<Go>, public Can<Idle> {
public:
explicit Train(const LinkPtr & link, float linkDist = 0) : Vehicle {link, linkDist} { }
@@ -25,6 +28,8 @@ public:
void render(const Shader & shader) const override;
void tick(TickDuration elapsed) override;
+ 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 d98533e..d3cae1d 100644
--- a/game/vehicles/vehicle.cpp
+++ b/game/vehicles/vehicle.cpp
@@ -1,8 +1,14 @@
#include "vehicle.h"
+#include "game/activity.h"
#include "game/network/link.h"
+#include "game/objective.h"
+#include "game/objectives/freeroam.h"
+#include "game/orders.h"
#include "game/vehicles/linkHistory.h"
Vehicle::Vehicle(const LinkPtr & l, float ld) : linkDist {ld}
{
linkHist.add(l, 0);
+ orders.create<FreeRoam>(&orders);
+ currentActivity = orders.current()->createActivity();
}
diff --git a/game/vehicles/vehicle.h b/game/vehicles/vehicle.h
index 659821f..c4c8beb 100644
--- a/game/vehicles/vehicle.h
+++ b/game/vehicles/vehicle.h
@@ -2,7 +2,9 @@
#define VEHICLE_H
#include "linkHistory.h"
+#include <game/activity.h>
#include <game/network/link.h>
+#include <game/orders.h>
#include <game/worldobject.h>
#include <gfx/renderable.h>
#include <memory>
@@ -13,9 +15,12 @@ class Vehicle : public WorldObject, public Renderable {
public:
explicit Vehicle(const LinkPtr & link, float linkDist = 0);
float linkDist; // distance along current link
- float speed {50}; // speed in m/s (~75 km/h)
+ float speed {}; // speed in m/s (~75 km/h)
[[nodiscard]] virtual const Location & getLocation() const = 0;
+ Orders orders;
+
+ ActivityPtr currentActivity;
protected:
LinkHistory linkHist;