fix: Add throttling to AI defense phase to prevent units from moving …#1160
Conversation
…instead of attacking The AI defense phase was issuing ATTACK commands to ALL army units on every single tick. This constant re-commanding caused units to continuously reset their attack state, resulting in: 1. Units moving around the enemy but never actually attacking 2. Multiple AI armies converging to the same location and sitting idle Changes: - Add DEFENSE_COMMAND_INTERVAL (20 ticks/1 sec) to throttle defense commands - Only re-command idle units, not units already engaged in combat - Increase threat search radius from 50 to 80 units for better detection - Include workers with attack damage in threat detection (worker rush defense) This matches the existing attack phase logic which properly throttles commands and only re-commands idle assault units. https://claude.ai/code/session_017TvSHA6ZyEaBu3iPh6p5AH
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dd1f8c1fe9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Unit needs commanding if: | ||
| // 1. It's idle (not doing anything) | ||
| // 2. It's completely stopped (no target, no destination) | ||
| const isIdle = unit.state === 'idle' && unit.targetEntityId === null; | ||
| const isStuck = unit.state === 'idle' && !unit.isInAssaultMode; |
There was a problem hiding this comment.
Recall non-idle units during defense
Because getIdleDefendingUnits only selects units in unit.state === 'idle', the defending phase will issue no commands if the army is already moving/attacking (e.g., marching to an assault or chasing elsewhere) when the AI switches to defending. In that scenario idleDefenders is empty, so the AI stays in defense while the army keeps its old orders and the base can be left undefended. Consider also including non‑engaged moving units (or issuing an initial full defense command on state change) so defense actually retasks the army.
Useful? React with 👍 / 👎.
…instead of attacking
The AI defense phase was issuing ATTACK commands to ALL army units on every single tick. This constant re-commanding caused units to continuously reset their attack state, resulting in:
Changes:
This matches the existing attack phase logic which properly throttles commands and only re-commands idle assault units.
https://claude.ai/code/session_017TvSHA6ZyEaBu3iPh6p5AH