From 9d0997624b2bbf70c48acd55943ebfe163ab04c0 Mon Sep 17 00:00:00 2001 From: Vasyl Horbachenko Date: Mon, 5 Nov 2018 03:17:06 +0200 Subject: [PATCH] fixes for selectable departure; generate statics for used units; raised RTB alt --- game/db.py | 1 - game/event/baseattack.py | 6 ++++-- game/event/frontlineattack.py | 1 + game/event/frontlinepatrol.py | 1 + game/event/infantrytransport.py | 3 ++- game/event/insurgentattack.py | 3 ++- game/event/intercept.py | 6 ++++-- game/event/navalintercept.py | 6 ++++-- game/event/strike.py | 3 ++- game/operation/operation.py | 15 ++++++++++----- gen/aircraft.py | 2 +- gen/airsupportgen.py | 9 +++++++-- gen/conflictgen.py | 3 ++- gen/triggergen.py | 4 +--- gen/visualgen.py | 12 ++++++++++++ ui/eventmenu.py | 2 +- ui/overviewcanvas.py | 6 +++--- 17 files changed, 57 insertions(+), 26 deletions(-) diff --git a/game/db.py b/game/db.py index f61ee379..2026ee47 100644 --- a/game/db.py +++ b/game/db.py @@ -235,7 +235,6 @@ SAM_BAN = [ Units that will always be spawned in the air """ TAKEOFF_BAN = [ - AV8BNA, # AI takeoff currently bugged attempting VTOL with no regards for the total weight ] """ diff --git a/game/event/baseattack.py b/game/event/baseattack.py index 2517a769..5e7ca266 100644 --- a/game/event/baseattack.py +++ b/game/event/baseattack.py @@ -61,7 +61,8 @@ class BaseAttackEvent(Event): op = BaseAttackOperation(game=self.game, attacker_name=self.attacker_name, defender_name=self.defender_name, - from_cp=self.departure_cp, + from_cp=self.from_cp, + departure_cp=self.departure_cp, to_cp=self.to_cp) op.setup(cas=assigned_units_from(cas), @@ -79,7 +80,8 @@ class BaseAttackEvent(Event): op = BaseAttackOperation(game=self.game, attacker_name=self.attacker_name, defender_name=self.defender_name, - from_cp=self.departure_cp, + from_cp=self.from_cp, + departure_cp=self.departure_cp, to_cp=self.to_cp) defenders = self.to_cp.base.scramble_sweep(self.game.settings.multiplier) diff --git a/game/event/frontlineattack.py b/game/event/frontlineattack.py index 3201ca47..032b03a1 100644 --- a/game/event/frontlineattack.py +++ b/game/event/frontlineattack.py @@ -68,6 +68,7 @@ class FrontlineAttackEvent(Event): attacker_name=self.attacker_name, defender_name=self.defender_name, from_cp=self.from_cp, + departure_cp=self.departure_cp, to_cp=self.to_cp) defenders = self.to_cp.base.assemble_attack() diff --git a/game/event/frontlinepatrol.py b/game/event/frontlinepatrol.py index 6f0b51d7..8cab0844 100644 --- a/game/event/frontlinepatrol.py +++ b/game/event/frontlinepatrol.py @@ -64,6 +64,7 @@ class FrontlinePatrolEvent(Event): attacker_name=self.attacker_name, defender_name=self.defender_name, from_cp=self.from_cp, + departure_cp=self.departure_cp, to_cp=self.to_cp) defenders = self.to_cp.base.assemble_attack() diff --git a/game/event/infantrytransport.py b/game/event/infantrytransport.py index 3be47800..0ebebd06 100644 --- a/game/event/infantrytransport.py +++ b/game/event/infantrytransport.py @@ -44,7 +44,8 @@ class InfantryTransportEvent(Event): game=self.game, attacker_name=self.attacker_name, defender_name=self.defender_name, - from_cp=self.departure_cp, + from_cp=self.from_cp, + departure_cp=self.departure_cp, to_cp=self.to_cp ) diff --git a/game/event/insurgentattack.py b/game/event/insurgentattack.py index 607d9d43..bf4d373c 100644 --- a/game/event/insurgentattack.py +++ b/game/event/insurgentattack.py @@ -56,7 +56,8 @@ class InsurgentAttackEvent(Event): op = InsurgentAttackOperation(game=self.game, attacker_name=self.attacker_name, defender_name=self.defender_name, - from_cp=self.departure_cp, + from_cp=self.from_cp, + departure_cp=self.departure_cp, to_cp=self.to_cp) op.setup(target=self.targets, strikegroup=flights[CAS]) diff --git a/game/event/intercept.py b/game/event/intercept.py index 1a99303a..d5a89b3e 100644 --- a/game/event/intercept.py +++ b/game/event/intercept.py @@ -76,7 +76,8 @@ class InterceptEvent(Event): op = InterceptOperation(game=self.game, attacker_name=self.attacker_name, defender_name=self.defender_name, - from_cp=self.departure_cp, + from_cp=self.from_cp, + departure_cp=self.departure_cp, to_cp=self.to_cp) op.setup(location=self.location, @@ -98,7 +99,8 @@ class InterceptEvent(Event): op = InterceptOperation(game=self.game, attacker_name=self.attacker_name, defender_name=self.defender_name, - from_cp=self.departure_cp, + from_cp=self.from_cp, + departure_cp=self.departure_cp, to_cp=self.to_cp) op.setup(escort=flights[CAP], diff --git a/game/event/navalintercept.py b/game/event/navalintercept.py index 269c22f5..f4c75f20 100644 --- a/game/event/navalintercept.py +++ b/game/event/navalintercept.py @@ -84,7 +84,8 @@ class NavalInterceptEvent(Event): self.game, attacker_name=self.attacker_name, defender_name=self.defender_name, - from_cp=self.departure_cp, + from_cp=self.from_cp, + departure_cp=self.departure_cp, to_cp=self.to_cp ) @@ -106,7 +107,8 @@ class NavalInterceptEvent(Event): self.game, attacker_name=self.attacker_name, defender_name=self.defender_name, - from_cp=self.departure_cp, + from_cp=self.from_cp, + departure_cp=self.departure_cp, to_cp=self.to_cp ) diff --git a/game/event/strike.py b/game/event/strike.py index d538541a..6e69dbdf 100644 --- a/game/event/strike.py +++ b/game/event/strike.py @@ -49,7 +49,8 @@ class StrikeEvent(Event): self.game, attacker_name=self.attacker_name, defender_name=self.defender_name, - from_cp=self.departure_cp, + from_cp=self.from_cp, + departure_cp=self.departure_cp, to_cp=self.to_cp ) diff --git a/game/operation/operation.py b/game/operation/operation.py index d4cb5085..509b3462 100644 --- a/game/operation/operation.py +++ b/game/operation/operation.py @@ -39,11 +39,13 @@ class Operation: attacker_name: str, defender_name: str, from_cp: ControlPoint, + departure_cp: ControlPoint, to_cp: ControlPoint = None): self.game = game self.attacker_name = attacker_name self.defender_name = defender_name self.from_cp = from_cp + self.departure_cp = departure_cp self.to_cp = to_cp self.is_quick = False @@ -89,7 +91,7 @@ class Operation: self.attackers_starting_position = None self.defenders_starting_position = None else: - self.attackers_starting_position = self.from_cp.at + self.attackers_starting_position = self.departure_cp.at self.defenders_starting_position = self.to_cp.at def prepare_carriers(self, for_units: db.UnitsDict): @@ -101,12 +103,10 @@ class Operation: country=self.game.player, at=global_cp.at) - if global_cp == self.from_cp and not self.is_quick: + if global_cp == self.departure_cp and not self.is_quick: self.attackers_starting_position = ship def generate(self): - self.visualgen.generate() - # air support self.airsupportgen.generate(self.is_awacs_enabled) for i, tanker_type in enumerate(self.airsupportgen.generated_tankers): @@ -143,12 +143,17 @@ class Operation: else: self.envgen.load(self.environment_settings) + # options self.forcedoptionsgen.generate() # main frequencies self.briefinggen.append_frequency("Flight", "251 MHz AM") - if self.conflict.from_cp.is_global or self.conflict.to_cp.is_global: + if self.departure_cp.is_global or self.conflict.to_cp.is_global: self.briefinggen.append_frequency("Carrier", "20X/ICLS CHAN1") # briefing self.briefinggen.generate() + + # visuals + self.visualgen.generate() + diff --git a/gen/aircraft.py b/gen/aircraft.py index 70aed59e..576552fb 100644 --- a/gen/aircraft.py +++ b/gen/aircraft.py @@ -30,7 +30,7 @@ ATTACK_CIRCLE_ALT = 5000 ATTACK_CIRCLE_DURATION = 15 CAS_ALTITUDE = 1000 -RTB_ALTITUDE = 1000 +RTB_ALTITUDE = 3000 HELI_ALT = 900 TRANSPORT_LANDING_ALT = 1000 diff --git a/gen/airsupportgen.py b/gen/airsupportgen.py index 595e4fc7..5b9fc30d 100644 --- a/gen/airsupportgen.py +++ b/gen/airsupportgen.py @@ -49,12 +49,14 @@ class AirSupportConflictGenerator: ) tanker_group.points[0].tasks.append(ActivateBeaconCommand(channel=97 + i, unit_id=tanker_group.id, aa=False)) + tanker_group.tasks.append(SetInvisibleCommand(True)) + tanker_group.tasks.append(SetImmortalCommand(True)) if is_awacs_enabled: awacs_unit = db.find_unittype(AWACS, self.conflict.attackers_side.name)[0] - self.mission.awacs_flight( + awacs_flight = self.mission.awacs_flight( country=self.mission.country(self.game.player), - name=namegen.next_awacs_name(self.mission.country(self.game.player),), + name=namegen.next_awacs_name(self.mission.country(self.game.player)), plane_type=awacs_unit, altitude=AWACS_ALT, airport=None, @@ -62,3 +64,6 @@ class AirSupportConflictGenerator: frequency=133, start_type=StartType.Warm, ) + + awacs_flight.tasks.append(SetInvisibleCommand(True)) + awacs_flight.tasks.append(SetImmortalCommand(True)) diff --git a/gen/conflictgen.py b/gen/conflictgen.py index f4b03bf8..63336147 100644 --- a/gen/conflictgen.py +++ b/gen/conflictgen.py @@ -277,7 +277,7 @@ class Conflict: ) @classmethod - def intercept_position(cls, from_cp: ControlPoint, to_cp:ControlPoint) -> Point: + def intercept_position(cls, from_cp: ControlPoint, to_cp: ControlPoint) -> Point: raw_distance = from_cp.position.distance_to_point(to_cp.position) * 1.5 distance = max(min(raw_distance, INTERCEPT_MAX_DISTANCE), INTERCEPT_MIN_DISTANCE) heading = _heading_sum(from_cp.position.heading_between_point(to_cp.position), random.choice([-1, 1]) * random.randint(60, 100)) @@ -285,6 +285,7 @@ class Conflict: @classmethod def intercept_conflict(cls, attacker: Country, defender: Country, position: Point, from_cp: ControlPoint, to_cp: ControlPoint, theater: ConflictTheater): + heading = from_cp.position.heading_between_point(position) return cls( position=position.point_from_heading(position.heading_between_point(to_cp.position), INTERCEPT_CONFLICT_DISTANCE), theater=theater, diff --git a/gen/triggergen.py b/gen/triggergen.py index 1c4ecc9b..08abc9b1 100644 --- a/gen/triggergen.py +++ b/gen/triggergen.py @@ -54,14 +54,12 @@ class TriggersGenerator: vehicle_group.late_activation = True activate_by_trigger.append(vehicle_group) - """ conflict_distance = player_cp.position.distance_to_point(self.conflict.position) minimum_radius = max(conflict_distance - TRIGGER_MIN_DISTANCE_FROM_START, TRIGGER_RADIUS_MINIMUM) if minimum_radius < 0: minimum_radius = 0 - result_radius = min(minimum_radius, radius) - """ + radius = min(minimum_radius, radius) activation_trigger_zone = self.mission.triggers.add_triggerzone(self.conflict.position, radius, name="Activation zone") activation_trigger = TriggerOnce(Event.NoEvent, "Activation trigger") diff --git a/gen/visualgen.py b/gen/visualgen.py index 227af12f..d0a35aab 100644 --- a/gen/visualgen.py +++ b/gen/visualgen.py @@ -124,6 +124,17 @@ class VisualGenerator: position=pos) break + def _generate_stub_planes(self): + mission_units = set() + for coalition_name, coalition in self.mission.coalition.items(): + for country in coalition.countries.values(): + for group in country.plane_group + country.helicopter_group + country.vehicle_group: + for unit in group.units: + mission_units.add(db.unit_type_of(unit)) + + for unit_type in mission_units: + self.mission.static_group(self.mission.country("USA"), "a", unit_type, Point(0, 0)) + def generate_target_smokes(self, target): spread = target.size * DESTINATION_SMOKE_DISTANCE_FACTOR for _ in range(0, int(target.size * DESTINATION_SMOKE_AMOUNT_FACTOR * (1.1 - target.base.strength))): @@ -159,3 +170,4 @@ class VisualGenerator: def generate(self): self._generate_frontline_smokes() + self._generate_stub_planes() diff --git a/ui/eventmenu.py b/ui/eventmenu.py index e8f7b530..78829962 100644 --- a/ui/eventmenu.py +++ b/ui/eventmenu.py @@ -195,7 +195,7 @@ class EventMenu(Menu): return if isinstance(self.event, FrontlineAttackEvent) or isinstance(self.event, FrontlinePatrolEvent): - if self.base.total_armor == 0: + if self.event.from_cp.base.total_armor == 0: self.error_label["text"] = "No ground vehicles available to attack!" return diff --git a/ui/overviewcanvas.py b/ui/overviewcanvas.py index acf98b1b..c680bbae 100644 --- a/ui/overviewcanvas.py +++ b/ui/overviewcanvas.py @@ -164,7 +164,8 @@ class OverviewCanvas: InsurgentAttackEvent: "insurgent_attack", InterceptEvent: "air_intercept", NavalInterceptEvent: "naval_intercept", - StrikeEvent: "strike"}.items(): + StrikeEvent: "strike", + UnitsDeliveryEvent: "delivery"}.items(): self.event_icons[category] = pygame.image.load(os.path.join("resources", "ui", "events", image + ".png")) @@ -473,7 +474,7 @@ class OverviewCanvas: return rect def _events_priority_key(event: Event) -> int: - priority_list = [InfantryTransportEvent, StrikeEvent, BaseAttackEvent] + priority_list = [InfantryTransportEvent, StrikeEvent, BaseAttackEvent, UnitsDeliveryEvent] if type(event) not in priority_list: return 0 else: @@ -481,7 +482,6 @@ class OverviewCanvas: events = self.game.events events.sort(key=_events_priority_key, reverse=True) - print(events) label_to_draw = None for event in self.game.events: