Ignore range when manually using auto-create

This commit is contained in:
Raffson 2024-03-09 19:01:38 +01:00
parent 15218d0241
commit eb6afbdf02
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
5 changed files with 15 additions and 5 deletions

View File

@ -38,7 +38,7 @@ class PackageBuilder:
self.laser_code_registry = laser_code_registry self.laser_code_registry = laser_code_registry
self.start_type = start_type self.start_type = start_type
def plan_flight(self, plan: ProposedFlight) -> bool: def plan_flight(self, plan: ProposedFlight, ignore_range: bool) -> bool:
"""Allocates aircraft for the given flight and adds them to the package. """Allocates aircraft for the given flight and adds them to the package.
If no suitable aircraft are available, False is returned. If the failed If no suitable aircraft are available, False is returned. If the failed
@ -55,6 +55,7 @@ class PackageBuilder:
heli, heli,
this_turn=True, this_turn=True,
preferred_type=plan.preferred_type, preferred_type=plan.preferred_type,
ignore_range=ignore_range,
) )
if squadron is None: if squadron is None:
return False return False

View File

@ -81,8 +81,9 @@ class PackageFulfiller:
builder: PackageBuilder, builder: PackageBuilder,
missing_types: Set[FlightType], missing_types: Set[FlightType],
purchase_multiplier: int, purchase_multiplier: int,
ignore_range: bool = False,
) -> None: ) -> None:
if not builder.plan_flight(flight): if not builder.plan_flight(flight, ignore_range):
pf = builder.package.primary_flight pf = builder.package.primary_flight
heli = pf.is_helo if pf else False heli = pf.is_helo if pf else False
missing_types.add(flight.task) missing_types.add(flight.task)
@ -138,6 +139,7 @@ class PackageFulfiller:
purchase_multiplier: int, purchase_multiplier: int,
now: datetime, now: datetime,
tracer: MultiEventTracer, tracer: MultiEventTracer,
ignore_range: bool = False,
) -> Optional[Package]: ) -> Optional[Package]:
"""Allocates aircraft for a proposed mission and adds it to the ATO.""" """Allocates aircraft for a proposed mission and adds it to the ATO."""
builder = PackageBuilder( builder = PackageBuilder(
@ -175,6 +177,7 @@ class PackageFulfiller:
builder, builder,
missing_types, missing_types,
purchase_multiplier, purchase_multiplier,
ignore_range,
) )
if missing_types: if missing_types:

View File

@ -52,6 +52,7 @@ class AirWing:
heli: bool, heli: bool,
this_turn: bool, this_turn: bool,
preferred_type: Optional[AircraftType] = None, preferred_type: Optional[AircraftType] = None,
ignore_range: bool = False,
) -> list[Squadron]: ) -> list[Squadron]:
airfield_cache = ObjectiveDistanceCache.get_closest_airfields(location) airfield_cache = ObjectiveDistanceCache.get_closest_airfields(location)
best_aircraft = AircraftType.priority_list_for_task(task) best_aircraft = AircraftType.priority_list_for_task(task)
@ -68,7 +69,7 @@ class AirWing:
] ]
for squadron in squadrons: for squadron in squadrons:
if squadron.can_auto_assign_mission( if squadron.can_auto_assign_mission(
location, task, size, heli, this_turn location, task, size, heli, this_turn, ignore_range
): ):
capable_at_base.append(squadron) capable_at_base.append(squadron)
if squadron.aircraft not in best_aircraft: if squadron.aircraft not in best_aircraft:
@ -100,9 +101,10 @@ class AirWing:
heli: bool, heli: bool,
this_turn: bool, this_turn: bool,
preferred_type: Optional[AircraftType] = None, preferred_type: Optional[AircraftType] = None,
ignore_range: bool = False,
) -> Optional[Squadron]: ) -> Optional[Squadron]:
for squadron in self.best_squadrons_for( for squadron in self.best_squadrons_for(
location, task, size, heli, this_turn, preferred_type location, task, size, heli, this_turn, preferred_type, ignore_range
): ):
return squadron return squadron
return None return None

View File

@ -281,6 +281,7 @@ class Squadron:
size: int, size: int,
heli: bool, heli: bool,
this_turn: bool, this_turn: bool,
ignore_range: bool = False,
) -> bool: ) -> bool:
if ( if (
self.location.cptype.name in ["FOB", "FARP"] self.location.cptype.name in ["FOB", "FARP"]
@ -304,6 +305,9 @@ class Squadron:
if heli and task == FlightType.REFUELING: if heli and task == FlightType.REFUELING:
return False return False
if ignore_range:
return True
distance_to_target = meters(location.distance_to(self.location)) distance_to_target = meters(location.distance_to(self.location))
return distance_to_target <= self.aircraft.max_mission_range return distance_to_target <= self.aircraft.max_mission_range

View File

@ -223,7 +223,7 @@ class QAutoCreateDialog(QDialog):
self.game.settings, self.game.settings,
) )
now = self.package_model.game_model.sim_controller.current_time_in_sim now = self.package_model.game_model.sim_controller.current_time_in_sim
package = pff.plan_mission(pm, 1, now, tracer) package = pff.plan_mission(pm, 1, now, tracer, ignore_range=True)
if package: if package:
package.set_tot_asap(now) package.set_tot_asap(now)
self.package = package self.package = package