From bde22b52eac90f88c506d891c39e7b7495f443bb Mon Sep 17 00:00:00 2001 From: MetalStormGhost Date: Sat, 10 Sep 2022 10:55:01 +0300 Subject: [PATCH] Attempt at fixing Carrier killed in state.json but not being removed from game, issue #2405. GenericCarrierGenerator.generate() will now generate the ship group with an array that only contains alive ship units, just like GroundObjectGenerator.generate() has previously done. Carrier groups will now also show up as destroyed/damaged on the map when the carrier is sunk. cherry-pick from e53dc5b80b77154db5271cc9f03bb9e98f79febe --- game/missiongenerator/tgogenerator.py | 14 ++++++++++++-- game/theater/controlpoint.py | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/game/missiongenerator/tgogenerator.py b/game/missiongenerator/tgogenerator.py index 7b43e3e3..42bc6e6b 100644 --- a/game/missiongenerator/tgogenerator.py +++ b/game/missiongenerator/tgogenerator.py @@ -405,7 +405,17 @@ class GenericCarrierGenerator(GroundObjectGenerator): logging.warning(f"Found empty carrier group in {self.control_point}") continue - ship_group = self.create_ship_group(group.group_name, group.units, atc) + ship_units = [] + for unit in group.units: + if unit.alive: + # All alive Ships + ship_units.append(unit) + + if not ship_units: + # Empty array (no alive units), stop here + return + + ship_group = self.create_ship_group(group.group_name, ship_units, atc) # Always steam into the wind, even if the carrier is being moved. # There are multiple unsimulated hours between turns, so we can @@ -414,7 +424,7 @@ class GenericCarrierGenerator(GroundObjectGenerator): brc = self.steam_into_wind(ship_group) # Set Carrier Specific Options - if g_id == 0: + if g_id == 0 and self.control_point.runway_is_operational(): # Get Correct unit type for the carrier. # This will upgrade to super carrier if option is enabled carrier_type = self.carrier_type diff --git a/game/theater/controlpoint.py b/game/theater/controlpoint.py index edf2c35e..f79dcf6c 100644 --- a/game/theater/controlpoint.py +++ b/game/theater/controlpoint.py @@ -1200,7 +1200,7 @@ class NavalControlPoint(ControlPoint, ABC): # while its escorts are still alive. for group in self.find_main_tgo().groups: for u in group.units: - if u.type in [ + if u.alive and u.type in [ Forrestal, Stennis, LHA_Tarawa,