Autoplanner will take number of pilots into account when planning purchases

- Added expected_pilots_next_turn() to Squadron. The procurement AI now correctly compares to it when evaluating if planes should be bought, instead of the maximum possible number of pilots.
- Added replenish_rate method to squadron.py to prevent expected_pilots_next_turn from returning an incorrect (too large) number when replenish rate > pilots required.
#1837
This commit is contained in:
MetalStormGhost 2022-02-20 01:48:05 +02:00 committed by GitHub
parent 5cd9af32fa
commit 2af274dc77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -185,6 +185,14 @@ class ProcurementAi:
) -> Tuple[float, bool]:
for squadron in squadrons:
price = squadron.aircraft.price * quantity
# Final check to make sure the number of aircraft won't exceed the number of available pilots
# after fulfilling this aircraft request.
if (
squadron.pilot_limits_enabled
and squadron.expected_size_next_turn + quantity
> squadron.expected_pilots_next_turn
):
continue
if price > budget:
continue

View File

@ -222,6 +222,17 @@ class Squadron:
def max_size(self) -> int:
return self.settings.squadron_pilot_limit
@property
def expected_pilots_next_turn(self) -> int:
return len(self.active_pilots) + self.replenish_rate
@property
def replenish_rate(self) -> int:
return min(
self.settings.squadron_replenishment_rate,
self._number_of_unfilled_pilot_slots,
)
@property
def active_pilots(self) -> list[Pilot]:
return self._pilots_with_status(PilotStatus.Active)