コード例 #1
0
ファイル: game.py プロジェクト: jeventy26/dcs_liberation
    def on_load(self) -> None:
        LuaPluginManager.load_settings(self.settings)
        ObjectiveDistanceCache.set_theater(self.theater)

        # Save game compatibility.

        # TODO: Remove in 2.3.
        if not hasattr(self, "conditions"):
            self.conditions = self.generate_conditions()
コード例 #2
0
    def create_package_for_airlift(self) -> None:
        distance_cache = ObjectiveDistanceCache.get_closest_airfields(
            self.transfer.position
        )
        air_wing = self.game.air_wing_for(self.for_player)
        for cp in distance_cache.closest_airfields:
            if cp.captured != self.for_player:
                continue

            inventory = self.game.aircraft_inventory.for_control_point(cp)
            for unit_type, available in inventory.all_aircraft:
                squadrons = air_wing.auto_assignable_for_task_with_type(
                    unit_type, FlightType.TRANSPORT
                )
                for squadron in squadrons:
                    if self.compatible_with_mission(unit_type, cp):
                        while (
                            available
                            and squadron.has_available_pilots
                            and self.transfer.transport is None
                        ):
                            flight_size = self.create_airlift_flight(
                                squadron, inventory
                            )
                            available -= flight_size
        if self.package.flights:
            self.game.ato_for(self.for_player).add_package(self.package)
コード例 #3
0
ファイル: game.py プロジェクト: kavinsky/dcs_liberation
 def on_load(self, game_still_initializing: bool = False) -> None:
     if not hasattr(self, "name_generator"):
         self.name_generator = naming.namegen
     # Hack: Replace the global name generator state with the state from the save
     # game.
     #
     # We need to persist this state so that names generated after game load don't
     # conflict with those generated before exit.
     naming.namegen = self.name_generator
     LuaPluginManager.load_settings(self.settings)
     ObjectiveDistanceCache.set_theater(self.theater)
     self.compute_conflicts_position()
     if not game_still_initializing:
         self.compute_threat_zones()
     self.blue_faker = Faker(self.faction_for(player=True).locales)
     self.red_faker = Faker(self.faction_for(player=False).locales)
コード例 #4
0
 def closest_enemy_airbase(
     cls, location: ControlPoint, max_distance: Distance
 ) -> Optional[ControlPoint]:
     airfields = ObjectiveDistanceCache.get_closest_airfields(location)
     for airfield in airfields.airfields_within(max_distance):
         if airfield.captured != location.captured:
             return airfield
     return None
コード例 #5
0
 def best_airbases_for(
         self,
         request: AircraftProcurementRequest) -> Iterator[ControlPoint]:
     distance_cache = ObjectiveDistanceCache.get_closest_airfields(
         request.near
     )
     for cp in distance_cache.airfields_within(request.range):
         if not cp.is_friendly(self.is_player):
             continue
         if not cp.runway_is_operational():
             continue
         if cp.unclaimed_parking(self.game) < request.number:
             continue
         yield cp
コード例 #6
0
 def best_airbases_for(
         self,
         request: AircraftProcurementRequest) -> Iterator[ControlPoint]:
     distance_cache = ObjectiveDistanceCache.get_closest_airfields(
         request.near)
     threatened = []
     for cp in distance_cache.operational_airfields_within(request.range):
         if not cp.is_friendly(self.is_player):
             continue
         if cp.unclaimed_parking(self.game) < request.number:
             continue
         if self.threat_zones.threatened(cp.position):
             threatened.append(cp)
         yield cp
     yield from threatened
コード例 #7
0
 def aircraft_retreat_destination(
         self, game: Game,
         airframe: Type[FlyingType]) -> Optional[ControlPoint]:
     closest = ObjectiveDistanceCache.get_closest_airfields(self)
     # TODO: Should be airframe dependent.
     max_retreat_distance = nautical_miles(200)
     # Skip the first airbase because that's the airbase we're retreating
     # from.
     airfields = list(closest.airfields_within(max_retreat_distance))[1:]
     for airbase in airfields:
         if not airbase.can_operate(airframe):
             continue
         if airbase.captured != self.captured:
             continue
         if airbase.unclaimed_parking(game) > 0:
             return airbase
     return None
コード例 #8
0
 def closest_airfields_to(location: MissionTarget) -> ClosestAirfields:
     """Returns the closest airfields to the given location."""
     return ObjectiveDistanceCache.get_closest_airfields(location)
コード例 #9
0
 def on_load(self) -> None:
     LuaPluginManager.load_settings(self.settings)
     ObjectiveDistanceCache.set_theater(self.theater)
     self.compute_conflicts_position()
     self.compute_threat_zones()