mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Roll-over excess time from tasks.
This commit is contained in:
parent
8c6b360e65
commit
c00f853f34
@ -21,5 +21,5 @@ class ActionState:
|
|||||||
def is_finished(self) -> bool:
|
def is_finished(self) -> bool:
|
||||||
return self._finished
|
return self._finished
|
||||||
|
|
||||||
def on_game_tick(self, time: datetime, duration: timedelta) -> None:
|
def on_game_tick(self, time: datetime, duration: timedelta) -> timedelta:
|
||||||
self.action.update_state(self, time, duration)
|
return self.action.update_state(self, time, duration)
|
||||||
|
|||||||
@ -6,7 +6,6 @@ from datetime import datetime, timedelta
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from dcs import Point
|
from dcs import Point
|
||||||
from dcs.task import Task
|
|
||||||
|
|
||||||
from game.ato.flightstate import Completed
|
from game.ato.flightstate import Completed
|
||||||
from game.ato.flightstate.actionstate import ActionState
|
from game.ato.flightstate.actionstate import ActionState
|
||||||
@ -111,10 +110,11 @@ class InFlight(FlightState, ABC):
|
|||||||
def on_game_tick(
|
def on_game_tick(
|
||||||
self, events: GameUpdateEvents, time: datetime, duration: timedelta
|
self, events: GameUpdateEvents, time: datetime, duration: timedelta
|
||||||
) -> None:
|
) -> None:
|
||||||
if (action := self.current_action) is not None:
|
while (action := self.current_action) is not None:
|
||||||
action.on_game_tick(time, duration)
|
duration = action.on_game_tick(time, duration)
|
||||||
if action.is_finished():
|
if action.is_finished():
|
||||||
self.pending_actions.popleft()
|
self.pending_actions.popleft()
|
||||||
|
if duration <= timedelta():
|
||||||
return
|
return
|
||||||
|
|
||||||
self.elapsed_time += duration
|
self.elapsed_time += duration
|
||||||
|
|||||||
@ -32,9 +32,12 @@ class Hold(WaypointAction):
|
|||||||
|
|
||||||
def update_state(
|
def update_state(
|
||||||
self, state: ActionState, time: datetime, duration: timedelta
|
self, state: ActionState, time: datetime, duration: timedelta
|
||||||
) -> None:
|
) -> timedelta:
|
||||||
if self._push_time_provider() <= time:
|
push_time = self._push_time_provider()
|
||||||
|
if push_time <= time:
|
||||||
state.finish()
|
state.finish()
|
||||||
|
return time - push_time
|
||||||
|
return timedelta()
|
||||||
|
|
||||||
def iter_tasks(self, ctx: TaskContext) -> Iterator[Task]:
|
def iter_tasks(self, ctx: TaskContext) -> Iterator[Task]:
|
||||||
remaining_time = self._push_time_provider() - ctx.mission_start_time
|
remaining_time = self._push_time_provider() - ctx.mission_start_time
|
||||||
|
|||||||
@ -21,7 +21,7 @@ class WaypointAction(ABC):
|
|||||||
@abstractmethod
|
@abstractmethod
|
||||||
def update_state(
|
def update_state(
|
||||||
self, state: ActionState, time: datetime, duration: timedelta
|
self, state: ActionState, time: datetime, duration: timedelta
|
||||||
) -> None:
|
) -> timedelta:
|
||||||
...
|
...
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
|||||||
@ -14,8 +14,8 @@ class TestAction(WaypointAction):
|
|||||||
|
|
||||||
def update_state(
|
def update_state(
|
||||||
self, state: ActionState, time: datetime, duration: timedelta
|
self, state: ActionState, time: datetime, duration: timedelta
|
||||||
) -> None:
|
) -> timedelta:
|
||||||
pass
|
return timedelta()
|
||||||
|
|
||||||
def iter_tasks(self, ctx: TaskContext) -> Iterator[Task]:
|
def iter_tasks(self, ctx: TaskContext) -> Iterator[Task]:
|
||||||
yield from []
|
yield from []
|
||||||
|
|||||||
@ -39,19 +39,21 @@ def test_hold_tick() -> None:
|
|||||||
t0 = datetime(1999, 3, 28)
|
t0 = datetime(1999, 3, 28)
|
||||||
task = Hold(lambda: t0 + timedelta(minutes=5), meters(8000), kph(400))
|
task = Hold(lambda: t0 + timedelta(minutes=5), meters(8000), kph(400))
|
||||||
state = ActionState(task)
|
state = ActionState(task)
|
||||||
task.update_state(state, t0, timedelta())
|
assert not task.update_state(state, t0, timedelta())
|
||||||
assert not state.is_finished()
|
assert not state.is_finished()
|
||||||
task.update_state(state, t0 + timedelta(minutes=1), timedelta(minutes=1))
|
assert not task.update_state(state, t0 + timedelta(minutes=1), timedelta(minutes=1))
|
||||||
assert not state.is_finished()
|
assert not state.is_finished()
|
||||||
task.update_state(state, t0 + timedelta(minutes=2), timedelta(minutes=1))
|
assert not task.update_state(state, t0 + timedelta(minutes=2), timedelta(minutes=1))
|
||||||
assert not state.is_finished()
|
assert not state.is_finished()
|
||||||
task.update_state(state, t0 + timedelta(minutes=3), timedelta(minutes=1))
|
assert not task.update_state(state, t0 + timedelta(minutes=3), timedelta(minutes=1))
|
||||||
assert not state.is_finished()
|
assert not state.is_finished()
|
||||||
task.update_state(state, t0 + timedelta(minutes=4), timedelta(minutes=1))
|
assert not task.update_state(state, t0 + timedelta(minutes=4), timedelta(minutes=1))
|
||||||
assert not state.is_finished()
|
assert not state.is_finished()
|
||||||
task.update_state(state, t0 + timedelta(minutes=5), timedelta(minutes=1))
|
assert not task.update_state(state, t0 + timedelta(minutes=5), timedelta(minutes=1))
|
||||||
assert state.is_finished()
|
assert state.is_finished()
|
||||||
task.update_state(state, t0 + timedelta(minutes=6), timedelta(minutes=1))
|
assert task.update_state(
|
||||||
|
state, t0 + timedelta(minutes=6), timedelta(minutes=1)
|
||||||
|
) == timedelta(minutes=1)
|
||||||
assert state.is_finished()
|
assert state.is_finished()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user