diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-03-16 18:29:37 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-03-16 18:29:37 +0000 |
commit | ea35e8ede4c3a522375d4539c872e8a6d6c9830a (patch) | |
tree | b0569f5ffe9b92b407bde67f501a0a79a2cf78e5 /game/vehicles | |
parent | Allow activities to be changed when doing them (diff) | |
download | ilt-ea35e8ede4c3a522375d4539c872e8a6d6c9830a.tar.bz2 ilt-ea35e8ede4c3a522375d4539c872e8a6d6c9830a.tar.xz ilt-ea35e8ede4c3a522375d4539c872e8a6d6c9830a.zip |
Implement goto so node
Encompasses determining a route and a distance to travel
Diffstat (limited to 'game/vehicles')
-rw-r--r-- | game/vehicles/train.cpp | 20 | ||||
-rw-r--r-- | game/vehicles/vehicle.cpp | 5 |
2 files changed, 19 insertions, 6 deletions
diff --git a/game/vehicles/train.cpp b/game/vehicles/train.cpp index 874db46..14753c0 100644 --- a/game/vehicles/train.cpp +++ b/game/vehicles/train.cpp @@ -6,6 +6,7 @@ #include "location.hpp" #include <algorithm> #include <functional> +#include <optional> #include <utility> void @@ -33,11 +34,24 @@ Train::tick(TickDuration dur) } void -Train::doActivity(Go *, TickDuration dur) +Train::doActivity(Go * go, TickDuration dur) { const auto maxSpeed = objects.front()->rvClass->maxSpeed; - if (speed != maxSpeed) { - speed += ((maxSpeed - speed) * dur.count()); + if (go->dist) { + *go->dist -= speed * dur.count(); + if (*go->dist < (speed * speed) / 60.F) { + speed -= std::min(speed, 30.F * dur.count()); + } + else { + if (speed != maxSpeed) { + speed += ((maxSpeed - speed) * dur.count()); + } + } + } + else { + if (speed != maxSpeed) { + speed += ((maxSpeed - speed) * dur.count()); + } } } diff --git a/game/vehicles/vehicle.cpp b/game/vehicles/vehicle.cpp index cd2331d..8730d6d 100644 --- a/game/vehicles/vehicle.cpp +++ b/game/vehicles/vehicle.cpp @@ -1,8 +1,8 @@ #include "vehicle.h" +#include "game/activities/idle.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" #include <algorithm> @@ -18,8 +18,7 @@ Vehicle::Vehicle(const LinkPtr & l, float ld) : linkDist {ld} { linkHist.add(l, 0); - orders.create<FreeRoam>(&orders); - currentActivity = orders.current()->createActivity(); + currentActivity = std::make_unique<Idle>(); } void |