feat(ai-ai): Implement emergency garrison fallback logic for AI behavior when no military units are available, with debug logging for player 1

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
autocommit 2026-04-15 21:44:04 -07:00
parent f44a328300
commit a783d1abbe

View file

@ -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")