From fa1166d01462ad18217ec5a14a6903766dc974ee Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Sat, 9 Jan 2021 13:10:21 -0800 Subject: [PATCH] Limit reserve ground units to 10. Allowing these to grow infinitely leads to some really weird behaviors when the enemy has been buying reserves long enough, where capturing a base might result in 80 enemy vehicles suddenly at the gates. This is just an interim fix. Ideally these units would be reinforcing the front line as needed (https://github.com/Khopa/dcs_liberation/issues/382), and a CP could be lost without needing to completely destroy the defender. --- game/procurement.py | 23 +++++++++++++++++++---- game/theater/controlpoint.py | 14 ++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/game/procurement.py b/game/procurement.py index 8d55d82e..0122ab59 100644 --- a/game/procurement.py +++ b/game/procurement.py @@ -225,7 +225,7 @@ class ProcurementAi: # Prefer to buy front line units at active front lines that are not # already overloaded. for cp in self.owned_points: - if cp.base.total_armor >= 30: + if cp.expected_ground_units_next_turn.total >= 30: # Control point is already sufficiently defended. continue for connected in cp.connected_points: @@ -233,8 +233,23 @@ class ProcurementAi: candidates.append(cp) if not candidates: - # Otherwise buy them anywhere valid. - candidates = [p for p in self.owned_points - if p.can_deploy_ground_units] + # Otherwise buy reserves, but don't exceed 10 reserve units per CP. + # These units do not exist in the world until the CP becomes + # connected to an active front line, at which point all these units + # will suddenly appear at the gates of the newly captured CP. + # + # To avoid sudden overwhelming numbers of units we avoid buying + # many. + # + # Also, do not bother buying units at bases that will never connect + # to a front line. + for cp in self.owned_points: + if not cp.can_deploy_ground_units: + continue + if cp.expected_ground_units_next_turn.total >= 10: + continue + if cp.is_global: + continue + candidates.append(cp) return candidates diff --git a/game/theater/controlpoint.py b/game/theater/controlpoint.py index 72733199..6c9c7791 100644 --- a/game/theater/controlpoint.py +++ b/game/theater/controlpoint.py @@ -588,6 +588,20 @@ class ControlPoint(MissionTarget, ABC): else: return 0 + @property + def expected_ground_units_next_turn(self) -> PendingOccupancy: + on_order = 0 + for unit_bought in self.pending_unit_deliveries.units: + if issubclass(unit_bought, FlyingType): + continue + if unit_bought in TYPE_SHORAD: + continue + on_order += self.pending_unit_deliveries.units[unit_bought] + + return PendingOccupancy(self.base.total_armor, on_order, + # Ground unit transfers not yet implemented. + transferring=0) + @property def income_per_turn(self) -> int: return 0