OpenTTD Source 20261112-master-gbcbec5e63f
newgrf_sound.h File Reference

Functions related to NewGRF provided sounds. More...

#include "sound_type.h"
#include "tile_type.h"
#include "vehicle_type.h"

Go to the source code of this file.

Enumerations

enum class  VehicleSoundEvent : uint8_t {
  Start = 1 , Tunnel = 2 , Breakdown = 3 , Running = 4 ,
  Touchdown = 5 , VisualEffect = 6 , Running16 = 7 , Stopped16 = 8 ,
  LoadUnload = 9
}
 Events at which a sound might be played. More...

Functions

SoundEntry * AllocateSound (uint num)
 Allocate sound slots.
void InitializeSoundPool ()
bool LoadNewGRFSound (SoundEntry &sound, SoundID sound_id)
 Extract meta data from a NewGRF sound.
SoundID GetNewGRFSoundID (const struct GRFFile *file, SoundID sound_id)
SoundEntry * GetSound (SoundID sound_id)
uint GetNumSounds ()
size_t GetSoundPoolAllocatedMemory ()
 Get size of memory allocated to sound effects.
bool PlayVehicleSound (const Vehicle *v, VehicleSoundEvent event, bool force=false)
 Checks whether a NewGRF wants to play a different vehicle sound effect.
void PlayTileSound (const struct GRFFile *file, SoundID sound_id, TileIndex tile)

Detailed Description

Functions related to NewGRF provided sounds.

Definition in file newgrf_sound.h.

Enumeration Type Documentation

◆ VehicleSoundEvent

enum class VehicleSoundEvent : uint8_t
strong

Events at which a sound might be played.

Enumerator
Start 

Vehicle starting, i.e. leaving, the station.

Tunnel 

Train entering a tunnel.

Breakdown 

Vehicle breaking down.

Running 

Vehicle running normally.

Touchdown 

Whenever a plane touches down.

VisualEffect 

Vehicle visual effect (steam, diesel smoke or electric spark) is shown.

Running16 

Every 16 ticks while the vehicle is running (speed > 0).

Stopped16 

Every 16 ticks while the vehicle is stopped (speed == 0).

LoadUnload 

Whenever cargo payment is made for a vehicle.

Definition at line 18 of file newgrf_sound.h.

Function Documentation

◆ AllocateSound()

SoundEntry * AllocateSound ( uint num)

Allocate sound slots.

Parameters
numNumber of slots to allocate.
Returns
First allocated slot.

Definition at line 33 of file newgrf_sound.cpp.

◆ GetNumSounds()

uint GetNumSounds ( )

Definition at line 57 of file newgrf_sound.cpp.

◆ GetSound()

SoundEntry * GetSound ( SoundID sound_id)

Definition at line 50 of file newgrf_sound.cpp.

◆ GetSoundPoolAllocatedMemory()

size_t GetSoundPoolAllocatedMemory ( )

Get size of memory allocated to sound effects.

Returns
Approximate memory allocated by loaded sound effects.

Definition at line 66 of file newgrf_sound.cpp.

◆ InitializeSoundPool()

void InitializeSoundPool ( )

Definition at line 41 of file newgrf_sound.cpp.

◆ LoadNewGRFSound()

bool LoadNewGRFSound ( SoundEntry & sound,
SoundID sound_id )

Extract meta data from a NewGRF sound.

Parameters
soundSound to load.
sound_idIdentifier of the sound to load.
Returns
True if a valid sound was loaded.

Definition at line 84 of file newgrf_sound.cpp.

References Debug, Error, RandomAccessFile::GetSimplifiedFilename(), Grf, SoundEntry::grf_container_ver, RandomAccessFile::ReadBlock(), RandomAccessFile::ReadByte(), RandomAccessFile::ReadDword(), RandomAccessFile::ReadWord(), RandomAccessFile::SeekTo(), StrMakeValid(), and Warning.

◆ PlayVehicleSound()

bool PlayVehicleSound ( const Vehicle * v,
VehicleSoundEvent event,
bool force )

Checks whether a NewGRF wants to play a different vehicle sound effect.

Parameters
vVehicle to play sound effect for.
eventTrigger for the sound effect.
forceShould we play the sound effect even if vehicle sound effects are muted?
Returns
false if the default sound effect shall be played instead.

Definition at line 144 of file newgrf_sound.cpp.

References _settings_client, CALLBACK_FAILED, CBID_VEHICLE_SOUND_EFFECT, Vehicle::engine_type, Vehicle::GetGRF(), GetNewGRFSoundID(), GetVehicleCallback(), SoundEffect, and to_underlying().

Referenced by AircraftController(), AircraftLandAirplane(), Vehicle::HandleBreakdown(), Ship::PlayLeaveStationSound(), Train::PlayLeaveStationSound(), Vehicle::ShowVisualEffect(), VehicleEnterTile_TunnelBridge(), and CargoPayment::~CargoPayment().