diff --git a/game/event/baseattack.py b/game/event/baseattack.py index dc356f0c..98b0bd52 100644 --- a/game/event/baseattack.py +++ b/game/event/baseattack.py @@ -61,7 +61,7 @@ class BaseAttackEvent(Event): self.to_cp.captured = False def player_defending(self, flights: ScrambledFlightsDict): - assert len(flights) == 1 and flights[CAP], "Invalid scrambled flights" + assert CAP in flights and len(flights) == 1, "Invalid scrambled flights" cas = self.from_cp.base.scramble_cas(self.game.settings.multiplier) escort = self.from_cp.base.scramble_sweep(self.game.settings.multiplier) @@ -83,7 +83,7 @@ class BaseAttackEvent(Event): self.operation = op def player_attacking(self, flights: ScrambledFlightsDict): - assert flights[CAP] and flights[CAS] and flights[PinpointStrike] and len(flights) == 3, "Invalid flights" + assert CAP in flights and CAS in flights and PinpointStrike in flights and len(flights) == 3, "Invalid flights" op = BaseAttackOperation(game=self.game, attacker_name=self.attacker_name, diff --git a/game/event/event.py b/game/event/event.py index db39a61a..e771a9f7 100644 --- a/game/event/event.py +++ b/game/event/event.py @@ -68,10 +68,10 @@ class Event: return self.operation.is_successfull(debriefing) def player_attacking(self, flights: ScrambledFlightsDict): - pass + assert False def player_defending(self, flights: ScrambledFlightsDict): - pass + assert False def generate(self): self.operation.is_awacs_enabled = self.is_awacs_enabled diff --git a/game/event/frontlineattack.py b/game/event/frontlineattack.py index 8a32b704..90e8ec0f 100644 --- a/game/event/frontlineattack.py +++ b/game/event/frontlineattack.py @@ -70,7 +70,7 @@ class FrontlineAttackEvent(Event): self.to_cp.base.affect_strength(-0.1) def player_attacking(self, flights: ScrambledFlightsDict): - assert flights[CAS] and flights[PinpointStrike] and len(flights) == 2, "Invalid flights" + assert CAS in flights and PinpointStrike in flights and len(flights) == 2, "Invalid flights" self.defenders = self.to_cp.base.assemble_attack() diff --git a/game/event/frontlinepatrol.py b/game/event/frontlinepatrol.py index 3f1acef0..3413dfbc 100644 --- a/game/event/frontlinepatrol.py +++ b/game/event/frontlinepatrol.py @@ -35,20 +35,6 @@ class FrontlinePatrolEvent(Event): def __str__(self): return "Frontline CAP" - """ - def is_successfull(self, debriefing: Debriefing): - total_targets = sum(self.cas.values()) - destroyed_targets = 0 - for unit, count in debriefing.destroyed_units[self.defender_name].items(): - if unit in self.cas: - destroyed_targets += count - - if self.from_cp.captured: - return float(destroyed_targets) / total_targets >= self.SUCCESS_TARGETS_HIT_PERCENTAGE - else: - return float(destroyed_targets) / total_targets < self.SUCCESS_TARGETS_HIT_PERCENTAGE - """ - def is_successfull(self, debriefing: Debriefing): alive_attackers = sum([v for k, v in debriefing.alive_units[self.attacker_name].items() if db.unit_task(k) == PinpointStrike]) alive_defenders = sum([v for k, v in debriefing.alive_units[self.defender_name].items() if db.unit_task(k) == PinpointStrike]) @@ -76,7 +62,7 @@ class FrontlinePatrolEvent(Event): pass def player_attacking(self, flights: ScrambledFlightsDict): - assert flights[CAP] and flights[PinpointStrike] and len(flights) == 2, "Invalid flights" + assert CAP in flights and PinpointStrike in flights and len(flights) == 2, "Invalid flights" self.cas = self.to_cp.base.scramble_cas(self.game.settings.multiplier) self.escort = self.to_cp.base.scramble_sweep(self.game.settings.multiplier * self.ESCORT_FACTOR) diff --git a/game/event/infantrytransport.py b/game/event/infantrytransport.py index 4ca7ee9a..2086c025 100644 --- a/game/event/infantrytransport.py +++ b/game/event/infantrytransport.py @@ -38,7 +38,7 @@ class InfantryTransportEvent(Event): self.from_cp.base.affect_strength(-self.STRENGTH_INFLUENCE) def player_attacking(self, flights: ScrambledFlightsDict): - assert flights[Embarking] and len(flights) == 1, "Invalid flights" + assert Embarking in flights and len(flights) == 1, "Invalid flights" op = InfantryTransportOperation( game=self.game, diff --git a/game/event/insurgentattack.py b/game/event/insurgentattack.py index 38fe5876..de4df51b 100644 --- a/game/event/insurgentattack.py +++ b/game/event/insurgentattack.py @@ -8,6 +8,8 @@ from game.event import * from game.event.frontlineattack import FrontlineAttackEvent from game.operation.insurgentattack import InsurgentAttackOperation +from .event import * + class InsurgentAttackEvent(Event): SUCCESS_FACTOR = 0.7 @@ -39,7 +41,7 @@ class InsurgentAttackEvent(Event): return not attackers_success def player_defending(self, flights: ScrambledFlightsDict): - assert flights[CAS] and len(flights) == 1, "Invalid flights" + assert CAS in flights and len(flights) == 1, "Invalid flights" suitable_unittypes = db.find_unittype(Reconnaissance, self.attacker_name) random.shuffle(suitable_unittypes) @@ -56,6 +58,3 @@ class InsurgentAttackEvent(Event): strikegroup=flights[CAS]) self.operation = op - - def player_attacking(self, interceptors: db.PlaneDict, clients: db.PlaneDict): - assert False diff --git a/game/event/intercept.py b/game/event/intercept.py index 24f77cc0..eca702e2 100644 --- a/game/event/intercept.py +++ b/game/event/intercept.py @@ -69,7 +69,7 @@ class InterceptEvent(Event): self.to_cp.base.affect_strength(-self.STRENGTH_INFLUENCE) def player_attacking(self, flights: ScrambledFlightsDict): - assert flights[CAP] and len(flights) == 1, "Invalid flights" + assert CAP in flights and len(flights) == 1, "Invalid flights" escort = self.to_cp.base.scramble_sweep(self._enemy_scramble_multiplier()) @@ -91,6 +91,8 @@ class InterceptEvent(Event): self.operation = op def player_defending(self, flights: ScrambledFlightsDict): + assert CAP in flights and len(flights) == 1, "Invalid flights" + interceptors = self.from_cp.base.scramble_interceptors(self.game.settings.multiplier) self.transport_unit = random.choice(db.find_unittype(Transport, self.defender_name)) diff --git a/game/event/navalintercept.py b/game/event/navalintercept.py index a1366f46..0f776197 100644 --- a/game/event/navalintercept.py +++ b/game/event/navalintercept.py @@ -78,7 +78,7 @@ class NavalInterceptEvent(Event): self.to_cp.base.affect_strength(-self.STRENGTH_INFLUENCE) def player_attacking(self, flights: ScrambledFlightsDict): - assert flights[CAS] and len(flights) == 1, "Invalid flights" + assert CAS in flights and len(flights) == 1, "Invalid flights" self.targets = { random.choice(db.find_unittype(CargoTransportation, self.defender_name)): self._targets_count(), @@ -99,7 +99,7 @@ class NavalInterceptEvent(Event): self.operation = op def player_defending(self, flights: ScrambledFlightsDict): - assert flights[CAP] and len(flights) == 1, "Invalid flights" + assert CAP in flights and len(flights) == 1, "Invalid flights" self.targets = { random.choice(db.find_unittype(CargoTransportation, self.defender_name)): self._targets_count(), diff --git a/game/event/strike.py b/game/event/strike.py index 50a50152..158da7af 100644 --- a/game/event/strike.py +++ b/game/event/strike.py @@ -22,6 +22,10 @@ class StrikeEvent(Event): def is_successfull(self, debriefing: Debriefing): return True + @property + def threat_description(self): + return "{} aircraft + AA".format(self.to_cp.base.scramble_count(self.game.settings.multiplier, CAP)) + @property def tasks(self): if self.is_player_attacking: @@ -47,7 +51,7 @@ class StrikeEvent(Event): self.to_cp.base.affect_strength(-self.SINGLE_OBJECT_STRENGTH_INFLUENCE * len(debriefing.destroyed_objects)) def player_attacking(self, flights: ScrambledFlightsDict): - assert flights[CAP] and flights[CAS] and len(flights) == 2, "Invalid flights" + assert CAP in flights and CAS in flights and len(flights) == 2, "Invalid flights" op = StrikeOperation( self.game,