Improve "Better troop management for nations 🤖"#4278
Conversation
Walkthrough
ChangesRetaliation Logic and Destination-Aware Troop Limiting
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/AiAttackBehavior.test.ts`:
- Around line 572-601: The test named "Hard: nation under attack bypasses
troopSendCap and isAttackTooWeak" does not properly verify the bypass logic
because the cap naturally increases after the neighbor loses troops to the
initial attack. To actually test the bypass, modify the test setup so that the
incoming attack amount (the 10_000 troops from the neighbor) exceeds the
neighbor-based cap calculation, ensuring the bypass logic max(neighborCap,
totalIncoming) is what allows the retaliation to exceed the normal cap, not just
natural cap fluctuations from troop losses.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 884635a1-3cdb-4b4c-b4a7-ac895ed793e5
📒 Files selected for processing (2)
src/core/execution/utils/AiAttackBehavior.tstests/AiAttackBehavior.test.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/core/execution/utils/AiAttackBehavior.ts`:
- Around line 140-142: The retaliation-only cap relaxation logic in
troopSendCap() and isAttackTooWeak() is being applied to all attacks when there
are incoming attacks, not just retaliations. To fix this, modify the call paths
to these methods to explicitly pass the retaliation context or attacker
identity. Update troopSendCap() to accept a parameter indicating whether the
current attack is a retaliation and who the incoming attacker is, then apply the
relaxed cap limits only when the destination owner is the actual incoming
attacker. Apply this same retaliation context passing logic to all call sites of
these methods throughout the attack behavior code.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9f848ce9-1d01-4edd-8c42-d455603017e7
📒 Files selected for processing (1)
src/core/execution/utils/AiAttackBehavior.ts
Description:
Allow Hard/Impossible nations to retaliate and expand freely
Previously, nations on Hard/Impossible difficulty could be stuck unable to fight back if their
troopSendCaporisAttackTooWeakchecks blocked them from sending enough troops. @legan320 on the main discord noticed it. Now:troopSendCapraises the cap to at least the total incoming attack troops, so nations can match the force being used against themisAttackTooWeakbypasses the 20% minimum check entirely when under attacktroopSendCapno longer applies when attacking Terra Nullius, so nations can always expand into unowned land with full troopsAll checks still apply normally for unprovoked attacks against other players.
Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
FloPinguin