Files
OpenFrontIO/src/core/execution
FloPinguin 8a8079b979 Fix parallel bot boat attacks of nations 🐛 (#4297)
## Description:

When a nation attacked multiple bots via boat attacks in parallel, each
boat attack computed its troop allocation independently using
`player.troops() / 5` without subtracting `botAttackTroopsSent`. The
cumulative troop commitment could exceed the nation's actual troop
count, and when the queued `AttackExecution`s ran `init()`, they drained
the nation to zero.

Planetary Realignment found this bug by accident, here Russia has only
39 troops:

<img width="1189" height="654" alt="image"
src="https://github.com/user-attachments/assets/07b85e00-6734-4ddd-a16e-fe53309e0ef8"
/>

The land attack path already handled this correctly. The bug in
`sendBoatAttack` was introduced by #3786, which made nations see and
attack enemies across rivers via boats, and changed `attackBots()` from
`.neighbors()` to `.nearby()`.

So the bug was on prod for the entirety of v31.

This fix extracts the shared attack troop calculation (reserve,
bot-aware allocation, troopSendCap, isAttackTooWeak, emoji) into a new
`calculateAttackTroops` method, with a callback for the non-bot troop
default (land: `player.troops() - targetTroops`, boat: `player.troops()
/ 5`). Bot targets in both paths now go through the same reserve-aware
calculation.

## Please complete the following:

- [X] I have added screenshots for all UI updates
- [X] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [X] I have added relevant tests to the test directory

## Please put your Discord username so you can be contacted if a bug or
regression is found:

FloPinguin
2026-06-16 10:22:06 -07:00
..
2026-04-12 17:18:52 -07:00