From 81d5cddac9003abc18e89c69e196172d975597f6 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Mon, 19 Apr 2021 17:12:33 -0700 Subject: [PATCH] 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. --- game/event/event.py | 2 -- game/theater/controlpoint.py | 6 +----- game/theater/supplyroutes.py | 7 +++++-- game/transfers.py | 4 +--- qt_ui/windows/basemenu/QBaseMenu2.py | 2 +- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/game/event/event.py b/game/event/event.py index 0d7daa8e..5f5917d3 100644 --- a/game/event/event.py +++ b/game/event/event.py @@ -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: diff --git a/game/theater/controlpoint.py b/game/theater/controlpoint.py index 9ce59a19..9b9558f4 100644 --- a/game/theater/controlpoint.py +++ b/game/theater/controlpoint.py @@ -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 diff --git a/game/theater/supplyroutes.py b/game/theater/supplyroutes.py index 72cf9602..eb02663d 100644 --- a/game/theater/supplyroutes.py +++ b/game/theater/supplyroutes.py @@ -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( diff --git a/game/transfers.py b/game/transfers.py index 9372df65..165b8030 100644 --- a/game/transfers.py +++ b/game/transfers.py @@ -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." diff --git a/qt_ui/windows/basemenu/QBaseMenu2.py b/qt_ui/windows/basemenu/QBaseMenu2.py index 8f287b6d..1dac5f43 100644 --- a/qt_ui/windows/basemenu/QBaseMenu2.py +++ b/qt_ui/windows/basemenu/QBaseMenu2.py @@ -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: