def _frontline_vector(self, from_cp: ControlPoint, to_cp: ControlPoint): # Cache mechanism to avoid performing frontline vector computation on every frame key = str(from_cp.id) + "_" + str(to_cp.id) if key in self.frontline_vector_cache: return self.frontline_vector_cache[key] else: frontline = Conflict.frontline_vector(from_cp, to_cp, self.game.theater) self.frontline_vector_cache[key] = frontline return frontline
def generate_frontline_cap(self, flight, ally_cp, enemy_cp): """ Generate a cap flight for the frontline between ally_cp and enemy cp in order to ensure air superiority and protect friendly CAP airbase :param flight: Flight to setup :param ally_cp: CP to protect :param enemy_cp: Enemy connected cp """ flight.flight_type = FlightType.CAP patrol_alt = random.randint(self.doctrine["PATROL_ALT_RANGE"][0], self.doctrine["PATROL_ALT_RANGE"][1]) # Find targets waypoints ingress, heading, distance = Conflict.frontline_vector( ally_cp, enemy_cp, self.game.theater) center = ingress.point_from_heading(heading, distance / 2) orbit_center = center.point_from_heading( heading - 90, random.randint(nm_to_meter(6), nm_to_meter(15))) combat_width = distance / 2 if combat_width > 500000: combat_width = 500000 if combat_width < 35000: combat_width = 35000 radius = combat_width * 1.25 orbit0p = orbit_center.point_from_heading(heading, radius) orbit1p = orbit_center.point_from_heading(heading + 180, radius) # Create points ascend = self.generate_ascend_point(flight.from_cp) flight.points.append(ascend) orbit0 = FlightWaypoint(orbit0p.x, orbit0p.y, patrol_alt) orbit0.name = "ORBIT 0" orbit0.description = "Standby between this point and the next one" orbit0.pretty_name = "Race-track start" orbit0.waypoint_type = FlightWaypointType.PATROL_TRACK flight.points.append(orbit0) orbit1 = FlightWaypoint(orbit1p.x, orbit1p.y, patrol_alt) orbit1.name = "ORBIT 1" orbit1.description = "Standby between this point and the previous one" orbit1.pretty_name = "Race-track end" orbit1.waypoint_type = FlightWaypointType.PATROL flight.points.append(orbit1) # Note : Targets of a PATROL TRACK waypoints are the points to be defended orbit0.targets.append(flight.from_cp) orbit0.targets.append(center) descend = self.generate_descend_point(flight.from_cp) flight.points.append(descend) rtb = self.generate_rtb_waypoint(flight.from_cp) flight.points.append(rtb)
def generate_cas(self, flight, from_cp, location): """ Generate a CAS flight at a given location :param flight: Flight to setup :param location: Location of the CAS targets """ is_helo = hasattr(flight.unit_type, "helicopter") and flight.unit_type.helicopter cap_alt = 1000 flight.points = [] flight.flight_type = FlightType.CAS ingress, heading, distance = Conflict.frontline_vector( from_cp, location, self.game.theater) center = ingress.point_from_heading(heading, distance / 2) egress = ingress.point_from_heading(heading, distance) ascend = self.generate_ascend_point(flight.from_cp) if is_helo: cap_alt = 500 ascend.alt = 500 flight.points.append(ascend) ingress_point = FlightWaypoint(ingress.x, ingress.y, cap_alt) ingress_point.alt_type = "RADIO" ingress_point.name = "INGRESS" ingress_point.pretty_name = "INGRESS" ingress_point.description = "Ingress into CAS area" ingress_point.waypoint_type = FlightWaypointType.INGRESS_CAS flight.points.append(ingress_point) center_point = FlightWaypoint(center.x, center.y, cap_alt) center_point.alt_type = "RADIO" center_point.description = "Provide CAS" center_point.name = "CAS" center_point.pretty_name = "CAS" center_point.waypoint_type = FlightWaypointType.CAS flight.points.append(center_point) egress_point = FlightWaypoint(egress.x, egress.y, cap_alt) egress_point.alt_type = "RADIO" egress_point.description = "Egress from CAS area" egress_point.name = "EGRESS" egress_point.pretty_name = "EGRESS" egress_point.waypoint_type = FlightWaypointType.EGRESS flight.points.append(egress_point) descend = self.generate_descend_point(flight.from_cp) if is_helo: descend.alt = 300 flight.points.append(descend) rtb = self.generate_rtb_waypoint(flight.from_cp) flight.points.append(rtb)
def draw_actual_frontline(self, frontline: FrontLine, scene: QGraphicsScene, pen: QPen) -> None: self.draw_bezier_frontline(scene, pen, frontline) vector = Conflict.frontline_vector(frontline.control_point_a, frontline.control_point_b, self.game.theater) left_pos = self._transform_point(vector[0]) right_pos = self._transform_point(vector[0].point_from_heading( vector[1], vector[2])) scene.addItem( QFrontLine(left_pos[0], left_pos[1], right_pos[0], right_pos[1], frontline, self.game_model))
def for_faction(cls, game: Game, player: bool) -> ThreatZones: """Generates the threat zones projected by the given coalition. Args: game: The game to generate the threat zone for. player: True if the coalition projecting the threat zone belongs to the player. Returns: The threat zones projected by the given coalition. If the threat zone belongs to the player, it is the zone that will be avoided by the enemy and vice versa. """ air_threats = [] air_defenses = [] for control_point in game.theater.controlpoints: if control_point.captured != player: continue if control_point.runway_is_operational(): point = ShapelyPoint(control_point.position.x, control_point.position.y) cap_threat_range = cls.barcap_threat_range(game, control_point) air_threats.append(point.buffer(cap_threat_range.meters)) for tgo in control_point.ground_objects: for group in tgo.groups: threat_range = tgo.threat_range(group) # Any system with a shorter range than this is not worth # even avoiding. if threat_range > nautical_miles(3): point = ShapelyPoint(tgo.position.x, tgo.position.y) threat_zone = point.buffer(threat_range.meters) air_defenses.append(threat_zone) for front_line in game.theater.conflicts(player): vector = Conflict.frontline_vector(front_line.control_point_a, front_line.control_point_b, game.theater) start = vector[0] end = vector[0].point_from_heading(vector[1], vector[2]) line = LineString([ ShapelyPoint(start.x, start.y), ShapelyPoint(end.x, end.y), ]) doctrine = game.faction_for(player).doctrine air_threats.append( line.buffer(doctrine.cap_engagement_range.meters)) return cls(airbases=unary_union(air_threats), air_defenses=unary_union(air_defenses))