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.
This commit is contained in:
Dan Albert 2022-03-07 18:19:09 -08:00
parent a6a44ef433
commit e95a9e0685
2 changed files with 7 additions and 1 deletions

View File

@ -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

View File

@ -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 (