On this page
Server rules: rounds, tickets, flags and spawning
The rules of a round are split in two. The engine keeps the round's state, the tickets, the spawn clock and the flags' heights; the game mode's Python script decides what they mean: when a flag moves, who bleeds, who scored. Both halves run in the port: the engine's in Rust, the script as the game ships it, through an embedded Python.
The round#
ServerGameLogic::update (bf2_w32ded.exe!0x00459950) runs by the game status: Playing, end of round, pre-game. updatePlaying (0x00459340) walks four phases:
| Phase | What happens |
|---|---|
| 0 | spawning allowed; the round state is broadcast |
| 1 | wait: are numPlayersNeededToStart players connected? Then the start delay begins, and spawning is blocked |
| 2 | the start delay counts down |
| 3 | the round: the round start tick is set, the time limit's end is tick + timeLimit x 30 |
In phase 3 a round ends by a ticket limit, by the time limit, or because too few players are left for notEnoughPlayersRestartDelay. Then updateEndOfRound (0x00455680) holds the end-of-round status for endOfRoundDelay (and endDelay more after a map's last round), counts the rounds played, and starts the next round or changes the map.
Tickets#
Each team has tickets (0 to 9999), a change per second and a list of limits.
updateTickets(dt) (0x004564b0), for team 1 then team 2:
acc = dt x rate + fraction
if tickets < -acc: acc = -tickets
n = ceil(acc); if n < 0: remove -n tickets
fraction = acc - nA positive rate never adds tickets: the fraction stays between -1 and 0. When the tickets changed, the limits are checked (checkTicketLimits 0x004563f0): the first limit, in ascending id, that the tickets crossed downward raises the Python event TicketLimitReached(team, -id).
Start tickets come from a table by map size (setDefaultNumberOfTicketsEx), read with the map list entry's player count, not with the size of the layer that was loaded. A level whose only conquest layer is the 64-player one, started from a 16-player map list line, gets the 16-player tickets. The original does this; so does the port.
Conquest's limits and bleed#
The conquest script (gpm_cq.py) sets, per team, limit 1 at 0 tickets, limit 2 at 10, limit 3 at 10 % and limit 4 at 20 % of the start tickets, and reacts:
| Limit crossed | The script |
|---|---|
| 1 (no tickets) | the other team wins |
| 2, 3, 4 | the ticket state changes (the HUD and the voice-over read it) |
updateTicketLoss sums the area values of the control points each team owns:
- a team bleeds
lossPerMin / 60 x overweight / 100tickets a second when the other team's area value is at least 100 and exceeds its own; - a team with no point and nobody alive loses the level's end-of-game loss a second, while the other team's bleed stops: the round is over in seconds;
- a death costs the victim's team one ticket.
Team 2's 20 % limit is computed from team 1's start tickets (int(T1 x 0.2) for both). On a level with unequal start tickets team 2's warning comes at the wrong count. The script is the game's own file, so the port runs it as it is.
A control point's flag#
A control point has an owner, a flag that is up for a team, and a height between 0 (bottom) and 1 (top). The script's onCPTrigger runs whenever somebody enters or leaves the point's radius:
- Occupants: alive, not man down, and of a vehicle its first player only.
- The attacker is the team with more occupants;
overweightis the difference. - Nobody inside: the flag drifts at 0.5 toward where it belongs (up for an owned point, down for a neutral one), over
timeToLoseControl. - Somebody inside: when the team whose flag is up is the attacker, or the flag is at the bottom of a neutral point, the flag rises at
overweight / timeToGetControla second; else it falls atoverweight / timeToLoseControl. - At the bottom the flag changes to the attacker's.
- A point that only one team may take ignores the other.
The engine moves the height (0x0058c070): h += dt x rate; at 1 or 0 it stops and tells the script (ControlPointChangedOwner), whose onCPStatusChange decides:
| The point is | The flag reaches | Result |
|---|---|---|
| owned | the bottom | neutralized; the other team's players in the radius score |
| neutral | the top | captured by the team whose flag it is; enemyTicketLossWhenCaptured takes tickets from the other team |
More attackers are faster in proportion: three against none raise the flag three times as fast as one, and three against two as fast as one alone.
Who gets the capture#
Of the scoring team's players in the radius, those who entered first (all who tie for the earliest entry time) get the full score; the others get the assist. Conquest gives +2 for a capture or a neutralize and +1 for the assist, and +1 for a defence. Ours: first_players and takeover in crates/bf2-game/src/conquest.rs, the flag's rate in flag_update.
Try it#
The point below belongs to team 2 and its flag is up. Send soldiers in and out; the rate, the takeover and the credit are computed by the rule above.
Scores#
The score block of a player holds the score, the team-work score, the skill score, the commander score, kills, deaths and team kills. The Python awards: a kill +2, a team kill -4, a suicide -2, a revive +2, heal, repair and ammo +1 each when the accumulated share reaches 100 % of a hit point bar or an ammo load (0x00455d90, 0x004566c0). A commander gets a share of every positive award of his team's players, as a fraction that is carried until it makes a whole point; the winning commander's score is doubled at the end.
Spawning#
- A death (
playerDeath0x004551d0) sets the player's spawn tick: now plusspawnTime x 30. A man-down player's wait counts from when he fell. processSpawns(0x00457de0) runs every Playing update, but looks at the waiting players only on every third call: spawns come in waves a tenth of a second apart.- A spawn attempt (
0x00456f90) needs: spawning allowed, the status Playing, a team, tickets above 0, a soldier template from the kit, and a spawn group that exists, belongs to the team and admits the player (a squad's group only its squad). - The spawn point is
candidates[rand() % n](pickSpawnPoint0x00611a70) among the group's points that admit the player, with the C runtime'srand, seeded at level load.
The map list and votes#
The map list (+mapList, default settings/maplist.con) is a script of lines mapList.append <level> <game mode> <size>; a line whose level or mode the mod does not have is refused. Rotation (0x00454f90): the next index is an override when one is set (a passed map vote sets one), else the index plus one, modulo the count.
Votes (ServerVoteManager, ours bf2_game::vote_manager):
- three kinds: a map vote, a kick vote and a mutiny against the commander, the last two per team;
- only with
sv.votingEnabled, and a new vote needssv.minPlayersForVotingpotential voters; - a vote passes with
ceil(majority x voters)yes votes (the majority is two thirds) withinsv.voteTime; - a passed map vote changes the map 5 seconds later; a passed mutiny removes the commander and gives him a cooldown of 5 minutes; a player's first vote counts, a second is ignored.
How it is tested#
The game-rule differentials (gp_* scenarios) play scripted rounds with headless players on our server and on the original dedicated server and compare scores, tickets, the round's end, squads, votes, teams, spawn timers and awards (test rigs). The original's 30 levels were read for their tickets per size: 169 combinations of mode and size.
Notes: notes/subsystems/game-logic-rules.md, game-logic-squads.md, engine.md (the map list). Code: crates/bf2-game (round, tickets, spawn, conquest, control_point, score, vote_manager), crates/bf2-server. The script side: the Python layer. What each game mode adds to these rules: game modes. Who plays when no human does: bots.
More of the server: start-up and the main loop, kills and scoring. Squads, the commander's election and his assets: squads and commander.
In the code#
The crates this page names, each with its line of docs/release/LAYOUT.md (the list is gathered by the wiki's build from the page itself):
| Crate | What it is |
|---|---|
crates/bf2-game | game rules and server game logic: settings, round flow, tickets, spawning, scoring, squads |
crates/bf2-server | PROGRAM bf2_server: the dedicated server, and the server as a library for the client's hosted games; its deploy files are under deploy/ |
Files this page names: crates/bf2-game/src/conquest.rs.
docs/dev/server/rules.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.