Dan Albert 87441b8939 Formalize waypoint actions.
Create a WaypointAction class that defines the actions taken at a
waypoint. These will often map one-to-one with DCS waypoint actions but
can also be higher level and generate multiple actions. Once everything
has migrated all waypoint-type-specific behaviors of
PydcsWaypointBuilder will be gone, and it'll be easier to keep the sim
behaviors in sync with the mission generator behaviors.

For now only hold has been migrated. This is actually probably the most
complicated action we have (starting with this may have been a mistake,
but it did find all the rough edges quickly) since it affects waypoint
timings and flight position during simulation. That part isn't handled
as neatly as I'd like because the FlightState still has to special case
LOITER points to avoid simulating the wrong waypoint position. At some
point we should probably start tracking real positions in FlightState,
and when we do that will be solved.
2023-08-13 12:43:59 -07:00

65 lines
2.3 KiB
Python

from datetime import datetime, timedelta
from game.ato.flightstate.actionstate import ActionState
from game.flightplan.waypointactions.hold import Hold
from game.flightplan.waypointactions.taskcontext import TaskContext
from game.utils import meters, kph
def test_hold_tasks() -> None:
t0 = datetime(1999, 3, 28)
tasks = list(
Hold(lambda: t0 + timedelta(minutes=5), meters(8000), kph(400)).iter_tasks(
TaskContext(t0 + timedelta(minutes=1))
)
)
assert len(tasks) == 1
task = tasks[0]
assert task.id == "ControlledTask"
assert task.params["stopCondition"]["time"] == 4 * 60
assert task.params["task"]["id"] == "Orbit"
assert task.params["task"]["params"]["altitude"] == 8000
assert task.params["task"]["params"]["pattern"] == "Circle"
assert task.params["task"]["params"]["speed"] == kph(400).meters_per_second
def test_hold_task_at_or_after_push() -> None:
t0 = datetime(1999, 3, 28)
assert not list(
Hold(lambda: t0, meters(8000), kph(400)).iter_tasks(TaskContext(t0))
)
assert not list(
Hold(lambda: t0, meters(8000), kph(400)).iter_tasks(
TaskContext(t0 + timedelta(minutes=1))
)
)
def test_hold_tick() -> None:
t0 = datetime(1999, 3, 28)
task = Hold(lambda: t0 + timedelta(minutes=5), meters(8000), kph(400))
state = ActionState(task)
task.update_state(state, t0, timedelta())
assert not state.is_finished()
task.update_state(state, t0 + timedelta(minutes=1), timedelta(minutes=1))
assert not state.is_finished()
task.update_state(state, t0 + timedelta(minutes=2), timedelta(minutes=1))
assert not state.is_finished()
task.update_state(state, t0 + timedelta(minutes=3), timedelta(minutes=1))
assert not state.is_finished()
task.update_state(state, t0 + timedelta(minutes=4), timedelta(minutes=1))
assert not state.is_finished()
task.update_state(state, t0 + timedelta(minutes=5), timedelta(minutes=1))
assert state.is_finished()
task.update_state(state, t0 + timedelta(minutes=6), timedelta(minutes=1))
assert state.is_finished()
def test_hold_description() -> None:
assert (
Hold(
lambda: datetime(1999, 3, 28) + timedelta(minutes=5), meters(8000), kph(400)
).describe()
== "Holding until 00:05:00"
)