Now connects more isolated zones in Pretense.

This commit is contained in:
MetalStormGhost 2023-09-16 17:21:28 +03:00
parent 529841bfe4
commit 13e7e976c3
2 changed files with 39 additions and 12 deletions

View File

@ -305,7 +305,7 @@ class PretenseLuaGenerator(LuaGenerator):
lua_string_zones += " }\n"
lua_string_zones += "})\n"
lua_string_connman = " cm = ConnectionManager:new()"
lua_string_connman = " cm = ConnectionManager:new()\n"
# Generate ConnectionManager connections
for cp in self.game.theater.controlpoints:
@ -313,14 +313,32 @@ class PretenseLuaGenerator(LuaGenerator):
lua_string_connman += (
f" cm: addConnection('{cp.name}', '{other_cp.name}')\n"
)
# Also connect carrier and LHA control points to adjacent friendly points
if cp.is_fleet and len(cp.connected_points) == 0:
for other_cp in self.game.theater.closest_friendly_control_points_to(
cp
):
for sea_connection in cp.shipping_lanes:
if sea_connection.is_friendly_to(cp):
lua_string_connman += (
f" cm: addConnection('{cp.name}', '{other_cp.name}')\n"
f" cm: addConnection('{cp.name}', '{sea_connection.name}')\n"
)
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:
for (
other_cp
) in self.game.theater.closest_friendly_control_points_to(cp):
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)
lua_string_connman += (
f" cm: addConnection('{cp.name}', '{closest_cp.name}')\n"
)
lua_string_connman += (
f" cm: addConnection('{cp.name}', '{second_closest_cp.name}')\n"
)
init_body_1_file = open("./resources/plugins/pretense/init_body_1.lua", "r")
init_body_1 = init_body_1_file.read()

View File

@ -209,10 +209,9 @@ class ConflictTheater:
Returns a tuple of the two nearest friendly ControlPoints in theater to ControlPoint cp.
(closest_cp, second_closest_cp)
"""
seen = set()
min_distance = math.inf
closest_cp = None
second_closest_cp = None
distances_to_cp = dict()
if cp.captured:
control_points = self.player_points()
else:
@ -220,11 +219,21 @@ class ConflictTheater:
for other_cp in control_points:
if cp == other_cp:
continue
print(f"{cp}: {other_cp} being evaluated...")
dist = other_cp.position.distance_to_point(cp.position)
if dist < min_distance:
second_closest_cp = closest_cp
print(f" {other_cp} is at {dist} meters")
distances_to_cp[dist] = other_cp
for i in sorted(distances_to_cp.keys()):
other_cp = distances_to_cp[i]
print(f" {other_cp} is at {i} meters")
if closest_cp is None:
closest_cp = other_cp
min_distance = dist
continue
elif second_closest_cp is None:
second_closest_cp = other_cp
break
break
assert closest_cp is not None
assert second_closest_cp is not None