def plan_action_for_groups( self, stance: CombatStance, ally_groups: List[Tuple[VehicleGroup, CombatGroup]], enemy_groups: List[Tuple[VehicleGroup, CombatGroup]], forward_heading: int, from_cp: ControlPoint, to_cp: ControlPoint, ) -> None: if not self.game.settings.perf_moving_units: return for dcs_group, group in ally_groups: if group.unit_type.eplrs_capable: dcs_group.points[0].tasks.append(EPLRS(dcs_group.id)) if group.role == CombatGroupRole.ARTILLERY: if self.game.settings.perf_artillery: target = self.get_artillery_target_in_range( dcs_group, group, enemy_groups ) if target is not None: self._plan_artillery_action( stance, group, dcs_group, forward_heading, target ) elif group.role in [CombatGroupRole.TANK, CombatGroupRole.IFV]: self._plan_tank_ifv_action( stance, enemy_groups, dcs_group, forward_heading, to_cp ) elif group.role in [CombatGroupRole.APC, CombatGroupRole.ATGM]: self._plan_apc_atgm_action(stance, dcs_group, forward_heading, to_cp) if stance == CombatStance.RETREAT: # In retreat mode, the units will fall back # If the ally base is close enough, the units will even regroup there if ( from_cp.position.distance_to_point(dcs_group.points[0].position) <= RETREAT_DISTANCE ): retreat_point = from_cp.position.random_point_within(500, 250) else: retreat_point = self.find_retreat_point(dcs_group, forward_heading) reposition_point = retreat_point.point_from_heading( forward_heading, 10 ) # Another point to make the unit face the enemy dcs_group.add_waypoint(retreat_point, PointAction.OffRoad) dcs_group.add_waypoint(reposition_point, PointAction.OffRoad)
def enable_eplrs(group: Group, unit_type: UnitType) -> None: if hasattr(unit_type, 'eplrs'): if unit_type.eplrs: group.points[0].tasks.append(EPLRS(group.id))
def plan_action_for_groups(self, stance, ally_groups, enemy_groups, forward_heading, from_cp, to_cp): if not self.game.settings.perf_moving_units: return for dcs_group, group in ally_groups: if hasattr(group.units[0], 'eplrs'): if group.units[0].eplrs: dcs_group.points[0].tasks.append(EPLRS(dcs_group.id)) if group.role == CombatGroupRole.ARTILLERY: # Fire on any ennemy in range if self.game.settings.perf_artillery: target = self.get_artillery_target_in_range( dcs_group, group, enemy_groups) if target is not None: if stance != CombatStance.RETREAT: hold_task = Hold() hold_task.number = 1 dcs_group.add_trigger_action(hold_task) # Artillery strike random start artillery_trigger = TriggerOnce( Event.NoEvent, "ArtilleryFireTask #" + str(dcs_group.id)) artillery_trigger.add_condition( TimeAfter(seconds=random.randint(1, 45) * 60)) fire_task = FireAtPoint(target, len(group.units) * 10, 100) if stance != CombatStance.RETREAT: fire_task.number = 2 else: fire_task.number = 1 dcs_group.add_trigger_action(fire_task) artillery_trigger.add_action( AITaskPush(dcs_group.id, len(dcs_group.tasks))) self.mission.triggerrules.triggers.append( artillery_trigger) # Artillery will fall back when under attack if stance != CombatStance.RETREAT: # Hold position dcs_group.points[0].tasks.append(Hold()) retreat = self.find_retreat_point( dcs_group, forward_heading, (int)(RETREAT_DISTANCE / 3)) dcs_group.add_waypoint( dcs_group.position.point_from_heading( forward_heading, 1), PointAction.OffRoad) dcs_group.points[1].tasks.append(Hold()) dcs_group.add_waypoint(retreat, PointAction.OffRoad) artillery_fallback = TriggerOnce( Event.NoEvent, "ArtilleryRetreat #" + str(dcs_group.id)) for i, u in enumerate(dcs_group.units): artillery_fallback.add_condition( UnitDamaged(u.id)) if i < len(dcs_group.units) - 1: artillery_fallback.add_condition(Or()) hold_2 = Hold() hold_2.number = 3 dcs_group.add_trigger_action(hold_2) retreat_task = GoToWaypoint(toIndex=3) retreat_task.number = 4 dcs_group.add_trigger_action(retreat_task) artillery_fallback.add_action( AITaskPush(dcs_group.id, len(dcs_group.tasks))) self.mission.triggerrules.triggers.append( artillery_fallback) for u in dcs_group.units: u.initial = True u.heading = forward_heading + random.randint( -5, 5) elif group.role in [CombatGroupRole.TANK, CombatGroupRole.IFV]: if stance == CombatStance.AGGRESSIVE: # Attack nearest enemy if any # Then move forward OR Attack enemy base if it is not too far away target = self.find_nearest_enemy_group( dcs_group, enemy_groups) if target is not None: rand_offset = Point( random.randint(-RANDOM_OFFSET_ATTACK, RANDOM_OFFSET_ATTACK), random.randint(-RANDOM_OFFSET_ATTACK, RANDOM_OFFSET_ATTACK)) dcs_group.add_waypoint( target.points[0].position + rand_offset, PointAction.OffRoad) dcs_group.points[1].tasks.append(AttackGroup( target.id)) if to_cp.position.distance_to_point( dcs_group.points[0].position ) <= AGGRESIVE_MOVE_DISTANCE: attack_point = to_cp.position.random_point_within( 500, 0) else: attack_point = self.find_offensive_point( dcs_group, forward_heading, AGGRESIVE_MOVE_DISTANCE) dcs_group.add_waypoint(attack_point, PointAction.OnRoad) elif stance == CombatStance.BREAKTHROUGH: # In breakthrough mode, the units will move forward # If the enemy base is close enough, the units will attack the base if to_cp.position.distance_to_point( dcs_group.points[0].position ) <= BREAKTHROUGH_OFFENSIVE_DISTANCE: attack_point = to_cp.position.random_point_within( 500, 0) else: attack_point = self.find_offensive_point( dcs_group, forward_heading, BREAKTHROUGH_OFFENSIVE_DISTANCE) dcs_group.add_waypoint(attack_point, PointAction.OnRoad) elif stance == CombatStance.ELIMINATION: # In elimination mode, the units focus on destroying as much enemy groups as possible targets = self.find_n_nearest_enemy_groups( dcs_group, enemy_groups, 3) i = 1 for target in targets: rand_offset = Point( random.randint(-RANDOM_OFFSET_ATTACK, RANDOM_OFFSET_ATTACK), random.randint(-RANDOM_OFFSET_ATTACK, RANDOM_OFFSET_ATTACK)) dcs_group.add_waypoint( target.points[0].position + rand_offset, PointAction.OffRoad) dcs_group.points[i].tasks.append(AttackGroup( target.id)) i = i + 1 if to_cp.position.distance_to_point( dcs_group.points[0].position ) <= AGGRESIVE_MOVE_DISTANCE: attack_point = to_cp.position.random_point_within( 500, 0) dcs_group.add_waypoint(attack_point) if stance != CombatStance.RETREAT: self.add_morale_trigger(dcs_group, forward_heading) elif group.role in [CombatGroupRole.APC, CombatGroupRole.ATGM]: if stance in [ CombatStance.AGGRESSIVE, CombatStance.BREAKTHROUGH, CombatStance.ELIMINATION ]: # APC & ATGM will never move too much forward, but will follow along any offensive if to_cp.position.distance_to_point( dcs_group.points[0].position ) <= AGGRESIVE_MOVE_DISTANCE: attack_point = to_cp.position.random_point_within( 500, 0) else: attack_point = self.find_offensive_point( dcs_group, forward_heading, AGGRESIVE_MOVE_DISTANCE) dcs_group.add_waypoint(attack_point, PointAction.OnRoad) if stance != CombatStance.RETREAT: self.add_morale_trigger(dcs_group, forward_heading) if stance == CombatStance.RETREAT: # In retreat mode, the units will fall back # If the ally base is close enough, the units will even regroup there if from_cp.position.distance_to_point( dcs_group.points[0].position) <= RETREAT_DISTANCE: retreat_point = from_cp.position.random_point_within( 500, 250) else: retreat_point = self.find_retreat_point( dcs_group, forward_heading) reposition_point = retreat_point.point_from_heading( forward_heading, 10) # Another point to make the unit face the enemy dcs_group.add_waypoint(retreat_point, PointAction.OnRoad) dcs_group.add_waypoint(reposition_point, PointAction.OffRoad)
def create_mission(campaign): m = dcs.Mission(terrain.Caucasus()) # setup airports for name, airport in campaign.airports.items(): coal_name = airport.coalition.value print(coal_name) assert (m.terrain.airports[name].set_coalition(coal_name)) usa = m.country("USA") russia = m.country("Russia") sochi = m.terrain.sochi_adler() ship_pos = sochi.position - dcs.Point(50000, 50000) print(f"{sochi.position=}") print(f"{ship_pos=}") cvbg = m.ship_group(country=usa, name="CVN 74 Stennis", _type=ships.CVN_74_John_C__Stennis, position=ship_pos) tasks = cvbg.points[0].tasks tasks.append(ActivateICLSCommand(unit_id=cvbg.id, channel=5)) tasks.append( ActivateBeaconCommand(unit_id=cvbg.id, channel=69, callsign="STN", aa=False)) cvbg.add_waypoint(ship_pos + dcs.Point(0, -100 * 1000)) cvbg.add_waypoint(ship_pos + dcs.Point(-30 * 1000, -100 * 1000)) cvbg.add_waypoint(ship_pos + dcs.Point(-30 * 1000, 0)) # cvbg.add_waypoint(ship_pos) # cvbg.add_waypoint(ship_pos + dcs.Point(0, -100*1000)) # cvbg.add_waypoint(ship_pos + dcs.Point(-30*1000, -100*1000)) # cvbg.add_waypoint(ship_pos + dcs.Point(-30*1000, 0)) # cvbg.add_waypoint(ship_pos) name = namegen.next_unit_name(usa) fg = m.flight_group_from_unit(country=usa, name=name, aircraft_type=planes.FA_18C_hornet, maintask=None, start_type=StartType.Warm, pad_group=cvbg, group_size=4) fg.set_client() offset = dcs.Point(random() * 1000.0, random() * 1000.0) orientation = random() * 360. sa2_pos = sochi.position + offset p = fg.add_waypoint(ship_pos + dcs.Point(1000, 3000), feet_to_meters(8000)) pos = point_along_route(p.position, sochi.position, 50 * 2000) p = fg.add_waypoint(pos, feet_to_meters(26000)) fg.add_waypoint(point_along_route(p.position, sochi.position, -1000), feet_to_meters(26000)) fg.land_at(cvbg) make_sa2_site(m, russia, sa2_pos, orientation) awacs = m.awacs_flight(usa, "AWACS", planes.E_3A, None, dcs.Point(sochi.position.x + 20000, sochi.position.y + 80000), race_distance=80 * 1000, heading=90, speed=knots_to_kph(500), altitude=feet_to_meters(30000)) tasks = awacs.points[0].tasks tasks.append(EPLRS()) campaign.mission = m return m
def enable_eplrs(group: VehicleGroup, unit_type: Type[VehicleType]) -> None: if unit_type.eplrs: group.points[0].tasks.append(EPLRS(group.id))
def configure_eplrs(group: FlyingGroup[Any], flight: Flight) -> None: if flight.unit_type.eplrs_capable: group.points[0].tasks.append(EPLRS(group.id))