mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Correct int/float confusion in Point APIs.
The heading and distance calculations always return floats.
This commit is contained in:
parent
a19a0b6789
commit
6ce02282e7
@ -1,10 +1,11 @@
|
|||||||
import itertools
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
|
import math
|
||||||
import random
|
import random
|
||||||
import sys
|
import sys
|
||||||
from datetime import date, datetime, timedelta
|
from datetime import date, datetime, timedelta
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, List, Type, Union
|
from typing import Any, List, Type, Union, cast
|
||||||
|
|
||||||
from dcs.action import Coalition
|
from dcs.action import Coalition
|
||||||
from dcs.mapping import Point
|
from dcs.mapping import Point
|
||||||
@ -614,7 +615,7 @@ class Game:
|
|||||||
# If there is no conflict take the center point between the two nearest opposing bases
|
# If there is no conflict take the center point between the two nearest opposing bases
|
||||||
if len(zones) == 0:
|
if len(zones) == 0:
|
||||||
cpoint = None
|
cpoint = None
|
||||||
min_distance = sys.maxsize
|
min_distance = math.inf
|
||||||
for cp in self.theater.player_points():
|
for cp in self.theater.player_points():
|
||||||
for cp2 in self.theater.enemy_points():
|
for cp2 in self.theater.enemy_points():
|
||||||
d = cp.position.distance_to_point(cp2.position)
|
d = cp.position.distance_to_point(cp2.position)
|
||||||
@ -651,7 +652,7 @@ class Game:
|
|||||||
self.__culling_zones = zones
|
self.__culling_zones = zones
|
||||||
|
|
||||||
def add_destroyed_units(self, data: dict[str, Union[float, str]]) -> None:
|
def add_destroyed_units(self, data: dict[str, Union[float, str]]) -> None:
|
||||||
pos = Point(data["x"], data["z"])
|
pos = Point(cast(float, data["x"]), cast(float, data["z"]))
|
||||||
if self.theater.is_on_land(pos):
|
if self.theater.is_on_land(pos):
|
||||||
self.__destroyed_units.append(data)
|
self.__destroyed_units.append(data)
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Iterable, List, Set, TYPE_CHECKING
|
from typing import Iterable, List, Set, TYPE_CHECKING, cast
|
||||||
|
|
||||||
from dcs import Mission
|
from dcs import Mission
|
||||||
from dcs.action import DoScript, DoScriptFile
|
from dcs.action import DoScript, DoScriptFile
|
||||||
@ -261,7 +261,7 @@ class Operation:
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
pos = Point(d["x"], d["z"])
|
pos = Point(cast(float, d["x"]), cast(float, d["z"]))
|
||||||
if (
|
if (
|
||||||
utype is not None
|
utype is not None
|
||||||
and not cls.game.position_culled(pos)
|
and not cls.game.position_culled(pos)
|
||||||
|
|||||||
@ -21,7 +21,7 @@ class MissionTarget:
|
|||||||
self.name = name
|
self.name = name
|
||||||
self.position = position
|
self.position = position
|
||||||
|
|
||||||
def distance_to(self, other: MissionTarget) -> int:
|
def distance_to(self, other: MissionTarget) -> float:
|
||||||
"""Computes the distance to the given mission target."""
|
"""Computes the distance to the given mission target."""
|
||||||
return self.position.distance_to_point(other.position)
|
return self.position.distance_to_point(other.position)
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import math
|
||||||
import random
|
import random
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import TYPE_CHECKING, List, Optional, Tuple
|
from typing import TYPE_CHECKING, List, Optional, Tuple
|
||||||
@ -655,7 +656,7 @@ class GroundConflictGenerator:
|
|||||||
@param group Group for which we should find the nearest ennemy
|
@param group Group for which we should find the nearest ennemy
|
||||||
@param enemy_groups Potential enemy groups
|
@param enemy_groups Potential enemy groups
|
||||||
"""
|
"""
|
||||||
min_distance = 99999999
|
min_distance = math.inf
|
||||||
target = None
|
target = None
|
||||||
for dcs_group, _ in enemy_groups:
|
for dcs_group, _ in enemy_groups:
|
||||||
dist = player_group.points[0].position.distance_to_point(
|
dist = player_group.points[0].position.distance_to_point(
|
||||||
@ -693,7 +694,7 @@ class GroundConflictGenerator:
|
|||||||
"""
|
"""
|
||||||
For artilery group, decide the distance from frontline with the range of the unit
|
For artilery group, decide the distance from frontline with the range of the unit
|
||||||
"""
|
"""
|
||||||
rg = getattr(group.unit_type.dcs_unit_type, "threat_range", 0) - 7500
|
rg = group.unit_type.dcs_unit_type.threat_range - 7500
|
||||||
if rg > DISTANCE_FROM_FRONTLINE[CombatGroupRole.ARTILLERY][1]:
|
if rg > DISTANCE_FROM_FRONTLINE[CombatGroupRole.ARTILLERY][1]:
|
||||||
rg = random.randint(
|
rg = random.randint(
|
||||||
DISTANCE_FROM_FRONTLINE[CombatGroupRole.ARTILLERY][0],
|
DISTANCE_FROM_FRONTLINE[CombatGroupRole.ARTILLERY][0],
|
||||||
|
|||||||
@ -375,9 +375,9 @@ class ObjectiveFinder:
|
|||||||
def _targets_by_range(
|
def _targets_by_range(
|
||||||
self, targets: Iterable[MissionTargetType]
|
self, targets: Iterable[MissionTargetType]
|
||||||
) -> Iterator[MissionTargetType]:
|
) -> Iterator[MissionTargetType]:
|
||||||
target_ranges: List[Tuple[MissionTargetType, int]] = []
|
target_ranges: list[tuple[MissionTargetType, float]] = []
|
||||||
for target in targets:
|
for target in targets:
|
||||||
ranges: List[int] = []
|
ranges: list[float] = []
|
||||||
for cp in self.friendly_control_points():
|
for cp in self.friendly_control_points():
|
||||||
ranges.append(target.distance_to(cp))
|
ranges.append(target.distance_to(cp))
|
||||||
target_ranges.append((target, min(ranges)))
|
target_ranges.append((target, min(ranges)))
|
||||||
@ -392,7 +392,7 @@ class ObjectiveFinder:
|
|||||||
Targets are sorted by their closest proximity to any friendly control
|
Targets are sorted by their closest proximity to any friendly control
|
||||||
point (airfield or fleet).
|
point (airfield or fleet).
|
||||||
"""
|
"""
|
||||||
targets: List[Tuple[TheaterGroundObject[Any], int]] = []
|
targets: list[tuple[TheaterGroundObject[Any], float]] = []
|
||||||
# Building objectives are made of several individual TGOs (one per
|
# Building objectives are made of several individual TGOs (one per
|
||||||
# building).
|
# building).
|
||||||
found_targets: Set[str] = set()
|
found_targets: Set[str] = set()
|
||||||
@ -431,7 +431,7 @@ class ObjectiveFinder:
|
|||||||
continue
|
continue
|
||||||
if ground_object.name in found_targets:
|
if ground_object.name in found_targets:
|
||||||
continue
|
continue
|
||||||
ranges: List[int] = []
|
ranges: list[float] = []
|
||||||
for friendly_cp in self.friendly_control_points():
|
for friendly_cp in self.friendly_control_points():
|
||||||
ranges.append(ground_object.distance_to(friendly_cp))
|
ranges.append(ground_object.distance_to(friendly_cp))
|
||||||
targets.append((ground_object, min(ranges)))
|
targets.append((ground_object, min(ranges)))
|
||||||
|
|||||||
@ -1207,10 +1207,12 @@ class FlightPlanBuilder:
|
|||||||
target = self.package.target.position
|
target = self.package.target.position
|
||||||
|
|
||||||
heading = self.package.waypoints.join.heading_between_point(target)
|
heading = self.package.waypoints.join.heading_between_point(target)
|
||||||
start = target.point_from_heading(heading, -self.doctrine.sweep_distance.meters)
|
start_pos = target.point_from_heading(
|
||||||
|
heading, -self.doctrine.sweep_distance.meters
|
||||||
|
)
|
||||||
|
|
||||||
builder = WaypointBuilder(flight, self.game, self.is_player)
|
builder = WaypointBuilder(flight, self.game, self.is_player)
|
||||||
start, end = builder.sweep(start, target, self.doctrine.ingress_altitude)
|
start, end = builder.sweep(start_pos, target, self.doctrine.ingress_altitude)
|
||||||
|
|
||||||
hold = builder.hold(self._hold_point(flight))
|
hold = builder.hold(self._hold_point(flight))
|
||||||
|
|
||||||
@ -1865,23 +1867,23 @@ class FlightPlanBuilder:
|
|||||||
return self._retreating_rendezvous_point(attack_transition)
|
return self._retreating_rendezvous_point(attack_transition)
|
||||||
return self._advancing_rendezvous_point(attack_transition)
|
return self._advancing_rendezvous_point(attack_transition)
|
||||||
|
|
||||||
def _ingress_point(self, heading: int) -> Point:
|
def _ingress_point(self, heading: float) -> Point:
|
||||||
return self.package.target.position.point_from_heading(
|
return self.package.target.position.point_from_heading(
|
||||||
heading - 180 + 15, self.doctrine.ingress_egress_distance.meters
|
heading - 180 + 15, self.doctrine.ingress_egress_distance.meters
|
||||||
)
|
)
|
||||||
|
|
||||||
def _egress_point(self, heading: int) -> Point:
|
def _egress_point(self, heading: float) -> Point:
|
||||||
return self.package.target.position.point_from_heading(
|
return self.package.target.position.point_from_heading(
|
||||||
heading - 180 - 15, self.doctrine.ingress_egress_distance.meters
|
heading - 180 - 15, self.doctrine.ingress_egress_distance.meters
|
||||||
)
|
)
|
||||||
|
|
||||||
def _target_heading_to_package_airfield(self) -> int:
|
def _target_heading_to_package_airfield(self) -> float:
|
||||||
return self._heading_to_package_airfield(self.package.target.position)
|
return self._heading_to_package_airfield(self.package.target.position)
|
||||||
|
|
||||||
def _heading_to_package_airfield(self, point: Point) -> int:
|
def _heading_to_package_airfield(self, point: Point) -> float:
|
||||||
return self.package_airfield().position.heading_between_point(point)
|
return self.package_airfield().position.heading_between_point(point)
|
||||||
|
|
||||||
def _distance_to_package_airfield(self, point: Point) -> int:
|
def _distance_to_package_airfield(self, point: Point) -> float:
|
||||||
return self.package_airfield().position.distance_to_point(point)
|
return self.package_airfield().position.distance_to_point(point)
|
||||||
|
|
||||||
def package_airfield(self) -> ControlPoint:
|
def package_airfield(self) -> ControlPoint:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user