mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Converted closest_friendly_control_points_to from returning a tuple of the two closest control points to returning a list of all in sorted order.
This commit is contained in:
parent
992beb5f45
commit
b99a719d1c
@ -23,6 +23,8 @@ from game.missiongenerator.missiondata import MissionData
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from game import Game
|
from game import Game
|
||||||
|
|
||||||
|
PRETENSE_NUMBER_OF_ZONES_TO_CONNECT_CARRIERS_TO = 2
|
||||||
|
|
||||||
|
|
||||||
class PretenseLuaGenerator(LuaGenerator):
|
class PretenseLuaGenerator(LuaGenerator):
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -324,23 +326,28 @@ class PretenseLuaGenerator(LuaGenerator):
|
|||||||
if len(cp.connected_points) == 0 and len(cp.shipping_lanes) == 0:
|
if len(cp.connected_points) == 0 and len(cp.shipping_lanes) == 0:
|
||||||
# Also connect carrier and LHA control points to adjacent friendly points
|
# Also connect carrier and LHA control points to adjacent friendly points
|
||||||
if cp.is_fleet:
|
if cp.is_fleet:
|
||||||
|
num_of_carrier_connections = 0
|
||||||
for (
|
for (
|
||||||
other_cp
|
other_cp
|
||||||
) in self.game.theater.closest_friendly_control_points_to(cp):
|
) in self.game.theater.closest_friendly_control_points_to(cp):
|
||||||
|
num_of_carrier_connections += 1
|
||||||
|
if (
|
||||||
|
num_of_carrier_connections
|
||||||
|
> PRETENSE_NUMBER_OF_ZONES_TO_CONNECT_CARRIERS_TO
|
||||||
|
):
|
||||||
|
break
|
||||||
|
|
||||||
lua_string_connman += (
|
lua_string_connman += (
|
||||||
f" cm: addConnection('{cp.name}', '{other_cp.name}')\n"
|
f" cm: addConnection('{cp.name}', '{other_cp.name}')\n"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# Finally, connect remaining non-connected points
|
# Finally, connect remaining non-connected points
|
||||||
(
|
closest_cps = self.game.theater.closest_friendly_control_points_to(cp)
|
||||||
closest_cp,
|
|
||||||
second_closest_cp,
|
|
||||||
) = self.game.theater.closest_friendly_control_points_to(cp)
|
|
||||||
lua_string_connman += (
|
lua_string_connman += (
|
||||||
f" cm: addConnection('{cp.name}', '{closest_cp.name}')\n"
|
f" cm: addConnection('{cp.name}', '{closest_cps[0].name}')\n"
|
||||||
)
|
)
|
||||||
lua_string_connman += (
|
lua_string_connman += (
|
||||||
f" cm: addConnection('{cp.name}', '{second_closest_cp.name}')\n"
|
f" cm: addConnection('{cp.name}', '{closest_cps[1].name}')\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
init_body_1_file = open("./resources/plugins/pretense/init_body_1.lua", "r")
|
init_body_1_file = open("./resources/plugins/pretense/init_body_1.lua", "r")
|
||||||
|
|||||||
@ -204,13 +204,11 @@ class ConflictTheater:
|
|||||||
|
|
||||||
def closest_friendly_control_points_to(
|
def closest_friendly_control_points_to(
|
||||||
self, cp: ControlPoint
|
self, cp: ControlPoint
|
||||||
) -> Tuple[ControlPoint, ControlPoint]:
|
) -> List[ControlPoint]:
|
||||||
"""
|
"""
|
||||||
Returns a tuple of the two nearest friendly ControlPoints in theater to ControlPoint cp.
|
Returns a list of the friendly ControlPoints in theater to ControlPoint cp, sorted closest to farthest.
|
||||||
(closest_cp, second_closest_cp)
|
|
||||||
"""
|
"""
|
||||||
closest_cp = None
|
closest_cps = list()
|
||||||
second_closest_cp = None
|
|
||||||
distances_to_cp = dict()
|
distances_to_cp = dict()
|
||||||
if cp.captured:
|
if cp.captured:
|
||||||
control_points = self.player_points()
|
control_points = self.player_points()
|
||||||
@ -223,18 +221,9 @@ class ConflictTheater:
|
|||||||
dist = other_cp.position.distance_to_point(cp.position)
|
dist = other_cp.position.distance_to_point(cp.position)
|
||||||
distances_to_cp[dist] = other_cp
|
distances_to_cp[dist] = other_cp
|
||||||
for i in sorted(distances_to_cp.keys()):
|
for i in sorted(distances_to_cp.keys()):
|
||||||
other_cp = distances_to_cp[i]
|
closest_cps.append(distances_to_cp[i])
|
||||||
if closest_cp is None:
|
|
||||||
closest_cp = other_cp
|
|
||||||
continue
|
|
||||||
elif second_closest_cp is None:
|
|
||||||
second_closest_cp = other_cp
|
|
||||||
break
|
|
||||||
break
|
|
||||||
|
|
||||||
assert closest_cp is not None
|
return closest_cps
|
||||||
assert second_closest_cp is not None
|
|
||||||
return closest_cp, second_closest_cp
|
|
||||||
|
|
||||||
def find_control_point_by_id(self, cp_id: UUID) -> ControlPoint:
|
def find_control_point_by_id(self, cp_id: UUID) -> ControlPoint:
|
||||||
for i in self.controlpoints:
|
for i in self.controlpoints:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user