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:
MetalStormGhost 2023-09-16 21:08:06 +03:00
parent 992beb5f45
commit b99a719d1c
2 changed files with 18 additions and 22 deletions

View File

@ -23,6 +23,8 @@ from game.missiongenerator.missiondata import MissionData
if TYPE_CHECKING:
from game import Game
PRETENSE_NUMBER_OF_ZONES_TO_CONNECT_CARRIERS_TO = 2
class PretenseLuaGenerator(LuaGenerator):
def __init__(
@ -324,23 +326,28 @@ class PretenseLuaGenerator(LuaGenerator):
if len(cp.connected_points) == 0 and len(cp.shipping_lanes) == 0:
# Also connect carrier and LHA control points to adjacent friendly points
if cp.is_fleet:
num_of_carrier_connections = 0
for (
other_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 += (
f" cm: addConnection('{cp.name}', '{other_cp.name}')\n"
)
else:
# Finally, connect remaining non-connected points
(
closest_cp,
second_closest_cp,
) = self.game.theater.closest_friendly_control_points_to(cp)
closest_cps = self.game.theater.closest_friendly_control_points_to(cp)
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 += (
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")

View File

@ -204,13 +204,11 @@ class ConflictTheater:
def closest_friendly_control_points_to(
self, cp: ControlPoint
) -> Tuple[ControlPoint, ControlPoint]:
) -> List[ControlPoint]:
"""
Returns a tuple of the two nearest friendly ControlPoints in theater to ControlPoint cp.
(closest_cp, second_closest_cp)
Returns a list of the friendly ControlPoints in theater to ControlPoint cp, sorted closest to farthest.
"""
closest_cp = None
second_closest_cp = None
closest_cps = list()
distances_to_cp = dict()
if cp.captured:
control_points = self.player_points()
@ -223,18 +221,9 @@ class ConflictTheater:
dist = other_cp.position.distance_to_point(cp.position)
distances_to_cp[dist] = other_cp
for i in sorted(distances_to_cp.keys()):
other_cp = 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
closest_cps.append(distances_to_cp[i])
assert closest_cp is not None
assert second_closest_cp is not None
return closest_cp, second_closest_cp
return closest_cps
def find_control_point_by_id(self, cp_id: UUID) -> ControlPoint:
for i in self.controlpoints: