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

Radio, the comm rose and soldiers' voices

BF22142Heroes

"Enemy boat spotted!" is four systems working together: a menu item that is a console command, a network event of a few bytes, a registry that turns a message name into one of several recorded variants in the right team's language, and a rule that decides whether you hear it over the radio with a filter or from the mouth of the soldier next to you. This page follows one call.

One radio call the comm rose an item is a console command: game.radioMessage <channel> <message> the event the message's id, the sender, the team, the channel: a few bytes the server sends it on to whom the channel names; it picks nothing each receiver: voice and filter commander, squad leader or grunt; the filter of the sender's seat each receiver: aloud or radio a soldier of your team within 15 m speaks it himself, if one of two slots is his each receiver: a variant and the text one of the line's recordings at random; its text in the chat BF2.exe!0x007a0de0 (rose), 0x0053e9e0 (event), 0x004441d0 (playback), 0x004f7f90 (soldier's voice), 0x004f7590 (variant)
One radio call. The server only routes it; everything a player hears and reads is decided on his own machine.

The registry#

VoiceMessages is loaded with each level (GameLogic::loadVoiceMessages, BF2.exe!0x004edb40), after the level's Init.con has named the two teams' languages. Common/Sound/VoiceMessages.con fills it:

CommandWhat it adds
addMessage <name>a message; at most 256
addRadioVoice <voice> <radio file> <text> [<local file> [<flags>]]a variant of the last message for one voice: the file heard over the radio, the text for the chat, and optionally the file a soldier speaks aloud
addRadioFilter <name> <file>a noise bed played with a radio line: a cockpit, a tank's interior
addHelpMessage <name> <file>a line of the help voice
setVolumes <radio> <filter>the two volumes

There are up to eight voices; the shipped data uses three in earnest: commander, squadleader, grunt. A message can have several variants a voice, and one is drawn at random each time (getSpeechId, 0x004f7590: start + rand() % count), which is why the same call does not sound the same twice.

Two details the notes found:

  • At Low sound quality a second variant of a line is refused: the registry keeps one recording a line, 153 fewer with the shipped scripts. Low quality also makes no soldier-voice sounds at all.
  • A voice name is case-sensitive, and the shipped data spells squadLeader with a capital L on two lines: that is a fourth voice, used by nobody else.

Languages: the radio speaks each team's language (set by gameLogic.setTeamLanguage), unless the player chose English-only voices; the help voice speaks the player's language, or English when that language ships no voice files. A dedicated server has no audio settings and uses one language for all.

From the rose to the wire#

The comm rose is HUD data. Its scripts map each item to a console command (radioInterface.setStringMap), and a click runs RadioInterface.selectOrder (0x007a0de0): it opens a sub-menu where there is one, else runs the item's command and closes the rose. On foot the items are, in the shipped scripts: spotted, go go go, need a pickup, negative, need ammo, follow me, need a medic, roger that, need backup, thank you, sorry. A vehicle's rose, a squad leader's and the commander's are other files of the same kind. A mod changes the rose by editing them.

Most items run game.radioMessage <channel> <message>. The channel says who should get it: the local team, the whole team, a squad, a vehicle's crew, the team and nearby enemies.

On the wire it is RadioMessageEvent (read 0x0053e8f0, write 0x0053e9e0): the message's id in 8 bits, the sender's player id in 8, the team in 2, a flags byte, the channel and a type. The server's part is to send it on to the players the channel names. It does not pick a variant, a voice or a text: a message id is all that travels.

What the receiver plays#

Game::playbackRadioMessage (0x004441d0), on each client that got the event:

  1. The voice and the filter. No sender (the game itself speaking): the commander's voice and filter. Otherwise the sender's vehicle decides the filter: the soundFilter of the first seat up from what he controls. A commander gets the commander's voice and filter; a squad leader the squad leader's voice; anyone else grunt.
  2. Your own call is played without a filter.
  3. Aloud or over the radio. If the sender is a soldier on foot, is not you, and the quality is not Low, the client first tries the soldier's own voice (below). Only if that is refused does the radio play: the variant on the team's radio sound, and under it the filter, looped as many times as it needs to cover the line's length.
  4. The text goes to the chat with the sender's name, unless the sender is on another team than you.
A quirk kept

A commander who sits in a vehicle whose soundFilter is empty ends up on the default filter and not the commander's: the flag for "use the default" is computed before the commander's case and never cleared. The port does the same.

A soldier's own voice#

VoiceMessages::playSoldierVO (0x004f7f90). The line's variant must have a "local" file, and its flags decide who may hear it this way:

  • unless the flag says otherwise, only your own team's soldiers are heard aloud;
  • unless the flag says otherwise, only a speaker within 15 m of your camera.

Then the speaker needs one of the two voice slots a team (getFreeVOSoundIndex, 0x004f7820): a silent slot is taken; else the slot whose speaker is dead; else the slot of the farthest speaker, and only when the new speaker is strictly closer. So when three soldiers around you shout at once, you hear the two nearest from where they stand, and the third over the radio.

The soldier-voice sound is 3D with a minimum distance of 3 m and reverb, and it follows the soldier (voices and space). A soldier who starts a new line stops his previous one softly.

The help voice and automatic lines#

  • Help lines ("press E to enter the vehicle") play on a 2D sound in their own volume group, and only when that group's volume is above 0.05: turning the help voice down in the options to nearly nothing switches them off.
  • Automatic lines are the ones the game itself triggers (their own file of the registry). They are radio messages, with no sender or with the soldier concerned as the sender, and follow the same path.
2142
Battlefield 2142 and Heroes

2142 keeps the registry, with its voice files in another folder. Heroes' HUD scripts have emotes and personal message lines in their communication folder (the Heroes HUD); the sweeps have not read Heroes' radio path, so this page says nothing about it.

What the port has#

PartState
the registry: messages, voices, variants, filters, the Low quality ruleported (bf2_audio::voice)
playbackRadioMessage: voice, filter, the commander's quirk, the textverified against the original function
the soldier's voice: flags, the 15 m, the two slots, the farthest gives wayverified against the original functions
the event's layoutported with the network events (packets)
the comm rose's menus and sendingported in the client (bf2_client::radio)
bots' radio: the queue, the hub, who answersported with the AI (bots)

One thing the port cannot inherit: a speaker of a team other than 1 or 2 makes the original read before the start of an array. The port answers "no slot".

How it is tested#

  • Registration against the original (crates/bf2-audio/tests/voice_oracle.rs): the original's own methods are run for adding messages and radio voices, with generated input and with the shipped scripts, and the port's registry, the soldier's voice-over and the radio playback must match.
  • Every shipped voice definition resolves to a file (retail_voice.rs).
  • On the wire (crates/bf2-net/tests/it_bf2/generic_events_bf2.rs): every such event writes and reads back through the event stream's own codec.
  • 2142: its message count, volumes and filters have tests of their own.

All eight addresses of this page stand in a test's own text.

In the code#

WhatWhere
the registry and playbackcrates/bf2-audio (voice)
the comm rose and sendingcrates/bf2-client/src/radio.rs
the HUD's side of the rosecrates/bf2-hud
the eventcrates/bf2-net

Notes: notes/subsystems/audio.md (section 14), notes/subsystems/ai-behaviour.md (section 48), notes/subsystems/network-events.md.

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