From a32a8447028798ef05af33230fbcfa3195ab430c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 8 Mar 2021 20:03:40 +0000 Subject: Initial commit of the orders/activities system Has the main window provide some control over our test train --- game/vehicles/train.cpp | 19 +++++++++++++++++++ game/vehicles/train.h | 7 ++++++- game/vehicles/vehicle.cpp | 6 ++++++ game/vehicles/vehicle.h | 7 ++++++- 4 files changed, 37 insertions(+), 2 deletions(-) (limited to 'game/vehicles') 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 @@ -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 { +class Train : public Vehicle, public Collection, public Can, public Can { 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(&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 #include +#include #include #include #include @@ -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; -- cgit v1.2.3