From e96210f48cd88fcdd9e33e077430653b56fd0941 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Sun, 20 Jun 2021 23:41:30 -0700 Subject: [PATCH 1/2] Don't order transports for incapable factions. If these orders can't be fulfilled for the faction it will prevent the faction from ordering any non-reserve aircraft since transports are given priority after reserve missions, and they'll never be fulfillable. As such, no non-reserve aircraft will ever be purchased for factions without transport aircraft. Factions without transport aircraft are screwed in other ways, but this will fix their air planning for campaigns that aren't dependent on airlift. --- changelog.md | 1 + game/squadrons.py | 7 +++++++ game/transfers.py | 5 ++++- gen/flights/ai_flight_planner.py | 9 +-------- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/changelog.md b/changelog.md index d812dd86..2e8da9de 100644 --- a/changelog.md +++ b/changelog.md @@ -32,6 +32,7 @@ Saves from 3.x are not compatible with 4.0. ## Fixes * **[Campaign AI]** Fix procurement for factions that lack some unit types. +* **[Campaign AI]** Fix auto purchase of aircraft for factions that have no transport aircraft. * **[Mission Generation]** Fixed problem with mission load when control point name contained an apostrophe. * **[Mission Generation]** Fixed EWR group names so they contribute to Skynet again. * **[Mission Generation]** Fixed duplicate name error when generating convoys and cargo ships when creating manual transfers after loading a game. diff --git a/game/squadrons.py b/game/squadrons.py index c60d94de..4e465903 100644 --- a/game/squadrons.py +++ b/game/squadrons.py @@ -368,6 +368,13 @@ class AirWing: def squadrons_for(self, aircraft: AircraftType) -> Sequence[Squadron]: return self.squadrons[aircraft] + def can_auto_plan(self, task: FlightType) -> bool: + try: + next(self.auto_assignable_for_task(task)) + return True + except StopIteration: + return False + def auto_assignable_for_task(self, task: FlightType) -> Iterator[Squadron]: for squadron in self.iter_squadrons(): if squadron.can_auto_assign(task): diff --git a/game/transfers.py b/game/transfers.py index be0baaa8..0fd432f4 100644 --- a/game/transfers.py +++ b/game/transfers.py @@ -592,7 +592,10 @@ class PendingTransfers: def order_airlift_assets(self) -> None: for control_point in self.game.theater.controlpoints: - self.order_airlift_assets_at(control_point) + if self.game.air_wing_for(control_point.captured).can_auto_plan( + FlightType.TRANSPORT + ): + self.order_airlift_assets_at(control_point) @staticmethod def desired_airlift_capacity(control_point: ControlPoint) -> int: diff --git a/gen/flights/ai_flight_planner.py b/gen/flights/ai_flight_planner.py index 099c5296..77e5916f 100644 --- a/gen/flights/ai_flight_planner.py +++ b/gen/flights/ai_flight_planner.py @@ -604,14 +604,7 @@ class CoalitionMissionPlanner: also possible for the player to exclude mission types from their squadron designs. """ - all_compatible = aircraft_for_task(mission_type) - for squadron in self.game.air_wing_for(self.is_player).iter_squadrons(): - if ( - squadron.aircraft in all_compatible - and mission_type in squadron.auto_assignable_mission_types - ): - return True - return False + return self.game.air_wing_for(self.is_player).can_auto_plan(mission_type) def critical_missions(self) -> Iterator[ProposedMission]: """Identifies the most important missions to plan this turn. From 47e038c9fac61f0d04924dc1f2ea19b52de89c46 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Sun, 20 Jun 2021 23:46:06 -0700 Subject: [PATCH 2/2] Fix command line campaign generator. --- qt_ui/main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qt_ui/main.py b/qt_ui/main.py index 64051a36..744f90de 100644 --- a/qt_ui/main.py +++ b/qt_ui/main.py @@ -18,6 +18,7 @@ from game.data.weapons import ( WEAPON_INTRODUCTION_YEARS, Weapon, ) +from game.db import FACTIONS from game.profiling import logged_duration from game.settings import Settings from game.theater.start_generator import GameGenerator, GeneratorSettings, ModSettings @@ -199,8 +200,8 @@ def create_game( inject_custom_payloads(Path(persistency.base_path())) campaign = Campaign.from_json(campaign_path) generator = GameGenerator( - blue, - red, + FACTIONS[blue], + FACTIONS[red], campaign.load_theater(), Settings( supercarrier=supercarrier,