mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Check for compatible squadrons when buying planes.
https://github.com/dcs-liberation/dcs_liberation/issues/276
This commit is contained in:
parent
d7768f86d3
commit
a2c10f1c7a
@ -50,6 +50,7 @@ class ProcurementAi:
|
|||||||
|
|
||||||
self.game = game
|
self.game = game
|
||||||
self.is_player = for_player
|
self.is_player = for_player
|
||||||
|
self.air_wing = game.air_wing_for(for_player)
|
||||||
self.faction = faction
|
self.faction = faction
|
||||||
self.manage_runways = manage_runways
|
self.manage_runways = manage_runways
|
||||||
self.manage_front_line = manage_front_line
|
self.manage_front_line = manage_front_line
|
||||||
@ -163,23 +164,31 @@ class ProcurementAi:
|
|||||||
|
|
||||||
return budget
|
return budget
|
||||||
|
|
||||||
def _affordable_aircraft_of_types(
|
def _affordable_aircraft_for_task(
|
||||||
self,
|
self,
|
||||||
types: List[Type[FlyingType]],
|
task: FlightType,
|
||||||
airbase: ControlPoint,
|
airbase: ControlPoint,
|
||||||
number: int,
|
number: int,
|
||||||
max_price: float,
|
max_price: float,
|
||||||
) -> Optional[Type[FlyingType]]:
|
) -> Optional[Type[FlyingType]]:
|
||||||
best_choice: Optional[Type[FlyingType]] = None
|
best_choice: Optional[Type[FlyingType]] = None
|
||||||
for unit in [u for u in types if u in self.faction.aircrafts]:
|
for unit in aircraft_for_task(task):
|
||||||
|
if unit not in self.faction.aircrafts:
|
||||||
|
continue
|
||||||
if db.PRICES[unit] * number > max_price:
|
if db.PRICES[unit] * number > max_price:
|
||||||
continue
|
continue
|
||||||
if not airbase.can_operate(unit):
|
if not airbase.can_operate(unit):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Affordable and compatible. To keep some variety, skip with a 50/50
|
for squadron in self.air_wing.squadrons_for(unit):
|
||||||
# chance. Might be a good idea to have the chance to skip based on
|
if task in squadron.mission_types:
|
||||||
# the price compared to the rest of the choices.
|
break
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Affordable, compatible, and we have a squadron capable of the task. To
|
||||||
|
# keep some variety, skip with a 50/50 chance. Might be a good idea to have
|
||||||
|
# the chance to skip based on the price compared to the rest of the choices.
|
||||||
best_choice = unit
|
best_choice = unit
|
||||||
if random.choice([True, False]):
|
if random.choice([True, False]):
|
||||||
break
|
break
|
||||||
@ -188,8 +197,8 @@ class ProcurementAi:
|
|||||||
def affordable_aircraft_for(
|
def affordable_aircraft_for(
|
||||||
self, request: AircraftProcurementRequest, airbase: ControlPoint, budget: float
|
self, request: AircraftProcurementRequest, airbase: ControlPoint, budget: float
|
||||||
) -> Optional[Type[FlyingType]]:
|
) -> Optional[Type[FlyingType]]:
|
||||||
return self._affordable_aircraft_of_types(
|
return self._affordable_aircraft_for_task(
|
||||||
aircraft_for_task(request.task_capability), airbase, request.number, budget
|
request.task_capability, airbase, request.number, budget
|
||||||
)
|
)
|
||||||
|
|
||||||
def fulfill_aircraft_request(
|
def fulfill_aircraft_request(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user