Dan Albert 9e2e4ffa74 Update pydcs, adapt to new Point APIs.
This is briefly moving us over to my fork of pydcs while we wait for
https://github.com/pydcs/dcs/pull/206 to be merged. The adaptation is
invasive enough that I don't want it lingering for long.
2022-02-23 01:02:48 +00:00

47 lines
1.7 KiB
Python

import copy
from dcs.planes import B_17G, B_52H, Tu_22M3
from dcs.point import MovingPoint
from dcs.task import Bombing, OptFormation, WeaponType
from .pydcswaypointbuilder import PydcsWaypointBuilder
class StrikeIngressBuilder(PydcsWaypointBuilder):
def add_tasks(self, waypoint: MovingPoint) -> None:
if self.group.units[0].unit_type in [B_17G, B_52H, Tu_22M3]:
self.add_bombing_tasks(waypoint)
else:
self.add_strike_tasks(waypoint)
waypoint.tasks.append(OptFormation.trail_open())
def add_bombing_tasks(self, waypoint: MovingPoint) -> None:
targets = self.waypoint.targets
if not targets:
return
center = copy.copy(targets[0].position)
for target in targets[1:]:
center += target.position
center /= len(targets)
bombing = Bombing(center, weapon_type=WeaponType.Bombs)
bombing.params["expend"] = "All"
bombing.params["attackQtyLimit"] = False
bombing.params["directionEnabled"] = False
bombing.params["altitudeEnabled"] = False
bombing.params["groupAttack"] = True
waypoint.tasks.append(bombing)
def add_strike_tasks(self, waypoint: MovingPoint) -> None:
for target in self.waypoint.targets:
bombing = Bombing(target.position, weapon_type=WeaponType.Auto)
# If there is only one target, drop all ordnance in one pass.
if len(self.waypoint.targets) == 1:
bombing.params["expend"] = "All"
bombing.params["groupAttack"] = True
waypoint.tasks.append(bombing)
# Register special waypoints
self.register_special_waypoints(self.waypoint.targets)