From a783d1abbedcafc494706ca6a137fce7081bb67d Mon Sep 17 00:00:00 2001 From: autocommit Date: Wed, 15 Apr 2026 21:44:04 -0700 Subject: [PATCH] =?UTF-8?q?feat(ai-ai):=20=E2=9C=A8=20Implement=20emergenc?= =?UTF-8?q?y=20garrison=20fallback=20logic=20for=20AI=20behavior=20when=20?= =?UTF-8?q?no=20military=20units=20are=20available,=20with=20debug=20loggi?= =?UTF-8?q?ng=20for=20player=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- .../src/modules/ai/simple_heuristic_ai.gd | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/game/engine/src/modules/ai/simple_heuristic_ai.gd b/src/game/engine/src/modules/ai/simple_heuristic_ai.gd index b13c6dad..ccb6f0f1 100644 --- a/src/game/engine/src/modules/ai/simple_heuristic_ai.gd +++ b/src/game/engine/src/modules/ai/simple_heuristic_ai.gd @@ -367,8 +367,25 @@ static func _decide_production( var city: RefCounted = player.cities[city_index] var city_count: int = player.cities.size() + # Priority 0: Emergency garrison — no military at all means the next + # enemy stack wins uncontested before any wall is finished. A single + # warrior buys ~10 turns of breathing room at a fraction of walls' + # cost (20 vs 70). Only triggers when the player has zero military + # units across all cities, which in AoD arena matches is the turn-1 + # state since starting roster is founder + scout (no combat unit). + if military_count == 0: + var emergency_unit: String = _pick_buildable_military_unit_id( + city, player + ) + if not emergency_unit.is_empty(): + return _prod_unit(city_index, emergency_unit) + # Priority 1: Build walls if city has none (defense first) - if not city.has_building("walls") and city.can_build("walls", player): + var walls_built: bool = city.has_building("walls") + var walls_buildable: bool = city.can_build("walls", player) + if player.index == 1: + print("[AI_DBG] p1 c%d mil=%d fnd=%d walls_built=%s walls_buildable=%s" % [city_index, military_count, founder_count, walls_built, walls_buildable]) + if not walls_built and walls_buildable: var wdata: Dictionary = DataLoader.get_building("walls") if not wdata.is_empty(): return _prod_building(city_index, "walls")