BF2.US bf2-rsdeveloper wiki Parity Discord bf2.us
On this page

Server rules: rounds, tickets, flags and spawning

BF22142

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.

A round on the server (ServerGameLogic::updatePlaying, bf2_w32ded.exe!0x00459340) phase 0 spawning allowed phase 1 wait for enough players phase 2 the start delay runs phase 3 the round: tickets, time numPlayersNeededToStart sv.startDelay x 30 ticks What ends a round a team's tickets reach 0: the limit with id 1 is crossed (TicketLimitReached), the other team wins the time limit: start + sv.timeLimit x 30 < tick; more tickets wins, equal tickets is a draw too few players for sv.notEnoughPlayersRestartDelay: the time limit event is raised then the end-of-round status for sv.endOfRoundDelay, and the next round or the next map tickets fall by deaths (1 each) and by the bleed: lossPerMin / 60 x overweight / 100 a second for the team that holds less 0x00459950 (update), 0x004564b0 (updateTickets), 0x004563f0 (checkTicketLimits), 0x00455680 (updateEndOfRound)
The phases of a round while the game status is Playing.

The round#

ServerGameLogic::update (bf2_w32ded.exe!0x00459950) runs by the game status: Playing, end of round, pre-game. updatePlaying (0x00459340) walks four phases:

PhaseWhat happens
0spawning allowed; the round state is broadcast
1wait: are numPlayersNeededToStart players connected? Then the start delay begins, and spawning is blocked
2the start delay counts down
3the 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:

text
acc = dt x rate + fraction
if tickets < -acc:  acc = -tickets
n = ceil(acc);  if n < 0: remove -n tickets
fraction = acc - n

A 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 crossedThe script
1 (no tickets)the other team wins
2, 3, 4the 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 / 100 tickets 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.
A bug of the original the port keeps

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:

  1. Occupants: alive, not man down, and of a vehicle its first player only.
  2. The attacker is the team with more occupants; overweight is the difference.
  3. Nobody inside: the flag drifts at 0.5 toward where it belongs (up for an owned point, down for a neutral one), over timeToLoseControl.
  4. 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 / timeToGetControl a second; else it falls at overweight / timeToLoseControl.
  5. At the bottom the flag changes to the attacker's.
  6. 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 isThe flag reachesResult
ownedthe bottomneutralized; the other team's players in the radius score
neutralthe topcaptured 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 (playerDeath 0x004551d0) sets the player's spawn tick: now plus spawnTime 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] (pickSpawnPoint 0x00611a70) among the group's points that admit the player, with the C runtime's rand, 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 needs sv.minPlayersForVoting potential voters;
  • a vote passes with ceil(majority x voters) yes votes (the majority is two thirds) within sv.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):

CrateWhat it is
crates/bf2-gamegame rules and server game logic: settings, round flow, tickets, spawning, scoring, squads
crates/bf2-serverPROGRAM 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.

Source: docs/dev/server/rules.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.