Skip to content

fix: AI armies no longer get permanently stuck at enemy base positions#1414

Merged
braedonsaunders merged 1 commit intomainfrom
claude/fix-ai-pathfinding-stuck-GlCYz
Feb 10, 2026
Merged

fix: AI armies no longer get permanently stuck at enemy base positions#1414
braedonsaunders merged 1 commit intomainfrom
claude/fix-ai-pathfinding-stuck-GlCYz

Conversation

@braedonsaunders
Copy link
Owner

Three interacting bugs caused AI armies to march to an enemy base and idle there indefinitely until the enemy was fully eliminated:

  1. Broken disengage timer: The timeout compared currentTick against lastEngagementCheck (updated every 10 ticks regardless of engagement state), so the duration was always ~10 and never exceeded the 100-tick threshold. Now tracks lastEngagedTick — the last tick engagement was actually true.

  2. Re-command cycle reset assault idle timeout: The 20-tick re-command interval called setAttackMoveTarget() which reset assaultIdleTicks to 0, preventing CombatSystem's 120-tick timeout from ever clearing assault mode. Now skips re-commanding units already at the target position (within 8 units distance).

  3. Position-only targeting in normal attacks: findEnemyBase() returned a cached basePosition with no entityId, forcing position-based ATTACK_MOVE instead of direct ATTACK commands. Now always queries live buildings and returns entityId for entity-targeted attacks, matching hunt mode behavior. Also filters out dead/non-operational buildings.

Additionally, the disengage path now calls returnUnitsToBase() to clear assault mode and send units home instead of just changing state.

https://claude.ai/code/session_01MwsxRyx6WEt2nw3dmG1nN4

Three interacting bugs caused AI armies to march to an enemy base and
idle there indefinitely until the enemy was fully eliminated:

1. Broken disengage timer: The timeout compared currentTick against
   lastEngagementCheck (updated every 10 ticks regardless of engagement
   state), so the duration was always ~10 and never exceeded the 100-tick
   threshold. Now tracks lastEngagedTick — the last tick engagement was
   actually true.

2. Re-command cycle reset assault idle timeout: The 20-tick re-command
   interval called setAttackMoveTarget() which reset assaultIdleTicks to
   0, preventing CombatSystem's 120-tick timeout from ever clearing
   assault mode. Now skips re-commanding units already at the target
   position (within 8 units distance).

3. Position-only targeting in normal attacks: findEnemyBase() returned a
   cached basePosition with no entityId, forcing position-based
   ATTACK_MOVE instead of direct ATTACK commands. Now always queries live
   buildings and returns entityId for entity-targeted attacks, matching
   hunt mode behavior. Also filters out dead/non-operational buildings.

Additionally, the disengage path now calls returnUnitsToBase() to clear
assault mode and send units home instead of just changing state.

https://claude.ai/code/session_01MwsxRyx6WEt2nw3dmG1nN4
@braedonsaunders braedonsaunders merged commit b36187e into main Feb 10, 2026
3 of 4 checks passed
@braedonsaunders braedonsaunders deleted the claude/fix-ai-pathfinding-stuck-GlCYz branch February 10, 2026 03:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants