From 4eb78c1367fb1fc517188331df3bb9bd690c4d26 Mon Sep 17 00:00:00 2001 From: Tom Kerr Date: Sat, 30 Mar 2024 12:56:56 +0000 Subject: [PATCH] fix: overproduce on low tech behaves as expected --- src/ares/behaviors/macro/spawn_controller.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ares/behaviors/macro/spawn_controller.py b/src/ares/behaviors/macro/spawn_controller.py index 23498c6..f3a4db2 100644 --- a/src/ares/behaviors/macro/spawn_controller.py +++ b/src/ares/behaviors/macro/spawn_controller.py @@ -89,6 +89,8 @@ def execute(self, ai: "AresBot", config: dict, mediator: ManagerMediator) -> boo proportion_sum: float = 0.0 # remember units that meet tech requirement units_ready_to_build: list[UnitID] = [] + # keep track of what units we have tech for + tech_ready_for: list[UnitID] = [] # iterate through desired army comp starting with the highest priority unit for unit_type_id, army_comp_info in sorted( army_comp_dict.items(), key=lambda x: x[1].get("priority", int(0)) @@ -111,6 +113,8 @@ def execute(self, ai: "AresBot", config: dict, mediator: ManagerMediator) -> boo if not ai.tech_ready_for_unit(unit_type_id): continue + tech_ready_for.append(unit_type_id) + # get all idle build structures/units we can create this unit from build_structures: list[Unit] = ai.get_build_structures( UNIT_TRAINED_FROM[unit_type_id], @@ -157,7 +161,11 @@ def execute(self, ai: "AresBot", config: dict, mediator: ManagerMediator) -> boo ai, unit_type_id, build_structures, amount, supply, cost ) # if we can only build one type of unit, keep adding them - if len(units_ready_to_build) == 1 and self.over_produce_on_low_tech: + if ( + len(tech_ready_for) == 1 + and self.over_produce_on_low_tech + and len(units_ready_to_build) > 0 + ): build_structures = ai.get_build_structures( UNIT_TRAINED_FROM[units_ready_to_build[0]], units_ready_to_build[0],