Remove weird single-CP supply route edge case.

A CP with a factory would be able to supply itself, but was not in a
supply route if it was the only connected friendly CP. When the player
starts with only one base against an enemy base this meant that it was
in no supply route, causing it to not be a recruitment location or a
place to buy more than a reserve of vehicles automatically.
This commit is contained in:
Dan Albert 2021-04-19 17:12:33 -07:00
parent bb3e83548c
commit 81d5cddac9
5 changed files with 8 additions and 13 deletions

View File

@ -551,8 +551,6 @@ class UnitsDeliveryEvent:
return self.destination
supply_route = SupplyRoute.for_control_point(self.destination)
if supply_route is None:
return None
sources = []
for control_point in supply_route:

View File

@ -346,11 +346,7 @@ class ControlPoint(MissionTarget, ABC):
from game.theater.supplyroutes import SupplyRoute
supply_route = SupplyRoute.for_control_point(self)
if supply_route is None:
return False
for cp in supply_route:
for cp in SupplyRoute.for_control_point(self):
if cp.can_recruit_ground_units(game):
return True
return False

View File

@ -42,11 +42,14 @@ class SupplyRoute:
def __iter__(self) -> Iterator[ControlPoint]:
yield from self.control_points
def __len__(self) -> int:
return len(self.control_points)
@classmethod
def for_control_point(cls, control_point: ControlPoint) -> Optional[SupplyRoute]:
def for_control_point(cls, control_point: ControlPoint) -> SupplyRoute:
connected_friendly_points = control_point.transitive_connected_friendly_points()
if not connected_friendly_points:
return None
return SupplyRoute([control_point])
return SupplyRoute([control_point] + connected_friendly_points)
def shortest_path_between(

View File

@ -40,8 +40,6 @@ class RoadTransferOrder(TransferOrder):
def path(self) -> List[ControlPoint]:
supply_route = SupplyRoute.for_control_point(self.position)
if supply_route is None:
raise RuntimeError(f"Supply route from {self.position.name} interrupted")
return supply_route.shortest_path_between(self.position, self.destination)
@ -83,7 +81,7 @@ class PendingTransfers:
return True
supply_route = SupplyRoute.for_control_point(transfer.destination)
if supply_route is None or transfer.position not in supply_route:
if transfer.position not in supply_route:
logging.info(
f"Route from {transfer.position.name} to {transfer.destination.name} "
"was cut off."

View File

@ -105,7 +105,7 @@ class QBaseMenu2(QDialog):
@property
def has_transfer_destinations(self) -> bool:
return SupplyRoute.for_control_point(self.cp) is not None
return len(SupplyRoute.for_control_point(self.cp)) > 1
@property
def can_repair_runway(self) -> bool: