From e95a9e0685aa482c92b4555b2c4d177188d25d54 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Mon, 7 Mar 2022 18:19:09 -0800 Subject: [PATCH] Stop ticking elapsed waypoints. If the parent tick caused the flight to move to the next waypoint, we shouldn't send events for the elapsed waypoint. --- game/ato/flightstate/inflight.py | 2 ++ game/ato/flightstate/navigating.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/game/ato/flightstate/inflight.py b/game/ato/flightstate/inflight.py index 0f97d635..541c9f27 100644 --- a/game/ato/flightstate/inflight.py +++ b/game/ato/flightstate/inflight.py @@ -29,6 +29,7 @@ class InFlight(FlightState, ABC): self.next_waypoint = waypoints[self.waypoint_index + 1] self.total_time_to_next_waypoint = self.travel_time_between_waypoints() self.elapsed_time = timedelta() + self.current_waypoint_elapsed = False @property def in_flight(self) -> bool: @@ -91,6 +92,7 @@ class InFlight(FlightState, ABC): def advance_to_next_waypoint(self) -> None: self.flight.set_state(self.next_waypoint_state()) + self.current_waypoint_elapsed = True def on_game_tick( self, events: GameUpdateEvents, time: datetime, duration: timedelta diff --git a/game/ato/flightstate/navigating.py b/game/ato/flightstate/navigating.py index 4ea5a14c..11c9c750 100644 --- a/game/ato/flightstate/navigating.py +++ b/game/ato/flightstate/navigating.py @@ -22,7 +22,11 @@ class Navigating(InFlight): self, events: GameUpdateEvents, time: datetime, duration: timedelta ) -> None: super().on_game_tick(events, time, duration) - events.update_flight_position(self.flight, self.estimate_position()) + + # If the parent tick caused this waypoint to become inactive don't update the + # position based on our now invalid state. + if not self.current_waypoint_elapsed: + events.update_flight_position(self.flight, self.estimate_position()) def progress(self) -> float: return (