mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Rename confusing front line methods/members.
This commit is contained in:
parent
900948f7c2
commit
46ddd884a2
@ -54,7 +54,7 @@ class FrontLineConflictDescription:
|
||||
def frontline_position(
|
||||
cls, frontline: FrontLine, theater: ConflictTheater, settings: Settings
|
||||
) -> Tuple[Point, Heading]:
|
||||
attack_heading = frontline.attack_heading
|
||||
attack_heading = frontline.blue_forward_heading
|
||||
position = cls.find_ground_position(
|
||||
frontline.position,
|
||||
settings.max_frontline_length * 1000,
|
||||
|
||||
@ -23,10 +23,12 @@ class FrontLineJs(BaseModel):
|
||||
@staticmethod
|
||||
def for_front_line(front_line: FrontLine) -> FrontLineJs:
|
||||
a = front_line.position.point_from_heading(
|
||||
front_line.attack_heading.right.degrees, nautical_miles(2).meters
|
||||
front_line.blue_forward_heading.right.degrees,
|
||||
nautical_miles(2).meters,
|
||||
)
|
||||
b = front_line.position.point_from_heading(
|
||||
front_line.attack_heading.left.degrees, nautical_miles(2).meters
|
||||
front_line.blue_forward_heading.left.degrees,
|
||||
nautical_miles(2).meters,
|
||||
)
|
||||
return FrontLineJs(id=front_line.id, extents=[a.latlng(), b.latlng()])
|
||||
|
||||
|
||||
@ -28,12 +28,12 @@ class FrontLineSegment:
|
||||
point_b: Point
|
||||
|
||||
@property
|
||||
def attack_heading(self) -> Heading:
|
||||
"""The heading of the frontline segment from player to enemy control point"""
|
||||
def blue_forward_heading(self) -> Heading:
|
||||
"""The heading toward the start of the next red segment or red base."""
|
||||
return Heading.from_degrees(self.point_a.heading_between_point(self.point_b))
|
||||
|
||||
@property
|
||||
def attack_distance(self) -> float:
|
||||
def length(self) -> float:
|
||||
"""Length of the segment"""
|
||||
return self.point_a.distance_to_point(self.point_b)
|
||||
|
||||
@ -81,7 +81,7 @@ class FrontLine(MissionTarget):
|
||||
return hash(id(self))
|
||||
|
||||
def _compute_position(self) -> Point:
|
||||
return self.point_from_a(self._position_distance)
|
||||
return self.point_along_route_from_blue(self._blue_route_progress)
|
||||
|
||||
def update_position(self) -> None:
|
||||
self.position = self._compute_position()
|
||||
@ -122,54 +122,52 @@ class FrontLine(MissionTarget):
|
||||
return self.blue_cp, self.red_cp
|
||||
|
||||
@property
|
||||
def attack_distance(self) -> float:
|
||||
def route_length(self) -> float:
|
||||
"""The total distance of all segments"""
|
||||
return sum(i.attack_distance for i in self.segments)
|
||||
return sum(i.length for i in self.segments)
|
||||
|
||||
@property
|
||||
def attack_heading(self) -> Heading:
|
||||
"""The heading of the active attack segment from player to enemy control point"""
|
||||
return self.active_segment.attack_heading
|
||||
def blue_forward_heading(self) -> Heading:
|
||||
"""The heading toward the start of the next red segment or red base."""
|
||||
return self.active_segment.blue_forward_heading
|
||||
|
||||
@property
|
||||
def active_segment(self) -> FrontLineSegment:
|
||||
"""The FrontLine segment where there can be an active conflict"""
|
||||
if self._position_distance <= self.segments[0].attack_distance:
|
||||
if self._blue_route_progress <= self.segments[0].length:
|
||||
return self.segments[0]
|
||||
|
||||
remaining_dist = self._position_distance
|
||||
distance_to_segment = self._blue_route_progress
|
||||
for segment in self.segments:
|
||||
if remaining_dist <= segment.attack_distance:
|
||||
if distance_to_segment <= segment.length:
|
||||
return segment
|
||||
else:
|
||||
remaining_dist -= segment.attack_distance
|
||||
distance_to_segment -= segment.length
|
||||
logging.error(
|
||||
"Frontline attack distance is greater than the sum of its segments"
|
||||
)
|
||||
return self.segments[0]
|
||||
|
||||
def point_from_a(self, distance: float) -> Point:
|
||||
"""
|
||||
Returns a point {distance} away from control_point_a along the frontline segments.
|
||||
"""
|
||||
if distance < self.segments[0].attack_distance:
|
||||
def point_along_route_from_blue(self, distance: float) -> Point:
|
||||
"""Returns a point {distance} away from control_point_a along the route."""
|
||||
if distance < self.segments[0].length:
|
||||
return self.blue_cp.position.point_from_heading(
|
||||
self.segments[0].attack_heading.degrees, distance
|
||||
self.segments[0].blue_forward_heading.degrees, distance
|
||||
)
|
||||
remaining_dist = distance
|
||||
for segment in self.segments:
|
||||
if remaining_dist < segment.attack_distance:
|
||||
if remaining_dist < segment.length:
|
||||
return segment.point_a.point_from_heading(
|
||||
segment.attack_heading.degrees, remaining_dist
|
||||
segment.blue_forward_heading.degrees, remaining_dist
|
||||
)
|
||||
else:
|
||||
remaining_dist -= segment.attack_distance
|
||||
remaining_dist -= segment.length
|
||||
raise RuntimeError(
|
||||
f"Could not find front line point {distance} from {self.blue_cp}"
|
||||
)
|
||||
|
||||
@property
|
||||
def _position_distance(self) -> float:
|
||||
def _blue_route_progress(self) -> float:
|
||||
"""
|
||||
The distance from point "a" where the conflict should occur
|
||||
according to the current strength of each control point
|
||||
@ -178,20 +176,20 @@ class FrontLine(MissionTarget):
|
||||
if self.blue_cp.base.strength == 0:
|
||||
return self._adjust_for_min_dist(0)
|
||||
if self.red_cp.base.strength == 0:
|
||||
return self._adjust_for_min_dist(self.attack_distance)
|
||||
return self._adjust_for_min_dist(self.route_length)
|
||||
strength_pct = self.blue_cp.base.strength / total_strength
|
||||
return self._adjust_for_min_dist(strength_pct * self.attack_distance)
|
||||
return self._adjust_for_min_dist(strength_pct * self.route_length)
|
||||
|
||||
def _adjust_for_min_dist(self, distance: float) -> float:
|
||||
"""
|
||||
Ensures the frontline conflict is never located within the minimum distance
|
||||
constant of either end control point.
|
||||
"""
|
||||
if (distance > self.attack_distance / 2) and (
|
||||
distance + FRONTLINE_MIN_CP_DISTANCE > self.attack_distance
|
||||
if (distance > self.route_length / 2) and (
|
||||
distance + FRONTLINE_MIN_CP_DISTANCE > self.route_length
|
||||
):
|
||||
distance = self.attack_distance - FRONTLINE_MIN_CP_DISTANCE
|
||||
elif (distance < self.attack_distance / 2) and (
|
||||
distance = self.route_length - FRONTLINE_MIN_CP_DISTANCE
|
||||
elif (distance < self.route_length / 2) and (
|
||||
distance < FRONTLINE_MIN_CP_DISTANCE
|
||||
):
|
||||
distance = FRONTLINE_MIN_CP_DISTANCE
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user