On this page
Squads, the commander and his assets
Squads and the commander are bookkeeping: who is in which squad, who leads it, who commands, what was ordered, and when each of the commander's assets is ready again. The server's squad manager does all of it and tells every client by events. It is one of the most completely verified parts of the port: the original's squad manager was run in-process beside the port's on scripted scenarios, and 14,444 lines of trace came out the same.
Squads#
Each team has ten squads: squad 0, Unassigned, and nine named Alpha to India. A squad holds at most six players. Per squad the manager keeps a name, a leader, a locked flag, and three kinds of order: the squad leader's, the commander's, and the squad's requests.
Joining (bf2_w32ded.exe!0x0045fe70)#
- Ignored while the player is dead (after his first death) or man down.
- A full squad: the joiner is told so.
- He joins when the squad is unlocked, or he holds an invitation, or the squad is empty. Otherwise the leader gets a request and the joiner a "locked" message.
- The first to join an empty squad becomes its leader.
- Every member is told, and Python hears
PlayerChangedSquad(player, old, new).
Two quirks the port keeps#
A commander who joins a squad should resign first. The original's call that does this pushes its two arguments in the wrong order (setCommander(team = -1, player = team)), finds no such team, and does nothing: the commander joins the squad and stays commander. The oracle run confirmed it, and the port does the same.
Leaving a squad does not check membership, and it adds the leaver to squad 0's member set. So squad 0 slowly fills with everybody who ever left a squad, and each later join or promotion to commander "leaves" squad 0 again: the script hears a PlayerChangedSquad(player, 0, 0) that means nothing. A statistics script that counts squad changes sees them, on the original and on the port.
The leader#
When the leader leaves, the first human member takes over, else any member (chooseNewSquadLeader). A change of leader clears the squad's orders and raises ChangedSquadLeader(squad, old, new). A leader with a soldier is a spawn point for his squad.
Orders and requests#
An order is a kind, an object and a position. Three paths, each an event to the clients and a HUD message to those concerned:
| From | To | What |
|---|---|---|
| the squad leader | his squad | move, attack, defend at a point; members may accept or not |
| the commander | a squad | the same, from the commander's map |
| a squad leader or the commander | the commander | a request: artillery here, a UAV there, supplies, a vehicle |
Bots get orders through the AI's own events, and in co-op a request to a bot commander is answered by the AI commander (bots).
Becoming commander#
- Apply (
0x0045f960). Refused while the player's cooldown from his last term runs. The first application of a team starts a timer of 15 seconds. - Selection. When the timer fires, the applicant with the highest rank gets the offer; among equal ranks the lowest player index. The others wait.
- Accept or decline. Only the offered player can accept. A decline passes the offer to the best remaining applicant.
- In office (
setCommander,0x0045fae0): he is taken out of his squad, flagged, every client is told, the other applicants get a "not chosen" message, and Python hearsChangedCommander. - Leaving: resigning, a successful mutiny vote, or changing team removes him; the remaining applicants are asked again after 10 seconds.
There is no check that an applicant applies to his own team's post: the original accepts the application, and the selection then offers nothing to a player it finds on the other team.
The commander's screen is a camera: the manager switches his view to an overhead camera object and back to his soldier.
The assets#
Each asset is a remote controlled object in the level (a trailer, a dish, guns) with a type and an armor. Every update the manager adds up, per team and type, the living count and the health ratio (0x005660d0): an asset is available when at least one of its objects lives.
| Asset | Runs for | Ready again after | Notes |
|---|---|---|---|
| UAV | 30 s | flight + 5 s | a vehicle is created above the target and circles: speed 30, radius 60, height 120 in the shipped template; removed when its time ends or its trailer dies |
| satellite scan | 11 s | scan + 16 s | its result goes to the commander alone |
| artillery | the guns' reload, less 60 ticks | each gun must be able to reach the target with a ballistic shot at 45 degrees, else the request is refused; the guns fire one tick apart, 60 ticks after the order | |
| vehicle drop | 59.9 s | the team's drop vehicle on a parachute; the spot is moved until a 6 x 6 grid of rays finds free ground | |
| supply drop | 300 s on the ground | 59.9 s | a crate on a parachute, a supply object once it lands |
Details worth knowing:
- No drop in the first minute. Both teams' "last drop" times start at zero, so a supply drop asked for in the first 59.9 seconds of the server's life is refused.
- A destroyed asset drops its type's count to zero and the asset is not available; the HUD's "no artillery" mark follows the same numbers (the HUD).
- A vehicle drop lands when its physics says "not in the air" two updates in a row, or it has moved less than 0.1 m an update for half a second; then the parachute goes. A dropped vehicle that stays empty too long is removed.
- Heights: a drop starts at the terrain, or the water, or whatever a ray from 500 m up hits first, plus the level's drop height (50 in the shipped setting).
Votes#
Mutiny against the commander and kicking a player are votes of the same vote manager, which runs behind the round logic every update. The rules and thresholds are on server rules.
What the port has#
| Part | State |
|---|---|
| the squad manager: join, leave, leader, orders, commander | verified: 9 scripted scenarios in-process, 14,444 trace lines identical; with eight scripted clients on the original server 1,104 of 1,109 items equal, the rest timing races |
| asset timers, request rules, the artillery gate | verified in both precisions: 11,298 trace lines identical |
| health aggregation, supply-drop cooldown and height | from the listing, with unit tests; no oracle run |
| on the server: choosing a commander, requests, timers, supply crates, the vehicle drop | compared with the original server: the same events and bytes |
| the UAV's creation and removal | ported; its in-flight branch is not ported |
| the artillery's firing, aiming and the shells' flight | read; see the notes for what runs |
| the squad leader's spawn point | static reading only, as the notes mark it |
2142 keeps the manager and changes the assets: an orbital strike among its remote controlled object types, EMP, the Titan's movement by the commander's orders (game modes), and squad leader gadgets. Heroes has neither squads nor a commander.
How it is tested#
- The squad manager (
crates/bf2-game/src/squad_manager.rs, 27 tests) is a state machine without a server around it: creating, joining, leaving, locking, inviting, the commander's application and resignation, and the events each raises in Battlefield 2 and in 2142. - Traces of the original's squad manager (
crates/bf2-game/tests/squad_oracle.rs): the original's squad code is run in-process on small scripted sequences, and the port's model must reproduce each trace line for line. - Commander assets (
commander_assets.rs): the UAV and scan timers, the artillery gate, the vehicle drop's cooldown, the supply crate's lifetime; the vehicle drop's landing has a test in the server's tick-order program.
Not ported and not tested: the UAV's in-flight branch.
In the code#
| What | Where |
|---|---|
| the squad manager, votes | crates/bf2-game/src/squad_manager.rs, vote_manager.rs |
| commander assets | crates/bf2-game/src/commander_assets.rs |
| the server's side: events, state at join, team change | crates/bf2-server/src/squads.rs, rules_assets.rs, votes.rs |
| vehicle drops and the UAV | crates/bf2-server/src/vehicles_drop.rs |
| the oracles | crates/bf2-game/tests/squad_oracle.rs, asset_oracle.rs |
Notes: notes/subsystems/game-logic-squads.md, notes/subsystems/game-logic-assets.md.
docs/dev/server/squads-and-commander.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.