From ea35e8ede4c3a522375d4539c872e8a6d6c9830a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 16 Mar 2021 18:29:37 +0000 Subject: Implement goto so node Encompasses determining a route and a distance to travel --- game/vehicles/train.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'game/vehicles/train.cpp') 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 #include +#include #include 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()); + } } } -- cgit v1.2.3